File: thetimerobjectasio.cc

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 (65 lines) | stat: -rw-r--r-- 1,342 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
59
60
61
62
63
64
65
#include <boost/bind.hpp>
#include "protocoltimerasio.h"
#include "thetimerobjectasio.h"


void TheTimerObjectAsio::timerExpiredEvent(const boost::system::error_code& err)
{
  if (boost::asio::error::operation_aborted==err)
  {
  }
  else
  {
    timerActive=false;
    if (myFunctorPointer)
    {
      (*myFunctorPointer)();
    }
  }
}


TheTimerObjectAsio::TheTimerObjectAsio(boost::asio::io_service & ioservice) : timer(ioservice)
{
  timerActive=false;
  myFunctorPointer=0;
}


TheTimerObjectAsio::~TheTimerObjectAsio()
{
  stop();
}


void TheTimerObjectAsio::startAlarmAt(const boost::posix_time::ptime & time, TimerEventFunctor * functor)
{
  myFunctorPointer=functor;
  timer.expires_at(time);
  timer.async_wait(boost::bind(&TheTimerObjectAsio::timerExpiredEvent, this, boost::asio::placeholders::error));
  timerActive=true;
}


void TheTimerObjectAsio::startAlarmAfter(const boost::posix_time::time_duration & expiry_time, TimerEventFunctor * functor)
{
  myFunctorPointer=functor;
  timer.expires_from_now(expiry_time);
  timer.async_wait(boost::bind(&TheTimerObjectAsio::timerExpiredEvent, this, boost::asio::placeholders::error));
  timerActive=true;
}


void TheTimerObjectAsio::stop()
{
  if (timerActive)
  {
    timer.cancel();
    timerActive=false;
  }
}

bool TheTimerObjectAsio::isRunning()
{
  return timerActive;
}