Token_Request_Reply.cpp

Go to the documentation of this file.
00001 // Token_Request_Reply.cpp,v 4.16 2006/02/28 00:23:12 shuston Exp
00002 
00003 #include "ace/Token_Request_Reply.h"
00004 
00005 #if defined (ACE_HAS_TOKENS_LIBRARY)
00006 
00007 #if !defined (__ACE_INLINE__)
00008 #include "ace/Token_Request_Reply.inl"
00009 #endif /* __ACE_INLINE__ */
00010 
00011 ACE_RCSID(ace, Token_Request_Reply, "Token_Request_Reply.cpp,v 4.16 2006/02/28 00:23:12 shuston Exp")
00012 
00013 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00014 
00015 // Default "do nothing" constructor.
00016 
00017 ACE_Token_Request::ACE_Token_Request (void)
00018   : token_name_ (0),
00019     client_id_ (0)
00020 {
00021 }
00022 
00023 // Create a ACE_Token_Request message.
00024 
00025 ACE_Token_Request::ACE_Token_Request (int token_type,
00026                                       int proxy_type,
00027                                       ACE_UINT32 operation_type,
00028                                       const ACE_TCHAR token_name[],
00029                                       const ACE_TCHAR client_id[],
00030                                       const ACE_Synch_Options &options)
00031 {
00032   this->token_type (token_type);
00033   this->proxy_type (proxy_type);
00034   this->operation_type (operation_type);
00035   this->requeue_position (0);      // to avoid Purify UMR
00036   this->notify (0);                // to avoid Purify UMR
00037   transfer_.arg_ = 0;              // to avoid Purify UMR
00038   ACE_OS::memset (transfer_.data_, 0, sizeof transfer_.data_); // to avoid Purify UMR
00039   this->token_name (token_name, client_id);
00040   this->options (options);
00041 }
00042 
00043 // Encode the transfer buffer into network byte order
00044 // so that it can be sent to the server.
00045 
00046 int
00047 ACE_Token_Request::encode (void *&buf)
00048 {
00049   buf = (void *) &this->transfer_;
00050   return this->length ();
00051 }
00052 
00053 // Decode the transfer buffer into host byte byte order
00054 // so that it can be used by the server.
00055 
00056 int
00057 ACE_Token_Request::decode (void)
00058 {
00059   this->token_name_ = this->transfer_.data_;
00060 
00061   options_.set (transfer_.use_timeout_ == 1 ? ACE_Synch_Options::USE_TIMEOUT : 0,
00062                 ACE_Time_Value (transfer_.sec_, transfer_.usec_),
00063                 (void *) transfer_.arg_);
00064 
00065   // Decode the variable-sized portion.
00066   size_t token_len = ACE_OS::strlen (this->token_name_);
00067 
00068   // Check to make sure this->tokenName_ isn't too long!
00069   if (token_len >= ACE_MAXTOKENNAMELEN)
00070     {
00071       errno = ENAMETOOLONG;
00072       return -1;
00073     }
00074   else // Skip this->tokenName_ + '\0' + ':'.
00075     this->client_id_ =
00076       &this->token_name_[(token_len + 2) * sizeof (ACE_TCHAR)];
00077 
00078   // Fixed size header
00079   // token_name_ plus '\0'
00080   // ':'
00081   // client_id_ plus '\0'
00082   size_t data_size = ACE_TOKEN_REQUEST_HEADER_SIZE
00083                      + ACE_OS::strlen (this->token_name_) + 1
00084                      + ACE_OS::strlen (this->client_id_) + 1
00085                      + 1;
00086 
00087   // Make sure the message was correctly received and framed.
00088   return this->length () == data_size ? 0 : -1;
00089 }
00090 
00091 // Print out the current values of the ACE_Token_Request.
00092 
00093 void
00094 ACE_Token_Request::dump (void) const
00095 {
00096 #if defined (ACE_HAS_DUMP)
00097   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00098   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("*******\nlength = %d\ntoken name = %s\nclient id = %s\n"),
00099              this->length (), this->token_name (), this->client_id ()));
00100   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("type = ")));
00101 
00102   if (this->token_type () == ACE_Tokens::MUTEX)
00103     ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("MUTEX\n")));
00104   else // == ACE_Tokens::RWLOCK
00105     {
00106       if (this->proxy_type () == ACE_RW_Token::READER)
00107         ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("RLOCK\n")));
00108       else // == WRITER
00109         ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("WLOCK\n")));
00110     }
00111 
00112   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("operation = ")));
00113   switch (this->operation_type ())
00114     {
00115     case ACE_Token_Request::ACQUIRE:
00116       ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("ACQUIRE\n")));
00117       break;
00118     case ACE_Token_Request::RELEASE:
00119       ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("RELEASE\n")));
00120       break;
00121     case ACE_Token_Request::RENEW:
00122       ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("RENEW\n")));
00123       break;
00124     default:
00125       ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("<unknown operation type> = %d\n"), this->operation_type ()));
00126       break;
00127     }
00128 
00129   if (this->options ()[ACE_Synch_Options::USE_TIMEOUT] == 0)
00130     ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("blocking forever\n")));
00131   else
00132     {
00133       ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("waiting for %d secs and %d usecs\n"),
00134                  this->options ().timeout ().sec (), this->options ().timeout ().usec ()));
00135     }
00136   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00137 #endif /* ACE_HAS_DUMP */
00138 }
00139 
00140 // ************************************************************
00141 // ************************************************************
00142 // ************************************************************
00143 
00144 // Create a ACE_Token_Reply message.
00145 
00146 ACE_Token_Reply::ACE_Token_Reply (void) // Type of reply.
00147 {
00148   this->arg (0);
00149   this->errnum (0);
00150   this->length (sizeof (Transfer));
00151 }
00152 
00153 // Encode the transfer buffer into network byte order
00154 // so that it can be sent to the client.
00155 
00156 int
00157 ACE_Token_Reply::encode (void *&buf)
00158 {
00159   buf = (void *) &this->transfer_;
00160   return this->length ();
00161 }
00162 
00163 // Decode the transfer buffer into host byte order
00164 // so that it can be used by the client.
00165 
00166 int
00167 ACE_Token_Reply::decode (void)
00168 {
00169   return 0;
00170 }
00171 
00172 // Print out current values of the ACE_Token_Reply object.
00173 
00174 void
00175 ACE_Token_Reply::dump (void) const
00176 {
00177 #if defined (ACE_HAS_DUMP)
00178   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("*******\nlength = %d\nerrnum = %d"),
00179              this->length (), this->errnum ()));
00180   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("arg = %d"), this->arg ()));
00181 #endif /* ACE_HAS_DUMP */
00182 }
00183 
00184 ACE_END_VERSIONED_NAMESPACE_DECL
00185 
00186 #endif /* ACE_HAS_TOKENS_LIBRARY */

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