Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / tests / Dynamic_TP / ORB_ThreadPool / Server.cpp
blob7fb3d8daf0cae2643e93d1d7869cc8088bd730ac
1 #include "Test_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/OS_NS_stdlib.h"
5 #include "ace/Thread_Manager.h"
7 #include "tao/ORB_Core_TSS_Resources.h"
8 #include "tao/ORB_Core.h"
9 #include "tao/Dynamic_TP/DTP_Thread_Pool.h"
11 const ACE_TCHAR *ior_output_file = ACE_TEXT ("server.ior");
13 int
14 parse_args (int argc, ACE_TCHAR *argv[])
16 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:s:p:"));
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 '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-o <iorfile>"
30 "\n",
31 argv [0]),
32 -1);
34 // Indicates successful parsing of the command line
35 return 0;
38 int
39 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
41 try
43 CORBA::ORB_var orb =
44 CORBA::ORB_init (argc, argv);
46 CORBA::Object_var poa_object =
47 orb->resolve_initial_references("RootPOA");
49 PortableServer::POA_var root_poa =
50 PortableServer::POA::_narrow (poa_object.in ());
52 if (CORBA::is_nil (root_poa.in ()))
53 ACE_ERROR_RETURN ((LM_ERROR,
54 " (%P|%t) Server panic: nil RootPOA\n"),
55 1);
57 PortableServer::POAManager_var poa_manager =
58 root_poa->the_POAManager ();
60 if (parse_args (argc, argv) != 0)
61 return 1;
63 Sleeper_i *test_impl;
64 ACE_NEW_RETURN (test_impl, Sleeper_i (orb.in ()), 1);
65 PortableServer::ServantBase_var owner_transfer(test_impl);
66 PortableServer::ObjectId_var id = root_poa->activate_object (test_impl);
67 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
68 Test::Sleeper_var sleeper = Test::Sleeper::_narrow (object.in ());
69 CORBA::String_var ior = orb->object_to_string (sleeper.in ());
71 ACE_DEBUG ((LM_DEBUG,"Server calling poa_manager::activate()\n"));
72 poa_manager->activate ();
74 // Output the IOR to the <ior_output_file>
75 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
76 if (output_file == 0)
77 ACE_ERROR_RETURN ((LM_ERROR,
78 "Cannot open output file %s for writing IOR: %C",
79 ior_output_file,
80 ior.in ()),
81 1);
82 ACE_OS::fprintf (output_file, "%s", ior.in ());
83 ACE_OS::fclose (output_file);
85 TAO_ORB_Core_TSS_Resources &tss =
86 *orb->orb_core ()->get_tss_resources ();
88 // The API calls it a lane but DTP Thread Pools
89 // are always a single lane.
90 TAO_DTP_Thread_Pool *pool =
91 static_cast <TAO_DTP_Thread_Pool *> (tss.lane_);
93 if (pool == 0)
95 ACE_DEBUG ((LM_DEBUG,"Server calling orb->run()\n"));
96 orb->run ();
98 else
100 ACE_OS::sleep (1);
101 ACE_DEBUG ((LM_DEBUG,"Server calling pool->wait()\n"));
102 pool->wait();
105 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Server - event loop finished\n"));
106 orb->destroy ();
108 catch (const CORBA::Exception& ex)
110 ex._tao_print_exception ("Server Exception caught:");
111 return 1;
114 return 0;