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

SourceForge.net Logo
Project
Download
Mailing lists

 

         

eventqueue.h

00001 /*
00002  * Orca-Robotics Project: Components for robotics 
00003  *               http://orca-robotics.sf.net/
00004  * Copyright (c) 2004-2009 Alex Brooks, Alexei Makarenko, Tobias Kaupp
00005  *
00006  * This distribution is licensed to you under the terms described in
00007  * the LICENSE file included in this distribution.
00008  *
00009  */
00010 
00011 #ifndef HYDROICEUTIL_EVENT_QUEUE_H
00012 #define HYDROICEUTIL_EVENT_QUEUE_H
00013 
00014 #include <list>
00015 #include <IceUtil/Monitor.h>
00016 #include <IceUtil/Mutex.h>
00017 #include <IceUtil/Handle.h>
00018 #include <IceUtil/Shared.h>
00019 #include <hydroiceutil/event.h>
00020 
00021 namespace hydroiceutil
00022 {
00023 
00024 class EventQueueOptimizer : public IceUtil::Shared
00025 {
00026 public:
00033     virtual bool combine( EventPtr& existing, const EventPtr& extra ) { return false; };
00034 };
00035 
00037 typedef IceUtil::Handle<EventQueueOptimizer> EventQueueOptimizerPtr;
00038 
00116 class EventQueue : public IceUtil::Shared, public IceUtil::Monitor<IceUtil::Mutex>
00117 {
00118 public:
00120     EventQueue( bool traceAddEvents=false, bool traceGetEvents=false );
00121 
00123     void setOptimizer( EventQueueOptimizerPtr optimizer );
00124 
00126     void add( const EventPtr& e );
00127 
00129     void add( int type );
00130 
00138     void optimizedAdd( const EventPtr& e );
00139 
00142     void get( EventPtr& e );
00143 
00146     bool timedGet( EventPtr& e, int timeoutMs );
00147 
00149     void clear();
00150 
00152     int size() const;
00153 
00154 private:
00155     std::list<EventPtr> events_;
00156     EventQueueOptimizerPtr optimizer_;
00157     bool traceAddEvents_;
00158     bool traceGetEvents_;
00159 };
00161 typedef IceUtil::Handle<EventQueue> EventQueuePtr;
00162 
00168 class EventQueueHolder : public IceUtil::Shared
00169 {
00170 public:
00171     virtual ~EventQueueHolder() {};
00179     virtual void postEvent( const EventPtr& e )=0;
00180 
00182     // implementation note:
00183     // I'd prefer to make this function polymorphic, postEvent(int), but ...
00184     // it will be hidden by the derived class's implementation of postEvent(const EventPtr&)
00185     // see http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9
00186     // It could be "unhidden" with 'using' in the derived class, but this is super ugly.
00187     //      using hydroiceutil::EventQueueHolder::postEvent;
00188     virtual void postEventWithType( int type ) { postEvent( new hydroiceutil::Event(type) ); };
00189 };
00191 typedef IceUtil::Handle<EventQueueHolder> EventQueueHolderPtr;
00192 
00193 } // namespace
00194 
00195 #endif
 

Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)


Generated for Orca Robotics by  doxygen 1.4.5