summaryrefslogtreecommitdiff
path: root/TAO/tests/AMI_Timeouts/timeout_i.cpp
blob: 85e35ccbf463110bf7f973fbd9348795c8a08045 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO/tests/AMI_Timeouts
//
// = FILENAME
//    server.cpp
//
// = DESCRIPTION
//    Implements the timeout CORBA Object and its reply handler.
//
// = AUTHOR
//    Michael Kircher <Michael.Kircher@mchp.siemens.de>
//
// ============================================================================

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

Timeout_i::Timeout_i (CORBA::ORB_ptr orb)
{
  orb_ = CORBA::ORB::_duplicate (orb);
}

Timeout_i::~Timeout_i ()
{
}

void
Timeout_i::sendTimeToWait (CORBA::Long msec)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  //ACE_DEBUG ((LM_DEBUG,
  //            "Timeout_i::sendTimeToWait: invoked with msec = %d\n\n",
  //            msec));

  if (msec != 0)
    {
      // ACE_DEBUG ((LM_DEBUG,
      //            "Timeout_i::sendTimeToWait: sleeping\n\n"));

      ACE_Time_Value tv (0, msec * 1000);
            ACE_OS::sleep (tv);
    }
}

void
Timeout_i::shutdown (void)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  orb_->shutdown ();
  //ACE_DEBUG ((LM_DEBUG,
  //            "Timeout_i::shutdown: shut down ORB\n\n"));
}

// Reply Handler implementation

TimeoutHandler_i::TimeoutHandler_i ()
: reply_counter_ (0)
, reply_excep_counter_ (0)
{
  timer_.reset ();
  timer_.start ();
  timer_.stop ();
}

TimeoutHandler_i::~TimeoutHandler_i ()
{
}

void
TimeoutHandler_i::sendTimeToWait (void)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_DEBUG ((LM_DEBUG,
              "reply"));
  reply_counter_++;
  timer_.stop ();
}

void
TimeoutHandler_i::sendTimeToWait_excep (::Messaging::ExceptionHolder *excep_holder)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  timer_.stop ();

  try
    {
      excep_holder->raise_exception ();
    }
  catch (const CORBA::TIMEOUT& )
    {
      ACE_DEBUG ((LM_DEBUG,
                  "timeout"));
      reply_excep_counter_++;
    }
  catch (...)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Error: Unexpected exception"));
    }
}

void
TimeoutHandler_i::reset_reply_counter ()
{
  reply_counter_ = 0;
}

void
TimeoutHandler_i::reset_reply_excep_counter ()
{
  reply_excep_counter_ = 0;
}

unsigned short
TimeoutHandler_i::reply_counter ()
{
  return reply_counter_;
}

unsigned short
TimeoutHandler_i::reply_excep_counter ()
{
  return reply_excep_counter_;
}

void
TimeoutHandler_i::start ()
{
  timer_.reset ();
  timer_.start ();
}

ACE_Time_Value &
TimeoutHandler_i::elapsed_time ()
{
  timer_.elapsed_time (elapsed_time_);
  return elapsed_time_;
}