2 // This version uses the Implementation Repository.
4 #include "Messenger_i.h"
5 #include "Terminator.h"
7 #include "tao/IORTable/IORTable.h"
8 #include "tao/PortableServer/Root_POA.h"
9 #include "tao/ImR_Client/ImR_Client.h"
13 PortableServer::POA_ptr
14 createPOA(PortableServer::POA_ptr root_poa
, const char* poa_name
)
16 PortableServer::LifespanPolicy_var life
=
17 root_poa
->create_lifespan_policy(PortableServer::PERSISTENT
);
19 PortableServer::IdAssignmentPolicy_var assign
=
20 root_poa
->create_id_assignment_policy(PortableServer::USER_ID
);
22 CORBA::PolicyList pols
;
24 pols
[0] = PortableServer::LifespanPolicy::_duplicate(life
.in());
25 pols
[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign
.in());
27 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager();
28 PortableServer::POA_var poa
=
29 root_poa
->create_POA(poa_name
, mgr
.in(), pols
);
38 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
41 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
43 CORBA::Object_var obj
= orb
->resolve_initial_references("RootPOA");
44 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow(obj
.in());
46 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager();
48 const char* poa_name
= "MessengerService";
50 PortableServer::POA_var messenger_poa
= createPOA(root_poa
.in(), poa_name
);
52 Terminator terminator
;
53 if (terminator
.open (0) == -1)
54 ACE_ERROR_RETURN((LM_ERROR
,
55 ACE_TEXT ("main Error opening terminator\n")),-1);
57 PortableServer::Servant_var
<Messenger_i
> messenger_servant
=
58 new Messenger_i(orb
.in(), terminator
);
60 PortableServer::ObjectId_var object_id
=
61 PortableServer::string_to_ObjectId("messenger_object");
64 // Activate the servant with the messenger POA,
65 // obtain its object reference, and get a
68 messenger_poa
->activate_object_with_id(object_id
.in(), messenger_servant
.in());
71 // Create binding between "MessengerService" and
72 // the messenger object reference in the IOR Table.
73 // Use a TAO extension to get the non imrified poa
74 // to avoid forwarding requests back to the ImR.
76 TAO_Root_POA
* tpoa
= dynamic_cast<TAO_Root_POA
*>(messenger_poa
.in());
77 obj
= tpoa
->id_to_reference_i(object_id
.in(), false);
78 CORBA::String_var messenger_ior
= orb
->object_to_string(obj
.in());
79 obj
= orb
->resolve_initial_references("IORTable");
80 IORTable::Table_var table
= IORTable::Table::_narrow(obj
.in());
81 table
->bind(poa_name
, messenger_ior
.in());
84 // This server is now ready to run.
85 // This version does not create an IOR
86 // file as demonstrated in the
87 // Developer's Guide. It assumes that
88 // users create IORs for the client using
89 // the tao_imr utility.
92 // Stop discarding requests.
96 std::cout
<< "Messenger server ready." << std::endl
;
100 std::cout
<< "Messenger server shutting down." << std::endl
;
102 root_poa
->destroy(1,1);
105 ACE_Message_Block
*mb
;
106 ACE_NEW_RETURN(mb
, ACE_Message_Block(0, ACE_Message_Block::MB_HANGUP
), -1);
110 catch(const CORBA::Exception
& ex
) {
111 std::cerr
<< "Server main() Caught CORBA::Exception" << ex
<< std::endl
;