#1 2017-12-25 21:39:34

Leslie7
Member
Registered: 2015-06-25
Posts: 248

Interface callback synchronization

Hi,

I have created a LAMW android chat client for testing the websocket connection  with the  Project31 chat server. The websocket part is working well smile, but I could not find any info on how to synchronize my code in NotifyBlaBla with the main thread in a GUI (none console) client.

Last edited by Leslie7 (2017-12-25 22:22:57)

Offline

#2 2017-12-26 08:50:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,242
Website

Re: Interface callback synchronization

There is only a VCL version available yet.

But the easiest is to send a FMX message with the text, in a similar way, on the android client.

Offline

#3 2017-12-26 09:31:35

Leslie7
Member
Registered: 2015-06-25
Posts: 248

Re: Interface callback synchronization

ab,

wow, you are present on the forum even today ... smile

LAMW is for Lazarus. It creates  a CustomApplication  which uses native controls via JNI to build the GUI.  The pascal code is compiled into ".so",  so anything that works for linux  may be working here as well.

I can see a  few possible general solutions:

1. Creating a thread for the sole purpose of passing the callback messages to the main thread. (eg a synchronized calling of a function of the form) .
2. Creating the websocket client in the context of a thread instead of the main thread.  - Is this a good idea for bidir communication?
3. Msg for the main window proc - not sure, this is a real option with LAMW

Last edited by Leslie7 (2017-12-26 09:32:04)

Offline

#4 2017-12-26 10:21:00

AOG
Member
Registered: 2014-02-24
Posts: 490

Re: Interface callback synchronization

If you are able to share your code somewhere, I can have a look also.

Offline

#5 2017-12-26 16:59:09

Leslie7
Member
Registered: 2015-06-25
Posts: 248

Re: Interface callback synchronization

AOG

I am trying out a few things. I will definitely ask for your help if I cannot get it working.

Thanks smile

Offline

#6 2017-12-26 23:06:58

Leslie7
Member
Registered: 2015-06-25
Posts: 248

Re: Interface callback synchronization

There is a simple workaround but it is not optimal:

1. we need a thread safe temporary storage
2. where the messages are stored by the callback method
3. a jTimer instance periodically checks if there are new stored messages and clears the temporary storage after the messages are displayed

Since LAMW does not have message handling on the pascal side probably the only way to do this properly is to go to the Java side  first via JNI  and call back to the pascal side in a synchronized fashion.

Offline

Board footer

Powered by FluxBB