1 #include "ace/Token_Request_Reply.h"
3 #if defined (ACE_HAS_TOKENS_LIBRARY)
5 #if !defined (__ACE_INLINE__)
6 #include "ace/Token_Request_Reply.inl"
7 #endif /* __ACE_INLINE__ */
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 // Create a ACE_Token_Request message.
13 ACE_Token_Request::ACE_Token_Request (int token_type
,
15 ACE_UINT32 operation_type
,
16 const ACE_TCHAR token_name
[],
17 const ACE_TCHAR client_id
[],
18 const ACE_Synch_Options
&options
)
20 this->token_type (token_type
);
21 this->proxy_type (proxy_type
);
22 this->operation_type (operation_type
);
23 this->requeue_position (0); // to avoid Purify UMR
24 this->notify (0); // to avoid Purify UMR
25 transfer_
.arg_
= 0; // to avoid Purify UMR
26 ACE_OS::memset (transfer_
.data_
, 0, sizeof transfer_
.data_
); // to avoid Purify UMR
27 this->token_name (token_name
, client_id
);
28 this->options (options
);
31 // Encode the transfer buffer into network byte order
32 // so that it can be sent to the server.
35 ACE_Token_Request::encode (void *&buf
)
37 buf
= (void *) &this->transfer_
;
38 return this->length ();
41 // Decode the transfer buffer into host byte byte order
42 // so that it can be used by the server.
45 ACE_Token_Request::decode ()
47 this->token_name_
= this->transfer_
.data_
;
49 options_
.set (transfer_
.use_timeout_
== 1 ? ACE_Synch_Options::USE_TIMEOUT
: 0,
50 ACE_Time_Value (transfer_
.sec_
, transfer_
.usec_
),
51 (void *) transfer_
.arg_
);
53 // Decode the variable-sized portion.
54 size_t token_len
= ACE_OS::strlen (this->token_name_
);
56 // Check to make sure this->tokenName_ isn't too long!
57 if (token_len
>= ACE_MAXTOKENNAMELEN
)
62 else // Skip this->tokenName_ + '\0' + ':'.
64 &this->token_name_
[(token_len
+ 2) * sizeof (ACE_TCHAR
)];
67 // token_name_ plus '\0'
69 // client_id_ plus '\0'
70 size_t data_size
= ACE_TOKEN_REQUEST_HEADER_SIZE
71 + ACE_OS::strlen (this->token_name_
) + 1
72 + ACE_OS::strlen (this->client_id_
) + 1
75 // Make sure the message was correctly received and framed.
76 return this->length () == data_size
? 0 : -1;
79 // Print out the current values of the ACE_Token_Request.
82 ACE_Token_Request::dump () const
84 #if defined (ACE_HAS_DUMP)
85 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
86 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("*******\nlength = %d\ntoken name = %s\nclient id = %s\n"),
87 this->length (), this->token_name (), this->client_id ()));
88 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("type = ")));
90 if (this->token_type () == ACE_Tokens::MUTEX
)
91 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("MUTEX\n")));
92 else // == ACE_Tokens::RWLOCK
94 if (this->proxy_type () == ACE_RW_Token::READER
)
95 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("RLOCK\n")));
97 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("WLOCK\n")));
100 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("operation = ")));
101 switch (this->operation_type ())
103 case ACE_Token_Request::ACQUIRE
:
104 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("ACQUIRE\n")));
106 case ACE_Token_Request::RELEASE
:
107 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("RELEASE\n")));
109 case ACE_Token_Request::RENEW
:
110 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("RENEW\n")));
113 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("<unknown operation type> = %d\n"), this->operation_type ()));
117 if (this->options ()[ACE_Synch_Options::USE_TIMEOUT
] == 0)
118 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("blocking forever\n")));
121 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("waiting for %d secs and %d usecs\n"),
122 this->options ().timeout ().sec (), this->options ().timeout ().usec ()));
124 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
125 #endif /* ACE_HAS_DUMP */
128 // ************************************************************
129 // ************************************************************
130 // ************************************************************
132 // Create a ACE_Token_Reply message.
134 ACE_Token_Reply::ACE_Token_Reply () // Type of reply.
138 this->length (sizeof (Transfer
));
141 // Encode the transfer buffer into network byte order
142 // so that it can be sent to the client.
145 ACE_Token_Reply::encode (void *&buf
)
147 buf
= (void *) &this->transfer_
;
148 return this->length ();
151 // Decode the transfer buffer into host byte order
152 // so that it can be used by the client.
155 ACE_Token_Reply::decode ()
160 // Print out current values of the ACE_Token_Reply object.
163 ACE_Token_Reply::dump () const
165 #if defined (ACE_HAS_DUMP)
166 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("*******\nlength = %d\nerrnum = %d"),
167 this->length (), this->errnum ()));
168 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("arg = %d"), this->arg ()));
169 #endif /* ACE_HAS_DUMP */
172 ACE_END_VERSIONED_NAMESPACE_DECL
174 #endif /* ACE_HAS_TOKENS_LIBRARY */