Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Dynamic / server_interceptor.cpp
blob4f12e95e2d577e2963d598d00f3d83d56f588118
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 "ace/OS_NS_string.h"
11 Echo_Server_Request_Interceptor::Echo_Server_Request_Interceptor (void)
12 : myname_ ("Echo_Server_Interceptor")
16 Echo_Server_Request_Interceptor::~Echo_Server_Request_Interceptor ()
20 char *
21 Echo_Server_Request_Interceptor::name (void)
23 return CORBA::string_dup (this->myname_);
26 void
27 Echo_Server_Request_Interceptor::destroy (void)
31 void
32 Echo_Server_Request_Interceptor::receive_request_service_contexts (
33 PortableInterceptor::ServerRequestInfo_ptr)
37 void
38 Echo_Server_Request_Interceptor::receive_request (
39 PortableInterceptor::ServerRequestInfo_ptr ri)
41 bool catched_exception = false;
42 try
44 PortableInterceptor::ReplyStatus rstatus = ri->reply_status ();
45 ACE_UNUSED_ARG (rstatus);
47 catch (const ::CORBA::BAD_INV_ORDER&)
49 catched_exception = true;
52 if (!catched_exception)
54 ACE_ERROR ((LM_ERROR,
55 "(%P|%t) ERROR, no exception when getting reply status\n"));
58 CORBA::String_var op = ri->operation ();
60 ACE_DEBUG ((LM_DEBUG,
61 "Echo_Server_Request_Interceptor::receive_request from \"%C\"\n",
62 op.in ()));
64 if (ACE_OS::strcmp (op.in (), "normal") == 0)
66 Dynamic::ParameterList_var paramlist =
67 ri->arguments ();
69 CORBA::Long param;
70 CORBA::ULong i = 0; // index -- explicitly used to avoid
71 // overloaded operator ambiguity.
72 paramlist[i].argument >>= param;
74 ACE_DEBUG ((LM_DEBUG,
75 "The arg is %d\n",
76 param));
78 i = 1;
79 CORBA::TypeCode_var second_typecode = paramlist[i].argument.type ();
80 if (second_typecode->kind () != CORBA::tk_null)
82 ACE_ERROR ((LM_ERROR,
83 "(%P|%t) ERROR in receive_request while checking "
84 "the type of the extracted out"
85 "argument\n"));
89 CORBA::String_var tmdi =
90 ri->target_most_derived_interface ();
92 ACE_DEBUG ((LM_DEBUG,
93 "Target most derived interface: %C\n",
94 tmdi.in ()));
97 void
98 Echo_Server_Request_Interceptor::send_reply (
99 PortableInterceptor::ServerRequestInfo_ptr ri)
102 CORBA::String_var op = ri->operation ();
104 ACE_DEBUG ((LM_DEBUG,
105 "Echo_Server_Request_Interceptor::send_reply from \"%C\"\n",
106 op.in ()));
108 if (ACE_OS::strcmp (op.in (), "normal") == 0)
110 Dynamic::ParameterList_var paramlist =
111 ri->arguments ();
113 CORBA::Long param;
114 CORBA::ULong i = 0; // index -- explicitly used to avoid
115 // overloaded operator ambiguity.
116 paramlist[i].argument >>= param;
117 ACE_DEBUG ((LM_DEBUG,
118 "The arg is %d\n",
119 param));
122 if (ACE_OS::strcmp (op.in (), "calculate") == 0)
124 Dynamic::ParameterList_var paramlist =
125 ri->arguments ();
127 CORBA::Long param1, param2, result = 0;
128 CORBA::ULong i = 0; // index -- explicitly used to avoid
129 // overloaded operator ambiguity.
130 paramlist[i++].argument >>= param1;
131 paramlist[i].argument >>= param2;
133 CORBA::Any_var result_any = ri->result ();
135 (result_any.in ()) >>= result;
137 ACE_DEBUG ((LM_DEBUG,
138 "The result of calculate is %d + %d = %d\n",
139 param1,
140 param2,
141 result));
145 void
146 Echo_Server_Request_Interceptor::send_exception (
147 PortableInterceptor::ServerRequestInfo_ptr ri)
150 CORBA::String_var op = ri->operation ();
152 ACE_DEBUG ((LM_DEBUG,
153 "Echo_Server_Request_Interceptor::send_exception "
154 "from \"%C\"\n",
155 op.in ()));
158 CORBA::Any_var any =
159 ri->sending_exception ();
161 CORBA::TypeCode_var type = any->type ();
163 const char *exception_id = type->id ();
165 ACE_DEBUG ((LM_DEBUG,
166 "Exception ID = %C\n",
167 exception_id));
170 void
171 Echo_Server_Request_Interceptor::send_other (
172 PortableInterceptor::ServerRequestInfo_ptr)
174 // Do Nothing