#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/OS/Threads/Tools/TickerTrigger.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2001, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVL_THREADLAUNCH_HEADER #define RAVL_THREADLAUNCH_HEADER 1 //////////////////////////////////////////////////////// //! rcsid="$Id: TickerTrigger.hh,v 1.3 2002/03/07 13:50:23 craftit Exp $" //! file="Ravl/OS/Threads/Tools/TickerTrigger.hh" //! lib=RavlThreads //! userlevel=Default //! docentry="Ravl.OS.Time" //! author="Charles Galambos" //! date="02/07/1999" #include "Ravl/OS/Date.hh" #include "Ravl/Threads/Thread.hh" #include "Ravl/Calls.hh" #include "Ravl/CallMethods.hh" namespace RavlN { //! userlevel=Develop //: Ticker body. // This class triggers a method at repeatedly with a fixed delay between calls. class TickerTriggerBodyC : public ThreadBodyC { public: TickerTriggerBodyC(RealT ndelay,const TriggerC &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; TriggerC se; }; //! userlevel=Normal //: Ticker handle. // This class triggers a method at repeatedly with a fixed delay between calls. class TickerTriggerC : public ThreadC { public: TickerTriggerC() {} //: Default constructor. TickerTriggerC(RealT ndelay,const TriggerC &nse) : ThreadC(*new TickerTriggerBodyC(ndelay,nse)) { Execute(); } //: Constructor. protected: TickerTriggerBodyC &Body() { return static_cast(ThreadC::Body()); } //: Access body. const TickerTriggerBodyC &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 TickerTrigger(RealT ndelay,const TriggerC &nse) { return TickerTriggerC(ndelay,nse); } inline ThreadC TickerTrigger(RealT ndelay,bool (*nFunc)()) { return TickerTriggerC(ndelay,Trigger(nFunc)); } template ThreadC TickerTrigger(RealT ndelay,bool (*nFunc)(DataT &dat),const DataT &dat) { return TickerTriggerC(ndelay,Trigger(nFunc,dat)); } template ThreadC TickerTrigger(RealT ndelay,const ObjT &nObj,bool (ObjT::*nFunc)()) { return TickerTriggerC(ndelay,Trigger(nObj,nFunc)); } template ThreadC TickerTrigger(RealT ndelay,const ObjT &nObj,bool (ObjT::*nFunc)(DataT &),const DataT &nDat) { return TickerTriggerC(ndelay,Trigger(nObj,nFunc,nDat)); } template ThreadC TickerTrigger(RealT ndelay,const ObjT &nObj,bool (ObjT::*nFunc)(Data1T &,Data2T &),const Data1T &nDat1,const Data2T &nDat2) { return TickerTriggerC(ndelay,Trigger(nObj,nFunc,nDat1,nDat2)); } } #endif