2 * Copyright (C) 2003, HELM Team.
4 * This file is part of HELM, an Hypertextual, Electronic
5 * Library of Mathematics, developed at the Computer Science
6 * Department, University of Bologna, Italy.
8 * HELM is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * HELM is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with HELM; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 * For details, see the HELM World-Wide-Web page,
24 * http://cs.unibo.it/helm/.
30 exception Client_already_in of client_id;;
31 exception Client_not_found of client_id;;
32 exception Musing_already_in of musing_id;;
33 exception Musing_not_found of musing_id;;
34 exception Tutor_already_in of tutor_id;;
35 exception Tutor_not_found of tutor_id;;
40 inherit ThreadSafe.threadSafe
42 val urls: (client_id, string) Hashtbl.t = Hashtbl.create 17
43 val subscriptions: (client_id, tutor_id list) Hashtbl.t = Hashtbl.create 17
45 method register id url = self#doWriter (lazy (
46 if Hashtbl.mem urls id then
47 raise (Client_already_in id)
49 Hashtbl.add urls id url;
50 Hashtbl.add subscriptions id []
53 method unregister id = self#doWriter (lazy (
54 if Hashtbl.mem urls id then begin
55 Hashtbl.remove urls id;
56 Hashtbl.remove subscriptions id
58 raise (Client_not_found id)
60 method isAuthenticated id = self#doReader (lazy (
63 method subscribe client_id tutor_ids = self#doWriter (lazy (
64 if Hashtbl.mem urls client_id then
65 Hashtbl.replace subscriptions client_id tutor_ids
67 raise (Client_not_found client_id)
69 method getUrl id = self#doReader (lazy (
70 if Hashtbl.mem urls id then
73 raise (Client_not_found id)
75 method getSubscription id = self#doReader (lazy (
76 if Hashtbl.mem urls id then
77 Hashtbl.find subscriptions id
79 raise (Client_not_found id)
87 inherit ThreadSafe.threadSafe
89 val tbl: (tutor_id, string * hint_type * string) Hashtbl.t =
92 method register id url hint_type dsc = self#doWriter (lazy (
93 if Hashtbl.mem tbl id then
94 raise (Tutor_already_in id)
96 Hashtbl.add tbl id (url, hint_type, dsc)
98 method unregister id = self#doWriter (lazy (
99 if Hashtbl.mem tbl id then
100 Hashtbl.remove tbl id
102 raise (Tutor_not_found id)
104 method isAuthenticated id = self#doReader (lazy (
107 method exists id = self#doReader (lazy (
110 method getTutor id = self#doReader (lazy (
111 if Hashtbl.mem tbl id then
114 raise (Tutor_not_found id)
117 let (url, _, _) = self#getTutor id in
119 method getHintType id =
120 let (_, hint_type, _) = self#getTutor id in
122 method getDescription id =
123 let (_, _, dsc) = self#getTutor id in
125 method index = self#doReader (lazy (
127 (fun id (url, hint_type, dsc) idx -> (id, dsc) :: idx) tbl []
135 inherit ThreadSafe.threadSafe
137 val musings: (musing_id, client_id * tutor_id) Hashtbl.t = Hashtbl.create 17
138 val clients: (client_id, musing_id) Hashtbl.t = Hashtbl.create 17
139 val tutors: (tutor_id, musing_id) Hashtbl.t = Hashtbl.create 17
141 method register musing_id client_id tutor_id = self#doWriter (lazy (
142 if Hashtbl.mem musings musing_id then
143 raise (Musing_already_in musing_id)
145 Hashtbl.add musings musing_id (client_id, tutor_id);
146 Hashtbl.add clients client_id musing_id;
147 Hashtbl.add tutors tutor_id musing_id
150 method unregister id = self#doWriter (lazy (
151 if Hashtbl.mem musings id then begin
152 Hashtbl.remove musings id;
153 hashtbl_remove_all clients id;
154 hashtbl_remove_all tutors id
157 method getByMusingId id = self#doReader (lazy (
159 Hashtbl.find musings id
160 with Not_found -> raise (Musing_not_found id)
162 method getByClientId id = self#doReader (lazy (
163 Hashtbl.find_all clients id
165 method getByTutorId id = self#doReader (lazy (
166 Hashtbl.find_all tutors id