1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
6 #include "tao/Messaging/Messaging.h"
7 #include "tao/BiDir_GIOP/BiDirGIOP.h"
9 const ACE_TCHAR
*ior_output_file
= 0;
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("o:i:"));
18 while ((c
= get_opts ()) != -1)
22 ior_output_file
= get_opts
.opt_arg ();
25 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
29 ACE_ERROR_RETURN ((LM_ERROR
, ACE_TEXT ("usage: %s -o <iorfile>")
30 ACE_TEXT ("-i <iterations>\n"), argv
[0]),
33 // Indicates successful parsing of the command line
38 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
42 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
44 CORBA::Object_var object
=
45 orb
->resolve_initial_references ("ORBPolicyManager");
47 CORBA::PolicyManager_var policy_mgr
=
48 CORBA::PolicyManager::_narrow (object
.in ());
49 if (CORBA::is_nil (policy_mgr
.in ()))
50 ACE_ERROR_RETURN ((LM_ERROR
, "failed to get policy manager\n"), 1);
51 CORBA::String_var ref_id
= policy_mgr
->_interface_repository_id ();
52 ACE_DEBUG ((LM_DEBUG
, "Policy MGR intid = %C\n", ref_id
.in ()));
54 CORBA::Object_var poa_object
=
55 orb
->resolve_initial_references ("RootPOA");
57 if (CORBA::is_nil (poa_object
.in ()))
58 ACE_ERROR_RETURN ((LM_ERROR
,
59 " (%P|%t) Unable to initialize the POA.\n"),
62 PortableServer::POA_var root_poa
=
63 PortableServer::POA::_narrow (poa_object
.in ());
64 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
66 // Policies for the childPOA to be created.
67 CORBA::PolicyList
policies (1);
71 pol
<<= BiDirPolicy::BOTH
;
73 orb
->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
, pol
);
75 // Create POA as child of RootPOA with the above policies. This POA
76 // will receive request in the same connection in which it sent
78 PortableServer::POA_var child_poa
=
79 root_poa
->create_POA ("child", poa_manager
.in (), policies
);
81 // Creation of childPOA is over. Destroy the Policy objects.
82 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
)
84 policies
[i
]->destroy ();
87 poa_manager
->activate ();
89 if (parse_args (argc
, argv
) != 0)
92 Simple_Server_i
server_impl (orb
.in (), iterations
);
94 PortableServer::ObjectId_var id
=
95 PortableServer::string_to_ObjectId ("simple_server");
97 child_poa
->activate_object_with_id (id
.in (), &server_impl
);
99 CORBA::Object_var obj
= child_poa
->id_to_reference (id
.in ());
101 CORBA::String_var ior
= orb
->object_to_string (obj
.in ());
103 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Server activated as <%C>\n", ior
.in ()));
105 // If the ior_output_file exists, output the ior to it
106 if (ior_output_file
!= 0)
108 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
109 if (output_file
== 0)
110 ACE_ERROR_RETURN ((LM_ERROR
,
111 "Cannot open output file for writing IOR: %C",
114 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
115 ACE_OS::fclose (output_file
);
120 ACE_Thread_Manager::instance ()->wait ();
122 root_poa
->destroy (1, 1);
124 catch (const CORBA::Exception
&excep
)
126 excep
._tao_print_exception ("Caught exception:");