Fellow Schemers,
I have 3 event-related needs:
1. I need to push events from C++ to Scheme 2. I need to push events from Scheme to C++ 3. I need to setup timers within Scheme that would also generate events
I could have C++ call a Scheme function and have the Scheme function return data. This would cover 1 and 2 except I would need to pass a list of events back into Scheme.
Sometimes I need to pass events from Scheme to C++ this could be one event or it could be a few.
Last but not least, I need to generate an event (i.e. do something) when a timer expires. All my processing could be done in a blocking fashion if it weren't for timers.
For example, I would set up a timer while waiting for player action and if the timer expired I would assume that the player is dead and fold his cards (this is poker) and force him to leave the game (remove him).
I would also set up a timer after enough players gathered for a game, just to wait and see if someone else would join. If there's still enough players after the timer expires then I would start the game. Otherwise I would go back to waiting for players.
My main loop MUST run in C++ as for my server I'm using a C++ networking library and for my GUI client I'm using SDL which has its own event loop as well.
Something I could do is set up two queues (lists?) in Scheme, one for incoming events and one for outgoing. My scheme code would then run in some sort of a thread, polling the incoming queue and posting events to the outgoing queue. C++ would poll the outgoing queue and post events to the incoming queue via a Scheme call.
Writing Scheme bindings for the networking library and for SDL could be another option but I'd rather try to set up a thin C++ to Scheme interface layer first as it would let me focus on the application logic.
Any suggestions?
Thanks in advance, Joel