1 #include "Messenger_i.h"
6 #include "tao/RTCORBA/RTCORBA.h"
7 #include "ace/Get_Opt.h"
9 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("Messenger.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.opt_arg ();
26 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
38 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
42 CORBA::ORB_var orb
= CORBA::ORB_init( argc
, argv
);
44 if (parse_args (argc
, argv
) != 0)
48 CORBA::Object_var obj
= orb
->resolve_initial_references("RTORB");
49 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow(obj
.in());
52 obj
= orb
->resolve_initial_references("PolicyCurrent");
53 CORBA::PolicyCurrent_var policy_current
=
54 CORBA::PolicyCurrent::_narrow(obj
.in());
55 if (CORBA::is_nil(policy_current
.in())) {
56 std::cerr
<< "Unable to narrow the PolicyCurrent" << std::endl
;
60 //Get reference to Root POA
61 obj
= orb
->resolve_initial_references( "RootPOA" );
62 PortableServer::POA_var poa
= PortableServer::POA::_narrow( obj
.in() );
64 // Activate POA Manager
65 PortableServer::POAManager_var mgr
= poa
->the_POAManager();
68 // Create the thread-pool
69 const CORBA::Short increment
= get_increment();
70 RTCORBA::ThreadpoolLanes
lanes(get_total_lanes());
71 lanes
.length(get_total_lanes());
72 std::cout
<< "Creating " << get_total_lanes() << " lane"
73 << (get_total_lanes() == 1 ? "" : "s") << std::endl
;
74 for(CORBA::ULong i
= 0; i
< get_total_lanes(); i
++) {
75 lanes
[i
].static_threads
= 1;
76 lanes
[i
].dynamic_threads
= 0;
78 lanes
[i
].lane_priority
= i
* increment
;
79 std::cout
<< " Priority: " << lanes
[i
].lane_priority
<< std::endl
;
82 RTCORBA::ThreadpoolId threadpool_id
=
83 rt_orb
->create_threadpool_with_lanes (0, // Stack Size
85 false, // Allow borrowing
86 false, // Allow request buffering
87 0, // Max buffered requests
88 0); // Max request buffer size
90 CORBA::PolicyList
poa_policy_list(2);
91 poa_policy_list
.length (2);
94 rt_orb
->create_priority_model_policy(RTCORBA::CLIENT_PROPAGATED
, 0);
96 rt_orb
->create_threadpool_policy(threadpool_id
);
98 PortableServer::POA_var client_propagated_poa
=
99 poa
->create_POA ("client_propagated_poa",
104 PortableServer::Servant_var
<Messenger_i
> messenger_servant
105 = new Messenger_i(orb
.in());
107 // Register the servant with the RootPOA, obtain its object
108 // reference, stringify it, and write it to a file.
109 PortableServer::ObjectId_var oid
=
110 client_propagated_poa
->activate_object( messenger_servant
.in() );
111 CORBA::Object_var messenger_obj
=
112 client_propagated_poa
->id_to_reference( oid
.in() );
113 CORBA::String_var str
= orb
->object_to_string( messenger_obj
.in() );
114 std::ofstream
iorFile(ACE_TEXT_ALWAYS_CHAR(ior_output_file
));
115 iorFile
<< str
.in() << std::endl
;
117 std::cout
<< "IOR written to file " << ACE_TEXT_ALWAYS_CHAR(ior_output_file
) << std::endl
;
123 catch(const CORBA::Exception
& ex
) {
124 std::cerr
<< "Caught CORBA exception: " << ex
<< std::endl
;