Module Db

module Db: sig .. end
Managing authentication and associated data for interactive sessions.

Patoline documents can be interactive, allowing for example an audience to connect remotely to a presentation and interact with it, possibly changing some parts of it (such as answering a poll, results being updated on-screen immediately).

This module provides tools for managing user sessions and a storage space for key/value pairs associated to each session.



Encoding and decoding data in the database


type 'a data = {
   name : string;
   init : 'a;
   read : unit -> 'a;
   write : 'a -> unit;
   reset : unit -> unit;
   distribution : ?group:string -> unit -> int * ('a * int) list;
}
exception DummyData
Exception raised when actually trying to use the Db.dummyData below.
val dummyData : string data
Dummy inhabitant of type Db.data, which can be used to initialize data structure, but whose content should never be used (calling any member function raises Db.DummyData).
type 'a coding = {
   encode : 'a -> string; (*
Serializing some value of type 'a to a string which can be stored in database.
*)
   decode : string -> 'a; (*
Parsing a string from the database and creating a value of type 'a. This should be the inverse of encode.
*)
}
val default_coding : 'a coding
Default polymorphic coding, using OCaml Marshal module, escaped using base64.
val string_coding : string coding
Strings coding, which ony uses base64 escaping.
val bool_coding : bool coding
Coding boolean as strings "true" and "false". Any value other than "true" in the database is decoded as false.

Connection to databases


module type DbInterface = sig .. end
Interface to be implemented by database managers
module type DbInstance = sig .. end
Generic type for database instances
type database = (module Db.DbInstance) 
type db = {
   db : unit -> database;
   create_data : 'a.
?log:bool ->
?visibility:Util.visibility -> 'a coding -> string -> 'a -> 'a data
;
   disconnect : unit -> unit;
}
val init_db : (module Db.DbInterface with type dbinfo = 'a) -> string -> 'a -> db

Hooks


val interaction_start_hook : (unit -> unit) list Pervasives.ref
List of functions called when the interactive session starts
val read_hook : (string -> Util.visibility -> unit) list Pervasives.ref
Hooks called when some data is being read from a database
val write_hook : (string -> Util.visibility -> unit) list Pervasives.ref
Hooks called when some data is being written to a database
val record : ('a -> 'b -> unit) list Pervasives.ref ->
('c -> 'd) -> 'c -> 'd * ('a * 'b) list
val stop_record : 'a list Pervasives.ref -> ('b -> 'c) -> 'b -> 'c
val record_read : ('a -> 'b) -> 'a -> 'b * (string * Util.visibility) list
val record_write : ('a -> 'b) -> 'a -> (string * Util.visibility) list
val stop_record_read : ('a -> 'b) -> 'a -> 'b
val stop_record_write : ('a -> 'b) -> 'a -> 'b
val do_interaction_start_hook : unit -> unit
Run all hooks in Db.interaction_start_hook.
val do_record_read : 'a data -> Util.visibility -> unit
Run all hooks in Db.read_hook.
val do_record_write : 'a data -> Util.visibility -> unit
Run all hooks in Db.write_hook.

Utility functions


val sessid : (string * string * (string * string) list) option Pervasives.ref
val secret : string Pervasives.ref
val make_sessid : unit -> string
val friends_from_string : string -> (string * string) list
val friends_to_string : (string * string) list -> string