2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/Thread_Manager.h"
6 #include "tao/ORB_Core_TSS_Resources.h"
7 #include "tao/ORB_Core.h"
8 #include "tao/Dynamic_TP/DTP_Thread_Pool.h"
10 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("middle.ior");
11 const ACE_TCHAR
*upstream_ior
= ACE_TEXT ("file://server.ior");
14 parse_args (int argc
, ACE_TCHAR
*argv
[])
16 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:o:"));
19 while ((c
= get_opts ()) != -1)
23 ior_output_file
= get_opts
.opt_arg ();
26 upstream_ior
= get_opts
.opt_arg ();
30 ACE_ERROR_RETURN ((LM_ERROR
,
38 // Indicates successful parsing of the command line
43 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
48 CORBA::ORB_init (argc
, argv
);
50 CORBA::Object_var obj
=
51 orb
->resolve_initial_references("RootPOA");
53 PortableServer::POA_var root_poa
=
54 PortableServer::POA::_narrow (obj
.in ());
56 if (CORBA::is_nil (root_poa
.in ()))
57 ACE_ERROR_RETURN ((LM_ERROR
,
58 " (%P|%t) Middle panic: nil RootPOA\n"),
61 PortableServer::POAManager_var poa_manager
=
62 root_poa
->the_POAManager ();
64 if (parse_args (argc
, argv
) != 0)
67 obj
= orb
->string_to_object (upstream_ior
);
68 Test::Sleeper_var sleeper
= Test::Sleeper::_narrow (obj
.in ());
70 if (CORBA::is_nil (sleeper
.in()))
71 ACE_ERROR_RETURN ((LM_ERROR
,
72 " (%P|%t) Middle panic: nil sleeper reference\n"),
77 ACE_NEW_RETURN (test_impl
, Middle_i (orb
.in (), sleeper
.in()), 1);
78 PortableServer::ServantBase_var
owner_transfer(test_impl
);
79 PortableServer::ObjectId_var id
= root_poa
->activate_object (test_impl
);
80 obj
= root_poa
->id_to_reference (id
.in ());
82 Test::Middle_var middle
= Test::Middle::_narrow (obj
.in ());
83 CORBA::String_var ior
= orb
->object_to_string (middle
.in ());
85 ACE_DEBUG ((LM_DEBUG
,"Middle calling poa_manager::activate()\n"));
86 poa_manager
->activate ();
88 // Output the IOR to the <ior_output_file>
89 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
91 ACE_ERROR_RETURN ((LM_ERROR
,
92 "Cannot open output file %s for writing IOR: %C",
96 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
97 ACE_OS::fclose (output_file
);
99 TAO_ORB_Core_TSS_Resources
&tss
=
100 *orb
->orb_core ()->get_tss_resources ();
102 // The API calls it a lane but DTP Thread Pools
103 // are always a single lane.
104 TAO_DTP_Thread_Pool
*pool
=
105 static_cast <TAO_DTP_Thread_Pool
*> (tss
.lane_
);
109 ACE_DEBUG ((LM_DEBUG
,"Middle calling orb->run()\n"));
114 ACE_DEBUG ((LM_DEBUG
,"Middle calling pool->wait()\n"));
118 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) Middle - event loop finished\n"));
121 catch (const CORBA::Exception
& ex
)
123 ex
._tao_print_exception ("Middle Exception caught:");