Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / tests / Dynamic_TP / ORB_ThreadPool / Middle.cpp
blob8f2b3147a860b79eaffc08008e5e907f4d4156c4
1 #include "Test_i.h"
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");
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:o:"));
17 int c;
19 while ((c = get_opts ()) != -1)
20 switch (c)
22 case 'o':
23 ior_output_file = get_opts.opt_arg ();
24 break;
25 case 'k':
26 upstream_ior = get_opts.opt_arg ();
27 break;
28 case '?':
29 default:
30 ACE_ERROR_RETURN ((LM_ERROR,
31 "usage: %s "
32 "-o <iorfile>"
33 "-k <upstream_ior>"
34 "\n",
35 argv [0]),
36 -1);
38 // Indicates successful parsing of the command line
39 return 0;
42 int
43 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
45 try
47 CORBA::ORB_var orb =
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"),
59 1);
61 PortableServer::POAManager_var poa_manager =
62 root_poa->the_POAManager ();
64 if (parse_args (argc, argv) != 0)
65 return 1;
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"),
73 1);
76 Middle_i *test_impl;
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");
90 if (output_file == 0)
91 ACE_ERROR_RETURN ((LM_ERROR,
92 "Cannot open output file %s for writing IOR: %C",
93 ior_output_file,
94 ior.in ()),
95 1);
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_);
107 if (pool == 0)
109 ACE_DEBUG ((LM_DEBUG,"Middle calling orb->run()\n"));
110 orb->run ();
112 else
114 ACE_DEBUG ((LM_DEBUG,"Middle calling pool->wait()\n"));
115 pool->wait();
118 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Middle - event loop finished\n"));
119 orb->destroy ();
121 catch (const CORBA::Exception& ex)
123 ex._tao_print_exception ("Middle Exception caught:");
124 return 1;
127 return 0;