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__ */
11 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
13 // Default "do nothing" constructor.
15 ACE_Token_Request::ACE_Token_Request (void)
21 // Create a ACE_Token_Request message.
23 ACE_Token_Request::ACE_Token_Request (int token_type
,
25 ACE_UINT32 operation_type
,
26 const ACE_TCHAR token_name
[],
27 const ACE_TCHAR client_id
[],
28 const ACE_Synch_Options
&options
)
30 this->token_type (token_type
);
31 this->proxy_type (proxy_type
);
32 this->operation_type (operation_type
);
33 this->requeue_position (0); // to avoid Purify UMR
34 this->notify (0); // to avoid Purify UMR
35 transfer_
.arg_
= 0; // to avoid Purify UMR
36 ACE_OS::memset (transfer_
.data_
, 0, sizeof transfer_
.data_
); // to avoid Purify UMR
37 this->token_name (token_name
, client_id
);
38 this->options (options
);
41 // Encode the transfer buffer into network byte order
42 // so that it can be sent to the server.
45 ACE_Token_Request::encode (void *&buf
)
47 buf
= (void *) &this->transfer_
;
48 return this->length ();
51 // Decode the transfer buffer into host byte byte order
52 // so that it can be used by the server.
55 ACE_Token_Request::decode (void)
57 this->token_name_
= this->transfer_
.data_
;
59 options_
.set (transfer_
.use_timeout_
== 1 ? ACE_Synch_Options::USE_TIMEOUT
: 0,
60 ACE_Time_Value (transfer_
.sec_
, transfer_
.usec_
),
61 (void *) transfer_
.arg_
);
63 // Decode the variable-sized portion.
64 size_t token_len
= ACE_OS::strlen (this->token_name_
);
66 // Check to make sure this->tokenName_ isn't too long!
67 if (token_len
>= ACE_MAXTOKENNAMELEN
)
72 else // Skip this->tokenName_ + '\0' + ':'.
74 &this->token_name_
[(token_len
+ 2) * sizeof (ACE_TCHAR
)];
77 // token_name_ plus '\0'
79 // client_id_ plus '\0'
80 size_t data_size
= ACE_TOKEN_REQUEST_HEADER_SIZE
81 + ACE_OS::strlen (this->token_name_
) + 1
82 + ACE_OS::strlen (this->client_id_
) + 1
85 // Make sure the message was correctly received and framed.
86 return this->length () == data_size
? 0 : -1;
89 // Print out the current values of the ACE_Token_Request.
92 ACE_Token_Request::dump (void) const
94 #if defined (ACE_HAS_DUMP)
95 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
96 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("*******\nlength = %d\ntoken name = %s\nclient id = %s\n"),
97 this->length (), this->token_name (), this->client_id ()));
98 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("type = ")));
100 if (this->token_type () == ACE_Tokens::MUTEX
)
101 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("MUTEX\n")));
102 else // == ACE_Tokens::RWLOCK
104 if (this->proxy_type () == ACE_RW_Token::READER
)
105 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("RLOCK\n")));
107 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("WLOCK\n")));
110 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("operation = ")));
111 switch (this->operation_type ())
113 case ACE_Token_Request::ACQUIRE
:
114 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("ACQUIRE\n")));
116 case ACE_Token_Request::RELEASE
:
117 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("RELEASE\n")));
119 case ACE_Token_Request::RENEW
:
120 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("RENEW\n")));
123 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("<unknown operation type> = %d\n"), this->operation_type ()));
127 if (this->options ()[ACE_Synch_Options::USE_TIMEOUT
] == 0)
128 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("blocking forever\n")));
131 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("waiting for %d secs and %d usecs\n"),
132 this->options ().timeout ().sec (), this->options ().timeout ().usec ()));
134 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
135 #endif /* ACE_HAS_DUMP */
138 // ************************************************************
139 // ************************************************************
140 // ************************************************************
142 // Create a ACE_Token_Reply message.
144 ACE_Token_Reply::ACE_Token_Reply (void) // Type of reply.
148 this->length (sizeof (Transfer
));
151 // Encode the transfer buffer into network byte order
152 // so that it can be sent to the client.
155 ACE_Token_Reply::encode (void *&buf
)
157 buf
= (void *) &this->transfer_
;
158 return this->length ();
161 // Decode the transfer buffer into host byte order
162 // so that it can be used by the client.
165 ACE_Token_Reply::decode (void)
170 // Print out current values of the ACE_Token_Reply object.
173 ACE_Token_Reply::dump (void) const
175 #if defined (ACE_HAS_DUMP)
176 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("*******\nlength = %d\nerrnum = %d"),
177 this->length (), this->errnum ()));
178 ACELIB_DEBUG ((LM_DEBUG
, ACE_TEXT ("arg = %d"), this->arg ()));
179 #endif /* ACE_HAS_DUMP */
182 ACE_END_VERSIONED_NAMESPACE_DECL
184 #endif /* ACE_HAS_TOKENS_LIBRARY */