00001 #include "ace/Name_Request_Reply.h"
00002 #include "ace/Log_Msg.h"
00003 #include "ace/Time_Value.h"
00004 #include "ace/OS_NS_string.h"
00005 #include "ace/os_include/arpa/os_inet.h"
00006
00007 ACE_RCSID (ace,
00008 Name_Request_Reply,
00009 "Name_Request_Reply.cpp,v 4.25 2005/10/28 16:14:53 ossama Exp")
00010
00011 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00012
00013
00014
00015 ACE_Name_Request::ACE_Name_Request (void)
00016 {
00017 ACE_TRACE ("ACE_Name_Request::ACE_Name_Request");
00018 }
00019
00020
00021
00022 ACE_Name_Request::ACE_Name_Request (
00023 ACE_INT32 t,
00024 const ACE_WCHAR_T name[],
00025 const ACE_UINT32 name_length,
00026 const ACE_WCHAR_T value[],
00027 const ACE_UINT32 value_length,
00028 const char type[],
00029 const ACE_UINT32 type_length,
00030 ACE_Time_Value *timeout)
00031 {
00032 ACE_TRACE ("ACE_Name_Request::ACE_Name_Request");
00033 this->msg_type (t);
00034 this->name_len (name_length);
00035 this->value_len (value_length);
00036 this->type_len (type_length);
00037
00038
00039 if (timeout == 0)
00040 {
00041 this->transfer_.block_forever_ = 1;
00042 this->transfer_.sec_timeout_ = 0;
00043 this->transfer_.usec_timeout_ = 0;
00044 }
00045 else
00046 {
00047 this->block_forever (0);
00048
00049 this->transfer_.sec_timeout_ = timeout->sec ();
00050 this->transfer_.usec_timeout_ = timeout->usec ();
00051 }
00052
00053
00054 this->name_ = this->transfer_.data_;
00055 this->value_ = &this->name_[name_length / sizeof (ACE_WCHAR_T) ];
00056 this->type_ = (char *)(&this->value_[value_length / sizeof (ACE_WCHAR_T)]);
00057
00058 (void) ACE_OS::memcpy (this->name_,
00059 name,
00060 name_length);
00061 (void) ACE_OS::memcpy (this->value_,
00062 value,
00063 value_length);
00064 (void) ACE_OS::memcpy (this->type_,
00065 type,
00066 type_length);
00067
00068
00069 size_t len = sizeof this->transfer_ - sizeof this->transfer_.data_;
00070
00071
00072 len += name_length + value_length + type_length ;
00073
00074 this->length (static_cast<ACE_UINT32> (len));
00075 }
00076
00077
00078
00079 void
00080 ACE_Name_Request::init (void)
00081 {
00082 ACE_TRACE ("ACE_Name_Request::init");
00083 this->length (sizeof this->transfer_);
00084 }
00085
00086
00087
00088 ACE_UINT32
00089 ACE_Name_Request::length (void) const
00090 {
00091 ACE_TRACE ("ACE_Name_Request::length");
00092 return this->transfer_.length_;
00093 }
00094
00095 void
00096 ACE_Name_Request::length (ACE_UINT32 l)
00097 {
00098 ACE_TRACE ("ACE_Name_Request::length");
00099 this->transfer_.length_ = l;
00100 }
00101
00102
00103
00104 ACE_INT32
00105 ACE_Name_Request::msg_type (void) const
00106 {
00107 ACE_TRACE ("ACE_Name_Request::msg_type");
00108 return this->transfer_.msg_type_;
00109 }
00110
00111 void
00112 ACE_Name_Request::msg_type (ACE_INT32 t)
00113 {
00114 ACE_TRACE ("ACE_Name_Request::msg_type");
00115 this->transfer_.msg_type_ = t;
00116 }
00117
00118
00119
00120 ACE_UINT32
00121 ACE_Name_Request::name_len (void) const
00122 {
00123 ACE_TRACE ("ACE_Name_Request::name_len");
00124 return this->transfer_.name_len_;
00125 }
00126
00127 void
00128 ACE_Name_Request::name_len (ACE_UINT32 t)
00129 {
00130 ACE_TRACE ("ACE_Name_Request::name_len");
00131 this->transfer_.name_len_ = t;
00132 }
00133
00134
00135
00136 ACE_UINT32
00137 ACE_Name_Request::value_len (void) const
00138 {
00139 ACE_TRACE ("ACE_Name_Request::value_len");
00140 return this->transfer_.value_len_;
00141 }
00142
00143 void
00144 ACE_Name_Request::value_len (ACE_UINT32 t)
00145 {
00146 ACE_TRACE ("ACE_Name_Request::value_len");
00147 this->transfer_.value_len_ = t;
00148 }
00149
00150
00151
00152 ACE_UINT32
00153 ACE_Name_Request::type_len (void) const
00154 {
00155 ACE_TRACE ("ACE_Name_Request::type_len");
00156 return this->transfer_.type_len_;
00157 }
00158
00159 void
00160 ACE_Name_Request::type_len (ACE_UINT32 t)
00161 {
00162 ACE_TRACE ("ACE_Name_Request::type_len");
00163 this->transfer_.type_len_ = t;
00164 }
00165
00166
00167
00168 ACE_UINT32
00169 ACE_Name_Request::block_forever (void) const
00170 {
00171 ACE_TRACE ("ACE_Name_Request::block_forever");
00172 return this->transfer_.block_forever_;
00173 }
00174
00175 void
00176 ACE_Name_Request::block_forever (ACE_UINT32 bs)
00177 {
00178 ACE_TRACE ("ACE_Name_Request::block_forever");
00179 this->transfer_.block_forever_ = bs;
00180 }
00181
00182
00183
00184 ACE_Time_Value
00185 ACE_Name_Request::timeout (void) const
00186 {
00187 ACE_TRACE ("ACE_Name_Request::timeout");
00188 return ACE_Time_Value (this->transfer_.sec_timeout_,
00189 this->transfer_.usec_timeout_);
00190 }
00191
00192 void
00193 ACE_Name_Request::timeout (const ACE_Time_Value timeout)
00194 {
00195 ACE_TRACE ("ACE_Name_Request::timeout");
00196 this->transfer_.sec_timeout_ = timeout.sec ();
00197 this->transfer_.usec_timeout_ = timeout.usec ();
00198 }
00199
00200
00201
00202 const ACE_WCHAR_T *
00203 ACE_Name_Request::name (void) const
00204 {
00205 ACE_TRACE ("ACE_Name_Request::name");
00206 return this->name_;
00207 }
00208
00209 void
00210 ACE_Name_Request::name (const ACE_WCHAR_T *t)
00211 {
00212 ACE_TRACE ("ACE_Name_Request::name");
00213 (void) ACE_OS::memcpy (this->name_,
00214 t,
00215 this->name_len ());
00216 }
00217
00218
00219
00220 const ACE_WCHAR_T *
00221 ACE_Name_Request::value (void) const
00222 {
00223 ACE_TRACE ("ACE_Name_Request::value");
00224 return this->value_;
00225 }
00226
00227 void
00228 ACE_Name_Request::value (const ACE_WCHAR_T *c)
00229 {
00230 ACE_TRACE ("ACE_Name_Request::value");
00231
00232 (void) ACE_OS::memcpy (this->value_,
00233 c,
00234 this->value_len());
00235 }
00236
00237
00238
00239 const char *
00240 ACE_Name_Request::type (void) const
00241 {
00242 ACE_TRACE ("ACE_Name_Request::type");
00243 return this->type_;
00244 }
00245
00246 void
00247 ACE_Name_Request::type (const char *c)
00248 {
00249 ACE_TRACE ("ACE_Name_Request::type");
00250 ACE_OS::strsncpy (this->type_,
00251 c,
00252 sizeof this->type_);
00253 }
00254
00255
00256
00257
00258 int
00259 ACE_Name_Request::encode (void *&buf)
00260 {
00261 ACE_TRACE ("ACE_Name_Request::encode");
00262
00263
00264 ACE_UINT32 len = this->length ();
00265
00266 size_t nv_data_len =
00267 (this->transfer_.name_len_ + this->transfer_.value_len_)
00268 / sizeof (ACE_WCHAR_T);
00269
00270 for (size_t i = 0; i < nv_data_len; i++)
00271 this->transfer_.data_[i] =
00272 htons (this->transfer_.data_[i]);
00273
00274 buf = (void *) &this->transfer_;
00275 this->transfer_.block_forever_ = htonl (this->transfer_.block_forever_);
00276 this->transfer_.usec_timeout_ = htonl (this->transfer_.usec_timeout_);
00277 this->transfer_.sec_timeout_ = htonl (this->transfer_.sec_timeout_);
00278 this->transfer_.length_ = htonl (this->transfer_.length_);
00279 this->transfer_.msg_type_ = htonl (this->transfer_.msg_type_);
00280 this->transfer_.name_len_ = htonl (this->transfer_.name_len_);
00281 this->transfer_.value_len_ = htonl (this->transfer_.value_len_);
00282 this->transfer_.type_len_ = htonl (this->transfer_.type_len_);
00283
00284 return len;
00285 }
00286
00287
00288
00289
00290 int
00291 ACE_Name_Request::decode (void)
00292 {
00293 ACE_TRACE ("ACE_Name_Request::decode");
00294
00295 this->transfer_.block_forever_ = ntohl (this->transfer_.block_forever_);
00296 this->transfer_.usec_timeout_ = ntohl (this->transfer_.usec_timeout_);
00297 this->transfer_.sec_timeout_ = ntohl (this->transfer_.sec_timeout_);
00298 this->transfer_.length_ = ntohl (this->transfer_.length_);
00299 this->transfer_.msg_type_ = ntohl (this->transfer_.msg_type_);
00300 this->transfer_.name_len_ = ntohl (this->transfer_.name_len_);
00301 this->transfer_.value_len_ = ntohl (this->transfer_.value_len_);
00302 this->transfer_.type_len_ = ntohl (this->transfer_.type_len_);
00303
00304 size_t nv_data_len =
00305 (this->transfer_.name_len_ + this->transfer_.value_len_)
00306 / sizeof (ACE_WCHAR_T);
00307
00308 for (size_t i = 0; i < nv_data_len; i++)
00309 this->transfer_.data_[i] =
00310 ntohs (this->transfer_.data_[i]);
00311
00312 this->name_ = this->transfer_.data_;
00313 this->value_ = &this->name_[this->transfer_.name_len_ / sizeof (ACE_WCHAR_T)];
00314 this->type_ = (char *)(&this->value_[this->transfer_.value_len_ / sizeof (ACE_WCHAR_T)]);
00315 this->type_[this->transfer_.type_len_] = '\0';
00316
00317
00318 return 0;
00319 }
00320
00321
00322
00323 void
00324 ACE_Name_Request::dump (void) const
00325 {
00326 #if defined (ACE_HAS_DUMP)
00327 ACE_TRACE ("ACE_Name_Request::dump");
00328 ACE_DEBUG ((LM_DEBUG,
00329 ACE_LIB_TEXT ("*******\nlength = %d\n"),
00330 this->length ()));
00331 ACE_DEBUG ((LM_DEBUG,
00332 ACE_LIB_TEXT ("message-type = ")));
00333
00334 switch (this->msg_type ())
00335 {
00336 case ACE_Name_Request::BIND:
00337 ACE_DEBUG ((LM_DEBUG,
00338 ACE_LIB_TEXT ("BIND\n")));
00339 break;
00340 case ACE_Name_Request::REBIND:
00341 ACE_DEBUG ((LM_DEBUG,
00342 ACE_LIB_TEXT ("REBIND\n")));
00343 break;
00344 case ACE_Name_Request::RESOLVE:
00345 ACE_DEBUG ((LM_DEBUG,
00346 ACE_LIB_TEXT ("RESOLVE\n")));
00347 break;
00348 case ACE_Name_Request::UNBIND:
00349 ACE_DEBUG ((LM_DEBUG,
00350 ACE_LIB_TEXT ("UNBIND\n")));
00351 break;
00352 case ACE_Name_Request::LIST_NAMES:
00353 ACE_DEBUG ((LM_DEBUG,
00354 ACE_LIB_TEXT ("LIST_NAMES\n")));
00355 break;
00356 case ACE_Name_Request::LIST_VALUES:
00357 ACE_DEBUG ((LM_DEBUG,
00358 ACE_LIB_TEXT ("LIST_VALUES\n")));
00359 break;
00360 case ACE_Name_Request::LIST_TYPES:
00361 ACE_DEBUG ((LM_DEBUG,
00362 ACE_LIB_TEXT ("LIST_TYPES\n")));
00363 break;
00364 case ACE_Name_Request::LIST_NAME_ENTRIES:
00365 ACE_DEBUG ((LM_DEBUG,
00366 ACE_LIB_TEXT ("LIST_NAME_ENTRIES\n")));
00367 break;
00368 case ACE_Name_Request::LIST_VALUE_ENTRIES:
00369 ACE_DEBUG ((LM_DEBUG,
00370 ACE_LIB_TEXT ("LIST_VALUE_ENTRIES\n")));
00371 break;
00372 case ACE_Name_Request::LIST_TYPE_ENTRIES:
00373 ACE_DEBUG ((LM_DEBUG,
00374 ACE_LIB_TEXT ("LIST_TYPE_ENTRIES\n")));
00375 break;
00376 default:
00377 ACE_DEBUG ((LM_DEBUG,
00378 ACE_LIB_TEXT ("<unknown type> = %d\n"),
00379 this->msg_type ()));
00380 break;
00381 }
00382
00383 if (this->block_forever ())
00384 ACE_DEBUG ((LM_DEBUG,
00385 ACE_LIB_TEXT ("blocking forever\n")));
00386 else
00387 {
00388 #if !defined (ACE_NLOGGING)
00389 ACE_Time_Value tv = this->timeout ();
00390 #endif
00391 ACE_DEBUG ((LM_DEBUG,
00392 ACE_LIB_TEXT ("waiting for %d secs and %d usecs\n"),
00393 tv.sec (),
00394 tv.usec ()));
00395 }
00396 ACE_DEBUG ((LM_DEBUG,
00397 ACE_LIB_TEXT ("*******\nname_len = %d\n"),
00398 this->name_len ()));
00399 ACE_DEBUG ((LM_DEBUG,
00400 ACE_LIB_TEXT ("*******\nvalue_len = %d\n"),
00401 this->value_len ()));
00402
00403 ACE_DEBUG ((LM_DEBUG,
00404 ACE_LIB_TEXT ("+++++++\n")));
00405 #endif
00406 }
00407
00408
00409
00410 ACE_Name_Reply::ACE_Name_Reply (void)
00411 {
00412 ACE_TRACE ("ACE_Name_Reply::ACE_Name_Reply");
00413
00414
00415 this->msg_type (0);
00416 this->errnum (0);
00417 this->length (sizeof this->transfer_);
00418 }
00419
00420
00421
00422 ACE_Name_Reply::ACE_Name_Reply (ACE_UINT32 t, ACE_UINT32 err)
00423 {
00424 ACE_TRACE ("ACE_Name_Reply::ACE_Name_Reply");
00425 this->msg_type (t);
00426 this->errnum (err);
00427 this->length (sizeof this->transfer_);
00428 }
00429
00430
00431
00432 void
00433 ACE_Name_Reply::init (void)
00434 {
00435 ACE_TRACE ("ACE_Name_Reply::init");
00436 this->length (sizeof this->transfer_);
00437 }
00438
00439
00440
00441 ACE_UINT32
00442 ACE_Name_Reply::length (void) const
00443 {
00444 ACE_TRACE ("ACE_Name_Reply::length");
00445 return this->transfer_.length_;
00446 }
00447
00448 void
00449 ACE_Name_Reply::length (ACE_UINT32 l)
00450 {
00451 ACE_TRACE ("ACE_Name_Reply::length");
00452 this->transfer_.length_ = l;
00453 }
00454
00455
00456
00457 ACE_INT32
00458 ACE_Name_Reply::msg_type (void) const
00459 {
00460 ACE_TRACE ("ACE_Name_Reply::msg_type");
00461 return this->transfer_.type_;
00462 }
00463
00464 void
00465 ACE_Name_Reply::msg_type (ACE_INT32 t)
00466 {
00467 ACE_TRACE ("ACE_Name_Reply::msg_type");
00468 this->transfer_.type_ = t;
00469 }
00470
00471
00472
00473 ACE_INT32
00474 ACE_Name_Reply::status (void) const
00475 {
00476 ACE_TRACE ("ACE_Name_Reply::status");
00477 return this->transfer_.type_;
00478 }
00479
00480
00481
00482 void
00483 ACE_Name_Reply::status (ACE_INT32 s)
00484 {
00485 ACE_TRACE ("ACE_Name_Reply::status");
00486 if (s == -1)
00487 this->transfer_.type_ = -1;
00488 else
00489 this->transfer_.type_ = 0;
00490 }
00491
00492
00493 ACE_UINT32
00494 ACE_Name_Reply::errnum (void) const
00495 {
00496 ACE_TRACE ("ACE_Name_Reply::errnum");
00497 return this->transfer_.errno_;
00498 }
00499
00500 void
00501 ACE_Name_Reply::errnum (ACE_UINT32 e)
00502 {
00503 ACE_TRACE ("ACE_Name_Reply::errnum");
00504 this->transfer_.errno_ = e;
00505 }
00506
00507
00508
00509
00510 int
00511 ACE_Name_Reply::encode (void *&buf)
00512 {
00513 ACE_TRACE ("ACE_Name_Reply::encode");
00514 int len = this->length ();
00515
00516 this->transfer_.length_ = htonl (this->transfer_.length_);
00517 this->transfer_.type_ = htonl (this->transfer_.type_);
00518 this->transfer_.errno_ = htonl (this->transfer_.errno_);
00519 buf = (void *) &this->transfer_;
00520 return len;
00521 }
00522
00523
00524
00525
00526 int
00527 ACE_Name_Reply::decode (void)
00528 {
00529 ACE_TRACE ("ACE_Name_Reply::decode");
00530 this->transfer_.length_ = ntohl (this->transfer_.length_);
00531 this->transfer_.type_ = ntohl (this->transfer_.type_);
00532 this->transfer_.errno_ = ntohl (this->transfer_.errno_);
00533 return 0;
00534 }
00535
00536
00537
00538 void
00539 ACE_Name_Reply::dump (void) const
00540 {
00541 #if defined (ACE_HAS_DUMP)
00542 ACE_TRACE ("ACE_Name_Reply::dump");
00543 ACE_DEBUG ((LM_DEBUG,
00544 ACE_LIB_TEXT ("*******\nlength = %d\nerrnum = %d"),
00545 this->length (),
00546 this->errnum ()));
00547 ACE_DEBUG ((LM_DEBUG,
00548 ACE_LIB_TEXT ("type = ")));
00549 switch (this->msg_type ())
00550 {
00551 case 0:
00552 ACE_DEBUG ((LM_DEBUG,
00553 ACE_LIB_TEXT ("SUCCESS\n")));
00554 break;
00555 case -1:
00556 ACE_DEBUG ((LM_DEBUG,
00557 ACE_LIB_TEXT ("FAILURE\n")));
00558 break;
00559 default:
00560 ACE_DEBUG ((LM_DEBUG,
00561 ACE_LIB_TEXT ("<unknown type> = %d\n"),
00562 this->msg_type ()));
00563 break;
00564 }
00565 #endif
00566 }
00567
00568 ACE_END_VERSIONED_NAMESPACE_DECL