diff options
-rw-r--r-- | TAO/tests/Quoter/QuoterFactoryFinder.cpp | 64 | ||||
-rw-r--r-- | TAO/tests/Quoter/Quoter_Client.cpp | 73 | ||||
-rw-r--r-- | TAO/tests/Quoter/Quoter_Server.cpp | 120 |
3 files changed, 127 insertions, 130 deletions
diff --git a/TAO/tests/Quoter/QuoterFactoryFinder.cpp b/TAO/tests/Quoter/QuoterFactoryFinder.cpp index 4a2365abe1e..2e92a975d65 100644 --- a/TAO/tests/Quoter/QuoterFactoryFinder.cpp +++ b/TAO/tests/Quoter/QuoterFactoryFinder.cpp @@ -19,10 +19,7 @@ #include "QuoterFactoryFinder.h" static const char usage [] = -"[-? |\n" -" [-O[RBport] ORB port number]]"; -// @@ The string above looks odd. Do you really need it to look like -// this?! +"[-? |\n[-O[RBport] ORB port number]]"; // Constructor QuoterFactoryFinder_i::QuoterFactoryFinder_i (void) @@ -63,7 +60,6 @@ QuoterFactoryFinder_i::QuoterFactoryFinder_i (void) // Bind the QuoterFactory Finder to the IDL_Quoter naming // context. - CosNaming::Name quoterFactoryFinderName_ (1); quoterFactoryFinderName_.length (1); quoterFactoryFinderName_[0].id = CORBA::string_dup ("QuoterFactoryFinder"); @@ -72,7 +68,6 @@ QuoterFactoryFinder_i::QuoterFactoryFinder_i (void) (CORBA::Object *) this, TAO_TRY_ENV); TAO_CHECK_ENV; - } TAO_CATCHANY { @@ -101,42 +96,57 @@ QuoterFactoryFinder_i::find_factories (const CosLifeCycle::Key &factory_key, CosNaming::Name factoryName = (CosNaming::Name) factory_key; // Try to get a reference to a Quoter Factory - CORBA::Object_var quoterObject_var = + CORBA::Object_var quoterFactoryObject_var = quoterNamingContext_var_->resolve (factoryName, env_here); - // See if there is an exception, if yes then throw the NoFactory - // exception. - if (env_here.exception () != 0) + // see if there is an exception, if yes then throw the NoFactory exception + if (env_here.exception () != 0) { + + // throw a NoFactory exception + _env_there.exception (new CosLifeCycle::NoFactory (factory_key)); + return 0; + } + + // Check if it is a valid Quoter Factory reference + if (CORBA::is_nil (quoterFactoryObject_var.in())) { + + // throw a NoFactory exception + _env_there.exception (new CosLifeCycle::NoFactory (factory_key)); + return 0; + } + + // were able to get a reference to Quoter Factory + else { + + // create a sequence of factories object + CosLifeCycle::Factories *factories_ptr = new CosLifeCycle::Factories (1); + + // See if there is an exception, if yes then throw the NoFactory + // exception. + if (env_here.exception () != 0) { // Throw a NoFactory exception. _env_there.exception (new CosLifeCycle::NoFactory (factory_key)); return 0; } - // Check if it is a valid Quoter Factory reference. - if (CORBA::is_nil (quoterObject_var.in ())) + // using the Naming Service only one reference is available + factories_ptr->length (1); + + // Check if it is a valid Quoter Factory reference. + if (CORBA::is_nil (quoterFactoryObject_var.in ())) { // throw a NoFactory exception. _env_there.exception (new CosLifeCycle::NoFactory (factory_key)); return 0; } - // Were able to get a reference to Quoter Factory. - else - { - // Create a sequence of factories object. - CosLifeCycle::Factories *factories_ptr = new - CosLifeCycle::Factories (1); - // Using the Naming Service only one reference is available. - factories_ptr->length (1); - - // Dereference the Object pointer. - (*factories_ptr)[0] = quoterObject_var; + // insert the object reference + (*factories_ptr)[0] = quoterFactoryObject_var; - ACE_DEBUG ((LM_DEBUG, - "Have reference to a Quoter Factory.\n")); - return factories_ptr; - } + ACE_DEBUG ((LM_DEBUG,"Have reference to a Quoter Factory.\n")); + return factories_ptr; + } } // Function get_options. diff --git a/TAO/tests/Quoter/Quoter_Client.cpp b/TAO/tests/Quoter/Quoter_Client.cpp index 73dbbab0cc4..7a40abf08e8 100644 --- a/TAO/tests/Quoter/Quoter_Client.cpp +++ b/TAO/tests/Quoter/Quoter_Client.cpp @@ -214,28 +214,33 @@ Quoter_Client::init_naming_service (void) { TAO_TRY { - CORBA::ORB_ptr orb_ptr = TAO_ORB_Core_instance ()->orb (); - TAO_CHECK_ENV; - + // Resolve the Naming Service CORBA::Object_var naming_obj = - orb_ptr->resolve_initial_references ("NameService"); + orb_->resolve_initial_references ("NameService"); + if (CORBA::is_nil (naming_obj.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to resolve the Name Service.\n"), -1); + CosNaming::NamingContext_var naming_context = CosNaming::NamingContext::_narrow (naming_obj.in (), TAO_TRY_ENV); TAO_CHECK_ENV; + // Try to get the quoter_factory CosNaming::Name quoter_factory_name (2); quoter_factory_name.length (2); quoter_factory_name[0].id = CORBA::string_dup ("IDL_Quoter"); quoter_factory_name[1].id = CORBA::string_dup ("quoter_factory"); + ACE_DEBUG ((LM_DEBUG, "Trying to resolve the Quoter Factory!\n")); + CORBA::Object_var factory_obj = naming_context->resolve (quoter_factory_name, TAO_TRY_ENV); TAO_CHECK_ENV; + + ACE_DEBUG ((LM_DEBUG, "Resolved the Quoter Factory!\n")); this->factory_ = Stock::Quoter_Factory::_narrow (factory_obj.in (), @@ -260,12 +265,11 @@ Quoter_Client::init_naming_service (void) int Quoter_Client::init (int argc, char **argv) { - int naming_result; this->argc_ = argc; this->argv_ = argv; TAO_TRY - { + { // Retrieve the ORB. this->orb_ = CORBA::ORB_init (this->argc_, this->argv_, @@ -278,55 +282,58 @@ Quoter_Client::init (int argc, char **argv) return -1; if (this->use_naming_service_) - { - naming_result = this->init_naming_service (); + { + int naming_result = this->init_naming_service (); if (naming_result == -1) return naming_result; - } + } else if (this->quoter_factory_key_ == 0) - { - ACE_ERROR_RETURN ((LM_ERROR, - "%s: no quoter factory key specified\n", - this->argv_[0]), - -1); + { + ACE_ERROR_RETURN ((LM_ERROR, + "%s: no quoter factory key specified\n", + this->argv_[0]), + -1); - CORBA::Object_var factory_object = + CORBA::Object_var factory_object = this->orb_->string_to_object (this->quoter_factory_key_, TAO_TRY_ENV); - TAO_CHECK_ENV; + TAO_CHECK_ENV; - this->factory_ = - Stock::Quoter_Factory::_narrow (factory_object.in (), TAO_TRY_ENV); - TAO_CHECK_ENV; + this->factory_ = Stock::Quoter_Factory::_narrow (factory_object.in (), + TAO_TRY_ENV); + TAO_CHECK_ENV; - if (CORBA::is_nil (this->factory_.in ())) - ACE_ERROR_RETURN ((LM_ERROR, - "invalid factory key <%s>\n", - this->quoter_factory_key_), - -1); + if (CORBA::is_nil (this->factory_.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR,"invalid factory key <%s>\n", + this->quoter_factory_key_), + -1); } + } ACE_DEBUG ((LM_DEBUG, "Factory received OK\n")); // Now retrieve the Quoter obj ref corresponding to the key. this->quoter_ = this->factory_->create_quoter (this->quoter_key_, - TAO_TRY_ENV); - + TAO_TRY_ENV); TAO_CHECK_ENV; + ACE_DEBUG ((LM_DEBUG, "Quoter Created\n")); if (CORBA::is_nil (this->quoter_)) - ACE_ERROR_RETURN ((LM_ERROR, - "null quoter objref returned by factory\n"), - -1); + { + ACE_ERROR_RETURN ((LM_ERROR, + "null quoter objref returned by factory\n"), + -1); + } } TAO_CATCHANY - { - TAO_TRY_ENV.print_exception ("Quoter::init"); - return -1; - } + { + TAO_TRY_ENV.print_exception ("Quoter::init"); + return -1; + } TAO_ENDTRY; return 0; diff --git a/TAO/tests/Quoter/Quoter_Server.cpp b/TAO/tests/Quoter/Quoter_Server.cpp index e4c4a3fe5d2..c0ccb8d5e31 100644 --- a/TAO/tests/Quoter/Quoter_Server.cpp +++ b/TAO/tests/Quoter/Quoter_Server.cpp @@ -1,6 +1,19 @@ // $Id$ - -#include "quoter_server.h" +// ============================================================================ +// +// = FILENAME +// Quoter_Server.cpp +// +// = DESCRIPTION +// The Server for the Quoter Factory +// +// = AUTHOR +// Darrell Brunsch (brunsch@cs.wustl.edu) +// Michael Kircher (mk1@cs.wustl.edu) +// +// ============================================================================ + +#include "Quoter_Server.h" Quoter_Server::Quoter_Server (void) : num_of_objs_ (1), @@ -53,38 +66,30 @@ Quoter_Server::parse_args (void) int Quoter_Server::init (int argc, - char** argv, + char* argv[], CORBA::Environment& env) { - // Call the init of TAO_ORB_Manager to create a child POA under the - // root POA. - this->init_child_poa (argc, - argv, - "child_poa", - env); - - TAO_CHECK_ENV_RETURN (env,-1); + //TAO_ORB_Manager::init(); + + // copy them, because parse_args expects them there this->argc_ = argc; this->argv_ = argv; this->parse_args (); + + // activate the object CORBA::String_var str = - this->activate_under_child_poa ("factory", - &this->factory_impl_, - env); - ACE_DEBUG ((LM_DEBUG, - "The IOR is: <%s>\n", - str.in ())); + this->activate (&this->quoter_Factory_Impl_, env); - if (this->ior_output_file_) - { - ACE_OS::fprintf (this->ior_output_file_, - "%s", - str.in ()); - ACE_OS::fclose (this->ior_output_file_); - } + ACE_DEBUG ((LM_DEBUG, "The IOR is: <%s>\n", str.in ())); + if (this->ior_output_file_) + { + ACE_OS::fprintf (this->ior_output_file_, "%s", str.in ()); + ACE_OS::fclose (this->ior_output_file_); + } + if (this->use_naming_service_) return this->init_naming_service (env); @@ -97,7 +102,7 @@ Quoter_Server::init (int argc, int Quoter_Server::init_naming_service (CORBA::Environment& env) { - TAO_TRY + TAO_TRY { CORBA::ORB_ptr orb_ptr = TAO_ORB_Core_instance()->orb(); TAO_CHECK_ENV; @@ -110,49 +115,28 @@ Quoter_Server::init_naming_service (CORBA::Environment& env) " (%P|%t) Unable to resolve the Name Service.\n"), -1); - CosNaming::NamingContext_var naming_context = + namingContext_var_ = CosNaming::NamingContext::_narrow (naming_obj.in (), TAO_TRY_ENV); TAO_CHECK_ENV; - factory = this->factory_impl_._this (env); - TAO_CHECK_ENV_RETURN (env,-1); - - - CosNaming::Name quoter_context_name (1); - quoter_context_name.length (1); - quoter_context_name[0].id = CORBA::string_dup ("IDL_Quoter"); - - this->quoter_context_ = - naming_context->bind_new_context (quoter_context_name, - env); - TAO_CHECK_ENV_RETURN (env,-1); + + CosNaming::Name quoterContextName (1); + quoterContextName.length (1); + quoterContextName[0].id = CORBA::string_dup ("IDL_Quoter"); + CosNaming::NamingContext_var quoterNameContext = + namingContext_var_->bind_new_context (quoterContextName, env); + TAO_CHECK_ENV_RETURN (env, -1); //Register the quoter_factory name with the IDL_quoter Naming //Context... - CosNaming::Name factory_name (1); - factory_name.length (1); - factory_name[0].id = CORBA::string_dup ("quoter_factory"); - this->quoter_context_->bind (factory_name, - factory.in (), - env); - TAO_CHECK_ENV_RETURN (env,-1); - -// CosNaming::Name quoter_factory_name (2); -// quoter_factory_name.length (2); -// quoter_factory_name[0].id = CORBA::string_dup ("IDL_Quoter"); -// quoter_factory_name[1].id = CORBA::string_dup ("quoter_factory"); -// CORBA::Object_var factory_obj = -// naming_context->resolve (quoter_factory_name,TAO_TRY_ENV); -// TAO_CHECK_ENV; -// -// this->factory_ = -// Stock::Quoter_Factory::_narrow (factory_obj.in (),TAO_TRY_ENV); -// TAO_CHECK_ENV; -// -// if (CORBA::is_nil (this->factory_.in ())) -// ACE_ERROR_RETURN ((LM_ERROR, -// " could not resolve quoter factory in Naming service <%s>\n"), -// -1); + CosNaming::Name quoterFactoryContextName (1); + quoterFactoryContextName.length (1); + quoterFactoryContextName[0].id = CORBA::string_dup ("quoter_factory"); + quoterNameContext->bind (quoterFactoryContextName, + quoter_Factory_Impl_._this(env), + env); + TAO_CHECK_ENV_RETURN (env, -1); + } TAO_CATCHANY { @@ -187,19 +171,15 @@ Quoter_Server::~Quoter_Server (void) factory_name.length (2); factory_name[0].id = CORBA::string_dup ("IDL_Quoter"); factory_name[1].id = CORBA::string_dup ("quoter_factory"); - // this->naming_context_->unbind (factory_name,TAO_TRY_ENV); - this->my_name_server_->unbind (factory_name,TAO_TRY_ENV); + this->namingContext_var_->unbind (factory_name,TAO_TRY_ENV); TAO_CHECK_ENV; factory_name.length (1); - // this->naming_context_->unbind - // (factory_name,TAO_TRY_ENV); - this->my_name_server_->unbind (factory_name,TAO_TRY_ENV); - TAO_CHECK_ENV; - // Destroy all the POAs. + this->namingContext_var_->unbind (factory_name,TAO_TRY_ENV); + // this->root_poa_->destroy (CORBA::B_TRUE, // CORBA::B_TRUE, // TAO_TRY_ENV); - TAO_CHECK_ENV; + // TAO_CHECK_ENV; } TAO_CATCH (CORBA::SystemException, sysex) { |