Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / CSD_Strategy_Tests / TP_Test_Static / ServerApp.cpp
blob4502397719b3bb535bd841d5df3a3ee3c3c5680f
1 #include "ServerApp.h"
2 #include "Foo_A_i.h"
3 #include "AppHelper.h"
4 #include "TestAppExceptionC.h"
5 #include "AppShutdown.h"
6 #include "ace/Get_Opt.h"
7 // To force static load the service.
8 #include "tao/PI/PI.h"
9 #include "tao/CSD_ThreadPool/CSD_ThreadPool.h"
12 ServerApp::ServerApp()
13 : TestAppBase ("TP_Test_1_Server"),
14 ior_filename_ (ACE_TEXT("test.ior")),
15 num_clients_ (1)
19 int
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);
30 if (result != 0)
32 return result;
35 TheAppShutdown->init(orb.in(), num_clients_);
37 // Get the Root POA
38 PortableServer::POA_var root_poa =
39 RefHelper<PortableServer::POA>::resolve_initial_ref(orb.in(),
40 "RootPOA");
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);
48 policies.length(0);
50 // Create the child POA
51 PortableServer::POA_var child_poa =
52 AppHelper::create_poa("ChildPoa",
53 root_poa.in(),
54 poa_manager.in(),
55 policies);
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(),
66 servant);
68 // Stringify and save the object reference to a file
69 AppHelper::ref_to_file(orb.in(),
70 obj.in(),
71 this->ior_filename_.c_str());
73 // Activate the POA Manager
74 poa_manager->activate();
76 ACE_DEBUG((LM_DEBUG,
77 "(%P|%t) ServerApp is ready. Running the ORB event loop.\n"));
79 // Run the ORB event loop.
80 orb->run ();
82 ACE_DEBUG((LM_DEBUG,
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 ();
93 ACE_DEBUG((LM_DEBUG,
94 "(%P|%t) ServerApp is destroying the Root POA.\n"));
96 root_poa->destroy(1, 1);
98 ACE_DEBUG((LM_DEBUG,
99 "(%P|%t) ServerApp is destroying the ORB.\n"));
101 orb->destroy();
103 ACE_DEBUG((LM_DEBUG,
104 "(%P|%t) ServerApp has completed running successfully.\n"));
106 return 0;
111 ServerApp::parse_args (int argc, ACE_TCHAR *argv[])
113 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:n:"));
115 int c;
117 while ((c = get_opts ()) != -1)
119 switch (c)
121 case 'o':
122 this->ior_filename_ = get_opts.opt_arg();
123 break;
125 case 'n':
127 int tmp = ACE_OS::atoi (get_opts.opt_arg());
128 if (tmp < 1)
130 ACE_ERROR((LM_ERROR,
131 "(%P|%t) Error. -n must be followed by an integer "
132 "value greater than 0.\n"));
133 return -1;
136 this->num_clients_ = tmp;
138 break;
140 case '?':
141 ACE_ERROR((LM_ERROR,
142 "(%P|%t) usage: %s -o <ior_filename> -n <num_clients>\n",
143 argv[0]));
144 return 1;
146 default:
147 ACE_ERROR((LM_ERROR,
148 "(%P|%t) usage: %s -o <ior_filename> -n <num_clients>\n",
149 argv[0]));
150 return -1;
154 return 0;