Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / ImplRepo / kill_slow_server / server.cpp
blob9c2027df62cd03bd8de113c9f40f8484614112df
1 // server.cpp
2 // This version uses the Implementation Repository.
4 #include "Test_i.h"
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"
11 #include "ace/Task.h"
12 #include "ace/streams.h"
13 #include "ace/OS_NS_unistd.h"
15 class ORB_Runner : public ACE_Task_Base
17 public:
18 ORB_Runner (CORBA::ORB_var orb) : orb_(orb) {}
19 int svc ()
21 this->orb_->run ();
22 return 0;
25 private:
26 CORBA::ORB_var orb_;
30 PortableServer::POA_var root_poa;
31 PortableServer::POA_var poa_a;
33 void
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;
43 pols.length(2);
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);
53 void
54 activatePOAs ()
56 PortableServer::POAManager_var mgr = root_poa->the_POAManager ();
57 mgr->activate ();
58 mgr = poa_a->the_POAManager ();
59 ACE_DEBUG ((LM_DEBUG, "%P server activating POAs\n"));
60 mgr->activate ();
63 int
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);
68 int poa_delay = 10;
70 try
72 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("p:?"));
73 int c;
75 while ((c = get_opts ()) != -1)
76 switch (c)
78 case 'p':
79 poa_delay = ACE_OS::atoi (get_opts.opt_arg ());
80 break;
81 case '?':
82 ACE_DEBUG ((LM_DEBUG,
83 "usage: %s "
84 "-d <seconds to delay before initializing POA> "
85 "-n Number of the server\n",
86 argv[0]));
87 return 1;
88 break;
91 // ACE_OS::sleep (poa_delay);
92 CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
93 root_poa = PortableServer::POA::_narrow (obj.in ());
95 runner->activate ();
97 ACE_CString base = ACE_CString ("TestObject");
98 createPOAs (base);
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);
115 if (!out.good())
117 ACE_DEBUG ((LM_DEBUG, "server did not get good bit from %C\n", status_file.c_str()));
119 out << ACE_OS::getpid () << endl;
120 out.close ();
122 ACE_Time_Value tv (poa_delay);
123 ACE_OS::sleep (tv);
124 activatePOAs ();
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());
138 base += "_a";
139 ACE_DEBUG ((LM_DEBUG, "%C:\n%C\n", base.c_str(), test_ior.in()));
140 table->bind (base.c_str (), test_ior.in ());
142 runner->wait ();
143 root_poa->destroy(1,1);
144 orb->destroy();
146 catch(const CORBA::Exception& ex)
148 ex._tao_print_exception ("Server main()");
149 return 1;
152 delete runner;
153 orb = CORBA::ORB::_nil ();
154 ACE_DEBUG ((LM_DEBUG, "Exiting Server pid = %d \n",
155 ACE_OS::getpid ()));
157 return 0;