Name: sleep/1
Module: system
codes_from_server(Codes) :- server_stream(Stream), read_from_server2(Stream,Codes).
Calls:
Name: read_from_server2/2
Name: server_stream/1
Called:
Name: process_term/2
codes_to_client(Codes) :- client_stream(Stream), put_codes(Codes, Stream), flush_output(Stream).
Name: flush_output/1
Name: put_codes/2
Name: client_stream/1
connect_to_server :- retractall(server_stream(_)), server_port(Port), catch( ( socket_client_open(localhost:Port,Stream,[type(text)]), assert( server_stream(Stream) )), error(system_error, system_error(E)), retry_connect_to_server(E)).
Name: catch/3
Name: server_port/1
Name: retractall/1
Name: retry_connect_to_server/1
Name: term_to_server/2
get_variable_name([Name=Var|_],V,N) :- Var==V,!,N=Name. get_variable_name([_|Rest],V,N) :- get_variable_name(Rest,V,N).
Name: RECURSIVE_CALL/3
Name: =/2
Name: !
Name: ==/2
Name: write_varterm/3
process_term(end_of_file,_) :- !, stop. process_term(halt,_) :- !, stop. process_term(Term,Vars) :- term_to_server(Term,Vars), codes_from_server(Codes), codes_to_client(Codes).
Name: codes_to_client/1
Name: codes_from_server/1
Name: stop/0
Name: read_socket/0
put_codes([],_). put_codes([C|Rest],Stream) :- put_code(Stream,C), put_codes(Rest,Stream).
Name: RECURSIVE_CALL/2
Name: put_code/2
read_from_server2(Stream,Codes) :- get_code(Stream, Code), ( Code == -1 -> Codes = [], retractall(server_stream(_)) ; Code == 1 -> Codes = [1] ; otherwise -> Codes = [Code|Rest], read_from_server2(Stream,Rest)).
Name: otherwise
Name: ->/2
Name: ->/3
Name: get_code/2
read_socket :- read_term_from_socket(Term,Vars), process_term(Term,Vars), read_socket.
Name: RECURSIVE_CALL/0
Name: read_term_from_socket/2
Name: start/0
read_term_from_socket(Term,Vars) :- client_stream(Stream), catch(read_term(Stream, Term, [variable_names(Vars)]), E, syntax_error(E)).
retry_connect_to_server(E) :- format('Error when trying to connect to server - retry in a second (~w)~n',[E]), sleep(1), connect_to_server.
Name: connect_to_server/0
Name: format/2
runtime_entry(start) :- start.
save(Port,Revision) :- assert( server_port(Port) ), assert( revision(Revision) ), save_program('probproxy.sav').
Name: save_program/1
Name: revision/1
Name: assert/1
start :- revision(Revision), socket_server_open(Port, Socket), format('Starting proxy ProB socket server.~n',[]), format('Port: ~w~n', [Port]), format('probcli revision: ~w~n',[Revision]), format('-- starting command loop --~n', []), flush_output, socket_server_accept(Socket, _Client, Stream, [type(text),encoding('UTF-8')]), assert( client_stream(Stream) ), read_socket, socket_server_close(Socket).
Name: socket_server_close/1
Name: socket_server_accept/4
Name: flush_output
Name: socket_server_open/2
Name: runtime_entry/1
stop :- format('Stopping proxy server, bye!~n',[]), halt.
Name: halt
Name: syntax_error/1
syntax_error(E) :- format('Got syntax error, get your Java code right!~n~w~n', [E]), stop.
term_to_server(Term,Vars) :- ( server_stream(Stream) -> write_varterm(Stream,Term,Vars), write(Stream,'.\n'), flush_output(Stream) ; otherwise -> connect_to_server, term_to_server(Term,Vars)).
Name: write/2
write_varterm(Stream,Term,Vars) :- ( var(Term) -> get_variable_name(Vars,Term,Varname), write(Stream,Varname) ; ground(Term) -> write_term(Stream,Term,[quoted(true)]) ; otherwise -> Term =.. [Functor|Args], write_term(Stream,Functor,[quoted(true)]), write(Stream,'('), write_varterm_l(Args,Stream,Vars), write(Stream,')')).
Name: write_varterm_l/3
Name: write_term/3
Name: =../2
Name: ground/1
Name: get_variable_name/3
Name: var/1
write_varterm_l([Arg|Rest],Stream,Vars) :- write_varterm(Stream,Arg,Vars), write_varterm_l2(Rest,Stream,Vars).
Name: write_varterm_l2/3
write_varterm_l2([],_Stream,_Vars). write_varterm_l2([Arg|Rest],Stream,Vars) :- write(Stream,','), write_varterm_l([Arg|Rest],Stream,Vars).