1 #include "ace/Get_Opt.h"
3 #include "tao/BiDir_GIOP/BiDirGIOP.h"
4 #include "tao/AnyTypeCode/Any.h"
5 #include "Server_Task.h"
6 #include "tao/ORB_Core.h"
7 #include "tao/Thread_Lane_Resources.h"
8 #include "tao/Transport_Cache_Manager.h"
9 #include "ace/Manual_Event.h"
11 const ACE_TCHAR
*ior_output_file
= 0;
12 static int no_iterations
= 10;
13 static int no_clients
= 2;
16 parse_args (int argc
, ACE_TCHAR
*argv
[])
18 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:i:c:"));
21 while ((c
= get_opts ()) != -1)
25 ior_output_file
= get_opts
.optarg
;
28 no_clients
= ACE_OS::atoi (get_opts
.optarg
);
31 no_iterations
= ACE_OS::atoi (get_opts
.optarg
);
35 ACE_ERROR_RETURN ((LM_ERROR
,
44 // Indicates successful parsing of the command line
50 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
55 CORBA::ORB_init (argc
, argv
);
57 if (parse_args (argc
, argv
) != 0)
60 CORBA::Object_var poa_object
=
61 orb
->resolve_initial_references ("RootPOA");
63 if (CORBA::is_nil (poa_object
.in ()))
64 ACE_ERROR_RETURN ((LM_ERROR
,
65 " (%P|%t) Unable to initialize the POA.\n"),
68 PortableServer::POA_var root_poa
=
69 PortableServer::POA::_narrow (poa_object
.in ());
71 PortableServer::POAManager_var poa_manager
=
72 root_poa
->the_POAManager ();
74 // Policies for the childPOA to be created.
75 CORBA::PolicyList
policies (1);
79 pol
<<= BiDirPolicy::BOTH
;
81 orb
->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE
,
84 // Create POA as child of RootPOA with the above policies. This POA
85 // will receive request in the same connection in which it sent
87 PortableServer::POA_var child_poa
=
88 root_poa
->create_POA ("childPOA",
92 // Creation of childPOA is over. Destroy the Policy objects.
93 for (CORBA::ULong i
= 0;
94 i
< policies
.length ();
97 policies
[i
]->destroy ();
100 poa_manager
->activate ();
102 ACE_Manual_Event manual_event
;
104 Sender_i
*sender
= 0;
105 ACE_NEW_RETURN (sender
,
106 Sender_i (no_clients
,
110 PortableServer::ServantBase_var
owner_transfer (sender
);
112 PortableServer::ObjectId_var id
=
113 child_poa
->activate_object (sender
);
115 CORBA::Object_var obj
=
116 child_poa
->id_to_reference (id
.in ());
118 CORBA::String_var ior
=
119 orb
->object_to_string (obj
.in ());
121 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
123 // If the ior_output_file exists, output the ior to it
124 if (ior_output_file
!= 0)
126 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
127 if (output_file
== 0)
128 ACE_ERROR_RETURN ((LM_ERROR
,
129 "Cannot open output file for writing IOR: %s",
132 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
133 ACE_OS::fclose (output_file
);
137 // Get the main thread id..
138 ACE_thread_t thr_id
= ACE_Thread::self ();
140 Server_Task
server_task (sender
,
144 ACE_Thread_Manager::instance ());
147 if (server_task
.activate (THR_NEW_LWP
| THR_JOINABLE
, 4, 1) == -1)
149 ACE_ERROR ((LM_ERROR
, "Error activating server task\n"));
152 // Only the main thread gets to run the ORB
153 if (thr_id
== ACE_Thread::self ())
155 // run the ORB for at most 60 seconds...
156 ACE_Time_Value
tv (60, 0);
158 // Call the ORB run from the main thread
161 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) event loop finished\n"));
164 ACE_Thread_Manager::instance ()->wait ();
166 root_poa
->destroy (true, true);
168 catch (const CORBA::Exception
& ex
)
170 ex
._tao_print_exception ("Caught exception:");