INTRODUCTION Overview Download and Install Quick Start Documentation Publications NONFRAMEWORK CODE Driver Interfaces Drivers Libraries Utilities FRAMEWORK CODE Interfaces Components Libraries Utilities Full Software Listings DEVELOPER Tutorials Examples Dev Guide Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
hydroiceutil::EventQueue Class ReferenceThread-safe event queue. More...
Detailed DescriptionThread-safe event queue. This class does not execute the events. For an event execution loop see EventLoop. First define some custom events. #include <hydroiceutil/eventqueue.h> enum EventType { Activate }; class ActivateEvent : public hydroiceutil::Event { public: ActivateEvent( bool urgent=false ) : hydroiceutil::Event( Activate ), isUrgent(urgent) {}; bool isUrgent; }; typedef IceUtil::Handle<ActivateEvent> ActivateEventPtr; Your threaded class will have an event queue, probably as a member variable. hydroiceutil::EventQueuePtr events_; Don't forget to initialize it in the constructor events_(new hydroiceutil::EventQueue) When running inside your thread, read from the queue, with or without timeout. Here's an example of doing it inside the run function of gbxiceutilacfr::Thread. void run() { hydroiceutil::EventPtr event; int timeoutMs = 500; while ( !isStopping() ) { if ( !events_->timedGet( event, timeoutMs ) ) { // timed out continue; } switch ( event->type() ) { // approx in order of call frequency case Activate : { ActivateEventPtr e = ActivateEventPtr::dynamicCast( event ); if ( e->isUrgent ) // do something else // don't do anything break; } default : { cout<<"Unknown event "<<event->type()<<". Ignoring..."<<endl; } } // switch } // while } Asynchronously from your main thread loop, you can add events to your queue. void outsideFunctionCall() { events_->add( new ActivateEvent() ); }
Member Function Documentation
Get event from the queue. If the queue is empty this call blocks indefinitely until an event is added.
Add event to the queue but, before the event is added, the queue tries to combine it with the last event already in the queue. This is done by calling combine() function of the queue's optimizer. The default optimizer does not support any combinations. To implement combination(s) for your events, write your own optimizer by deriving from EventQueueOptimizer. Calling this function when the event is empty or when the queue's optimizer is not set or when the combine() operation fails for some reason is equivalent to calling add().
Get event from the queue with timeout. Returns TRUE if event was received, FALSE if timeout occured. References hydroiceutil::now(). The documentation for this class was generated from the following files:
|
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)