#ifndef DPTHREADLAUNCH_HEADER #define DPTHREADLAUNCH_HEADER 1 //////////////////////////////////////////////////////// //! rcsid="$Id: Ticker.hh,v 1.6 2000/10/04 12:45:14 ees1cg Exp $" //! file="amma/StdType/System/PThreads/Tools/Ticker.hh" //! lib=PThreadTools //! userlevel=Default //! docentry="default.Charles Galambos" //! author="Charles Galambos" //! date="02/07/99" #include "amma/Date.hh" #include "amma/PThread/EventHandler.hh" #include "amma/PThread/Thread.hh" namespace PThread { //! userlevel=Develop //: Ticker event body. class TickerEventBodyC : public ThreadBodyC { public: TickerEventBodyC(RealT ndelay,const SignalEventC &nse) : delay(ndelay), se(nse) {} //: Let rip ! virtual int Start(); //: Called on startup. void SendTerminate() { delay = -1; } //: Set terminate. // Obsolete use Shutdown() void Shutdown() { delay = -1; } //: Shutdown ticker. protected: RealT delay; DateC next; SignalEventC se; }; //! userlevel=Normal //: Ticker event handle. class TickerEventC : public ThreadC { public: TickerEventC() {} //: Default constructor. TickerEventC(RealT ndelay,const SignalEventC &nse) : ThreadC(*new TickerEventBodyC(ndelay,nse)) { Execute(); } //: Constructor. protected: TickerEventBodyC &Body() { return static_cast(ThreadC::Body()); } //: Access body. const TickerEventBodyC &Body() const { return static_cast(ThreadC::Body()); } //: Access body. public: void SendTerminate() { Body().SendTerminate(); } //: Send terminate. // Obsolete use Shutdown() void Shutdown() { Body().SendTerminate(); } //: Send terminate. }; //////////////////////////////////////////////////////////////// inline ThreadC Ticker(RealT ndelay,const SignalEventC &nse) { return TickerEventC(ndelay,nse); } inline ThreadC Ticker(RealT ndelay,void (*nFunc)()) { return TickerEventC(ndelay,SignalEvent(nFunc)); } template ThreadC Ticker(RealT ndelay,void (*nFunc)(DataT &dat),const DataT &dat) { return TickerEventC(ndelay,SignalEvent(nFunc,dat)); } template ThreadC Ticker(RealT ndelay,const ObjT &nObj,void (ObjT::*nFunc)()) { return TickerEventC(ndelay,SignalEvent(nObj,nFunc)); } template ThreadC Ticker(RealT ndelay,const ObjT &nObj,void (ObjT::*nFunc)(DataT &),const DataT &nDat) { return TickerEventC(ndelay,SignalEvent(nObj,nFunc,nDat)); } template ThreadC Ticker(RealT ndelay,const ObjT &nObj,void (ObjT::*nFunc)(Data1T &,Data2T &),const Data1T &nDat1,const Data2T &nDat2) { return TickerEventC(ndelay,SignalEvent(nObj,nFunc,nDat1,nDat2)); } } #endif