summaryrefslogtreecommitdiff
path: root/ACE/examples/APG/Timers/CB.cpp
blob: 0e4c352e12e33d29c4e61cbb7e08a6defdeff64c (plain)
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
66
67
68
69
70
// $Id$

#include "ace/Log_Msg.h"
#include "CB.h"
#include "TimerDispatcher.h"

CB::CB () : count_(0)
{
  ACE_TRACE ("CB::CB");
}

// Listing 1 code/ch20
int CB::handle_timeout (const ACE_Time_Value &,
                        const void *arg)
{
  ACE_TRACE ("CB::handle_timeout");

  const int *val = static_cast<const int*> (arg);
  ACE_ASSERT ((*val) == timerID_);

  ACE_UNUSED_ARG (val);

  if (count_ == 5)
    {
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("Reseting interval for timer %d\n"),
                  timerID_));

      // New interval is 10 ms.
      ACE_Time_Value interval (0L, 1000L);
      int status = Timer::instance ()->reset_interval
                                         (timerID_, interval);
#if defined (ACE_NDEBUG)
      ACE_UNUSED_ARG (status);
#else
      ACE_ASSERT (status != -1);
#endif
    }

  if (count_++ == 10)
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Canceling %d\n"),
                  timerID_));
      ACE_ASSERT ((Timer::instance ()->cancel (this)) != 0);
    }

  return 0;
}
// Listing 1

void
CB::setID (long timerID)
{
  ACE_TRACE ("CB::setID");
  timerID_ = timerID;
}

long
CB::getID (void)
{
  ACE_TRACE ("CB::getID");
  return timerID_;
}

int
CB::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
{
  ACE_TRACE ("CB::handle_close");
  return 0;
}