2 #include "ace/Get_Opt.h"
5 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
9 parse_args (int argc
, ACE_TCHAR
*argv
[])
11 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:n:"));
14 while ((c
= get_opts ()) != -1)
18 ior_output_file
= get_opts
.opt_arg ();
22 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
27 ACE_ERROR_RETURN ((LM_ERROR
,
34 // Indicates successful parsing of the command line
41 * Use the ACE_Task_Base class to run server threads
43 class Worker
: public ACE_Task_Base
46 Worker (CORBA::ORB_ptr orb
);
50 // The thread entry point.
58 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
62 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
64 CORBA::Object_var poa_object
=
65 orb
->resolve_initial_references("RootPOA");
67 if (CORBA::is_nil (poa_object
.in ()))
68 ACE_ERROR_RETURN ((LM_ERROR
,
69 " (%P|%t) Unable to initialize the POA.\n"),
72 PortableServer::POA_var root_poa
=
73 PortableServer::POA::_narrow (poa_object
.in ());
75 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
77 if (parse_args (argc
, argv
) != 0)
80 Simple_Server_i
server_impl (orb
.in ());
82 PortableServer::ObjectId_var id
=
83 root_poa
->activate_object (&server_impl
);
85 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
87 Simple_Server_var server
= Simple_Server::_narrow (object
.in ());
89 CORBA::String_var ior
= orb
->object_to_string (server
.in ());
91 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
93 // If the ior_output_file exists, output the ior to it
94 if (ior_output_file
!= 0)
96 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
98 ACE_ERROR_RETURN ((LM_ERROR
,
99 "Cannot open output file for writing IOR: %s",
102 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
103 ACE_OS::fclose (output_file
);
106 poa_manager
->activate ();
108 Worker
worker (orb
.in ());
109 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
111 ACE_ERROR_RETURN ((LM_ERROR
,
112 "Cannot activate client threads\n"),
115 worker
.thr_mgr ()->wait ();
117 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
119 const char *fname
= "server_terminated";
120 FILE *output_file
= ACE_OS::fopen (fname
, "w");
121 if (output_file
== 0)
122 ACE_ERROR_RETURN ((LM_ERROR
,
123 "Cannot open output file for writing: ",
126 ACE_OS::fprintf (output_file
, "%s", "OK\n");
127 ACE_OS::fclose (output_file
);
129 catch (const CORBA::Exception
& ex
)
131 ex
._tao_print_exception ("Exception caught:");
138 // ****************************************************************
140 Worker::Worker (CORBA::ORB_ptr orb
)
141 : orb_ (CORBA::ORB::_duplicate (orb
))
152 catch (const CORBA::Exception
&)