PVData C++ 8.0.7
Loading...
Searching...
No Matches
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
29namespace epics { namespace pvData {
30
31class TimerCallback;
32class Timer;
33typedef std::tr1::shared_ptr<TimerCallback> TimerCallbackPtr;
34typedef std::tr1::shared_ptr<Timer> TimerPtr;
35
40class epicsShareClass TimerCallback {
41public:
42 POINTER_DEFINITIONS(TimerCallback);
50 virtual ~TimerCallback(){}
54 virtual void callback() = 0;
58 virtual void timerStopped() = 0;
59private:
60 epicsTime timeToRun;
61 double period;
62 bool onList;
63 bool cancelled;
64 bool processing;
65 friend class Timer;
66 struct IncreasingTime;
67};
68
73class epicsShareClass Timer : private Runnable {
74public:
75 POINTER_DEFINITIONS(Timer);
80 Timer(std::string threadName, ThreadPriority priority);
81 virtual ~Timer();
83 void close();
90 TimerCallbackPtr const &timerCallback,
91 double delay);
99 TimerCallbackPtr const &timerCallback,
100 double delay,
101 double period);
107 bool cancel(TimerCallbackPtr const &timerCallback);
113 bool isScheduled(TimerCallbackPtr const &timerCallback) const;
118 void dump(std::ostream& o) const;
119
120private:
121 virtual void run();
122
123 // call with mutex held
124 void addElement(TimerCallbackPtr const &timerCallback);
125
127
128 mutable Mutex mutex;
129 queue_t queue;
130 Event waitForWork;
131 bool waiting;
132 bool alive;
133 Thread thread;
134};
135
136epicsShareExtern std::ostream& operator<<(std::ostream& o, const Timer& timer);
137
138}}
139#endif /* TIMER_H */
basic_ostream< _CharT, _Traits > & operator<<(basic_ostream< _CharT, _Traits > &__os, const basic_string< _CharT, _Traits, _Alloc > &__str)
C++ wrapper for epicsEvent from EPICS base.
Definition event.h:31
C++ wrapper for epicsThread from EPICS base.
Definition thread.h:65
Class that must be implemented by code that makes Timer requests.
Definition timer.h:40
virtual void timerStopped()=0
Support for delayed or periodic callback execution.
Definition timer.h:73
void dump(std::ostream &o) const
void close()
Prevent new callbacks from being scheduled, and cancel pending callbacks.
bool cancel(TimerCallbackPtr const &timerCallback)
void schedulePeriodic(TimerCallbackPtr const &timerCallback, double delay, double period)
Timer(std::string threadName, ThreadPriority priority)
bool isScheduled(TimerCallbackPtr const &timerCallback) const
void scheduleAfterDelay(TimerCallbackPtr const &timerCallback, double delay)
epics
Definition convert.h:21