diff options
author | pradeep <pradeep@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-05-12 07:37:53 +0000 |
---|---|---|
committer | pradeep <pradeep@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-05-12 07:37:53 +0000 |
commit | f50d28320983bcb15ad5852a26c1708f984d6d44 (patch) | |
tree | 2f2c23b96f63c0a71480d59c6bedf2ce55e0f9a1 | |
parent | 416792c8d1e11ed821dba8bc6ab977be3d7f9efa (diff) | |
download | ATCD-f50d28320983bcb15ad5852a26c1708f984d6d44.tar.gz |
*** empty log message ***
8 files changed, 563 insertions, 244 deletions
diff --git a/TAO/orbsvcs/examples/CosEC/Factory/CosEventChannelFactory_i.cpp b/TAO/orbsvcs/examples/CosEC/Factory/CosEventChannelFactory_i.cpp index 06855792215..1f99340f1a2 100644 --- a/TAO/orbsvcs/examples/CosEC/Factory/CosEventChannelFactory_i.cpp +++ b/TAO/orbsvcs/examples/CosEC/Factory/CosEventChannelFactory_i.cpp @@ -15,14 +15,17 @@ TAO_CosEventChannelFactory_i::TAO_CosEventChannelFactory_i (void) TAO_CosEventChannelFactory_i::~TAO_CosEventChannelFactory_i (void) { +#if 0 ACE_DEBUG ((LM_DEBUG, "in TAO_CosEventChannelFactory_i dtor")); +#endif // No-Op. } int TAO_CosEventChannelFactory_i::init (PortableServer::POA_ptr poa, + const char* child_poa_name, CosNaming::NamingContext_ptr naming, CORBA_Environment &TAO_IN_ENV ) @@ -31,24 +34,21 @@ TAO_CosEventChannelFactory_i::init if (poa == PortableServer::POA::_nil ()) return -1; - // Create a UNIQUE_ID policy + // Create a UNIQUE_ID policy because we want the POA to detect + // duplicates for us. PortableServer::IdUniquenessPolicy_var idpolicy = - poa->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID, //UNIQUE_ID, + poa->create_id_uniqueness_policy (PortableServer::UNIQUE_ID, ACE_TRY_ENV); ACE_CHECK_RETURN (-1); - // @@ Pradeep: Why did you end up using the MULTIPLE_ID policy? And - // why doesn't it match with the comment? // Create a PolicyList CORBA::PolicyList policy_list; policy_list.length (1); policy_list [0] = PortableServer::IdUniquenessPolicy::_duplicate (idpolicy); - // @@ Pradeep: maybe a little comment explaining why you don't need - // to override any POA policies would be a good idea. // Create the child POA. - this->poa_ = poa->create_POA ("CosEC_ChildPOA", + this->poa_ = poa->create_POA (child_poa_name, PortableServer::POAManager::_nil (), policy_list, ACE_TRY_ENV); @@ -58,14 +58,9 @@ TAO_CosEventChannelFactory_i::init idpolicy->destroy (ACE_TRY_ENV); ACE_CHECK_RETURN (-1); - this->poa_ = poa; - - // @@ I want to use the child poa but the factoryec::create fails - // with that. - // So use the root poa for the time being. ;( - // @@ Pradeep: Maybe it fails because you didn't specify the USER_ID - // policy too? - return 0; + //this->poa_ = PortableServer::POA::_duplicate (poa); + // uncomment this if we want to use the parent poa for some reason. + return 0; } CosEventChannelAdmin::EventChannel_ptr @@ -78,32 +73,32 @@ TAO_CosEventChannelFactory_i::create { ACE_ASSERT (this->poa_ != PortableServer::POA::_nil ()); + CosEventChannelAdmin::EventChannel_ptr const ec_nil = + CosEventChannelAdmin::EventChannel::_nil (); + ACE_TRY { PortableServer::ObjectId_var oid = TAO_POA::string_to_ObjectId (channel_id); - FactoryCosEventChannel_i *_ec; + FactoryCosEventChannel_i *_ec = 0; ACE_NEW_THROW_EX (_ec, FactoryCosEventChannel_i, CORBA::NO_MEMORY ()); - // @@ Pradeep: you may need to pass more arguments to that - // exception. ACE_TRY_CHECK; auto_ptr <FactoryCosEventChannel_i> ec (_ec); - // @@ Pradeep: you may want to store the _ec variable directly - // in the auto_ptr, that way you don't leak memory if the - // constructor raises an exception... + // let all those contained in FactoryEC use the default POA. + // We only need the FactoryEC's to be unique! + PortableServer::POA_ptr defPOA = this->_default_POA (ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (ec->init (defPOA, + ACE_TRY_ENV) == -1) + return ec_nil; - // @@ Pradeep: use the auto_ptr to manipulate the ec, that way - // you don't need to change the code if the initialization of - // _ec and ec changes. - if (_ec->init (this->poa_, - ACE_TRY_ENV) == -1) - return 0; // @@ Pradeep: you have a point here! the POA that the EC needs // to activate its own objects maybe different from the POA // where you activate the EC itself, this is because the @@ -113,12 +108,12 @@ TAO_CosEventChannelFactory_i::create ACE_CString str_channel_id (channel_id); - if (_ec->activate (str_channel_id, + if (ec->activate (str_channel_id, ACE_TRY_ENV) == -1) - return 0; + return ec_nil; this->poa_->activate_object_with_id (oid, - _ec, + ec.get (), ACE_TRY_ENV); ACE_TRY_CHECK; @@ -128,10 +123,8 @@ TAO_CosEventChannelFactory_i::create ACE_TRY_CHECK; // Give the ownership to the POA. - _ec->_remove_ref (ACE_TRY_ENV); + ec->_remove_ref (ACE_TRY_ENV); ACE_TRY_CHECK; - // @@ Pradeep: is this OK? Does the reference count start at 1 - // then? if (store_in_naming_service && this->naming_ != CosNaming::NamingContext::_nil ()) @@ -151,51 +144,48 @@ TAO_CosEventChannelFactory_i::create } ACE_CATCH (PortableServer::POA::ServantAlreadyActive, sa_ex) { - // @@ Pradeep: you shouldn't return 0, but - // CosEventChannelAdmin::EventChannel::_nil () use a - // temporary variable or a macro if it is too much pain. ACE_THROW_RETURN (CosEventChannelFactory::DuplicateChannel, - 0); + ec_nil); } ACE_CATCH (PortableServer::POA::ObjectAlreadyActive, oaa_ex) { ACE_THROW_RETURN (CosEventChannelFactory::DuplicateChannel, - 0); + ec_nil); } ACE_CATCH (PortableServer::POA::WrongPolicy, wp_ex) { ACE_THROW_RETURN (CORBA::UNKNOWN (), - 0); + ec_nil); } ACE_CATCH (PortableServer::POA::ObjectNotActive, ona_ex) { ACE_THROW_RETURN (CosEventChannelFactory::BindFailed, - 0); + ec_nil); } ACE_CATCH (CosNaming::NamingContext::NotFound, nf_ex) { ACE_THROW_RETURN (CosEventChannelFactory::BindFailed, - 0); + ec_nil); } ACE_CATCH (CosNaming::NamingContext::CannotProceed, cp_ex) { ACE_THROW_RETURN (CosEventChannelFactory::BindFailed, - 0); + ec_nil); } ACE_CATCH (CosNaming::NamingContext::InvalidName, in_ex) { ACE_THROW_RETURN (CosEventChannelFactory::BindFailed, - 0); + ec_nil); } ACE_CATCH (CosNaming::NamingContext::AlreadyBound, ab) { ACE_THROW_RETURN (CosEventChannelFactory::BindFailed, - 0); + ec_nil); } ACE_ENDTRY; - ACE_CHECK_RETURN (0); + ACE_CHECK_RETURN (ec_nil); - ACE_NOTREACHED (return 0;) + ACE_NOTREACHED (return ec_nil;) } void @@ -217,7 +207,7 @@ TAO_CosEventChannelFactory_i::destroy CORBA::Object_var obj = this->poa_->id_to_reference (oid, ACE_TRY_ENV); - ACE_CHECK; + ACE_TRY_CHECK; // Remove from the naming service. if (unbind_from_naming_service && this->naming_ != CosNaming::NamingContext::_nil ()) @@ -227,26 +217,21 @@ TAO_CosEventChannelFactory_i::destroy name[0].id = CORBA::string_dup (channel_id); this->naming_->unbind (name, ACE_TRY_ENV); - ACE_CHECK; + ACE_TRY_CHECK; } - // deactivate from the poa. - this->poa_->deactivate_object (oid, - ACE_TRY_ENV); CosEventChannelAdmin::EventChannel_var fact_ec = CosEventChannelAdmin::EventChannel::_narrow (obj.in (), ACE_TRY_ENV); - ACE_CHECK; - - // @@ Pradeep: in a completely complaint ORB this will fail: you - // are invoking an operation after the servant was - // deactivated. It is even possible that the reference count - // went to 0 already and the program crashes. - // We need to either invoke this before or use - // id_to_servant() then a downcast and then operate on the - // servant directly. + ACE_TRY_CHECK; + fact_ec->destroy (ACE_TRY_ENV); - ACE_CHECK; + ACE_TRY_CHECK; + + // deactivate from the poa. + this->poa_->deactivate_object (oid, + ACE_TRY_ENV); + ACE_TRY_CHECK; } ACE_CATCHANY { @@ -265,6 +250,9 @@ TAO_CosEventChannelFactory_i::find { ACE_ASSERT (this->poa_ != PortableServer::POA::_nil ()); + CosEventChannelAdmin::EventChannel_ptr const ec_nil = + CosEventChannelAdmin::EventChannel::_nil (); + ACE_TRY { PortableServer::ObjectId_var oid = @@ -278,14 +266,13 @@ TAO_CosEventChannelFactory_i::find } ACE_CATCHANY { - // @@ Pradeep: same comment about 0 vs. _nil() ACE_THROW_RETURN (CosEventChannelFactory::NoSuchChannel, - 0); + ec_nil); } ACE_ENDTRY; - ACE_CHECK_RETURN (0); + ACE_CHECK_RETURN (ec_nil); - ACE_NOTREACHED (return 0;) + ACE_NOTREACHED (return ec_nil;) } char* @@ -316,135 +303,3 @@ TAO_CosEventChannelFactory_i::find_channel_id ACE_NOTREACHED (return 0;) } - -int -main (int argc, char *argv []) -{ - // @@ Pradeep: can we put the main function on a separate file? That - // will make it easier for the users to integrate the class in - // their system. - // Also: can we give the users some command line options to - // control the name to use in the naming service? - const char* Factory_Name = "CosEC_Factory"; - // The name of the factory registered with the naming service. - - TAO_CosEventChannelFactory_i *factory_servant_; - // The factory servant. - - PortableServer::POA_var root_poa_; - // Reference to the root poa. - - CORBA::ORB_var orb_; - // The ORB that we use. - - CosEventChannelFactory::ChannelFactory_var factory_; - // The corba object after activation. - - TAO_Naming_Client naming_client_; - // Use a naming client. - - // Ref counted servants are on the heap.. - ACE_NEW_RETURN (factory_servant_, - TAO_CosEventChannelFactory_i (), - 1); - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - orb_ = CORBA::ORB_init (argc, - argv, - "", - ACE_TRY_ENV); - ACE_TRY_CHECK; - - CORBA::Object_var poa_object = - orb_->resolve_initial_references("RootPOA", - ACE_TRY_ENV); - ACE_TRY_CHECK; - - if (CORBA::is_nil (poa_object.in ())) - ACE_ERROR_RETURN ((LM_ERROR, - " (%P|%t) Unable to initialize the POA.\n"), - -1); - - root_poa_ = - PortableServer::POA::_narrow (poa_object.in (), - ACE_TRY_ENV); - ACE_TRY_CHECK; - - PortableServer::POAManager_var poa_manager = - root_poa_->the_POAManager (ACE_TRY_ENV); - - ACE_TRY_CHECK; - - poa_manager->activate (ACE_TRY_ENV); - - ACE_TRY_CHECK; - - // Initialization of the naming service. - if (naming_client_.init (orb_.in ()) != 0) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) Unable to initialize " - "the TAO_Naming_Client. \n"), - 1); - - if (factory_servant_->init (root_poa_.in (), - naming_client_.get_context (), - ACE_TRY_ENV) != 0) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) Unable to initialize " - "the factory. \n"), - 1); - - // activate the factory in the root poa. - factory_ = factory_servant_->_this (ACE_TRY_ENV); - ACE_TRY_CHECK; - - // Give the ownership to the POA. - factory_servant_->_remove_ref (ACE_TRY_ENV); - - ACE_TRY_CHECK; - CORBA::String_var - str = orb_->object_to_string (factory_.in (), - ACE_TRY_ENV); - ACE_TRY_CHECK; - - ACE_DEBUG ((LM_DEBUG, - "CosEvent_Service: The Cos Event Channel Factory IOR is <%s>\n", - str.in ())); - - CosNaming::Name name (1); - name.length (1); - name[0].id = CORBA::string_dup (Factory_Name); - naming_client_->rebind (name, - factory_.in (), - ACE_TRY_ENV); - ACE_TRY_CHECK; - - ACE_DEBUG ((LM_DEBUG, - "Registered with the naming service as %s\n", Factory_Name)); - - orb_->run (); - - return 0; - } - ACE_CATCH (CORBA::UserException, ue) - { - // @@ Pradeep: there is a macro for this: ACE_PRINT_EXCEPTION. - // print_exception() is a TAO extension, so we shouldn't rely - // on it. - ue.print_exception ("cosecfactory: "); - return -1; - } - ACE_CATCH (CORBA::SystemException, se) - { - se.print_exception ("cosecfactory: "); - return -1; - } - ACE_ENDTRY; - ACE_CHECK_RETURN (-1); - - ACE_NOTREACHED (return 0;) - // @@ Pradeep: was this intentional or is it just a misplaced - // semi-colon? -} diff --git a/TAO/orbsvcs/examples/CosEC/Factory/CosEventChannelFactory_i.h b/TAO/orbsvcs/examples/CosEC/Factory/CosEventChannelFactory_i.h index 03a29ca074a..26969aa5836 100644 --- a/TAO/orbsvcs/examples/CosEC/Factory/CosEventChannelFactory_i.h +++ b/TAO/orbsvcs/examples/CosEC/Factory/CosEventChannelFactory_i.h @@ -21,20 +21,12 @@ #ifndef TAO_COSEVENTCHANNELFACTORY_H #define TAO_COSEVENTCHANNELFACTORY_H -// @@ Pradeep: I couldn't find the IDL file did you commit it? #include "CosEventChannelFactoryS.h" - -// @@ Pradeep: you only need to include CosNamingC.h, why is -// CosNamingS.h included? And do you need this include in the -// header file? Isn't the .cpp file enough? -#include "orbsvcs/CosNamingS.h" #include "orbsvcs/CosNamingC.h" class TAO_CosEventChannelFactory_i : public virtual POA_CosEventChannelFactory::ChannelFactory, - // @@ Pradeep: Shouldn't this be PortableServer::RefCountServantBase - // or something similar? - public virtual TAO_RefCountServantBase + public virtual PortableServer::RefCountServantBase { public: // = Initialization and termination code. @@ -45,15 +37,15 @@ class TAO_CosEventChannelFactory_i : // Destructor. int init (PortableServer::POA_ptr poa, + const char* child_poa_name, CosNaming::NamingContext_ptr naming = CosNaming::NamingContext::_nil (), CORBA::Environment &ACE_TRY_ENV = CORBA::Environment::default_environment ()); - // This method creates creates a child poa with <poa> as the + // This method creates a child poa with <poa> as the // parent. It also accepts a Naming_Context which is used to register // the event channels if specified. // Returns -1 on error, 0 on success. // @@ Pradeep: this looks OK. I wonder if it would be a good idea to // raise exceptions, but I'm undecided. - // @@ Pradeep: can the user specify the name of the child poa? // @@ Pradeep: when is the child poa destroyed? Maybe we should add // a destroy() method to the factory interface (in IDL). diff --git a/TAO/orbsvcs/examples/CosEC/Factory/FactoryClient.cpp b/TAO/orbsvcs/examples/CosEC/Factory/FactoryClient.cpp index d0aa3cdabe5..69297b53ee5 100644 --- a/TAO/orbsvcs/examples/CosEC/Factory/FactoryClient.cpp +++ b/TAO/orbsvcs/examples/CosEC/Factory/FactoryClient.cpp @@ -15,7 +15,7 @@ class FactoryClient public: // Initialization and termination methods FactoryClient (void); - ~FactoryClient (void); + virtual ~FactoryClient (void); int init_ORB (int argc, char *argv [], CORBA::Environment &ACE_TRY_ENV); // Initializes the ORB. @@ -38,8 +38,21 @@ protected: createChannel (const char *channel_id, CosEventChannelFactory::ChannelFactory_ptr factory, CORBA::Environment &ACE_TRY_ENV); - // create a channel. + // Create a channel. + void destroyChannel (const char *channel_id, + CORBA::Environment &ACE_TRY_ENV); + // Destroy the channel. + + void findChannel (const char* channel_id, + CORBA::Environment &ACE_TRY_ENV); + // Find a channel. + + void findChannel_Id (CosEventChannelAdmin::EventChannel_ptr channel, + CORBA::Environment &ACE_TRY_ENV); + // Find a channel. + + // = Protected Data members. const char* factoryName_; // The name of the factory registered with the naming service. @@ -154,32 +167,106 @@ FactoryClient::createFactory (CORBA::Environment &ACE_TRY_ENV) CosEventChannelAdmin::EventChannel_ptr FactoryClient::createChannel (const char *channel_id, CosEventChannelFactory::ChannelFactory_ptr factory, + CORBA::Environment &ACE_TRY_ENV) +{ + CosEventChannelAdmin::EventChannel_ptr ec = + CosEventChannelAdmin::EventChannel::_nil (); + + ACE_TRY + { + ec = factory->create (channel_id, + this->use_naming_service, + ACE_TRY_ENV); + ACE_TRY_CHECK; + + ACE_ASSERT (ec != + CosEventChannelAdmin::EventChannel::_nil ()); + + ACE_DEBUG ((LM_DEBUG, + "Created Cos Event Channel \"%s \"\n", + channel_id)); + } + ACE_CATCH (CORBA::UserException, ue) + { + ACE_PRINT_EXCEPTION (ue, + "User Exception in createChannel: "); + return CosEventChannelAdmin::EventChannel::_nil (); + } + ACE_CATCH (CORBA::SystemException, se) + { + ACE_PRINT_EXCEPTION (se, + "System Exception in createChannel: "); + return CosEventChannelAdmin::EventChannel::_nil (); + } + ACE_ENDTRY; + + return ec; +} + +void +FactoryClient::destroyChannel (const char *channel_id, + CORBA::Environment &ACE_TRY_ENV) +{ + ACE_DEBUG ((LM_DEBUG, + "Destroying Cos Event Channel \"%s \"\n", + channel_id)); + + this->factory_->destroy (channel_id, + use_naming_service, + ACE_TRY_ENV); + ACE_CHECK; +} + +void +FactoryClient::findChannel (const char* channel_id, CORBA::Environment &ACE_TRY_ENV) { - CosEventChannelAdmin::EventChannel_var ec = - factory->create (channel_id, - this->use_naming_service, - ACE_TRY_ENV); - ACE_CHECK_RETURN (0); + ACE_DEBUG ((LM_DEBUG, + "trying to find the Channel \"%s \"\n", + channel_id)); + + CosEventChannelAdmin::EventChannel_var channel = + this->factory_->find (channel_id, + ACE_TRY_ENV); + ACE_CHECK; - ACE_ASSERT (ec.in () != - CosEventChannelAdmin::EventChannel::_nil ()); + ACE_DEBUG ((LM_DEBUG, + "find returned %d\n", channel.in ())); - return ec.in (); + this->findChannel_Id (channel.in (), + ACE_TRY_ENV); } +void +FactoryClient:: findChannel_Id +(CosEventChannelAdmin::EventChannel_ptr channel, + CORBA::Environment &ACE_TRY_ENV) +{ + ACE_DEBUG ((LM_DEBUG, + "trying to find the Channel %d \n", + channel)); + + char *channel_id = + this->factory_->find_channel_id (channel, + ACE_TRY_ENV); + ACE_CHECK; + + ACE_DEBUG ((LM_DEBUG, + "find returned %s\n", channel_id)); +} + +/* + * excercise the factory: create 3 Channels and test the factory. + */ + int FactoryClient::run_test (CORBA::Environment &ACE_TRY_ENV) { ACE_ASSERT (this->factory_.in () != CosEventChannelFactory::ChannelFactory::_nil ()); - char *channel_id [3] = {"cosec1", "cosec2", "cosec3"}; - CosEventChannelAdmin::EventChannel_ptr cosec [3]; - - ACE_DEBUG ((LM_DEBUG, - "Trying to create a Cos Event Channel \"%s \"\n", - channel_id[0])); + const char *channel_id [3] = {"cosec1", "cosec2", "cosec3"}; + CosEventChannelAdmin::EventChannel_var cosec [3]; // create the first cosec cosec[0] = this->createChannel (channel_id[0], @@ -187,21 +274,78 @@ FactoryClient::run_test (CORBA::Environment &ACE_TRY_ENV) ACE_TRY_ENV); ACE_CHECK_RETURN (-1); + // create the second cosec + cosec[1] = this->createChannel (channel_id[1], + this->factory_, + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + // create the third cosec + cosec[2] = this->createChannel (channel_id[2], + this->factory_, + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + // see it we can destroy this one.. + this->destroyChannel (channel_id[2], + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + // see if we can create it again? + cosec[2] = this->createChannel (channel_id[2], + this->factory_, + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + // see if it can detect duplicates. + this->createChannel (channel_id[2], + this->factory_, + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + // see if it can give us the id? - ACE_DEBUG ((LM_DEBUG, - "Check to see if it gives us the right id back\n")); - ACE_CString returned_id = - this->factory_->find_channel_id (cosec[0], - ACE_TRY_ENV); + this->findChannel_Id (cosec[0], + ACE_TRY_ENV); ACE_CHECK_RETURN (-1); - // print what we saw.. - ACE_DEBUG ((LM_DEBUG, - "Returned Channel id %s\n", - returned_id.fast_rep ())); + this->findChannel_Id (cosec[1], + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + this->findChannel_Id (cosec[2], + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + // check if we can get the channels from the id. + this->findChannel (channel_id[0], + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + this->findChannel (channel_id[1], + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + this->findChannel (channel_id[2], + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); - // this->orb_->run (); + //destroy them all. + this->destroyChannel (channel_id[0], + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + this->destroyChannel (channel_id[1], + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + this->destroyChannel (channel_id[2], + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + // end of testing. + ACE_DEBUG ((LM_DEBUG, + "Factory testing complete\n")); return 0; } @@ -238,20 +382,21 @@ main (int argc, char *argv []) } ft.run_test (ACE_TRY_ENV); - - return 0; + ACE_TRY_CHECK; } ACE_CATCH (CORBA::UserException, ue) { - ue.print_exception ("User Exception in FactoryClient: "); + ACE_PRINT_EXCEPTION (ue, + "test failed: User Exception in FactoryClient: "); return 1; } ACE_CATCH (CORBA::SystemException, se) { - se.print_exception ("System Exception in FactoryClient: "); + ACE_PRINT_EXCEPTION (se, + "test failed: System Exception in FactoryClient: "); return 1; } ACE_ENDTRY; - ACE_NOTREACHED (return 0;) + return 0; } diff --git a/TAO/orbsvcs/examples/CosEC/Factory/FactoryCosEventChannel_i.cpp b/TAO/orbsvcs/examples/CosEC/Factory/FactoryCosEventChannel_i.cpp index 308de1fc7f2..de6ee5364ec 100644 --- a/TAO/orbsvcs/examples/CosEC/Factory/FactoryCosEventChannel_i.cpp +++ b/TAO/orbsvcs/examples/CosEC/Factory/FactoryCosEventChannel_i.cpp @@ -4,7 +4,7 @@ #include "FactoryCosEventChannel_i.h" // @@ Pradeep: remember to use "" not <> in your includes. -#include <ace/Auto_Ptr.h> +#include "ace/Auto_Ptr.h" // @@ Pradeep: if you are using the new TAO_EC_Event_Channel you // *don't* need a scheduler. @@ -29,8 +29,11 @@ FactoryCosEventChannel_i::FactoryCosEventChannel_i (void) FactoryCosEventChannel_i::~FactoryCosEventChannel_i (void) { +#if 0 ACE_DEBUG ((LM_DEBUG, - "In FactoryCosEventChannel_i dtor")); + "In FactoryCosEventChannel_i %d dtor\n", + this)); +#endif } int @@ -38,7 +41,7 @@ FactoryCosEventChannel_i::init (PortableServer::POA_ptr poa, CORBA::Environment &ACE_TRY_ENV) { ACE_ASSERT (poa != PortableServer::POA::_nil ()); - this->poa_ = poa; + this->poa_ = PortableServer::POA::_duplicate (poa); // Create the Scheduler servant ACE_Config_Scheduler* _sched_servant; @@ -74,6 +77,7 @@ FactoryCosEventChannel_i::init (PortableServer::POA_ptr poa, return 0; // success. } +#if 0 int FactoryCosEventChannel_i::activate (ACE_CString& str_channel_id, CORBA::Environment &ACE_TRY_ENV) @@ -98,7 +102,7 @@ FactoryCosEventChannel_i::activate (ACE_CString& str_channel_id, ACE_TRY_ENV); ACE_CHECK_RETURN (-1); - // Give the ownership to the POA. + this->sched_servant_->_remove_ref (ACE_TRY_ENV); ACE_CHECK_RETURN (-1); @@ -196,6 +200,75 @@ FactoryCosEventChannel_i::activate (ACE_CString& str_channel_id, ACE_TRY_ENV); ACE_CHECK_RETURN (-1); } +#endif + +int +FactoryCosEventChannel_i::activate (ACE_CString& str_channel_id, + CORBA::Environment &ACE_TRY_ENV) +{ + ACE_ASSERT (this->poa_ != PortableServer::POA::_nil ()); + + this->scheduler_ = this->sched_servant_->_this (ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + this->sched_servant_->_remove_ref (ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + /*if (ACE_Scheduler_Factory::server (this->scheduler_.in ()) == -1) + return -1;*/ + + //Activate the Rtec + this->ec_servant_->activate (ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + this->rtec_ = this->ec_servant_->_this (ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + // Give the ownership to the POA. + this->ec_servant_->_remove_ref (ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + // Initialize the CosEC servant. + RtecScheduler::handle_t supp_handle = + this->scheduler_->create ("supplier", + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + this->supplier_qos_.insert (1, + ACE_ES_EVENT_ANY, + supp_handle, + 1); + + RtecScheduler::handle_t cons_handle = + this->scheduler_->create ("consumer", + ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + this->consumer_qos_.start_disjunction_group (); + this->consumer_qos_.insert_source (1, // default = 1 + cons_handle); + + const RtecEventChannelAdmin::ConsumerQOS &consumerqos = + this->consumer_qos_.get_ConsumerQOS (); + + const RtecEventChannelAdmin::SupplierQOS &supplierqos = + this->supplier_qos_.get_SupplierQOS (); + + if (this->cosec_servant_->init (consumerqos, + supplierqos, + this->rtec_.in (), + ACE_TRY_ENV) != 0) + return -1; + ACE_CHECK_RETURN (-1); + + // Start the CosEC + this->cosec_ = this->cosec_servant_->_this (ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); + + // Give the ownership to the POA. + this->cosec_servant_->_remove_ref (ACE_TRY_ENV); + ACE_CHECK_RETURN (-1); +} CosEventChannelAdmin::ConsumerAdmin_ptr FactoryCosEventChannel_i::for_consumers (CORBA::Environment &ACE_TRY_ENV) diff --git a/TAO/orbsvcs/examples/CosEC/Factory/FactoryDriver.cpp b/TAO/orbsvcs/examples/CosEC/Factory/FactoryDriver.cpp new file mode 100644 index 00000000000..946fec75f6b --- /dev/null +++ b/TAO/orbsvcs/examples/CosEC/Factory/FactoryDriver.cpp @@ -0,0 +1,164 @@ +// -*- C++ -*- +// $Id$ + +#include "FactoryDriver.h" +#include "ace/Get_Opt.h" + +FactoryDriver::FactoryDriver (const char* name) + :factoryName_ (name), + child_poa_name_ ("CosEC_ChildPOA"), + factory_servant_ (0) +{ + //No-Op. +} + +FactoryDriver::~FactoryDriver (void) +{ + //No-Op. +} + +int +FactoryDriver::parse_args (int argc, char *argv []) +{ + ACE_Get_Opt get_opts (argc, argv, "dr:"); + int c = 0; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'd': // debug flag. + TAO_debug_level++; + break; + + case 'r': + factoryName_ = get_opts.optarg; + break; + + case '?': // display help for use of the server. + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-r] <Factory Name>" + "\n", + argv [0]), + -1); + } + + // Indicates successful parsing of command line. + return 0; +} + +int +FactoryDriver::start (int argc, char *argv []) +{ + if (this->parse_args (argc, argv) == -1) + return -1; + + // Ref counted servants are on the heap.. + ACE_NEW_RETURN (factory_servant_, + TAO_CosEventChannelFactory_i (), + -1); + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + orb_ = CORBA::ORB_init (argc, + argv, + "", + ACE_TRY_ENV); + ACE_TRY_CHECK; + + CORBA::Object_var poa_object = + orb_->resolve_initial_references("RootPOA", + ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Unable to initialize the POA.\n"), + -1); + + root_poa_ = + PortableServer::POA::_narrow (poa_object.in (), + ACE_TRY_ENV); + ACE_TRY_CHECK; + + PortableServer::POAManager_var poa_manager = + root_poa_->the_POAManager (ACE_TRY_ENV); + + ACE_TRY_CHECK; + + poa_manager->activate (ACE_TRY_ENV); + + ACE_TRY_CHECK; + + // Initialization of the naming service. + if (naming_client_.init (orb_.in ()) != 0) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) Unable to initialize " + "the TAO_Naming_Client. \n"), + 1); + + if (factory_servant_->init (root_poa_.in (), + child_poa_name_, + naming_client_.get_context (), + ACE_TRY_ENV) != 0) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) Unable to initialize " + "the factory. \n"), + 1); + + // activate the factory in the root poa. + factory_ = factory_servant_->_this (ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Give the ownership to the POA. + factory_servant_->_remove_ref (ACE_TRY_ENV); + + ACE_TRY_CHECK; + CORBA::String_var + str = orb_->object_to_string (factory_.in (), + ACE_TRY_ENV); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, + "CosEvent_Service: The Cos Event Channel Factory IOR is <%s>\n", + str.in ())); + + CosNaming::Name name (1); + name.length (1); + name[0].id = CORBA::string_dup (factoryName_); + naming_client_->rebind (name, + factory_.in (), + ACE_TRY_ENV); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, + "Registered with the naming service as %s\n", factoryName_)); + + orb_->run (); + } + ACE_CATCH (CORBA::UserException, ue) + { + ACE_PRINT_EXCEPTION (ue, + "cosecfactory: "); + return 1; + } + ACE_CATCH (CORBA::SystemException, se) + { + ACE_PRINT_EXCEPTION (se, + "cosecfactory: "); + return 1; + } + ACE_ENDTRY; + ACE_CHECK_RETURN (1); + + return 0; +} + +int +FactoryDriver::stop (void) +{ + orb_->shutdown (); + return 0; +} diff --git a/TAO/orbsvcs/examples/CosEC/Factory/FactoryDriver.h b/TAO/orbsvcs/examples/CosEC/Factory/FactoryDriver.h new file mode 100644 index 00000000000..9c66669f0e6 --- /dev/null +++ b/TAO/orbsvcs/examples/CosEC/Factory/FactoryDriver.h @@ -0,0 +1,75 @@ + +// -*- C++ -*- +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/orbsvcs/examples/CosEC/Factory +// +// = FILENAME +// FactoryDriver.h +// +// = DESCRIPTION +// This class implements the Factory driver. +// +// = AUTHOR +// Pradeep Gore <pradeep@cs.wustl.edu> +// +// ============================================================================ + +#ifndef TAO_FACTORYDRIVER_H +#define TAO_FACTORYDRIVER_H + +#include "CosEventChannelFactory_i.h" +#include "orbsvcs/Naming/Naming_Utils.h" + +class FactoryDriver +{ + // = TITLE + // Driver class for the CosEventChannel Factory. + // = DESCRIPTION + // creates a CosEventChannel Factory and registers it with the + // naming service. + // + public: + // = Initialization and termination code. + FactoryDriver (const char* factory = "CosEC_Factory"); + // Constructor. + + ~FactoryDriver (void); + // Destructor. + + int start (int argc, char *argv []); + // Start the driver. + + int stop (void); + //Stop the driver. + + protected: + int parse_args (int argc, char *argv []); + // Parse the command-line arguments and set options. + + const char* factoryName_; + // The name of the factory registered with the naming service. + + const char* child_poa_name_; + // The name of the Child POA. + + TAO_CosEventChannelFactory_i *factory_servant_; + // The factory servant. + + PortableServer::POA_var root_poa_; + // Reference to the root poa. + + CORBA::ORB_var orb_; + // The ORB that we use. + + CosEventChannelFactory::ChannelFactory_var factory_; + // The corba object after activation. + + TAO_Naming_Client naming_client_; + // Use a naming client. + +}; +#endif /* TAO_FACTORYDRIVER_H */ diff --git a/TAO/orbsvcs/examples/CosEC/Factory/Makefile b/TAO/orbsvcs/examples/CosEC/Factory/Makefile index ae44d82973f..a1112a59b2b 100644 --- a/TAO/orbsvcs/examples/CosEC/Factory/Makefile +++ b/TAO/orbsvcs/examples/CosEC/Factory/Makefile @@ -20,6 +20,8 @@ PROG_SRCS = \ CosEventChannelFactory_i.cpp \ FactoryCosEventChannel_i.cpp \ FactoryClient.cpp \ + FactoryDriver.cpp \ + main.cpp SRC = $(IDL_SRC) $(PROG_SRCS) @@ -27,7 +29,9 @@ FACTORY_OBJS = \ CosEventChannelFactoryC.o \ CosEventChannelFactoryS.o \ CosEventChannelFactory_i.o \ - FactoryCosEventChannel_i.o + FactoryCosEventChannel_i.o \ + FactoryDriver.o \ + main.o CLIENT_OBJS = \ FactoryClient.o \ diff --git a/TAO/orbsvcs/examples/CosEC/Factory/main.cpp b/TAO/orbsvcs/examples/CosEC/Factory/main.cpp new file mode 100644 index 00000000000..f705e7613be --- /dev/null +++ b/TAO/orbsvcs/examples/CosEC/Factory/main.cpp @@ -0,0 +1,11 @@ +// -*- C++ -*- +// $Id$ + +#include "FactoryDriver.h" + +int +main (int argc, char *argv []) +{ + FactoryDriver driver; + driver.start (argc, argv); +} |