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

Token_Request_Reply.cpp

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

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