2 // This version uses the Implementation Repository.
4 #include "Messenger_i.h"
5 #include "tao/IORTable/IORTable.h"
6 #include "tao/PortableServer/Root_POA.h"
9 PortableServer::POA_ptr
10 createPOA(PortableServer::POA_ptr root_poa
, const char* poa_name
)
12 PortableServer::LifespanPolicy_var life
=
13 root_poa
->create_lifespan_policy(PortableServer::PERSISTENT
);
15 PortableServer::IdAssignmentPolicy_var assign
=
16 root_poa
->create_id_assignment_policy(PortableServer::USER_ID
);
18 CORBA::PolicyList pols
;
20 pols
[0] = PortableServer::LifespanPolicy::_duplicate(life
.in());
21 pols
[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign
.in());
23 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager();
24 PortableServer::POA_var poa
=
25 root_poa
->create_POA(poa_name
, mgr
.in(), pols
);
34 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
37 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
39 CORBA::Object_var obj
= orb
->resolve_initial_references("RootPOA");
40 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow(obj
.in());
42 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager();
44 const char* poa_name
= "MessengerService";
46 PortableServer::POA_var messenger_poa
= createPOA(root_poa
.in(), poa_name
);
48 PortableServer::Servant_var
<Messenger_i
> messenger_servant
= new Messenger_i
;
50 PortableServer::ObjectId_var object_id
=
51 PortableServer::string_to_ObjectId("messenger_object");
54 // Activate the servant with the messenger POA,
55 // obtain its object reference, and get a
58 messenger_poa
->activate_object_with_id(object_id
.in(), messenger_servant
.in());
61 // Create binding between "MessengerService" and
62 // the messenger object reference in the IOR Table.
63 // Use a TAO extension to get the non imrified poa
64 // to avoid forwarding requests back to the ImR.
66 TAO_Root_POA
* tpoa
= dynamic_cast<TAO_Root_POA
*>(messenger_poa
.in());
67 obj
= tpoa
->id_to_reference_i(object_id
.in(), false);
68 CORBA::String_var messenger_ior
= orb
->object_to_string(obj
.in());
69 obj
= orb
->resolve_initial_references("IORTable");
70 IORTable::Table_var table
= IORTable::Table::_narrow(obj
.in());
71 table
->bind(poa_name
, messenger_ior
.in());
74 // This server is now ready to run.
75 // This version does not create an IOR
76 // file as demonstrated in the
77 // Developer's Guide. It assumes that
78 // users create IORs for the client using
79 // the tao_imr utility.
82 // Stop discarding requests.
86 std::cout
<< "Messenger server ready." << std::endl
;
90 std::cout
<< "Messenger server shutting down." << std::endl
;
92 root_poa
->destroy(1,1);
95 catch(const CORBA::Exception
& ex
) {
96 std::cerr
<< "Server main() Caught CORBA::Exception" << ex
<< std::endl
;