Timer.h

Go to the documentation of this file.
00001 #ifndef __TIMER_H__
00002 #define __TIMER_H__
00003 
00004 /*
00005 
00006 $Header$
00007 
00008 */
00009 
00010 #include <vector>
00011 #include <set>
00012 
00013 #include <sys/time.h>
00014 
00015 #include "Object.h"
00016 #include "Signal.h"
00017 
00018 // Messages.
00019 static const char *const MSG_TIMER_CANNOT_GET_TIME = "Cannot get current time (%s).";
00020 
00021 using namespace std;
00022 
00023 class Core;
00024 
00025 class Timer : public Object
00026 {
00027 
00028 friend class Core;
00029 
00030   PYLON_OBJECT
00031 
00032 public:
00033 
00034   Timer(const unsigned int msTime, const bool periodical = true);
00035   virtual ~Timer();
00036 
00037   int setPeriodical(const bool yes = true);
00038   bool periodical() const;
00039 
00040   int setTime(const unsigned int msTime);
00041   unsigned int time() const;
00042 
00043   static int singleShot(const unsigned int msTime, Object *slotObject, SlotMethod slotMethod);
00044 
00045   virtual int suspend();
00046   virtual int resume();
00047 
00048   unsigned int sinceShot() const;
00049   unsigned int tillShot() const;
00050   bool ready() const;
00051 
00052   static int list(String &text);
00053   static int listSingleShot(String &text);
00054 
00055   // Signals.
00056   SIGNAL(suspended);
00057   SIGNAL(resumed);
00058   SIGNAL(shot);
00059 
00060 private:
00061 
00062   typedef struct
00063   {
00064     unsigned int msTime;
00065     ObjectId slotObjectId;
00066     SlotMethod slotMethod;
00067     struct timeval firedTimestamp;
00068   } SingleShot;
00069   typedef vector<SingleShot> SingleShotList;
00070 
00071   typedef set<Timer *> TimerList;
00072 
00073   int shoot();
00074   static int singleShoot();
00075   static unsigned int since(const struct timeval &timestamp);
00076 
00077   static int shootTimers();
00078 
00079   bool _periodical;
00080   unsigned int _msTime;
00081   struct timeval _lastShotTimestamp;
00082 
00083   static SingleShotList _singleShots;
00084 
00085   static TimerList _timers;
00086 };
00087 
00088 inline
00089 String TIMER_COLOR_TITLE(const String &str)
00090 {
00091   return COLOR_STRING(str, LIGHT_CYAN, NONE);
00092 }
00093 
00094 #endif

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1