> 1) Is there any way to send multiple parameters using WServer::post()? You can use boost::bind to bind up to 9 arguments.
> 2) How should I use signal/slot from a background boost thread to notify > multiple sessions? Signals and slots in Wt (in contradistinction to Qt) can't cross application boundaries. So signal and slots must be in one application. One application must be managed by one or zero threads at the same time. If you want to notify slots from other thread, you should create a signal in the same application where slots live and emit this signal through WServer::post. Using application lock was previous technique for this, when there were no WServer::post. > 3) Is there any other mechanism I should use to send notifications with > multiple parameters from a polling thread to multiple sessions? I developed signal-free system passing events across Wt sessions. It is part of library wt-classes. http://starius.ru/wt-classes/reference/group__notify.html notify::Server is event server, passing events to all subscribers. notify::Widget is event subscriber. notify::Event is Event. You should inherit from this class to add your own data to the event. Event must provide key() method returning the string to which Widgets subscribe. Steps. 1. Create server-global instance of notify::Server. 2. Create Widgets in sessions. Widget subscribes to particular events (by string key) of the serve in Widget's constructor. 3. In any thread: create instance of Event's descendant. Pass it to server.emit() method. 4. All widgets get this event in their .notify() virtual method in their application content (as if this method was called by e.g. button's clicked signal), which is implemented by you. 5. Updates of user interface are pushed with wApp->triggerUpdate() by notify::Server itself. To disable this, set Server.set_updates_enabled(false). If .emit() was called from the same application where Widget is created, then event is passed through WServer.post. To enable optimization, which passes such events directly by calling widget.notify(event), set server.set_direct_to_this(true). Here is example (not very simple) of using this. Multi-user game rock-paper-scissors, with bots. http://starius.ru/wt-classes/examples/rock-paper-scissors Source: http://starius.ru/wt-classes/reference/examples_2rock-paper-scissors_8cpp-example.html Regards, Nagaev Boris On Thu, Oct 31, 2013 at 2:33 AM, Joe VanAndel <[email protected]> wrote: > My application has background threads that communicate with our weather radar > hardware and need to notify all web sessions of status changes (e.g. the > position of the antenna, the status of the transmitter). > > I have tried using both WServer::post() as well as signal/slot - each has > their advantages and disadvantages. > > Using WServer::post > > I've been using WServer::post(), but the callback function doesn't take any > arguments, so the notified session has to retrieve the status, and then > decode it. Note if I want to send multiple arguments, I have to encode them > into a StatusEvent, and the session needs to decode the StatusEvent. (This > technique was shamelessly borrowed from the Wt simplechat example). > > > =========================== > Using signal and slots > > I have some older code that is using Wt signals and slots. I liked that I > could send multiple parameters to a slot, but the UpdateLock caused me > problems - I needed to run one copy of the hardware polling thread per > session, rather than a single instance. > > > =========================== > Questions: > 1) Is there any way to send multiple parameters using WServer::post()? > > 2) How should I use signal/slot from a background boost thread to notify > multiple sessions? > My current code looks like: > > app = Wt::WApplication::Instance() > Wt::WApplication::UpdateLock lock app->getUpdateLock(); > logSignal_.emit(text); > app->triggerUpdate(); // push the changes to the browser > > Do I need to call logSignal_.emit(text) multiple times, once for each session > that needs to be notified? Or do I need to lock all sessions, before calling > logSignal_.emit(text) ? > > 3) Is there any other mechanism I should use to send notifications with > multiple parameters from a polling thread to multiple sessions? > =========================== > > > FYI, using WServer::post() the sequence of calls is: > > <Session> > statusServer_.registerCallback( > this, wApp->bind( boost::bind( &SystemStatus_UI::statusEventCallback, > this)), ids) > > <background thread>: > StatusServer::postStatusEvent(const StatusEvent &event) > WServer:post(sessionId, callback) > > <Session> > > SystemStatus_UI::statusEventCallback() // called from WServer::post() > > event = statusServer_.getEvent(this) > processStatusEvent(event) > > > > > ------------------------------------------------------------------------------ > Android is increasing in popularity, but the open development platform that > developers love is also attractive to malware creators. Download this white > paper to learn more about secure code signing practices that can help keep > Android apps secure. > http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk > _______________________________________________ > witty-interest mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/witty-interest ------------------------------------------------------------------------------ Android is increasing in popularity, but the open development platform that developers love is also attractive to malware creators. Download this white paper to learn more about secure code signing practices that can help keep Android apps secure. http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk _______________________________________________ witty-interest mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/witty-interest
