1 #include "Echo_Caller.h"
2 #include "tao/ORB_Core.h"
3 #include "ace/Get_Opt.h"
4 #include "Server_Thread_Pool.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
10 parse_args (int argc
, ACE_TCHAR
*argv
[]);
13 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
18 CORBA::ORB_init (argc
, argv
);
20 CORBA::Object_var poa_object
=
21 orb
->resolve_initial_references("RootPOA");
23 PortableServer::POA_var root_poa
=
24 PortableServer::POA::_narrow (poa_object
.in ());
26 if (CORBA::is_nil (root_poa
.in ()))
27 ACE_ERROR_RETURN ((LM_ERROR
,
28 " (%P|%t) Panic: nil RootPOA\n"),
31 PortableServer::POAManager_var poa_manager
=
32 root_poa
->the_POAManager ();
34 if (parse_args (argc
, argv
) != 0)
37 ACE_Thread_Manager mymanager
;
38 Thread_Pool
callback_pool (orb
.in (), &mymanager
, 10);
40 PortableServer::ServantBase_var impl
;
42 Echo_Caller
* tmp
= 0;
43 // ACE_NEW_RETURN is the worst possible way to handle
44 // exceptions (think: what if the constructor allocates memory
45 // and fails?), but I'm not in the mood to fight for a more
46 // reasonable way to handle allocation errors in ACE.
48 Echo_Caller(&callback_pool
),
53 PortableServer::ObjectId_var id
=
54 root_poa
->activate_object (impl
.in ());
56 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
58 Test::Echo_Caller_var server
=
59 Test::Echo_Caller::_narrow (object_act
.in ());
61 CORBA::String_var ior
=
62 orb
->object_to_string (server
.in ());
64 // If the ior_output_file exists, output the ior to it
65 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
67 ACE_ERROR_RETURN ((LM_ERROR
,
68 "Cannot open output file for writing IOR: %s",
71 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
72 ACE_OS::fclose (output_file
);
74 poa_manager
->activate ();
76 ORB_Task
worker (orb
.in ());
77 worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
82 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) server - event loop finished\n"));
87 root_poa
->destroy (true, true);
91 catch (const CORBA::Exception
& ex
)
93 ex
._tao_print_exception ("Exception caught:");
101 parse_args (int argc
, ACE_TCHAR
*argv
[])
103 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
106 while ((c
= get_opts ()) != -1)
110 ior_output_file
= get_opts
.opt_arg ();
115 ACE_ERROR_RETURN ((LM_ERROR
,
122 // Indicates successful parsing of the command line