summaryrefslogtreecommitdiff
path: root/ace/Time_Request_Reply.cpp
blob: 26405d378401bd5d0a71e4da46fef5efbbe6b8b3 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// $Id$

#include "ace/Time_Request_Reply.h"
#include "ace/Log_Msg.h"

ACE_RCSID(ace, Time_Request_Reply, "$Id$")

// Default "do nothing" constructor.

ACE_Time_Request::ACE_Time_Request (void)
{
  ACE_TRACE ("ACE_Time_Request::ACE_Time_Request");
}

// Create a ACE_Time_Request message.

ACE_Time_Request::ACE_Time_Request (ACE_INT32 t, // Type of request.
                                    const ACE_UINT32 time,
                                    ACE_Time_Value *timeout) // Max time waiting for request.
{
  ACE_TRACE ("ACE_Time_Request::ACE_Time_Request");
  this->msg_type (t);

  // If timeout is a NULL pointer, then block forever...
  if (timeout == 0)
    {
      this->transfer_.block_forever_ = 1;
      this->transfer_.sec_timeout_   = 0;
      this->transfer_.usec_timeout_  = 0;
    }
  else // Do a "timed wait."
    {
      this->block_forever (0);
      // Keep track of how long client is willing to wait.
      this->transfer_.sec_timeout_ = timeout->sec ();
      this->transfer_.usec_timeout_ = timeout->usec ();
    }

  // Copy time into request
  this->time_ = this->transfer_.time_ = time;
}

// Initialize length_ in order to avoid problems with byte-ordering
void
ACE_Time_Request::init (void)
{
  ACE_TRACE ("ACE_Time_Request::init");
//  this->length (sizeof this->transfer_);
}

// Get the fixed size of message
ssize_t
ACE_Time_Request::size (void) const
{
  ACE_TRACE ("ACE_Time_Request::size");
  return sizeof (this->transfer_);
}

// = Set/get the type of the message.
ACE_INT32
ACE_Time_Request::msg_type (void) const
{
  ACE_TRACE ("ACE_Time_Request::msg_type");
  return this->transfer_.msg_type_;
}

void
ACE_Time_Request::msg_type (ACE_INT32 t)
{
  ACE_TRACE ("ACE_Time_Request::msg_type");
  this->transfer_.msg_type_ = t;
}

// = Set/get the blocking semantics.
ACE_UINT32
ACE_Time_Request::block_forever (void) const
{
  ACE_TRACE ("ACE_Time_Request::block_forever");
  return this->transfer_.block_forever_;
}

void
ACE_Time_Request::block_forever (ACE_UINT32 bs)
{
  ACE_TRACE ("ACE_Time_Request::block_forever");
  this->transfer_.block_forever_ = bs;
}

// = Set/get the timeout.
ACE_Time_Value
ACE_Time_Request::timeout (void) const
{
  ACE_TRACE ("ACE_Time_Request::timeout");
  return ACE_Time_Value (this->transfer_.sec_timeout_, this->transfer_.usec_timeout_);
}

void
ACE_Time_Request::timeout (const ACE_Time_Value timeout)
{
  ACE_TRACE ("ACE_Time_Request::timeout");
  this->transfer_.sec_timeout_  = timeout.sec ();
  this->transfer_.usec_timeout_ = timeout.usec ();
}

// = Set/get the time
ACE_UINT32
ACE_Time_Request::time (void) const
{
  ACE_TRACE ("ACE_Time_Request::time");
  return this->time_;
}

void
ACE_Time_Request::time (ACE_UINT32 t)
{
  ACE_TRACE ("ACE_Time_Request::time");
  this->time_ = t;
}

// Encode the transfer buffer into network byte order
// so that it can be sent to the server.
int
ACE_Time_Request::encode (void *&buf)
{
  ACE_TRACE ("ACE_Time_Request::encode");
  // Compute the length *before* doing the marshaling.

  buf = (void *) &this->transfer_;
  this->transfer_.block_forever_ = htonl (this->transfer_.block_forever_);
  this->transfer_.usec_timeout_  = htonl (this->transfer_.usec_timeout_);
  this->transfer_.sec_timeout_   = htonl (this->transfer_.sec_timeout_);
  this->transfer_.msg_type_      = htonl (this->transfer_.msg_type_);
  this->transfer_.time_          = htonl (this->transfer_.time_);

  return this->size ();  // Always fixed
}

// Decode the transfer buffer into host byte byte order
// so that it can be used by the server.
int
ACE_Time_Request::decode (void)
{
  ACE_TRACE ("ACE_Time_Request::decode");
  // Decode
  this->transfer_.block_forever_ = ntohl (this->transfer_.block_forever_);
  this->transfer_.usec_timeout_  = ntohl (this->transfer_.usec_timeout_);
  this->transfer_.sec_timeout_   = ntohl (this->transfer_.sec_timeout_);
  this->transfer_.msg_type_      = ntohl (this->transfer_.msg_type_);
  this->transfer_.time_          = ntohl (this->transfer_.time_);

  this->time_ = this->transfer_.time_;
  return 0;
}

// Print out the current values of the ACE_Time_Request.

void
ACE_Time_Request::dump (void) const
{
  ACE_TRACE ("ACE_Time_Request::dump");
  ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("*******\nlength = %d\n"),
              this->size ()));
  ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("message-type = ")));

  switch (this->msg_type ())
    {
    case ACE_Time_Request::TIME_UPDATE:
      ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("TIME_UPDATE\n")));
      break;
    default:
      ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("<unknown type> = %d\n"), this->msg_type ()));
      break;
    }

  if (this->block_forever ())
    ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("blocking forever\n")));
  else
    {
#if !defined (ACE_NLOGGING)
      ACE_Time_Value tv = this->timeout ();
#endif /* ! ACE_NLOGGING */
      ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("waiting for %d secs and %d usecs\n"),
                  tv.sec (), tv.usec ()));
    }
  ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("*******\ntime = %d\n"),
              this->time ()));
  ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("+++++++\n")));
}