Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / ImplRepo / oneway / server.cpp
blobe62303e7d4930b15615e68650b97db97485382ee
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/streams.h"
12 #include "ace/OS_NS_unistd.h"
14 PortableServer::POA_var root_poa;
15 PortableServer::POA_var poa_a;
16 PortableServer::POA_var poa_b;
18 void
19 createPOAs(ACE_CString &base)
21 PortableServer::LifespanPolicy_var life =
22 root_poa->create_lifespan_policy(PortableServer::PERSISTENT);
24 PortableServer::IdAssignmentPolicy_var assign =
25 root_poa->create_id_assignment_policy(PortableServer::USER_ID);
27 CORBA::PolicyList pols;
28 pols.length(2);
29 pols[0] = PortableServer::LifespanPolicy::_duplicate(life.in());
30 pols[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign.in());
32 PortableServer::POAManager_var mgr = PortableServer::POAManager::_nil();
33 ACE_CString poa_name = base + ACE_CString ("_a");
34 poa_a = root_poa->create_POA(poa_name.c_str(), mgr.in(), pols);
35 poa_name = base + ACE_CString ("_b");
36 poa_b = root_poa->create_POA(poa_name.c_str(), mgr.in(), pols);
39 void
40 activatePOAs()
42 PortableServer::POAManager_var mgr = root_poa->the_POAManager ();
43 mgr->activate ();
44 mgr = poa_a->the_POAManager ();
45 mgr->activate ();
46 mgr = poa_b->the_POAManager ();
47 mgr->activate ();
50 int
51 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
53 try {
54 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
56 const ACE_TCHAR *iorfile = ACE_TEXT ("");
58 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("o:?"));
59 int c;
61 while ((c = get_opts ()) != -1)
62 switch (c)
64 case 'o':
65 iorfile = get_opts.opt_arg ();
66 break;
67 case '?':
68 ACE_DEBUG ((LM_DEBUG,
69 "usage: %s "
70 "-d <seconds to delay before initializing POA> "
71 "-n Number of the server\n",
72 argv[0]));
73 return 1;
74 break;
77 CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
78 root_poa = PortableServer::POA::_narrow (obj.in ());
79 // TAO_Root_POA::imr_client_adapter_name ("Test_Imr_Adapter");
81 ACE_CString base = ACE_CString ("TestObject");
82 createPOAs (base);
84 PortableServer::Servant_var<Test_i> test_servant = new Test_i ();
86 PortableServer::ObjectId_var object_id =
87 PortableServer::string_to_ObjectId (base.c_str());
89 poa_a->activate_object_with_id (object_id.in(), test_servant.in ());
90 obj = poa_a->id_to_reference (object_id.in());
92 Test_var tva = Test::_narrow (obj.in());
94 if (ACE_OS::strlen (iorfile) > 0)
96 CORBA::String_var ior = orb->object_to_string (obj.in());
97 FILE *output_file= ACE_OS::fopen (iorfile, "w");
98 if (output_file == 0)
99 ACE_ERROR_RETURN ((LM_ERROR,
100 "Cannot open output file for writing IOR: %s\n",
101 iorfile),
103 ACE_OS::fprintf (output_file, "%s", ior.in ());
104 ACE_OS::fclose (output_file);
107 poa_b->activate_object_with_id (object_id.in(), test_servant.in ());
108 obj = poa_b->id_to_reference (object_id.in());
110 Test_var tvb = Test::_narrow (obj.in());
112 // object_id = root_poa->activate_object (test_servant.in());
115 // This server is now ready to run.
116 // This version does not create an IOR
117 // file as demonstrated in the
118 // Developer's Guide. It assumes that
119 // users create IORs for the client using
120 // the tao_imr utility.
123 // Stop discarding requests.
125 activatePOAs ();
128 // Create binding between "TestService" and
129 // the test object reference in the IOR Table.
130 // Use a TAO extension to get the non imrified poa
131 // to avoid forwarding requests back to the ImR.
133 TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*> (poa_a.in ());
134 ACE_ASSERT (tpoa != 0);
136 obj = tpoa->id_to_reference_i (object_id.in (), false);
137 CORBA::String_var test_ior = orb->object_to_string (obj.in ());
138 obj = orb->resolve_initial_references("IORTable");
139 IORTable::Table_var table = IORTable::Table::_narrow (obj.in ());
140 table->bind(base.c_str (), test_ior.in ());
143 ACE_CString status_file = base + ACE_CString(".status");
144 ofstream out(status_file.c_str ());
145 out << "started" << endl;
148 test_ior = orb->object_to_string (tva.in());
149 base += "_a";
150 ACE_DEBUG ((LM_DEBUG, "%s:\n%s\n", base.c_str(), test_ior.in()));
151 table->bind (base.c_str (), test_ior.in ());
152 base[base.length()-1] = 'b';
153 test_ior = orb->object_to_string (tvb.in());
154 ACE_DEBUG ((LM_DEBUG, "%s:\n%s\n", base.c_str(), test_ior.in()));
155 table->bind (base.c_str (), test_ior.in ());
157 ACE_DEBUG ((LM_DEBUG,
158 "Started Server %s \n",
159 base.c_str()));
161 orb->run();
162 root_poa->destroy(1,1);
163 orb->destroy();
165 catch(const CORBA::Exception& ex) {
166 ex._tao_print_exception ("Server main()");
167 return 1;
170 return 0;