2 #include "tao/IORTable/IORTable.h"
3 #include "ace/OS_NS_strings.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "ace/Thread_Manager.h"
7 #include "ace/Get_Opt.h"
9 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("test.ior");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.opt_arg ();
26 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
37 class ORB_Run_Task
: public ACE_Task_Base
43 ORB_Run_Task (CORBA::ORB_ptr orb
)
44 : orb_(CORBA::ORB::_duplicate(orb
))
54 catch (const CORBA::Exception
&ex
)
57 "(%P|%t) server orb run thread caught %s\n",ex
._name()));
64 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
68 bool endpoint_found
= false;
69 for (int i
= 0; i
< argc
; i
++)
71 if ((ACE_OS::strcasecmp (argv
[i
],ACE_TEXT("-ORBEndpoint")) == 0) ||
72 (ACE_OS::strcasecmp (argv
[i
],ACE_TEXT("-ORBListenEndpoints")) == 0))
77 ACE_ERROR_RETURN ((LM_ERROR
,
78 "ERROR: %s requires an explicit endpoint!\n",
80 ACE_DEBUG ((LM_DEBUG
,"(%P|%t) server started\n"));
82 CORBA::ORB_init (argc
, argv
);
84 if (parse_args (argc
, argv
) != 0)
87 CORBA::Object_var obj
=
88 orb
->resolve_initial_references("RootPOA");
90 PortableServer::POA_var root_poa
=
91 PortableServer::POA::_narrow (obj
.in ());
93 if (CORBA::is_nil (root_poa
.in ()))
94 ACE_ERROR_RETURN ((LM_ERROR
,
95 " (%P|%t) Panic: nil RootPOA\n"),
98 obj
= orb
->resolve_initial_references("IORTable");
100 IORTable::Table_var iortable
=
101 IORTable::Table::_narrow(obj
.in());
103 if (CORBA::is_nil (root_poa
.in ()))
104 ACE_ERROR_RETURN ((LM_ERROR
,
105 " (%P|%t) Panic: nil IORTable\n"),
108 ORB_Killer
killer (orb
.in());
110 ACE_NEW_RETURN (servant
,
113 PortableServer::ServantBase_var
owner_transfer(servant
);
115 PortableServer::ObjectId_var id
=
116 root_poa
->activate_object (servant
);
118 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
120 Test::IORTable_Shutdown_Race_var target
=
121 Test::IORTable_Shutdown_Race::_narrow (object
.in ());
123 CORBA::String_var ior
=
124 orb
->object_to_string (target
.in ());
126 iortable
->bind ("Racer",ior
.in());
128 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
130 poa_manager
->activate ();
132 ACE_DEBUG ((LM_DEBUG
,
133 "(%P|%t) server - activating ORB threads\n"));
135 ORB_Run_Task
ort (orb
.in());
136 ort
.activate (THR_NEW_LWP
| THR_JOINABLE
, 3);
137 ACE_DEBUG ((LM_DEBUG
,"(%P|%t) server - ORB running\n"));
140 // Output the IOR to the <ior_output_file> - to signal readiness.
141 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
142 if (output_file
== 0)
143 ACE_ERROR_RETURN ((LM_ERROR
,
144 "Cannot open output file for writing IOR: %s\n",
147 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
148 ACE_OS::fclose (output_file
);
150 ACE_Thread_Manager
*tm
= ort
.thr_mgr();
152 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
156 catch (const CORBA::Exception
&ex
)
158 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server main - caught %s\n",ex
._name()));