Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / ImplRepo / PICurrent / Server.cpp
blob51b07d54ce8ac3e82a52f9b16a4b85349f9550d0
1 #include "Test_i.h"
2 #include "Terminator.h"
4 #include "tao/IORTable/IORTable.h"
5 #include "tao/PortableServer/Root_POA.h"
6 #include "tao/ImR_Client/ImR_Client.h"
8 #include <iostream>
10 PortableServer::POA_ptr
11 createPOA(PortableServer::POA_ptr root_poa, const char* poa_name)
13 PortableServer::LifespanPolicy_var life =
14 root_poa->create_lifespan_policy(PortableServer::PERSISTENT);
16 PortableServer::IdAssignmentPolicy_var assign =
17 root_poa->create_id_assignment_policy(PortableServer::USER_ID);
19 CORBA::PolicyList pols;
20 pols.length(2);
21 pols[0] = PortableServer::LifespanPolicy::_duplicate(life.in());
22 pols[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign.in());
24 PortableServer::POAManager_var mgr = root_poa->the_POAManager();
25 PortableServer::POA_var poa =
26 root_poa->create_POA(poa_name, mgr.in(), pols);
28 life->destroy();
29 assign->destroy();
31 return poa._retn();
34 int
35 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
37 try {
38 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
40 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
41 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
43 PortableServer::POAManager_var mgr = root_poa->the_POAManager();
45 const char* poa_name = "TestService";
47 PortableServer::POA_var test_poa = createPOA(root_poa.in(), poa_name);
49 Terminator terminator;
50 if (terminator.open (0) == -1)
51 ACE_ERROR_RETURN((LM_ERROR,
52 ACE_TEXT ("main Error opening terminator\n")),-1);
54 PortableServer::Servant_var<Test_i> test_servant =
55 new Test_i(terminator);
57 PortableServer::ObjectId_var object_id =
58 PortableServer::string_to_ObjectId("test_object");
60 test_poa->activate_object_with_id(object_id.in(), test_servant.in());
62 TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(test_poa.in());
63 obj = tpoa->id_to_reference_i(object_id.in(), false);
64 CORBA::String_var test_ior = orb->object_to_string(obj.in());
65 obj = orb->resolve_initial_references("IORTable");
66 IORTable::Table_var table = IORTable::Table::_narrow(obj.in());
67 table->bind(poa_name, test_ior.in());
69 mgr->activate();
71 std::cout << "Test server ready." << std::endl;
73 orb->run();
75 std::cout << "Test server shutting down." << std::endl;
77 root_poa->destroy(1,1);
78 orb->destroy();
80 ACE_Message_Block *mb;
81 ACE_NEW_RETURN(mb, ACE_Message_Block(0, ACE_Message_Block::MB_HANGUP), -1);
82 terminator.putq(mb);
83 terminator.wait();
85 catch(const CORBA::Exception& ex) {
86 std::cerr << "Server main() Caught CORBA::Exception" << ex << std::endl;
87 return 1;
90 return 0;