2 #include "ace/Get_Opt.h"
4 #include "tao/ORB_Core.h"
6 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("file://test.ior");
7 const ACE_TCHAR
*srv_shutdown_file
= ACE_TEXT("server_terminated");
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:n:x:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.opt_arg ();
25 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
29 srv_shutdown_file
= get_opts
.opt_arg ();
34 ACE_ERROR_RETURN ((LM_ERROR
,
41 // Indicates successful parsing of the command line
48 * Use the ACE_Task_Base class to run server threads
50 class Worker
: public ACE_Task_Base
53 Worker (CORBA::ORB_ptr orb
);
57 // The thread entry point.
65 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
69 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
71 CORBA::Object_var poa_object
=
72 orb
->resolve_initial_references("RootPOA");
74 if (CORBA::is_nil (poa_object
.in ()))
75 ACE_ERROR_RETURN ((LM_ERROR
,
76 " (%P|%t) Unable to initialize the POA.\n"),
79 PortableServer::POA_var root_poa
=
80 PortableServer::POA::_narrow (poa_object
.in ());
82 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
84 if (parse_args (argc
, argv
) != 0)
87 Simple_Server_i
server_impl (orb
.in ());
89 PortableServer::ObjectId_var id
=
90 root_poa
->activate_object (&server_impl
);
92 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
94 Simple_Server_var server
= Simple_Server::_narrow (object
.in ());
96 CORBA::String_var ior
= orb
->object_to_string (server
.in ());
98 ACE_DEBUG ((LM_DEBUG
, "Activated as <%s>\n", ior
.in ()));
100 // If the ior_output_file exists, output the ior to it
101 if (ior_output_file
!= 0)
103 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
104 if (output_file
== 0)
105 ACE_ERROR_RETURN ((LM_ERROR
,
106 "Cannot open output file for writing IOR: %s",
109 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
110 ACE_OS::fclose (output_file
);
113 poa_manager
->activate ();
115 Worker
worker (orb
.in ());
116 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
118 ACE_ERROR_RETURN ((LM_ERROR
,
119 "Cannot activate client threads\n"),
122 worker
.thr_mgr ()->wait ();
124 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
126 FILE *output_file
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(srv_shutdown_file
), "w");
127 if (output_file
== 0)
128 ACE_ERROR_RETURN ((LM_ERROR
,
129 "Cannot open output file for writing: ",
130 ACE_TEXT_ALWAYS_CHAR(srv_shutdown_file
)),
132 ACE_OS::fprintf (output_file
, "%s", "OK\n");
133 ACE_OS::fclose (output_file
);
135 catch (const CORBA::Exception
& ex
)
137 ex
._tao_print_exception ("Exception caught:");
144 // ****************************************************************
146 Worker::Worker (CORBA::ORB_ptr orb
)
147 : orb_ (CORBA::ORB::_duplicate (orb
))
158 catch (const CORBA::Exception
&)