diff options
Diffstat (limited to 'TAO/tests/CSD_Strategy_Tests/TP_Test_Static/ServerApp.cpp')
-rw-r--r-- | TAO/tests/CSD_Strategy_Tests/TP_Test_Static/ServerApp.cpp | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/TAO/tests/CSD_Strategy_Tests/TP_Test_Static/ServerApp.cpp b/TAO/tests/CSD_Strategy_Tests/TP_Test_Static/ServerApp.cpp new file mode 100644 index 00000000000..348e7987ba8 --- /dev/null +++ b/TAO/tests/CSD_Strategy_Tests/TP_Test_Static/ServerApp.cpp @@ -0,0 +1,171 @@ +// $Id$ +#include "ServerApp.h" +#include "Foo_A_i.h" +#include "AppHelper.h" +#include "TestAppExceptionC.h" +#include "AppShutdown.h" +#include "ace/Get_Opt.h" +// To force static load the service. +#include "tao/CSD_ThreadPool/CSD_ThreadPool.h" + + +ServerApp::ServerApp() + : TestAppBase("TP_Test_1_Server"), + ior_filename_ ("test.ior"), + num_clients_ (1) +{ +} + +ServerApp::~ServerApp() +{ +} + +int +ServerApp::run_i(int argc, char* argv[] ACE_ENV_ARG_DECL) +{ + // Initialize the ORB before parsing our own args. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "" ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Parse the command-line args for this application. + // * Returns -1 if problems are encountered. + // * Returns 1 if the usage statement was explicitly requested. + // * Returns 0 otherwise. + int result = this->parse_args(argc, argv); + if (result != 0) + { + return result; + } + + TheAppShutdown->init(orb.in(), num_clients_ ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Get the Root POA + PortableServer::POA_var root_poa = + RefHelper<PortableServer::POA>::resolve_initial_ref(orb.in(), + "RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Get the POAManager from the Root POA. + PortableServer::POAManager_var poa_manager + = root_poa->the_POAManager(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Create the child POA Policies. + CORBA::PolicyList policies(0); + policies.length(0); + + // Create the child POA + PortableServer::POA_var child_poa = + AppHelper::create_poa("ChildPoa", + root_poa.in(), + poa_manager.in(), + policies + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Create the servant object. + Foo_A_i* servant = new Foo_A_i(); + + // Local smart pointer variable to deal with releasing the reference + // to the servant object when the variable falls out of scope. + PortableServer::ServantBase_var servant_owner(servant); + + // Obtain the object reference using the servant + CORBA::Object_var obj = AppHelper::activate_servant(child_poa.in(), + servant + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Stringify and save the object reference to a file + AppHelper::ref_to_file(orb.in(), + obj.in(), + this->ior_filename_.c_str() + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Activate the POA Manager + poa_manager->activate(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + ACE_DEBUG((LM_DEBUG, + "(%P|%t) ServerApp is ready. Running the ORB event loop.\n")); + + // Run the ORB event loop. + orb->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + ACE_DEBUG((LM_DEBUG, + "(%P|%t) ServerApp ORB event loop has completed.\n")); + + TheAppShutdown->wait (); + + ACE_DEBUG((LM_DEBUG, + "(%P|%t) ServerApp is destroying the Root POA.\n")); + + ACE_DEBUG((LM_DEBUG, + "(%P|%t) ServerApp is destroying the Root POA.\n")); + + root_poa->destroy(1, 1 ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + ACE_DEBUG((LM_DEBUG, + "(%P|%t) ServerApp is destroying the ORB.\n")); + + orb->destroy(ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + ACE_DEBUG((LM_DEBUG, + "(%P|%t) ServerApp has completed running successfully.\n")); + + return 0; +} + + +int +ServerApp::parse_args(int argc, char* argv[]) +{ + ACE_Get_Opt get_opts(argc, argv, "o:n:"); + + int c; + + while ((c = get_opts()) != -1) + { + switch (c) + { + case 'o': + this->ior_filename_ = get_opts.opt_arg(); + break; + + case 'n': + { + int tmp = ACE_OS::atoi(get_opts.opt_arg()); + if (tmp < 1) + { + ACE_ERROR((LM_ERROR, + "(%P|%t) Error. -n must be followed by an integer " + "value greater than 0.\n")); + return -1; + } + + this->num_clients_ = tmp; + } + break; + + case '?': + ACE_ERROR((LM_ERROR, + "(%P|%t) usage: %s -o <ior_filename> -n <num_clients>\n", + argv[0])); + return 1; + + default: + ACE_ERROR((LM_ERROR, + "(%P|%t) usage: %s -o <ior_filename> -n <num_clients>\n", + argv[0])); + return -1; + } + } + + return 0; +} |