4 #include "TestAppExceptionC.h"
5 #include "AppShutdown.h"
6 #include "ace/Get_Opt.h"
7 #include "tao/CSD_ThreadPool/CSD_TP_Strategy.h"
8 #include "tao/Intrusive_Ref_Count_Handle_T.h"
9 // To force static load the service.
10 #include "tao/PI/PI.h"
11 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
13 ServerApp::ServerApp()
14 : TestAppBase("TP_Test_1_Server"),
20 ServerApp::run_i(int argc
, ACE_TCHAR
* argv
[])
22 // Initialize the ORB before parsing our own args.
23 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
25 // Parse the command-line args for this application.
26 // * Returns -1 if problems are encountered.
27 // * Returns 1 if the usage statement was explicitly requested.
28 // * Returns 0 otherwise.
29 int result
= this->parse_args(argc
, argv
);
35 TheAppShutdown
->init(orb
.in(), num_clients_
);
38 PortableServer::POA_var root_poa
=
39 RefHelper
<PortableServer::POA
>::resolve_initial_ref(orb
.in(),
42 // Get the POAManager from the Root POA.
43 PortableServer::POAManager_var poa_manager
44 = root_poa
->the_POAManager();
46 // Create the child POA Policies.
47 CORBA::PolicyList
policies(0);
50 // Create the child POA
51 PortableServer::POA_var child_poa
=
52 AppHelper::create_poa("ChildPoa",
58 // Create the thread pool servant dispatching strategy object, and
59 // hold it in a (local) smart pointer variable.
60 TAO_Intrusive_Ref_Count_Handle
<TAO::CSD::TP_Strategy
> csd_strategy
=
61 new TAO::CSD::TP_Strategy();
63 // Tell the strategy to apply itself to the child poa.
64 if (csd_strategy
->apply_to(child_poa
.in()) == false)
67 "Failed to apply CSD strategy to child poa.\n"));
71 // Create the servant object.
72 Foo_A_i
* servant
= new Foo_A_i();
74 // Local smart pointer variable to deal with releasing the reference
75 // to the servant object when the variable falls out of scope.
76 PortableServer::ServantBase_var
servant_owner(servant
);
78 // Obtain the object reference using the servant
79 CORBA::Object_var obj
= AppHelper::activate_servant(child_poa
.in(),
82 // Stringify and save the object reference to a file
83 AppHelper::ref_to_file(orb
.in(),
85 this->ior_filename_
.c_str());
87 // Activate the POA Manager
88 poa_manager
->activate();
91 "(%P|%t) ServerApp is ready. Running the ORB event loop.\n"));
93 // Run the ORB event loop.
97 "(%P|%t) ServerApp ORB event loop has completed.\n"));
99 TheAppShutdown
->wait ();
101 // Calling wait on ACE_Thread_Manager singleton to avoid the problem
102 // that the main thread might exit before all CSD Threads exit.
104 // Wait for all CSD task threads exit.
105 ACE_Thread_Manager::instance ()->wait ();
108 "(%P|%t) ServerApp is destroying the Root POA.\n"));
110 root_poa
->destroy(1, 1);
113 "(%P|%t) ServerApp is destroying the ORB.\n"));
118 "(%P|%t) ServerApp has completed running successfully.\n"));
125 ServerApp::parse_args(int argc
, ACE_TCHAR
* argv
[])
127 ACE_Get_Opt
get_opts(argc
, argv
, ACE_TEXT("o:n:"));
131 while ((c
= get_opts()) != -1)
136 this->ior_filename_
= get_opts
.opt_arg();
141 int tmp
= ACE_OS::atoi(get_opts
.opt_arg());
145 "(%P|%t) Error. -n must be followed by an integer "
146 "value greater than 0.\n"));
150 this->num_clients_
= tmp
;
156 "(%P|%t) usage: %s -o <ior_filename> -n <num_clients>\n",
162 "(%P|%t) usage: %s -o <ior_filename> -n <num_clients>\n",