1 #include "MessengerC.h"
2 #include "tao/TimeBaseC.h"
3 #include "tao/Messaging/Messaging.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR
*ior
= ACE_TEXT ("file://MessengerServer.ior");
8 long msecs
= 0; // the RelativeRoundtripTimeout value
11 parse_args (int argc
, ACE_TCHAR
*argv
[])
13 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:t:"));
16 while ((c
= get_opts ()) != -1)
20 ior
= get_opts
.opt_arg ();
23 msecs
= ACE_OS::atoi(get_opts
.opt_arg ());
27 ACE_ERROR_RETURN ((LM_ERROR
,
35 // Indicates successful parsing of the command line
39 int ACE_TMAIN(int argc
, ACE_TCHAR
* argv
[])
43 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
45 if (parse_args (argc
, argv
) != 0)
48 CORBA::Object_var obj
= orb
->string_to_object(ior
);
49 if (CORBA::is_nil(obj
.in())) {
50 std::cerr
<< "Nil Messenger reference" << std::endl
;
53 Messenger_var messenger
= Messenger::_narrow(obj
.in());
54 ACE_ASSERT(! CORBA::is_nil(messenger
.in()));
56 obj
= orb
->resolve_initial_references("ORBPolicyManager");
57 CORBA::PolicyManager_var policy_manager
= CORBA::PolicyManager::_narrow(obj
.in());
58 ACE_ASSERT(! CORBA::is_nil(policy_manager
.in()));
59 obj
= orb
->resolve_initial_references("PolicyCurrent");
60 CORBA::PolicyCurrent_var policy_current
= CORBA::PolicyCurrent::_narrow (obj
.in());
61 ACE_ASSERT(! CORBA::is_nil(policy_current
.in()));
63 // TimeT is in 10ths of a microsecond (10000 == 1.0e-3 * 1.0e7).
65 std::cout
<< "Enter relative roundtrip timeout in milliseconds -->";
68 TimeBase::TimeT relative_rt_timeout
= msecs
* 10000;
70 CORBA::Any relative_rt_timeout_as_any
;
71 relative_rt_timeout_as_any
<<= relative_rt_timeout
;
72 CORBA::PolicyList
policy_list(1);
73 policy_list
.length(1);
75 orb
->create_policy(Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
76 relative_rt_timeout_as_any
);
78 // We demonstrate setting the policy at each of three levels. In practice,
79 // you would only need to set the policy for one of these.
80 // Set timeouts for the whole orb.
81 policy_manager
->set_policy_overrides(policy_list
, CORBA::ADD_OVERRIDE
);
82 // Set timeouts for the current thread.
83 policy_current
->set_policy_overrides(policy_list
, CORBA::ADD_OVERRIDE
);
84 // Set timeouts for the messenger object.
85 obj
= messenger
->_set_policy_overrides(policy_list
, CORBA::SET_OVERRIDE
);
86 messenger
= Messenger::_narrow(obj
.in());
87 ACE_ASSERT(! CORBA::is_nil(messenger
.in()));
89 policy_list
[0]->destroy();
90 policy_list
[0] = CORBA::Policy::_nil();
92 CORBA::String_var message
= CORBA::string_dup("Hello!");
95 messenger
->send_message ("TAO User", "TAO Test", message
.inout());
96 std::cerr
<< "ERROR: Message did not timeout." << std::endl
;
97 } catch(const CORBA::TIMEOUT
&) {
98 std::cout
<< "Message Timed out as expected." << std::endl
;
101 catch(const CORBA::Exception
& ex
) {
102 std::cerr
<< "Caught a CORBA exception: " << ex
<< std::endl
;