1 // This version uses the Implementation Repository.
5 #include "tao/IORTable/IORTable.h"
6 #include "tao/PortableServer/Root_POA.h"
7 #include "tao/ImR_Client/ImR_Client.h"
9 #include "ace/Get_Opt.h"
10 #include "ace/streams.h"
11 #include "ace/OS_NS_unistd.h"
13 PortableServer::POA_ptr
14 createPOA(PortableServer::POA_ptr root_poa
, const char* poa_name
)
16 PortableServer::LifespanPolicy_var life
=
17 root_poa
->create_lifespan_policy(PortableServer::PERSISTENT
);
19 PortableServer::IdAssignmentPolicy_var assign
=
20 root_poa
->create_id_assignment_policy(PortableServer::USER_ID
);
22 CORBA::PolicyList pols
;
24 pols
[0] = PortableServer::LifespanPolicy::_duplicate(life
.in());
25 pols
[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign
.in());
27 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager();
28 PortableServer::POA_var poa
=
29 root_poa
->create_POA(poa_name
, mgr
.in(), pols
);
38 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
41 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
43 int init_delay_secs
= 0;
44 int num_requests_expected
= 0;
46 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("d:n:?"));
49 while ((c
= get_opts ()) != -1)
53 init_delay_secs
= ACE_OS::atoi (get_opts
.opt_arg ());
56 num_requests_expected
= ACE_OS::atoi (get_opts
.opt_arg ());
61 "-d <seconds to delay before initializing POA> ",
62 "-n <number of expected requests> \n",
69 "(%P|%t) Server: delaying in initialization for <%d> seconds\n",
71 ACE_OS::sleep (init_delay_secs
);
73 "(%P|%t) Server: done with delay\n"));
75 CORBA::Object_var obj
= orb
->resolve_initial_references("RootPOA");
76 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow(obj
.in());
78 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager();
80 ACE_CString
poa_name("TestObject");
82 PortableServer::POA_var test_poa
= createPOA(root_poa
.in(),
85 PortableServer::Servant_var
<Test_i
> test_servant
=
86 new Test_i(orb
.in(), num_requests_expected
);
88 PortableServer::ObjectId_var object_id
=
89 PortableServer::string_to_ObjectId("test_object");
91 // Activate the servant with the test POA,
92 // obtain its object reference, and get a
94 test_poa
->activate_object_with_id(object_id
.in(), test_servant
.in());
96 // Create binding between "TestService" and
97 // the test object reference in the IOR Table.
98 // Use a TAO extension to get the non imrified poa
99 // to avoid forwarding requests back to the ImR.
100 TAO_Root_POA
* tpoa
= dynamic_cast<TAO_Root_POA
*>(test_poa
.in());
103 ACE_ERROR ((LM_ERROR
,
104 ACE_TEXT ("(%P|%t) Server: Could not cast POA to root POA")
109 obj
= tpoa
->id_to_reference_i(object_id
.in(), false);
110 CORBA::String_var test_ior
= orb
->object_to_string(obj
.in());
111 obj
= orb
->resolve_initial_references("IORTable");
112 IORTable::Table_var table
= IORTable::Table::_narrow(obj
.in());
113 table
->bind(poa_name
.c_str (), test_ior
.in());
115 // This server is now ready to run.
116 // This version does not create an IOR
117 // file as demonstrated in the
118 // Developer's Guide. It assumes that
119 // users create IORs for the client using
120 // the tao_imr utility.
122 // Stop discarding requests.
125 ACE_DEBUG ((LM_DEBUG
,
126 "(%P|%t) Server: started <%C>\n",
130 ACE_CString status_file
= poa_name
+ ACE_CString(".status");
131 ofstream
out(status_file
.c_str ());
132 out
<< "started" << endl
;
137 root_poa
->destroy(1,1);
140 ACE_DEBUG ((LM_DEBUG
,
141 "(%P|%t) Server: ended <%C>\n",
144 catch(const CORBA::Exception
& ex
) {
145 ex
._tao_print_exception ("Server main()");
149 bool const expected_requests_made
= Test_i::expected_requests_made ();
150 if (!expected_requests_made
)
152 ACE_ERROR ((LM_ERROR
,
153 "(%P|%t) Server: ERROR: Expected number of requests were not made\n"));
156 int const status
= expected_requests_made
? 0 : -1;