00001
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
00010
00011 ACE_RCSID(ace, Token_Request_Reply, "$Id: Token_Request_Reply.cpp 79134 2007-07-31 18:23:50Z johnnyw $")
00012
00013 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00014
00015
00016
00017 ACE_Token_Request::ACE_Token_Request (void)
00018 : token_name_ (0),
00019 client_id_ (0)
00020 {
00021 }
00022
00023
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);
00036 this->notify (0);
00037 transfer_.arg_ = 0;
00038 ACE_OS::memset (transfer_.data_, 0, sizeof transfer_.data_);
00039 this->token_name (token_name, client_id);
00040 this->options (options);
00041 }
00042
00043
00044
00045
00046 int
00047 ACE_Token_Request::encode (void *&buf)
00048 {
00049 buf = (void *) &this->transfer_;
00050 return this->length ();
00051 }
00052
00053
00054
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
00066 size_t token_len = ACE_OS::strlen (this->token_name_);
00067
00068
00069 if (token_len >= ACE_MAXTOKENNAMELEN)
00070 {
00071 errno = ENAMETOOLONG;
00072 return -1;
00073 }
00074 else
00075 this->client_id_ =
00076 &this->token_name_[(token_len + 2) * sizeof (ACE_TCHAR)];
00077
00078
00079
00080
00081
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
00088 return this->length () == data_size ? 0 : -1;
00089 }
00090
00091
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_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_TEXT ("type = ")));
00101
00102 if (this->token_type () == ACE_Tokens::MUTEX)
00103 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("MUTEX\n")));
00104 else
00105 {
00106 if (this->proxy_type () == ACE_RW_Token::READER)
00107 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("RLOCK\n")));
00108 else
00109 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("WLOCK\n")));
00110 }
00111
00112 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("operation = ")));
00113 switch (this->operation_type ())
00114 {
00115 case ACE_Token_Request::ACQUIRE:
00116 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACQUIRE\n")));
00117 break;
00118 case ACE_Token_Request::RELEASE:
00119 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("RELEASE\n")));
00120 break;
00121 case ACE_Token_Request::RENEW:
00122 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("RENEW\n")));
00123 break;
00124 default:
00125 ACE_DEBUG ((LM_DEBUG, ACE_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_TEXT ("blocking forever\n")));
00131 else
00132 {
00133 ACE_DEBUG ((LM_DEBUG, ACE_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
00138 }
00139
00140
00141
00142
00143
00144
00145
00146 ACE_Token_Reply::ACE_Token_Reply (void)
00147 {
00148 this->arg (0);
00149 this->errnum (0);
00150 this->length (sizeof (Transfer));
00151 }
00152
00153
00154
00155
00156 int
00157 ACE_Token_Reply::encode (void *&buf)
00158 {
00159 buf = (void *) &this->transfer_;
00160 return this->length ();
00161 }
00162
00163
00164
00165
00166 int
00167 ACE_Token_Reply::decode (void)
00168 {
00169 return 0;
00170 }
00171
00172
00173
00174 void
00175 ACE_Token_Reply::dump (void) const
00176 {
00177 #if defined (ACE_HAS_DUMP)
00178 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("*******\nlength = %d\nerrnum = %d"),
00179 this->length (), this->errnum ()));
00180 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("arg = %d"), this->arg ()));
00181 #endif
00182 }
00183
00184 ACE_END_VERSIONED_NAMESPACE_DECL
00185
00186 #endif