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
= 0;
85 ACE_NEW_RETURN (service_impl
,
88 PortableServer::ServantBase_var
owner_transfer(service_impl
);
90 service_impl
->orb_
= CORBA::ORB::_duplicate (orb
.in());
92 PortableServer::ObjectId_var id
=
93 root_poa
->activate_object (service_impl
);
95 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
97 Test::Service_var service
=
98 Test::Service::_narrow (object
.in ());
100 CORBA::String_var ior
=
101 orb
->object_to_string (service
.in ());
103 // If the ior_output_file exists, output the ior to it
104 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
105 if (output_file
== 0)
106 ACE_ERROR_RETURN ((LM_ERROR
,
107 "Cannot open output file for writing IOR: %s",
110 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
111 ACE_OS::fclose (output_file
);
113 poa_manager
->activate ();
115 ACE_Time_Value
tv (50, 0);
118 ACE_DEBUG ((LM_DEBUG
, "Event loop finished\n"));
120 service_impl
->dump_results ();
122 root_poa
->destroy (1, 1);
126 catch (const CORBA::Exception
& ex
)
128 ex
._tao_print_exception ("Exception caught:");