1 #include "MessengerLocator_i.h"
2 #include "MessengerC.h"
4 #include "tao/AnyTypeCode/TypeCode.h"
7 #include "ace/Get_Opt.h"
9 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("Messenger.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.opt_arg ();
26 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
37 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
41 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
43 if (parse_args (argc
, argv
) != 0)
46 // Get a reference to the POA
47 CORBA::Object_var obj
= orb
->resolve_initial_references("RootPOA");
48 PortableServer::POA_var rootPOA
= PortableServer::POA::_narrow (obj
.in());
50 // Active the POA Manager
51 PortableServer::POAManager_var mgr
= rootPOA
->the_POAManager();
54 // Create the policies and assign them for the child POA
55 CORBA::PolicyList
policies(3);
58 policies
[0] = rootPOA
->create_id_assignment_policy(PortableServer::USER_ID
);
59 policies
[1] = rootPOA
->create_request_processing_policy(PortableServer::USE_SERVANT_MANAGER
);
60 policies
[2] = rootPOA
->create_servant_retention_policy(PortableServer::NON_RETAIN
);
62 // Create the POA with these policies
63 PortableServer::POA_var childPOA
= rootPOA
->create_POA("childPOA", mgr
.in(), policies
);
65 // Destroy the policy objects
66 for (CORBA::ULong i
= 0; i
!= policies
.length(); ++i
) {
67 policies
[i
]->destroy();
70 // Create our Messenger's ServantLocator.
71 PortableServer::ServantLocator_var locator
= new Messenger_Locator_i
;
73 // Set the Servant Manager with the childPOA.
74 childPOA
->set_servant_manager(locator
.in());
76 // Get the object id for the user-created ID in the childPOA.
77 PortableServer::ObjectId_var child_oid
= PortableServer::string_to_ObjectId("Messenger");
79 // Create the object without creating a servant.
80 CORBA::Object_var messenger_obj
=
81 childPOA
->create_reference_with_id(child_oid
.in(), ::_tc_Messenger
->id());
83 // Put the object reference into an IOR string
84 CORBA::String_var str
= orb
->object_to_string(messenger_obj
.in());
86 // Write the IOR string to a file
87 std::ofstream
iorFile(ACE_TEXT_ALWAYS_CHAR(ior_output_file
)); // Throws exception if there's a problem.
91 std::cout
<< "IOR written to the file " << ACE_TEXT_ALWAYS_CHAR(ior_output_file
) << std::endl
;
93 // Accept requests from clients.
97 rootPOA
->destroy(true,true);
100 catch(const CORBA::Exception
& ex
) {
101 std::cerr
<< "Server Caught a CORBA::Exception: " << ex
<< std::endl
;