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");
9 #if defined (ACE_OPENVMS)
10 // need this to circumvent link error on OpenVMS
11 // has to do with interference in template instantiations
12 // for the server build by previous compilation of TestX
13 // components in client build which are reused by server
14 // without recompilation
15 ACE_Time_Value dum
= ACE_Time_Value::zero
;
19 parse_args (int argc
, ACE_TCHAR
*argv
[]);
22 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
27 CORBA::ORB_init (argc
, argv
);
29 CORBA::Object_var poa_object
=
30 orb
->resolve_initial_references("RootPOA");
32 PortableServer::POA_var root_poa
=
33 PortableServer::POA::_narrow (poa_object
.in ());
35 if (CORBA::is_nil (root_poa
.in ()))
36 ACE_ERROR_RETURN ((LM_ERROR
,
37 " (%P|%t) Panic: nil RootPOA\n"),
40 PortableServer::POAManager_var poa_manager
=
41 root_poa
->the_POAManager ();
43 CORBA::Object_var object
=
44 orb
->resolve_initial_references ("PolicyCurrent");
46 if (parse_args (argc
, argv
) != 0)
49 PortableServer::Servant_var
<Server
> impl
;
52 // ACE_NEW_RETURN is the worst possible way to handle
53 // exceptions (think: what if the constructor allocates memory
54 // and fails?), but I'm not in the mood to fight for a more
55 // reasonable way to handle allocation errors in ACE.
62 PortableServer::ObjectId_var id
=
63 root_poa
->activate_object (impl
.in ());
65 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
67 Test::Server_var server
=
68 Test::Server::_narrow (object_act
.in ());
70 CORBA::String_var ior
=
71 orb
->object_to_string (server
.in ());
73 // If the ior_output_file exists, output the ior to it
74 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
76 ACE_ERROR_RETURN ((LM_ERROR
,
77 "Cannot open output file for writing IOR: %s",
80 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
81 ACE_OS::fclose (output_file
);
83 poa_manager
->activate ();
85 ORB_Task
task(orb
.in());
86 task
.activate(THR_NEW_LWP
| THR_JOINABLE
, 4, 1);
90 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
92 root_poa
->destroy (1, 1);
96 catch (const CORBA::Exception
& ex
)
98 ex
._tao_print_exception ("Exception caught:");
106 parse_args (int argc
, ACE_TCHAR
*argv
[])
108 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
111 while ((c
= get_opts ()) != -1)
115 ior_output_file
= get_opts
.opt_arg ();
120 ACE_ERROR_RETURN ((LM_ERROR
,
127 // Indicates successful parsing of the command line