2 // This version uses the Implementation Repository.
6 #include "tao/IORTable/IORTable.h"
7 #include "tao/PortableServer/Root_POA.h"
8 #include "tao/ImR_Client/ImR_Client.h"
10 #include "ace/Get_Opt.h"
12 #include "ace/streams.h"
13 #include "ace/OS_NS_unistd.h"
15 class ORB_Runner
: public ACE_Task_Base
18 explicit ORB_Runner (CORBA::ORB_ptr orb
) : orb_(CORBA::ORB::_duplicate(orb
)) {}
29 PortableServer::POA_var root_poa
;
30 PortableServer::POA_var poa_a
;
33 createPOAs(ACE_CString
&base
)
35 PortableServer::LifespanPolicy_var life
=
36 root_poa
->create_lifespan_policy(PortableServer::PERSISTENT
);
38 PortableServer::IdAssignmentPolicy_var assign
=
39 root_poa
->create_id_assignment_policy(PortableServer::USER_ID
);
41 CORBA::PolicyList pols
;
43 pols
[0] = PortableServer::LifespanPolicy::_duplicate(life
.in());
44 pols
[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign
.in());
46 PortableServer::POAManager_var mgr
= PortableServer::POAManager::_nil();
47 ACE_CString poa_name
= base
+ ACE_CString ("_a");
48 poa_a
= root_poa
->create_POA(poa_name
.c_str(), mgr
.in(), pols
);
54 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager ();
56 mgr
= poa_a
->the_POAManager ();
61 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
63 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
64 ORB_Runner
*runner
= new ORB_Runner (orb
.in ());
66 int shutdown_delay
= 0;
68 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Start server main\n"));
72 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("p:s:?"));
75 while ((c
= get_opts ()) != -1)
79 poa_delay
= ACE_OS::atoi (get_opts
.opt_arg ());
82 shutdown_delay
= ACE_OS::atoi (get_opts
.opt_arg ());
87 "-d <seconds to delay before initializing POA> "
88 "-s <seconds to delay before exiting main after the ORB destroy>\n",
94 ACE_OS::sleep (poa_delay
);
95 CORBA::Object_var obj
= orb
->resolve_initial_references ("RootPOA");
96 root_poa
= PortableServer::POA::_narrow (obj
.in ());
100 ACE_CString base
= ACE_CString ("TestObject");
103 PortableServer::Servant_var
<Test_i
> test_servant
= new Test_i (orb
.in ());
105 PortableServer::ObjectId_var object_id
=
106 PortableServer::string_to_ObjectId (base
.c_str());
108 poa_a
->activate_object_with_id (object_id
.in(), test_servant
.in ());
109 obj
= poa_a
->id_to_reference (object_id
.in());
111 Test_var tva
= Test::_narrow (obj
.in());
113 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Started Server pid <%P> poa delay <%d> shutdown delay <%d>\n", poa_delay
, shutdown_delay
));
116 ACE_CString status_file
= base
+ ACE_CString(".status");
117 ofstream
out(status_file
.c_str (), ios_base::app
);
120 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server did not get good bit from %s\n", status_file
.c_str()));
122 out
<< ACE_OS::getpid () << endl
;
125 ACE_OS::sleep (poa_delay
);
128 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Activated POA pid <%P>\n"));
130 TAO_Root_POA
* tpoa
= dynamic_cast<TAO_Root_POA
*> (poa_a
.in ());
131 ACE_ASSERT (tpoa
!= 0);
133 obj
= tpoa
->id_to_reference_i (object_id
.in (), false);
134 CORBA::String_var test_ior
= orb
->object_to_string (obj
.in ());
135 obj
= orb
->resolve_initial_references("IORTable");
136 IORTable::Table_var table
= IORTable::Table::_narrow (obj
.in ());
137 table
->bind(base
.c_str (), test_ior
.in ());
139 test_ior
= orb
->object_to_string (tva
.in());
141 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) %C:\n%C\n", base
.c_str(), test_ior
.in()));
142 table
->bind (base
.c_str (), test_ior
.in ());
146 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Destroying POA pid <%P>\n"));
148 root_poa
->destroy(1,1);
151 catch(const CORBA::Exception
& ex
)
153 ex
._tao_print_exception ("Server main()");
158 orb
= CORBA::ORB::_nil ();
160 ACE_OS::sleep (shutdown_delay
);
162 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Exiting Server pid <%P>\n"));