1 #include "ace/Get_Opt.h"
3 #include "Server_Worker.h"
5 const ACE_TCHAR
*ior_output_file
= 0;
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
40 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
46 CORBA::ORB_init (argc
, argv
);
48 CORBA::Object_var poa_object
=
49 orb
->resolve_initial_references("RootPOA");
51 if (CORBA::is_nil (poa_object
.in ()))
52 ACE_ERROR_RETURN ((LM_ERROR
,
53 " (%P|%t) Unable to initialize the POA.\n"),
56 // Get a Root POA reference
57 PortableServer::POA_var root_poa
=
58 PortableServer::POA::_narrow (poa_object
.in ());
60 PortableServer::POAManager_var poa_manager
=
61 root_poa
->the_POAManager ();
63 if (parse_args (argc
, argv
) != 0)
66 Simple_Server_i
server_impl (orb
.in ());
68 Simple_Server_var server
=
71 CORBA::String_var ior
=
72 orb
->object_to_string (server
.in ());
74 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
76 // If the ior_output_file exists, output the ior to it
77 if (ior_output_file
!= 0)
79 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
81 ACE_ERROR_RETURN ((LM_ERROR
,
82 "Cannot open output file for writing IOR: %s",
85 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
86 ACE_OS::fclose (output_file
);
89 poa_manager
->activate ();
91 Server_Worker
worker (orb
.in ());
92 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
94 ACE_ERROR_RETURN ((LM_ERROR
,
95 "Cannot activate client threads\n"),
98 worker
.thr_mgr ()->wait ();
100 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
104 catch (const CORBA::Exception
& ex
)
106 ex
._tao_print_exception ("Exception caught:");