Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Benchmark / client_interceptors.cpp
blob2b058217bb8665b232df5799f1c33d1d521d6bbe
1 #include "client_interceptors.h"
3 #include "tao/AnyTypeCode/DynamicC.h"
4 #include "tao/AnyTypeCode/TypeCode.h"
5 #include "ace/OS_NS_string.h"
6 #include "ace/Log_Msg.h"
8 const CORBA::ULong request_ctx_id = 0xdead;
9 //const CORBA::ULong reply_ctx_id = 0xbeef; // Never used.
11 Vault_Client_Request_Interceptor::Vault_Client_Request_Interceptor ()
12 : myname_ ("Vault_Client_Interceptor")
16 Vault_Client_Request_Interceptor::~Vault_Client_Request_Interceptor ()
20 char *
21 Vault_Client_Request_Interceptor::name ()
23 return CORBA::string_dup (this->myname_);
26 void
27 Vault_Client_Request_Interceptor::destroy ()
31 void
32 Vault_Client_Request_Interceptor::send_poll (
33 PortableInterceptor::ClientRequestInfo_ptr)
35 // Do nothing
38 void
39 Vault_Client_Request_Interceptor::send_request (
40 PortableInterceptor::ClientRequestInfo_ptr ri)
42 CORBA::String_var op = ri->operation ();
44 if (ACE_OS::strcmp (op.in (), "authenticate") == 0)
46 // Make the context to send the context to the target.
47 IOP::ServiceContext sc;
48 sc.context_id = request_ctx_id;
50 const char passwd[] = "root123";
51 CORBA::ULong string_len = sizeof (passwd) + 1;
52 CORBA::Octet *buf = 0;
53 ACE_NEW (buf,
54 CORBA::Octet [string_len]);
55 ACE_OS::strcpy (reinterpret_cast<char *> (buf), passwd);
57 sc.context_data.replace (string_len, string_len, buf, 1);
59 // Add this context to the service context list.
60 ri->add_request_service_context (sc, 0);
63 if (ACE_OS::strcmp (op.in (), "update_records") == 0)
65 Dynamic::ParameterList_var paramlist =
66 ri->arguments ();
68 const Test_Interceptors::Secure_Vault::Record *record = 0;
69 CORBA::Long id;
70 CORBA::ULong i = 0; // index -- explicitly used to avoid
71 // overloaded operator ambiguity.
72 paramlist[i++].argument >>= id;
73 paramlist[i].argument >>= record;
77 void
78 Vault_Client_Request_Interceptor::receive_reply (
79 PortableInterceptor::ClientRequestInfo_ptr ri)
81 CORBA::String_var op = ri->operation ();
83 if (ACE_OS::strcmp (op.in (), "update_records") == 0)
85 CORBA::Long result;
86 CORBA::Any_var result_any = ri->result ();
88 (result_any.in ()) >>= result;
92 void
93 Vault_Client_Request_Interceptor::receive_other (
94 PortableInterceptor::ClientRequestInfo_ptr)
96 // Do nothing
99 void
100 Vault_Client_Request_Interceptor::receive_exception (
101 PortableInterceptor::ClientRequestInfo_ptr ri)
103 CORBA::Any_var any = ri->received_exception ();
105 CORBA::TypeCode_var tc = any->type ();
107 const char *id = tc->id ();
109 CORBA::String_var exception_id =
110 ri->received_exception_id ();
112 if (ACE_OS::strcmp (id, exception_id.in ()) != 0)
113 ACE_ERROR ((LM_ERROR,
114 "Mismatched exception IDs: %s != %s\n",
116 exception_id.in ()));
120 ////////////////////////////////// Context /////////////////////////
122 Vault_Client_Request_Context_Interceptor::Vault_Client_Request_Context_Interceptor ()
123 : myname_ ("Vault_Client_Context_Interceptor")
127 Vault_Client_Request_Context_Interceptor::~Vault_Client_Request_Context_Interceptor ()
131 char *
132 Vault_Client_Request_Context_Interceptor::name ()
134 return CORBA::string_dup (this->myname_);
137 void
138 Vault_Client_Request_Context_Interceptor::destroy ()
142 void
143 Vault_Client_Request_Context_Interceptor::send_poll (
144 PortableInterceptor::ClientRequestInfo_ptr)
146 // Do nothing
149 void
150 Vault_Client_Request_Context_Interceptor::send_request (
151 PortableInterceptor::ClientRequestInfo_ptr ri)
153 // MAke the context to send the context to the target
154 IOP::ServiceContext sc;
155 sc.context_id = request_ctx_id;
157 const char passwd[] = "root123";
158 CORBA::ULong string_len = sizeof (passwd) + 1;
159 CORBA::Octet *buf = 0;
160 ACE_NEW_THROW_EX (buf,
161 CORBA::Octet [string_len],
162 CORBA::NO_MEMORY ());
164 ACE_OS::strcpy (reinterpret_cast<char *> (buf), passwd);
166 sc.context_data.replace (string_len, string_len, buf, 1);
168 // Add this context to the service context list.
169 ri->add_request_service_context (sc, 0);
172 void
173 Vault_Client_Request_Context_Interceptor::receive_other (
174 PortableInterceptor::ClientRequestInfo_ptr)
176 // Do nothing
179 void
180 Vault_Client_Request_Context_Interceptor::receive_reply (
181 PortableInterceptor::ClientRequestInfo_ptr)
185 void
186 Vault_Client_Request_Context_Interceptor::receive_exception (
187 PortableInterceptor::ClientRequestInfo_ptr ri)
189 CORBA::Any_var any = ri->received_exception ();
191 CORBA::TypeCode_var tc = any->type ();
193 const char *id = tc->id ();
195 CORBA::String_var exception_id =
196 ri->received_exception_id ();
198 if (ACE_OS::strcmp (id, exception_id.in ()) != 0)
199 ACE_ERROR ((LM_ERROR,
200 "Mismatched exception IDs %s != %s\n",
202 exception_id.in ()));
206 ///////////////////////////////////Dynamic ////////////////////////////////////
208 Vault_Client_Request_Dynamic_Interceptor::Vault_Client_Request_Dynamic_Interceptor ()
209 : myname_ ("Vault_Client_Dynamic_Interceptor")
213 Vault_Client_Request_Dynamic_Interceptor::~Vault_Client_Request_Dynamic_Interceptor ()
217 char *
218 Vault_Client_Request_Dynamic_Interceptor::name ()
220 return CORBA::string_dup (this->myname_);
223 void
224 Vault_Client_Request_Dynamic_Interceptor::destroy ()
228 void
229 Vault_Client_Request_Dynamic_Interceptor::send_poll (
230 PortableInterceptor::ClientRequestInfo_ptr)
232 // Do nothing
235 void
236 Vault_Client_Request_Dynamic_Interceptor::send_request (
237 PortableInterceptor::ClientRequestInfo_ptr ri)
239 CORBA::String_var op = ri->operation ();
241 if (ACE_OS::strcmp (op.in (), "authenticate") == 0)
243 Dynamic::ParameterList_var paramlist =
244 ri->arguments ();
246 const char *user;
247 CORBA::ULong i = 0; // index -- explicitly used to avoid
248 // overloaded operator ambiguity.
249 paramlist[i].argument >>= user;
252 if (ACE_OS::strcmp (op.in (), "update_records") == 0)
254 Dynamic::ParameterList_var paramlist =
255 ri->arguments ();
257 const Test_Interceptors::Secure_Vault::Record *record = 0;
258 CORBA::Long id;
259 CORBA::ULong i = 0; // index -- explicitly used to avoid
260 // overloaded operator ambiguity.
261 paramlist[i++].argument >>= id;
262 paramlist[i].argument >>= record;
266 void
267 Vault_Client_Request_Dynamic_Interceptor::receive_reply (
268 PortableInterceptor::ClientRequestInfo_ptr ri)
270 CORBA::String_var op = ri->operation ();
272 if (ACE_OS::strcmp (op.in (), "ready") == 0)
274 CORBA::Short result;
276 CORBA::Any_var result_any = ri->result ();
278 (result_any.in ()) >>= result;
281 if (ACE_OS::strcmp (op.in (), "update_records") == 0)
283 CORBA::Long result;
285 CORBA::Any_var result_any = ri->result ();
287 (result_any.in ()) >>= result;
291 void
292 Vault_Client_Request_Dynamic_Interceptor::receive_other (
293 PortableInterceptor::ClientRequestInfo_ptr)
295 // Do nothing
298 void
299 Vault_Client_Request_Dynamic_Interceptor::receive_exception (
300 PortableInterceptor::ClientRequestInfo_ptr ri)
302 CORBA::Any_var any = ri->received_exception ();
304 CORBA::TypeCode_var tc = any->type ();
306 const char *id = tc->id ();
308 CORBA::String_var exception_id =
309 ri->received_exception_id ();
311 if (ACE_OS::strcmp (id, exception_id.in ()) != 0)
312 ACE_ERROR ((LM_ERROR,
313 "Mismatched exception IDs %s != %s\n",
315 exception_id.in ()));
319 //////////////////////////////NOOP///////////////////////////////////////
321 Vault_Client_Request_NOOP_Interceptor::Vault_Client_Request_NOOP_Interceptor ()
322 : myname_ ("Vault_Client_NOOP_Interceptor")
326 Vault_Client_Request_NOOP_Interceptor::~Vault_Client_Request_NOOP_Interceptor ()
330 char *
331 Vault_Client_Request_NOOP_Interceptor::name ()
333 return CORBA::string_dup (this->myname_);
336 void
337 Vault_Client_Request_NOOP_Interceptor::destroy ()
341 void
342 Vault_Client_Request_NOOP_Interceptor::send_poll (
343 PortableInterceptor::ClientRequestInfo_ptr)
345 // Do nothing
348 void
349 Vault_Client_Request_NOOP_Interceptor::send_request (
350 PortableInterceptor::ClientRequestInfo_ptr)
354 void
355 Vault_Client_Request_NOOP_Interceptor::receive_other (
356 PortableInterceptor::ClientRequestInfo_ptr)
358 // Do nothing
361 void
362 Vault_Client_Request_NOOP_Interceptor::receive_reply (
363 PortableInterceptor::ClientRequestInfo_ptr)
367 void
368 Vault_Client_Request_NOOP_Interceptor::receive_exception (
369 PortableInterceptor::ClientRequestInfo_ptr ri)
371 CORBA::Any_var any = ri->received_exception ();
373 CORBA::TypeCode_var tc = any->type ();
375 const char *id = tc->id ();
377 CORBA::String_var exception_id =
378 ri->received_exception_id ();
380 if (ACE_OS::strcmp (id, exception_id.in ()) != 0)
381 ACE_ERROR ((LM_ERROR,
382 "Mismatched exception IDs %s != %s\n",
384 exception_id.in ()));