File: protocoltimer.h

package info (click to toggle)
sinfo 0.0.48-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,332 kB
  • sloc: sh: 11,213; cpp: 6,722; makefile: 271; xml: 151; perl: 149
file content (58 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef _protocoltimer_h
#define _protocoltimer_h

#include "protocolio.h"
#include "thetimerobjectbase.h"
#include <boost/date_time/posix_time/posix_time.hpp>


/**
* @brief the timer link class to be uses within state machines
*
*/
class ProtocolTimer
{
private:
  TimerEventFunctor * myHandlerBase;
  TheTimerObjectBase * theTimerObjectBase;

public:
  ProtocolTimer(ProtocolIO & protocolIO);
  ~ProtocolTimer();

  template <typename TClass>
  void startAlarmAt(const boost::posix_time::ptime & time, TClass handler)
  {
    if (myHandlerBase)
    {
      delete myHandlerBase;
      myHandlerBase=0;
    }
    myHandlerBase = new TimerEventFunctor(handler);

    theTimerObjectBase->startAlarmAt(time, myHandlerBase);
  }

  template <typename TClass>
  void startAlarmAfter(const boost::posix_time::time_duration & expiry_time, TClass handler)
  {
    if (myHandlerBase)
    {
      delete myHandlerBase;
      myHandlerBase=0;
    }
    myHandlerBase = new TimerEventFunctor(handler);

    theTimerObjectBase->startAlarmAfter(expiry_time, myHandlerBase);
  }

  void stop();

  bool isRunning()
  {
    return theTimerObjectBase->isRunning();
  }
};


#endif // _protocoltimer_h