3 //=============================================================================
5 * @file Token_Request_Reply.h
7 * Define the format used to exchange messages between the
8 * ACE_Token Server and its clients.
10 * @author Douglas C. Schmidt (d.schmidt@vanderbilt.edu)
11 * @author Tim Harrison (harrison@cs.wustl.edu)
13 //=============================================================================
16 #ifndef ACE_TOKEN_REQUEST_REPLY_H
17 #define ACE_TOKEN_REQUEST_REPLY_H
18 #include /**/ "ace/pre.h"
20 #include "ace/Local_Tokens.h"
22 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 #endif /* ACE_LACKS_PRAGMA_ONCE */
26 #if defined (ACE_HAS_TOKENS_LIBRARY)
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
30 /// Specifies the size of the fixed length portion of
31 /// the Transfer structure in ACE_Token_Request
32 #define ACE_TOKEN_REQUEST_HEADER_SIZE 40
35 * @class ACE_Token_Request
37 * @brief Message format for delivering requests to the ACE_Token Server.
39 * This class is implemented to minimize data copying.
40 * In particular, all marshaling is done in situ...
42 class ACE_Export ACE_Token_Request
48 /// Acquire the token.
50 /// Release the token.
56 // Try to acquire the token.
60 /// Default constructor.
61 ACE_Token_Request (void);
64 * @param token_type MUTEX, RWLOCK
65 * @param proxy_type MUTEX, RLOCK, WLOCK (acquires mean different things)
66 * @param operation method
69 * @param options We check USE_TIMEOUT and use the arg.
71 ACE_Token_Request (int token_type
,
74 const ACE_TCHAR token_name
[],
75 const ACE_TCHAR client_id
[],
76 const ACE_Synch_Options
&options
);
78 /// Get the length of the encoded/decoded message.
79 ACE_UINT32
length (void) const;
81 /// Set the length of the encoded/decoded message.
82 void length (ACE_UINT32
);
84 /// Get the type of proxy
85 int proxy_type (void) const;
87 /// Set the type of proxy
88 void proxy_type (int proxy_type
);
90 /// Get the type of token
91 int token_type (void) const;
93 /// Set the type of token
94 void token_type (int token_type
);
96 /// Get the type of the operation.
97 ACE_UINT32
operation_type (void) const;
99 /// Set the type of the operation.
100 void operation_type (ACE_UINT32
);
102 /// Get the requeue position. These should be used when renew
103 /// is the operation type.
104 ACE_UINT32
requeue_position (void) const;
106 /// Set the requeue position. These should be used when renew
107 /// is the operation type.
108 void requeue_position (ACE_UINT32
);
110 /// Get notify. These should be used when acquire is the operation type.
111 ACE_UINT32
notify (void) const;
113 /// Set notify. These should be used when acquire is the operation type.
114 void notify (ACE_UINT32
);
117 ACE_Synch_Options
&options (void) const;
120 void options (const ACE_Synch_Options
&options
);
122 // = Set/get the name of the token and the client id. The set
123 // method is combined to make it easier on us. We're copying the
124 // names as a contiguous buffer.
125 ACE_TCHAR
*token_name (void) const;
126 ACE_TCHAR
*client_id (void) const;
127 void token_name (const ACE_TCHAR
*token_name
, const ACE_TCHAR
*client_id
);
129 /// Encode the message before transmission.
130 int encode (void *&);
132 /// Decode message after reception. This must be called to set the
133 /// internal options.
136 /// Print out the values of the message for debugging purposes.
137 void dump (void) const;
140 // = The 5 fields in the <Transfer> struct are transmitted to the server.
141 // The remaining 2 fields are not tranferred -- they are used only on
142 // the server-side to simplify lookups.
146 /// Length of entire request.
149 /// Type of the request (i.e., MUTEX, RLOCK, WLOCK...
150 ACE_UINT32 token_type_
;
152 /// Type of the request (i.e., MUTEX, RLOCK, WLOCK...
153 ACE_UINT32 proxy_type_
;
155 /// Type of the request (i.e., <ACQUIRE>, <RELEASE>, <RENEW>, and <REMOVE>).
156 ACE_UINT32 operation_type_
;
158 /// this only makes sense when operation type is renew
159 ACE_UINT32 requeue_position_
;
161 /// this only makes sense when operation type is renew
164 // = ACE_Synch_Options stuff
166 /// Indicates if we should block forever. If 1, then <secTimeout_>
167 /// and <usecTimeout_> indicates how long we should wait. If 0,
168 /// then we block forever.
169 ACE_UINT32 use_timeout_
;
171 /// Max seconds willing to wait for token if not blocking forever.
174 /// Max micro seconds to wait for token if not blocking forever.
177 /// value returned in <Token_Reply::arg>;
180 /// The data portion contains the <tokenName_> including a 0 terminator,
181 /// a ':', then the <clientId> including a 0 terminator
182 ACE_TCHAR data_
[ACE_MAXTOKENNAMELEN
+ ACE_MAXCLIENTIDLEN
+ 3];
185 /// Pointer to the beginning of the token name in this->data_.
186 ACE_TCHAR
*token_name_
;
188 /// Pointer to the beginning of the client id in this->data_;
189 ACE_TCHAR
*client_id_
;
191 /// Holds arg, sec, usec, etc.
192 ACE_Synch_Options options_
;
196 * @class ACE_Token_Reply
198 * @brief Message format for delivering replies from the ACE_Token Server.
200 * This class is implemented to minimize data copying.
201 * In particular, all marshaling is done in situ...
203 class ACE_Export ACE_Token_Reply
206 /// Default constructor.
207 ACE_Token_Reply (void);
209 /// Get the length of the encoded/decoded message.
210 ACE_UINT32
length (void) const;
212 /// Set the length of the encoded/decoded message.
213 void length (ACE_UINT32
);
215 /// Get the errno of a reply.
216 ACE_UINT32
errnum (void) const;
218 /// Set the errno of a reply.
219 void errnum (ACE_UINT32
);
221 /// Get the arg of a reply.
222 ACE_UINT32
arg (void) const;
224 /// Set the arg of a reply.
225 void arg (ACE_UINT32
);
227 /// Encode the message before transfer.
228 int encode (void *&);
230 /// Decode a message after reception.
233 /// Print out the values of the message for debugging purposes.
234 void dump (void) const;
237 // = The 2 fields in the <Transfer> struct are transmitted to the server.
241 /// Length of entire reply.
244 /// Indicates why error occurred if <this->type_> == <FAILURE>.
245 /// Typical reasons include:
246 /// @c EWOULDBLOCK (if client requested a non-blocking check for the token).
247 /// @c ETIME (if the client timed out after waiting for the token).
248 /// <ENOLCK> (if the token lock was removed out from underneath a waiter).
249 /// <EACCES> (attempt to renew a token that isn't owned by the client).
258 ACE_END_VERSIONED_NAMESPACE_DECL
260 #if defined (__ACE_INLINE__)
261 #include "ace/Token_Request_Reply.inl"
262 #endif /* __ACE_INLINE__ */
264 #endif /* ACE_HAS_TOKENS_LIBRARY */
266 #include /**/ "ace/post.h"
267 #endif /* ACE_TOKEN_REQUEST_REPLY_H */