3 #include "tao/IORTable/IORTable.h"
4 #include "tao/PortableServer/Root_POA.h"
5 #include "tao/ImR_Client/ImR_Client.h"
7 #include "ace/Get_Opt.h"
8 #include "ace/Read_Buffer.h"
9 #include "ace/streams.h"
12 : public virtual POA_test
17 test_i (CORBA::ORB_ptr orb
)
19 , orb_(CORBA::ORB::_duplicate(orb
))
24 virtual CORBA::Long
get (void)
27 CORBA::Object_var obj
= orb_
->resolve_initial_references("POACurrent");
28 PortableServer::Current_var cur
= PortableServer::Current::_narrow(obj
.in());
29 ACE_ASSERT(! CORBA::is_nil(cur
.in()));
30 PortableServer::POA_var poa
= cur
->get_POA();
31 CORBA::String_var poaname
= poa
->the_name();
33 ACE_DEBUG((LM_DEBUG
, "%s: get() %d\n", poaname
.in(), n_
));
38 // The server name of the Aiprlane Server
39 static const char DEFAULT_SERVER_NAME
[] = "TestObject";
41 Server_i::Server_i (void)
42 : server_name_(DEFAULT_SERVER_NAME
)
52 Server_i::parse_args (int argc
, ACE_TCHAR
* argv
[])
54 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("p:c:h"));
57 while ((c
= get_opts ()) != -1)
61 case 'p': // prefix for all created objects
62 this->server_name_
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
64 case 'c': // Number of imr-ified objects to create.
65 this->count_
= ACE_OS::atoi(get_opts
.opt_arg());
67 case '?': // display help for use of the server.
70 ACE_ERROR_RETURN ((LM_ERROR
,
72 " [-c] <count=1> ImR-ified objects."
73 " [-p] <prefix=%s> To all ImR-ified object names."
76 DEFAULT_SERVER_NAME
),1);
85 ACE_CString
toStr(int n
)
88 return ACE_OS::itoa(n
, buf
, 10);
93 Server_i::init (int argc
, ACE_TCHAR
** argv
)
97 this->orb_
= CORBA::ORB_init (argc
, argv
);
99 int retval
= this->parse_args (argc
, argv
);
103 CORBA::Object_var obj
=
104 this->orb_
->resolve_initial_references ("RootPOA");
106 PortableServer::POA::_narrow (obj
.in ());
107 ACE_ASSERT(! CORBA::is_nil(this->root_poa_
.in()));
109 PortableServer::POAManager_var poa_manager
=
110 this->root_poa_
->the_POAManager ();
112 obj
= this->orb_
->resolve_initial_references ("IORTable");
113 IORTable::Table_var ior_table
=
114 IORTable::Table::_narrow (obj
.in ());
115 ACE_ASSERT(! CORBA::is_nil(ior_table
.in()));
117 // If -orbuseimr 1 is specified then all persistent poas will be
118 // registered with the imr.
119 CORBA::PolicyList
policies (2);
121 policies
[0] = this->root_poa_
->create_id_assignment_policy (PortableServer::USER_ID
);
122 policies
[1] = this->root_poa_
->create_lifespan_policy (PortableServer::PERSISTENT
);
125 ACE_NEW_RETURN (test_svt
, test_i(orb_
.in()), -1);
126 PortableServer::ServantBase_var
scoped_svt(test_svt
);
128 PortableServer::ObjectId_var server_id
=
129 PortableServer::string_to_ObjectId ("Test");
131 // Create count_ POAs, activate an object in each, and register the object with
133 for (int i
= 0; i
< this->count_
; ++i
)
135 ACE_CString name
= this->server_name_
+ "_" + toStr(i
);
137 PortableServer::POA_var poa
=
138 this->root_poa_
->create_POA (name
.c_str(),
142 poa
->activate_object_with_id (server_id
.in (), test_svt
);
144 TAO_Root_POA
* tmp_poa
= dynamic_cast<TAO_Root_POA
*>(poa
.in());
145 obj
= tmp_poa
->id_to_reference_i (server_id
.in (), false);
147 CORBA::String_var ior
= this->orb_
->object_to_string (obj
.in ());
149 ior_table
->bind (name
.c_str(), ior
.in ());
152 policies
[0]->destroy();
153 policies
[1]->destroy();
155 catch (const CORBA::Exception
& ex
)
157 ex
._tao_print_exception ("Server_i::init");
170 PortableServer::POAManager_var poa_manager
=
171 this->root_poa_
->the_POAManager ();
173 poa_manager
->activate ();
175 // We have potentially lots of IORs, so just write out a simple text
176 // file that the run_test.pl can use to know we're done.
178 ACE_CString status
= this->server_name_
+ ACE_CString(".status");
179 ofstream
out(status
.c_str());
180 out
<< "started" << endl
;
183 ACE_DEBUG ((LM_DEBUG
,
184 "\n Started Server %s with %d imr-ified objects.\n\n",
185 this->server_name_
.c_str(),
190 this->root_poa_
->destroy(1, 1);
191 this->orb_
->destroy();
193 catch (const CORBA::Exception
& ex
)
195 ex
._tao_print_exception ("Server_i::run");