5 #include "ace/Get_Opt.h"
9 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("");
10 const ACE_TCHAR
*shutdown_ior_output_file
= ACE_TEXT("");
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:s:"));
18 while ((c
= get_opts ()) != -1)
22 ior_output_file
= get_opts
.opt_arg ();
25 shutdown_ior_output_file
= get_opts
.opt_arg ();
29 ACE_ERROR_RETURN ((LM_ERROR
,
32 "-s <shutdown_iorfile>"
38 // Indicates successful parsing of the command line
44 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
48 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
50 if (parse_args (argc
, argv
) != 0)
53 CORBA::Object_var poa_object
= orb
->resolve_initial_references ("RootPOA");
54 PortableServer::POA_var rootPOA
= PortableServer::POA::_narrow (poa_object
.in ());
55 PortableServer::POAManager_var poa_manager
= rootPOA
->the_POAManager ();
57 // Policies for the firstPOA to be created.
58 CORBA::PolicyList
policies (5);
62 rootPOA
->create_lifespan_policy (PortableServer::PERSISTENT
);
64 // Servant Retention Policy
66 rootPOA
->create_servant_retention_policy (PortableServer::RETAIN
);
68 // ID Assignment Policy
70 rootPOA
->create_id_assignment_policy (PortableServer::USER_ID
);
72 // Request Processing Policy
74 rootPOA
->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY
);
78 rootPOA
->create_thread_policy (PortableServer::ORB_CTRL_MODEL
);
80 PortableServer::POA_var demoPOA
81 = rootPOA
->create_POA ("HelloWorldServer",
85 for (CORBA::ULong i
= 0;
86 i
< policies
.length ();
89 CORBA::Policy_ptr policy
= policies
[i
];
93 // Create object for shutdown commanded by client.
96 Demo_HelloWorld_i
* hello
= new Demo_HelloWorld_i(orb
.in());
99 PortableServer::ObjectId_var oid
= PortableServer::string_to_ObjectId ("shutdown");
100 demoPOA
->activate_object_with_id (oid
.in (), hello
);
103 // Create an object reference.
104 CORBA::Object_var myhello
= demoPOA
->id_to_reference(oid
.in());
106 // Put the object reference as an IOR string
107 ofstream
out(ACE_TEXT_ALWAYS_CHAR (shutdown_ior_output_file
));
108 CORBA::String_var ior
= orb
->object_to_string (myhello
.in ());
110 // save the reference into a file
114 // Create object to handle client sayHello requests.
117 Demo_HelloWorld_i
* hello
= new Demo_HelloWorld_i(orb
.in());
119 // Get the Object ID.
120 PortableServer::ObjectId_var oid
= PortableServer::string_to_ObjectId ("hello");
121 demoPOA
->activate_object_with_id (oid
.in (), hello
);
123 // Create an object reference.
124 CORBA::Object_var myhello
= demoPOA
->id_to_reference(oid
.in());
126 // Put the object reference as an IOR string
127 ofstream
out(ACE_TEXT_ALWAYS_CHAR (ior_output_file
));
128 CORBA::String_var ior
= orb
->object_to_string (myhello
.in ());
130 // save the reference into a file
134 //////////////////////////////////////////////////////////////////////////////////////////////////
135 poa_manager
->activate ();
137 std::cout
<< ior_output_file
<< " is ready " << std::endl
;
140 // Destroy the POA, waiting until the destruction terminates
141 rootPOA
->destroy (1, 1);
144 catch (const CORBA::Exception
&e
)
146 std::cerr
<< "Unexpected exception: " << e
<< std::endl
;