PVData C++  8.0.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
timer.h
1 /* timer.h */
2 /*
3  * Copyright information and license terms for this software can be
4  * found in the file LICENSE that is included with the distribution
5  */
9 #ifndef TIMER_H
10 #define TIMER_H
11 #include <memory>
12 #include <list>
13 
14 #include <stddef.h>
15 #include <stdlib.h>
16 #include <stddef.h>
17 #include <string.h>
18 #include <stdio.h>
19 
20 #include <pv/pvType.h>
21 #include <pv/thread.h>
22 #include <pv/timeStamp.h>
23 #include <pv/event.h>
24 #include <pv/lock.h>
25 #include <pv/sharedPtr.h>
26 
27 #include <shareLib.h>
28 
29 namespace epics { namespace pvData {
30 
31 class TimerCallback;
32 class Timer;
33 typedef std::tr1::shared_ptr<TimerCallback> TimerCallbackPtr;
34 typedef std::tr1::shared_ptr<Timer> TimerPtr;
35 
40 class epicsShareClass TimerCallback {
41 public:
42  POINTER_DEFINITIONS(TimerCallback);
46  TimerCallback();
50  virtual ~TimerCallback(){}
54  virtual void callback() = 0;
58  virtual void timerStopped() = 0;
59 private:
60  epicsTime timeToRun;
61  double period;
62  bool onList;
63  friend class Timer;
64  struct IncreasingTime;
65 };
66 
71 class epicsShareClass Timer : private Runnable {
72 public:
73  POINTER_DEFINITIONS(Timer);
78  Timer(std::string threadName, ThreadPriority priority);
79  virtual ~Timer();
81  void close();
87  void scheduleAfterDelay(
88  TimerCallbackPtr const &timerCallback,
89  double delay);
96  void schedulePeriodic(
97  TimerCallbackPtr const &timerCallback,
98  double delay,
99  double period);
105  bool cancel(TimerCallbackPtr const &timerCallback);
111  bool isScheduled(TimerCallbackPtr const &timerCallback) const;
116  void dump(std::ostream& o) const;
117 
118 private:
119  virtual void run();
120 
121  // call with mutex held
122  void addElement(TimerCallbackPtr const &timerCallback);
123 
125 
126  mutable Mutex mutex;
127  queue_t queue;
128  Event waitForWork;
129  bool waiting;
130  bool alive;
131  Thread thread;
132 };
133 
134 epicsShareExtern std::ostream& operator<<(std::ostream& o, const Timer& timer);
135 
136 }}
137 #endif /* TIMER_H */
basic_ostream< _CharT, _Traits > & operator<<(basic_ostream< _CharT, _Traits > &__os, const basic_string< _CharT, _Traits, _Alloc > &__str)
virtual ~TimerCallback()
Definition: timer.h:50
C++ wrapper for epicsEvent from EPICS base.
Definition: event.h:31
Class that must be implemented by code that makes Timer requests.
Definition: timer.h:40
Support for delayed or periodic callback execution.
Definition: timer.h:71
C++ wrapper for epicsThread from EPICS base.
Definition: thread.h:65