00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Token_Request_Reply.h 00006 * 00007 * Token_Request_Reply.h,v 4.21 2006/01/26 11:32:50 jwillemsen Exp 00008 * 00009 * Define the format used to exchange messages between the 00010 * ACE_Token Server and its clients. 00011 * 00012 * 00013 * @author Douglas C. Schmidt (schmidt@cs.wustl.edu) 00014 * @author Tim Harrison (harrison@cs.wustl.edu) 00015 */ 00016 //============================================================================= 00017 00018 00019 #ifndef ACE_TOKEN_REQUEST_REPLY_H 00020 #define ACE_TOKEN_REQUEST_REPLY_H 00021 #include /**/ "ace/pre.h" 00022 00023 #include "ace/Local_Tokens.h" 00024 00025 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00026 # pragma once 00027 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00028 00029 #if defined (ACE_HAS_TOKENS_LIBRARY) 00030 00031 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00032 00033 /// Specifies the size of the fixed length portion of 00034 /// the Transfer structure in ACE_Token_Request 00035 #define ACE_TOKEN_REQUEST_HEADER_SIZE 40 00036 00037 /** 00038 * @class ACE_Token_Request 00039 * 00040 * @brief Message format for delivering requests to the ACE_Token Server. 00041 * 00042 * This class is implemented to minimize data copying. 00043 * In particular, all marshaling is done in situ... 00044 */ 00045 class ACE_Export ACE_Token_Request 00046 { 00047 public: 00048 /// Operation types. 00049 enum OPERATION 00050 { 00051 /// Acquire the token. 00052 ACQUIRE, 00053 /// Release the token. 00054 RELEASE, 00055 /// Renew the token. 00056 RENEW, 00057 /// Remove the token. 00058 REMOVE, 00059 // Try to acquire the token. 00060 TRY_ACQUIRE 00061 }; 00062 00063 /// Default constructor. 00064 ACE_Token_Request (void); 00065 00066 /** 00067 * @param token_type MUTEX, RWLOCK 00068 * @param proxy_type MUTEX, RLOCK, WLOCK (acquires mean different things) 00069 * @param operation method 00070 * @param token_name 00071 * @param client_id 00072 * @param options We check USE_TIMEOUT and use the arg. 00073 */ 00074 ACE_Token_Request (int token_type, 00075 int proxy_type, 00076 ACE_UINT32 operation, 00077 const ACE_TCHAR token_name[], 00078 const ACE_TCHAR client_id[], 00079 const ACE_Synch_Options &options); 00080 00081 /// Get the length of the encoded/decoded message. 00082 ACE_UINT32 length (void) const; 00083 00084 /// Set the length of the encoded/decoded message. 00085 void length (ACE_UINT32); 00086 00087 /// Get the type of proxy 00088 int proxy_type (void) const; 00089 00090 /// Set the type of proxy 00091 void proxy_type (int proxy_type); 00092 00093 /// Get the type of token 00094 int token_type (void) const; 00095 00096 /// Set the type of token 00097 void token_type (int token_type); 00098 00099 /// Get the type of the operation. 00100 ACE_UINT32 operation_type (void) const; 00101 00102 /// Set the type of the operation. 00103 void operation_type (ACE_UINT32); 00104 00105 /// Get the requeue position. These should be used when renew 00106 /// is the operation type. 00107 ACE_UINT32 requeue_position (void) const; 00108 00109 /// Set the requeue position. These should be used when renew 00110 /// is the operation type. 00111 void requeue_position (ACE_UINT32); 00112 00113 /// Get notify. These should be used when acquire is the operation type. 00114 ACE_UINT32 notify (void) const; 00115 00116 /// Set notify. These should be used when acquire is the operation type. 00117 void notify (ACE_UINT32); 00118 00119 /// Get the timeout. 00120 ACE_Synch_Options &options (void) const; 00121 00122 /// Set the timeout. 00123 void options (const ACE_Synch_Options &options); 00124 00125 // = Set/get the name of the token and the client id. The set 00126 // method is combined to make it easier on us. We're copying the 00127 // names as a contiguous buffer. 00128 ACE_TCHAR *token_name (void) const; 00129 ACE_TCHAR *client_id (void) const; 00130 void token_name (const ACE_TCHAR *token_name, const ACE_TCHAR *client_id); 00131 00132 /// Encode the message before transmission. 00133 int encode (void *&); 00134 00135 /// Decode message after reception. This must be called to set the 00136 /// internal options. 00137 int decode (void); 00138 00139 /// Print out the values of the message for debugging purposes. 00140 void dump (void) const; 00141 00142 private: 00143 // = The 5 fields in the <Transfer> struct are transmitted to the server. 00144 // The remaining 2 fields are not tranferred -- they are used only on 00145 // the server-side to simplify lookups. 00146 00147 struct Transfer 00148 { 00149 /// Length of entire request. 00150 ACE_UINT32 length_; 00151 00152 /// Type of the request (i.e., MUTEX, RLOCK, WLOCK... 00153 ACE_UINT32 token_type_; 00154 00155 /// Type of the request (i.e., MUTEX, RLOCK, WLOCK... 00156 ACE_UINT32 proxy_type_; 00157 00158 /// Type of the request (i.e., <ACQUIRE>, <RELEASE>, <RENEW>, and <REMOVE>). 00159 ACE_UINT32 operation_type_; 00160 00161 /// this only makes sense when operation type is renew 00162 ACE_UINT32 requeue_position_; 00163 00164 /// this only makes sense when operation type is renew 00165 ACE_UINT32 notify_; 00166 00167 // = ACE_Synch_Options stuff 00168 00169 /// Indicates if we should block forever. If 1, then <secTimeout_> 00170 /// and <usecTimeout_> indicates how long we should wait. If 0, 00171 /// then we block forever. 00172 ACE_UINT32 use_timeout_; 00173 00174 /// Max seconds willing to wait for token if not blocking forever. 00175 ACE_UINT32 sec_; 00176 00177 /// Max micro seconds to wait for token if not blocking forever. 00178 ACE_UINT32 usec_; 00179 00180 /// value returned in <Token_Reply::arg>; 00181 ACE_UINT32 arg_; 00182 00183 /// The data portion contains the <tokenName_> including a 0 terminator, 00184 /// a ':', then the <clientId> including a 0 terminator 00185 ACE_TCHAR data_[ACE_MAXTOKENNAMELEN + ACE_MAXCLIENTIDLEN + 3]; 00186 } transfer_; 00187 00188 /// Pointer to the beginning of the token name in this->data_. 00189 ACE_TCHAR *token_name_; 00190 00191 /// Pointer to the beginning of the client id in this->data_; 00192 ACE_TCHAR *client_id_; 00193 00194 /// Holds arg, sec, usec, etc. 00195 ACE_Synch_Options options_; 00196 }; 00197 00198 /** 00199 * @class ACE_Token_Reply 00200 * 00201 * @brief Message format for delivering replies from the ACE_Token Server. 00202 * 00203 * This class is implemented to minimize data copying. 00204 * In particular, all marshaling is done in situ... 00205 */ 00206 class ACE_Export ACE_Token_Reply 00207 { 00208 public: 00209 /// Default constructor. 00210 ACE_Token_Reply (void); 00211 00212 /// Get the length of the encoded/decoded message. 00213 ACE_UINT32 length (void) const; 00214 00215 /// Set the length of the encoded/decoded message. 00216 void length (ACE_UINT32); 00217 00218 /// Get the errno of a reply. 00219 ACE_UINT32 errnum (void) const; 00220 00221 /// Set the errno of a reply. 00222 void errnum (ACE_UINT32); 00223 00224 /// Get the arg of a reply. 00225 ACE_UINT32 arg (void) const; 00226 00227 /// Set the arg of a reply. 00228 void arg (ACE_UINT32); 00229 00230 /// Encode the message before transfer. 00231 int encode (void *&); 00232 00233 /// Decode a message after reception. 00234 int decode (void); 00235 00236 /// Print out the values of the message for debugging purposes. 00237 void dump (void) const; 00238 00239 private: 00240 // = The 2 fields in the <Transfer> struct are transmitted to the server. 00241 00242 struct Transfer 00243 { 00244 /// Length of entire reply. 00245 ACE_UINT32 length_; 00246 00247 /// Indicates why error occurred if <this->type_> == <FAILURE>. 00248 /// Typical reasons include: 00249 /// <EWOULDBLOCK> (if client requested a non-blocking check for the token). 00250 /// <ETIME> (if the client timed out after waiting for the token). 00251 /// <ENOLCK> (if the token lock was removed out from underneath a waiter). 00252 /// <EACCES> (attempt to renew a token that isn't owned by the client). 00253 ACE_UINT32 errno_; 00254 00255 /// magic cookie 00256 ACE_UINT32 arg_; 00257 00258 } transfer_; 00259 }; 00260 00261 ACE_END_VERSIONED_NAMESPACE_DECL 00262 00263 #if defined (__ACE_INLINE__) 00264 #include "ace/Token_Request_Reply.inl" 00265 #endif /* __ACE_INLINE__ */ 00266 00267 #endif /* ACE_HAS_TOKENS_LIBRARY */ 00268 00269 #include /**/ "ace/post.h" 00270 #endif /* ACE_TOKEN_REQUEST_REPLY_H */