1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
4 #include "tao/BiDir_GIOP/BiDirGIOP.h"
5 #include "tao/AnyTypeCode/Any.h"
8 const ACE_TCHAR
*ior_output_file
= 0;
9 int no_iterations
= 10;
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:i:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.opt_arg ();
24 no_iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
28 ACE_ERROR_RETURN ((LM_ERROR
,
36 // Indicates successful parsing of the command line
41 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
46 CORBA::ORB_init (argc
, argv
);
48 CORBA::Object_var poa_object
=
49 orb
->resolve_initial_references ("RootPOA");
51 if (CORBA::is_nil (poa_object
.in ()))
52 ACE_ERROR_RETURN ((LM_ERROR
,
53 " (%P|%t) Unable to initialize the POA.\n"),
56 PortableServer::POA_var root_poa
=
57 PortableServer::POA::_narrow (poa_object
.in ());
59 PortableServer::POAManager_var poa_manager
=
60 root_poa
->the_POAManager ();
62 // Policies for the childPOA to be created.
63 CORBA::PolicyList
policies (1);
67 pol
<<= BiDirPolicy::BOTH
;
69 orb
->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
,
72 // Create POA as child of RootPOA with the above policies. This POA
73 // will receive request in the same connection in which it sent
75 PortableServer::POA_var child_poa
=
76 root_poa
->create_POA ("childPOA",
80 // Creation of childPOA is over. Destroy the Policy objects.
81 for (CORBA::ULong i
= 0;
82 i
< policies
.length ();
85 policies
[i
]->destroy ();
88 poa_manager
->activate ();
90 if (parse_args (argc
, argv
) != 0)
93 Simple_Server_i
server_impl (orb
.in (),
96 PortableServer::ObjectId_var id
=
97 PortableServer::string_to_ObjectId ("simple_server");
99 child_poa
->activate_object_with_id (id
.in (),
102 CORBA::Object_var obj
=
103 child_poa
->id_to_reference (id
.in ());
105 CORBA::String_var ior
=
106 orb
->object_to_string (obj
.in ());
108 ACE_DEBUG ((LM_DEBUG
,
109 ACE_TEXT ("(%P|%t) Server activated as <%C>\n"), ior
.in ()));
111 // If the ior_output_file exists, output the ior to it
112 if (ior_output_file
!= 0)
114 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
115 if (output_file
== 0)
116 ACE_ERROR_RETURN ((LM_ERROR
,
117 ACE_TEXT ("Cannot open output file for writing IOR: %s"),
120 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
121 ACE_OS::fclose (output_file
);
127 // Just process one upcall. We know that we would get the
128 // clients IOR in that call.
129 CORBA::Boolean pending
=
137 // Now that hopefully we have the clients IOR, just start
138 // making remote calls to the client.
139 retval
= server_impl
.call_client ();
141 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("event loop finished\n")));
143 root_poa
->destroy (true, true);
147 catch (const CORBA::Exception
& ex
)
149 ex
._tao_print_exception (ACE_TEXT ("Caught exception:"));