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 ORB_Runner (CORBA::ORB_var orb
) : orb_(orb
) {}
30 PortableServer::POA_var root_poa
;
31 PortableServer::POA_var poa_a
;
34 createPOAs(ACE_CString
&base
)
36 PortableServer::LifespanPolicy_var life
=
37 root_poa
->create_lifespan_policy(PortableServer::PERSISTENT
);
39 PortableServer::IdAssignmentPolicy_var assign
=
40 root_poa
->create_id_assignment_policy(PortableServer::USER_ID
);
42 CORBA::PolicyList pols
;
44 pols
[0] = PortableServer::LifespanPolicy::_duplicate(life
.in());
45 pols
[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign
.in());
47 PortableServer::POAManager_var mgr
= PortableServer::POAManager::_nil();
48 ACE_CString poa_name
= base
+ ACE_CString ("_a");
49 ACE_DEBUG ((LM_DEBUG
, "%P server creating POA %C\n", poa_name
.c_str()));
50 poa_a
= root_poa
->create_POA(poa_name
.c_str(), mgr
.in(), pols
);
56 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager ();
58 mgr
= poa_a
->the_POAManager ();
59 ACE_DEBUG ((LM_DEBUG
, "%P server activating POAs\n"));
64 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
66 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
67 ORB_Runner
*runner
= new ORB_Runner (orb
);
72 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("p:?"));
75 while ((c
= get_opts ()) != -1)
79 poa_delay
= ACE_OS::atoi (get_opts
.opt_arg ());
84 "-d <seconds to delay before initializing POA> "
85 "-n Number of the server\n",
91 // ACE_OS::sleep (poa_delay);
92 CORBA::Object_var obj
= orb
->resolve_initial_references ("RootPOA");
93 root_poa
= PortableServer::POA::_narrow (obj
.in ());
97 ACE_CString base
= ACE_CString ("TestObject");
100 PortableServer::Servant_var
<Test_i
> test_servant
= new Test_i
;
102 PortableServer::ObjectId_var object_id
=
103 PortableServer::string_to_ObjectId (base
.c_str());
105 poa_a
->activate_object_with_id (object_id
.in(), test_servant
.in ());
106 obj
= poa_a
->id_to_reference (object_id
.in());
108 Test_var tva
= Test::_narrow (obj
.in());
110 ACE_DEBUG ((LM_DEBUG
, "Started Server pid = %d poa delay %d\n", ACE_OS::getpid (), poa_delay
));
113 ACE_CString status_file
= base
+ ACE_CString(".status");
114 ofstream
out(status_file
.c_str (), ios_base::app
);
117 ACE_DEBUG ((LM_DEBUG
, "server did not get good bit from %C\n", status_file
.c_str()));
119 out
<< ACE_OS::getpid () << endl
;
122 ACE_Time_Value
tv (poa_delay
);
126 ACE_DEBUG ((LM_DEBUG
, "Activated POA pid = %d \n", ACE_OS::getpid ()));
128 TAO_Root_POA
* tpoa
= dynamic_cast<TAO_Root_POA
*> (poa_a
.in ());
129 ACE_ASSERT (tpoa
!= 0);
131 obj
= tpoa
->id_to_reference_i (object_id
.in (), false);
132 CORBA::String_var test_ior
= orb
->object_to_string (obj
.in ());
133 obj
= orb
->resolve_initial_references("IORTable");
134 IORTable::Table_var table
= IORTable::Table::_narrow (obj
.in ());
135 table
->bind(base
.c_str (), test_ior
.in ());
137 test_ior
= orb
->object_to_string (tva
.in());
139 ACE_DEBUG ((LM_DEBUG
, "%C:\n%C\n", base
.c_str(), test_ior
.in()));
140 table
->bind (base
.c_str (), test_ior
.in ());
143 root_poa
->destroy(1,1);
146 catch(const CORBA::Exception
& ex
)
148 ex
._tao_print_exception ("Server main()");
153 orb
= CORBA::ORB::_nil ();
154 ACE_DEBUG ((LM_DEBUG
, "Exiting Server pid = %d \n",