Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Dynamic / server_interceptor.cpp
blob222a168df487169df3414372dbe5921872765811
1 #include "tao/AnyTypeCode/TypeCode.h"
2 #include "tao/AnyTypeCode/AnyTypeCode_Adapter_Impl.h"
3 #include "tao/AnyTypeCode/DynamicC.h"
5 #include "server_interceptor.h"
6 #include "testC.h"
8 #include "ace/Log_Msg.h"
9 #include <cstring>
11 Echo_Server_Request_Interceptor::Echo_Server_Request_Interceptor (int& result)
12 : result_ (result)
16 char *
17 Echo_Server_Request_Interceptor::name ()
19 return CORBA::string_dup ("Echo_Server_Interceptor");
22 void
23 Echo_Server_Request_Interceptor::destroy ()
27 void
28 Echo_Server_Request_Interceptor::receive_request_service_contexts (
29 PortableInterceptor::ServerRequestInfo_ptr ri)
31 bool catched_exception = false;
32 try
34 CORBA::String_var tmdi = ri->target_most_derived_interface ();
36 catch (const ::CORBA::BAD_INV_ORDER& ex)
38 // BAD_INV_ORDER should be thrown with minor code 14
39 catched_exception = (ex.minor () == (CORBA::OMGVMCID | 14));
42 if (!catched_exception)
44 ++this->result_;
45 ACE_ERROR ((LM_ERROR,
46 "(%P|%t) ERROR, no exception when calling target_most_derived_interface from receive_request_service_contexts\n"));
49 catched_exception = false;
50 try
52 CORBA::Boolean const tmdi = ri->target_is_a ("FOO");
53 ACE_UNUSED_ARG(tmdi);
55 catch (const ::CORBA::BAD_INV_ORDER& ex)
57 // BAD_INV_ORDER should be thrown with minor code 14
58 catched_exception = (ex.minor () == (CORBA::OMGVMCID | 14));
61 if (!catched_exception)
63 ++this->result_;
64 ACE_ERROR ((LM_ERROR,
65 "(%P|%t) ERROR, no exception when calling target_is_a from receive_request_service_contexts\n"));
68 catched_exception = false;
69 try
71 PortableInterceptor::ReplyStatus const tmdi = ri->reply_status ();
72 ACE_UNUSED_ARG(tmdi);
74 catch (const ::CORBA::BAD_INV_ORDER& ex)
76 // BAD_INV_ORDER should be thrown with minor code 14
77 catched_exception = (ex.minor () == (CORBA::OMGVMCID | 14));
80 if (!catched_exception)
82 ++this->result_;
83 ACE_ERROR ((LM_ERROR,
84 "(%P|%t) ERROR, no exception when calling reply_status from receive_request_service_contexts\n"));
87 catched_exception = false;
88 try
90 Dynamic::ParameterList_var paramlist = ri->arguments ();
92 catch (const ::CORBA::BAD_INV_ORDER& ex)
94 // BAD_INV_ORDER should be thrown with minor code 14
95 catched_exception = (ex.minor () == (CORBA::OMGVMCID | 14));
98 if (!catched_exception)
100 ++this->result_;
101 ACE_ERROR ((LM_ERROR,
102 "(%P|%t) ERROR, no exception when calling arguments from receive_request_service_contexts\n"));
106 void
107 Echo_Server_Request_Interceptor::receive_request (
108 PortableInterceptor::ServerRequestInfo_ptr ri)
110 bool catched_exception = false;
113 PortableInterceptor::ReplyStatus rstatus = ri->reply_status ();
114 ACE_UNUSED_ARG (rstatus);
116 catch (const ::CORBA::BAD_INV_ORDER& ex)
118 // BAD_INV_ORDER should be thrown with minor code 14
119 catched_exception = (ex.minor () == (CORBA::OMGVMCID | 14));
122 if (!catched_exception)
124 ++this->result_;
125 ACE_ERROR ((LM_ERROR,
126 "(%P|%t) ERROR, no exception when getting reply status\n"));
129 CORBA::String_var op = ri->operation ();
131 ACE_DEBUG ((LM_DEBUG,
132 "Echo_Server_Request_Interceptor::receive_request from \"%C\"\n",
133 op.in ()));
135 CORBA::Boolean targetisa = ri->target_is_a ("FOO");
136 if (targetisa)
138 ++this->result_;
139 ACE_ERROR ((LM_ERROR,
140 "(%P|%t) ERROR in receive_request while checking "
141 "target_is_a, it is not a FOO\n"));
143 targetisa = ri->target_is_a ("IDL:Test_Interceptors/Visual:1.0");
144 if (!targetisa)
146 ++this->result_;
147 ACE_ERROR ((LM_ERROR,
148 "(%P|%t) ERROR in receive_request while checking "
149 "target_is_a, it should be IDL:Test_Interceptors/Visual:1.0\n"));
152 if (std::strcmp (op.in (), "normal") == 0)
154 Dynamic::ParameterList_var paramlist = ri->arguments ();
156 CORBA::Long param;
157 CORBA::ULong i = 0; // index -- explicitly used to avoid
158 // overloaded operator ambiguity.
159 paramlist[i].argument >>= param;
161 ACE_DEBUG ((LM_DEBUG,
162 "The arg is %d\n",
163 param));
165 i = 1;
166 CORBA::TypeCode_var second_typecode = paramlist[i].argument.type ();
167 if (second_typecode->kind () != CORBA::tk_null)
169 ++this->result_;
170 ACE_ERROR ((LM_ERROR,
171 "(%P|%t) ERROR in receive_request while checking "
172 "the type of the extracted out"
173 "argument\n"));
177 CORBA::String_var tmdi = ri->target_most_derived_interface ();
179 ACE_DEBUG ((LM_DEBUG,
180 "Target most derived interface: %C\n",
181 tmdi.in ()));
183 if (std::strcmp (tmdi.in (), "IDL:Test_Interceptors/Visual:1.0") != 0)
185 ++this->result_;
186 ACE_ERROR ((LM_ERROR,
187 "(%P|%t) ERROR in receive_request while checking "
188 "target_most_derived_interface\n"));
191 catched_exception = false;
194 PortableInterceptor::ReplyStatus const tmdi = ri->reply_status ();
195 ACE_UNUSED_ARG(tmdi);
197 catch (const ::CORBA::BAD_INV_ORDER& ex)
199 // BAD_INV_ORDER should be thrown with minor code 14
200 catched_exception = (ex.minor () == (CORBA::OMGVMCID | 14));
203 if (!catched_exception)
205 ++this->result_;
206 ACE_ERROR ((LM_ERROR,
207 "(%P|%t) ERROR, no exception when calling reply_status from receive_request\n"));
211 void
212 Echo_Server_Request_Interceptor::send_reply (PortableInterceptor::ServerRequestInfo_ptr ri)
214 CORBA::String_var op = ri->operation ();
216 ACE_DEBUG ((LM_DEBUG,
217 "Echo_Server_Request_Interceptor::send_reply from \"%C\"\n",
218 op.in ()));
220 if (std::strcmp (op.in (), "normal") == 0)
222 Dynamic::ParameterList_var paramlist = ri->arguments ();
224 CORBA::Long param;
225 CORBA::ULong i = 0; // index -- explicitly used to avoid
226 // overloaded operator ambiguity.
227 paramlist[i].argument >>= param;
228 ACE_DEBUG ((LM_DEBUG,
229 "The arg is %d\n",
230 param));
233 if (std::strcmp (op.in (), "calculate") == 0)
235 Dynamic::ParameterList_var paramlist = ri->arguments ();
237 CORBA::Long param1, param2, result = 0;
238 CORBA::ULong i = 0; // index -- explicitly used to avoid
239 // overloaded operator ambiguity.
240 paramlist[i++].argument >>= param1;
241 paramlist[i].argument >>= param2;
243 CORBA::Any_var result_any = ri->result ();
245 (result_any.in ()) >>= result;
247 ACE_DEBUG ((LM_DEBUG,
248 "The result of calculate is %d + %d = %d\n",
249 param1,
250 param2,
251 result));
255 void
256 Echo_Server_Request_Interceptor::send_exception (
257 PortableInterceptor::ServerRequestInfo_ptr ri)
259 CORBA::String_var op = ri->operation ();
261 ACE_DEBUG ((LM_DEBUG,
262 "Echo_Server_Request_Interceptor::send_exception "
263 "from \"%C\"\n",
264 op.in ()));
266 CORBA::Any_var any = ri->sending_exception ();
268 CORBA::TypeCode_var type = any->type ();
270 CORBA::String_var exception_id = type->id ();
272 ACE_DEBUG ((LM_DEBUG,
273 "Exception ID = %C\n",
274 exception_id.in ()));
277 void
278 Echo_Server_Request_Interceptor::send_other (
279 PortableInterceptor::ServerRequestInfo_ptr)
281 // Do Nothing