package patoline

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

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 = {
  1. name : string;
  2. init : 'a;
  3. read : unit -> 'a;
  4. write : 'a -> unit;
  5. reset : unit -> unit;
  6. distribution : ?group:string -> unit -> int * ('a * int) list;
}
exception DummyData

Exception raised when actually trying to use the dummyData below.

val dummyData : string data

Dummy inhabitant of type data, which can be used to initialize data structure, but whose content should never be used (calling any member function raises DummyData).

type 'a coding = {
  1. encode : 'a -> string;
    (*

    Serializing some value of type 'a to a string which can be stored in database.

    *)
  2. 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 DbInstance)
type db = {
  1. db : unit -> database;
  2. create_data : 'a. ?log:bool -> ?visibility:Patutil.Util.visibility -> 'a coding -> string -> 'a -> 'a data;
  3. disconnect : unit -> unit;
}
val init_db : (module DbInterface with type dbinfo = 'a) -> string -> 'a -> db

Hooks

val interaction_start_hook : (unit -> unit) list Stdlib.ref

List of functions called when the interactive session starts

val read_hook : (string -> Patutil.Util.visibility -> unit) list Stdlib.ref

Hooks called when some data is being read from a database

val write_hook : (string -> Patutil.Util.visibility -> unit) list Stdlib.ref

Hooks called when some data is being written to a database

val record : ('a -> 'b -> unit) list Stdlib.ref -> ('c -> 'd) -> 'c -> 'd * ('a * 'b) list
val stop_record : 'a list Stdlib.ref -> ('b -> 'c) -> 'b -> 'c
val record_read : ('a -> 'b) -> 'a -> 'b * (string * Patutil.Util.visibility) list
val record_write : ('a -> 'b) -> 'a -> (string * Patutil.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 interaction_start_hook.

val do_record_read : 'a data -> Patutil.Util.visibility -> unit

Run all hooks in read_hook.

val do_record_write : 'a data -> Patutil.Util.visibility -> unit

Run all hooks in write_hook.

Utility functions

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

Innovation. Community. Security.