2 #include "Server_ORBInitializer.h"
3 #include "tao/ORBInitializer_Registry.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.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 PortableInterceptor::ORBInitializer_var
initializer(
42 new Server_ORBInitializer
);
43 PortableInterceptor::register_orb_initializer(initializer
.in());
47 CORBA::ORB_init (argc
, argv
);
49 CORBA::Object_var poa_object
=
50 orb
->resolve_initial_references("RootPOA");
52 PortableServer::POA_var root_poa
=
53 PortableServer::POA::_narrow (poa_object
.in ());
55 if (CORBA::is_nil (root_poa
.in ()))
56 ACE_ERROR_RETURN ((LM_ERROR
,
57 " (%P|%t) Panic: nil RootPOA\n"),
60 PortableServer::POAManager_var poa_manager
=
61 root_poa
->the_POAManager ();
63 if (parse_args (argc
, argv
) != 0)
67 ACE_NEW_RETURN (echo_impl
,
70 PortableServer::ServantBase_var
owner_transfer(echo_impl
);
72 PortableServer::ObjectId_var id
=
73 root_poa
->activate_object (echo_impl
);
75 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
78 Test::Echo::_narrow (object
.in ());
80 CORBA::String_var ior
=
81 orb
->object_to_string (echo
.in ());
83 // Output the IOR to the <ior_output_file>
84 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
86 ACE_ERROR_RETURN ((LM_ERROR
,
87 "Cannot open output file for writing IOR: %s",
90 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
91 ACE_OS::fclose (output_file
);
93 poa_manager
->activate ();
97 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
99 root_poa
->destroy (true, true);
103 catch (const CORBA::Exception
& ex
)
105 ex
._tao_print_exception ("Exception caught:");