Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Name_Request_Reply.cpp

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

Generated on Mon Jun 16 11:20:28 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002