1 #include "MessengerC.h"
4 #include "tao/RTCORBA/RTCORBA.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR
*ior_file
= ACE_TEXT ("file://Messenger.ior");
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
15 while ((c
= get_opts ()) != -1)
19 ior_file
= get_opts
.opt_arg ();
24 ACE_ERROR_RETURN ((LM_ERROR
,
31 // Indicates successful parsing of the command line
37 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
41 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
43 if (parse_args (argc
, argv
) != 0)
47 CORBA::Object_var obj
= orb
->resolve_initial_references("RTORB");
48 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow (obj
.in());
51 obj
= orb
->resolve_initial_references("PolicyCurrent");
52 CORBA::PolicyCurrent_var policy_current
=
53 CORBA::PolicyCurrent::_narrow(obj
.in());
54 if (CORBA::is_nil(policy_current
.in())) {
55 std::cerr
<< "Unable to narrow the PolicyCurrent" << std::endl
;
60 obj
= orb
->string_to_object(ior_file
);
61 if( CORBA::is_nil( obj
.in() ) ) {
62 std::cerr
<< "Nil Messenger reference" << std::endl
;
67 Messenger_var messenger
= Messenger::_narrow( obj
.in() );
68 if( CORBA::is_nil( messenger
.in() ) ) {
69 std::cerr
<< "Argument is not a Messenger reference" << std::endl
;
73 // Set the Private Connection Policy
74 CORBA::PolicyList
policy_list(1);
75 policy_list
.length (1);
76 policy_list
[0] = rt_orb
->create_private_connection_policy();
77 policy_current
->set_policy_overrides (policy_list
,
81 obj
= orb
->resolve_initial_references ("RTCurrent");
82 RTCORBA::Current_var current
=
83 RTCORBA::Current::_narrow(obj
.in ());
85 // Change to a priority that matches the server
86 current
->the_priority(0);
88 // Explicitly bind a connection to the server
89 CORBA::PolicyList_var inconsistent_policies
;
90 CORBA::Boolean status
=
91 messenger
->_validate_connection(inconsistent_policies
.out());
93 std::cerr
<< "Unable to explicitly bind to the server" << std::endl
;
97 static const CORBA::Short increment
= get_increment();
98 for(CORBA::ULong i
= 0; i
< get_total_lanes(); i
++) {
99 // Set the priority to one that matches one of the lanes
100 CORBA::Short priority
= i
* increment
;
101 current
->the_priority(priority
);
104 CORBA::String_var message
= CORBA::string_dup( "Hello!" );
105 messenger
->send_message( "TAO User", "TAO Test", message
.inout() );
108 catch(const CORBA::Exception
& ex
) {
109 std::cerr
<< "MessengerClient caught CORBA exception: " << ex
<< std::endl
;
113 std::cerr
<< "MessengerClient exception" << std::endl
;
117 std::cout
<< "messages were sent" << std::endl
;