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
[])
42 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
44 if (parse_args (argc
, argv
) != 0)
47 CORBA::Object_var obj
= orb
->string_to_object(ior
);
48 if (CORBA::is_nil(obj
.in())) {
49 std::cerr
<< "Nil Messenger reference" << std::endl
;
52 Messenger_var messenger
= Messenger::_narrow(obj
.in());
53 ACE_ASSERT(! CORBA::is_nil(messenger
.in()));
55 obj
= orb
->resolve_initial_references("ORBPolicyManager");
56 CORBA::PolicyManager_var policy_manager
= CORBA::PolicyManager::_narrow(obj
.in());
57 ACE_ASSERT(! CORBA::is_nil(policy_manager
.in()));
58 obj
= orb
->resolve_initial_references("PolicyCurrent");
59 CORBA::PolicyCurrent_var policy_current
= CORBA::PolicyCurrent::_narrow (obj
.in());
60 ACE_ASSERT(! CORBA::is_nil(policy_current
.in()));
62 // TimeT is in 10ths of a microsecond (10000 == 1.0e-3 * 1.0e7).
64 std::cout
<< "Enter relative roundtrip timeout in milliseconds -->";
67 TimeBase::TimeT relative_rt_timeout
= msecs
* 10000;
69 CORBA::Any relative_rt_timeout_as_any
;
70 relative_rt_timeout_as_any
<<= relative_rt_timeout
;
71 CORBA::PolicyList
policy_list(1);
72 policy_list
.length(1);
74 orb
->create_policy(Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
75 relative_rt_timeout_as_any
);
77 // We demonstrate setting the policy at each of three levels. In practice,
78 // you would only need to set the policy for one of these.
79 // Set timeouts for the whole orb.
80 policy_manager
->set_policy_overrides(policy_list
, CORBA::ADD_OVERRIDE
);
81 // Set timeouts for the current thread.
82 policy_current
->set_policy_overrides(policy_list
, CORBA::ADD_OVERRIDE
);
83 // Set timeouts for the messenger object.
84 obj
= messenger
->_set_policy_overrides(policy_list
, CORBA::SET_OVERRIDE
);
85 messenger
= Messenger::_narrow(obj
.in());
86 ACE_ASSERT(! CORBA::is_nil(messenger
.in()));
88 policy_list
[0]->destroy();
89 policy_list
[0] = CORBA::Policy::_nil();
91 CORBA::String_var message
= CORBA::string_dup("Hello!");
94 messenger
->send_message ("TAO User", "TAO Test", message
.inout());
95 std::cerr
<< "ERROR: Message did not timeout." << std::endl
;
96 } catch(const CORBA::TIMEOUT
&) {
97 std::cout
<< "Message Timed out as expected." << std::endl
;
100 catch(const CORBA::Exception
& ex
) {
101 std::cerr
<< "Caught a CORBA exception: " << ex
<< std::endl
;