2 #include "ace/Get_Opt.h"
4 #include "ace/OS_NS_stdio.h"
6 const ACE_TCHAR
*ior_file
= 0;
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:c:n:"));
15 while ((c
= get_opts ()) != -1)
19 ior_file
= get_opts
.opt_arg ();
22 number
= ACE_OS::atoi (get_opts
.opt_arg ());
25 ACE_ERROR_RETURN ((LM_ERROR
,
28 "-n <server number>\n",
37 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
42 CORBA::ORB_init (argc
, argv
, "Server ORB");
44 CORBA::Object_var poa_object
=
45 orb
->resolve_initial_references ("RootPOA");
47 if (CORBA::is_nil (poa_object
.in ()))
48 ACE_ERROR_RETURN ((LM_ERROR
,
49 " (%P|%t) Unable to initialize the POA.\n"),
52 PortableServer::POA_var root_poa
=
53 PortableServer::POA::_narrow (poa_object
.in ());
55 PortableServer::POAManager_var poa_manager
=
56 root_poa
->the_POAManager ();
58 if (::parse_args (argc
, argv
) != 0)
62 ACE_NEW_RETURN (test_impl
, test_i (number
, orb
.in ()), 1);
63 PortableServer::ServantBase_var
owner_transfer (test_impl
);
65 PortableServer::ObjectId_var id
=
66 root_poa
->activate_object (test_impl
);
68 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
70 RTTest::test_var test
=
71 RTTest::test::_narrow (object
.in ());
73 CORBA::String_var ior
=
74 orb
->object_to_string (test
.in ());
76 FILE *output_file
= ACE_OS::fopen (ior_file
, "w");
78 ACE_ERROR_RETURN ((LM_ERROR
,
79 "Cannot open output file <%s> for writing "
83 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
84 ACE_OS::fclose (output_file
);
86 poa_manager
->activate ();
88 // Run the ORB event loop.
91 root_poa
->destroy (true, true);
95 ACE_DEBUG ((LM_DEBUG
, "Event loop finished.\n"));
97 catch (const CORBA::Exception
& ex
)
99 ex
._tao_print_exception ("Caught exception:");