3 #include "tao/Messaging/Messaging.h"
4 #include "tao/ORB_Core.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
10 parse_args (int argc
, ACE_TCHAR
*argv
[]);
13 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
18 CORBA::ORB_init (argc
, argv
);
20 CORBA::Object_var poa_object
=
21 orb
->resolve_initial_references("RootPOA");
23 PortableServer::POA_var root_poa
=
24 PortableServer::POA::_narrow (poa_object
.in ());
26 if (CORBA::is_nil (root_poa
.in ()))
27 ACE_ERROR_RETURN ((LM_ERROR
,
28 " (%P|%t) Panic: nil RootPOA\n"),
31 PortableServer::POAManager_var poa_manager
=
32 root_poa
->the_POAManager ();
34 CORBA::Object_var object
=
35 orb
->resolve_initial_references ("PolicyCurrent");
37 if (parse_args (argc
, argv
) != 0)
40 PortableServer::Servant_var
<Server
> impl
;
43 // ACE_NEW_RETURN is the worst possible way to handle
44 // exceptions (think: what if the constructor allocates memory
45 // and fails?), but I'm not in the mood to fight for a more
46 // reasonable way to handle allocation errors in ACE.
53 PortableServer::ObjectId_var id
=
54 root_poa
->activate_object (impl
.in ());
56 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
58 Test::Server_var server
=
59 Test::Server::_narrow (object_act
.in ());
61 CORBA::String_var ior
=
62 orb
->object_to_string (server
.in ());
64 // If the ior_output_file exists, output the ior to it
65 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
67 ACE_ERROR_RETURN ((LM_ERROR
,
68 "Cannot open output file for writing IOR: %s",
71 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
72 ACE_OS::fclose (output_file
);
74 poa_manager
->activate ();
76 ORB_Task
task(orb
.in());
77 task
.activate(THR_NEW_LWP
| THR_JOINABLE
, 4, 1);
81 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
83 root_poa
->destroy (true, true);
87 catch (const CORBA::Exception
& ex
)
89 ex
._tao_print_exception ("Exception caught:");
97 parse_args (int argc
, ACE_TCHAR
*argv
[])
99 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
102 while ((c
= get_opts ()) != -1)
106 ior_output_file
= get_opts
.opt_arg ();
111 ACE_ERROR_RETURN ((LM_ERROR
,
118 // Indicates successful parsing of the command line