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
|
eventscheduler.h00001 /* 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_SCHEDULER_H 00012 #define HYDROICEUTIL_EVENT_SCHEDULER_H 00013 00014 #include <gbxutilacfr/tracer.h> 00015 #include <gbxsickacfr/gbxiceutilacfr/thread.h> 00016 #include <hydroiceutil/event.h> 00017 #include <IceUtil/Time.h> 00018 #include <IceUtil/Mutex.h> 00019 #include <map> 00020 00021 namespace hydroiceutil { 00022 00029 class EventScheduler : public gbxiceutilacfr::Thread 00030 { 00031 public: 00033 struct Config 00034 { 00035 Config() : 00036 pollIntervalMs(500), 00037 // lateDispatchToleranceMs(-1), 00038 traceScheduledEvents(false), 00039 traceDispatchedEvents(false) {}; 00040 00042 void validate( gbxutilacfr::Tracer& tracer ); 00043 00046 int pollIntervalMs; 00047 // Issue warning when a scheduled event is dispatched more then @c lateDispatchToleranceMs [ms] 00048 // late. Default is -1 (no warnings); 00049 // int lateDispatchToleranceMs; 00052 bool traceScheduledEvents; 00055 bool traceDispatchedEvents; 00056 }; 00057 00059 EventScheduler( gbxutilacfr::Tracer& tracer, const EventScheduler::Config& config=EventScheduler::Config() ); 00060 00062 void scheduleEvent( EventReceiver& receiver, const EventPtr &event, double delay ); 00063 00066 void scheduleEvent( EventReceiver& receiver, int type, double delay ); 00067 00068 // from Thread 00069 virtual void run(); 00070 00071 private: 00072 // storing absolute time of the scheduled events (so that we don't have to recompute them every time). 00073 // Allow duplicates with multimap in case 2 events happen to be scheduled for the same instant. 00074 struct EventItem 00075 { 00076 EventItem( EventReceiver& r, const EventPtr& e ) : 00077 receiver(r), event(e) {}; 00078 EventReceiver& receiver; 00079 EventPtr event; 00080 }; 00081 typedef std::multimap<IceUtil::Time,EventItem> TimeEventMap; 00082 TimeEventMap schedule_; 00083 IceUtil::Mutex scheduleMutex_; 00084 00085 void dispatchEvents(); 00086 00087 gbxutilacfr::Tracer& tracer_; 00088 Config config_; 00089 }; 00091 typedef IceUtil::Handle<EventScheduler> EventSchedulerPtr; 00092 00093 } // namespace 00094 00095 #endif |
Webmaster: Tobias Kaupp (tobasco at users.sourceforge.net)