/* timer.h */ /** * Copyright - See the COPYRIGHT that is included with this distribution. * EPICS pvData is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ /** * @author mrk */ #ifndef TIMER_H #define TIMER_H #include #include #include #include #include #include #include #include #include #include #include #include namespace epics { namespace pvData { class TimerCallback; class Timer; typedef std::tr1::shared_ptr TimerCallbackPtr; typedef std::tr1::shared_ptr TimerPtr; class TimerCallback { public: POINTER_DEFINITIONS(TimerCallback); TimerCallback(); virtual ~TimerCallback(){} virtual void callback() = 0; virtual void timerStopped() = 0; private: TimerCallbackPtr next; TimeStamp timeToRun; double period; bool onList; friend class Timer; }; class Timer : public Runnable { public: POINTER_DEFINITIONS(Timer); Timer(String threadName, ThreadPriority priority); virtual ~Timer(); virtual void run(); void scheduleAfterDelay( TimerCallbackPtr const &timerCallback, double delay); void schedulePeriodic( TimerCallbackPtr const &timerCallback, double delay, double period); void cancel(TimerCallbackPtr const &timerCallback); bool isScheduled(TimerCallbackPtr const &timerCallback); void toString(StringBuilder builder); private: void addElement(TimerCallbackPtr const &timerCallback); TimerCallbackPtr head; Mutex mutex; Event waitForWork; Event waitForDone; bool alive; Thread thread; }; }} #endif /* TIMER_H */