3 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_unistd.h"
6 #include "ace/Thread.h"
7 #include "tao/PortableInterceptorC.h"
9 #include "tao/LocalObject.h"
10 #include "tao/ORBInitializer_Registry.h"
12 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
13 int number_of_tries
= 5;
15 TAO_SYNCH_MUTEX ofs_lock
;
16 PortableInterceptor::Current_var pic
;
17 PortableInterceptor::SlotId slot_id
;
18 const IOP::ServiceId service_id
= 0xdeadbeef;
22 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
, mon
, ofs_lock
, 0);
28 class Worker
: public ACE_Task_Base
31 Messenger_var messenger
;
33 Worker (Messenger_ptr m
)
34 : messenger(Messenger::_duplicate (m
)) {}
38 int offset
= get_offset ();
39 CORBA::String_var message
= CORBA::string_dup( "Hello!" );
41 ACE_OS::snprintf(user
, 100, "client %d", offset
/ 100);
43 for (; try_count
< number_of_tries
; ++try_count
)
46 in
<<= CORBA::ULong (try_count
+ offset
);
48 ACE_TEXT("(%P|%t) set slot data %d\n"),
50 pic
->set_slot (slot_id
, in
);
53 messenger
->send_message( user
, "Test 1", message
.inout() );
56 ACE_TEXT("(%P|%t) received response for ")
57 ACE_TEXT("message <%d> to server\n"),
60 catch (const CORBA::Exception
& ex
)
63 ACE_TEXT("(%P|%t) ignoring %C\n"),
74 : public virtual PortableInterceptor::ClientRequestInterceptor
,
75 public virtual ::CORBA::LocalObject
78 virtual char * name (void)
80 return CORBA::string_dup ("Client_Req_Int");
83 virtual void destroy (void)
87 virtual void send_poll (PortableInterceptor::ClientRequestInfo_ptr
)
91 virtual void receive_reply (PortableInterceptor::ClientRequestInfo_ptr
)
95 virtual void receive_other (PortableInterceptor::ClientRequestInfo_ptr
)
99 virtual void receive_exception (PortableInterceptor::ClientRequestInfo_ptr
)
103 virtual void send_request (PortableInterceptor::ClientRequestInfo_ptr ri
)
106 if (CORBA::is_nil (this->pic_
.in()))
108 ACE_GUARD (TAO_SYNCH_MUTEX
, g
, this->lock_
);
109 if (CORBA::is_nil (this->pic_
.in()))
112 ACE_TCHAR
**argv
= 0;
113 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
114 CORBA::Object_var obj
= orb
->resolve_initial_references ("PICurrent");
115 this->pic_
= PortableInterceptor::Current::_narrow (obj
.in ());
119 CORBA::String_var op
= ri
->operation ();
120 if (ACE_OS::strcmp (op
.in (), "send_message") != 0)
124 CORBA::Any_var out
= this->pic_
->get_slot (slot_id
);
127 ACE_DEBUG ((LM_DEBUG
,
128 ACE_TEXT("(%P|%t) send_request got %u\n"), v
));
129 IOP::ServiceContext sc
;
130 sc
.context_id
= ::service_id
;
132 ri
->add_request_service_context (sc
, 0);
136 ACE_ERROR ((LM_ERROR
,
137 ACE_TEXT("(%P|%t) send_request failed to get slot data\n")));
142 TAO_SYNCH_MUTEX lock_
;
143 PortableInterceptor::Current_var pic_
;
147 class ORB_Initializer
: public virtual PortableInterceptor::ORBInitializer
,
148 public virtual ::CORBA::LocalObject
152 pre_init (PortableInterceptor::ORBInitInfo_ptr
)
157 post_init (PortableInterceptor::ORBInitInfo_ptr info
)
159 slot_id
= info
->allocate_slot_id ();
160 ACE_DEBUG ((LM_DEBUG
, "Allocated slot with id %d.\n", slot_id
));
161 PortableInterceptor::ClientRequestInterceptor_ptr interceptor
=
162 PortableInterceptor::ClientRequestInterceptor::_nil ();
164 // Install the Echo client request interceptor
165 ACE_NEW_THROW_EX (interceptor
,
167 CORBA::NO_MEMORY ());
169 PortableInterceptor::ClientRequestInterceptor_var
170 client_interceptor
= interceptor
;
172 info
->add_client_request_interceptor (client_interceptor
.in ());
178 parse_args (int argc
, ACE_TCHAR
*argv
[])
180 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
183 while ((c
= get_opts ()) != -1)
187 ior
= get_opts
.opt_arg ();
192 ACE_ERROR_RETURN ((LM_ERROR
,
193 ACE_TEXT("usage: %s ")
194 ACE_TEXT("-k <ior> ")
199 // Indicates successful parsing of the command line
204 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
208 PortableInterceptor::ORBInitializer_var orb_initializer
=
209 new ORB_Initializer ();
210 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
212 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
214 if (parse_args (argc
, argv
) != 0)
217 CORBA::Object_var obj
= orb
->string_to_object( ior
);
218 Messenger_var messenger
= Messenger::_narrow( obj
.in() );
220 obj
= orb
->resolve_initial_references ("PICurrent");
221 pic
= PortableInterceptor::Current::_narrow (obj
.in ());
223 Worker
w (messenger
.in ());
224 w
.activate (THR_JOINABLE
| THR_NEW_LWP
, 3);
229 catch(const CORBA::Exception
& ex
) {
230 ACE_DEBUG ((LM_DEBUG
,
231 ACE_TEXT ("Client main() Caught CORBA::Exception: %C\n"),