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"),
73 : public virtual PortableInterceptor::ClientRequestInterceptor
,
74 public virtual ::CORBA::LocalObject
77 virtual char * name ()
79 return CORBA::string_dup ("Client_Req_Int");
82 virtual void destroy ()
86 virtual void send_poll (PortableInterceptor::ClientRequestInfo_ptr
)
90 virtual void receive_reply (PortableInterceptor::ClientRequestInfo_ptr
)
94 virtual void receive_other (PortableInterceptor::ClientRequestInfo_ptr
)
98 virtual void receive_exception (PortableInterceptor::ClientRequestInfo_ptr
)
102 virtual void send_request (PortableInterceptor::ClientRequestInfo_ptr ri
)
104 if (CORBA::is_nil (this->pic_
.in()))
106 ACE_GUARD (TAO_SYNCH_MUTEX
, g
, this->lock_
);
107 if (CORBA::is_nil (this->pic_
.in()))
110 ACE_TCHAR
**argv
= 0;
111 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
112 CORBA::Object_var obj
= orb
->resolve_initial_references ("PICurrent");
113 this->pic_
= PortableInterceptor::Current::_narrow (obj
.in ());
117 CORBA::String_var op
= ri
->operation ();
118 if (ACE_OS::strcmp (op
.in (), "send_message") != 0)
122 CORBA::Any_var out
= this->pic_
->get_slot (slot_id
);
125 ACE_DEBUG ((LM_DEBUG
,
126 ACE_TEXT("(%P|%t) send_request got %u\n"), v
));
127 IOP::ServiceContext sc
;
128 sc
.context_id
= ::service_id
;
130 ri
->add_request_service_context (sc
, 0);
134 ACE_ERROR ((LM_ERROR
,
135 ACE_TEXT("(%P|%t) send_request failed to get slot data\n")));
140 TAO_SYNCH_MUTEX lock_
;
141 PortableInterceptor::Current_var pic_
;
144 class ORB_Initializer
: public virtual PortableInterceptor::ORBInitializer
,
145 public virtual ::CORBA::LocalObject
149 pre_init (PortableInterceptor::ORBInitInfo_ptr
)
154 post_init (PortableInterceptor::ORBInitInfo_ptr info
)
156 slot_id
= info
->allocate_slot_id ();
157 ACE_DEBUG ((LM_DEBUG
, "Allocated slot with id %d.\n", slot_id
));
158 PortableInterceptor::ClientRequestInterceptor_ptr interceptor
=
159 PortableInterceptor::ClientRequestInterceptor::_nil ();
161 // Install the Echo client request interceptor
162 ACE_NEW_THROW_EX (interceptor
,
164 CORBA::NO_MEMORY ());
166 PortableInterceptor::ClientRequestInterceptor_var
167 client_interceptor
= interceptor
;
169 info
->add_client_request_interceptor (client_interceptor
.in ());
174 parse_args (int argc
, ACE_TCHAR
*argv
[])
176 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
179 while ((c
= get_opts ()) != -1)
183 ior
= get_opts
.opt_arg ();
188 ACE_ERROR_RETURN ((LM_ERROR
,
189 ACE_TEXT("usage: %s ")
190 ACE_TEXT("-k <ior> ")
195 // Indicates successful parsing of the command line
200 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
204 PortableInterceptor::ORBInitializer_var orb_initializer
=
205 new ORB_Initializer ();
206 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
208 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
210 if (parse_args (argc
, argv
) != 0)
213 CORBA::Object_var obj
= orb
->string_to_object(ior
);
214 Messenger_var messenger
= Messenger::_narrow(obj
.in());
216 obj
= orb
->resolve_initial_references ("PICurrent");
217 pic
= PortableInterceptor::Current::_narrow (obj
.in ());
219 Worker
w (messenger
.in ());
220 w
.activate (THR_JOINABLE
| THR_NEW_LWP
, 3);
225 catch(const CORBA::Exception
& ex
) {
226 ACE_DEBUG ((LM_DEBUG
,
227 ACE_TEXT ("Client main() Caught CORBA::Exception: %C\n"),