2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
6 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("test.ior");
9 parse_args (int argc
, ACE_TCHAR
*argv
[])
11 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("o:"));
14 while ((c
= get_opts ()) != -1)
18 ior_output_file
= get_opts
.opt_arg ();
22 ACE_ERROR_RETURN ((LM_ERROR
,
23 ACE_TEXT ("usage: %s ")
24 ACE_TEXT ("-o <iorfile>")
29 // Indicates successful parsing of the command line
34 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
39 CORBA::ORB_init (argc
, argv
);
41 ::Test::vtp_init
*vtp_factory
= 0;
42 ACE_NEW_THROW_EX (vtp_factory
,
45 CORBA::ValueFactoryBase_var vtp_factory_owner
= vtp_factory
;
47 orb
->register_value_factory (vtp_factory
->tao_repository_id (),
50 CORBA::Object_var poa_object
=
51 orb
->resolve_initial_references ("RootPOA");
53 if (CORBA::is_nil (poa_object
.in ()))
54 ACE_ERROR_RETURN ((LM_ERROR
,
55 ACE_TEXT ("Unable to initialize the POA.\n")),
58 PortableServer::POA_var root_poa
=
59 PortableServer::POA::_narrow (poa_object
.in ());
61 PortableServer::POAManager_var poa_manager
=
62 root_poa
->the_POAManager ();
64 poa_manager
->activate ();
66 if (parse_args (argc
, argv
) != 0)
70 ACE_NEW_RETURN (server_impl
,
71 A_i (orb
.in (), vtp_factory
),
73 PortableServer::ServantBase_var
safe (server_impl
);
75 PortableServer::ObjectId_var id
=
76 root_poa
->activate_object (server_impl
);
78 CORBA::Object_var test_obj
=
79 root_poa
->id_to_reference (id
.in ());
82 Test::A::_narrow (test_obj
.in ());
84 CORBA::String_var ior
=
85 orb
->object_to_string (server
.in ());
88 ACE_TEXT ("Test::A: <%C>\n"),
91 // If the ior_output_file exists, output the ior to it
92 if (ior_output_file
!= 0)
94 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
96 ACE_ERROR_RETURN ((LM_ERROR
,
97 ACE_TEXT ("Cannot open output file ")
98 ACE_TEXT ("for writing IOR: %s"),
101 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
102 ACE_OS::fclose (output_file
);
107 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("event loop finished\n")));
109 root_poa
->destroy (true, true);
113 catch (const CORBA::Exception
& ex
)
115 ex
._tao_print_exception (
116 "Caught exception in server:");