This is Unofficial EPICS BASE Doxygen Site
timer.h
Go to the documentation of this file.
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 
41 public:
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:
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 
124  typedef std::list<TimerCallbackPtr> queue_t;
125 
126  mutable Mutex mutex;
127  queue_t queue;
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 */
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
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
Mark external symbols and entry points for shared libraries.
std::ostream & operator<<(std::ostream &o, const Field &f)
Support for delayed or periodic callback execution.
Definition: timer.h:71
#define epicsShareExtern
Definition: shareLib.h:204
virtual ~TimerCallback()
Definition: timer.h:50
#define POINTER_DEFINITIONS(clazz)
Definition: sharedPtr.h:198
epicsMutex mutex
Definition: pvAccess.cpp:71
std::tr1::shared_ptr< TimerCallback > TimerCallbackPtr
Definition: timer.h:32
Definition: caget.c:48
#define epicsShareClass
Definition: shareLib.h:206
epicsEventId waitForWork
Definition: errlog.c:66
std::tr1::shared_ptr< Timer > TimerPtr
Definition: timer.h:34
C++ wrapper for epicsThread from EPICS base.
Definition: thread.h:65
epicsMutex Mutex
Definition: lock.h:28
epicsThreadRunable Runnable
Definition: thread.h:43