2 #include "tao/Messaging/Messaging.h"
3 #include "tao/AnyTypeCode/Any.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 CORBA::ORB_init (argc
, argv
);
43 CORBA::Object_var object
=
44 orb
->resolve_initial_references ("PolicyCurrent");
46 CORBA::PolicyCurrent_var policy_current
=
47 CORBA::PolicyCurrent::_narrow (object
.in ());
49 if (CORBA::is_nil (policy_current
.in ()))
51 ACE_ERROR ((LM_ERROR
, "ERROR: Nil policy current\n"));
54 CORBA::Any scope_as_any
;
55 scope_as_any
<<= Messaging::SYNC_NONE
;
57 CORBA::PolicyList
policies(1); policies
.length (1);
59 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
62 policy_current
->set_policy_overrides (policies
, CORBA::ADD_OVERRIDE
);
64 policies
[0]->destroy ();
66 CORBA::Object_var poa_object
=
67 orb
->resolve_initial_references("RootPOA");
69 PortableServer::POA_var root_poa
=
70 PortableServer::POA::_narrow (poa_object
.in ());
72 if (CORBA::is_nil (root_poa
.in ()))
73 ACE_ERROR_RETURN ((LM_ERROR
,
74 " (%P|%t) Panic: nil RootPOA\n"),
77 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
79 if (parse_args (argc
, argv
) != 0)
82 Server
*server_impl
= 0;
83 ACE_NEW_RETURN (server_impl
,
86 PortableServer::ServantBase_var
owner_transfer(server_impl
);
88 PortableServer::ObjectId_var id
=
89 root_poa
->activate_object (server_impl
);
91 object
= root_poa
->id_to_reference (id
.in ());
93 Test::Server_var test_server
= Test::Server::_narrow (object
.in ());
95 CORBA::String_var ior
= orb
->object_to_string (test_server
.in ());
97 // Output the IOR to the <ior_output_file>
98 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
100 ACE_ERROR_RETURN ((LM_ERROR
,
101 "Cannot open output file for writing IOR: %s\n",
104 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
105 ACE_OS::fclose (output_file
);
107 poa_manager
->activate ();
111 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
113 root_poa
->destroy (1, 1);
117 catch (const CORBA::Exception
& ex
)
119 ex
._tao_print_exception ("Exception caught:");