Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 108 lines (76 sloc) 3.31 kb
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (** Communications with clients. *)
19
20 type json = JsonTypes.json
21
22 (** Client module should be define type of client identifier and
23 message and a serialization function for ping register. *)
24 module type CLIENT = sig
25
26 (** Type of identifier of a client. *)
27 type key
28
29 (** Type of message can be sent to clients. *)
30 type msg
31
32 (** Serialiaze a message to json which can be interpreted by a client. *)
33 val serialize : msg -> json Cps.t
34
35 (** {6 For debug}*)
36 (** Used by [PING_DEBUG]. *)
37 val key_to_string : key -> string
38
39 end
40
41 module type SCHEDULER = sig
42 type async_key
43 val sleep : int -> (unit -> unit) -> async_key
44 val abort : async_key -> unit
45 end
46
47 (** Make a ping register. A ping register is a module which allows to
48 communicates with cient.*)
49 module Make (S : SCHEDULER) (C : CLIENT) : sig
50
51 (** Kind of ping register events. *)
52 type event =
53 | Connect (** Launched when a client connects to ping register. *)
54 | Disconnect (** Launched when a client is disconnected to ping register. *)
55
56 (** Type of key binded to an event handler (see section Events). *)
57 type event_key
58
59 (** {6 Sending messages} *)
60
61 (** [send message id] Send a message to client identified by
62 [id]. *)
63 val send : C.msg -> C.key -> unit
64
65 (** Broadcast a message to all connected clients. *)
66 val broadcast : C.msg -> unit
67
68 (** {6 Interactions with client}*)
69
70 (** [ping id winfo nb] Ping the register form client [id], [winfo]
71 must allows to reply to client. [nb] is the ping number. *)
72 val ping : C.key -> HttpServerTypes.web_info -> int -> unit
73
74 (** [pang id winfo nb] Like as [ping id winfo nb] but you can reply
75 to this specific [pang] with [return id nb response]. *)
76 val pang : C.key -> HttpServerTypes.web_info -> int -> unit
77
78 (** Returns a [pang]. *)
79 val return : C.key -> int -> string -> unit
80
81 (** {6 Events} *)
82
83 (** Register a callback that will be executed when a corresponding
84 event will be launched. The first parameters indicates on
85 which client the callback will be registered, if it's None
86 then the callback will be executed for all client. *)
87 val register_event : C.key option -> event -> (C.key -> unit) -> event_key
88
89 (** Remove callback event registered associated with [event_key]. *)
90 val remove_event : event_key -> unit
91
92 (** {6 Utils} *)
93
94 (** Check if the client is already connected to the ping
95 register. *)
96 val mem : C.key -> bool
97
98 (** Delete a client entry. *)
99 val delete : C.key -> unit
100
523cb66 @BourgerieQuentin [fix] ping_register: A client connection is created on first ping, but i...
BourgerieQuentin authored
101 (** Create a client entry (Is needed ...). *)
102 val create : C.key -> unit
103
606eb78 @BourgerieQuentin [feature] ping_register: Add a bypass that indicates the number of dangl...
BourgerieQuentin authored
104 (** Return the number of connections. *)
105 val size : unit -> int
106
fccc685 Initial open-source release
MLstate authored
107 end
Something went wrong with that request. Please try again.