2 #include "ace/Get_Opt.h"
5 const ACE_TCHAR
*ior_output_file
= 0;
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:n:"));
15 while ((c
= get_opts ()) != -1)
19 ior_output_file
= get_opts
.opt_arg ();
23 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
28 ACE_ERROR_RETURN ((LM_ERROR
,
35 // Indicates successful parsing of the command line
42 * Use the ACE_Task_Base class to run server threads
44 class Worker
: public ACE_Task_Base
47 Worker (CORBA::ORB_ptr orb
);
50 virtual int svc (void);
51 // The thread entry point.
59 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
64 CORBA::ORB_init (argc
, argv
);
66 CORBA::Object_var poa_object
=
67 orb
->resolve_initial_references("RootPOA");
69 if (CORBA::is_nil (poa_object
.in ()))
70 ACE_ERROR_RETURN ((LM_ERROR
,
71 " (%P|%t) Unable to initialize the POA.\n"),
74 PortableServer::POA_var root_poa
=
75 PortableServer::POA::_narrow (poa_object
.in ());
77 PortableServer::POAManager_var poa_manager
=
78 root_poa
->the_POAManager ();
80 if (parse_args (argc
, argv
) != 0)
83 Simple_Server_i
server_impl (orb
.in ());
85 PortableServer::ObjectId_var id
=
86 root_poa
->activate_object (&server_impl
);
88 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
90 Simple_Server_var server
=
91 Simple_Server::_narrow (object
.in ());
93 CORBA::String_var ior
=
94 orb
->object_to_string (server
.in ());
96 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
98 // If the ior_output_file exists, output the ior to it
99 if (ior_output_file
!= 0)
101 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
102 if (output_file
== 0)
103 ACE_ERROR_RETURN ((LM_ERROR
,
104 "Cannot open output file for writing IOR: %s",
107 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
108 ACE_OS::fclose (output_file
);
111 poa_manager
->activate ();
113 Worker
worker (orb
.in ());
114 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
116 ACE_ERROR_RETURN ((LM_ERROR
,
117 "Cannot activate client threads\n"),
120 worker
.thr_mgr ()->wait ();
122 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
124 catch (const CORBA::Exception
& ex
)
126 ex
._tao_print_exception ("Exception caught:");
133 // ****************************************************************
135 Worker::Worker (CORBA::ORB_ptr orb
)
136 : orb_ (CORBA::ORB::_duplicate (orb
))
147 catch (const CORBA::Exception
&)