Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Dynamic / client_interceptor.cpp
blobaf4dab6e0b9a6e24ab940737da514be7496d7a5c
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 "ace/OS_NS_string.h"
11 Echo_Client_Request_Interceptor::Echo_Client_Request_Interceptor (void)
12 : myname_ ("Echo_Client_Interceptor")
16 Echo_Client_Request_Interceptor::~Echo_Client_Request_Interceptor ()
20 char *
21 Echo_Client_Request_Interceptor::name (void)
23 return CORBA::string_dup (this->myname_);
26 void
27 Echo_Client_Request_Interceptor::destroy (void)
31 void
32 Echo_Client_Request_Interceptor::send_poll (
33 PortableInterceptor::ClientRequestInfo_ptr)
35 // Do nothing
38 void
39 Echo_Client_Request_Interceptor::send_request (
40 PortableInterceptor::ClientRequestInfo_ptr ri)
42 bool catched_exception = false;
43 try
45 PortableInterceptor::ReplyStatus rstatus = ri->reply_status ();
46 ACE_UNUSED_ARG (rstatus);
48 catch (const ::CORBA::BAD_INV_ORDER&)
50 catched_exception = true;
53 if (!catched_exception)
55 ACE_ERROR ((LM_ERROR,
56 "(%P|%t) ERROR, no exception when getting reply status\n"));
59 CORBA::String_var op = ri->operation ();
61 ACE_DEBUG ((LM_DEBUG,
62 "Echo_Client_Request_Interceptor::send_request from "
63 "\"%C\"\n",
64 op.in ()));
66 // For the "normal" operation, get the argument list.
67 if (ACE_OS::strcmp (op.in (),
68 "normal") == 0)
70 Dynamic::ParameterList_var paramlist =
71 ri->arguments ();
73 if (paramlist->length () != 2)
75 ACE_ERROR ((LM_ERROR,
76 "(%P|%t) All parameters not available\n"));
80 CORBA::ULong first = 0, second = 1; // If you dont understand
81 // why this is done, then
82 // try changing it.
83 if (paramlist[first].mode != CORBA::PARAM_IN ||
84 paramlist[second].mode != CORBA::PARAM_OUT)
86 ACE_ERROR ((LM_ERROR,
87 "(%P|%t) ERROR in the extracted argument list\n"));
90 CORBA::Long param = 0;
91 paramlist[first].argument >>= param;
93 if (param != 10)
95 ACE_ERROR ((LM_ERROR,
96 "(%P|%t) ERROR in send_request while checking "
97 "the value of the extracted "
98 "arguments\n"));
101 CORBA::TypeCode_var second_typecode = paramlist[second].argument.type ();
102 if (second_typecode->kind () != CORBA::tk_null)
104 ACE_ERROR ((LM_ERROR,
105 "(%P|%t) ERROR in send_request while checking "
106 "the type of the extracted out"
107 "argument\n"));
112 void
113 Echo_Client_Request_Interceptor::receive_other (
114 PortableInterceptor::ClientRequestInfo_ptr ri)
117 CORBA::String_var op = ri->operation ();
119 ACE_DEBUG ((LM_DEBUG,
120 "Echo_Client_Request_Interceptor::receive_other "
121 "from \"%C\"\n",
122 op.in ()));
125 void
126 Echo_Client_Request_Interceptor::receive_reply (
127 PortableInterceptor::ClientRequestInfo_ptr ri)
129 CORBA::String_var op = ri->operation ();
131 ACE_DEBUG ((LM_DEBUG,
132 "Echo_Client_Request_Interceptor::receive_reply "
133 "from \"%C\"\n",
134 op.in ()));
136 // For the "normal" operation, get the argument list.
137 if (ACE_OS::strcmp (op.in (),
138 "normal") == 0)
140 Dynamic::ParameterList_var paramlist =
141 ri->arguments ();
143 if (paramlist->length () != 2)
145 ACE_ERROR ((LM_ERROR,
146 "(%P|%t) All parameters not available\n"));
150 CORBA::ULong first = 0, second = 1; // If you dont understand
151 // why this is done, then
152 // try changing it.
153 if (paramlist[first].mode != CORBA::PARAM_IN ||
154 paramlist[second].mode != CORBA::PARAM_OUT)
156 ACE_ERROR ((LM_ERROR,
157 "(%P|%t) ERROR in the extracted argument list\n"));
160 CORBA::Long param = 0;
161 paramlist[first].argument >>= param;
163 if (param != 10)
165 ACE_ERROR ((LM_ERROR,
166 "(%P|%t) ERROR in send_request while checking "
167 "the value of the extracted "
168 "arguments\n"));
171 const char *str = 0;
173 paramlist[second].argument >>= str;
175 CORBA::String_var transfer (str);
177 if (ACE_OS::strcmp (str,
178 "DO_NOT_INSULT_MY_INTELLIGENCE") != 0)
180 ACE_ERROR ((LM_ERROR,
181 "(%P|%t) ERROR in send_request while checking "
182 "the value of the extracted "
183 "out arguments\n"));
187 if (ACE_OS::strcmp (op.in (), "calculate") == 0)
189 Dynamic::ParameterList_var paramlist =
190 ri->arguments ();
192 CORBA::Long param1, param2, result;
193 CORBA::ULong i = 0; // index -- explicitly used to avoid
194 // overloaded operator ambiguity.
195 paramlist[i++].argument >>= param1;
196 paramlist[i].argument >>= param2;
198 CORBA::Any_var result_any = ri->result ();
200 (result_any.in ()) >>= result;
202 ACE_DEBUG ((LM_DEBUG,
203 "The result of calculate() is %d + %d = %d\n",
204 param1,
205 param2,
206 result));
209 if (ACE_OS::strcmp (op.in (), "_get_the_structure") == 0)
211 CORBA::Any_var a = ri->result ();
213 const Test_Interceptors::Visual::VarLenStruct * v = 0;
215 (a.in ()) >>= v;
217 ACE_DEBUG ((LM_DEBUG,
218 "The result of the_structure() is:\n"
219 " flag = %d\n"
220 " message = %C\n",
221 v->flag,
222 v->message.in ()));
226 void
227 Echo_Client_Request_Interceptor::receive_exception (
228 PortableInterceptor::ClientRequestInfo_ptr ri)
231 CORBA::String_var op = ri->operation ();
233 ACE_DEBUG ((LM_DEBUG,
234 "Echo_Client_Request_Interceptor::received_exception "
235 "from \"%C\"\n",
236 op.in ()));
239 CORBA::String_var exception_id =
240 ri->received_exception_id ();
242 ACE_DEBUG ((LM_DEBUG,
243 "Exception ID = %C\n",
244 exception_id.in ()));