4 #include "TestAppExceptionC.h"
5 #include "AppShutdown.h"
6 #include "ace/Get_Opt.h"
7 // To force static load the service.
9 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
12 ServerApp::ServerApp()
13 : TestAppBase ("TP_Test_1_Server"),
14 ior_filename_ (ACE_TEXT("test.ior")),
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",
57 // Create the servant object.
58 Foo_A_i
* servant
= new Foo_A_i();
60 // Local smart pointer variable to deal with releasing the reference
61 // to the servant object when the variable falls out of scope.
62 PortableServer::ServantBase_var
servant_owner(servant
);
64 // Obtain the object reference using the servant
65 CORBA::Object_var obj
= AppHelper::activate_servant(child_poa
.in(),
68 // Stringify and save the object reference to a file
69 AppHelper::ref_to_file(orb
.in(),
71 this->ior_filename_
.c_str());
73 // Activate the POA Manager
74 poa_manager
->activate();
77 "(%P|%t) ServerApp is ready. Running the ORB event loop.\n"));
79 // Run the ORB event loop.
83 "(%P|%t) ServerApp ORB event loop has completed.\n"));
85 TheAppShutdown
->wait ();
87 // Calling wait on ACE_Thread_Manager singleton to avoid the problem
88 // that the main thread might exit before all CSD Threads exit.
90 // Wait for all CSD task threads exit.
91 ACE_Thread_Manager::instance ()->wait ();
94 "(%P|%t) ServerApp is destroying the Root POA.\n"));
96 root_poa
->destroy(1, 1);
99 "(%P|%t) ServerApp is destroying the ORB.\n"));
104 "(%P|%t) ServerApp has completed running successfully.\n"));
111 ServerApp::parse_args (int argc
, ACE_TCHAR
*argv
[])
113 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:n:"));
117 while ((c
= get_opts ()) != -1)
122 this->ior_filename_
= get_opts
.opt_arg();
127 int tmp
= ACE_OS::atoi (get_opts
.opt_arg());
131 "(%P|%t) Error. -n must be followed by an integer "
132 "value greater than 0.\n"));
136 this->num_clients_
= tmp
;
142 "(%P|%t) usage: %s -o <ior_filename> -n <num_clients>\n",
148 "(%P|%t) usage: %s -o <ior_filename> -n <num_clients>\n",