1 // author : Boris Kolpackov <boris@kolpackov.net>
2 #include "tao/AnyTypeCode/AnyTypeCode_methods.h"
5 #include "tao/PI_Server/PI_Server.h"
7 #include "tao/LocalObject.h"
8 #include "tao/ORBInitializer_Registry.h"
10 #include "ace/OS_NS_stdio.h"
11 #include "ace/Get_Opt.h"
13 #include "InvokeMeS.h"
15 using namespace CORBA
;
16 using namespace PortableServer
;
17 using namespace PortableInterceptor
;
19 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("test.ior");
22 parse_args (int argc
, ACE_TCHAR
*argv
[])
24 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
27 while ((c
= get_opts ()) != -1)
31 ior_output_file
= get_opts
.opt_arg ();
36 ACE_ERROR_RETURN ((LM_ERROR
,
43 // Indicates successful parsing of the command line
50 PortableInterceptor::SlotId slot_id
;
52 CORBA::Long
getMySlot(
53 PortableInterceptor::ServerRequestInfo_ptr ri
,
54 PortableInterceptor::Current_ptr pi_current
,
56 const CORBA::Long correctTSCvalue
,
57 const CORBA::Long correctRSCvalue
)
59 CORBA::Long number
= 0;
63 const bool correctOperation
=
64 (0 == ACE_OS::strcmp( op
.in (), "invoke_me" ));
70 ACE_DEBUG ((LM_DEBUG
, "SERVER %C -> get_slot(TSC) -> is ", location
));
71 data
= pi_current
->get_slot(slot_id
);
74 if (tc
->kind() == CORBA::tk_null
)
76 ACE_DEBUG ((LM_DEBUG
, "EMPTY -> "));
77 if (0 != correctTSCvalue
)
79 ACE_DEBUG ((LM_DEBUG
, "WRONG\n"));
82 ACE_DEBUG ((LM_DEBUG
, "OK\n"));
84 else if (data
.in() >>= number
)
86 ACE_DEBUG ((LM_DEBUG
, "long (%d) -> ", number
));
87 if ((0 != correctTSCvalue
) && (correctTSCvalue
!= number
))
89 ACE_DEBUG ((LM_DEBUG
, "WRONG\n"));
92 ACE_DEBUG ((LM_DEBUG
, "OK\n"));
96 ACE_DEBUG ((LM_DEBUG
, "UNKNOWN TYPE\n"));
100 ACE_DEBUG ((LM_DEBUG
, "SERVER %C -> get_slot(RSC) -> is ", location
));
101 data
= ri
->get_slot(slot_id
);
104 if (tc
->kind() == CORBA::tk_null
)
106 ACE_DEBUG ((LM_DEBUG
, "EMPTY -> "));
107 if (0 != correctRSCvalue
)
109 ACE_DEBUG ((LM_DEBUG
, "WRONG\n"));
112 ACE_DEBUG ((LM_DEBUG
, "OK\n"));
113 #if TAO_HAS_EXTENDED_FT_INTERCEPTORS == 1
117 #endif /* TAO_HAS_EXTENDED_FT_INTERCEPTORS == 1 */
119 else if (data
.in() >>= number
)
121 ACE_DEBUG ((LM_DEBUG
, "long (%d) -> ", number
));
122 if ((0 != correctRSCvalue
) && (correctRSCvalue
!= number
))
124 ACE_DEBUG ((LM_DEBUG
, "WRONG\n"));
127 ACE_DEBUG ((LM_DEBUG
, "OK\n"));
132 ACE_DEBUG ((LM_DEBUG
, "WRONG TYPE\n"));
140 void getAndSetMySlot(
141 PortableInterceptor::ServerRequestInfo_ptr ri
,
142 PortableInterceptor::Current_ptr pi_current
,
143 const char *location
,
144 const CORBA::Long correctTSCvalue
,
145 const CORBA::Long correctRSCvalue
)
147 const CORBA::Long number
=
155 if (number
&& (0 != ACE_OS::strcmp( location
, "receive_request" )))
157 // Insert data into the RSC (request scope current).
161 ACE_DEBUG ((LM_DEBUG
, "SERVER %C -> set_slot(RSC)", location
));
162 ri
->set_slot( slot_id
, data
);
164 ACE_DEBUG ((LM_DEBUG
, " -> long (%d)\n", number
));
177 class InvokeMeImpl
: public virtual POA_InvokeMe
180 InvokeMeImpl (ORB_ptr orb
)
181 : orb_ (ORB::_duplicate (orb
))
185 virtual void invoke_me()
187 ACE_DEBUG ((LM_DEBUG
, "invoke_me\n"));
190 //FUZZ: disable check_for_lack_ACE_OS
194 ACE_DEBUG ((LM_DEBUG
, "\nServer is shutting down.\n"));
195 this->orb_
->shutdown (false);
197 //FUZZ: enable check_for_lack_ACE_OS
205 class ReplicaController
: public virtual ServerRequestInterceptor
,
206 public virtual ::CORBA::LocalObject
208 PortableInterceptor::Current_ptr pi_current_
;
210 ReplicaController (PortableInterceptor::Current_ptr pi_current
)
211 : pi_current_( pi_current
)
218 return string_dup ("ReplicaController");
226 #if TAO_HAS_EXTENDED_FT_INTERCEPTORS == 1
228 tao_ft_interception_point (ServerRequestInfo_ptr ri
, OctetSeq_out
)
230 getAndSetMySlot( ri
, this->pi_current_
, "tao_ft_interception_point", 0, 0);
232 #endif /*TAO_HAS_EXTENDED_FT_INTERCEPTORS*/
235 receive_request_service_contexts (ServerRequestInfo_ptr ri
)
237 #if TAO_HAS_EXTENDED_FT_INTERCEPTORS == 1
238 getAndSetMySlot( ri
, this->pi_current_
, "receive_request_service_contexts", 0, 61);
240 getAndSetMySlot( ri
, this->pi_current_
, "receive_request_service_contexts", 0, 0);
241 #endif /* TAO_HAS_EXTENDED_FT_INTERCEPTORS == 1 */
245 receive_request (ServerRequestInfo_ptr ri
)
247 getAndSetMySlot( ri
, this->pi_current_
, "receive_request", 62, 62);
251 send_reply (ServerRequestInfo_ptr ri
)
253 getAndSetMySlot( ri
, this->pi_current_
, "send_reply", 62, 62);
257 send_exception (ServerRequestInfo_ptr ri
)
259 getAndSetMySlot( ri
, this->pi_current_
, "send_exception", 62, 62);
263 send_other (ServerRequestInfo_ptr ri
)
265 getAndSetMySlot( ri
, this->pi_current_
, "send_other", 62, 62);
269 class ORB_Initializer
: public virtual ORBInitializer
,
270 public virtual ::CORBA::LocalObject
274 pre_init (ORBInitInfo_ptr
)
279 post_init (ORBInitInfo_ptr info
)
281 CORBA::Object_var obj
=
282 info
->resolve_initial_references ("PICurrent");
284 PortableInterceptor::Current_var pi_current
=
285 PortableInterceptor::Current::_narrow (obj
.in ());
287 slot_id
= info
->allocate_slot_id ();
288 ACE_DEBUG ((LM_DEBUG
, "Allocated slot with id %d.\n", slot_id
));
290 ServerRequestInterceptor_var
291 interceptor (new ReplicaController (pi_current
.in ()));
292 info
->add_server_request_interceptor (interceptor
.in ());
297 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
299 ORBInitializer_var
orb_initializer (new ORB_Initializer ());
300 register_orb_initializer (orb_initializer
.in ());
302 ORB_var
orb (ORB_init (argc
, argv
));
304 if (parse_args (argc
, argv
) != 0)
307 Object_var
obj (orb
->resolve_initial_references ("RootPOA"));
309 POA_var
root_poa (POA::_narrow (obj
.in ()));
310 POAManager_var
poa_manager (root_poa
->the_POAManager ());
312 InvokeMeImpl
* impl
= new InvokeMeImpl (orb
.in ());
313 ServantBase_var
impl_var (impl
);
315 PortableServer::ObjectId_var id_act
=
316 root_poa
->activate_object (impl
);
318 CORBA::Object_var object
= root_poa
->id_to_reference (id_act
.in ());
320 InvokeMe_var ref
= InvokeMe::_narrow (object
.in ());
321 String_var
ior (orb
->object_to_string (ref
.in ()));
323 poa_manager
->activate ();
327 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
328 if (output_file
== 0)
330 ACE_ERROR_RETURN ((LM_ERROR
,
331 "Cannot open output file <%s> for writing "
338 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
339 ACE_OS::fclose (output_file
);
341 ACE_DEBUG ((LM_DEBUG
, "Server is ready, IOR is in '%s'\n", ior_output_file
));
343 // Run the ORB event loop.
347 root_poa
->destroy (true, true);
350 ACE_DEBUG ((LM_DEBUG
, "Event loop finished.\n"));