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()));
65 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
69 bool endpoint_found
= false;
70 for (int i
= 0; i
< argc
; i
++)
72 if ((ACE_OS::strcasecmp (argv
[i
],ACE_TEXT("-ORBEndpoint")) == 0) ||
73 (ACE_OS::strcasecmp (argv
[i
],ACE_TEXT("-ORBListenEndpoints")) == 0))
78 ACE_ERROR_RETURN ((LM_ERROR
,
79 "ERROR: %s requires an explicit endpoint!\n",
81 ACE_DEBUG ((LM_DEBUG
,"(%P|%t) server started\n"));
83 CORBA::ORB_init (argc
, argv
);
85 if (parse_args (argc
, argv
) != 0)
88 CORBA::Object_var obj
=
89 orb
->resolve_initial_references("RootPOA");
91 PortableServer::POA_var root_poa
=
92 PortableServer::POA::_narrow (obj
.in ());
94 if (CORBA::is_nil (root_poa
.in ()))
95 ACE_ERROR_RETURN ((LM_ERROR
,
96 " (%P|%t) Panic: nil RootPOA\n"),
99 obj
= orb
->resolve_initial_references("IORTable");
101 IORTable::Table_var iortable
=
102 IORTable::Table::_narrow(obj
.in());
104 if (CORBA::is_nil (root_poa
.in ()))
105 ACE_ERROR_RETURN ((LM_ERROR
,
106 " (%P|%t) Panic: nil IORTable\n"),
109 ORB_Killer
killer (orb
.in());
111 ACE_NEW_RETURN (servant
,
114 PortableServer::ServantBase_var
owner_transfer(servant
);
116 PortableServer::ObjectId_var id
=
117 root_poa
->activate_object (servant
);
119 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
121 Test::IORTable_Shutdown_Race_var target
=
122 Test::IORTable_Shutdown_Race::_narrow (object
.in ());
124 CORBA::String_var ior
=
125 orb
->object_to_string (target
.in ());
127 iortable
->bind ("Racer",ior
.in());
129 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
131 poa_manager
->activate ();
133 ACE_DEBUG ((LM_DEBUG
,
134 "(%P|%t) server - activating ORB threads\n"));
136 ORB_Run_Task
ort (orb
.in());
137 ort
.activate (THR_NEW_LWP
| THR_JOINABLE
, 3);
138 ACE_DEBUG ((LM_DEBUG
,"(%P|%t) server - ORB running\n"));
141 // Output the IOR to the <ior_output_file> - to signal readiness.
142 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
143 if (output_file
== 0)
144 ACE_ERROR_RETURN ((LM_ERROR
,
145 "Cannot open output file for writing IOR: %s\n",
148 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
149 ACE_OS::fclose (output_file
);
151 ACE_Thread_Manager
*tm
= ort
.thr_mgr();
153 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
157 catch (const CORBA::Exception
&ex
)
159 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server main - caught %s\n",ex
._name()));