| 1 | % (c) 2011-2021 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, | |
| 2 | % Heinrich Heine Universitaet Duesseldorf | |
| 3 | % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) | |
| 4 | ||
| 5 | :- module(zmq, [init_zmq/0, | |
| 6 | master_main/10, alloc_term/3, | |
| 7 | setup_worker/5, work_reactor/1, teardown_worker/0, | |
| 8 | new_results_message/1, start_timer/0, stop_timer/0, | |
| 9 | msg_put_str/2, put_succ/4, add_stats/1, send_and_destroy_msg/1]). | |
| 10 | ||
| 11 | :- use_module(probsrc(module_information)). | |
| 12 | :- module_info(group,zmq). | |
| 13 | :- module_info(description,'This is the interface to C code for distributed model checking.'). | |
| 14 | ||
| 15 | foreign_resource('zmq', [master_main, alloc_term, | |
| 16 | setup_worker, work_reactor, teardown_worker, | |
| 17 | new_results_message, | |
| 18 | start_timer, stop_timer, | |
| 19 | msg_put_str, put_succ, | |
| 20 | add_stats, send_and_destroy_msg]). | |
| 21 | ||
| 22 | % master functions | |
| 23 | foreign(master_main, c, master_main(+integer,+integer,+integer,+address(zchunk_t),+address(zchunk_t),+string,+string,+string,+integer,[-integer])). | |
| 24 | foreign(alloc_term, c, alloc_term(+address(char), +integer, [-address(zchunk_t)])). | |
| 25 | ||
| 26 | % worker functions | |
| 27 | foreign(setup_worker, c, setup_worker(+integer, +integer, +string, +string, +string)). | |
| 28 | foreign(work_reactor, c, work_reactor([-integer])). | |
| 29 | foreign(teardown_worker, c, teardown_worker). | |
| 30 | foreign(new_results_message, c, new_results_message([-address(zmsg_t)])). | |
| 31 | foreign(start_timer, c, start_timer). | |
| 32 | foreign(stop_timer, c, stop_timer). | |
| 33 | foreign(msg_put_str, c, msg_put_str(+address(zmsg_t), +string)). | |
| 34 | foreign(put_succ, c, put_succ(+address(zmsg_t), +address(char), +integer, +integer)). | |
| 35 | foreign(add_stats, c, add_stats(+address(zmsg_t))). | |
| 36 | foreign(send_and_destroy_msg, c, send_and_destroy_msg(+address(zmsg_t))). | |
| 37 | ||
| 38 | :- dynamic is_initialised/0. | |
| 39 | ||
| 40 | init_zmq :- is_initialised,!. | |
| 41 | init_zmq :- | |
| 42 | safe_load_foreign_resource(zmq), | |
| 43 | assertz(is_initialised). | |
| 44 | ||
| 45 | ||
| 46 | safe_load_foreign_resource(R) :- | |
| 47 | E=error(existence_error(_,_),_), | |
| 48 | % print(loading_foreign_resource(R)),nl, | |
| 49 | catch(load_foreign_resource(library(R)), E, ( | |
| 50 | format(user_error,'~n! Could not load ~w library!~n! Check that it is available in the lib folder of ProB.~n~n',[R]), | |
| 51 | throw(E) | |
| 52 | )). |