summaryrefslogtreecommitdiff
path: root/TAO/tests/Oneway_Send_Timeouts/Test_i.cpp
blob: b472a1f8430a4e1e315fd5833a86d885d37c0aec (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

#include "Test_i.h"

#include "ace/High_Res_Timer.h"
#include "ace/OS_NS_unistd.h"

Test_i::Test_i (CORBA::ORB_ptr orb)
  : sleep_ (false), unsleep_ (true)
  , orb_ (CORBA::ORB::_duplicate (orb))
{ }

Test_i::~Test_i ()
{
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) ~Test_i>\n"));
}

void
Test_i::sleep (CORBA::Long sec, CORBA::Long msec)
  ACE_THROW_SPEC ((::CORBA::SystemException))
{
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test_i::sleep> enter\n"));
  sleep_ = true;
  unsleep_ = false;

  ACE_Time_Value duration (sec);
  duration.msec (msec);

  if (sec == 0 && msec == 0) {
    // 1000 seconds is infinity
    duration.sec (1000);
  }

  ACE_Time_Value current = ACE_High_Res_Timer::gettimeofday_hr ();
  ACE_Time_Value timeout = current + duration;

  ACE_Time_Value sleep_time;
  sleep_time.msec (10);
  while (current < timeout) {
    if (!sleep_) {
      break;
    }
    ACE_OS::sleep (sleep_time);
    current += sleep_time;
  }
  sleep_ = false;
  unsleep_ = true;
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test_i::sleep> exit\n"));
}

void
Test_i::unsleep ()
  ACE_THROW_SPEC ((::CORBA::SystemException))
{
  sleep_ = false;

  ACE_Time_Value sleep_time;
  sleep_time.msec (10);
  while (unsleep_ == false) {
    ACE_OS::sleep (sleep_time);
  }
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test_i::unsleep>\n"));
}

void
Test_i::dummy_one_way (const char* msg)
  ACE_THROW_SPEC ((::CORBA::SystemException))
{
  if (msg != 0) {
    ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test_i::dummy_one_way> %.25s\n", msg));
  }
  // do nothing
}

void
Test_i::dummy_two_way ()
    ACE_THROW_SPEC ((::CORBA::SystemException))
{
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test_i::dummy_two_way>\n"));
}

void
Test_i::shutdown ()
  ACE_THROW_SPEC ((::CORBA::SystemException))
{
  orb_->shutdown (0);
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) Test_i::shutdown>\n"));
}