Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / ImplRepo / MT_stress / server_i.cpp
blob01466a89e1a389eda7884d9e576f7e9003599706
1 #include "server_i.h"
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
13 int n_;
14 public:
15 test_i ()
16 : n_(0)
20 virtual ~test_i ()
24 virtual CORBA::Long get ()
26 ++n_;
27 return n_;
31 Server_i::Server_i ()
32 : server_name_()
33 , second_name_()
37 Server_i::~Server_i()
39 this->root_poa_->destroy(1, 1);
40 this->orb_->destroy();
43 int
44 Server_i::parse_args (int argc, ACE_TCHAR* argv[])
46 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("s:d:"));
47 int c;
49 while ((c = get_opts ()) != -1)
51 switch (c)
53 case 'd':
54 this->second_name_ = ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ());
55 break;
56 case 's':
57 this->server_name_ = ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ());
58 break;
59 default:
60 ACE_ERROR_RETURN ((LM_ERROR,
61 "usage: %s"
62 " [-d <name>] name of the server to depend on."
63 " -s <name> name of this server."
64 "\n",
65 argv[0]),1);
69 return 0;
72 int
73 Server_i::init (int argc, ACE_TCHAR** argv)
75 try
77 this->orb_ = CORBA::ORB_init (argc, argv);
79 int retval = this->parse_args (argc, argv);
80 if (retval != 0)
81 return retval;
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);
94 policies.length (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);
98 test_i* test_svt;
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(),
107 poa_manager.in (),
108 policies);
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);
121 n.length (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 ());
131 return 1;
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 &)
143 return 1;
145 test_var test = test::_narrow(nsobj.in());
146 test->get();
149 catch (const CORBA::Exception& ex)
151 ex._tao_print_exception ("Server_i::init");
152 throw;
156 return 0;
160 Server_i::run ()
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;
175 this->orb_->run ();
177 catch (const CORBA::Exception& ex)
179 ex._tao_print_exception ("Server_i::run");
180 throw;
184 return 0;