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

Time_Request_Reply.cpp

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

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