Time_Request_Reply.cpp

Go to the documentation of this file.
00001 // Time_Request_Reply.cpp,v 4.18 2005/10/28 23:55:10 ossama Exp
00002 
00003 #include "ace/Time_Request_Reply.h"
00004 #include "ace/Log_Msg.h"
00005 #include "ace/os_include/netinet/os_in.h"
00006 #include "ace/os_include/arpa/os_inet.h"
00007 
00008 ACE_RCSID(ace, Time_Request_Reply, "Time_Request_Reply.cpp,v 4.18 2005/10/28 23:55:10 ossama Exp")
00009 
00010 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00011 
00012 // Default "do nothing" constructor.
00013 
00014 ACE_Time_Request::ACE_Time_Request (void)
00015 {
00016   ACE_TRACE ("ACE_Time_Request::ACE_Time_Request");
00017 }
00018 
00019 // Create a ACE_Time_Request message.
00020 
00021 ACE_Time_Request::ACE_Time_Request (ACE_INT32 t, // Type of request.
00022                                     const ACE_UINT32 time,
00023                                     ACE_Time_Value *timeout) // Max time waiting for request.
00024 {
00025   ACE_TRACE ("ACE_Time_Request::ACE_Time_Request");
00026   this->msg_type (t);
00027 
00028   // If timeout is a NULL pointer, then block forever...
00029   if (timeout == 0)
00030     {
00031       this->transfer_.block_forever_ = 1;
00032       this->transfer_.sec_timeout_   = 0;
00033       this->transfer_.usec_timeout_  = 0;
00034     }
00035   else // Do a "timed wait."
00036     {
00037       this->block_forever (0);
00038       // Keep track of how long client is willing to wait.
00039       this->transfer_.sec_timeout_ = timeout->sec ();
00040       this->transfer_.usec_timeout_ = timeout->usec ();
00041     }
00042 
00043   // Copy time into request
00044   this->time_ = this->transfer_.time_ = time;
00045 }
00046 
00047 // Initialize length_ in order to avoid problems with byte-ordering
00048 void
00049 ACE_Time_Request::init (void)
00050 {
00051   ACE_TRACE ("ACE_Time_Request::init");
00052 //  this->length (sizeof this->transfer_);
00053 }
00054 
00055 // Get the fixed size of message
00056 ssize_t
00057 ACE_Time_Request::size (void) const
00058 {
00059   ACE_TRACE ("ACE_Time_Request::size");
00060   return sizeof (this->transfer_);
00061 }
00062 
00063 // = Set/get the type of the message.
00064 ACE_INT32
00065 ACE_Time_Request::msg_type (void) const
00066 {
00067   ACE_TRACE ("ACE_Time_Request::msg_type");
00068   return this->transfer_.msg_type_;
00069 }
00070 
00071 void
00072 ACE_Time_Request::msg_type (ACE_INT32 t)
00073 {
00074   ACE_TRACE ("ACE_Time_Request::msg_type");
00075   this->transfer_.msg_type_ = t;
00076 }
00077 
00078 // = Set/get the blocking semantics.
00079 ACE_UINT32
00080 ACE_Time_Request::block_forever (void) const
00081 {
00082   ACE_TRACE ("ACE_Time_Request::block_forever");
00083   return this->transfer_.block_forever_;
00084 }
00085 
00086 void
00087 ACE_Time_Request::block_forever (ACE_UINT32 bs)
00088 {
00089   ACE_TRACE ("ACE_Time_Request::block_forever");
00090   this->transfer_.block_forever_ = bs;
00091 }
00092 
00093 // = Set/get the timeout.
00094 ACE_Time_Value
00095 ACE_Time_Request::timeout (void) const
00096 {
00097   ACE_TRACE ("ACE_Time_Request::timeout");
00098   return ACE_Time_Value (this->transfer_.sec_timeout_, this->transfer_.usec_timeout_);
00099 }
00100 
00101 void
00102 ACE_Time_Request::timeout (const ACE_Time_Value& timeout)
00103 {
00104   ACE_TRACE ("ACE_Time_Request::timeout");
00105   this->transfer_.sec_timeout_  = timeout.sec ();
00106   this->transfer_.usec_timeout_ = timeout.usec ();
00107 }
00108 
00109 // = Set/get the time
00110 ACE_UINT32
00111 ACE_Time_Request::time (void) const
00112 {
00113   ACE_TRACE ("ACE_Time_Request::time");
00114   return this->time_;
00115 }
00116 
00117 void
00118 ACE_Time_Request::time (ACE_UINT32 t)
00119 {
00120   ACE_TRACE ("ACE_Time_Request::time");
00121   this->time_ = t;
00122 }
00123 
00124 // Encode the transfer buffer into network byte order
00125 // so that it can be sent to the server.
00126 int
00127 ACE_Time_Request::encode (void *&buf)
00128 {
00129   ACE_TRACE ("ACE_Time_Request::encode");
00130   // Compute the length *before* doing the marshaling.
00131 
00132   buf = (void *) &this->transfer_;
00133   this->transfer_.block_forever_ = htonl (this->transfer_.block_forever_);
00134   this->transfer_.usec_timeout_  = htonl (this->transfer_.usec_timeout_);
00135   this->transfer_.sec_timeout_   = htonl (this->transfer_.sec_timeout_);
00136   this->transfer_.msg_type_      = htonl (this->transfer_.msg_type_);
00137   this->transfer_.time_          = htonl (this->transfer_.time_);
00138 
00139   return this->size ();  // Always fixed
00140 }
00141 
00142 // Decode the transfer buffer into host byte byte order
00143 // so that it can be used by the server.
00144 int
00145 ACE_Time_Request::decode (void)
00146 {
00147   ACE_TRACE ("ACE_Time_Request::decode");
00148   // Decode
00149   this->transfer_.block_forever_ = ntohl (this->transfer_.block_forever_);
00150   this->transfer_.usec_timeout_  = ntohl (this->transfer_.usec_timeout_);
00151   this->transfer_.sec_timeout_   = ntohl (this->transfer_.sec_timeout_);
00152   this->transfer_.msg_type_      = ntohl (this->transfer_.msg_type_);
00153   this->transfer_.time_          = ntohl (this->transfer_.time_);
00154 
00155   this->time_ = this->transfer_.time_;
00156   return 0;
00157 }
00158 
00159 // Print out the current values of the ACE_Time_Request.
00160 
00161 void
00162 ACE_Time_Request::dump (void) const
00163 {
00164 #if defined (ACE_HAS_DUMP)
00165   ACE_TRACE ("ACE_Time_Request::dump");
00166   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("*******\nlength = %d\n"),
00167               this->size ()));
00168   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("message-type = ")));
00169 
00170   switch (this->msg_type ())
00171     {
00172     case ACE_Time_Request::TIME_UPDATE:
00173       ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("TIME_UPDATE\n")));
00174       break;
00175     default:
00176       ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("<unknown type> = %d\n"), this->msg_type ()));
00177       break;
00178     }
00179 
00180   if (this->block_forever ())
00181     ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("blocking forever\n")));
00182   else
00183     {
00184 #if !defined (ACE_NLOGGING)
00185       ACE_Time_Value tv = this->timeout ();
00186 #endif /* ! ACE_NLOGGING */
00187       ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("waiting for %d secs and %d usecs\n"),
00188                   tv.sec (), tv.usec ()));
00189     }
00190   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("*******\ntime = %d\n"),
00191               this->time ()));
00192   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("+++++++\n")));
00193 #endif /* ACE_HAS_DUMP */
00194 }
00195 
00196 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:42:06 2006 for ACE by doxygen 1.3.6