Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Name_Request_Reply.cpp
blobbef296599a25617cf50e4ab99cf4c0d25e7fbc96
1 #include "ace/Name_Request_Reply.h"
2 #include "ace/Basic_Types.h"
3 #include "ace/CDR_Base.h"
4 #include "ace/Log_Category.h"
5 #include "ace/Time_Value.h"
6 #include "ace/Truncate.h"
7 #include "ace/OS_NS_string.h"
8 #include "ace/os_include/arpa/os_inet.h"
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
12 // Default "do nothing" constructor.
13 ACE_Name_Request::ACE_Name_Request ()
15 ACE_TRACE ("ACE_Name_Request::ACE_Name_Request");
18 // Create a ACE_Name_Request message.
19 ACE_Name_Request::ACE_Name_Request (
20 ACE_INT32 t, // Type of request.
21 const ACE_WCHAR_T name[], // Name
22 const ACE_UINT32 name_length, // size in bytes
23 const ACE_WCHAR_T value[], //
24 const ACE_UINT32 value_length, // size in bytes
25 const char type[], //
26 const ACE_UINT32 type_length, // size in bytes
27 ACE_Time_Value *timeout) // Max time waiting for request.
29 ACE_TRACE ("ACE_Name_Request::ACE_Name_Request");
30 this->msg_type (t);
31 this->name_len (name_length);
32 this->value_len (value_length);
33 this->type_len (type_length);
35 // If timeout is a NULL pointer, then block forever...
36 if (timeout == 0)
38 this->transfer_.block_forever_ = 1;
39 this->transfer_.sec_timeout_ = 0;
40 this->transfer_.usec_timeout_ = 0;
42 else // Do a "timed wait."
44 this->block_forever (0);
45 // Keep track of how long client is willing to wait.
46 this->transfer_.sec_timeout_ = timeout->sec ();
47 this->transfer_.usec_timeout_ =
48 static_cast<ACE_UINT32> (timeout->usec ());
51 // Set up pointers and copy name value and type into request.
52 this->name_ = this->transfer_.data_;
53 this->value_ = &this->name_[name_length / sizeof (ACE_WCHAR_T) ];
54 this->type_ = (char *)(&this->value_[value_length / sizeof (ACE_WCHAR_T)]); //
56 (void) ACE_OS::memcpy (this->name_,
57 name,
58 name_length);
59 (void) ACE_OS::memcpy (this->value_,
60 value,
61 value_length);
62 (void) ACE_OS::memcpy (this->type_,
63 type,
64 type_length);
66 // Compute size of the fixed portion of the message...
67 size_t len = sizeof this->transfer_ - sizeof this->transfer_.data_;
69 // ... then add in the amount of the variable-sized portion.
70 len += name_length + value_length + type_length ;
72 this->length (static_cast<ACE_UINT32> (len));
75 // Initialize length_ in order to avoid problems with byte-ordering.
77 void
78 ACE_Name_Request::init ()
80 ACE_TRACE ("ACE_Name_Request::init");
81 this->length (sizeof this->transfer_);
84 // = Set/get the length of the encoded/decoded message.
86 ACE_UINT32
87 ACE_Name_Request::length () const
89 ACE_TRACE ("ACE_Name_Request::length");
90 return this->transfer_.length_;
93 void
94 ACE_Name_Request::length (ACE_UINT32 l)
96 ACE_TRACE ("ACE_Name_Request::length");
97 this->transfer_.length_ = l;
100 // = Set/get the type of the message.
102 ACE_INT32
103 ACE_Name_Request::msg_type () const
105 ACE_TRACE ("ACE_Name_Request::msg_type");
106 return this->transfer_.msg_type_;
109 void
110 ACE_Name_Request::msg_type (ACE_INT32 t)
112 ACE_TRACE ("ACE_Name_Request::msg_type");
113 this->transfer_.msg_type_ = t;
116 // = Set/get the len of the name
118 ACE_UINT32
119 ACE_Name_Request::name_len () const
121 ACE_TRACE ("ACE_Name_Request::name_len");
122 return this->transfer_.name_len_;
125 void
126 ACE_Name_Request::name_len (ACE_UINT32 t)
128 ACE_TRACE ("ACE_Name_Request::name_len");
129 this->transfer_.name_len_ = t;
132 // = Set/get the len of the value
134 ACE_UINT32
135 ACE_Name_Request::value_len () const
137 ACE_TRACE ("ACE_Name_Request::value_len");
138 return this->transfer_.value_len_;
141 void
142 ACE_Name_Request::value_len (ACE_UINT32 t)
144 ACE_TRACE ("ACE_Name_Request::value_len");
145 this->transfer_.value_len_ = t;
148 // = Set/get the len of the type
150 ACE_UINT32
151 ACE_Name_Request::type_len () const
153 ACE_TRACE ("ACE_Name_Request::type_len");
154 return this->transfer_.type_len_;
157 void
158 ACE_Name_Request::type_len (ACE_UINT32 t)
160 ACE_TRACE ("ACE_Name_Request::type_len");
161 this->transfer_.type_len_ = t;
164 // = Set/get the blocking semantics.
166 ACE_UINT32
167 ACE_Name_Request::block_forever () const
169 ACE_TRACE ("ACE_Name_Request::block_forever");
170 return this->transfer_.block_forever_;
173 void
174 ACE_Name_Request::block_forever (ACE_UINT32 bs)
176 ACE_TRACE ("ACE_Name_Request::block_forever");
177 this->transfer_.block_forever_ = bs;
180 // = Set/get the timeout.
182 ACE_Time_Value
183 ACE_Name_Request::timeout () const
185 ACE_TRACE ("ACE_Name_Request::timeout");
186 time_t sec = ACE_Utils::truncate_cast<time_t> (this->transfer_.sec_timeout_);
187 return ACE_Time_Value (sec, this->transfer_.usec_timeout_);
190 void
191 ACE_Name_Request::timeout (const ACE_Time_Value timeout)
193 ACE_TRACE ("ACE_Name_Request::timeout");
194 this->transfer_.sec_timeout_ = timeout.sec ();
195 this->transfer_.usec_timeout_ = static_cast<ACE_UINT32> (timeout.usec ());
198 // = Set/get the name
200 const ACE_WCHAR_T *
201 ACE_Name_Request::name () const
203 ACE_TRACE ("ACE_Name_Request::name");
204 return this->name_;
207 void
208 ACE_Name_Request::name (const ACE_WCHAR_T *t)
210 ACE_TRACE ("ACE_Name_Request::name");
211 (void) ACE_OS::memcpy (this->name_,
213 this->name_len ());
216 // = Set/get the value
218 const ACE_WCHAR_T *
219 ACE_Name_Request::value () const
221 ACE_TRACE ("ACE_Name_Request::value");
222 return this->value_;
225 void
226 ACE_Name_Request::value (const ACE_WCHAR_T *c)
228 ACE_TRACE ("ACE_Name_Request::value");
230 (void) ACE_OS::memcpy (this->value_,
232 this->value_len());
235 // = Set/get the type
237 const char *
238 ACE_Name_Request::type () const
240 ACE_TRACE ("ACE_Name_Request::type");
241 return this->type_;
244 void
245 ACE_Name_Request::type (const char *c)
247 ACE_TRACE ("ACE_Name_Request::type");
248 ACE_OS::strsncpy (this->type_,
250 sizeof this->type_);
253 // Encode the transfer buffer into network byte order so that it can
254 // be sent to the server.
257 ACE_Name_Request::encode (void *&buf)
259 ACE_TRACE ("ACE_Name_Request::encode");
260 // Compute the length *before* doing the marshaling.
262 ACE_UINT32 len = this->length ();
264 size_t nv_data_len =
265 (this->transfer_.name_len_ + this->transfer_.value_len_)
266 / sizeof (ACE_WCHAR_T);
268 for (size_t i = 0; i < nv_data_len; i++)
269 this->transfer_.data_[i] =
270 static_cast<ACE_WCHAR_T> (ACE_HTONS (this->transfer_.data_[i]));
272 buf = (void *) &this->transfer_;
273 this->transfer_.block_forever_ = ACE_HTONL (this->transfer_.block_forever_);
274 this->transfer_.usec_timeout_ = ACE_HTONL (this->transfer_.usec_timeout_);
275 #if defined (ACE_LITTLE_ENDIAN)
276 ACE_UINT64 secs = this->transfer_.sec_timeout_;
277 ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.sec_timeout_);
278 #endif
279 this->transfer_.length_ = ACE_HTONL (this->transfer_.length_);
280 this->transfer_.msg_type_ = ACE_HTONL (this->transfer_.msg_type_);
281 this->transfer_.name_len_ = ACE_HTONL (this->transfer_.name_len_);
282 this->transfer_.value_len_ = ACE_HTONL (this->transfer_.value_len_);
283 this->transfer_.type_len_ = ACE_HTONL (this->transfer_.type_len_);
285 return len;
288 // Decode the transfer buffer into host byte byte order so that it can
289 // be used by the server.
292 ACE_Name_Request::decode ()
294 ACE_TRACE ("ACE_Name_Request::decode");
295 // Decode the fixed-sized portion first.
296 this->transfer_.block_forever_ = ACE_NTOHL (this->transfer_.block_forever_);
297 this->transfer_.usec_timeout_ = ACE_NTOHL (this->transfer_.usec_timeout_);
298 #if defined (ACE_LITTLE_ENDIAN)
299 ACE_UINT64 secs = this->transfer_.sec_timeout_;
300 ACE_CDR::swap_8 ((const char *)&secs, (char *)&this->transfer_.sec_timeout_);
301 #endif
302 this->transfer_.length_ = ACE_NTOHL (this->transfer_.length_);
303 this->transfer_.msg_type_ = ACE_NTOHL (this->transfer_.msg_type_);
304 this->transfer_.name_len_ = ACE_NTOHL (this->transfer_.name_len_);
305 this->transfer_.value_len_ = ACE_NTOHL (this->transfer_.value_len_);
306 this->transfer_.type_len_ = ACE_NTOHL (this->transfer_.type_len_);
308 size_t nv_data_len =
309 (this->transfer_.name_len_ + this->transfer_.value_len_)
310 / sizeof (ACE_WCHAR_T);
312 for (size_t i = 0; i < nv_data_len; i++)
313 this->transfer_.data_[i] =
314 static_cast<ACE_WCHAR_T> (ACE_NTOHS (this->transfer_.data_[i]));
316 this->name_ = this->transfer_.data_;
317 this->value_ = &this->name_[this->transfer_.name_len_ / sizeof (ACE_WCHAR_T)];
318 this->type_ = (char *)(&this->value_[this->transfer_.value_len_ / sizeof (ACE_WCHAR_T)]);
319 this->type_[this->transfer_.type_len_] = '\0';
321 // Decode the variable-sized portion.
322 return 0;
325 // Print out the current values of the ACE_Name_Request.
327 void
328 ACE_Name_Request::dump () const
330 #if defined (ACE_HAS_DUMP)
331 ACE_TRACE ("ACE_Name_Request::dump");
332 ACELIB_DEBUG ((LM_DEBUG,
333 ACE_TEXT ("*******\nlength = %d\n"),
334 this->length ()));
335 ACELIB_DEBUG ((LM_DEBUG,
336 ACE_TEXT ("message-type = ")));
338 switch (this->msg_type ())
340 case ACE_Name_Request::BIND:
341 ACELIB_DEBUG ((LM_DEBUG,
342 ACE_TEXT ("BIND\n")));
343 break;
344 case ACE_Name_Request::REBIND:
345 ACELIB_DEBUG ((LM_DEBUG,
346 ACE_TEXT ("REBIND\n")));
347 break;
348 case ACE_Name_Request::RESOLVE:
349 ACELIB_DEBUG ((LM_DEBUG,
350 ACE_TEXT ("RESOLVE\n")));
351 break;
352 case ACE_Name_Request::UNBIND:
353 ACELIB_DEBUG ((LM_DEBUG,
354 ACE_TEXT ("UNBIND\n")));
355 break;
356 case ACE_Name_Request::LIST_NAMES:
357 ACELIB_DEBUG ((LM_DEBUG,
358 ACE_TEXT ("LIST_NAMES\n")));
359 break;
360 case ACE_Name_Request::LIST_VALUES:
361 ACELIB_DEBUG ((LM_DEBUG,
362 ACE_TEXT ("LIST_VALUES\n")));
363 break;
364 case ACE_Name_Request::LIST_TYPES:
365 ACELIB_DEBUG ((LM_DEBUG,
366 ACE_TEXT ("LIST_TYPES\n")));
367 break;
368 case ACE_Name_Request::LIST_NAME_ENTRIES:
369 ACELIB_DEBUG ((LM_DEBUG,
370 ACE_TEXT ("LIST_NAME_ENTRIES\n")));
371 break;
372 case ACE_Name_Request::LIST_VALUE_ENTRIES:
373 ACELIB_DEBUG ((LM_DEBUG,
374 ACE_TEXT ("LIST_VALUE_ENTRIES\n")));
375 break;
376 case ACE_Name_Request::LIST_TYPE_ENTRIES:
377 ACELIB_DEBUG ((LM_DEBUG,
378 ACE_TEXT ("LIST_TYPE_ENTRIES\n")));
379 break;
380 default:
381 ACELIB_DEBUG ((LM_DEBUG,
382 ACE_TEXT ("<unknown type> = %d\n"),
383 this->msg_type ()));
384 break;
387 if (this->block_forever ())
388 ACELIB_DEBUG ((LM_DEBUG,
389 ACE_TEXT ("blocking forever\n")));
390 else
392 #if !defined (ACE_NLOGGING)
393 ACE_Time_Value tv = this->timeout ();
394 #endif /* ! ACE_NLOGGING */
395 ACELIB_DEBUG ((LM_DEBUG,
396 ACE_TEXT ("waiting for %d secs and %d usecs\n"),
397 tv.sec (),
398 tv.usec ()));
400 ACELIB_DEBUG ((LM_DEBUG,
401 ACE_TEXT ("*******\nname_len = %d\n"),
402 this->name_len ()));
403 ACELIB_DEBUG ((LM_DEBUG,
404 ACE_TEXT ("*******\nvalue_len = %d\n"),
405 this->value_len ()));
407 ACELIB_DEBUG ((LM_DEBUG,
408 ACE_TEXT ("+++++++\n")));
409 #endif /* ACE_HAS_DUMP */
412 // Default constructor.
414 ACE_Name_Reply::ACE_Name_Reply ()
416 ACE_TRACE ("ACE_Name_Reply::ACE_Name_Reply");
418 // Initialize to a known quantity.
419 this->msg_type (0);
420 this->errnum (0);
421 this->length (sizeof this->transfer_);
424 // Create a ACE_Name_Reply message.
426 ACE_Name_Reply::ACE_Name_Reply (ACE_UINT32 t, ACE_UINT32 err) // Type of reply.
428 ACE_TRACE ("ACE_Name_Reply::ACE_Name_Reply");
429 this->msg_type (t);
430 this->errnum (err);
431 this->length (sizeof this->transfer_);
434 // Initialize length_ to avoid problems with byte-ordering.
436 void
437 ACE_Name_Reply::init ()
439 ACE_TRACE ("ACE_Name_Reply::init");
440 this->length (sizeof this->transfer_);
443 // = Set/get the length of the encoded/decoded message.
445 ACE_UINT32
446 ACE_Name_Reply::length () const
448 ACE_TRACE ("ACE_Name_Reply::length");
449 return this->transfer_.length_;
452 void
453 ACE_Name_Reply::length (ACE_UINT32 l)
455 ACE_TRACE ("ACE_Name_Reply::length");
456 this->transfer_.length_ = l;
459 // = Set/get the type of the message.
461 ACE_INT32
462 ACE_Name_Reply::msg_type () const
464 ACE_TRACE ("ACE_Name_Reply::msg_type");
465 return this->transfer_.type_;
468 void
469 ACE_Name_Reply::msg_type (ACE_INT32 t)
471 ACE_TRACE ("ACE_Name_Reply::msg_type");
472 this->transfer_.type_ = t;
475 // Get the status of the reply (0 == success, -1 == failure).
477 ACE_INT32
478 ACE_Name_Reply::status () const
480 ACE_TRACE ("ACE_Name_Reply::status");
481 return this->transfer_.type_;
484 // Set the status of the reply (0 == success, -1 == failure).
486 void
487 ACE_Name_Reply::status (ACE_INT32 s)
489 ACE_TRACE ("ACE_Name_Reply::status");
490 if (s == -1)
491 this->transfer_.type_ = -1;
492 else
493 this->transfer_.type_ = 0;
496 // = Set/get the errno of a failed reply.
497 ACE_UINT32
498 ACE_Name_Reply::errnum () const
500 ACE_TRACE ("ACE_Name_Reply::errnum");
501 return this->transfer_.errno_;
504 void
505 ACE_Name_Reply::errnum (ACE_UINT32 e)
507 ACE_TRACE ("ACE_Name_Reply::errnum");
508 this->transfer_.errno_ = e;
511 // Encode the transfer buffer into network byte order
512 // so that it can be sent to the client.
515 ACE_Name_Reply::encode (void *&buf)
517 ACE_TRACE ("ACE_Name_Reply::encode");
518 int len = this->length (); // Get length *before* marshaling.
520 this->transfer_.length_ = ACE_HTONL (this->transfer_.length_);
521 this->transfer_.type_ = ACE_HTONL (this->transfer_.type_);
522 this->transfer_.errno_ = ACE_HTONL (this->transfer_.errno_);
523 buf = (void *) &this->transfer_;
524 return len;
527 // Decode the transfer buffer into host byte order so that it can be
528 // used by the client.
531 ACE_Name_Reply::decode ()
533 ACE_TRACE ("ACE_Name_Reply::decode");
534 this->transfer_.length_ = ACE_NTOHL (this->transfer_.length_);
535 this->transfer_.type_ = ACE_NTOHL (this->transfer_.type_);
536 this->transfer_.errno_ = ACE_NTOHL (this->transfer_.errno_);
537 return 0;
540 // Print out current values of the ACE_Name_Reply object.
542 void
543 ACE_Name_Reply::dump () const
545 #if defined (ACE_HAS_DUMP)
546 ACE_TRACE ("ACE_Name_Reply::dump");
547 ACELIB_DEBUG ((LM_DEBUG,
548 ACE_TEXT ("*******\nlength = %d\nerrnum = %d"),
549 this->length (),
550 this->errnum ()));
551 ACELIB_DEBUG ((LM_DEBUG,
552 ACE_TEXT ("type = ")));
553 switch (this->msg_type ())
555 case 0:
556 ACELIB_DEBUG ((LM_DEBUG,
557 ACE_TEXT ("SUCCESS\n")));
558 break;
559 case -1:
560 ACELIB_DEBUG ((LM_DEBUG,
561 ACE_TEXT ("FAILURE\n")));
562 break;
563 default:
564 ACELIB_DEBUG ((LM_DEBUG,
565 ACE_TEXT ("<unknown type> = %d\n"),
566 this->msg_type ()));
567 break;
569 #endif /* ACE_HAS_DUMP */
572 ACE_END_VERSIONED_NAMESPACE_DECL