exception Empty_must;;
-module MQICallbacks =
- struct
- let log s = prerr_string s
- end
-
-module MQI = MQueryInterpreter.Make(MQICallbacks)
+module MQI = MQueryInterpreter
+module MQIC = MQIConn
let broker_id = ref None
let my_own_id = Hbugs_tutors_common.init_tutor ()
| Some broker_id -> id = broker_id
(* thread who do the dirty work *)
-let slave (state, musing_id) =
+let slave mqi_handle (state, musing_id) =
try
prerr_endline (sprintf "Hi, I'm the slave for musing %s" musing_id);
let (proof, goal) = Hbugs_tutors_common.load_state state in
| hd::tl -> hd
in
let uris =
- TacticChaser.searchPattern
+ TacticChaser.searchPattern mqi_handle
~output_html:prerr_endline ~choose_must () ~status:(proof, goal)
in
if uris = [] then
(* exception ==> no additional arm *)
raise (unbox_exception e)
-let hbugs_callback =
+let hbugs_callback mqi_handle =
let ids = Hashtbl.create 17 in
let forbidden () =
prerr_endline "ignoring request from unauthorized broker";
if is_authenticated broker_id then begin
prerr_endline "received Start_musing";
let new_musing_id = Hbugs_id_generator.new_musing_id () in
- let id = Hbugs_deity.create slave (state, new_musing_id) in
+ let id = Hbugs_deity.create (slave mqi_handle) (state, new_musing_id) in
prerr_endline
(sprintf "starting a new musing (tid = %d, id = %s)" id new_musing_id);
Hashtbl.add ids new_musing_id id ;
Exception ("unexpected_msg",
Hbugs_messages.string_of_msg unexpected_msg)
-let callback (req: Http_types.request) outchan =
+let callback mqi_handle (req: Http_types.request) outchan =
try
let req_msg = Hbugs_messages.msg_of_string req#body in
- let answer = hbugs_callback req_msg in
+ let answer = hbugs_callback mqi_handle req_msg in
Http_daemon.respond ~body:(Hbugs_messages.string_of_msg answer) outchan
with Hbugs_messages.Parse_error (subj, reason) ->
Http_daemon.respond
outchan
let main () =
- let mqi_options = "" in (* default MathQL interpreter options *)
+ let mqi_flags = [] in (* default MathQL interpreter options *)
try
Sys.catch_break true;
at_exit (fun () -> Hbugs_tutors_common.unregister_from_broker my_own_id);
broker_id :=
Some (Hbugs_tutors_common.register_to_broker
my_own_id my_own_url "FOO" "Search_pattern_apply tutor");
- ignore (MQI.init mqi_options) ;
+ let mqi_handle = MQIC.init mqi_flags prerr_string in
Http_daemon.start'
- ~addr:my_own_addr ~port:my_own_port ~mode:`Thread callback;
- MQI.close mqi_options
+ ~addr:my_own_addr ~port:my_own_port ~mode:`Thread (callback mqi_handle);
+ MQIC.close mqi_handle
with Sys.Break -> () (* exit nicely, invoking at_exit functions *)
;;