3 #include "tao/ImR_Client/ImR_Client.h"
5 #include "orbsvcs/CosNamingC.h"
7 #include "ace/Get_Opt.h"
8 #include "ace/Read_Buffer.h"
9 #include "ace/streams.h"
11 class test_i
: public virtual POA_test
24 virtual CORBA::Long
get ()
39 this->root_poa_
->destroy(1, 1);
40 this->orb_
->destroy();
44 Server_i::parse_args (int argc
, ACE_TCHAR
* argv
[])
46 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("s:d:"));
49 while ((c
= get_opts ()) != -1)
54 this->second_name_
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
57 this->server_name_
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
60 ACE_ERROR_RETURN ((LM_ERROR
,
62 " [-d <name>] name of the server to depend on."
63 " -s <name> name of this server."
73 Server_i::init (int argc
, ACE_TCHAR
** argv
)
77 this->orb_
= CORBA::ORB_init (argc
, argv
);
79 int retval
= this->parse_args (argc
, argv
);
83 CORBA::Object_var obj
=
84 this->orb_
->resolve_initial_references ("RootPOA");
85 this->root_poa_
= PortableServer::POA::_narrow (obj
.in ());
86 ACE_ASSERT(! CORBA::is_nil(this->root_poa_
.in()));
88 PortableServer::POAManager_var poa_manager
=
89 this->root_poa_
->the_POAManager ();
91 // If -orbuseimr 1 is specified then all persistent poas will be
92 // registered with the imr.
93 CORBA::PolicyList
policies (2);
95 policies
[0] = this->root_poa_
->create_id_assignment_policy (PortableServer::USER_ID
);
96 policies
[1] = this->root_poa_
->create_lifespan_policy (PortableServer::PERSISTENT
);
99 ACE_NEW_RETURN (test_svt
, test_i
, -1);
100 PortableServer::ServantBase_var
scoped_svt(test_svt
);
102 PortableServer::ObjectId_var server_id
=
103 PortableServer::string_to_ObjectId ("Test");
105 PortableServer::POA_var poa
=
106 this->root_poa_
->create_POA (this->server_name_
.c_str(),
110 poa
->activate_object_with_id (server_id
.in (), test_svt
);
111 obj
= poa
->id_to_reference (server_id
.in ());
113 policies
[0]->destroy();
114 policies
[1]->destroy();
116 CORBA::Object_var nsobj
=
117 this->orb_
->resolve_initial_references ("NameService");
118 CosNaming::NamingContext_var nc
=
119 CosNaming::NamingContext::_narrow (nsobj
.in ());
120 CosNaming::Name
n(1);
122 n
[0].id
= CORBA::string_dup (this->server_name_
.c_str ());
126 nsobj
= nc
->resolve (n
);
128 catch (CosNaming::NamingContext::NotFound
&)
130 nc
->bind (n
, obj
.in ());
133 if (this->second_name_
.length ())
135 n
[0].id
= CORBA::string_dup (this->second_name_
.c_str ());
139 nsobj
= nc
->resolve (n
);
141 catch (CosNaming::NamingContext::NotFound
&)
145 test_var test
= test::_narrow(nsobj
.in());
149 catch (const CORBA::Exception
& ex
)
151 ex
._tao_print_exception ("Server_i::init");
164 PortableServer::POAManager_var poa_manager
=
165 this->root_poa_
->the_POAManager ();
167 poa_manager
->activate ();
170 ACE_CString status
= this->server_name_
+ ACE_CString(".status");
171 ofstream
out(status
.c_str());
172 out
<< "started" << endl
;
177 catch (const CORBA::Exception
& ex
)
179 ex
._tao_print_exception ("Server_i::run");