Update NEWS
[ACE_TAO.git] / ACE / netsvcs / lib / Time_Request_Reply.cpp
blobf23cc9d1b7a7b61a2c3ad432ec8c8cf56437e521
1 #include "ace/Basic_Types.h"
2 #include "ace/CDR_Base.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/Truncate.h"
5 #include "ace/os_include/netinet/os_in.h"
6 #include "ace/os_include/arpa/os_inet.h"
8 #include "Time_Request_Reply.h"
10 // Default "do nothing" constructor.
11 ACE_Time_Request::ACE_Time_Request (void)
13 ACE_TRACE ("ACE_Time_Request::ACE_Time_Request");
16 // Create a ACE_Time_Request message.
17 ACE_Time_Request::ACE_Time_Request (ACE_INT32 t, // Type of request.
18 const time_t time,
19 ACE_Time_Value *timeout) // Max time waiting for request.
21 ACE_TRACE ("ACE_Time_Request::ACE_Time_Request");
22 this->msg_type (t);
24 // If timeout is a NULL pointer, then block forever...
25 if (timeout == 0)
27 this->transfer_.block_forever_ = 1;
28 this->transfer_.sec_timeout_ = 0;
29 this->transfer_.usec_timeout_ = 0;
31 else // Do a "timed wait."
33 this->block_forever (0);
34 // Keep track of how long client is willing to wait.
35 this->transfer_.sec_timeout_ = timeout->sec ();
36 this->transfer_.usec_timeout_ = timeout->usec ();
39 // Copy time into request
40 this->transfer_.time_ = this->time_ = time;
43 // Get the fixed size of message
44 ssize_t
45 ACE_Time_Request::size (void) const
47 ACE_TRACE ("ACE_Time_Request::size");
48 return sizeof (this->transfer_);
51 // = Set/get the type of the message.
52 ACE_INT32
53 ACE_Time_Request::msg_type (void) const
55 ACE_TRACE ("ACE_Time_Request::msg_type");
56 return this->transfer_.msg_type_;
59 void
60 ACE_Time_Request::msg_type (ACE_INT32 t)
62 ACE_TRACE ("ACE_Time_Request::msg_type");
63 this->transfer_.msg_type_ = t;
66 // = Set/get the blocking semantics.
67 ACE_UINT32
68 ACE_Time_Request::block_forever (void) const
70 ACE_TRACE ("ACE_Time_Request::block_forever");
71 return this->transfer_.block_forever_;
74 void
75 ACE_Time_Request::block_forever (ACE_UINT32 bs)
77 ACE_TRACE ("ACE_Time_Request::block_forever");
78 this->transfer_.block_forever_ = bs;
81 // = Set/get the timeout.
82 ACE_Time_Value
83 ACE_Time_Request::timeout (void) const
85 ACE_TRACE ("ACE_Time_Request::timeout");
86 time_t sec = ACE_Utils::truncate_cast<time_t> (this->transfer_.sec_timeout_);
87 return ACE_Time_Value (sec, this->transfer_.usec_timeout_);
90 void
91 ACE_Time_Request::timeout (const ACE_Time_Value& timeout)
93 ACE_TRACE ("ACE_Time_Request::timeout");
94 this->transfer_.sec_timeout_ = timeout.sec ();
95 this->transfer_.usec_timeout_ = timeout.usec ();
98 // = Set/get the time
99 time_t
100 ACE_Time_Request::time (void) const
102 ACE_TRACE ("ACE_Time_Request::time");
103 return this->time_;
106 void
107 ACE_Time_Request::time (time_t t)
109 ACE_TRACE ("ACE_Time_Request::time");
110 this->time_ = t;
113 // Encode the transfer buffer into network byte order
114 // so that it can be sent to the server.
116 ACE_Time_Request::encode (void *&buf)
118 ACE_TRACE ("ACE_Time_Request::encode");
119 // Compute the length *before* doing the marshaling.
121 buf = (void *) &this->transfer_;
122 this->transfer_.block_forever_ = ACE_HTONL (this->transfer_.block_forever_);
123 this->transfer_.usec_timeout_ = ACE_HTONL (this->transfer_.usec_timeout_);
124 this->transfer_.msg_type_ = ACE_HTONL (this->transfer_.msg_type_);
125 #if defined (ACE_LITTLE_ENDIAN)
126 ACE_UINT64 secs = this->transfer_.sec_timeout_;
127 ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.sec_timeout_);
128 secs = this->transfer_.time_;
129 ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.time_);
130 #endif
132 return this->size (); // Always fixed
135 // Decode the transfer buffer into host byte byte order
136 // so that it can be used by the server.
138 ACE_Time_Request::decode (void)
140 ACE_TRACE ("ACE_Time_Request::decode");
141 // Decode
142 this->transfer_.block_forever_ = ACE_NTOHL (this->transfer_.block_forever_);
143 this->transfer_.usec_timeout_ = ACE_NTOHL (this->transfer_.usec_timeout_);
144 this->transfer_.msg_type_ = ACE_NTOHL (this->transfer_.msg_type_);
145 #if defined (ACE_LITTLE_ENDIAN)
146 ACE_UINT64 secs = this->transfer_.sec_timeout_;
147 ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.sec_timeout_);
148 secs = this->transfer_.time_;
149 ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.time_);
150 #endif
152 this->time_ = ACE_Utils::truncate_cast<time_t> (this->transfer_.time_);
153 return 0;
156 // Print out the current values of the ACE_Time_Request.
158 void
159 ACE_Time_Request::dump (void) const
161 #if defined (ACE_HAS_DUMP)
162 ACE_TRACE ("ACE_Time_Request::dump");
163 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("*******\nlength = %d\n"),
164 this->size ()));
165 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("message-type = ")));
167 switch (this->msg_type ())
169 case ACE_Time_Request::TIME_UPDATE:
170 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TIME_UPDATE\n")));
171 break;
172 default:
173 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("<unknown type> = %d\n"), this->msg_type ()));
174 break;
177 if (this->block_forever ())
178 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("blocking forever\n")));
179 else
181 #if !defined (ACE_NLOGGING)
182 ACE_Time_Value tv = this->timeout ();
183 #endif /* ! ACE_NLOGGING */
184 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("waiting for %d secs and %d usecs\n"),
185 (int)(tv.sec ()), tv.usec ()));
187 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("*******\ntime = %d\n"),
188 (int)(this->time ())));
189 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("+++++++\n")));
190 #endif /* ACE_HAS_DUMP */