2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/Thread_Manager.h"
5 #include "tao/BiDir_GIOP/BiDirGIOP.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
15 while ((c
= get_opts ()) != -1)
19 ior_output_file
= get_opts
.opt_arg ();
24 ACE_ERROR_RETURN ((LM_ERROR
,
31 // Indicates successful parsing of the command line
36 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
41 CORBA::ORB_init (argc
, argv
);
43 CORBA::Object_var obj
=
44 orb
->resolve_initial_references("RootPOA");
46 PortableServer::POA_var root_poa
=
47 PortableServer::POA::_narrow (obj
.in ());
49 if (CORBA::is_nil (root_poa
.in ()))
50 ACE_ERROR_RETURN ((LM_ERROR
,
51 " (%P|%t) Panic: nil RootPOA\n"),
54 PortableServer::POAManager_var poa_manager
=
55 root_poa
->the_POAManager ();
57 // Policies for the childPOA to be created.
58 CORBA::PolicyList
policies (1);
62 pol
<<= BiDirPolicy::BOTH
;
64 orb
->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
,
67 // Create POA as child of RootPOA with the above policies. This POA
68 // will receive request in the same connection in which it sent
70 PortableServer::POA_var child_poa
=
71 root_poa
->create_POA ("childPOA",
75 // Creation of childPOA is over. Destroy the Policy objects.
76 for (CORBA::ULong i
= 0;
77 i
< policies
.length ();
80 policies
[i
]->destroy ();
83 if (parse_args (argc
, argv
) != 0)
87 ACE_NEW_RETURN (hello_impl
,
90 PortableServer::ServantBase_var
owner(hello_impl
);
92 PortableServer::ObjectId_var id
=
93 child_poa
->activate_object(hello_impl
);
95 obj
= child_poa
->id_to_reference (id
.in());
97 Test::Hello_var hello
=
98 Test::Hello::_narrow (obj
.in());
100 CORBA::String_var ior
=
101 orb
->object_to_string (hello
.in ());
103 // Output the IOR to the <ior_output_file>
104 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
105 if (output_file
== 0)
106 ACE_ERROR_RETURN ((LM_ERROR
,
107 "Cannot open output file for writing IOR: %s\n",
110 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
111 ACE_OS::fclose (output_file
);
113 poa_manager
->activate ();
117 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
119 // Wait for threads that may have been started by the Hello
121 ACE_Thread_Manager::instance()->wait();
123 root_poa
->destroy (1, 1);
127 catch (const CORBA::Exception
& ex
)
129 ex
._tao_print_exception ("Exception caught:");