FLTK logo

[fltk.general] API access to FLTK app

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

API access to FLTK app Rob McDonald Jan 14, 2022  
  Apologies for a long setup to what may be an elementary question.

My FLTK interactive program also has a C++ API that we use SWIG to generate wrappers to call from Python and other scripting languages.

When launched normally, a small main() handles some command line options, displays the initial windows, and starts the FLTK event loop.

When called from the API (say Python), an instance of the main data structures is loaded into memory, and calls are made from Python as needed -- no event loop.  In fact, we usually use the API from a binary that does not have any GUI, OpenGL, or FLTK code compiled or linked in.

All the complex data 'lives' in the C++ side of things.  We only pass relatively simple data back and forth through the API.  All significant program state remains on the C++ side.

We would like to be able to launch an interactive GUI from Python that allows the user to interact with the program at the same time Python is interacting.  My program is single threaded and was not designed with thread safety in mind.

To do this, I think we need to...

Add a StartGUI() routine to the API that will start a new thread, open the default GUI windows, and start the event loop (basically do what main() does for the interactive program).  The original thread will return control to Python.

Add a lock that prevents truly simultaneous access.  Whenever an event comes in, FLTK must acquire the lock before calling into my code to handle the event.  Once the event is fully handled (and control returns to the event loop), the lock is released.

At the same time, every API call must acquire the lock before doing anything.  The lock will be released when the API call is finished.

Acquiring the lock will be blocking -- whether from the GUI or the API, if the program is busy, you'll see some lag or hesitation.  However, much of the time, you will be able to interact normally with the program.

Is this the right idea?  Do I have a fundamental misunderstanding here?  Can anyone point at an example application that takes this approach?

Thanks in advance for any help,

Rob



--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/58ea8224-20d0-4967-bebb-ee6027586185n%40googlegroups.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.