1 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
5 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("middle.ior");
6 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:k:i:"));
15 while ((c
= get_opts ()) != -1)
19 ior_output_file
= get_opts
.opt_arg ();
23 ior
= get_opts
.opt_arg ();
27 niterations
= ACE_OS::atoi (get_opts
.opt_arg ());
32 ACE_ERROR_RETURN ((LM_ERROR
,
41 // Indicates successful parsing of the command line
46 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
51 CORBA::ORB_init (argc
, argv
);
53 CORBA::Object_var poa_object
=
54 orb
->resolve_initial_references("RootPOA");
56 if (CORBA::is_nil (poa_object
.in ()))
57 ACE_ERROR_RETURN ((LM_ERROR
,
58 " (%P|%t) Unable to initialize the POA.\n"),
61 PortableServer::POA_var root_poa
=
62 PortableServer::POA::_narrow (poa_object
.in ());
64 PortableServer::POAManager_var poa_manager
=
65 root_poa
->the_POAManager ();
67 poa_manager
->activate ();
69 if (parse_args (argc
, argv
) != 0)
72 CORBA::Object_var object
=
73 orb
->string_to_object (ior
);
75 Simple_Server_var server
=
76 Simple_Server::_narrow (object
.in ());
78 if (CORBA::is_nil (server
.in ()))
80 ACE_ERROR_RETURN ((LM_ERROR
,
81 "Object reference <%s> is nil.\n",
86 Middle_i
*middle_impl
= 0;
87 ACE_NEW_RETURN (middle_impl
,
92 PortableServer::ServantBase_var
owner_transfer(middle_impl
);
94 PortableServer::ObjectId_var id
=
95 root_poa
->activate_object (middle_impl
);
97 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
99 Simple_Server_var middle
=
100 Simple_Server::_narrow (object_act
.in ());
102 CORBA::String_var ior
=
103 orb
->object_to_string (middle
.in ());
105 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
107 // If the ior_output_file exists, output the ior to it
108 if (ior_output_file
!= 0)
110 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
111 if (output_file
== 0)
112 ACE_ERROR_RETURN ((LM_ERROR
,
113 "Cannot open output file for writing IOR: %s",
116 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
117 ACE_OS::fclose (output_file
);
122 ACE_DEBUG ((LM_DEBUG
, "middle - event loop finished\n"));
124 root_poa
->destroy (true, true);
126 catch (const CORBA::Exception
& ex
)
128 ex
._tao_print_exception ("Exception caught in middle:");