3 #include "tao/Messaging/Messaging.h"
4 #include "tao/AnyTypeCode/Any.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_stdio.h"
8 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
11 parse_args (int argc
, ACE_TCHAR
*argv
[])
13 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
16 while ((c
= get_opts ()) != -1)
20 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 poa_object
=
44 orb
->resolve_initial_references("RootPOA");
46 PortableServer::POA_var root_poa
=
47 PortableServer::POA::_narrow (poa_object
.in ());
49 if (CORBA::is_nil (root_poa
.in ()))
50 ACE_ERROR_RETURN ((LM_ERROR
,
51 " (%P|%t) Panic: nil RootPOA\n"),
54 PortableServer::POAManager_var poa_manager
=
55 root_poa
->the_POAManager ();
57 // Make all oneways "reliable."
59 CORBA::Object_var manager_object
=
60 orb
->resolve_initial_references("ORBPolicyManager");
61 CORBA::PolicyManager_var policy_manager
=
62 CORBA::PolicyManager::_narrow(manager_object
.in());
64 if (CORBA::is_nil (policy_manager
.in ()))
65 ACE_ERROR_RETURN ((LM_ERROR
,
66 " (%P|%t) Panic: nil PolicyManager\n"),
68 CORBA::Any policy_value
;
69 policy_value
<<= Messaging::SYNC_WITH_SERVER
;
70 CORBA::PolicyList
policies(1); policies
.length(1);
72 orb
->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE
,
75 policy_manager
->set_policy_overrides (policies
,
78 policies
[0]->destroy ();
81 if (parse_args (argc
, argv
) != 0)
84 Service
*service_impl
;
85 ACE_NEW_RETURN (service_impl
,
88 PortableServer::ServantBase_var
owner_transfer(service_impl
);
90 PortableServer::ObjectId_var id
=
91 root_poa
->activate_object (service_impl
);
93 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
95 Test::Service_var service
=
96 Test::Service::_narrow (object
.in ());
98 CORBA::String_var ior
=
99 orb
->object_to_string (service
.in ());
101 // If the ior_output_file exists, output the ior to it
102 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
103 if (output_file
== 0)
104 ACE_ERROR_RETURN ((LM_ERROR
,
105 "Cannot open output file for writing IOR: %s",
108 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
109 ACE_OS::fclose (output_file
);
111 poa_manager
->activate ();
115 ACE_DEBUG ((LM_DEBUG
, "Event loop finished\n"));
117 root_poa
->destroy (true, true);
121 catch (const CORBA::Exception
& ex
)
123 ex
._tao_print_exception ("Exception caught:");