diff options
Diffstat (limited to 'TAO/tests')
-rw-r--r-- | TAO/tests/Quoter/Quoter.idl | 79 | ||||
-rw-r--r-- | TAO/tests/Quoter/QuoterFactoryFinder.cpp | 205 | ||||
-rw-r--r-- | TAO/tests/Quoter/QuoterFactoryFinder.h | 26 | ||||
-rw-r--r-- | TAO/tests/Quoter/Quoter_Client.cpp | 125 | ||||
-rw-r--r-- | TAO/tests/Quoter/Quoter_Client.h | 15 | ||||
-rw-r--r-- | TAO/tests/Quoter/Quoter_Impl.cpp | 135 | ||||
-rw-r--r-- | TAO/tests/Quoter/Quoter_Impl.h | 26 | ||||
-rw-r--r-- | TAO/tests/Quoter/Quoter_Server.cpp | 32 | ||||
-rw-r--r-- | TAO/tests/Quoter/Quoter_Server.h | 2 |
9 files changed, 338 insertions, 307 deletions
diff --git a/TAO/tests/Quoter/Quoter.idl b/TAO/tests/Quoter/Quoter.idl index e83b42534b1..be0fa4d28ae 100644 --- a/TAO/tests/Quoter/Quoter.idl +++ b/TAO/tests/Quoter/Quoter.idl @@ -1,17 +1,23 @@ // $Id$ + // ============================================================================ // // = FILENAME // quoter.idl // // = DESCRIPTION -// Quoter example uses the POA and CosLifeCycle interfaces +// Quoter example that illustrate the use of the global POA and +// the CosLifeCycle service. // // = AUTHOR // Darrell Brunsch (brunsch@cs.wustl.edu) // Michael Kircher (mk1@cs.wustl.edu) // +// ============================================================================ +// @@ Is there a way to get TAO's IDL compiler to accept "relative +// names" via the use of a command-line option? It seems wrong to +// hard-code the pathname here. #include "../../orbsvcs/orbsvcs/CosLifeCycle.idl" module Stock @@ -20,51 +26,52 @@ module Stock exception Invalid_Quoter {}; interface Quoter : CosLifeCycle::LifeCycleObject - { - // = TITLE - // Access Stock information. + { + // = TITLE + // Access Stock information. - long get_quote (in string stock_name) - raises (Invalid_Stock, Invalid_Quoter); - // Returns the current stock value or throws and exception. + long get_quote (in string stock_name) + raises (Invalid_Stock, Invalid_Quoter); + // Returns the current stock value or throws and exception. - void destroy (); - // Destroy a Quoter session and release resources. + void destroy (); + // Destroy a Quoter session and release resources. - // LifeCycleObject copy(in FactoryFinder there, - // in Criteria the_criteria) - // raises(NoFactory, NotCopyable, InvalidCriteria, CannotMeetCriteria); - // copies this object to a location "there" using the "the_criteria" + // LifeCycleObject copy(in FactoryFinder there, + // in Criteria the_criteria) + // raises(NoFactory, NotCopyable, InvalidCriteria, CannotMeetCriteria); + // copies this object to a location "there" using the "the_criteria" - // void move(in FactoryFinder there, - // in Criteria the_criteria) - // raises(NoFactory, NotMovable, InvalidCriteria, CannotMeetCriteria); - // moves this object to a location "there" using the "the_criteria" + // void move(in FactoryFinder there, + // in Criteria the_criteria) + // raises(NoFactory, NotMovable, InvalidCriteria, CannotMeetCriteria); + // moves this object to a location "there" using the "the_criteria" - // void remove() - // raises(NotRemovable); - // removes/deletes this object + // void remove() + // raises(NotRemovable); + // removes/deletes this object - }; + }; interface Quoter_Factory - { - // = TITLE - // Manage the lifecycle of a Quoter object. - Quoter create_quoter (in string name) - raises (Invalid_Quoter); - // Returns a new Quoter selected by name e.g., "Dow Jones," - // "Reuters,", etc - }; + { + // = TITLE + // Manage the lifecycle of a Quoter object. + + Quoter create_quoter (in string name) + raises (Invalid_Quoter); + // Returns a new Quoter selected by name e.g., "Dow Jones," + // "Reuters,", etc + }; interface QuoterFactoryFinder : CosLifeCycle::FactoryFinder - { - // = TITLE - // Wrapper for the CosLifeCycle FactoryFinder - // - // inherits: - // Factories find_factories(in Key factory_key) raises(NoFactory); - }; + { + // = TITLE + // Wrapper for the CosLifeCycle FactoryFinder + // + // inherits: + // Factories find_factories(in Key factory_key) raises(NoFactory); + }; }; diff --git a/TAO/tests/Quoter/QuoterFactoryFinder.cpp b/TAO/tests/Quoter/QuoterFactoryFinder.cpp index d3ded44a597..4a2365abe1e 100644 --- a/TAO/tests/Quoter/QuoterFactoryFinder.cpp +++ b/TAO/tests/Quoter/QuoterFactoryFinder.cpp @@ -1,4 +1,5 @@ // $Id$ + // ============================================================================ // // = FILENAME @@ -20,58 +21,59 @@ static const char usage [] = "[-? |\n" " [-O[RBport] ORB port number]]"; - +// @@ The string above looks odd. Do you really need it to look like +// this?! // Constructor -QuoterFactoryFinder_i::QuoterFactoryFinder_i () { - - TAO_TRY { +QuoterFactoryFinder_i::QuoterFactoryFinder_i (void) +{ + TAO_TRY + { + // Get a reference to the ORB. + CORBA::ORB_var orb_var = TAO_ORB_Core_instance ()->orb (); + TAO_CHECK_ENV; - // get a reference to the ORB - CORBA::ORB_var orb_var = TAO_ORB_Core_instance()->orb(); - TAO_CHECK_ENV; + // Get the Naming Service object reference. + CORBA::Object_var namingObj_var = + orb_var->resolve_initial_references ("NameService"); + TAO_CHECK_ENV; - // Get the Naming Service object reference. - CORBA::Object_var namingObj_var = - orb_var->resolve_initial_references ("NameService"); - TAO_CHECK_ENV; + if (CORBA::is_nil (namingObj_var.in ())) + ACE_ERROR ((LM_ERROR, + " (%P|%t) Unable get the Naming Service.\n")); - if (CORBA::is_nil (namingObj_var.in ())) { + // Narrow the object reference to a Naming Context. + CosNaming::NamingContext_var namingContext_var = + CosNaming::NamingContext::_narrow (namingObj_var.in (), + TAO_TRY_ENV); + TAO_CHECK_ENV; - ACE_ERROR((LM_ERROR, - " (%P|%t) Unable get the Naming Service.\n")); - } + // Get the IDL_Quoter naming context. + CosNaming::Name quoterContextName (1); // max = 1 + quoterContextName.length (1); + quoterContextName[0].id = CORBA::string_dup ("IDL_Quoter"); - // narrow the object reference to a Naming Context - CosNaming::NamingContext_var namingContext_var = - CosNaming::NamingContext::_narrow (namingObj_var.in (), - TAO_TRY_ENV); - TAO_CHECK_ENV; - - // get the IDL_Quoter naming context - CosNaming::Name quoterContextName (1); // max = 1 - quoterContextName.length(1); - quoterContextName[0].id = CORBA::string_dup ("IDL_Quoter"); - CORBA::Object_var quoterNamingObj_var = + CORBA::Object_var quoterNamingObj_var = namingContext_var->resolve (quoterContextName, TAO_TRY_ENV); - TAO_CHECK_ENV; + TAO_CHECK_ENV; - quoterNamingContext_var_ = - CosNaming::NamingContext::_narrow (quoterNamingObj_var.in (), - TAO_TRY_ENV); + quoterNamingContext_var_ = + CosNaming::NamingContext::_narrow (quoterNamingObj_var.in (), + TAO_TRY_ENV); + // Bind the QuoterFactory Finder to the IDL_Quoter naming + // context. - // bind the QuoterFactory Finder to the IDL_Quoter naming context + CosNaming::Name quoterFactoryFinderName_ (1); + quoterFactoryFinderName_.length (1); + quoterFactoryFinderName_[0].id = CORBA::string_dup ("QuoterFactoryFinder"); - CosNaming::Name quoterFactoryFinderName_ (1); - quoterFactoryFinderName_.length (1); - quoterFactoryFinderName_[0].id = CORBA::string_dup ("QuoterFactoryFinder"); - this->quoterNamingContext_var_->bind (quoterFactoryFinderName_, - (CORBA::Object *)this, - TAO_TRY_ENV); - TAO_CHECK_ENV; + this->quoterNamingContext_var_->bind (quoterFactoryFinderName_, + (CORBA::Object *) this, + TAO_TRY_ENV); + TAO_CHECK_ENV; - } + } TAO_CATCHANY { TAO_TRY_ENV.print_exception ("SYS_EX"); @@ -79,93 +81,92 @@ QuoterFactoryFinder_i::QuoterFactoryFinder_i () { TAO_ENDTRY; } -// Destructor -QuoterFactoryFinder_i::~QuoterFactoryFinder_i () { +// Destructor. +QuoterFactoryFinder_i::~QuoterFactoryFinder_i (void) +{ } CosLifeCycle::Factories * -QuoterFactoryFinder_i::find_factories (const CosLifeCycle::Key & factory_key, - CORBA::Environment &_env_there) { - +QuoterFactoryFinder_i::find_factories (const CosLifeCycle::Key &factory_key, + CORBA::Environment &_env_there) +{ CORBA::Environment env_here; // fill in the name of the Quoter Factory // CosNaming::Name factoryName (1); // max = 1 - // factoryName.length(1); + // factoryName.length (1); // factoryName[0].id = CORBA::string_dup ("quoter_factory"); // or CosNaming::Name factoryName = (CosNaming::Name) factory_key; - // Try to get a reference to a Quoter Factory CORBA::Object_var quoterObject_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) { - - // 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())) { - - // throw a NoFactory exception - _env_there.exception (new CosLifeCycle::NoFactory (factory_key)); - return 0; - } - - // were able to get a reference to Quoter Factory - else { + // 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; + } - // 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); + // Check if it is a valid Quoter Factory reference. + if (CORBA::is_nil (quoterObject_var.in ())) + { + // throw a NoFactory exception. + _env_there.exception (new CosLifeCycle::NoFactory (factory_key)); + return 0; + } - // dereference the Object pointer - (*factories_ptr)[0] = quoterObject_var; + // 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); - ACE_DEBUG ((LM_DEBUG,"Have reference to a Quoter Factory.\n")); + // Dereference the Object pointer. + (*factories_ptr)[0] = quoterObject_var; - return factories_ptr; - } + ACE_DEBUG ((LM_DEBUG, + "Have reference to a Quoter Factory.\n")); + return factories_ptr; + } } // Function get_options. static u_int -get_options (int argc, - char *argv []) +get_options (int argc, char *argv []) { - // We need the 'O' in get_opt() because we also want to have ORB + // We need the 'O' in get_opt () because we also want to have ORB // parameters, they all start with 'O'. ACE_Get_Opt get_opt (argc, argv, "O?"); int opt; while ((opt = get_opt ()) != EOF) - { - switch (opt) - { - case '?': - ACE_DEBUG ((LM_DEBUG, - "Usage: %s %s\n", - argv[0], usage)); - ACE_OS::exit (0); - break; - default: - ACE_ERROR_RETURN ((LM_ERROR, - "%s: unknown arg, -%c\n" - "Usage: %s %s\n", - argv[0], char(opt), - argv[0], - usage), - 1); - } - } + switch (opt) + { + case '?': + ACE_DEBUG ((LM_DEBUG, + "Usage: %s %s\n", + argv[0], usage)); + ACE_OS::exit (0); + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "%s: unknown arg, -%c\n" + "Usage: %s %s\n", + argv[0], char (opt), + argv[0], + usage), + 1); + } if (argc != get_opt.optind) ACE_ERROR_RETURN ((LM_ERROR, @@ -175,7 +176,6 @@ get_options (int argc, argv[0], usage), 1); - return 0; } @@ -188,6 +188,7 @@ main (int argc, char *argv []) { // Initialize ORB. + // @@ Can you please replace all this with the TAO_ORB_Manager? CORBA::ORB_ptr orb_ptr = CORBA::ORB_init (argc, argv, "internet", @@ -195,25 +196,29 @@ main (int argc, char *argv []) TAO_CHECK_ENV; // Connect to the RootPOA. - CORBA::Object_var poa_object = orb_ptr->resolve_initial_references("RootPOA"); + CORBA::Object_var poa_object = + orb_ptr->resolve_initial_references ("RootPOA"); + if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1); PortableServer::POA_var root_poa = - PortableServer::POA::_narrow (poa_object.in (), TAO_TRY_ENV); + PortableServer::POA::_narrow (poa_object.in (), + TAO_TRY_ENV); TAO_CHECK_ENV; PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (TAO_TRY_ENV); + TAO_CHECK_ENV; - // get the Options + // Get the Options. if (get_options (argc, argv)) ACE_OS::exit (-1); - // instantiate the QuoterFactoryFinder + // Instantiate the QuoterFactoryFinder. QuoterFactoryFinder_i *quoterFactoryFinder_i_ptr_; ACE_NEW_RETURN (quoterFactoryFinder_i_ptr_, QuoterFactoryFinder_i (), diff --git a/TAO/tests/Quoter/QuoterFactoryFinder.h b/TAO/tests/Quoter/QuoterFactoryFinder.h index cf3a166f8a0..6283466993e 100644 --- a/TAO/tests/Quoter/QuoterFactoryFinder.h +++ b/TAO/tests/Quoter/QuoterFactoryFinder.h @@ -1,4 +1,5 @@ // $Id$ + // ============================================================================ // // = FILENAME @@ -17,26 +18,25 @@ #if !defined (QUOTER_FACTORY_FINDER_H) #define QUOTER_FACTORY_FINDER_H - -class QuoterFactoryFinder_i : public POA_Stock::QuoterFactoryFinder { +class QuoterFactoryFinder_i : public POA_Stock::QuoterFactoryFinder +{ // = TILE // A CosLifeCycle conforming Factory Finder for the Quoter // example. It uses the Naming Service to find a fitting factory. public: - QuoterFactoryFinder_i (); - ~QuoterFactoryFinder_i (); + QuoterFactoryFinder_i (void); + ~QuoterFactoryFinder_i (void); - virtual CosLifeCycle::Factories * find_factories ( - const CosLifeCycle::Key & factory_key, - CORBA::Environment &_tao_environment); - // Returns a squence of Factories if factories matching the factory_key - // were found. If no factory was found, then the NoFactory exception, - // defined in CosLifeCycle, is raised. + virtual CosLifeCycle::Factories * find_factories (const CosLifeCycle::Key & factory_key, + CORBA::Environment &_tao_environment); + // Returns a squence of Factories if factories matching the + // factory_key were found. If no factory was found, then the + // NoFactory exception, defined in CosLifeCycle, is raised. private: - CosNaming::NamingContext_var quoterNamingContext_var_; - // Hold a reference to the Quoter example naming context + CosNaming::NamingContext_var quoterNamingContext_var_; + // Hold a reference to the Quoter example naming context. }; -#endif // QUOTER_FACTORY_FINDER_H +#endif /* QUOTER_FACTORY_FINDER_H */ diff --git a/TAO/tests/Quoter/Quoter_Client.cpp b/TAO/tests/Quoter/Quoter_Client.cpp index 214cd60fbd8..73dbbab0cc4 100644 --- a/TAO/tests/Quoter/Quoter_Client.cpp +++ b/TAO/tests/Quoter/Quoter_Client.cpp @@ -2,12 +2,13 @@ //#include "ace/Profile_Timer.h" //#include "ace/Env_Value_T.h" + #include "ace/Read_Buffer.h" #include "quoter_client.h" #include "orbsvcs/CosNamingC.h" Quoter_Task::Quoter_Task (int argc, char **argv) - : argc_(argc), argv_(argv) + : argc_ (argc), argv_ (argv) { // Nothing } @@ -26,10 +27,12 @@ Quoter_Task::svc (void) { CORBA::Object_var naming_obj = this->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); @@ -39,12 +42,15 @@ Quoter_Task::svc (void) quoter_factory_name.length (2); quoter_factory_name[0].id = CORBA::string_dup ("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); + naming_context->resolve (quoter_factory_name, TAO_TRY_ENV); + TAO_CHECK_ENV; Stock::Quoter_Factory_var factory_ = - Stock::Quoter_Factory::_narrow (factory_obj.in (),TAO_TRY_ENV); + Stock::Quoter_Factory::_narrow (factory_obj.in (), + TAO_TRY_ENV); TAO_CHECK_ENV; @@ -208,7 +214,7 @@ Quoter_Client::init_naming_service (void) { TAO_TRY { - CORBA::ORB_ptr orb_ptr = TAO_ORB_Core_instance()->orb(); + CORBA::ORB_ptr orb_ptr = TAO_ORB_Core_instance ()->orb (); TAO_CHECK_ENV; CORBA::Object_var naming_obj = @@ -225,12 +231,15 @@ Quoter_Client::init_naming_service (void) 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); + naming_context->resolve (quoter_factory_name, + TAO_TRY_ENV); TAO_CHECK_ENV; this->factory_ = - Stock::Quoter_Factory::_narrow (factory_obj.in (),TAO_TRY_ENV); + Stock::Quoter_Factory::_narrow (factory_obj.in (), + TAO_TRY_ENV); TAO_CHECK_ENV; if (CORBA::is_nil (this->factory_.in ())) @@ -256,68 +265,68 @@ Quoter_Client::init (int argc, char **argv) this->argv_ = argv; TAO_TRY - { - // Retrieve the ORB. - this->orb_ = CORBA::ORB_init (this->argc_, - this->argv_, - "internet", - TAO_TRY_ENV); - TAO_CHECK_ENV; + { + // Retrieve the ORB. + this->orb_ = CORBA::ORB_init (this->argc_, + this->argv_, + "internet", + TAO_TRY_ENV); + TAO_CHECK_ENV; - // Parse command line and verify parameters. - if (this->parse_args () == -1) - return -1; + // Parse command line and verify parameters. + if (this->parse_args () == -1) + return -1; - if (this->use_naming_service_) { - naming_result = this->init_naming_service (); - if (naming_result < 0) - 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); + if (this->use_naming_service_) + { + 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); - CORBA::Object_var factory_object = - this->orb_->string_to_object (this->quoter_factory_key_, - TAO_TRY_ENV); - TAO_CHECK_ENV; + CORBA::Object_var factory_object = + this->orb_->string_to_object (this->quoter_factory_key_, + TAO_TRY_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")); + 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); + // Now retrieve the Quoter obj ref corresponding to the key. + this->quoter_ = + this->factory_->create_quoter (this->quoter_key_, + TAO_TRY_ENV); - TAO_CHECK_ENV; - ACE_DEBUG ((LM_DEBUG, "Quoter Created\n")); + 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); - } + if (CORBA::is_nil (this->quoter_)) + 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; @@ -361,7 +370,7 @@ Quoter_Client::init (int argc, char **argv) TAO_CHECK_ENV; this->factory_ = - Stock::Quoter_Factory::_narrow (factory_object.in(), TAO_TRY_ENV); + Stock::Quoter_Factory::_narrow (factory_object.in (), TAO_TRY_ENV); TAO_CHECK_ENV; if (CORBA::is_nil (this->factory_.in ())) diff --git a/TAO/tests/Quoter/Quoter_Client.h b/TAO/tests/Quoter/Quoter_Client.h index c259ed4b5dd..dc9b6bedf7a 100644 --- a/TAO/tests/Quoter/Quoter_Client.h +++ b/TAO/tests/Quoter/Quoter_Client.h @@ -1,8 +1,5 @@ -// $Id$ // -*- C++ -*- - -#if !defined (QUOTER_CLIENT_H) -#define QUOTER_CLIENT_H +// $Id$ // ============================================================================ // @@ -20,6 +17,9 @@ // // ============================================================================ +#if !defined (QUOTER_CLIENT_H) +#define QUOTER_CLIENT_H + #include "ace/Get_Opt.h" #include "ace/Task.h" #include "ace/Thread_Manager.h" @@ -94,6 +94,11 @@ private: class Quoter_Task : public ACE_Task<ACE_SYNCH> { + // = TITLE + // @@@ Write this + // + // = DESCRIPTION + // @@@ Write this public: Quoter_Task (int argc, char **argv); @@ -105,4 +110,4 @@ private: char **argv_; }; -#endif /* QUOTER_CLIENT_H */
\ No newline at end of file +#endif /* QUOTER_CLIENT_H */ diff --git a/TAO/tests/Quoter/Quoter_Impl.cpp b/TAO/tests/Quoter/Quoter_Impl.cpp index 0591d9bda26..9cf81cbd529 100644 --- a/TAO/tests/Quoter/Quoter_Impl.cpp +++ b/TAO/tests/Quoter/Quoter_Impl.cpp @@ -34,12 +34,12 @@ Stock::Quoter_ptr Quoter_Factory_Impl::create_quoter (const char *name, CORBA::Environment &env) { - ACE_DEBUG ((LM_DEBUG, "Quoter Created\n")); + ACE_DEBUG ((LM_DEBUG, + "Quoter Created\n")); ACE_UNUSED_ARG (name); return my_quoter_._this (env); } - // Constructor Quoter_Impl::Quoter_Impl (const char *) @@ -52,7 +52,8 @@ Quoter_Impl::~Quoter_Impl (void) { } -Quoter_Impl::get_quote (char const *stock_name, class CORBA_Environment &env) +Quoter_Impl::get_quote (char const *stock_name, + class CORBA_Environment &env) { ACE_UNUSED_ARG (stock_name); ACE_UNUSED_ARG (env); @@ -73,69 +74,75 @@ void Quoter_Impl::destroy (CORBA::Environment &env) TAO_ORB_Core_instance ()->orb ()->shutdown (); } - - CosLifeCycle::LifeCycleObject_ptr Quoter_Impl::copy (CosLifeCycle::FactoryFinder_ptr there, - const CosLifeCycle::Criteria & the_criteria, - CORBA::Environment &_env_there) { - - TAO_TRY { - // The name of the Quoter Factory - CosLifeCycle::Key factoryKey (1); // max = 1 - factoryKey.length(1); - factoryKey[0].id = CORBA::string_dup ("quoter_factory"); + const CosLifeCycle::Criteria &the_criteria, + CORBA::Environment &_env_there) +{ + TAO_TRY + { + // The name of the Quoter Factory + CosLifeCycle::Key factoryKey (1); // max = 1 + factoryKey.length(1); + factoryKey[0].id = + CORBA::string_dup ("quoter_factory"); - // Find an appropriate factory over there - CosLifeCycle::Factories_ptr factories_ptr = - there->find_factories (factoryKey,_env_there); - - // Only a NoFactory exception might have occured, so if it occured, - // then go immediately back. - if (_env_there.exception() != 0) { - // _env_there contains already the exception - return CosLifeCycle::LifeCycleObject::_nil(); - } - - // now it is known that there is at least one factory - Stock::Quoter_var quoter_var; - for (unsigned int i = 0; i < factories_ptr->length (); i++) { - - // get the first object reference to a factory - CORBA::Object_var quoter_FactoryObj_var = (*factories_ptr)[i]; - - // narrow it to a Quoter Factory - Stock::Quoter_Factory_var quoter_Factory_var = - Stock::Quoter_Factory::_narrow (quoter_FactoryObj_var.in (), - TAO_TRY_ENV); - TAO_CHECK_ENV; - - // try to get a Quoter created by this factory - quoter_var = quoter_Factory_var->create_quoter ("quoter_copied", TAO_TRY_ENV); - // @@ mk1: The create_quoter should return an exception - TAO_CHECK_ENV; - - if (CORBA::is_nil (quoter_var.in ())) { - - // if we had already our last chance, then give up - if (i == factories_ptr->length ()) { - _env_there.exception (new CosLifeCycle::NoFactory (factoryKey)); + // Find an appropriate factory over there. + CosLifeCycle::Factories_ptr factories_ptr = + there->find_factories (factoryKey, _env_there); + + // Only a NoFactory exception might have occured, so if it + // occured, then go immediately back. + if (_env_there.exception() != 0) + { + // _env_there contains already the exception. return CosLifeCycle::LifeCycleObject::_nil(); } - else { - ACE_ERROR((LM_ERROR,"Quoter::copy: Factory did not create the Quoter properly.\n")); - // else tell what's wrong and try the next factory + + // Now it is known that there is at least one factory. + Stock::Quoter_var quoter_var; + + for (u_int i = 0; i < factories_ptr->length (); i++) + { + // Get the first object reference to a factory. + CORBA::Object_var quoter_FactoryObj_var = (*factories_ptr)[i]; + + // Narrow it to a Quoter Factory. + Stock::Quoter_Factory_var quoter_Factory_var = + Stock::Quoter_Factory::_narrow (quoter_FactoryObj_var.in (), + TAO_TRY_ENV); + TAO_CHECK_ENV; + + // Try to get a Quoter created by this factory. + quoter_var = + quoter_Factory_var->create_quoter ("quoter_copied", TAO_TRY_ENV); + + // @@ mk1: The create_quoter should return an exception + TAO_CHECK_ENV; + + if (CORBA::is_nil (quoter_var.in ())) + { + // If we had already our last chance, then give up. + if (i == factories_ptr->length ()) + { + _env_there.exception (new CosLifeCycle::NoFactory (factoryKey)); + return CosLifeCycle::LifeCycleObject::_nil(); + } + else + { + ACE_ERROR ((LM_ERROR, + "Quoter::copy: Factory did not create the Quoter properly.\n")); + // Else tell what's wrong and try the next factory. + } + } + else + break; + // if succeeded in creating a new Quoter over there, then stop trying } - } - else { - break; - // if succeeded in creating a new Quoter over there, then stop trying - } - } - // return an object reference to the newly created Quoter - return (CosLifeCycle::LifeCycleObject_ptr) quoter_var; - } + // Return an object reference to the newly created Quoter. + return (CosLifeCycle::LifeCycleObject_ptr) quoter_var; + } TAO_CATCHANY { TAO_TRY_ENV.print_exception ("SYS_EX"); @@ -147,8 +154,9 @@ Quoter_Impl::copy (CosLifeCycle::FactoryFinder_ptr there, void Quoter_Impl::move (CosLifeCycle::FactoryFinder_ptr there, - const CosLifeCycle::Criteria & the_criteria, - CORBA::Environment &_env_there) { + const CosLifeCycle::Criteria &the_criteria, + CORBA::Environment &_env_there) +{ // for later // this->copy (there, the_criteria, _env_there); @@ -156,10 +164,11 @@ Quoter_Impl::move (CosLifeCycle::FactoryFinder_ptr there, // that the object reference has to stay the same. But if it has // to stay the same this object. the old object, has to forward // further calls. + _env_there.exception (new CosLifeCycle::NotMovable()); } void -Quoter_Impl::remove (CORBA::Environment &_tao_environment) { - +Quoter_Impl::remove (CORBA::Environment &_tao_environment) +{ } diff --git a/TAO/tests/Quoter/Quoter_Impl.h b/TAO/tests/Quoter/Quoter_Impl.h index 3993c8c5a6a..714181643dc 100644 --- a/TAO/tests/Quoter/Quoter_Impl.h +++ b/TAO/tests/Quoter/Quoter_Impl.h @@ -44,18 +44,15 @@ public: virtual void destroy (CORBA_Environment &env); - virtual CosLifeCycle::LifeCycleObject_ptr copy ( - CosLifeCycle::FactoryFinder_ptr there, - const CosLifeCycle::Criteria & the_criteria, - CORBA::Environment &_tao_environment); - - virtual void move ( - CosLifeCycle::FactoryFinder_ptr there, - const CosLifeCycle::Criteria & the_criteria, - CORBA::Environment &_tao_environment); - - virtual void remove ( - CORBA::Environment &_tao_environment); + virtual CosLifeCycle::LifeCycleObject_ptr copy (CosLifeCycle::FactoryFinder_ptr there, + const CosLifeCycle::Criteria &the_criteria, + CORBA::Environment &_tao_environment); + + virtual void move (CosLifeCycle::FactoryFinder_ptr there, + const CosLifeCycle::Criteria &the_criteria, + CORBA::Environment &_tao_environment); + + virtual void remove (CORBA::Environment &_tao_environment); }; class Quoter_Factory_Impl; @@ -68,7 +65,7 @@ class Quoter_Factory_Impl: public POA_Stock::Quoter_Factory // Quoter_Factory_Impl // // = DESCRIPTION - // Factory object returning the quoter_impl objrefs + // Factory object returning the quoter_impl objrefs. public: Quoter_Factory_Impl (void); // Constructor. @@ -78,10 +75,11 @@ public: virtual Stock::Quoter_ptr create_quoter (const char *name, CORBA::Environment &env); - // Return the quoter by the id <name> + // Return the quoter by the id <name>. private: Quoter_Impl my_quoter_; + // @@ Do we just want one of these?! }; #endif /* QUOTER_IMPL_H */ diff --git a/TAO/tests/Quoter/Quoter_Server.cpp b/TAO/tests/Quoter/Quoter_Server.cpp index bd55d214336..e4c4a3fe5d2 100644 --- a/TAO/tests/Quoter/Quoter_Server.cpp +++ b/TAO/tests/Quoter/Quoter_Server.cpp @@ -3,9 +3,9 @@ #include "quoter_server.h" Quoter_Server::Quoter_Server (void) - :num_of_objs_ (1), - use_naming_service_ (1), - ior_output_file_ (0) + : num_of_objs_ (1), + use_naming_service_ (1), + ior_output_file_ (0) { } @@ -56,8 +56,8 @@ Quoter_Server::init (int argc, char** argv, CORBA::Environment& env) { - // Call the init of TAO_ORB_Manager to create a child POA - // under the root POA. + // Call the init of TAO_ORB_Manager to create a child POA under the + // root POA. this->init_child_poa (argc, argv, "child_poa", @@ -91,8 +91,8 @@ Quoter_Server::init (int argc, return 0; } -// Initialisation of Naming Service and register IDL_Quoter Context and -// Quoter_factory object. +// Initialisation of Naming Service and register IDL_Quoter Context +// and Quoter_factory object. int Quoter_Server::init_naming_service (CORBA::Environment& env) @@ -104,10 +104,12 @@ Quoter_Server::init_naming_service (CORBA::Environment& env) CORBA::Object_var naming_obj = orb_ptr->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; @@ -119,6 +121,7 @@ Quoter_Server::init_naming_service (CORBA::Environment& env) 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); @@ -159,9 +162,6 @@ Quoter_Server::init_naming_service (CORBA::Environment& env) TAO_ENDTRY; return 0; - - - } int @@ -196,9 +196,9 @@ Quoter_Server::~Quoter_Server (void) this->my_name_server_->unbind (factory_name,TAO_TRY_ENV); TAO_CHECK_ENV; // Destroy all the POAs. -// this->root_poa_->destroy (CORBA::B_TRUE, -// CORBA::B_TRUE, -// TAO_TRY_ENV); + // this->root_poa_->destroy (CORBA::B_TRUE, + // CORBA::B_TRUE, + // TAO_TRY_ENV); TAO_CHECK_ENV; } TAO_CATCH (CORBA::SystemException, sysex) @@ -220,15 +220,15 @@ main (int argc, char *argv[]) Quoter_Server quoter_server; ACE_DEBUG ((LM_DEBUG, - "\n \t IDL_Quoter:SERVER \n \n")); + "\n\tIDL_Quoter:SERVER \n \n")); TAO_TRY { if (quoter_server.init (argc,argv,TAO_TRY_ENV) == -1) return 1; else { - quoter_server.run (TAO_TRY_ENV); - TAO_CHECK_ENV; + quoter_server.run (TAO_TRY_ENV); + TAO_CHECK_ENV; } } TAO_CATCH (CORBA::SystemException, sysex) diff --git a/TAO/tests/Quoter/Quoter_Server.h b/TAO/tests/Quoter/Quoter_Server.h index 7130a3ac5d4..92e3edac82f 100644 --- a/TAO/tests/Quoter/Quoter_Server.h +++ b/TAO/tests/Quoter/Quoter_Server.h @@ -28,8 +28,6 @@ #include "orbsvcs/Naming/Naming_Utils.h" #include "tao/tao.h" - - class Quoter_Server : public TAO_ORB_Manager { // =TITLE |