Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Dynamic / client_interceptor.cpp
blobe42b70344cabdf5fbcfc9fb3c22cf9738517981b
1 #include "client_interceptor.h"
2 #include "testC.h"
4 #include "tao/AnyTypeCode/DynamicC.h"
5 #include "tao/AnyTypeCode/TypeCode.h"
6 #include "tao/AnyTypeCode/AnyTypeCode_Adapter_Impl.h"
8 #include "ace/Log_Msg.h"
9 #include <cstring>
11 Echo_Client_Request_Interceptor::Echo_Client_Request_Interceptor (int& result)
12 : result_ (result)
16 char *
17 Echo_Client_Request_Interceptor::name ()
19 return CORBA::string_dup ("Echo_Client_Interceptor");
22 void
23 Echo_Client_Request_Interceptor::destroy ()
27 void
28 Echo_Client_Request_Interceptor::send_poll (PortableInterceptor::ClientRequestInfo_ptr)
30 // Do nothing
33 void
34 Echo_Client_Request_Interceptor::send_request (PortableInterceptor::ClientRequestInfo_ptr ri)
36 bool catched_exception = false;
37 try
39 PortableInterceptor::ReplyStatus rstatus = ri->reply_status ();
40 ACE_UNUSED_ARG (rstatus);
42 catch (const ::CORBA::BAD_INV_ORDER& ex)
44 // BAD_INV_ORDER should be thrown with minor code 14
45 catched_exception = (ex.minor () == (CORBA::OMGVMCID | 14));
48 if (!catched_exception)
50 ++this->result_;
51 ACE_ERROR ((LM_ERROR,
52 "(%P|%t) ERROR, no exception when getting reply status\n"));
55 CORBA::String_var op = ri->operation ();
57 ACE_DEBUG ((LM_DEBUG,
58 "Echo_Client_Request_Interceptor::send_request from "
59 "\"%C\"\n",
60 op.in ()));
62 // For the "normal" operation, get the argument list.
63 if (std::strcmp (op.in (), "normal") == 0)
65 Dynamic::ParameterList_var paramlist = ri->arguments ();
67 if (paramlist->length () != 2)
69 ++this->result_;
70 ACE_ERROR ((LM_ERROR,
71 "(%P|%t) All parameters not available\n"));
74 CORBA::ULong first = 0, second = 1; // If you dont understand
75 // why this is done, then
76 // try changing it.
77 if (paramlist[first].mode != CORBA::PARAM_IN ||
78 paramlist[second].mode != CORBA::PARAM_OUT)
80 ACE_ERROR ((LM_ERROR,
81 "(%P|%t) ERROR in the extracted argument list\n"));
84 CORBA::Long param = 0;
85 paramlist[first].argument >>= param;
87 if (param != 10)
89 ++this->result_;
90 ACE_ERROR ((LM_ERROR,
91 "(%P|%t) ERROR in send_request while checking "
92 "the value of the extracted "
93 "arguments\n"));
96 CORBA::TypeCode_var second_typecode = paramlist[second].argument.type ();
97 if (second_typecode->kind () != CORBA::tk_null)
99 ++this->result_;
100 ACE_ERROR ((LM_ERROR,
101 "(%P|%t) ERROR in send_request while checking "
102 "the type of the extracted out"
103 "argument\n"));
108 void
109 Echo_Client_Request_Interceptor::receive_other (PortableInterceptor::ClientRequestInfo_ptr ri)
111 CORBA::String_var op = ri->operation ();
113 ACE_DEBUG ((LM_DEBUG,
114 "Echo_Client_Request_Interceptor::receive_other "
115 "from \"%C\"\n",
116 op.in ()));
119 void
120 Echo_Client_Request_Interceptor::receive_reply (PortableInterceptor::ClientRequestInfo_ptr ri)
122 CORBA::String_var op = ri->operation ();
124 ACE_DEBUG ((LM_DEBUG,
125 "Echo_Client_Request_Interceptor::receive_reply "
126 "from \"%C\"\n",
127 op.in ()));
129 // For the "normal" operation, get the argument list.
130 if (std::strcmp (op.in (), "normal") == 0)
132 Dynamic::ParameterList_var paramlist = ri->arguments ();
134 if (paramlist->length () != 2)
136 ACE_ERROR ((LM_ERROR,
137 "(%P|%t) All parameters not available\n"));
140 CORBA::ULong first = 0, second = 1; // If you dont understand
141 // why this is done, then
142 // try changing it.
143 if (paramlist[first].mode != CORBA::PARAM_IN ||
144 paramlist[second].mode != CORBA::PARAM_OUT)
146 ++this->result_;
147 ACE_ERROR ((LM_ERROR,
148 "(%P|%t) ERROR in the extracted argument list\n"));
151 CORBA::Long param = 0;
152 paramlist[first].argument >>= param;
154 if (param != 10)
156 ++this->result_;
157 ACE_ERROR ((LM_ERROR,
158 "(%P|%t) ERROR in send_request while checking "
159 "the value of the extracted "
160 "arguments\n"));
163 const char *str = 0;
165 paramlist[second].argument >>= str;
167 CORBA::String_var transfer (str);
169 if (std::strcmp (str, "DO_NOT_INSULT_MY_INTELLIGENCE") != 0)
171 ++this->result_;
172 ACE_ERROR ((LM_ERROR,
173 "(%P|%t) ERROR in send_request while checking "
174 "the value of the extracted "
175 "out arguments\n"));
179 if (std::strcmp (op.in (), "calculate") == 0)
181 Dynamic::ParameterList_var paramlist = ri->arguments ();
183 CORBA::Long param1, param2, result;
184 CORBA::ULong i = 0; // index -- explicitly used to avoid
185 // overloaded operator ambiguity.
186 paramlist[i++].argument >>= param1;
187 paramlist[i].argument >>= param2;
189 CORBA::Any_var result_any = ri->result ();
191 (result_any.in ()) >>= result;
193 ACE_DEBUG ((LM_DEBUG,
194 "The result of calculate() is %d + %d = %d\n",
195 param1,
196 param2,
197 result));
200 if (std::strcmp (op.in (), "_get_the_structure") == 0)
202 CORBA::Any_var a = ri->result ();
204 const Test_Interceptors::Visual::VarLenStruct * v = nullptr;
206 (a.in ()) >>= v;
208 ACE_DEBUG ((LM_DEBUG,
209 "The result of the_structure() is:\n"
210 " flag = %d\n"
211 " message = %C\n",
212 v->flag,
213 v->message.in ()));
217 void
218 Echo_Client_Request_Interceptor::receive_exception (
219 PortableInterceptor::ClientRequestInfo_ptr ri)
221 CORBA::String_var op = ri->operation ();
223 ACE_DEBUG ((LM_DEBUG,
224 "Echo_Client_Request_Interceptor::received_exception "
225 "from \"%C\"\n",
226 op.in ()));
228 CORBA::String_var exception_id = ri->received_exception_id ();
230 ACE_DEBUG ((LM_DEBUG,
231 "Exception ID = %C\n",
232 exception_id.in ()));