Subject: Re: [SWIPL] How may I leave a PCE window available for input while a server is running on it?

From: "Armando Stellato" <[email-masked]>
Date: Wed, 26 Sep 2001 17:41:54 +0200

Thank you for your answer.
Just This morning i found an alternative solution, take a look and tell me
if it sounds "good".
I found the class timer (in xpce) and used it to send a message to prolog
every #milliseconds, letting @prolog use the predicate dispatch
for client-waiting.
In this way, the window is not busy anymore and, another important thing,
while timer continues to make prolog listen for clients, the predicate
dispatch can then deal with every client that connected to the server.
So, while SWI-prolog on windows is not multithreaded, the use of XPCE can
start multiple parallel prolog predicates from the same application, this is
kind of multitasking...even on windows...
This fact, combined with the broadcast-library providd with XPCE, can give
life to a complex agent-based environment!!
This the portion of code I modified wuth the introduction of the timer
class:

dispatch(_GUI) :-
 new(@dispatch_timer,timer(0.02,message(@prolog,dispatch1))),
 send(@dispatch_timer,start).

/*
 send(GUI,synchronise),        this portion of code is no more needed
 send(GUI,flush),
 dispatch1,
 !.
*/

dispatch1 :-
 findall(WriteStream,
agents:connection(_ClientId,_Socket,WriteStream,_ReadStream), Clients),
 listen_stream(Server),
 wait_for_input([Server|Clients],ReadyList, 0.015),
 (ReadyList \= [])
 ->
 format('ReadyList is: ~w~n',ReadyList),
 process_listen_queue(ReadyList)
 ;
% write(waiting),nl,flush_output,
 true.

Do you think it is a good solution???

Again, thank you.
Armando

----- Original Message -----
From: "Jan Wielemaker" <[email-masked]>
To: "Armando Stellato" <[email-masked]>; "SWI Mailing List"
<[email-masked]>
Sent: Wednesday, September 26, 2001 4:53 PM
Subject: Re: [SWIPL] How may I leave a PCE window available for input while
a server is running on it?

> On Mon, 13 Aug 2001, Armando Stellato wrote:
> >Hi,
> >I'm writing a Prolog-server on windows, so I can't use multitasking.
> >The problem is: if i make the server listening for inputs, he is busy
> >and I cannot access the window (the pointer is in the classic sand glass
> >shape). I'm using a repeat-loop to open a repetition of 0.55ms time
> >cells where the server is listening for clients. If I could add
> >something between the time cells for make the window listening for
> >manual inputs, the problem would be solved, but I don't know what.
> >Thank u in advance.
>
> You can clear the busy cursor using send(Frame, busy_cursor, @nil) and
> invoke send(@display, synchronise) from your loop to make the system
> look for events.  This call processes pending GUI events (if any) and
> returns immediately after doing so.
>
> This kind of programming is a bit nastly though.  Multi-threading or
> using multiple communicating Prolog applications probably gives more
> reliable results.  For example you could use one Prolog process doing
> the server work and control that from another doing the GUI work and
> contacting the server just like to other clients.
>
> Regards --- Jan