3 * Stefano Zacchiroli <zack@cs.unibo.it>
4 * for the HELM Team http://helm.cs.unibo.it/
6 * This file is part of HELM, an Hypertextual, Electronic
7 * Library of Mathematics, developed at the Computer Science
8 * Department, University of Bologna, Italy.
10 * HELM is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * HELM is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with HELM; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * For details, see the HELM World-Wide-Web page,
26 * http://helm.cs.unibo.it/
32 exception Client_already_in of client_id;;
33 exception Client_not_found of client_id;;
34 exception Musing_already_in of musing_id;;
35 exception Musing_not_found of musing_id;;
36 exception Tutor_already_in of tutor_id;;
37 exception Tutor_not_found of tutor_id;;
42 inherit ThreadSafe.threadSafe
44 val urls: (client_id, string) Hashtbl.t = Hashtbl.create 17
45 val subscriptions: (client_id, tutor_id list) Hashtbl.t = Hashtbl.create 17
47 method register id url = self#doWriter (lazy (
48 if Hashtbl.mem urls id then
49 raise (Client_already_in id)
51 Hashtbl.add urls id url;
52 Hashtbl.add subscriptions id []
55 method unregister id = self#doWriter (lazy (
56 if Hashtbl.mem urls id then begin
57 Hashtbl.remove urls id;
58 Hashtbl.remove subscriptions id
60 raise (Client_not_found id)
62 method isAuthenticated id = self#doReader (lazy (
65 method subscribe client_id tutor_ids = self#doWriter (lazy (
66 if Hashtbl.mem urls client_id then
67 Hashtbl.replace subscriptions client_id tutor_ids
69 raise (Client_not_found client_id)
71 method getUrl id = self#doReader (lazy (
72 if Hashtbl.mem urls id then
75 raise (Client_not_found id)
77 method getSubscription id = self#doReader (lazy (
78 if Hashtbl.mem urls id then
79 Hashtbl.find subscriptions id
81 raise (Client_not_found id)
89 inherit ThreadSafe.threadSafe
91 val tbl: (tutor_id, string * hint_type * string) Hashtbl.t =
94 method register id url hint_type dsc = self#doWriter (lazy (
95 if Hashtbl.mem tbl id then
96 raise (Tutor_already_in id)
98 Hashtbl.add tbl id (url, hint_type, dsc)
100 method unregister id = self#doWriter (lazy (
101 if Hashtbl.mem tbl id then
102 Hashtbl.remove tbl id
104 raise (Tutor_not_found id)
106 method isAuthenticated id = self#doReader (lazy (
109 method exists id = self#doReader (lazy (
112 method getTutor id = self#doReader (lazy (
113 if Hashtbl.mem tbl id then
116 raise (Tutor_not_found id)
119 let (url, _, _) = self#getTutor id in
121 method getHintType id =
122 let (_, hint_type, _) = self#getTutor id in
124 method getDescription id =
125 let (_, _, dsc) = self#getTutor id in
127 method index = self#doReader (lazy (
129 (fun id (url, hint_type, dsc) idx -> (id, dsc) :: idx) tbl []
137 inherit ThreadSafe.threadSafe
139 val musings: (musing_id, client_id * tutor_id) Hashtbl.t = Hashtbl.create 17
140 val clients: (client_id, musing_id) Hashtbl.t = Hashtbl.create 17
141 val tutors: (tutor_id, musing_id) Hashtbl.t = Hashtbl.create 17
143 method register musing_id client_id tutor_id = self#doWriter (lazy (
144 if Hashtbl.mem musings musing_id then
145 raise (Musing_already_in musing_id)
147 Hashtbl.add musings musing_id (client_id, tutor_id);
148 Hashtbl.add clients client_id musing_id;
149 Hashtbl.add tutors tutor_id musing_id
152 method unregister id = self#doWriter (lazy (
153 if Hashtbl.mem musings id then begin
154 Hashtbl.remove musings id;
155 hashtbl_remove_all clients id;
156 hashtbl_remove_all tutors id
159 method getByMusingId id = self#doReader (lazy (
161 Hashtbl.find musings id
162 with Not_found -> raise (Musing_not_found id)
164 method getByClientId id = self#doReader (lazy (
165 Hashtbl.find_all clients id
167 method getByTutorId id = self#doReader (lazy (
168 Hashtbl.find_all tutors id