|
orca-robotics INTRODUCTION Overview Download and Install Documentation REPOSITORY Interfaces Drivers Libraries Utilities Software Map DEVELOPER Dashboard PEOPLE Contributors Users Project Download Mailing lists
|
hydroiceutil::EventQueue Class ReferenceThread-safe event queue. More...
Detailed DescriptionThread-safe event queue.First define custom events. #include <hydroiceutil/eventqueue.h>
enum EventType { Activate };
class ActivateEvent : public hydroiceutil::Event
{
public:
ActivateEvent() : hydroiceutil::Event( Activate ) {};
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 gbxsickacfr::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
}
Member Function Documentation
The documentation for this class was generated from the following files:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)
1.4.5