diff options
Diffstat (limited to 'TAO/tests/MProfile_Forwarding/Manager.cpp')
-rw-r--r-- | TAO/tests/MProfile_Forwarding/Manager.cpp | 304 |
1 files changed, 0 insertions, 304 deletions
diff --git a/TAO/tests/MProfile_Forwarding/Manager.cpp b/TAO/tests/MProfile_Forwarding/Manager.cpp deleted file mode 100644 index acb82622d62..00000000000 --- a/TAO/tests/MProfile_Forwarding/Manager.cpp +++ /dev/null @@ -1,304 +0,0 @@ -//$Id$ -#include "ace/Get_Opt.h" -#include "Manager.h" - -const char *first_ior = 0; -const char *second_ior = 0; -const char *third_ior = 0; -const char *ior_output_file = 0; - -int -parse_args (int argc, char *argv[]) -{ - ACE_Get_Opt get_opts (argc, argv, "a:b:c:d:"); - int c; - - while ((c = get_opts ()) != -1) - switch (c) - { - case 'a': - first_ior = get_opts.optarg; - break; - case 'b': - second_ior = get_opts.optarg; - break; - case 'c': - third_ior = get_opts.optarg; - break; - case 'd': - ior_output_file = get_opts.optarg; - break; - case '?': - default: - ACE_ERROR_RETURN ((LM_ERROR, - "usage: %s " - "-a <iorfile>" - "-b <iorfile>" - "-c <iorfile>" - "\n", - argv [0]), - -1); - } - // Indicates sucessful parsing of the command line - return 0; -} - - -int -main (int argc, - char *argv[]) -{ - ACE_DECLARE_NEW_CORBA_ENV; - - Manager manager; - - ACE_TRY - { - // Initilaize the ORB, POA etc. - manager.init (argc, - argv, - ACE_TRY_ENV); - ACE_TRY_CHECK; - - if (parse_args (argc, argv) == -1) - return -1; - - manager.activate_servant (ACE_TRY_ENV); - ACE_TRY_CHECK; - - manager.make_iors_register (ACE_TRY_ENV); - ACE_TRY_CHECK; - - manager.run (ACE_TRY_ENV); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Caught"); - return -1; - } - ACE_ENDTRY; - - return 0; -} - -Manager::Manager (void) - :orb_ (0), - new_poa_var_ (0) -{ - //no-op -} - -int -Manager::init (int argc, - char *argv[], - CORBA::Environment &ACE_TRY_ENV) -{ - this->orb_ = CORBA::ORB_init (argc, - argv, - 0, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - // Obtain the RootPOA. - CORBA::Object_var obj_var = - this->orb_->resolve_initial_references ("RootPOA"); - - // Get the POA_var object from Object_var. - PortableServer::POA_var root_poa_var = - PortableServer::POA::_narrow (obj_var.in (), ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - // Get the POAManager of the RootPOA. - PortableServer::POAManager_var poa_manager_var = - root_poa_var->the_POAManager (ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - poa_manager_var->activate (ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - // Policies for the childPOA to be created. - CORBA::PolicyList policies (4); - policies.length (4); - - // The next two policies are common to both - // Id Assignment Policy - policies[0] = - root_poa_var->create_id_assignment_policy (PortableServer::USER_ID, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - // Lifespan policy - policies[1] = - root_poa_var->create_lifespan_policy (PortableServer::PERSISTENT, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - // Tell the POA to use a servant manager - policies[2] = - root_poa_var->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - // Servant Retention Policy -> Use a locator - policies[3] = - root_poa_var->create_servant_retention_policy (PortableServer::NON_RETAIN, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - ACE_CString name = "newPOA"; - - new_poa_var_ = - root_poa_var->create_POA (name.c_str (), - poa_manager_var.in (), - policies, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - // Creation of childPOAs is over. Destroy the Policy objects. - for (CORBA::ULong i = 0; - i < policies.length (); - ++i) - { - CORBA::Policy_ptr policy = policies[i]; - policy->destroy (ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - } - - return 0; -} - - -int -Manager::activate_servant (CORBA::Environment &ACE_TRY_ENV) -{ - - ACE_NEW_THROW_EX (this->servant_locator_, - Servant_Locator (this->orb_), - CORBA::NO_MEMORY ()); - ACE_CHECK_RETURN (-1); - - PortableServer::ServantLocator_var servant_locator_var = - this->servant_locator_->_this (ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - // Set ServantLocator object as the servant Manager of - // secondPOA. - this->new_poa_var_->set_servant_manager (servant_locator_var.in (), - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - // Try to create a reference with user created ID in new_poa - // which uses ServantLocator. - - PortableServer::ObjectId_var second_foo_oid_var = - PortableServer::string_to_ObjectId ("Simple_Server"); - - this->new_manager_ior_ = - new_poa_var_->create_reference_with_id (second_foo_oid_var.in (), - "IDL:Simple_Server:1.0", ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - return 0; -} - - -int -Manager::make_iors_register (CORBA::Environment &ACE_TRY_ENV) -{ - // First server - CORBA::Object_var object_primary = - this->orb_->string_to_object (first_ior, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - //Second server - CORBA::Object_var object_secondary = - this->orb_->string_to_object (second_ior, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - if (third_ior == 0) - ACE_DEBUG ((LM_DEBUG, - "Here is the culprit \n")); - // Third Server - CORBA::Object_var object_tertiary = - this->orb_->string_to_object (third_ior, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - // Get an object reference for the ORBs IORManipultion object! - CORBA_Object_ptr IORM = - this->orb_->resolve_initial_references (TAO_OBJID_IORMANIPULATION, - 0, - ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - TAO_IOP::TAO_IOR_Manipulation_ptr iorm = - TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM, ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - - // Create the list - TAO_IOP::TAO_IOR_Manipulation::IORList iors (3); - iors.length(3); - iors [0] = CORBA::Object::_duplicate (object_primary); - iors [1] = CORBA::Object::_duplicate (object_secondary); - iors [2] = CORBA::Object::_duplicate (this->new_manager_ior_); - - // Create a merged set 1; - CORBA_Object_var merged_set1 = - iorm->merge_iors (iors, ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - if (object_secondary.in () == 0) - ACE_DEBUG ((LM_DEBUG, - " There is a problem 1 ")); - - if (object_tertiary.in () == 0) - ACE_DEBUG ((LM_DEBUG, - " There is a problem \n")); - - TAO_IOP::TAO_IOR_Manipulation::IORList iors_again (3); - iors_again.length(3); - iors_again [0] = CORBA::Object::_duplicate (object_secondary); - iors_again [1] = CORBA::Object::_duplicate (object_tertiary); - iors_again [2] = CORBA::Object::_duplicate (this->new_manager_ior_); - - // Create merged set 2 - CORBA_Object_var merged_set2 = - iorm->merge_iors (iors_again, ACE_TRY_ENV); - ACE_CHECK_RETURN (-1); - - CORBA::String_var iorref1 = - this->orb_->object_to_string (merged_set1); - - if (ior_output_file != 0) - { - FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); - if (output_file == 0) - ACE_ERROR_RETURN ((LM_ERROR, - "Cannot open output file for writing IOR: %s", - ior_output_file), - 1); - ACE_OS::fprintf (output_file, "%s", iorref1.in ()); - ACE_OS::fclose (output_file); - } - - this->servant_locator_->set (merged_set2); - - return 0; -} - - -int -Manager::run (CORBA::Environment &ACE_TRY_ENV) -{ - if (this->orb_->run (ACE_TRY_ENV) == -1) - ACE_ERROR_RETURN ((LM_DEBUG, - "Error in run \n"), - -1); - - return 0; -} |