diff options
author | wilson_d <wilson_d@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-10-07 14:35:54 +0000 |
---|---|---|
committer | wilson_d <wilson_d@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-10-07 14:35:54 +0000 |
commit | 1a3b5fff2e356995134aed1f2ac448ad22127754 (patch) | |
tree | ec99f3c00e726b0e4390f8b802ad614ed69e9a4f | |
parent | c743f057a34aa4dbfd0991db8612ac9e91e0be30 (diff) | |
download | ATCD-1a3b5fff2e356995134aed1f2ac448ad22127754.tar.gz |
ChangeLogTag: Tues Oct 7 08:44:52 2003 Dale Wilson <wilson_d@ociweb.com>
30 files changed, 2176 insertions, 1350 deletions
diff --git a/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp b/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp index 229a38fa34c..a7d1690c4c3 100644 --- a/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp +++ b/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp @@ -14,7 +14,6 @@ #include "Fault_Detector_i.h" #include "ace/Get_Opt.h" #include "orbsvcs/CosNamingC.h" -#include "tao/PortableServer/ORB_Manager.h" #include "orbsvcs/PortableGroup/PG_Properties_Decoder.h" // Use this macro at the beginning of CORBA methods @@ -45,20 +44,20 @@ ////////////////////////////////////////////////////// // FT_FaultDetectorFactory_i Construction/destruction -FT_FaultDetectorFactory_i::FT_FaultDetectorFactory_i () +TAO::FT_FaultDetectorFactory_i::FT_FaultDetectorFactory_i () : ior_output_file_(0) - , nsName_(0) - , quitOnIdle_(0) - , emptySlots_(0) - , quitRequested_(0) + , ns_name_(0) + , quit_on_idle_(0) + , empty_slots_(0) + , quit_requested_(0) { } -FT_FaultDetectorFactory_i::~FT_FaultDetectorFactory_i () +TAO::FT_FaultDetectorFactory_i::~FT_FaultDetectorFactory_i () { //scope the guard { - InternalGuard guard (internals_); + InternalGuard guard (this->internals_); // be sure all detectors are gone // before this object disappears @@ -66,32 +65,32 @@ FT_FaultDetectorFactory_i::~FT_FaultDetectorFactory_i () } ACE_DECLARE_NEW_ENV; fini (ACE_ENV_SINGLE_ARG_PARAMETER); - threadManager_.close (); + this->threadManager_.close (); } //////////////////////////////////////////// // FT_FaultDetectorFactory_i private methods -void FT_FaultDetectorFactory_i::shutdown_i() +void TAO::FT_FaultDetectorFactory_i::shutdown_i() { // assume mutex is locked - for (size_t nDetector = 0; nDetector < detectors_.size(); ++nDetector) + for (size_t nDetector = 0; nDetector < this->detectors_.size(); ++nDetector) { - Fault_Detector_i * detector = detectors_[nDetector]; + Fault_Detector_i * detector = this->detectors_[nDetector]; if (detector != 0) { - detector->requestQuit(); + detector->request_quit(); } } } -int FT_FaultDetectorFactory_i::write_IOR() +int TAO::FT_FaultDetectorFactory_i::write_ior() { int result = -1; - FILE* out = ACE_OS::fopen (ior_output_file_, "w"); + FILE* out = ACE_OS::fopen (this->ior_output_file_, "w"); if (out) { - ACE_OS::fprintf (out, "%s", static_cast<const char *>(ior_)); + ACE_OS::fprintf (out, "%s", ACE_static_cast(const char *, this->ior_)); ACE_OS::fclose (out); result = 0; } @@ -107,7 +106,7 @@ int FT_FaultDetectorFactory_i::write_IOR() ////////////////////////////////////////////////////// // FT_FaultDetectorFactory_i public, non-CORBA methods -int FT_FaultDetectorFactory_i::parse_args (int argc, char * argv[]) +int TAO::FT_FaultDetectorFactory_i::parse_args (int argc, char * argv[]) { ACE_Get_Opt get_opts (argc, argv, "o:q"); int c; @@ -117,11 +116,11 @@ int FT_FaultDetectorFactory_i::parse_args (int argc, char * argv[]) switch (c) { case 'o': - ior_output_file_ = get_opts.opt_arg (); + this->ior_output_file_ = get_opts.opt_arg (); break; case 'q': { - quitOnIdle_ = 1; + this->quit_on_idle_ = 1; break; } @@ -142,19 +141,19 @@ int FT_FaultDetectorFactory_i::parse_args (int argc, char * argv[]) return 0; } -const char * FT_FaultDetectorFactory_i::identity () const +const char * TAO::FT_FaultDetectorFactory_i::identity () const { - return identity_.c_str(); + return this->identity_.c_str(); } -int FT_FaultDetectorFactory_i::idle (int & result) +int TAO::FT_FaultDetectorFactory_i::idle (int & result) { ACE_UNUSED_ARG (result); - int quit = quitRequested_; - if (quit == 0 && detectors_.size() == emptySlots_) + int quit = this->quit_requested_; + if (quit == 0 && this->detectors_.size() == this->empty_slots_) { // don't quitOnIdle until something has happened - if (quitOnIdle_ && emptySlots_ != 0) + if (this->quit_on_idle_ && this->empty_slots_ != 0) { ACE_ERROR (( LM_INFO, "FaultDetectorFactory exits due to quit on idle option.\n" @@ -167,53 +166,95 @@ int FT_FaultDetectorFactory_i::idle (int & result) } -int FT_FaultDetectorFactory_i::fini (ACE_ENV_SINGLE_ARG_DECL) +int TAO::FT_FaultDetectorFactory_i::fini (ACE_ENV_SINGLE_ARG_DECL) { - if (ior_output_file_ != 0) + if (this->ior_output_file_ != 0) { - ACE_OS::unlink (ior_output_file_); - ior_output_file_ = 0; + ACE_OS::unlink (this->ior_output_file_); + this->ior_output_file_ = 0; } - if (nsName_ != 0) + if (this->ns_name_ != 0) { - naming_context_->unbind (this_name_ + this->naming_context_->unbind (this_name_ ACE_ENV_ARG_PARAMETER); - nsName_ = 0; + this->ns_name_ = 0; } return 0; } -int FT_FaultDetectorFactory_i::init (TAO_ORB_Manager & orbManager - ACE_ENV_ARG_DECL) +int TAO::FT_FaultDetectorFactory_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) { int result = 0; - orb_ = orbManager.orb(); + this->orb_ = orb; - // Register with the ORB. - ior_ = orbManager.activate (this - ACE_ENV_ARG_PARAMETER); + // Use the ROOT POA for now + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); - if (ior_output_file_ != 0) + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")), + -1); + + // Get the POA object. + this->poa_ = + PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); + + ACE_CHECK_RETURN (-1); + + if (CORBA::is_nil(this->poa_)) { - identity_ = "file:"; - identity_ += ior_output_file_; - result = write_IOR(); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")), + -1); + } + + PortableServer::POAManager_var poa_manager = + this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Register with the POA. + + this->objectId_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // find my IOR + + CORBA::Object_var obj = + this->poa_->id_to_reference (objectId_.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->ior_ = this->orb_->object_to_string (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (this->ior_output_file_ != 0) + { + this->identity_ = "file:"; + this->identity_ += this->ior_output_file_; + result = write_ior(); } else { // if no IOR file specified, // then always try to register with name service - nsName_ = "FT_FaultDetectorFactory"; + this->ns_name_ = "FT_FaultDetectorFactory"; } - if (nsName_ != 0) + if (this->ns_name_ != 0) { - identity_ = "name:"; - identity_ += nsName_; + this->identity_ = "name:"; + this->identity_ += this->ns_name_; CORBA::Object_var naming_obj = - orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); + this->orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; if (CORBA::is_nil(naming_obj.in ())){ @@ -222,14 +263,14 @@ int FT_FaultDetectorFactory_i::init (TAO_ORB_Manager & orbManager 1); } - naming_context_ = - CosNaming::NamingContext::_narrow (naming_obj.in () ACE_ENV_ARG_PARAMETER); + this->naming_context_ = + ::CosNaming::NamingContext::_narrow (naming_obj.in () ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; - this_name_.length (1); - this_name_[0].id = CORBA::string_dup (nsName_); + this->this_name_.length (1); + this->this_name_[0].id = CORBA::string_dup (this->ns_name_); - naming_context_->rebind (this_name_, _this() + this->naming_context_->rebind (this->this_name_, _this() ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; } @@ -237,14 +278,14 @@ int FT_FaultDetectorFactory_i::init (TAO_ORB_Manager & orbManager return result; } -CORBA::ULong FT_FaultDetectorFactory_i::allocateId() +CORBA::ULong TAO::FT_FaultDetectorFactory_i::allocate_id() { - CORBA::ULong id = detectors_.size(); - if (emptySlots_ != 0) + CORBA::ULong id = this->detectors_.size(); + if (this->empty_slots_ != 0) { for(CORBA::ULong pos = 0; pos < id; ++pos) { - if (detectors_[pos] == 0) + if (this->detectors_[pos] == 0) { id = pos; } @@ -252,23 +293,23 @@ CORBA::ULong FT_FaultDetectorFactory_i::allocateId() } else { - detectors_.push_back(0); - emptySlots_ += 1; + this->detectors_.push_back(0); + this->empty_slots_ += 1; } return id; } -void FT_FaultDetectorFactory_i::removeDetector(CORBA::ULong id, Fault_Detector_i * detector) +void TAO::FT_FaultDetectorFactory_i::remove_detector(CORBA::ULong id, TAO::Fault_Detector_i * detector) { - InternalGuard guard (internals_); - if (id < detectors_.size()) + InternalGuard guard (this->internals_); + if (id < this->detectors_.size()) { - if(detectors_[id] == detector) + if(this->detectors_[id] == detector) { - delete detectors_[id]; - detectors_[id] = 0; - emptySlots_ += 1; - if (emptySlots_ == detectors_.size()) + delete this->detectors_[id]; + this->detectors_[id] = 0; + this->empty_slots_ += 1; + if (this->empty_slots_ == this->detectors_.size()) { ACE_ERROR (( LM_INFO, "FaultDetectorFactory is idle.\n" @@ -288,7 +329,7 @@ void FT_FaultDetectorFactory_i::removeDetector(CORBA::ULong id, Fault_Detector_i ACE_ERROR (( LM_ERROR, "Attempt to remove invalid detector %d. Limit %d.\n", ACE_static_cast(int, id), - ACE_static_cast(int, detectors_.size()) + ACE_static_cast(int, this->detectors_.size()) )); } } @@ -296,16 +337,16 @@ void FT_FaultDetectorFactory_i::removeDetector(CORBA::ULong id, Fault_Detector_i ////////////////////////////////////////// // FT_FaultDetectorFactory_i CORBA methods -void FT_FaultDetectorFactory_i::change_properties ( +void TAO::FT_FaultDetectorFactory_i::change_properties ( const FT::Properties & property_set - ACE_ENV_ARG_DECL_WITH_DEFAULTS + ACE_ENV_ARG_DECL ) ACE_THROW_SPEC (( CORBA::SystemException , PortableGroup::InvalidProperty )) { - METHOD_ENTRY(FT_FaultDetectorFactory_i::change_properties); + METHOD_ENTRY(TAO::FT_FaultDetectorFactory_i::change_properties); // TimeT is expressed in 10E-7 seconds (== 100 nSec == 0.1 uSec) static const long timeT_per_uSec = 10L; @@ -318,10 +359,10 @@ void FT_FaultDetectorFactory_i::change_properties ( { // note: these should be unsigned long, but // ACE_Time_Value wants longs. - long uSec = static_cast<long>((value / timeT_per_uSec) % uSec_per_sec); - long sec = static_cast<long>((value / timeT_per_uSec) / uSec_per_sec); + long uSec = ACE_static_cast (long, (value / timeT_per_uSec) % uSec_per_sec); + long sec = ACE_static_cast (long, (value / timeT_per_uSec) / uSec_per_sec); ACE_Time_Value atv(sec, uSec); - Fault_Detector_i::setTimeValue(atv); + TAO::Fault_Detector_i::set_time_for_all_detectors(atv); } else { @@ -334,22 +375,22 @@ void FT_FaultDetectorFactory_i::change_properties ( ex.nam[0].id = CORBA::string_dup(FT::FT_FAULT_MONITORING_INTERVAL); ACE_THROW (ex); } - METHOD_RETURN(FT_FaultDetectorFactory_i::change_properties); + METHOD_RETURN(TAO::FT_FaultDetectorFactory_i::change_properties); } -void FT_FaultDetectorFactory_i::shutdown (ACE_ENV_SINGLE_ARG_DECL) +void TAO::FT_FaultDetectorFactory_i::shutdown (ACE_ENV_SINGLE_ARG_DECL) ACE_THROW_SPEC (( CORBA::SystemException )) { - METHOD_ENTRY(FT_FaultDetectorFactory_i::shutdown); - InternalGuard guard (internals_); + METHOD_ENTRY(TAO::FT_FaultDetectorFactory_i::shutdown); + InternalGuard guard (this->internals_); shutdown_i (); - quitRequested_ = 1; - METHOD_RETURN(FT_FaultDetectorFactory_i::shutdown); + this->quit_requested_ = 1; + METHOD_RETURN(TAO::FT_FaultDetectorFactory_i::shutdown); } -CORBA::Object_ptr FT_FaultDetectorFactory_i::create_object ( +CORBA::Object_ptr TAO::FT_FaultDetectorFactory_i::create_object ( const char * type_id, const FT::Criteria & the_criteria, FT::GenericFactory::FactoryCreationId_out factory_creation_id @@ -364,8 +405,8 @@ CORBA::Object_ptr FT_FaultDetectorFactory_i::create_object ( , PortableGroup::CannotMeetCriteria )) { - METHOD_ENTRY(FT_FaultDetectorFactory_i::create_object); - InternalGuard guard (internals_); + METHOD_ENTRY(TAO::FT_FaultDetectorFactory_i::create_object); + InternalGuard guard (this->internals_); ::TAO_PG::Properties_Decoder decoder (the_criteria); @@ -438,13 +479,13 @@ CORBA::Object_ptr FT_FaultDetectorFactory_i::create_object ( ACE_THROW ( PortableGroup::InvalidCriteria() ); } - CORBA::ULong detectorId = allocateId(); + CORBA::ULong detectorId = allocate_id(); // NOTE: ACE_NEW is incompatable with ACE_Auto_Basic_Ptr // so create a bare pointer first. - Fault_Detector_i * pFD = 0; + TAO::Fault_Detector_i * pFD = 0; - ACE_NEW_NORETURN(pFD, Fault_Detector_i( + ACE_NEW_NORETURN(pFD, TAO::Fault_Detector_i( *this, detectorId, notifier, @@ -460,7 +501,7 @@ CORBA::Object_ptr FT_FaultDetectorFactory_i::create_object ( )); ACE_THROW ( PortableGroup::ObjectNotCreated() ); } - ACE_Auto_Basic_Ptr<Fault_Detector_i> detector(pFD); + ACE_Auto_Basic_Ptr<TAO::Fault_Detector_i> detector(pFD); ACE_NEW_NORETURN ( factory_creation_id, PortableGroup::GenericFactory::FactoryCreationId); @@ -474,18 +515,18 @@ CORBA::Object_ptr FT_FaultDetectorFactory_i::create_object ( } (*factory_creation_id) <<= detectorId; - (*detector).start(threadManager_); + (*detector).start(this->threadManager_); - detectors_[detectorId] = detector.release(); - emptySlots_ -= 1; + this->detectors_[detectorId] = detector.release(); + this->empty_slots_ -= 1; // since FaultDetector is not a CORBA object (it does not implement // an interface.) we always return NIL; - METHOD_RETURN(FT_FaultDetectorFactory_i::create_object) + METHOD_RETURN(TAO::FT_FaultDetectorFactory_i::create_object) CORBA::Object::_nil(); } -void FT_FaultDetectorFactory_i::delete_object ( +void TAO::FT_FaultDetectorFactory_i::delete_object ( const FT::GenericFactory::FactoryCreationId & factory_creation_id ACE_ENV_ARG_DECL ) @@ -494,17 +535,17 @@ void FT_FaultDetectorFactory_i::delete_object ( , PortableGroup::ObjectNotFound )) { - METHOD_ENTRY(FT_FaultDetectorFactory_i::delete_object); + METHOD_ENTRY(TAO::FT_FaultDetectorFactory_i::delete_object); - InternalGuard guard (internals_); + InternalGuard guard (this->internals_); CORBA::ULong detectorId; factory_creation_id >>= detectorId; - if (detectorId < detectors_.size()) + if (detectorId < this->detectors_.size()) { - if(detectors_[detectorId] != 0) + if(this->detectors_[detectorId] != 0) { - detectors_[detectorId]->requestQuit(); + this->detectors_[detectorId]->request_quit(); } else { @@ -515,13 +556,13 @@ void FT_FaultDetectorFactory_i::delete_object ( { ACE_THROW(::PortableGroup::ObjectNotFound()); } - METHOD_RETURN(FT_FaultDetectorFactory_i::delete_object); + METHOD_RETURN(TAO::FT_FaultDetectorFactory_i::delete_object); } -CORBA::Boolean FT_FaultDetectorFactory_i::is_alive (ACE_ENV_SINGLE_ARG_DECL) +CORBA::Boolean TAO::FT_FaultDetectorFactory_i::is_alive (ACE_ENV_SINGLE_ARG_DECL) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_RETURN(FT_FaultDetectorFactory_i::is_alive) + METHOD_RETURN(TAO::FT_FaultDetectorFactory_i::is_alive) 1; } @@ -530,10 +571,10 @@ CORBA::Boolean FT_FaultDetectorFactory_i::is_alive (ACE_ENV_SINGLE_ARG_DECL) // competence-challenged compilers. #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - template ACE_Vector<Fault_Detector_i *>; + template ACE_Vector<TAO::Fault_Detector_i *>; template ACE_Guard<ACE_Mutex>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -# pragma instantiate ACE_Vector<Fault_Detector_i *> +# pragma instantiate ACE_Vector<TAO::Fault_Detector_i *> # pragma ACE_Guard<ACE_Mutex> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.h b/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.h index 9cc440e61c8..800a858ea52 100644 --- a/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.h +++ b/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.h @@ -16,15 +16,18 @@ #ifndef FT_FAULTDETECTORFACTORY_I_H_ #define FT_FAULTDETECTORFACTORY_I_H_ +#include /**/ <ace/pre.h> #include <ace/ACE.h> #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -#include <ace/pre.h> ////////////////////////////////// // Classes declared in this header -class FT_FaultDetectorFactory_i; +namespace TAO +{ + class FT_FaultDetectorFactory_i; +} ///////////////////////////////// // Includes needed by this header @@ -34,8 +37,6 @@ class FT_FaultDetectorFactory_i; ///////////////////// // Forward references -class TAO_ORB_Manager; -class Fault_Detector_i; /** * Implement the FaultDetectorFactory interface. @@ -63,10 +64,10 @@ class Fault_Detector_i; * notification message then sets its own quit requested flag. * * When a detector discovers the quit requested flag has been set - * it calls the removeDetector method of the factory, then ends + * it calls the remove_detector method of the factory, then ends * the thread. * - * The removeDetector method of the factory removes the detector from + * The remove_detector method of the factory removes the detector from * the detectors_ collection, then deletes the Fault_Detector_i object. * * Shutdown: @@ -79,209 +80,230 @@ class Fault_Detector_i; * deleted. * */ -class FT_FaultDetectorFactory_i : public virtual POA_FT::FaultDetectorFactory + +namespace TAO { - typedef ACE_Vector<Fault_Detector_i *> DetectorVec; - - ////////////////////// - // non-CORBA interface -public: - /** - * Default constructor. - */ - FT_FaultDetectorFactory_i (); - - /** - * Virtual destructor. - */ - virtual ~FT_FaultDetectorFactory_i (); - - /** - * Parse command line arguments. - * @param argc traditional C argc - * @param argv traditional C argv - * @return zero for success; nonzero is process return code for failure. - */ - int parse_args (int argc, char * argv[]); - - /** - * Initialize this object. - * @param orbManager our ORB -- we keep var to it. - * @return zero for success; nonzero is process return code for failure. - */ - int init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL_WITH_DEFAULTS); - - /** - * Prepare to exit. - * @return zero for success; nonzero is process return code for failure. - */ - int fini (ACE_ENV_SINGLE_ARG_DECL); - - /** - * Idle-time activity. - * - * @param result is set to process return code if return value is non-zero. - * @return zero to continue; nonzero to exit - */ - int idle(int & result); - - - /** - * Identify this fault detector factory. - * @return a string to identify this object for logging/console message purposes. - */ - const char * identity () const; - - /** - * Remove pointer to individual detector; delete Fault_Detector_i. - * See FaultDetector life cycle description. - * @param id the numerical id assigned to this FaultDetector. - * @param detector a pointer to the detector object (redundant for safety.) - */ - void removeDetector (CORBA::ULong id, Fault_Detector_i * detector); - - ////////////////// - // CORBA interface - // See IDL for documentation - - /////////////////////////////////////////////// - // CORBA interface FaultDetectorFactory methods - virtual void change_properties ( - const FT::Properties & property_set - ACE_ENV_ARG_DECL_WITH_DEFAULTS + ///////////////////// + // Forward references + class Fault_Detector_i; + + ///////////////////// + // Class Declarations + class FT_FaultDetectorFactory_i : public virtual POA_FT::FaultDetectorFactory + { + typedef ACE_Vector<Fault_Detector_i *> DetectorVec; + + ////////////////////// + // non-CORBA interface + public: + /** + * Default constructor. + */ + FT_FaultDetectorFactory_i (); + + /** + * Virtual destructor. + */ + virtual ~FT_FaultDetectorFactory_i (); + + /** + * Parse command line arguments. + * @param argc traditional C argc + * @param argv traditional C argv + * @return zero for success; nonzero is process return code for failure. + */ + int parse_args (int argc, char * argv[]); + + /** + * Initialize this object. + * @param orb our ORB -- we keep var to it. + * @return zero for success; nonzero is process return code for failure. + */ + int init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL); + + /** + * Prepare to exit. + * @return zero for success; nonzero is process return code for failure. + */ + int fini (ACE_ENV_SINGLE_ARG_DECL); + + /** + * Idle-time activity. + * + * @param result is set to process return code if return value is non-zero. + * @return zero to continue; nonzero to exit + */ + int idle(int & result); + + + /** + * Identify this fault detector factory. + * @return a string to identify this object for logging/console message purposes. + */ + const char * identity () const; + + /** + * Remove pointer to individual detector; delete Fault_Detector_i. + * See FaultDetector life cycle description. + * @param id the numerical id assigned to this FaultDetector. + * @param detector a pointer to the detector object (redundant for safety.) + */ + void remove_detector (CORBA::ULong id, Fault_Detector_i * detector); + + ////////////////// + // CORBA interface + // See IDL for documentation + + /////////////////////////////////////////////// + // CORBA interface FaultDetectorFactory methods + virtual void change_properties ( + const FT::Properties & property_set + ACE_ENV_ARG_DECL + ) + ACE_THROW_SPEC (( + CORBA::SystemException + , PortableGroup::InvalidProperty + )); + + virtual void shutdown (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC (( + CORBA::SystemException + )); + + ///////////////////////////////////////// + // CORBA interface GenericFactory methods + virtual CORBA::Object_ptr create_object ( + const char * type_id, + const FT::Criteria & the_criteria, + FT::GenericFactory::FactoryCreationId_out factory_creation_id + ACE_ENV_ARG_DECL ) ACE_THROW_SPEC (( CORBA::SystemException + , PortableGroup::NoFactory + , PortableGroup::ObjectNotCreated + , PortableGroup::InvalidCriteria , PortableGroup::InvalidProperty + , PortableGroup::CannotMeetCriteria + )); + + virtual void delete_object ( + const FT::GenericFactory::FactoryCreationId & factory_creation_id + ACE_ENV_ARG_DECL + ) + ACE_THROW_SPEC (( + CORBA::SystemException + , PortableGroup::ObjectNotFound )); - virtual void shutdown (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC (( - CORBA::SystemException - )); - - ///////////////////////////////////////// - // CORBA interface GenericFactory methods - virtual CORBA::Object_ptr create_object ( - const char * type_id, - const FT::Criteria & the_criteria, - FT::GenericFactory::FactoryCreationId_out factory_creation_id - ACE_ENV_ARG_DECL_WITH_DEFAULTS - ) - ACE_THROW_SPEC (( - CORBA::SystemException - , PortableGroup::NoFactory - , PortableGroup::ObjectNotCreated - , PortableGroup::InvalidCriteria - , PortableGroup::InvalidProperty - , PortableGroup::CannotMeetCriteria - )); - - virtual void delete_object ( - const FT::GenericFactory::FactoryCreationId & factory_creation_id - ACE_ENV_ARG_DECL_WITH_DEFAULTS - ) - ACE_THROW_SPEC (( - CORBA::SystemException - , PortableGroup::ObjectNotFound - )); - - ////////////////////////////////////////// - // CORBA interface PullMonitorable methods - - virtual CORBA::Boolean is_alive (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - ///////////////////////// - // Implementation methods -private: - /** - * Find or allocate an ID for a new detector - */ - CORBA::ULong allocateId(); - - /** - * Write this factory's IOR to a file - */ - int write_IOR (); - - /** - * Clean house for factory shut down. - */ - void shutdown_i (); - - /////////////// - // Data Members -private: - - /** - * Protect internal state. - * Mutex should be locked by corba methods, or by - * external (public) methods before calling implementation - * methods. - * Implementation methods should assume the mutex is - * locked if necessary. - */ - ACE_Mutex internals_; - typedef ACE_Guard<ACE_Mutex> InternalGuard; - - /** - * The orb - */ - CORBA::ORB_var orb_; - - /** - * IOR of this object as assigned by orb. - */ - CORBA::String_var ior_; - - /** - * A file to which the factory's IOR should be written. - */ - const char * ior_output_file_; - - /** - * A name to be used to register the factory with the name service. - */ - const char * nsName_; - - CosNaming::NamingContext_var naming_context_; - - CosNaming::Name this_name_; - - /** - * Quit on idle flag. - */ - int quitOnIdle_; - - /** - * A human-readable string to distinguish this from other Notifiers. - */ - ACE_CString identity_; - - /** - * A manager for all FaultDetector threads. - */ - ACE_Thread_Manager threadManager_; - - /** - * A vector of FaultDetectors. Note that the FaultDetector ID - * is an index into this vector. - */ - DetectorVec detectors_; - - /** - * count of empty entries in detectors_ - * Used to determine when the factory is idle, and to avoid - * fruitless searches for empty slots. - */ - size_t emptySlots_; - - /** - * boolean: starts false. Set to true when it's time to quit. - */ - int quitRequested_; -}; - -#include <ace/post.h> + ////////////////////////////////////////// + // CORBA interface PullMonitorable methods + + virtual CORBA::Boolean is_alive (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + ///////////////////////// + // Implementation methods + private: + /** + * Find or allocate an ID for a new detector + */ + CORBA::ULong allocate_id(); + + /** + * Write this factory's IOR to a file + */ + int write_ior (); + + /** + * Clean house for factory shut down. + */ + void shutdown_i (); + + /////////////// + // Data Members + private: + + /** + * Protect internal state. + * Mutex should be locked by corba methods, or by + * external (public) methods before calling implementation + * methods. + * Implementation methods should assume the mutex is + * locked if necessary. + */ + ACE_Mutex internals_; + typedef ACE_Guard<ACE_Mutex> InternalGuard; + + /** + * The orb + */ + CORBA::ORB_var orb_; + + /** + * The POA used to activate this object. + */ + PortableServer::POA_var poa_; + + /** + * The CORBA object id assigned to this object. + */ + PortableServer::ObjectId_var objectId_; + + + /** + * IOR of this object as assigned by orb. + */ + CORBA::String_var ior_; + + /** + * A file to which the factory's IOR should be written. + */ + const char * ior_output_file_; + + /** + * A name to be used to register the factory with the name service. + */ + const char * ns_name_; + + ::CosNaming::NamingContext_var naming_context_; + + ::CosNaming::Name this_name_; + + /** + * Quit on idle flag. + */ + int quit_on_idle_; + + /** + * A human-readable string to distinguish this from other Notifiers. + */ + ACE_CString identity_; + + /** + * A manager for all FaultDetector threads. + */ + ACE_Thread_Manager threadManager_; + + /** + * A vector of FaultDetectors. Note that the FaultDetector ID + * is an index into this vector. + */ + DetectorVec detectors_; + + /** + * count of empty entries in detectors_ + * Used to determine when the factory is idle, and to avoid + * fruitless searches for empty slots. + */ + size_t empty_slots_; + + /** + * boolean: starts false. Set to true when it's time to quit. + */ + int quit_requested_; + }; +} // namespace TAO + +#include /**/ <ace/post.h> #endif /* FT_FAULTDETECTORFACTORY_I_H_ */ diff --git a/TAO/orbsvcs/Fault_Detector/Fault_Detector_Main.cpp b/TAO/orbsvcs/Fault_Detector/Fault_Detector_Main.cpp index aa6e52e3120..e77fc3db83f 100644 --- a/TAO/orbsvcs/Fault_Detector/Fault_Detector_Main.cpp +++ b/TAO/orbsvcs/Fault_Detector/Fault_Detector_Main.cpp @@ -14,13 +14,13 @@ */ //============================================================================= -#include <tao/Utils/ServantMain.h> +#include <tao/Utils/Server_Main.h> #include "FT_FaultDetectorFactory_i.h" int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { - TAO::Utils::ServantMain<FT_FaultDetectorFactory_i> servantMain("FaultDetectorFactory"); - return servantMain.Main(argc, argv); + TAO::Utils::Server_Main<TAO::FT_FaultDetectorFactory_i> server_main("TAO_FaultDetector"); + return server_main.run(argc, argv); } /////////////////////////////////// @@ -28,10 +28,7 @@ int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) // inept compilers. #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - template TAO::Utils::ServantMain<FT_FaultDetectorFactory_i>; + template TAO::Utils::Server_Main<FT_FaultDetectorFactory_i>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -# pragma instantiate TAO::Utils::ServantMain<FT_FaultDetectorFactory_i> +# pragma instantiate TAO::Utils::Server_Main<FT_FaultDetectorFactory_i> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - - - diff --git a/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.cpp b/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.cpp index ef3be4b0b85..2c41681825f 100644 --- a/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.cpp +++ b/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.cpp @@ -17,21 +17,21 @@ /////////////////////////////// // Fault_Detector_i static data -ACE_Time_Value Fault_Detector_i::sleepTime_(1,0); +ACE_Time_Value TAO::Fault_Detector_i::sleep_time_(1,0); ///////////////////////////////////////// // Fault_Detector_i public static methods -void Fault_Detector_i::setTimeValue(ACE_Time_Value value) +void TAO::Fault_Detector_i::set_time_for_all_detectors(ACE_Time_Value value) { - sleepTime_ = value; + sleep_time_ = value; } //////////////////////////////////////////// // Fault_Detector_i construction/destruction -Fault_Detector_i::Fault_Detector_i ( +TAO::Fault_Detector_i::Fault_Detector_i ( FT_FaultDetectorFactory_i & factory, CORBA::ULong id, FT::FaultNotifier_ptr & notifier, @@ -48,13 +48,13 @@ Fault_Detector_i::Fault_Detector_i ( , object_type_(object_type) , group_id_(group_id) , sleep_(0) // initially not signaled - , quitRequested_(0) + , quit_requested_(0) { - notifier_ = FT::FaultNotifier::_duplicate(notifier); - monitorable_ = FT::PullMonitorable::_duplicate(monitorable); + this->notifier_ = FT::FaultNotifier::_duplicate(notifier); + this->monitorable_ = FT::PullMonitorable::_duplicate(monitorable); } -Fault_Detector_i::~Fault_Detector_i () +TAO::Fault_Detector_i::~Fault_Detector_i () { } @@ -62,14 +62,14 @@ Fault_Detector_i::~Fault_Detector_i () // Fault_Detector_i public interface -void Fault_Detector_i::requestQuit() +void TAO::Fault_Detector_i::request_quit() { - quitRequested_ = 1; + this->quit_requested_ = 1; // wake up the thread - sleep_.signal (); + this->sleep_.signal (); } -void Fault_Detector_i::start(ACE_Thread_Manager & threadManager) +void TAO::Fault_Detector_i::start(ACE_Thread_Manager & threadManager) { threadManager.spawn(thr_func, this); } @@ -77,27 +77,27 @@ void Fault_Detector_i::start(ACE_Thread_Manager & threadManager) /////////////////////////////////////////////////// // Fault_Detector_i private implementation methods -void Fault_Detector_i::run() +void TAO::Fault_Detector_i::run() { - while ( ! quitRequested_ ) + while ( ! this->quit_requested_ ) { ACE_TRY_NEW_ENV { - if (monitorable_->is_alive(ACE_ENV_SINGLE_ARG_PARAMETER)) + if (this->monitorable_->is_alive(ACE_ENV_SINGLE_ARG_PARAMETER)) { ACE_TRY_CHECK; // use this rather than ACE_OS::sleep - // to allow the nap to be interruped see requestQuit - sleep_.wait (&sleepTime_, 0); + // to allow the nap to be interruped see request_quit + this->sleep_.wait (&sleep_time_, 0); } else { - ACE_ERROR ((LM_ERROR, + ACE_ERROR ((LM_INFO, "FaultDetector%d FAULT: not alive.\n", id_ )); notify(); - quitRequested_ = 1; + this->quit_requested_ = 1; } } ACE_CATCHANY // todo refine this @@ -106,7 +106,7 @@ void Fault_Detector_i::run() "FaultDetector FAULT: exception.\n" )); notify(); - quitRequested_ = 1; + this->quit_requested_ = 1; } ACE_ENDTRY; } @@ -115,20 +115,20 @@ void Fault_Detector_i::run() // member data after making this call. // todo: use "scoped resource management" to make // this exception-safe and stupid-return-safe. - factory_.removeDetector (id_, this); + this->factory_.remove_detector (this->id_, this); } -void Fault_Detector_i::notify() +void TAO::Fault_Detector_i::notify() { CosNotification::StructuredEvent_var vEvent; ACE_NEW_NORETURN(vEvent, CosNotification::StructuredEvent ); if (vEvent.ptr() != 0) { - short length = 2; - if( object_type_ != 0) + CORBA::ULong length = 2; + if( this->object_type_ != 0) { length = 3; - if (group_id_!= 0) + if (this->group_id_!= 0) { length = 4; } @@ -138,29 +138,35 @@ void Fault_Detector_i::notify() vEvent->header.fixed_header.event_type.type_name = FT::FT_EVENT_TYPE_NAME; vEvent->filterable_data.length(length); vEvent->filterable_data[0].name = FT::FT_DOMAIN_ID; - (vEvent->filterable_data[0].value) <<= domain_id_; + (vEvent->filterable_data[0].value) <<= this->domain_id_; vEvent->filterable_data[1].name = FT::FT_LOCATION; - (vEvent->filterable_data[1].value) <<= object_location_; - if (object_type_!= 0) + (vEvent->filterable_data[1].value) <<= this->object_location_; + if (this->object_type_!= 0) { vEvent->filterable_data[2].name = FT::FT_TYPE_ID; - (vEvent->filterable_data[2].value) <<= object_type_; - if (group_id_!= 0) + (vEvent->filterable_data[2].value) <<= this->object_type_; + if (this->group_id_!= 0) { vEvent->filterable_data[3].name = FT::FT_GROUP_ID; - vEvent->filterable_data[3].value <<= group_id_; + vEvent->filterable_data[3].value <<= this->group_id_; } } ACE_TRY_NEW_ENV { - notifier_->push_structured_fault(vEvent.in() +ACE_ERROR ((LM_ERROR, +"call Fault Detector push Structured Event.\n" +)); + this->notifier_->push_structured_fault(vEvent.in() ACE_ENV_ARG_PARAMETER); +ACE_ERROR ((LM_ERROR, +"return from Fault Detector push Structured Event.\n" +)); ACE_TRY_CHECK; } ACE_CATCHANY { ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Fault Detector cannot send notification.\n"); + "Fault Detector cannot send notification."); } ACE_ENDTRY; } @@ -177,10 +183,10 @@ void Fault_Detector_i::notify() // Fault_Detector_i private static implementation methods //static -ACE_THR_FUNC_RETURN Fault_Detector_i::thr_func (void * arg) +ACE_THR_FUNC_RETURN TAO::Fault_Detector_i::thr_func (void * arg) { - Fault_Detector_i * detector = static_cast<Fault_Detector_i *>(arg); - detector->run(); + TAO::Fault_Detector_i * detector = ACE_static_cast (TAO::Fault_Detector_i * , arg); + detector->run (); return 0; } diff --git a/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.h b/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.h index cb8b8a6cf99..f6f0827170b 100644 --- a/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.h +++ b/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.h @@ -20,150 +20,164 @@ #ifndef FAULT_DETECTOR_I_H_ #define FAULT_DETECTOR_I_H_ +#include /**/ <ace/pre.h> #include <ace/ACE.h> #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -#include <ace/pre.h> + +////////////////////////////////// +// Classes declared in this header +namespace TAO +{ + class Fault_Detector_i; +} + #include "orbsvcs/FT_NotifierC.h" #include "orbsvcs/FT_ReplicaC.h" #include "ace/Time_Value.h" -////////////////////// -// Forward references - -class FT_FaultDetectorFactory_i; - -////////////////////// -// Class declarations -class Fault_Detector_i +namespace TAO { - /////////////////// - // Public interface -public: - /** - * Construct FaultDetector. - * @param factory to be notified when this detector goes away. - * @param id to use when notifyting the factory of detector departure. - * @param notifier to receive the fault notification if our monitorable faults. - * @param monitorable object to be monitored. - * @param domain_id data to include in fault notification. - * @param object_location data to include in fault notification. - * @param object_type data to include in fault notification. - * @param group_id data to include in fault notification. - */ - Fault_Detector_i ( - FT_FaultDetectorFactory_i & factory, - CORBA::ULong id, - FT::FaultNotifier_ptr & notifier, - FT::PullMonitorable_ptr & monitorable, - FT::FTDomainId domain_id, - const FT::Location & object_location, - FT::TypeId object_type, - FT::ObjectGroupId group_id - ); - /** - * destructor. - * Non-virtual because this class does not take part in - * inheritence. - */ - ~Fault_Detector_i (); - - /** - * Start the thread associated with this fault detector. - * @param threadManager to track this thread. - */ - void start(ACE_Thread_Manager & threadManager); - - /** - * Request that this detector shut itself down. - */ - void requestQuit(); - - //////////////////////// - // Static public methods -public: - /** - * Set the polling time for all FaultDetectors in this process. - * @param value the time between polls. - */ - static void setTimeValue (ACE_Time_Value value); - - ///////////////////////// - // implementation methods -private: - /** - * Send the notification message. - */ - void notify(); - - /** - * The method to be run in the fault detector thread. - */ - void run(); - - /** - * The startup function for the fault detector thread. - */ - static ACE_THR_FUNC_RETURN thr_func (void * arg); - - //////////////////// - // Forbidden methods -private: - Fault_Detector_i (); - Fault_Detector_i (Fault_Detector_i & rhs); - Fault_Detector_i & operator = (const Fault_Detector_i & rhs); - - /////////////// - // Static data -private: - /** - * Time between polls for all fault detectors in this process. - */ - static ACE_Time_Value sleepTime_; - - /////////////// - // Data members -private: - /** - * The factory that "owns" us." - */ - FT_FaultDetectorFactory_i & factory_; - - /** - * How the factory knows who we are. - */ - CORBA::ULong id_; - - /** - * Where to send fault notification messages. - */ - FT::FaultNotifier_var notifier_; - - /** - * What to monitor. - */ - FT::PullMonitorable_var monitorable_; - - /** - * Data for the notification message. - */ - FT::FTDomainId domain_id_; - FT::Location object_location_; - FT::TypeId object_type_; - FT::ObjectGroupId group_id_; - - /** - * An Event (in the Win32 sense) to implement interruptable sleep. - */ - ACE_Manual_Event sleep_; - - /** - * A boolean flag. If true, this fault detector should leave. - */ - int quitRequested_; -}; -#include <ace/post.h> + ////////////////////// + // Forward references + + class FT_FaultDetectorFactory_i; + + ////////////////////// + // Class declarations + + class Fault_Detector_i + { + /////////////////// + // Public interface + public: + /** + * Construct FaultDetector. + * @param factory to be notified when this detector goes away. + * @param id to use when notifyting the factory of detector departure. + * @param notifier to receive the fault notification if our monitorable faults. + * @param monitorable object to be monitored. + * @param domain_id data to include in fault notification. + * @param object_location data to include in fault notification. + * @param object_type data to include in fault notification. + * @param group_id data to include in fault notification. + */ + Fault_Detector_i ( + FT_FaultDetectorFactory_i & factory, + CORBA::ULong id, + FT::FaultNotifier_ptr & notifier, + FT::PullMonitorable_ptr & monitorable, + FT::FTDomainId domain_id, + const FT::Location & object_location, + FT::TypeId object_type, + FT::ObjectGroupId group_id + ); + /** + * destructor. + * Non-virtual because this class does not take part in + * inheritence. + */ + ~Fault_Detector_i (); + + /** + * Start the thread associated with this fault detector. + * @param threadManager to track this thread. + */ + void start(ACE_Thread_Manager & threadManager); + + /** + * Request that this detector shut itself down. + */ + void request_quit(); + + //////////////////////// + // Static public methods + public: + /** + * Set the polling time for all FaultDetectors in this process. + * @param value the time between polls. + */ + static void set_time_for_all_detectors (ACE_Time_Value value); + + ///////////////////////// + // implementation methods + private: + /** + * Send the notification message. + */ + void notify(); + + /** + * The method to be run in the fault detector thread. + */ + void run(); + + /** + * The startup function for the fault detector thread. + */ + static ACE_THR_FUNC_RETURN thr_func (void * arg); + + //////////////////// + // Forbidden methods + private: + Fault_Detector_i (); + Fault_Detector_i (Fault_Detector_i & rhs); + Fault_Detector_i & operator = (const Fault_Detector_i & rhs); + + /////////////// + // Static data + private: + /** + * Time between polls for all fault detectors in this process. + */ + static ACE_Time_Value sleep_time_; + + /////////////// + // Data members + private: + /** + * The factory that "owns" us." + */ + FT_FaultDetectorFactory_i & factory_; + + /** + * How the factory knows who we are. + */ + CORBA::ULong id_; + + /** + * Where to send fault notification messages. + */ + FT::FaultNotifier_var notifier_; + + /** + * What to monitor. + */ + FT::PullMonitorable_var monitorable_; + + /** + * Data for the notification message. + */ + FT::FTDomainId domain_id_; + FT::Location object_location_; + FT::TypeId object_type_; + FT::ObjectGroupId group_id_; + + /** + * An Event (in the Win32 sense) to implement interruptable sleep. + * Manual rather than auto because once quit is requested we never + * want to sleep again. + */ + ACE_Manual_Event sleep_; + + /** + * A boolean flag. If true, this fault detector should leave. + */ + int quit_requested_; + }; +} // namespace TAO +#include /**/ <ace/post.h> #endif // FAULT_DETECTOR_I_H_ diff --git a/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.cpp b/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.cpp index 7022c87dc88..60799e18807 100644 --- a/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.cpp +++ b/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.cpp @@ -14,7 +14,6 @@ #include "FT_Notifier_i.h" #include "ace/Get_Opt.h" -#include "tao/PortableServer/ORB_Manager.h" // Use this macro at the beginning of CORBA methods // to aid in debugging. #define METHOD_ENTRY(name) \ @@ -41,40 +40,48 @@ // Implementation skeleton constructor -FT_FaultNotifier_i::FT_FaultNotifier_i () +TAO::FT_FaultNotifier_i::FT_FaultNotifier_i () : ior_output_file_(0) - , nsName_(0) - , consumerConnects_(0) - , consumerDisconnects_(0) - , quitOnIdle_(0) + , ns_name_(0) + , consumer_connects_(0) + , consumer_disconnects_(0) + , quit_on_idle_(0) + , quitting_(0) + , gone_(0) { } // Implementation skeleton destructor -FT_FaultNotifier_i::~FT_FaultNotifier_i () +TAO::FT_FaultNotifier_i::~FT_FaultNotifier_i () { fini (ACE_ENV_SINGLE_ARG_PARAMETER); } -int FT_FaultNotifier_i::idle(int &result ACE_ENV_ARG_DECL) +int TAO::FT_FaultNotifier_i::idle(int &result ACE_ENV_ARG_DECL) { + static unsigned long linger = 0; ACE_UNUSED_ARG(result); - int quit = 0; - if (quitOnIdle_) + if (gone_) { - if ( consumerConnects_ != 0 - && consumerConnects_ == consumerDisconnects_) + if ( linger == 0) { - quit = 1; - ACE_ERROR((LM_ERROR, - "FaultNotifier quit on idle: connects %d, disconnects %d\n", - ACE_static_cast (unsigned int, consumerConnects_), - ACE_static_cast (unsigned int, consumerDisconnects_) - )); + ACE_ERROR ((LM_ERROR, + "FaultNotifier (%P|%t) Begin linger.\n" + )); + } + if(++linger > 5)//10) + { + ACE_ERROR ((LM_ERROR, + "FaultNotifier (%P|%t) idle returnning gone\n" + )); + } + else + { + return 0; } } - return quit; + return this->gone_; } //////////////////////////////////////////// @@ -82,13 +89,13 @@ int FT_FaultNotifier_i::idle(int &result ACE_ENV_ARG_DECL) // TODO: find this a common home -int FT_FaultNotifier_i::write_IOR() +int TAO::FT_FaultNotifier_i::write_ior() { int result = -1; - FILE* out = ACE_OS::fopen (ior_output_file_, "w"); + FILE* out = ACE_OS::fopen (this->ior_output_file_, "w"); if (out) { - ACE_OS::fprintf (out, "%s", static_cast<const char *>(ior_)); + ACE_OS::fprintf (out, "%s", ACE_static_cast(const char *, this->ior_)); ACE_OS::fclose (out); result = 0; } @@ -104,7 +111,7 @@ int FT_FaultNotifier_i::write_IOR() ////////////////////////////////////////////////////// // FT_FaultNotifier_i public, non-CORBA methods -int FT_FaultNotifier_i::parse_args (int argc, char * argv[]) +int TAO::FT_FaultNotifier_i::parse_args (int argc, char * argv[]) { ACE_Get_Opt get_opts (argc, argv, "o:vq"); int c; @@ -115,17 +122,17 @@ int FT_FaultNotifier_i::parse_args (int argc, char * argv[]) { case 'o': { - ior_output_file_ = get_opts.opt_arg (); + this->ior_output_file_ = get_opts.opt_arg (); break; } case 'q': { - quitOnIdle_ = 1; + this->quit_on_idle_ = 1; break; } case 'v': { - verbose_ = 1; + this->verbose_ = 1; break; } case '?': @@ -146,23 +153,40 @@ int FT_FaultNotifier_i::parse_args (int argc, char * argv[]) return 0; } -const char * FT_FaultNotifier_i::identity () const +const char * TAO::FT_FaultNotifier_i::identity () const +{ + return this->identity_.c_str(); +} + +PortableServer::POA_ptr TAO::FT_FaultNotifier_i::_default_POA (ACE_ENV_SINGLE_ARG_DECL) +{ + return poa_.in(); +} + + +void TAO::FT_FaultNotifier_i::_remove_ref (ACE_ENV_SINGLE_ARG_DECL) { - return identity_.c_str(); + notify_channel_->destroy(ACE_ENV_SINGLE_ARG_DECL); + ACE_CHECK; + + ACE_ERROR ((LM_ERROR, + "FaultNotifier (%P|%t) _remove_ref setting gone\n" + )); + this->gone_ = 1; } -int FT_FaultNotifier_i::fini (ACE_ENV_SINGLE_ARG_DECL) +int TAO::FT_FaultNotifier_i::fini (ACE_ENV_SINGLE_ARG_DECL) { - if (ior_output_file_ != 0) + if (this->ior_output_file_ != 0) { - ACE_OS::unlink (ior_output_file_); - ior_output_file_ = 0; + ACE_OS::unlink (this->ior_output_file_); + this->ior_output_file_ = 0; } - if (nsName_ != 0 && naming_context_.in() != 0) + if (this->ns_name_ != 0 && this->naming_context_.in() != 0) { - naming_context_->unbind (this_name_ + this->naming_context_->unbind (this_name_ ACE_ENV_ARG_PARAMETER); - nsName_ = 0; + this->ns_name_ = 0; } int TODO_unregister_with_ReplicationManager; @@ -170,155 +194,186 @@ int FT_FaultNotifier_i::fini (ACE_ENV_SINGLE_ARG_DECL) return 0; } -int FT_FaultNotifier_i::init (TAO_ORB_Manager & orbManager - ACE_ENV_ARG_DECL) +int TAO::FT_FaultNotifier_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL ) { int result = 0; - orb_ = orbManager.orb(); + this->orb_ = orb; - // Register with the ORB. - ior_ = orbManager.activate (this - ACE_ENV_ARG_PARAMETER); + // Use the ROOT POA for now + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")), + -1); - //////////////////////////////////////////////// - // Register with coresident Notification Channel + // Get the POA object. + this->poa_ = + PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); - result = orbManager.activate_poa_manager(ACE_ENV_SINGLE_ARG_PARAMETER); ACE_CHECK_RETURN (-1); - if (result == 0) + + if (CORBA::is_nil(this->poa_)) { - PortableServer::POA_var poa = orbManager.root_poa(); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")), + -1); + } - CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = - TAO_Notify_EventChannelFactory_i::create (poa.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - CosNotification::QoSProperties initial_qos; - CosNotification::AdminProperties initial_admin; - notify_channel_ = - notify_factory->create_channel (initial_qos, - initial_admin, - channelId_ - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); + PortableServer::POAManager_var poa_manager = + this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; - filter_factory_ = notify_channel_->default_filter_factory (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; - /////////////////////////// - // Producer registration - supplierAdmin_ = notify_channel_->default_supplier_admin (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); + // Register with the POA. - ::CosNotifyChannelAdmin::ProxyID proxyId = 0; + this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; - ////////////////////// - // structured producer - ::CosNotifyChannelAdmin::ProxyConsumer_var consumer - = supplierAdmin_->obtain_notification_push_consumer ( - ::CosNotifyChannelAdmin::STRUCTURED_EVENT, - proxyId - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); + // find my IOR - structuredProxyPushConsumer_ - = ::CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(consumer - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - if (CORBA::is_nil (structuredProxyPushConsumer_)) - { - ACE_ERROR_RETURN ((LM_ERROR, - "%T %n (%P|%t) Should not occur: Unable to narrow Structured Proxy Push Consumer\n"), - 1); - } + CORBA::Object_var obj = + this->poa_->id_to_reference (object_id_.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; - // todo: implement a push supplier if we want to receive disconnect notice - // todo: if not, is this call necessary? - CosNotifyComm::StructuredPushSupplier_var stubPushSupplier = - CosNotifyComm::StructuredPushSupplier::_nil(); + this->ior_ = this->orb_->object_to_string (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; - structuredProxyPushConsumer_->connect_structured_push_supplier (stubPushSupplier.in() - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - //////////////////// - // Sequence producer - consumer - = supplierAdmin_->obtain_notification_push_consumer ( - ::CosNotifyChannelAdmin::SEQUENCE_EVENT, - proxyId - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - ::CosNotifyChannelAdmin::SequenceProxyPushConsumer_var sequenceProxyPushConsumer_ - = ::CosNotifyChannelAdmin::SequenceProxyPushConsumer::_narrow(consumer - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - if (CORBA::is_nil (sequenceProxyPushConsumer_)) - { - ACE_ERROR_RETURN ((LM_ERROR, - "%T %n (%P|%t) Should not occur: Unable to narrow Sequence Proxy Push Consumer\n"), - 1); - } + //////////////////////////////////////////////// + // Register with coresident Notification Channel + CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = + TAO_Notify_EventChannelFactory_i::create (poa_.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + CosNotification::QoSProperties initial_qos; + CosNotification::AdminProperties initial_admin; + this->notify_channel_ = + notify_factory->create_channel (initial_qos, + initial_admin, + channel_id_ + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->filter_factory_ = this->notify_channel_->default_filter_factory (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; - // todo: implement this if we want to receive disconnect notice - // todo: if not, is this call necessary? - CosNotifyComm::SequencePushSupplier_var stubSeqPushSupplier = - CosNotifyComm::SequencePushSupplier::_nil(); + /////////////////////////// + // Producer registration + + this->supplier_admin_ = this->notify_channel_->default_supplier_admin (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ::CosNotifyChannelAdmin::ProxyID proxyId = 0; + + ////////////////////// + // structured producer + ::CosNotifyChannelAdmin::ProxyConsumer_var consumer + = this->supplier_admin_->obtain_notification_push_consumer ( + ::CosNotifyChannelAdmin::STRUCTURED_EVENT, + proxyId + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; - sequenceProxyPushConsumer_->connect_sequence_push_supplier (stubSeqPushSupplier.in() + structured_proxy_push_consumer_ + = ::CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(consumer ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); + ACE_TRY_CHECK; + if (CORBA::is_nil (this->structured_proxy_push_consumer_)) + { + ACE_ERROR_RETURN ((LM_ERROR, + "%T %n (%P|%t) Should not occur: Unable to narrow Structured Proxy Push Consumer\n"), + 1); + } - /////////////////////////// - // Consumer registration + // todo: implement a push supplier if we want to receive disconnect notice + CosNotifyComm::StructuredPushSupplier_var stubPushSupplier = + CosNotifyComm::StructuredPushSupplier::_nil(); - // find the channel administrator for consumers - consumerAdmin_ = notify_channel_->default_consumer_admin (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - if (CORBA::is_nil (consumerAdmin_)) - { - ACE_ERROR ((LM_ERROR, - "%T %n (%P|%t) NIL consumer admin\n" - )); - result = -1; - } - // everything else happens when subscriber shows up + this->structured_proxy_push_consumer_->connect_structured_push_supplier (stubPushSupplier.in() + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + //////////////////// + // Sequence producer + consumer + = this->supplier_admin_->obtain_notification_push_consumer ( + ::CosNotifyChannelAdmin::SEQUENCE_EVENT, + proxyId + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + this->sequence_proxy_push_consumer_ + = ::CosNotifyChannelAdmin::SequenceProxyPushConsumer::_narrow(consumer + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + if (CORBA::is_nil (this->sequence_proxy_push_consumer_)) + { + ACE_ERROR_RETURN ((LM_ERROR, + "%T %n (%P|%t) Should not occur: Unable to narrow Sequence Proxy Push Consumer\n"), + 1); } + // todo: implement this if we want to receive disconnect notice + CosNotifyComm::SequencePushSupplier_var stubSeqPushSupplier = + CosNotifyComm::SequencePushSupplier::_nil(); + + this->sequence_proxy_push_consumer_->connect_sequence_push_supplier (stubSeqPushSupplier.in() + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + /////////////////////////// + // Consumer registration + + // find the channel administrator for consumers + this->consumer_admin_ = this->notify_channel_->default_consumer_admin (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + if (CORBA::is_nil (this->consumer_admin_)) + { + ACE_ERROR ((LM_ERROR, + "%T %n (%P|%t) NIL consumer admin\n" + )); + result = -1; + } + // everything else happens when subscriber shows up /////////////////////////////// // Set up and ready for action // publish our IOR if(result == 0) { - if (ior_output_file_ != 0) + if (this->ior_output_file_ != 0) { - identity_ = "file:"; - identity_ += ior_output_file_; - result = write_IOR(); + this->identity_ = "file:"; + this->identity_ += this->ior_output_file_; + result = write_ior(); } else { // if no IOR file specified, // then always try to register with name service - nsName_ = "FT_FaultNotifier"; + this->ns_name_ = "FT_FaultNotifier"; } } if (result == 0) { - if (nsName_ != 0) + if (this->ns_name_ != 0) { - identity_ = "name:"; - identity_ += nsName_; + this->identity_ = "name:"; + this->identity_ += this->ns_name_; CORBA::Object_var naming_obj = - orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); + this->orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; if (CORBA::is_nil(naming_obj.in ())){ ACE_ERROR_RETURN ((LM_ERROR, @@ -326,21 +381,21 @@ int FT_FaultNotifier_i::init (TAO_ORB_Manager & orbManager 1); } - naming_context_ = + this->naming_context_ = CosNaming::NamingContext::_narrow (naming_obj.in () ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - if (CORBA::is_nil(naming_context_)) + ACE_TRY_CHECK; + if (CORBA::is_nil(this->naming_context_)) { ACE_ERROR_RETURN ((LM_ERROR, "%T %n (%P|%t) Should not occur: Can't narrow initial reference to naming context.\n"), 1); } - this_name_.length (1); - this_name_[0].id = CORBA::string_dup (nsName_); + this->this_name_.length (1); + this->this_name_[0].id = CORBA::string_dup (this->ns_name_); - naming_context_->rebind (this_name_, _this() + this->naming_context_->rebind (this->this_name_, _this() ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); + ACE_TRY_CHECK; } } @@ -352,55 +407,55 @@ int FT_FaultNotifier_i::init (TAO_ORB_Manager & orbManager /////////////////// // CORBA METHODS -void FT_FaultNotifier_i::push_structured_fault ( +void TAO::FT_FaultNotifier_i::push_structured_fault ( const CosNotification::StructuredEvent & event ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_ENTRY(FT_FaultNotifier_i::push_structured_fault); + METHOD_ENTRY(TAO::FT_FaultNotifier_i::push_structured_fault); - structuredProxyPushConsumer_->push_structured_event (event + this->structured_proxy_push_consumer_->push_structured_event (event ACE_ENV_ARG_PARAMETER); - METHOD_RETURN(FT_FaultNotifier_i::push_structured_fault); + METHOD_RETURN(TAO::FT_FaultNotifier_i::push_structured_fault); } -void FT_FaultNotifier_i::push_sequence_fault ( +void TAO::FT_FaultNotifier_i::push_sequence_fault ( const CosNotification::EventBatch & events ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_ENTRY(FT_FaultNotifier_i::push_sequence_fault); + METHOD_ENTRY(TAO::FT_FaultNotifier_i::push_sequence_fault); - sequenceProxyPushConsumer_->push_structured_events (events + this->sequence_proxy_push_consumer_->push_structured_events (events ACE_ENV_ARG_PARAMETER); - METHOD_RETURN(FT_FaultNotifier_i::push_sequence_fault); + METHOD_RETURN(TAO::FT_FaultNotifier_i::push_sequence_fault); } -::CosNotifyFilter::Filter_ptr FT_FaultNotifier_i::create_subscription_filter ( +::CosNotifyFilter::Filter_ptr TAO::FT_FaultNotifier_i::create_subscription_filter ( const char * constraint_grammar ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException, CosNotifyFilter::InvalidGrammar)) { - METHOD_ENTRY(FT_FaultNotifier_i::create_subscription_filter); + METHOD_ENTRY(TAO::FT_FaultNotifier_i::create_subscription_filter); - CosNotifyFilter::Filter_var filter = filter_factory_->create_filter ("ETCL"); - METHOD_RETURN(FT_FaultNotifier_i::create_subscription_filter) + CosNotifyFilter::Filter_var filter = this->filter_factory_->create_filter ("ETCL"); + METHOD_RETURN(TAO::FT_FaultNotifier_i::create_subscription_filter) filter._retn (); } -FT::FaultNotifier::ConsumerId FT_FaultNotifier_i::connect_structured_fault_consumer ( +FT::FaultNotifier::ConsumerId TAO::FT_FaultNotifier_i::connect_structured_fault_consumer ( CosNotifyComm::StructuredPushConsumer_ptr push_consumer, CosNotifyFilter::Filter_ptr filter ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_ENTRY(FT_FaultNotifier_i::connect_structured_fault_consumer); + METHOD_ENTRY(TAO::FT_FaultNotifier_i::connect_structured_fault_consumer); ///////////////////////// // find a ProxyInfo entry @@ -408,9 +463,9 @@ FT::FaultNotifier::ConsumerId FT_FaultNotifier_i::connect_structured_fault_consu size_t infoPos = 0; int looking = 1; - for ( size_t pos = 0; looking && pos < proxyInfos_.size (); ++pos) + for ( size_t pos = 0; looking && pos < this->proxy_infos_.size (); ++pos) { - ProxyInfo & pi = proxyInfos_[pos]; + ProxyInfo & pi = this->proxy_infos_[pos]; if (CORBA::is_nil(pi.proxyVar_)) { infoPos = pos; @@ -419,21 +474,21 @@ FT::FaultNotifier::ConsumerId FT_FaultNotifier_i::connect_structured_fault_consu } if (looking) { - infoPos = proxyInfos_.size(); - proxyInfos_.push_back(ProxyInfo()); + infoPos = this->proxy_infos_.size(); + this->proxy_infos_.push_back(ProxyInfo()); } /////////////////////////////////////// // Assign an ID, populate the ProxyInfo FT::FaultNotifier::ConsumerId result = infoPos; - ProxyInfo & info = proxyInfos_[infoPos]; + ProxyInfo & info = this->proxy_infos_[infoPos]; info.proxyVar_ - = consumerAdmin_->obtain_notification_push_supplier ( + = this->consumer_admin_->obtain_notification_push_supplier ( ::CosNotifyChannelAdmin::STRUCTURED_EVENT, info.proxyId_ ACE_ENV_ARG_PARAMETER); - consumerConnects_ += 1; + this->consumer_connects_ += 1; ::CosNotifyChannelAdmin::StructuredProxyPushSupplier_var proxySupplier = ::CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(info.proxyVar_ @@ -458,26 +513,26 @@ FT::FaultNotifier::ConsumerId FT_FaultNotifier_i::connect_structured_fault_consu } } - METHOD_RETURN(FT_FaultNotifier_i::connect_structured_fault_consumer) result; + METHOD_RETURN(TAO::FT_FaultNotifier_i::connect_structured_fault_consumer) result; } -FT::FaultNotifier::ConsumerId FT_FaultNotifier_i::connect_sequence_fault_consumer ( +FT::FaultNotifier::ConsumerId TAO::FT_FaultNotifier_i::connect_sequence_fault_consumer ( CosNotifyComm::SequencePushConsumer_ptr push_consumer, CosNotifyFilter::Filter_ptr filter ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_ENTRY(FT_FaultNotifier_i::connect_sequence_fault_consumer); + METHOD_ENTRY(TAO::FT_FaultNotifier_i::connect_sequence_fault_consumer); ///////////////////////// // find a ProxyInfo entry // use the first nil entry or a new entry if no nils found size_t infoPos = 0; int looking = 1; - for ( size_t pos = 0; looking && pos < proxyInfos_.size (); ++pos) + for ( size_t pos = 0; looking && pos < this->proxy_infos_.size (); ++pos) { - ProxyInfo & pi = proxyInfos_[pos]; + ProxyInfo & pi = this->proxy_infos_[pos]; if (CORBA::is_nil(pi.proxyVar_)) { infoPos = pos; @@ -486,21 +541,21 @@ FT::FaultNotifier::ConsumerId FT_FaultNotifier_i::connect_sequence_fault_consume } if (looking) { - infoPos = proxyInfos_.size(); - proxyInfos_.push_back(ProxyInfo()); + infoPos = this->proxy_infos_.size(); + this->proxy_infos_.push_back(ProxyInfo()); } /////////////////////////////////////// // Assign an ID, populate the ProxyInfo FT::FaultNotifier::ConsumerId result = infoPos; - ProxyInfo & info = proxyInfos_[infoPos]; + ProxyInfo & info = this->proxy_infos_[infoPos]; info.proxyVar_ - = consumerAdmin_->obtain_notification_push_supplier ( + = this->consumer_admin_->obtain_notification_push_supplier ( ::CosNotifyChannelAdmin::SEQUENCE_EVENT, info.proxyId_ ACE_ENV_ARG_PARAMETER); - consumerConnects_ += 1; + this->consumer_connects_ += 1; ::CosNotifyChannelAdmin::SequenceProxyPushSupplier_var proxySupplier = ::CosNotifyChannelAdmin::SequenceProxyPushSupplier::_narrow(info.proxyVar_ @@ -523,21 +578,21 @@ FT::FaultNotifier::ConsumerId FT_FaultNotifier_i::connect_sequence_fault_consume proxySupplier->add_filter(filter); } } - METHOD_RETURN(FT_FaultNotifier_i::connect_sequence_fault_consumer) result; + METHOD_RETURN(TAO::FT_FaultNotifier_i::connect_sequence_fault_consumer) result; } -void FT_FaultNotifier_i::disconnect_consumer ( +void TAO::FT_FaultNotifier_i::disconnect_consumer ( FT::FaultNotifier::ConsumerId connection ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException, CosEventComm::Disconnected)) { - METHOD_ENTRY(FT_FaultNotifier_i::disconnect_consumer); + METHOD_ENTRY(TAO::FT_FaultNotifier_i::disconnect_consumer); size_t index = ACE_static_cast ( size_t, connection); - if (index < proxyInfos_.size()) + if (index < this->proxy_infos_.size()) { - ProxyInfo & info = proxyInfos_[index]; + ProxyInfo & info = this->proxy_infos_[index]; if (CORBA::is_nil(info.proxyVar_) ) { ACE_THROW(CosEventComm::Disconnected()); @@ -565,7 +620,7 @@ void FT_FaultNotifier_i::disconnect_consumer ( else { ACE_ERROR((LM_ERROR, - "Unexpected proxy supplier type\n" + "%T %n (%P|%t) Unexpected proxy supplier type\n" )); ACE_THROW(CosEventComm::Disconnected()); } @@ -577,27 +632,42 @@ void FT_FaultNotifier_i::disconnect_consumer ( ACE_THROW(CosEventComm::Disconnected()); } - consumerDisconnects_ += 1; + this->consumer_disconnects_ += 1; + if (this->quit_on_idle_) + { + if (! this->quitting_ + && this->consumer_connects_ == this->consumer_disconnects_) + { + ACE_ERROR((LM_ERROR, + "FaultNotifier (%P|%t) quit on idle: connects %d, disconnects %d\n", + ACE_static_cast (unsigned int, this->consumer_connects_), + ACE_static_cast (unsigned int, this->consumer_disconnects_) + )); + this->poa_->deactivate_object (this->object_id_.in () + ACE_ENV_ARG_PARAMETER); + this->quitting_ = 1; + } + } - METHOD_RETURN(FT_FaultNotifier_i::disconnect_consumer); + METHOD_RETURN(TAO::FT_FaultNotifier_i::disconnect_consumer); } -CORBA::Boolean FT_FaultNotifier_i::is_alive (ACE_ENV_SINGLE_ARG_DECL) +CORBA::Boolean TAO::FT_FaultNotifier_i::is_alive (ACE_ENV_SINGLE_ARG_DECL) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_RETURN(FT_FaultNotifier_i::is_alive) 1; + METHOD_RETURN(TAO::FT_FaultNotifier_i::is_alive) 1; } ////////////// // ProxyInfo -FT_FaultNotifier_i::ProxyInfo::ProxyInfo () +TAO::FT_FaultNotifier_i::ProxyInfo::ProxyInfo () : proxyId_ (0) , proxyVar_ (::CosNotifyChannelAdmin::ProxySupplier::_nil()) { } -FT_FaultNotifier_i::ProxyInfo::ProxyInfo (const ProxyInfo & rhs) +TAO::FT_FaultNotifier_i::ProxyInfo::ProxyInfo (const ProxyInfo & rhs) : proxyId_ (rhs.proxyId_) , proxyVar_ (rhs.proxyVar_) { diff --git a/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.h b/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.h index 3a52934400d..468396348f3 100644 --- a/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.h +++ b/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.h @@ -1,20 +1,38 @@ // -*- C++ -*- // // $Id$ - -// @@ OCI folks -- file header please... -#ifndef FT_NOTIFIER_I_H_ -#define FT_NOTIFIER_I_H_ - -// @@OCI folks -- please include pre.h before the pragma. Oh, BTW gcc -// 3.* would complain that pragma has been deprecated. Probably you -// should add a simple header file before the pragma. +//============================================================================= +/** + * @file Fault_Notifier_i.h + * + * $Id$ + * + * This file is part of Fault Tolerant CORBA. + * This file declares the Fault_Notifier_i class. + * A FaultNotifer is a subset of a notification channel. It allows interested + * parties to subscribe to fault notifications. The most likely interested party + * is the ReplicationManager. + * + * @author Dale Wilson <wilson_d@ociweb.com> + */ +//============================================================================= + +#ifndef TAO_FT_NOTIFIER_I_H_ +#define TAO_FT_NOTIFIER_I_H_ +#include /**/ "ace/pre.h" +#include "ace/ACE.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) #pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -#include "ace/pre.h" +////////////////////////////////// +// Classes declared in this header +namespace TAO +{ + class FT_FaultNotifier_i; +} + #include <orbsvcs/FT_NotifierS.h> #include <orbsvcs/Notify/Notify_EventChannelFactory_i.h> @@ -22,203 +40,225 @@ ///////////////////// // Forward references -class TAO_ORB_Manager; - -// @@OCI folks, please use the TAO namespace -class FT_FaultNotifier_i : public virtual POA_FT::FaultNotifier +namespace TAO { - ////////////////////// - // non-CORBA interface -public: - /** - * Default constructor. - */ - FT_FaultNotifier_i (); - - /** - * Virtual destructor. - */ - virtual ~FT_FaultNotifier_i (); - - - /** - * Parse command line arguments. - * @param argc traditional C argc - * @param argv traditional C argv - * @return zero for success; nonzero is process return code for failure. - */ - int parse_args (int argc, char * argv[]); - - /** - * Initialize this object. - * @param orbManager our ORB -- we keep var to it. - * @return zero for success; nonzero is process return code for failure. - */ - int init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL_WITH_DEFAULTS); - - /** - * Prepare to exit - * @return zero for success; nonzero is process return code for failure. - */ - int fini (ACE_ENV_SINGLE_ARG_DECL); - - /** - * Identify this fault notifier. - * @return a string to identify this object for logging/console message purposes. - */ - const char * identity () const; - - /** - * idle time activity. - * @param result [out] status code to return from process - * @returns 0 to continue; nonzero to quit - */ - int idle(int &result ACE_ENV_ARG_DECL_WITH_DEFAULTS); - - ////////////////// - // CORBA interface - // See IDL for documentation - - //@@OCI folks, please don't use "WITH_DEFAULTS" since that makes a - // TSS lookup, which is slower. Yes, IDL compile generates with - //them, but the implementation should have the raw macro. - - virtual void push_structured_fault ( - const CosNotification::StructuredEvent & event - ACE_ENV_ARG_DECL_WITH_DEFAULTS + class FT_FaultNotifier_i : public virtual POA_FT::FaultNotifier + { + ////////////////////// + // non-CORBA interface + public: + /** + * Default constructor. + */ + FT_FaultNotifier_i (); + + /** + * Virtual destructor. + */ + virtual ~FT_FaultNotifier_i (); + + + /** + * Parse command line arguments. + * @param argc traditional C argc + * @param argv traditional C argv + * @return zero for success; nonzero is process return code for failure. + */ + int parse_args (int argc, char * argv[]); + + /** + * Initialize this object. + * @param orbManager our ORB -- we keep var to it. + * @return zero for success; nonzero is process return code for failure. + */ + int init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL); + + /** + * Prepare to exit + * @return zero for success; nonzero is process return code for failure. + */ + int fini (ACE_ENV_SINGLE_ARG_DECL); + + /** + * Identify this fault notifier. + * @return a string to identify this object for logging/console message purposes. + */ + const char * identity () const; + + /** + * idle time activity. + * @param result [out] status code to return from process + * @returns 0 to continue; nonzero to quit + */ + int idle(int &result ACE_ENV_ARG_DECL); + + ////////////////// + // CORBA interface + // See IDL for documentation + + virtual void push_structured_fault ( + const CosNotification::StructuredEvent & event + ACE_ENV_ARG_DECL + ) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void push_sequence_fault ( + const CosNotification::EventBatch & events + ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException)); - virtual void push_sequence_fault ( - const CosNotification::EventBatch & events - ACE_ENV_ARG_DECL_WITH_DEFAULTS - ) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual ::CosNotifyFilter::Filter_ptr create_subscription_filter ( - const char * constraint_grammar - ACE_ENV_ARG_DECL_WITH_DEFAULTS - ) - ACE_THROW_SPEC ((CORBA::SystemException, CosNotifyFilter::InvalidGrammar)); - - virtual FT::FaultNotifier::ConsumerId connect_structured_fault_consumer ( - CosNotifyComm::StructuredPushConsumer_ptr push_consumer, - CosNotifyFilter::Filter_ptr filter - ACE_ENV_ARG_DECL_WITH_DEFAULTS - ) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual FT::FaultNotifier::ConsumerId connect_sequence_fault_consumer ( - CosNotifyComm::SequencePushConsumer_ptr push_consumer, - CosNotifyFilter::Filter_ptr filter - ACE_ENV_ARG_DECL_WITH_DEFAULTS - ) - ACE_THROW_SPEC ((CORBA::SystemException)); - - virtual void disconnect_consumer ( - FT::FaultNotifier::ConsumerId connection - ACE_ENV_ARG_DECL_WITH_DEFAULTS - ) - ACE_THROW_SPEC ((CORBA::SystemException, CosEventComm::Disconnected)); - - ////////////////////////////////////////// - // CORBA interface PullMonitorable methods - virtual CORBA::Boolean is_alive (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) - ACE_THROW_SPEC ((CORBA::SystemException)); - - ///////////////////////// - // Implementation methods -private: - /** - * Write this notifier's IOR to a file - */ - int write_IOR (); - - /////////////// - // Data Members -private: - - /** - * Protect internal state. - * Mutex should be locked by corba methods, or by - * external (public) methods before calling implementation - * methods. - * Implementation methods should assume the mutex is - * locked if necessary. - */ - ACE_Mutex internals_; - typedef ACE_Guard<ACE_Mutex> InternalGuard; - - /** - * The orb - */ - CORBA::ORB_var orb_; - - /** - * IOR of this object as assigned by orb. - */ - CORBA::String_var ior_; - - /** - * A file to which the notifier's IOR should be written. - */ - const char * ior_output_file_; - - /** - * A name to be used to register the notifier with the name service. - */ - const char * nsName_; - - CosNaming::NamingContext_var naming_context_; - - CosNaming::Name this_name_; - - /** - * A human-readable string to distinguish this from other Notifiers. - */ - ACE_CString identity_; - - ///////////////////////////// - // - struct ProxyInfo - { - ::CosNotifyChannelAdmin::ProxyID proxyId_; - ::CosNotifyChannelAdmin::ProxySupplier_var proxyVar_; - - ProxyInfo (); - ProxyInfo (const ProxyInfo & rhs); - }; - - typedef ACE_Vector <ProxyInfo> ProxyInfoVec; - - ProxyInfoVec proxyInfos_; + virtual ::CosNotifyFilter::Filter_ptr create_subscription_filter ( + const char * constraint_grammar + ACE_ENV_ARG_DECL + ) + ACE_THROW_SPEC ((CORBA::SystemException, CosNotifyFilter::InvalidGrammar)); - size_t consumerConnects_; - size_t consumerDisconnects_; + virtual FT::FaultNotifier::ConsumerId connect_structured_fault_consumer ( + CosNotifyComm::StructuredPushConsumer_ptr push_consumer, + CosNotifyFilter::Filter_ptr filter + ACE_ENV_ARG_DECL + ) + ACE_THROW_SPEC ((CORBA::SystemException)); -///////////////////// - ::CosNotifyChannelAdmin::ChannelID channelId_; - ::CosNotifyChannelAdmin::EventChannel_var notify_channel_; - ::CosNotifyFilter::FilterFactory_var filter_factory_; - ::CosNotifyChannelAdmin::SupplierAdmin_var supplierAdmin_; - ::CosNotifyChannelAdmin::ConsumerAdmin_var consumerAdmin_; + virtual FT::FaultNotifier::ConsumerId connect_sequence_fault_consumer ( + CosNotifyComm::SequencePushConsumer_ptr push_consumer, + CosNotifyFilter::Filter_ptr filter + ACE_ENV_ARG_DECL + ) + ACE_THROW_SPEC ((CORBA::SystemException)); - ::CosNotifyChannelAdmin::StructuredProxyPushConsumer_var structuredProxyPushConsumer_; - ::CosNotifyChannelAdmin::SequenceProxyPushConsumer_var sequenceProxyPushConsumer_; + virtual void disconnect_consumer ( + FT::FaultNotifier::ConsumerId connection + ACE_ENV_ARG_DECL + ) + ACE_THROW_SPEC ((CORBA::SystemException, CosEventComm::Disconnected)); - /** - * boolean true means display debug messages (default is false) - */ - int verbose_; + ////////////////////////////////////////// + // CORBA interface PullMonitorable methods + virtual CORBA::Boolean is_alive (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); - /* - * boolean quit when all consumers disconnect - */ - int quitOnIdle_; -}; + ///////////////////////////////////////// + // Override CORBA servant virtual methods + virtual PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL); + + virtual void _remove_ref (ACE_ENV_SINGLE_ARG_DECL); + + ///////////////////////// + // Implementation methods + private: + /** + * Write this notifier's IOR to a file + */ + int write_ior (); + + /////////////// + // Data Members + private: + + /** + * Protect internal state. + * Mutex should be locked by corba methods, or by + * external (public) methods before calling implementation + * methods. + * Implementation methods should assume the mutex is + * locked if necessary. + */ + ACE_Mutex internals_; + typedef ACE_Guard<ACE_Mutex> InternalGuard; + + /** + * The orb + */ + CORBA::ORB_var orb_; + + /** + * The POA used to activate this object. + */ + PortableServer::POA_var poa_; + + /** + * The CORBA object id assigned to this object. + */ + PortableServer::ObjectId_var object_id_; + + + /** + * IOR of this object as assigned by orb. + */ + CORBA::String_var ior_; + + /** + * A file to which the notifier's IOR should be written. + */ + const char * ior_output_file_; + + /** + * A name to be used to register the notifier with the name service. + */ + const char * ns_name_; + + CosNaming::NamingContext_var naming_context_; + + CosNaming::Name this_name_; + + /** + * A human-readable string to distinguish this from other Notifiers. + */ + ACE_CString identity_; + + ///////////////////////////// + // + struct ProxyInfo + { + ::CosNotifyChannelAdmin::ProxyID proxyId_; + ::CosNotifyChannelAdmin::ProxySupplier_var proxyVar_; + + ProxyInfo (); + ProxyInfo (const ProxyInfo & rhs); + }; + + typedef ACE_Vector <ProxyInfo> ProxyInfoVec; + + ProxyInfoVec proxy_infos_; + + size_t consumer_connects_; + size_t consumer_disconnects_; + + ::CosNotifyChannelAdmin::ChannelID channel_id_; + ::CosNotifyChannelAdmin::EventChannel_var notify_channel_; + ::CosNotifyFilter::FilterFactory_var filter_factory_; + ::CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin_; + ::CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin_; + + ::CosNotifyChannelAdmin::StructuredProxyPushConsumer_var structured_proxy_push_consumer_; + ::CosNotifyChannelAdmin::SequenceProxyPushConsumer_var sequence_proxy_push_consumer_; + + /** + * boolean true means display debug messages (default is false) + */ + int verbose_; + + /* + * boolean quit when all consumers disconnect + */ + int quit_on_idle_; + + /** + * boolean: set true we've asked CORBA to deactivate + */ + int quitting_; + + /** + * boolean: set true when CORBA is done with this object. + */ + int gone_; -#include "ace/post.h" + }; +} // namespace TAO +#include /**/ "ace/post.h" -#endif /* FT_NOTIFIER_I_H_ */ +#endif /* TAO_FT_NOTIFIER_I_H_ */ diff --git a/TAO/orbsvcs/Fault_Notifier/Fault_Notifier_Main.cpp b/TAO/orbsvcs/Fault_Notifier/Fault_Notifier_Main.cpp index 2bfaa4b3b02..54162acea31 100644 --- a/TAO/orbsvcs/Fault_Notifier/Fault_Notifier_Main.cpp +++ b/TAO/orbsvcs/Fault_Notifier/Fault_Notifier_Main.cpp @@ -14,13 +14,13 @@ */ //============================================================================= -#include <tao/Utils/ServantMain.h> +#include <tao/Utils/Server_Main.h> #include "FT_Notifier_i.h" int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { - TAO::Utils::ServantMain<FT_FaultNotifier_i> servantMain("FaultNotifier"); - return servantMain.Main(argc, argv); + TAO::Utils::Server_Main<TAO::FT_FaultNotifier_i> server_main("TAO_FaultNotifier"); + return server_main.run(argc, argv); } /////////////////////////////////// @@ -28,9 +28,9 @@ int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) // inept compilers. #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - template TAO::Utils::ServantMain<FT_FaultNotifier_i>; + template TAO::Utils::Server_Main<FT_FaultNotifier_i>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -# pragma instantiate TAO::Utils::ServantMain<FT_FaultNotifier_i> +# pragma instantiate TAO::Utils::Server_Main<FT_FaultNotifier_i> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/tests/FT_App/FTAPP_FactoryRegistry_Main.cpp b/TAO/orbsvcs/tests/FT_App/FTAPP_FactoryRegistry_Main.cpp index b09ab0cb3da..846f4393201 100644 --- a/TAO/orbsvcs/tests/FT_App/FTAPP_FactoryRegistry_Main.cpp +++ b/TAO/orbsvcs/tests/FT_App/FTAPP_FactoryRegistry_Main.cpp @@ -12,13 +12,13 @@ */ //============================================================================= -#include <tao/Utils/ServantMain.h> +#include <tao/Utils/Server_Main.h> #include "FactoryRegistry_i.h" int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { - TAO::Utils::ServantMain<FactoryRegistry_i> servantMain("FactoryRegistry"); - return servantMain.Main(argc, argv); + TAO::Utils::Server_Main<FactoryRegistry_i> server_main("FactoryRegistry"); + return server_main.run(argc, argv); } /////////////////////////////////// @@ -26,8 +26,8 @@ int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) // inept compilers. #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - template TAO::Utils::ServantMain<FactoryRegistry_i>; + template TAO::Utils::Server_Main<FactoryRegistry_i>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -# pragma instantiate TAO::Utils::ServantMain<FactoryRegistry_i> +# pragma instantiate TAO::Utils::Server_Main<FactoryRegistry_i> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/tests/FT_App/FTAPP_Notifier_Main.cpp b/TAO/orbsvcs/tests/FT_App/FTAPP_Notifier_Main.cpp index 977838eb284..304882a6ccb 100644 --- a/TAO/orbsvcs/tests/FT_App/FTAPP_Notifier_Main.cpp +++ b/TAO/orbsvcs/tests/FT_App/FTAPP_Notifier_Main.cpp @@ -13,13 +13,13 @@ */ //============================================================================= -#include <tao/Utils/ServantMain.h> +#include <tao/Utils/Server_Main.h> #include "StubFaultNotifier.h" int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { - TAO::Utils::ServantMain<StubFaultNotifier> servantMain("FaultNotifier"); - return servantMain.Main(argc, argv); + TAO::Utils::Server_Main<StubFaultNotifier> server_main("FaultNotifier"); + return server_main.run(argc, argv); } /////////////////////////////////// diff --git a/TAO/orbsvcs/tests/FT_App/FT_App.mpc b/TAO/orbsvcs/tests/FT_App/FT_App.mpc index d4758c64e26..946c4e22838 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_App.mpc +++ b/TAO/orbsvcs/tests/FT_App/FT_App.mpc @@ -26,6 +26,10 @@ project(*Client): taoclient, fault_tolerance, iormanip, ftorb, orbsvcsexe { Source_Files { FT_Client.cpp } + Documentation_Files { + // pretend the pl file is documentation for now + run_test_basic.pl + } } project(*Notifier): taoserver, fault_tolerance, orbsvcsexe { @@ -67,16 +71,6 @@ project(*Analyzer): taoclient, fault_tolerance, orbsvcsexe { StubBatchConsumer.cpp } -// // Custom folder: script to run this test -// Define_Custom(Script){ -// inputext = .pl, .py, .rb -// generic_outputext = .txt -// } -// -// Script_Files { -// run_test_detector.pl -// } - // explicitly omit IDL files IDL_Files { } @@ -95,16 +89,6 @@ project(*FaultConsumer): taoserver, fault_tolerance, orbsvcsexe { ../../FT_ReplicationManager/FT_FaultConsumer.cpp } -// // Custom folder: script to run this test -// Define_Custom(Script){ -// inputext = .pl, .py, .rb -// generic_outputext = .txt -// } -// -// Script_Files { -// run_test_detector.pl -// } - // explicitly omit IDL files IDL_Files { } @@ -122,16 +106,6 @@ project(*FactoryRegistry): taoclient, fault_tolerance, orbsvcsexe { FactoryRegistry_i.cpp } -// // Custom folder: script to run this test -// Define_Custom(Script){ -// inputext = .pl, .py, .rb -// generic_outputext = .txt -// } -// -// Script_Files { -// run_test_detector.pl -// } - // explicitly omit IDL files IDL_Files { } diff --git a/TAO/orbsvcs/tests/FT_App/FT_Client.cpp b/TAO/orbsvcs/tests/FT_App/FT_Client.cpp index e1a18c42e45..ba213f282d9 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_Client.cpp +++ b/TAO/orbsvcs/tests/FT_App/FT_Client.cpp @@ -78,12 +78,12 @@ FTClientMain::FTClientMain () FTClientMain::~FTClientMain () { - if (inFile_.is_open()) + if (this->inFile_.is_open()) { - inFile_.close(); + this->inFile_.close(); } - ACE_OS::free (fargValue_); - fargValue_ = 0; + ACE_OS::free (this->fargValue_); + this->fargValue_ = 0; } void FTClientMain::commandUsage(ostream & out) @@ -143,42 +143,42 @@ void FTClientMain::commandUsage(ostream & out) int FTClientMain::parse_args (int argc, char *argv[]) { - argc_ = argc; - argv_ = argv; + this->argc_ = argc; + this->argv_ = argv; int result = 0; // find the -f filename argument // and treat it specially - fargValue_ = 0; + this->fargValue_ = 0; int nArg; - for(nArg = 1; fargValue_ == 0 && nArg < argc - 1; ++nArg) + for(nArg = 1; this->fargValue_ == 0 && nArg < argc - 1; ++nArg) { if (argv[nArg][0] == '-' && argv[nArg][1] == 'f' && argv[nArg][2] == '\0') { // remember the starting, current, and ending position of farg - fargValue_ = ACE_OS::strdup(argv[nArg+1]); - fargPos_ = fargValue_; - fargEnd_ = fargValue_ + ACE_OS::strlen(fargPos_); + this->fargValue_ = ACE_OS::strdup(argv[nArg+1]); + this->fargPos_ = this->fargValue_; + this->fargEnd_ = this->fargValue_ + ACE_OS::strlen(this->fargPos_); // find a comma delimiter, and // chop the string there. - char * delim = ACE_OS::strchr (fargValue_, ','); + char * delim = ACE_OS::strchr (this->fargValue_, ','); while(delim != 0) { *delim = '\0'; delim = ACE_OS::strchr (delim + 1, ','); } - argv[nArg+1] = fargValue_; + argv[nArg+1] = this->fargValue_; - std::cout << "FT Client: Initial primary replica: " << fargPos_ << std::endl; + std::cout << "FT Client: Initial primary replica: " << this->fargPos_ << std::endl; // point fargPos at the next filename - fargPos_ = fargPos_ + ACE_OS::strlen(fargPos_); - if (fargPos_ != fargEnd_) + this->fargPos_ = this->fargPos_ + ACE_OS::strlen(this->fargPos_); + if (this->fargPos_ != this->fargEnd_) { - fargPos_ += 1; + this->fargPos_ += 1; } } } @@ -192,16 +192,16 @@ FTClientMain::parse_args (int argc, char *argv[]) switch (c) { case 'c': - inFileName_ = get_opts.opt_arg (); - inFile_.open(inFileName_); - if(inFile_.is_open() && inFile_.good()) + this->inFileName_ = get_opts.opt_arg (); + this->inFile_.open(this->inFileName_); + if(this->inFile_.is_open() && this->inFile_.good()) { - std::cout << "FT Client: Reading commands from " << inFileName_ << std::endl; - commandIn_ = & inFile_; + std::cout << "FT Client: Reading commands from " << this->inFileName_ << std::endl; + this->commandIn_ = & this->inFile_; } else { - std::cout << "FT Client: Can't open input file: " << inFileName_ << std::endl; + std::cout << "FT Client: Can't open input file: " << this->inFileName_ << std::endl; result = -1; } break; @@ -253,12 +253,12 @@ int FTClientMain::pass ( ::FT::State_var update; unsigned long updateValue = 0; - while(more && result == 0 && ! commandIn_->eof()) + while(more && result == 0 && ! this->commandIn_->eof()) { if (! retry || command.length () == 0 ) { char buffer[1000]; - commandIn_->getline(buffer, sizeof(buffer)-1); + this->commandIn_->getline(buffer, sizeof(buffer)-1); command = buffer; } retry = 0; @@ -270,14 +270,14 @@ int FTClientMain::pass ( char * junque; long operand = strtol(cdr.c_str(),&junque, 10); - if (verbose_ >= NOISY) + if (this->verbose_ >= NOISY) { std::cout << "FT Client: " << command << std::endl; } // turn echo on (based on verbose) // individual commands can turn it off - int echo = verbose_ >= QUIET; + int echo = this->verbose_ >= QUIET; switch(op) { @@ -288,7 +288,7 @@ int FTClientMain::pass ( } case '=': { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->set(" << operand << ");" << std::endl; } @@ -299,7 +299,7 @@ int FTClientMain::pass ( } case 'c': { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->get();" << std::endl; } @@ -320,7 +320,7 @@ int FTClientMain::pass ( } case '>': { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->counter(" << operand << ");" << std::endl; } @@ -331,7 +331,7 @@ int FTClientMain::pass ( } case '+': { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->increment(" << operand << ");" << std::endl; } @@ -342,7 +342,7 @@ int FTClientMain::pass ( } case '-': { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->increment(" << -operand << ");" << std::endl; } @@ -353,7 +353,7 @@ int FTClientMain::pass ( } case '<': { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->counter();" << std::endl; } @@ -365,7 +365,7 @@ int FTClientMain::pass ( } case '!': { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->is_alive();" << std::endl; } @@ -376,18 +376,18 @@ int FTClientMain::pass ( } case 'd': { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->die(" << operand << ");" << std::endl; } - ft_server->die(static_cast<FT_TEST::TestReplica::Bane>(operand ACE_ENV_ARG_PARAMETER)); + ft_server->die(ACE_static_cast (FT_TEST::TestReplica::Bane, operand) ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; echo = 0; break; } case 's': { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->get_state();" << std::endl; } @@ -400,7 +400,7 @@ int FTClientMain::pass ( { if (state.in() != 0) { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->set_state(saved_state);" << std::endl; } @@ -416,7 +416,7 @@ int FTClientMain::pass ( } case 'u': { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->get_update();" << std::endl; } @@ -429,7 +429,7 @@ int FTClientMain::pass ( { if (update.in() != 0) { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->set_update(saved_update);" << std::endl; } @@ -445,7 +445,7 @@ int FTClientMain::pass ( } case 'v': { - verbose_ = static_cast<Verbosity> (operand); + this->verbose_ = ACE_static_cast(Verbosity, operand); break; } case 'z': @@ -464,10 +464,11 @@ int FTClientMain::pass ( { ACE_TRY_NEW_ENV { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->shutdown();" << std::endl; } +std::cout << "call shutdown" << std::endl; ft_server->shutdown( ACE_ENV_SINGLE_ARG_PARAMETER); } ACE_CATCHANY @@ -491,9 +492,9 @@ int FTClientMain::pass ( break; } } - if (echo && verbose_ >= QUIET) + if (echo && this->verbose_ >= QUIET) { - if (verbose_ >= LOUD) + if (this->verbose_ >= LOUD) { std::cout << "FT Client: ->get();" << std::endl; } @@ -502,7 +503,7 @@ int FTClientMain::pass ( ACE_TRY_CHECK; if (value == counter) { - if (verbose_ >= NORMAL) + if (this->verbose_ >= NORMAL) { std::cout << "FT Client: " << counter << std::endl;; } @@ -521,9 +522,10 @@ int FTClientMain::pass ( int FTClientMain::run () { int result = 0; + ServerVar ft_server; // Initialize the ft_server. - result = ft_server.init ("FT_TEST",argc_, argv_); + result = ft_server.init ("FT_TEST",this->argc_, this->argv_); if ( result == 0) { @@ -534,7 +536,7 @@ int FTClientMain::run () int retry = 0; ACE_TRY_CHECK; - if (verbose_ >= NORMAL) + if (this->verbose_ >= NORMAL) { std::cout << "FT Client: Initial counter " << counter << std::endl; } @@ -544,7 +546,7 @@ int FTClientMain::run () } int more = 1; - while (more && result == 0 && ! commandIn_->eof()) + while (more && result == 0 && ! this->commandIn_->eof()) { ACE_TRY_NEW_ENV { @@ -558,13 +560,13 @@ int FTClientMain::run () retry = 0; int handled = 0; - if(fargPos_ != 0 && fargPos_ != fargEnd_) + if(this->fargPos_ != 0 && this->fargPos_ != this->fargEnd_) { - handled = ! ft_server.reconnect_file(fargPos_); + handled = ! ft_server.reconnect_file(this->fargPos_); if (handled) { std::cout << "FT Client: Recovering from fault." << std::endl; - std::cout << "FT Client: Activate " << fargPos_ << std::endl; + std::cout << "FT Client: Activate " << this->fargPos_ << std::endl; if (command.length () == 0) { std::cout << "FT Client: No command to retry." << std::endl; @@ -588,10 +590,10 @@ int FTClientMain::run () } // advance fargPos to next filename - fargPos_ += ACE_OS::strlen(fargPos_); - if (fargPos_ != fargEnd_) + this->fargPos_ += ACE_OS::strlen(this->fargPos_); + if (this->fargPos_ != this->fargEnd_) { - fargPos_ += 1; + this->fargPos_ += 1; } } } diff --git a/TAO/orbsvcs/tests/FT_App/FT_Replica.cpp b/TAO/orbsvcs/tests/FT_App/FT_Replica.cpp index 6225cfe6cde..9a962ca653d 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_Replica.cpp +++ b/TAO/orbsvcs/tests/FT_App/FT_Replica.cpp @@ -12,11 +12,11 @@ */ //============================================================================= -#include <tao/Utils/ServantMain.h> +#include <tao/Utils/Server_Main.h> #include "FT_ReplicaFactory_i.h" int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { - TAO::Utils::ServantMain<FT_ReplicaFactory_i> servantMain("TestReplicaFactory"); - return servantMain.Main(argc, argv); + TAO::Utils::Server_Main<FT_ReplicaFactory_i> server_main("TestReplicaFactory"); + return server_main.run(argc, argv); } diff --git a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp index bca3056ee78..4ce33159fb1 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp +++ b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp @@ -46,12 +46,15 @@ // FT_ReplicaFactory_i Construction/destruction FT_ReplicaFactory_i::FT_ReplicaFactory_i () - : iorOutputFile(0) - , nsName_(0) - , quitOnIdle_(0) - , testOutputFile_(0) - , emptySlots_(0) - , quitRequested_(0) + : ior_output_file_(0) + , factory_registry_ior_file_(0) + , ns_name_(0) + , type_id_(0) + , location_(0) + , quit_on_idle_(0) + , test_output_file_(0) + , empty_slots_(0) + , quit_requested_(0) { } @@ -60,7 +63,7 @@ FT_ReplicaFactory_i::~FT_ReplicaFactory_i () { //scope the guard { - InternalGuard guard (internals_); + InternalGuard guard (this->internals_); // be sure all replicas are gone // before this object disappears @@ -73,15 +76,15 @@ FT_ReplicaFactory_i::~FT_ReplicaFactory_i () //////////////////////////////////////////// // FT_ReplicaFactory_i private methods -CORBA::ULong FT_ReplicaFactory_i::allocateId() +CORBA::ULong FT_ReplicaFactory_i::allocate_id() { // assume mutex is locked - CORBA::ULong id = replicas_.size(); - if (emptySlots_ != 0) + CORBA::ULong id = this->replicas_.size(); + if (this->empty_slots_ != 0) { for(CORBA::ULong pos = 0; pos < id; ++pos) { - if (replicas_[pos] == 0) + if (this->replicas_[pos] == 0) { id = pos; } @@ -89,8 +92,8 @@ CORBA::ULong FT_ReplicaFactory_i::allocateId() } else { - replicas_.push_back(0); - emptySlots_ += 1; + this->replicas_.push_back(0); + this->empty_slots_ += 1; } return id; } @@ -98,17 +101,17 @@ CORBA::ULong FT_ReplicaFactory_i::allocateId() void FT_ReplicaFactory_i::shutdown_i() { // assume mutex is locked - for (size_t nReplica = 0; nReplica < replicas_.size(); ++nReplica) + for (size_t nReplica = 0; nReplica < this->replicas_.size(); ++nReplica) { - FT_TestReplica_i * replica = replicas_[nReplica]; + FT_TestReplica_i * replica = this->replicas_[nReplica]; if (replica != 0) { - replica->requestQuit(); + replica->request_quit(); } } } -int FT_ReplicaFactory_i::writeIOR(const char * outputFile, const char * ior) +int FT_ReplicaFactory_i::write_ior(const char * outputFile, const char * ior) { int result = -1; FILE* out = ACE_OS::fopen (outputFile, "w"); @@ -132,7 +135,7 @@ int FT_ReplicaFactory_i::writeIOR(const char * outputFile, const char * ior) int FT_ReplicaFactory_i::parse_args (int argc, char * argv[]) { - ACE_Get_Opt get_opts (argc, argv, "o:t:r:q"); + ACE_Get_Opt get_opts (argc, argv, "o:n:f:i:l:t:q"); int c; while ((c = get_opts ()) != -1) @@ -141,23 +144,38 @@ int FT_ReplicaFactory_i::parse_args (int argc, char * argv[]) { case 'o': { - iorOutputFile = get_opts.opt_arg (); + this->ior_output_file_ = get_opts.opt_arg (); break; } - case 'r': + case 'n': { - identity_ = get_opts.opt_arg (); + this->ns_name_ = get_opts.opt_arg (); + break; + } + case 'f': + { + this->factory_registry_ior_file_ = get_opts.opt_arg (); + break; + } + case 'i': + { + this->type_id_ = get_opts.opt_arg (); + break; + } + case 'l': + { + this->location_ = get_opts.opt_arg (); break; } case 'q': { - quitOnIdle_ = 1; + this->quit_on_idle_ = 1; break; } case 't': { - testOutputFile_ = get_opts.opt_arg (); + this->test_output_file_ = get_opts.opt_arg (); break; } @@ -167,6 +185,10 @@ int FT_ReplicaFactory_i::parse_args (int argc, char * argv[]) ACE_ERROR_RETURN ((LM_ERROR, "usage: %s" " -o <factory ior file>" + " -n <naming service registration name>" + " -f <factory registry ior file>" + " -i <registration: type_id>" + " -l <registration: location>" " -t <test replica ior file>" " -q{uit on idle}" "\n", @@ -181,35 +203,38 @@ int FT_ReplicaFactory_i::parse_args (int argc, char * argv[]) const char * FT_ReplicaFactory_i::identity () const { - return identity_.c_str(); + return this->identity_.c_str(); } int FT_ReplicaFactory_i::idle (int & result) { result = 0; - size_t replicaCount = replicas_.size(); - if (replicaCount != emptySlots_) + size_t replicaCount = this->replicas_.size(); + if (replicaCount != this->empty_slots_) { for (size_t nReplica = 0; result == 0 && nReplica < replicaCount; ++nReplica) { - FT_TestReplica_i * replica = replicas_[nReplica]; + FT_TestReplica_i * replica = this->replicas_[nReplica]; if (replica != 0) { - if (replica->idle(result)) - { - removeReplica(nReplica, replica); - } + // give the replica's idle processing a change + // ignore the return status (the replica should shut itself down + // unless result is non-zero. + // non-zero result means panic. + replica->idle(result); } } } - int quit = (quitRequested_ || result != 0); - if (!quit && replicas_.size() == emptySlots_) + int quit = (this->quit_requested_ || result != 0); + if (!quit && this->replicas_.size() == this->empty_slots_) { +/* if you re-enable this, add some kind of throttle to avoid noise. ACE_ERROR (( LM_ERROR, "ReplicaFactory is idle.\n" )); - if (quitOnIdle_ && emptySlots_ != 0) +*/ + if (this->quit_on_idle_ && this->empty_slots_ != 0) { ACE_ERROR (( LM_ERROR, "ReplicaFactory exits due to quit on idle option.\n" @@ -224,53 +249,165 @@ int FT_ReplicaFactory_i::idle (int & result) int FT_ReplicaFactory_i::fini (ACE_ENV_SINGLE_ARG_DECL) { - if (iorOutputFile != 0) + if (this->ior_output_file_ != 0) { - ACE_OS::unlink (iorOutputFile); - iorOutputFile = 0; + ACE_OS::unlink (this->ior_output_file_); + this->ior_output_file_ = 0; } - if (nsName_ != 0) + if (this->ns_name_ != 0) { - naming_context_->unbind (this_name_ + this->naming_context_->unbind (this_name_ ACE_ENV_ARG_PARAMETER); - nsName_ = 0; + this->ns_name_ = 0; } return 0; } -int FT_ReplicaFactory_i::init (TAO_ORB_Manager & orbManager - ACE_ENV_ARG_DECL) +int FT_ReplicaFactory_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) { int result = 0; - orbManager_ = & orbManager; - orb_ = orbManager.orb(); + this->orb_ = orb; + + // Use the ROOT POA for now + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + if (CORBA::is_nil (poa_object.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")), + -1); + } + + // Get the POA object. + this->poa_ = + PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); - // Register with the ORB. - ior_ = orbManager.activate (this - ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); + if (CORBA::is_nil(this->poa_)) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")), + -1); + } + + PortableServer::POAManager_var poa_manager = + this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Register with the POA. + + this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Object_var this_obj = + this->poa_->id_to_reference (object_id_.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->ior_ = this->orb_->object_to_string (this_obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + + if (factory_registry_ior_file_ != 0) + { + CORBA::String_var registry_ior; + if (read_ior_file(this->factory_registry_ior_file_, registry_ior)) + { + CORBA::Object_var reg_obj = this->orb_->string_to_object(registry_ior + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + this->factory_registry_ = ::PortableGroup::FactoryRegistry::_narrow(reg_obj); + if (! CORBA::is_nil(factory_registry_)) + { + ::PortableGroup::GenericFactory_var this_var = ::PortableGroup::GenericFactory::_narrow(this_obj); + if (! CORBA::is_nil(this_var)) + { + PortableGroup::FactoryInfo info; + info.the_factory = this_var; + info.the_location.length(1); + info.the_location[0].id = CORBA::string_dup(location_); + info.the_criteria.length(0); + + factory_registry_->register_factory( + this->type_id_, + info + ACE_ENV_ARG_PARAMETER); + + } + else + { + ACE_ERROR (( LM_ERROR, + "Unexpected error: object reference should be a ReplicaFactory?\n" + )); + } + } + else + { + ACE_ERROR (( LM_ERROR, + "Can't resolve Factory Registry IOR %s\n", + this->factory_registry_ior_file_ + )); + result = -1; + } + } + else + { + ACE_ERROR (( LM_ERROR, + "Can't read %s\n", + this->factory_registry_ior_file_ + )); + result = -1; + } + } + int identified = 0; // bool + + if (this->type_id_ != 0) + { + this->identity_ = type_id_; + if (this->location_ != 0) + { + this->identity_ += "@"; + this->identity_ += this->location_; + } + identified = 1; + } - if (iorOutputFile != 0) + if (this->ior_output_file_ != 0) { - identity_ = "file:"; - identity_ += iorOutputFile; - result = writeIOR (iorOutputFile, ior_); + if (!identified) + { + this->identity_ = "file:"; + this->identity_ += this->ior_output_file_; + // note: don't set identified--ns identity overrides file identitiy + } + result = write_ior (this->ior_output_file_, this->ior_); } else { // if no IOR file specified, // then always try to register with name service - nsName_ = "FT_ReplicaFactory"; + this->ns_name_ = "FT_ReplicaFactory"; } - if (nsName_ != 0) + if (this->ns_name_ != 0) { - identity_ = "name:"; - identity_ += nsName_; + if (!identified) + { + this->identity_ = "name:"; + this->identity_ += this->ns_name_; + } CORBA::Object_var naming_obj = - orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); + this->orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; if (CORBA::is_nil(naming_obj.in ())){ @@ -279,47 +416,74 @@ int FT_ReplicaFactory_i::init (TAO_ORB_Manager & orbManager 1); } - naming_context_ = + this->naming_context_ = CosNaming::NamingContext::_narrow (naming_obj.in () ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; - this_name_.length (1); - this_name_[0].id = CORBA::string_dup (nsName_); + this->this_name_.length (1); + this->this_name_[0].id = CORBA::string_dup (this->ns_name_); - naming_context_->rebind (this_name_, _this() + this->naming_context_->rebind (this->this_name_, _this() ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; } // if we're testing. Create a replica at startup time - if (testOutputFile_ != 0) + if (this->test_output_file_ != 0) { - // shouldn't be necessary, but createReplica assumes this - InternalGuard guard (internals_); - FT_TestReplica_i * replica = createReplica (); - - PortableServer::POA_var poa = replica->_default_POA (ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - ::CORBA::Object_var obj = poa->servant_to_reference(replica); - ::CORBA::ORB_var orb = orbManager_->orb(); - ::CORBA::String_var replicaIOR = orb->object_to_string(obj); - writeIOR (testOutputFile_, replicaIOR); + // shouldn't be necessary, but create_replica assumes this + InternalGuard guard (this->internals_); + FT_TestReplica_i * replica = create_replica (); + + PortableServer::POA_var poa = replica->_default_POA (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + ::CORBA::Object_var replica_obj = poa->servant_to_reference(replica ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + ::CORBA::String_var replicaIOR = this->orb_->object_to_string(replica_obj ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + write_ior (this->test_output_file_, replicaIOR); } return result; } -void FT_ReplicaFactory_i::removeReplica(CORBA::ULong id, FT_TestReplica_i * replica) +int FT_ReplicaFactory_i::read_ior_file(const char * fileName, CORBA::String_var & ior) +{ + int result = 0; + FILE *in = ACE_OS::fopen (fileName, "r"); + ACE_OS::fseek(in, 0, SEEK_END); + size_t fileSize = ACE_OS::ftell(in); + ACE_OS::fseek(in, 0, SEEK_SET); + char * buffer; + ACE_NEW_NORETURN (buffer, + char[fileSize+1]); + if (buffer != 0) + { + if( fileSize == ACE_OS::fread(buffer, 1, fileSize, in)) + { + buffer[fileSize] = '\0'; + ior = CORBA::string_dup(buffer); + ACE_TRY_CHECK; + result = 1; // success + } + delete[] buffer; + } + return result; +} + + + +void FT_ReplicaFactory_i::remove_replica(CORBA::ULong id, FT_TestReplica_i * replica) { - InternalGuard guard (internals_); - if (id < replicas_.size()) + InternalGuard guard (this->internals_); + if (id < this->replicas_.size()) { - if(replicas_[id] == replica) + if(this->replicas_[id] == replica) { replica->fini(); delete replica; - replicas_[id] = 0; - emptySlots_ += 1; + this->replicas_[id] = 0; + this->empty_slots_ += 1; } else { @@ -334,7 +498,7 @@ void FT_ReplicaFactory_i::removeReplica(CORBA::ULong id, FT_TestReplica_i * repl ACE_ERROR (( LM_ERROR, "Attempt to remove invalid replica %d. Limit %d.\n", ACE_static_cast(int, id), - ACE_static_cast(int, replicas_.size()) + ACE_static_cast(int, this->replicas_.size()) )); } } @@ -358,7 +522,7 @@ CORBA::Object_ptr FT_ReplicaFactory_i::create_object ( )) { METHOD_ENTRY(FT_ReplicaFactory_i::create_object); - InternalGuard guard (internals_); + InternalGuard guard (this->internals_); ::TAO_PG::Properties_Decoder decoder (the_criteria); @@ -383,7 +547,7 @@ CORBA::Object_ptr FT_ReplicaFactory_i::create_object ( ACE_THROW ( PortableGroup::InvalidCriteria() ); } - FT_TestReplica_i * replica = createReplica(); + FT_TestReplica_i * replica = create_replica(); if (replica == 0) { ACE_ERROR ((LM_ERROR, @@ -402,26 +566,26 @@ CORBA::Object_ptr FT_ReplicaFactory_i::create_object ( ACE_THROW ( PortableGroup::ObjectNotCreated() ); } - (*factory_creation_id) <<= replica->factoryId(); + (*factory_creation_id) <<= replica->factory_id(); - ::CORBA::Object_ptr obj = replica->_default_POA()->servant_to_reference(replica); - METHOD_RETURN(FT_ReplicaFactory_i::create_object) obj->_duplicate(obj ACE_ENV_ARG_PARAMETER); + ::CORBA::Object_ptr replica_obj = replica->_default_POA()->servant_to_reference(replica); + METHOD_RETURN(FT_ReplicaFactory_i::create_object) replica_obj->_duplicate(replica_obj ACE_ENV_ARG_PARAMETER); } -FT_TestReplica_i * FT_ReplicaFactory_i::createReplica() +FT_TestReplica_i * FT_ReplicaFactory_i::create_replica() { // assume mutex is locked - CORBA::ULong factoryId = allocateId(); + CORBA::ULong factoryId = allocate_id(); FT_TestReplica_i * pFTReplica = 0; ACE_NEW_NORETURN(pFTReplica, FT_TestReplica_i( this, factoryId )); - replicas_[factoryId] = pFTReplica; - emptySlots_ -= 1; + this->replicas_[factoryId] = pFTReplica; + this->empty_slots_ -= 1; - pFTReplica->init (*orbManager_ ACE_ENV_ARG_PARAMETER); + pFTReplica->init (this->orb_ ACE_ENV_ARG_PARAMETER); return pFTReplica; } @@ -436,15 +600,15 @@ void FT_ReplicaFactory_i::delete_object ( { METHOD_ENTRY(FT_ReplicaFactory_i::delete_object); - InternalGuard guard (internals_); + InternalGuard guard (this->internals_); CORBA::ULong factoryId; factory_creation_id >>= factoryId; - if (factoryId < replicas_.size()) + if (factoryId < this->replicas_.size()) { - if(replicas_[factoryId] != 0) + if(this->replicas_[factoryId] != 0) { - replicas_[factoryId]->requestQuit(); + this->replicas_[factoryId]->request_quit(); } else { @@ -471,9 +635,9 @@ void FT_ReplicaFactory_i::shutdown (ACE_ENV_SINGLE_ARG_DECL) )) { METHOD_ENTRY(FT_FaultDetectorFactory_i::shutdown); - InternalGuard guard (internals_); + InternalGuard guard (this->internals_); shutdown_i (); - quitRequested_ = 1; + this->quit_requested_ = 1; METHOD_RETURN(FT_FaultDetectorFactory_i::shutdown); } diff --git a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h index 558e05ca448..c02ddee15fa 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h +++ b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h @@ -70,7 +70,7 @@ public: * @param orbManager our ORB -- we keep var to it. * @return zero for success; nonzero is process return code for failure. */ - int init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL_WITH_DEFAULTS); + int init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL_WITH_DEFAULTS); /** * Prepare to exit. @@ -93,7 +93,7 @@ public: * @param id the numerical id assigned to this replica. * @param replica a pointer to the Replica object (redundant for safety.) */ - void removeReplica (CORBA::ULong id, FT_TestReplica_i * replica); + void remove_replica (CORBA::ULong id, FT_TestReplica_i * replica); ////////////////// // CORBA interface @@ -142,17 +142,22 @@ private: /** * Actual replica creation happens in this method. */ - FT_TestReplica_i * createReplica(); + FT_TestReplica_i * create_replica(); /** * Find or allocate an ID for a new replica */ - CORBA::ULong allocateId(); + CORBA::ULong allocate_id(); /** * Write this factory's IOR to a file */ - int writeIOR (const char * outputFile, const char * ior); + int write_ior (const char * outputFile, const char * ior); + + /** + * Read IOR from a file + */ + int read_ior_file(const char * fileName, CORBA::String_var & ior); /** * Clean house for factory shut down. @@ -179,41 +184,64 @@ private: ACE_Mutex internals_; typedef ACE_Guard<ACE_Mutex> InternalGuard; - TAO_ORB_Manager * orbManager_; /** * The orb */ CORBA::ORB_var orb_; /** - * IOR of this object as assigned by orb. + * The POA used to activate this object. + */ + PortableServer::POA_var poa_; + + /** + * The CORBA object id assigned to this object. + */ + PortableServer::ObjectId_var object_id_; + + /** + * IOR of this object as assigned by poa */ CORBA::String_var ior_; /** * A file to which the factory's IOR should be written. */ - const char * iorOutputFile; + const char * ior_output_file_; + + /** + * A file from which to read the factory registry IOR + */ + const char * factory_registry_ior_file_; + /** + * The factory registry with which to register. + */ + PortableGroup::FactoryRegistry_var factory_registry_; /** * A file to which the test replica's IOR will be written */ - const char * testOutputFile_; + const char * test_output_file_; /** * A name to be used to register the factory with the name service. */ - const char * nsName_; + const char * ns_name_; CosNaming::NamingContext_var naming_context_; CosNaming::Name this_name_; + +//todo initialize + const char * type_id_; + const char * location_; + /** * Quit on idle flag. */ - int quitOnIdle_; + int quit_on_idle_; /** * A vector of Replicas. Note that the Replica ID @@ -226,12 +254,12 @@ private: * Used to determine when the factory is idle and to avoid futile * searches for empty slots. */ - size_t emptySlots_; + size_t empty_slots_; /** * boolean: starts false. Set to true when it's time to quit. */ - int quitRequested_; + int quit_requested_; }; diff --git a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp index d4334e51ca1..a8f51e0c1b0 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp +++ b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp @@ -36,10 +36,10 @@ namespace template<typename BUFFER> void storeLong(BUFFER & state, size_t offset, long value) { - state[offset ] = static_cast<unsigned char>(value >> 24); - state[offset + 1] = static_cast<unsigned char>(value >> 16); - state[offset + 2] = static_cast<unsigned char>(value >> 8); - state[offset + 3] = static_cast<unsigned char>(value ); + state[offset ] = ACE_static_cast (unsigned char, value >> 24); + state[offset + 1] = ACE_static_cast (unsigned char, value >> 16); + state[offset + 2] = ACE_static_cast (unsigned char, value >> 8); + state[offset + 3] = ACE_static_cast (unsigned char, value ); } /** @@ -66,16 +66,16 @@ namespace // Macros to simplify suicide. #define KEVORKIAN(value, method) \ - if (death_pending_ == (FT_TEST::TestReplica::value)){ \ + if (this->death_pending_ == (FT_TEST::TestReplica::value)){ \ suicide (#value " in method " #method); \ CORBA::OBJECT_NOT_EXIST ex; \ ACE_THROW(ex); \ } else ; #define KEVORKIAN_DURING(method) \ - if (death_pending_ == FT_TEST::TestReplica::BEFORE_STATE_CHANGE \ - || death_pending_ == FT_TEST::TestReplica::BEFORE_REPLICATION \ - || death_pending_ == FT_TEST::TestReplica::BEFORE_REPLY ){ \ + if (this->death_pending_ == FT_TEST::TestReplica::BEFORE_STATE_CHANGE \ + || this->death_pending_ == FT_TEST::TestReplica::BEFORE_REPLICATION \ + || this->death_pending_ == FT_TEST::TestReplica::BEFORE_REPLY ){ \ suicide ("read-only method " #method); \ CORBA::OBJECT_NOT_EXIST ex; \ ACE_THROW(ex); \ @@ -85,9 +85,9 @@ namespace ////////////////////////////////////////////////// // class FT_TestReplica_i construction/destruction -FT_TestReplica_i::FT_TestReplica_i (FT_ReplicaFactory_i * factory, long factoryId) +FT_TestReplica_i::FT_TestReplica_i (FT_ReplicaFactory_i * factory, long factory_id) : factory_(factory) - , factoryId_(factoryId) + , factory_id_(factory_id) , death_pending_(FT_TEST::TestReplica::NOT_YET) , verbose_(1) { @@ -100,12 +100,11 @@ FT_TestReplica_i::~FT_TestReplica_i () void FT_TestReplica_i::suicide(const char * note) { - std::cout << factory_->identity() << '#' << factoryId_ << " Simulate fault: " << note << std::endl; - //////////////////////////////////////// - // WARNING: The following call deletes this object and - // deactivates the servant! With luck it'll zap the replica - // not the entire process. - factory_->removeReplica(factoryId_, this); + std::cout << this->factory_->identity() << '#' << this->factory_id_ << " Simulate fault: " << note << std::endl; + + // Tell the poa we aren't accepting future calls + this->poa_->deactivate_object (this->object_id_.in () + ACE_ENV_ARG_PARAMETER); } ///////////////////////////////////////////////////// @@ -123,19 +122,19 @@ FT_TestReplica_i::usage_options() return ""; } -long FT_TestReplica_i::factoryId()const +long FT_TestReplica_i::factory_id()const { - return factoryId_; + return this->factory_id_; } ::PortableServer::POA_ptr FT_TestReplica_i::_default_POA (ACE_ENV_SINGLE_ARG_DECL) { - return ::PortableServer::POA::_duplicate(poa_ ACE_ENV_ARG_PARAMETER); + return ::PortableServer::POA::_duplicate(this->poa_ ACE_ENV_ARG_PARAMETER); } -PortableServer::ObjectId FT_TestReplica_i::objectId()const +PortableServer::ObjectId FT_TestReplica_i::object_id()const { - return objectId_.in(); + return this->object_id_.in(); } @@ -144,19 +143,60 @@ PortableServer::ObjectId FT_TestReplica_i::objectId()const * @param orbManager our ORB -- we keep var to it. * @return zero for success; nonzero is process return code for failure. */ -int FT_TestReplica_i::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) +int FT_TestReplica_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) { - orbManager_ = & orbManager; - poa_ = orbManager_->root_poa(); - objectId_ = poa_->activate_object (this ACE_ENV_ARG_PARAMETER); + this->orb_ = orb; + + // Use the ROOT POA for now + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); + + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")), + -1); + + // Get the POA object. + this->poa_ = + PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); + + ACE_CHECK_RETURN (-1); + + if (CORBA::is_nil(this->poa_)) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")), + -1); + } + + PortableServer::POAManager_var poa_manager = + this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + + // Register with the POA. + + this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + return 0; } +void FT_TestReplica_i::_remove_ref (ACE_ENV_SINGLE_ARG_DECL) +{ + ////////////////////////////////////////////////// + // WARNING: The following call invokes fini then deletes this object + this->factory_->remove_replica(this->factory_id_, this); +} + int FT_TestReplica_i::fini (ACE_ENV_SINGLE_ARG_DECL) { - poa_->deactivate_object (objectId_.in () - ACE_ENV_ARG_PARAMETER); return 0; } @@ -170,12 +210,12 @@ CORBA::Boolean FT_TestReplica_i::is_alive () KEVORKIAN(DURING_IS_ALIVE, is_alive) ACE_ERROR ((LM_ERROR, "%s#%d: is_alive: %d\n", - factory_->identity(), - factoryId_, - (death_pending_ != FT_TEST::TestReplica::DENY_IS_ALIVE) + this->factory_->identity(), + this->factory_id_, + (this->death_pending_ != FT_TEST::TestReplica::DENY_IS_ALIVE) )); - return death_pending_ != FT_TEST::TestReplica::DENY_IS_ALIVE; + return this->death_pending_ != FT_TEST::TestReplica::DENY_IS_ALIVE; } ///////////////////////////////////////////////////// @@ -288,17 +328,17 @@ void FT_TestReplica_i::die (FT_TEST::TestReplica::Bane when ACE_ENV_ARG_DECL) ACE_THROW_SPEC ((CORBA::SystemException)) { - std::cout << factory_->identity() << '#' << factoryId_ << " Received death threat: " << when << std::endl; + std::cout << this->factory_->identity() << '#' << this->factory_id_ << " Received death threat: " << when << std::endl; - death_pending_ = when; + this->death_pending_ = when; KEVORKIAN(RIGHT_NOW, die) } void FT_TestReplica_i::shutdown (ACE_ENV_SINGLE_ARG_DECL) ACE_THROW_SPEC ((CORBA::SystemException)) { - factory_->removeReplica(factoryId_, this); - death_pending_ = FT_TEST::TestReplica::CLEAN_EXIT; + std::cout << this->factory_->identity() << '#' << this->factory_id_ << " Shut down requested" << std::endl; + this->death_pending_ = FT_TEST::TestReplica::CLEAN_EXIT; } ////////////////////////////////////////////// @@ -306,27 +346,31 @@ void FT_TestReplica_i::shutdown (ACE_ENV_SINGLE_ARG_DECL) int FT_TestReplica_i::idle (int & result) { int quit = 0; - if (death_pending_ == FT_TEST::TestReplica::WHILE_IDLE) + if (this->death_pending_ == FT_TEST::TestReplica::WHILE_IDLE) { ACE_ERROR ((LM_ERROR, "%s#%d: Simulated fault WHILE_IDLE", - factory_->identity(), - ACE_static_cast(int, factoryId_ ) + this->factory_->identity(), + ACE_static_cast(int, this->factory_id_ ) )); + this->poa_->deactivate_object (this->object_id_.in () + ACE_ENV_ARG_PARAMETER); result = 0; quit = 1; } - else if (death_pending_ == FT_TEST::TestReplica::CLEAN_EXIT) + else if (this->death_pending_ == FT_TEST::TestReplica::CLEAN_EXIT) { + this->poa_->deactivate_object (this->object_id_.in () + ACE_ENV_ARG_PARAMETER); result = 0; quit = 1; } return quit; } -void FT_TestReplica_i::requestQuit() +void FT_TestReplica_i::request_quit() { - death_pending_ = FT_TEST::TestReplica::WHILE_IDLE; + this->death_pending_ = FT_TEST::TestReplica::WHILE_IDLE; } @@ -339,9 +383,9 @@ void FT_TestReplica_i::store(long counter) storeLong(buffer, 0, counter); ACE_OS::fwrite(buffer, 1, sizeof(long), f); ACE_OS::fclose(f); - if (verbose_) + if (this->verbose_) { - std::cout << factory_->identity() << '#' << factoryId_ << ": " << counter << std::endl; + std::cout << this->factory_->identity() << '#' << this->factory_id_ << ": " << counter << std::endl; } } } diff --git a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h index 63d646ca1b1..a3a899ddb39 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h +++ b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h @@ -23,7 +23,6 @@ //////////////////// // Forward Reference class FT_ReplicaFactory_i; -class TAO_ORB_Manager; /** * Implement the TestReplica IDL interface. @@ -34,7 +33,7 @@ class TAO_ORB_Manager; class FT_TestReplica_i : public virtual POA_FT_TEST::TestReplica { public: - FT_TestReplica_i (FT_ReplicaFactory_i * factory, long factoryId); + FT_TestReplica_i (FT_ReplicaFactory_i * factory, long factory_id); virtual ~FT_TestReplica_i (); /** @@ -59,7 +58,7 @@ public: * @param orbManager our ORB -- we keep var to it. * @return zero for success; nonzero is process return code for failure. */ - int init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL); + int init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL); /** * Prepare to exit. @@ -74,17 +73,20 @@ public: */ int idle(int &result); - void requestQuit(); + void request_quit(); - virtual PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL); - long factoryId()const; + long factory_id()const; + + ::FT_TEST::TestReplica_ptr object_reference(); - ::FT_TEST::TestReplica_ptr objectReference(); - PortableServer::ObjectId objectId()const; -// char * IOR(); + PortableServer::ObjectId object_id()const; + ////////////////////////////////////////// + // Override CORBA servant virtual methods + virtual PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL); + virtual void FT_TestReplica_i::_remove_ref (ACE_ENV_SINGLE_ARG_DECL); private: /////////////////////////// @@ -167,7 +169,7 @@ private: /** * The ID number assigned by the factory */ - long factoryId_; + long factory_id_; /** * the factory that created thsi replica @@ -175,9 +177,9 @@ private: FT_ReplicaFactory_i * factory_; /** - * The orb used to activate this object + * The orb */ - TAO_ORB_Manager * orbManager_; + CORBA::ORB_var orb_; /** * The POA used to activate this object. @@ -187,7 +189,7 @@ private: /** * The CORBA object id assigned to this object. */ - PortableServer::ObjectId_var objectId_; + PortableServer::ObjectId_var object_id_; }; diff --git a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.cpp b/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.cpp index 6db1278c848..104c3e75834 100644 --- a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.cpp +++ b/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.cpp @@ -34,10 +34,10 @@ return /* value goes here */ FactoryRegistry_i::FactoryRegistry_i () - : iorOutputFile(0) - , nsName_(0) - , quitOnIdle_(0) - , quitRequested_(0) + : ior_output_file_(0) + , ns_name_(0) + , quit_on_idle_(0) + , quit_requested_(0) { } @@ -51,7 +51,7 @@ FactoryRegistry_i::~FactoryRegistry_i (void) int FactoryRegistry_i::parse_args (int argc, char * argv[]) { - ACE_Get_Opt get_opts (argc, argv, "o:t:r:q"); + ACE_Get_Opt get_opts (argc, argv, "o:q"); int c; while ((c = get_opts ()) != -1) @@ -60,12 +60,12 @@ int FactoryRegistry_i::parse_args (int argc, char * argv[]) { case 'o': { - iorOutputFile = get_opts.opt_arg (); + this->ior_output_file_ = get_opts.opt_arg (); break; } case 'q': { - quitOnIdle_ = 1; + this->quit_on_idle_ = 1; break; } @@ -75,7 +75,6 @@ int FactoryRegistry_i::parse_args (int argc, char * argv[]) ACE_ERROR_RETURN ((LM_ERROR, "usage: %s" " -o <factory ior file>" - " -t <test replica ior file>" " -q{uit on idle}" "\n", argv [0]), @@ -89,66 +88,108 @@ int FactoryRegistry_i::parse_args (int argc, char * argv[]) const char * FactoryRegistry_i::identity () const { - return identity_.c_str(); + return this->identity_.c_str(); } int FactoryRegistry_i::idle (int & result) { result = 0; - int quit = quitRequested_; + int quit = this->quit_requested_; return quit; } int FactoryRegistry_i::fini (ACE_ENV_SINGLE_ARG_DECL) { - if (iorOutputFile != 0) + if (this->ior_output_file_ != 0) { - ACE_OS::unlink (iorOutputFile); - iorOutputFile = 0; + ACE_OS::unlink (this->ior_output_file_); + this->ior_output_file_ = 0; } - if (nsName_ != 0) + if (this->ns_name_ != 0) { - naming_context_->unbind (this_name_ + this->naming_context_->unbind (this_name_ ACE_ENV_ARG_PARAMETER); - nsName_ = 0; + this->ns_name_ = 0; } return 0; } -int FactoryRegistry_i::init (TAO_ORB_Manager & orbManager - ACE_ENV_ARG_DECL) +int FactoryRegistry_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) { int result = 0; - orbManager_ = & orbManager; - orb_ = orbManager.orb(); + this->orb_ = orb; - // Register with the ORB. - ior_ = orbManager.activate (this - ACE_ENV_ARG_PARAMETER); + // Use the ROOT POA for now + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); - if (iorOutputFile != 0) + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")), + -1); + + // Get the POA object. + this->poa_ = + PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); + + ACE_CHECK_RETURN (-1); + + if (CORBA::is_nil(this->poa_)) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")), + -1); + } + + PortableServer::POAManager_var poa_manager = + this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Register with the POA. + + this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // find my IOR + + CORBA::Object_var obj = + this->poa_->id_to_reference (object_id_.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->ior_ = this->orb_->object_to_string (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + + if (this->ior_output_file_ != 0) { - identity_ = "file:"; - identity_ += iorOutputFile; - result = writeIOR (iorOutputFile, ior_); + this->identity_ = "file:"; + this->identity_ += this->ior_output_file_; + result = writeIOR (this->ior_output_file_, this->ior_); } else { // if no IOR file specified, // then always try to register with name service - nsName_ = "FactoryRegistry"; + this->ns_name_ = "FactoryRegistry"; } - if (nsName_ != 0) + if (this->ns_name_ != 0) { - identity_ = "name:"; - identity_ += nsName_; + this->identity_ = "name:"; + this->identity_ += this->ns_name_; CORBA::Object_var naming_obj = - orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); + this->orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; if (CORBA::is_nil(naming_obj.in ())){ @@ -157,14 +198,14 @@ int FactoryRegistry_i::init (TAO_ORB_Manager & orbManager 1); } - naming_context_ = + this->naming_context_ = CosNaming::NamingContext::_narrow (naming_obj.in () ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; - this_name_.length (1); - this_name_[0].id = CORBA::string_dup (nsName_); + this->this_name_.length (1); + this->this_name_[0].id = CORBA::string_dup (this->ns_name_); - naming_context_->rebind (this_name_, _this() + this->naming_context_->rebind (this->this_name_, _this() ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; } @@ -197,7 +238,7 @@ void FactoryRegistry_i::register_factory ( METHOD_ENTRY(FactoryRegistry_i::register_factory); PortableGroup::FactoryInfos * infos; - if (registry_.find(type_id, infos) ) + if (this->registry_.find(type_id, infos) == 0) { ACE_DEBUG(( LM_DEBUG, "register_factory found infos for %s", type_id @@ -206,7 +247,7 @@ void FactoryRegistry_i::register_factory ( else { ACE_DEBUG(( LM_DEBUG, - "register_factory: no infos for %s", type_id + "register_factory: no infos for %s\n", type_id )); // Note the 5. It's a guess about the number of factories // that might exist for any particular type of object. @@ -219,7 +260,7 @@ void FactoryRegistry_i::register_factory ( ACE_THROW (CORBA::NO_MEMORY (TAO_DEFAULT_MINOR_CODE, CORBA::COMPLETED_NO)); } - registry_.bind(type_id, infos); + this->registry_.bind(type_id, infos); } // at this point infos points to the infos structure // for this type.. @@ -251,7 +292,7 @@ void FactoryRegistry_i::unregister_factory ( METHOD_ENTRY(FactoryRegistry_i::unregister_factory); PortableGroup::FactoryInfos * infos; - if (registry_.find(type_id, infos) ) + if (this->registry_.find(type_id, infos) == 0) { ACE_DEBUG(( LM_DEBUG, "register_factory found infos for %s", type_id @@ -279,7 +320,7 @@ void FactoryRegistry_i::unregister_factory ( else { assert ( length == 1 ); - registry_.unbind (type_id); + this->registry_.unbind (type_id); delete infos; } } @@ -292,7 +333,7 @@ void FactoryRegistry_i::unregister_factory ( )); ACE_THROW ( PortableGroup::MemberNotFound() ); infos->length(0); - registry_.bind(type_id, infos); + this->registry_.bind(type_id, infos); } METHOD_RETURN(FactoryRegistry_i::unregister_factory); @@ -306,7 +347,7 @@ void FactoryRegistry_i::unregister_factory_by_type ( { METHOD_ENTRY(FactoryRegistry_i::unregister_factory_by_type); PortableGroup::FactoryInfos * infos; - if (registry_.unbind(type_id, infos) ) + if (this->registry_.unbind(type_id, infos) ) { ACE_DEBUG(( LM_DEBUG, "unregister_factory_by_type found infos for %s", type_id @@ -334,8 +375,8 @@ void FactoryRegistry_i::unregister_factory_by_location ( ACE_Vector<ACE_CString> hitList; // iterate through the registery - for (RegistryType_Iterator it = registry_.begin(); - it != registry_.end(); + for (RegistryType_Iterator it = this->registry_.begin(); + it != this->registry_.end(); ++it) { RegistryType_Entry & entry = *it; @@ -373,7 +414,7 @@ void FactoryRegistry_i::unregister_factory_by_location ( for (size_t nHit = 0; nHit < hitList.size(); ++nHit) { PortableGroup::FactoryInfos * infos; - if (registry_.unbind(hitList[nHit], infos) ) + if (this->registry_.unbind(hitList[nHit], infos) ) { delete infos; } @@ -406,7 +447,7 @@ void FactoryRegistry_i::unregister_factory_by_location ( } PortableGroup::FactoryInfos * typeInfos; - if (registry_.unbind(type_id, typeInfos) ) + if (this->registry_.unbind(type_id, typeInfos) ) { ACE_DEBUG(( LM_DEBUG, "unregister_factory_by_type found infos for %s", type_id @@ -424,7 +465,7 @@ void FactoryRegistry_i::unregister_factory_by_location ( { METHOD_ENTRY(FactoryRegistry_i::list_factories_by_location); ::PortableGroup::FactoryInfos_var infos; - ACE_NEW_NORETURN(infos, ::PortableGroup::FactoryInfos(registry_.current_size()) ); + ACE_NEW_NORETURN(infos, ::PortableGroup::FactoryInfos(this->registry_.current_size()) ); if (infos.ptr() == 0) { ACE_ERROR(( LM_ERROR, @@ -436,8 +477,8 @@ void FactoryRegistry_i::unregister_factory_by_location ( size_t count = 0; // iterate through the registery - for (RegistryType_Iterator it = registry_.begin(); - it != registry_.end(); + for (RegistryType_Iterator it = this->registry_.begin(); + it != this->registry_.end(); ++it) { RegistryType_Entry & entry = *it; diff --git a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h b/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h index 58d5f2c8ca6..9d3a81ab9f9 100644 --- a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h +++ b/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h @@ -69,7 +69,7 @@ public: * @param orbManager our ORB -- we keep var to it. * @return zero for success; nonzero is process return code for failure. */ - int init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL_WITH_DEFAULTS); + int init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL); /** * Prepare to exit. @@ -160,13 +160,23 @@ private: ACE_Mutex internals_; typedef ACE_Guard<ACE_Mutex> InternalGuard; - TAO_ORB_Manager * orbManager_; /** - * The orb + * The orb */ CORBA::ORB_var orb_; /** + * The POA used to activate this object. + */ + PortableServer::POA_var poa_; + + /** + * The CORBA object id assigned to this object. + */ + PortableServer::ObjectId_var object_id_; + + + /** * IOR of this object as assigned by poa. */ CORBA::String_var ior_; @@ -174,12 +184,12 @@ private: /** * A file to which the factory's IOR should be written. */ - const char * iorOutputFile; + const char * ior_output_file_; /** * A name to be used to register the factory with the name service. */ - const char * nsName_; + const char * ns_name_; CosNaming::NamingContext_var naming_context_; @@ -188,12 +198,12 @@ private: /** * Quit on idle flag. */ - int quitOnIdle_; + int quit_on_idle_; /** * boolean: starts false. Set to true when it's time to quit. */ - int quitRequested_; + int quit_requested_; RegistryType registry_; diff --git a/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.cpp b/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.cpp index 743c80625aa..4b3bbec4533 100644 --- a/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.cpp +++ b/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.cpp @@ -25,28 +25,70 @@ int StubBatchConsumer::parse_args (int argc, char * argv[]) return optionError; } + +::PortableServer::POA_ptr StubBatchConsumer::_default_POA (ACE_ENV_SINGLE_ARG_DECL) +{ + return ::PortableServer::POA::_duplicate(this->poa_ ACE_ENV_ARG_PARAMETER); +} + +PortableServer::ObjectId StubBatchConsumer::objectId()const +{ + return this->objectId_.in(); +} + + /** * register this object */ -int StubBatchConsumer::init (TAO_ORB_Manager & orbManager, - ::FT::FaultNotifier_var & notifier - ACE_ENV_ARG_DECL) +int StubBatchConsumer::init (CORBA::ORB_var & orb, ::FT::FaultNotifier_var & notifier ACE_ENV_ARG_DECL) { int result = 0; - orb_ = orbManager.orb(); + this->orb_ = orb; - notifier_ = notifier; + // Use the ROOT POA for now + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")), + -1); + + // Get the POA object. + this->poa_ = + PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); - // Register with the ORB. - ior_ = orbManager.activate (this - ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); - identity_ = "StubBatchConsumer"; + if (CORBA::is_nil(this->poa_)) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")), + -1); + } + + PortableServer::POAManager_var poa_manager = + this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Register with the POA. + + this->objectId_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->notifier_ = notifier; + + this->identity_ = "StubBatchConsumer"; CosNotifyFilter::Filter_var filter = CosNotifyFilter::Filter::_nil(); - consumerId_ = notifier->connect_sequence_fault_consumer( + this->consumerId_ = notifier->connect_sequence_fault_consumer( _this(), filter); @@ -58,7 +100,7 @@ int StubBatchConsumer::init (TAO_ORB_Manager & orbManager, */ const char * StubBatchConsumer::identity () const { - return identity_.c_str(); + return this->identity_.c_str(); } /** @@ -66,14 +108,14 @@ const char * StubBatchConsumer::identity () const */ void StubBatchConsumer::fini (ACE_ENV_SINGLE_ARG_DECL) { - notifier_->disconnect_consumer(consumerId_ ACE_ENV_ARG_PARAMETER); + this->notifier_->disconnect_consumer(this->consumerId_ ACE_ENV_ARG_PARAMETER); } int StubBatchConsumer::idle(int & result) { ACE_UNUSED_ARG(result); - return quit_; + return this->quit_; } //////////////// @@ -117,7 +159,7 @@ void StubBatchConsumer::disconnect_sequence_push_consumer ( ACE_ERROR ((LM_ERROR, "StubBatchConsumer:disconnect_sequence_push_consumer interpreted as quit request.\n" )); - quit_ = 1; + this->quit_ = 1; } #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) diff --git a/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.h b/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.h index c33f5c96cbc..a2ecde5b714 100644 --- a/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.h +++ b/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.h @@ -12,7 +12,6 @@ ////////////////////// // Forward references -class TAO_ORB_Manager; ///////////////////// // Class declarations @@ -34,6 +33,9 @@ public: */ virtual ~StubBatchConsumer (); + ::PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL); + ::PortableServer::ObjectId objectId()const; + /** * Parse command line arguments. */ @@ -42,10 +44,7 @@ public: /** * Publish this objects IOR. */ - int init ( - TAO_ORB_Manager & orbManager, - ::FT::FaultNotifier_var & notifier - ACE_ENV_ARG_DECL); + int init (CORBA::ORB_var & orbManager, ::FT::FaultNotifier_var & notifier ACE_ENV_ARG_DECL); /** * Return a string to identify this object for logging/console message purposes. @@ -107,14 +106,19 @@ private: // Data Members private: /** - * The orb + * The orb */ CORBA::ORB_var orb_; /** - * IOR of this object as assigned by orb. + * The POA used to activate this object. + */ + PortableServer::POA_var poa_; + + /** + * The CORBA object id assigned to this object. */ - CORBA::String_var ior_; + PortableServer::ObjectId_var objectId_; /** * A human-readable string to distinguish this from other FaultConsumers. diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp b/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp index 5eac532ee7c..ec9ba25d4a2 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp +++ b/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp @@ -35,24 +35,24 @@ int StubFaultAnalyzer::parse_args (int argc, char * argv[]) { case 'r': { - if (replicaIorBuffer_ == 0) + if (this->replicaIorBuffer_ == 0) { const char * repNames = get_opts.opt_arg (); size_t repNameLen = ACE_OS::strlen(repNames); // make a working copy of the string - ACE_NEW_NORETURN(replicaIorBuffer_, + ACE_NEW_NORETURN(this->replicaIorBuffer_, char[repNameLen + 1]); - if ( replicaIorBuffer_ != 0) + if ( this->replicaIorBuffer_ != 0) { - ACE_OS::memcpy(replicaIorBuffer_, repNames, repNameLen+1); + ACE_OS::memcpy(this->replicaIorBuffer_, repNames, repNameLen+1); // tokenize the string on ',' // into iorReplicaFiles_ - char * pos = replicaIorBuffer_; + char * pos = this->replicaIorBuffer_; while (pos != 0) { - iorReplicaFiles_.push_back(pos); + this->iorReplicaFiles_.push_back(pos); // find a comma delimiter, and // chop the string there. pos = ACE_OS::strchr (pos, ','); @@ -82,17 +82,17 @@ int StubFaultAnalyzer::parse_args (int argc, char * argv[]) } case 'd': { - iorDetectorFile_ = get_opts.opt_arg (); + this->iorDetectorFile_ = get_opts.opt_arg (); break; } case 'n': { - iorNotifierFile_ = get_opts.opt_arg (); + this->iorNotifierFile_ = get_opts.opt_arg (); break; } case 'o': { - readyFile_ = get_opts.opt_arg (); + this->readyFile_ = get_opts.opt_arg (); break; } @@ -107,21 +107,21 @@ int StubFaultAnalyzer::parse_args (int argc, char * argv[]) if(! optionError) { - if (0 == replicaIorBuffer_) + if (0 == this->replicaIorBuffer_) { ACE_ERROR ((LM_ERROR, "-r option is required.\n" )); optionError = -1; } - if (0 == iorDetectorFile_) + if (0 == this->iorDetectorFile_) { ACE_ERROR ((LM_ERROR, "-d option is required.\n" )); optionError = -1; } - if (0 == iorNotifierFile_) + if (0 == this->iorNotifierFile_) { ACE_ERROR ((LM_ERROR, "-n option is required.\n" @@ -148,46 +148,45 @@ int StubFaultAnalyzer::parse_args (int argc, char * argv[]) /** * Register this object as necessary */ -int StubFaultAnalyzer::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) +int StubFaultAnalyzer::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) { int result = 0; - orb_ = orbManager.orb(); - + this->orb_ = orb; ////////////////////////////////////////// // resolve reference to detector factory CORBA::String_var factoryIOR; - if (readIORFile(iorDetectorFile_, factoryIOR)) + if (readIORFile(this->iorDetectorFile_, factoryIOR)) { - CORBA::Object_var obj = orb_->string_to_object(factoryIOR); - factory_ = ::FT::FaultDetectorFactory::_narrow(obj); - if (CORBA::is_nil(factory_)) + CORBA::Object_var obj = this->orb_->string_to_object(factoryIOR); + this->factory_ = ::FT::FaultDetectorFactory::_narrow(obj); + if (CORBA::is_nil(this->factory_)) { - std::cerr << "Can't resolve Detector Factory IOR " << iorDetectorFile_ << std::endl; + std::cerr << "Can't resolve Detector Factory IOR " << this->iorDetectorFile_ << std::endl; result = -1; } } else { - std::cerr << "Can't read " << iorDetectorFile_ << std::endl; + std::cerr << "Can't read " << this->iorDetectorFile_ << std::endl; result = -1; } ////////////////////////////////////////// // resolve references to notifier CORBA::String_var notifierIOR; - if (readIORFile(iorNotifierFile_, notifierIOR)) + if (readIORFile(this->iorNotifierFile_, notifierIOR)) { - CORBA::Object_var obj = orb_->string_to_object(notifierIOR); - notifier_ = ::FT::FaultNotifier::_narrow(obj); - if (CORBA::is_nil(notifier_)) + CORBA::Object_var obj = this->orb_->string_to_object(notifierIOR); + this->notifier_ = ::FT::FaultNotifier::_narrow(obj); + if (CORBA::is_nil(this->notifier_)) { - std::cerr << "Can't resolve Notifier IOR " << iorNotifierFile_ << std::endl; + std::cerr << "Can't resolve Notifier IOR " << this->iorNotifierFile_ << std::endl; result = -1; } } else { - std::cerr << "Can't read " << iorNotifierFile_ << std::endl; + std::cerr << "Can't read " << this->iorNotifierFile_ << std::endl; result = -1; } @@ -196,12 +195,12 @@ int StubFaultAnalyzer::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) // register fault consumers if (result == 0) { - result = faultConsumer_.init(orbManager, notifier_); + result = this->faultConsumer_.init(orb, this->notifier_); } if (result == 0) { - result = batchConsumer_.init(orbManager, notifier_); + result = this->batchConsumer_.init(orb, this->notifier_); } ///////////////////////// @@ -211,14 +210,14 @@ int StubFaultAnalyzer::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) //////////////////////////////////// // resolve references to replicas // create a fault detector for each replica - size_t replicaCount = iorReplicaFiles_.size(); + size_t replicaCount = this->iorReplicaFiles_.size(); for(size_t nRep = 0; result == 0 && nRep < replicaCount; ++nRep) { - const char * iorName = iorReplicaFiles_[nRep]; + const char * iorName = this->iorReplicaFiles_[nRep]; CORBA::String_var ior; if (readIORFile(iorName, ior)) { - CORBA::Object_var obj = orb_->string_to_object(ior); + CORBA::Object_var obj = this->orb_->string_to_object(ior); FT::PullMonitorable_var replica = FT::PullMonitorable::_narrow(obj); if (CORBA::is_nil(replica)) { @@ -227,14 +226,14 @@ int StubFaultAnalyzer::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) } else { - replicas_.push_back(replica); + this->replicas_.push_back(replica); CORBA::String_var type_id = CORBA::string_dup("FaultDetector"); TAO_PG::Properties_Encoder encoder; PortableGroup::Value value; - value <<= notifier_; + value <<= this->notifier_; encoder.add(::FT::FT_NOTIFIER, value); value <<= replica; @@ -274,7 +273,7 @@ int StubFaultAnalyzer::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) encoder.encode(criteria); FT::GenericFactory::FactoryCreationId_var factory_creation_id; - factory_->create_object ( + this->factory_->create_object ( type_id.in(), criteria.in(), factory_creation_id @@ -290,9 +289,9 @@ int StubFaultAnalyzer::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) } } - if (result == 0 && readyFile_ != 0) + if (result == 0 && this->readyFile_ != 0) { - std::ofstream ready(readyFile_, ios::out); + std::ofstream ready(this->readyFile_, ios::out); ready << "ready" << std::endl; ready.close(); } @@ -306,7 +305,7 @@ int StubFaultAnalyzer::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) */ const char * StubFaultAnalyzer::identity () const { - return identity_.c_str(); + return this->identity_.c_str(); } /** @@ -314,8 +313,8 @@ const char * StubFaultAnalyzer::identity () const */ int StubFaultAnalyzer::fini (ACE_ENV_SINGLE_ARG_DECL) { - faultConsumer_.fini(ACE_ENV_SINGLE_ARG_PARAMETER); - batchConsumer_.fini(ACE_ENV_SINGLE_ARG_PARAMETER); + this->faultConsumer_.fini(ACE_ENV_SINGLE_ARG_PARAMETER); + this->batchConsumer_.fini(ACE_ENV_SINGLE_ARG_PARAMETER); return 0; } @@ -325,7 +324,7 @@ int StubFaultAnalyzer::idle(int & result) ACE_UNUSED_ARG(result); int quit = 0; - if (replicas_.size() == faultConsumer_.notifications()) + if (this->replicas_.size() == this->faultConsumer_.notifications()) { quit = 1; } diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.h b/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.h index ee2635f7fce..425fff60165 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.h +++ b/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.h @@ -16,7 +16,6 @@ ////////////////////// // Forward references -class TAO_ORB_Manager; ///////////////////// // Class declarations @@ -45,7 +44,7 @@ public: /** * Initialize this object */ - int init (TAO_ORB_Manager & orbManager); + int init (CORBA::ORB_var & orb); /** * Return a string to identify this object for logging/console message purposes. @@ -74,14 +73,19 @@ private: // Data Members private: /** - * The orb + * The orb */ CORBA::ORB_var orb_; /** - * IOR of this object as assigned by orb. + * The POA used to activate this object. */ - CORBA::String_var ior_; + PortableServer::POA_var poa_; + + /** + * The CORBA object id assigned to this object. + */ + PortableServer::ObjectId_var objectId_; /** * A human-readable string to distinguish this from other Notifiers. diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp b/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp index 083c1643daa..2447a62f68e 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp +++ b/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp @@ -18,9 +18,19 @@ StubFaultConsumer::~StubFaultConsumer () { } +::PortableServer::POA_ptr StubFaultConsumer::_default_POA (ACE_ENV_SINGLE_ARG_DECL) +{ + return ::PortableServer::POA::_duplicate(this->poa_ ACE_ENV_ARG_PARAMETER); +} + +PortableServer::ObjectId StubFaultConsumer::objectId()const +{ + return this->objectId_.in(); +} + size_t StubFaultConsumer::notifications () const { - return notifications_; + return this->notifications_; } @@ -36,24 +46,24 @@ int StubFaultConsumer::parse_args (int argc, char * argv[]) { case 'r': { - if (replicaIorBuffer_ == 0) + if (this->replicaIorBuffer_ == 0) { const char * repNames = get_opts.opt_arg (); size_t repNameLen = ACE_OS::strlen(repNames); // make a working copy of the string - ACE_NEW_NORETURN(replicaIorBuffer_, + ACE_NEW_NORETURN(this->replicaIorBuffer_, char[repNameLen + 1]); - if ( replicaIorBuffer_ != 0) + if ( this->replicaIorBuffer_ != 0) { - ACE_OS::memcpy(replicaIorBuffer_, repNames, repNameLen+1); + ACE_OS::memcpy(this->replicaIorBuffer_, repNames, repNameLen+1); // tokenize the string on ',' // into iorReplicaFiles_ - char * pos = replicaIorBuffer_; + char * pos = this->replicaIorBuffer_; while (pos != 0) { - iorReplicaFiles_.push_back(pos); + this->iorReplicaFiles_.push_back(pos); // find a comma delimiter, and // chop the string there. pos = ACE_OS::strchr (pos, ','); @@ -83,17 +93,17 @@ int StubFaultConsumer::parse_args (int argc, char * argv[]) } case 'd': { - iorDetectorFile_ = get_opts.opt_arg (); + this->iorDetectorFile_ = get_opts.opt_arg (); break; } case 'n': { - nsName_ = get_opts.opt_arg (); + this->nsName_ = get_opts.opt_arg (); break; } case 'o': { - iorOutputFile_ = get_opts.opt_arg (); + this->iorOutputFile_ = get_opts.opt_arg (); break; } @@ -108,14 +118,14 @@ int StubFaultConsumer::parse_args (int argc, char * argv[]) if(! optionError) { - if (0 == replicaIorBuffer_) + if (0 == this->replicaIorBuffer_) { ACE_ERROR ((LM_ERROR, "-r option is required.\n" )); optionError = -1; } - if (0 == iorDetectorFile_) + if (0 == this->iorDetectorFile_) { ACE_ERROR ((LM_ERROR, "-d option is required.\n" @@ -143,25 +153,56 @@ int StubFaultConsumer::parse_args (int argc, char * argv[]) /** * Register this object. */ -int StubFaultConsumer::init (TAO_ORB_Manager & orbManager, +int StubFaultConsumer::init (CORBA::ORB_var & orb, ::FT::FaultNotifier_var & notifier ACE_ENV_ARG_DECL) { int result = 0; - orb_ = orbManager.orb(); + this->orb_ = orb; + + // Use the ROOT POA for now + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); - notifier_ = notifier; + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")), + -1); + + // Get the POA object. + this->poa_ = + PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); - // Register with the ORB. - ior_ = orbManager.activate (this - ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); + if (CORBA::is_nil(this->poa_)) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")), + -1); + } + + PortableServer::POAManager_var poa_manager = + this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Register with the POA. + + this->objectId_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->notifier_ = notifier; - identity_ = "StubFaultConsumer"; + this->identity_ = "StubFaultConsumer"; CosNotifyFilter::Filter_var filter = CosNotifyFilter::Filter::_nil(); - consumerId_ = notifier->connect_structured_fault_consumer( + this->consumerId_ = notifier->connect_structured_fault_consumer( _this(), filter); @@ -173,7 +214,7 @@ int StubFaultConsumer::init (TAO_ORB_Manager & orbManager, */ const char * StubFaultConsumer::identity () const { - return identity_.c_str(); + return this->identity_.c_str(); } /** @@ -181,7 +222,7 @@ const char * StubFaultConsumer::identity () const */ int StubFaultConsumer::fini (ACE_ENV_SINGLE_ARG_DECL) { - notifier_->disconnect_consumer(consumerId_ ACE_ENV_ARG_PARAMETER); + this->notifier_->disconnect_consumer(this->consumerId_ ACE_ENV_ARG_PARAMETER); return 0; } @@ -189,7 +230,7 @@ int StubFaultConsumer::fini (ACE_ENV_SINGLE_ARG_DECL) int StubFaultConsumer::idle(int & result) { ACE_UNUSED_ARG(result); - return quit_; + return this->quit_; } //////////////// @@ -202,13 +243,13 @@ void StubFaultConsumer::push_structured_event( { //////////////////////////////////////// // keep track of how many we've received - notifications_ += 1; + this->notifications_ += 1; ACE_ERROR ((LM_ERROR, "FaultConsumer: Received Fault notification(%d):\n" "FaultConsumer: Header EventType domain: %s\n" "FaultConsumer: Header EventType type: %s\n" "FaultConsumer: Header EventName: %s\n", - ACE_static_cast (unsigned int, notifications_), + ACE_static_cast (unsigned int, this->notifications_), ACE_static_cast (const char *, notification.header.fixed_header.event_type.domain_name), ACE_static_cast (const char *, notification.header.fixed_header.event_type.type_name), ACE_static_cast (const char *, notification.header.fixed_header.event_name) @@ -246,7 +287,7 @@ void StubFaultConsumer::disconnect_structured_push_consumer(ACE_ENV_SINGLE_ARG_D ACE_ERROR ((LM_ERROR, "StubFaultConsumer:disconnect_structured_push_consumer interpreted as quit request.\n" )); - quit_ = 1; + this->quit_ = 1; } #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.h b/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.h index 266c3489c21..9e451af6010 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.h +++ b/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.h @@ -12,7 +12,6 @@ ////////////////////// // Forward references -class TAO_ORB_Manager; ///////////////////// // Class declarations @@ -34,6 +33,10 @@ public: */ virtual ~StubFaultConsumer (); + + ::PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL); + ::PortableServer::ObjectId objectId()const; + /** * Parse command line arguments. */ @@ -42,9 +45,7 @@ public: /** * Publish this objects IOR. */ - int init ( - TAO_ORB_Manager & orbManager, - ::FT::FaultNotifier_var & notifier + int init (CORBA::ORB_var & orb, ::FT::FaultNotifier_var & notifier ACE_ENV_ARG_DECL); /** @@ -101,14 +102,20 @@ private: // Data Members private: /** - * The orb + * The orb */ CORBA::ORB_var orb_; /** - * IOR of this object as assigned by orb. + * The POA used to activate this object. + */ + PortableServer::POA_var poa_; + + /** + * The CORBA object id assigned to this object. */ - CORBA::String_var ior_; + PortableServer::ObjectId_var objectId_; + /** * A human-readable string to distinguish this from other FaultConsumers. diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.cpp b/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.cpp index d753c39f8ad..ec57b9f08c9 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.cpp +++ b/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.cpp @@ -19,11 +19,25 @@ StubFaultNotifier::StubFaultNotifier () StubFaultNotifier::~StubFaultNotifier () { - delete [] replicaIorBuffer_; - replicaIorBuffer_ = 0; + delete [] this->replicaIorBuffer_; + this->replicaIorBuffer_ = 0; } +::PortableServer::POA_ptr StubFaultNotifier::_default_POA (ACE_ENV_SINGLE_ARG_DECL) +{ + return ::PortableServer::POA::_duplicate(this->poa_ ACE_ENV_ARG_PARAMETER); +} + +PortableServer::ObjectId StubFaultNotifier::objectId()const +{ + return this->objectId_.in(); +} + + + + + int StubFaultNotifier::parse_args (int argc, char * argv[]) { int optionError = 0; @@ -35,24 +49,24 @@ int StubFaultNotifier::parse_args (int argc, char * argv[]) { case 'r': { - if (replicaIorBuffer_ == 0) + if (this->replicaIorBuffer_ == 0) { const char * repNames = get_opts.opt_arg (); size_t repNameLen = ACE_OS::strlen(repNames); // make a working copy of the string - ACE_NEW_NORETURN(replicaIorBuffer_, + ACE_NEW_NORETURN(this->replicaIorBuffer_, char[repNameLen + 1]); - if ( replicaIorBuffer_ != 0) + if ( this->replicaIorBuffer_ != 0) { - ACE_OS::memcpy(replicaIorBuffer_, repNames, repNameLen+1); + ACE_OS::memcpy(this->replicaIorBuffer_, repNames, repNameLen+1); // tokenize the string on ',' // into iorReplicaFiles_ - char * pos = replicaIorBuffer_; + char * pos = this->replicaIorBuffer_; while (pos != 0) { - iorReplicaFiles_.push_back(pos); + this->iorReplicaFiles_.push_back(pos); // find a comma delimiter, and // chop the string there. pos = ACE_OS::strchr (pos, ','); @@ -82,17 +96,17 @@ int StubFaultNotifier::parse_args (int argc, char * argv[]) } case 'd': { - iorDetectorFile_ = get_opts.opt_arg (); + this->iorDetectorFile_ = get_opts.opt_arg (); break; } case 'n': { - nsName_ = get_opts.opt_arg (); + this->nsName_ = get_opts.opt_arg (); break; } case 'o': { - iorOutputFile_ = get_opts.opt_arg (); + this->iorOutputFile_ = get_opts.opt_arg (); break; } @@ -107,14 +121,14 @@ int StubFaultNotifier::parse_args (int argc, char * argv[]) if(! optionError) { - if (0 == replicaIorBuffer_) + if (0 == this->replicaIorBuffer_) { ACE_ERROR ((LM_ERROR, "-r option is required.\n" )); optionError = -1; } - if (0 == iorDetectorFile_) + if (0 == this->iorDetectorFile_) { ACE_ERROR ((LM_ERROR, "-d option is required.\n" @@ -143,12 +157,12 @@ int StubFaultNotifier::parse_args (int argc, char * argv[]) */ int StubFaultNotifier::fini () { - if(nsName_ != 0) + if(this->nsName_ != 0) { ACE_TRY_NEW_ENV { CORBA::Object_var naming_obj = - orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); + this->orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; if (CORBA::is_nil(naming_obj.in ())){ @@ -163,7 +177,7 @@ int StubFaultNotifier::fini () CosNaming::Name this_name (1); this_name.length (1); - this_name[0].id = CORBA::string_dup (nsName_); + this_name[0].id = CORBA::string_dup (this->nsName_); naming_context->rebind (this_name, _this() ACE_ENV_ARG_PARAMETER); @@ -181,46 +195,78 @@ int StubFaultNotifier::fini () /** * Publish this objects IOR. */ -int StubFaultNotifier::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) +int StubFaultNotifier::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) { int result = 0; - orb_ = orbManager.orb(); + this->orb_ = orb; - // Register with the ORB. - ior_ = orbManager.activate (this - ACE_ENV_ARG_PARAMETER); + // Use the ROOT POA for now + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA + ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")), + -1); + + // Get the POA object. + this->poa_ = + PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); + + ACE_CHECK_RETURN (-1); + + if (CORBA::is_nil(this->poa_)) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")), + -1); + } + + PortableServer::POAManager_var poa_manager = + this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Register with the POA. + + this->objectId_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + ////////////////////////////////////////// // resolve references to detector factory CORBA::String_var factoryIOR; - if (readIORFile(iorDetectorFile_, factoryIOR)) + if (read_ior_file(this->iorDetectorFile_, factoryIOR)) { - CORBA::Object_var obj = orb_->string_to_object(factoryIOR); - factory_ = ::FT::FaultDetectorFactory::_narrow(obj); - if (CORBA::is_nil(factory_)) + CORBA::Object_var obj = this->orb_->string_to_object(factoryIOR); + this->factory_ = ::FT::FaultDetectorFactory::_narrow(obj); + if (CORBA::is_nil(this->factory_)) { - std::cerr << "Can't resolve Detector Factory IOR " << iorDetectorFile_ << std::endl; + std::cerr << "Can't resolve Detector Factory IOR " << this->iorDetectorFile_ << std::endl; result = -1; } } else { - std::cerr << "Can't read " << iorDetectorFile_ << std::endl; + std::cerr << "Can't read " << this->iorDetectorFile_ << std::endl; result = -1; } if (result == 0) { //////////////////////////////////// // resolve references to replicas - size_t replicaCount = iorReplicaFiles_.size(); + size_t replicaCount = this->iorReplicaFiles_.size(); for(size_t nRep = 0; result == 0 && nRep < replicaCount; ++nRep) { - const char * iorName = iorReplicaFiles_[nRep]; + const char * iorName = this->iorReplicaFiles_[nRep]; CORBA::String_var ior; - if (readIORFile(iorName, ior)) + if (read_ior_file(iorName, ior)) { - CORBA::Object_var obj = orb_->string_to_object(ior); + CORBA::Object_var obj = this->orb_->string_to_object(ior); FT::PullMonitorable_var replica = FT::PullMonitorable::_narrow(obj); if (CORBA::is_nil(replica)) { @@ -229,7 +275,7 @@ int StubFaultNotifier::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) } else { - replicas_.push_back(replica); + this->replicas_.push_back(replica); CORBA::String_var type_id = CORBA::string_dup("FaultDetector"); @@ -276,7 +322,7 @@ int StubFaultNotifier::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) encoder.encode(criteria); FT::GenericFactory::FactoryCreationId_var factory_creation_id; - factory_->create_object ( + this->factory_->create_object ( type_id.in(), criteria.in(), factory_creation_id @@ -292,26 +338,26 @@ int StubFaultNotifier::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) } } - if (iorOutputFile_ != 0) + if (this->iorOutputFile_ != 0) { - identity_ = "file:"; - identity_ += iorOutputFile_; - result = writeIORFile(); + this->identity_ = "file:"; + this->identity_ += this->iorOutputFile_; + result = write_ior_file(); } else { // if no IOR file specified, // then always try to register with name service - nsName_ = "FT_FaultNotifier"; + this->nsName_ = "FT_FaultNotifier"; } - if(nsName_ != 0) + if(this->nsName_ != 0) { - identity_ = "name:"; - identity_ += nsName_; + this->identity_ = "name:"; + this->identity_ += this->nsName_; CORBA::Object_var naming_obj = - orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); + this->orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; if (CORBA::is_nil(naming_obj.in ())){ @@ -326,7 +372,7 @@ int StubFaultNotifier::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) CosNaming::Name this_name (1); this_name.length (1); - this_name[0].id = CORBA::string_dup (nsName_); + this_name[0].id = CORBA::string_dup (this->nsName_); naming_context->rebind (this_name, _this() ACE_ENV_ARG_PARAMETER); @@ -336,7 +382,7 @@ int StubFaultNotifier::init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL) return result; } -int StubFaultNotifier::readIORFile(const char * fileName, CORBA::String_var & ior) +int StubFaultNotifier::read_ior_file(const char * fileName, CORBA::String_var & ior) { int result = 0; FILE *in = ACE_OS::fopen (fileName, "r"); @@ -360,13 +406,13 @@ int StubFaultNotifier::readIORFile(const char * fileName, CORBA::String_var & io return result; } -int StubFaultNotifier::writeIORFile() +int StubFaultNotifier::write_ior_file() { int result = -1; - FILE* out = ACE_OS::fopen (iorOutputFile_, "w"); + FILE* out = ACE_OS::fopen (this->iorOutputFile_, "w"); if (out) { - ACE_OS::fprintf (out, "%s", static_cast<const char *>(ior_)); + ACE_OS::fprintf (out, "%s", ACE_static_cast(const char *, this->ior_)); ACE_OS::fclose (out); result = 0; } @@ -378,7 +424,7 @@ int StubFaultNotifier::writeIORFile() */ const char * StubFaultNotifier::identity () const { - return identity_.c_str(); + return this->identity_.c_str(); } /** @@ -492,9 +538,9 @@ int StubFaultNotifier::idle(int & result) int quit = 0; ACE_TRY_NEW_ENV { - if(factory_.ptr() != 0 && !CORBA::is_nil(factory_)) + if(this->factory_.ptr() != 0 && !CORBA::is_nil(this->factory_)) { - if (!factory_->is_alive( ACE_ENV_SINGLE_ARG_PARAMETER)) + if (!this->factory_->is_alive( ACE_ENV_SINGLE_ARG_PARAMETER)) { quit = 1; } diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.h b/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.h index 6daeeb9c49a..cf2abdf77c8 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.h +++ b/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.h @@ -46,7 +46,7 @@ public: /** * Initialize. */ - int init (TAO_ORB_Manager & orbManager); + int init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL); /** * Prepare to exit. @@ -65,6 +65,12 @@ public: */ int idle(int &result); + // override virtuals +::PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL); + + PortableServer::ObjectId objectId()const; + + /** * Clean house for process shut down. */ @@ -120,8 +126,8 @@ public: ///////////////// // Implementation private: - int writeIORFile(); - int readIORFile(const char * fileName, CORBA::String_var & ior); + int write_ior_file(); + int read_ior_file(const char * fileName, CORBA::String_var & ior); /////////////// // Data Members @@ -132,7 +138,17 @@ private: CORBA::ORB_var orb_; /** - * IOR of this object as assigned by orb. + * The POA used to activate this object. + */ + PortableServer::POA_var poa_; + + /** + * The CORBA object id assigned to this object. + */ + PortableServer::ObjectId_var objectId_; + + /** + * IOR of this object as assigned by poa */ CORBA::String_var ior_; diff --git a/TAO/orbsvcs/tests/FT_App/run_test_notifier.pl b/TAO/orbsvcs/tests/FT_App/run_test_notifier.pl index 12beb068146..99e0b42ef8e 100755 --- a/TAO/orbsvcs/tests/FT_App/run_test_notifier.pl +++ b/TAO/orbsvcs/tests/FT_App/run_test_notifier.pl @@ -133,8 +133,8 @@ unlink $client_data; my($status) = 0; -my($REP1) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory1_ior -t $replica1_ior -r 1 -q"); -my($REP2) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory2_ior -t $replica2_ior -r 2 -q"); +my($REP1) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory1_ior -t $replica1_ior -l loc1 -i type1 -q"); +my($REP2) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory2_ior -t $replica2_ior -l loc2 -i type1 -q"); my($DET) = new PerlACE::Process ("$ENV{'TAO_ROOT'}/orbsvcs/Fault_Detector$build_directory/Fault_Detector", "-o $detector_ior -q"); my($NOT) = new PerlACE::Process ("$ENV{'TAO_ROOT'}/orbsvcs/Fault_Notifier$build_directory/Fault_Notifier", "-o $notifier_ior -v -q"); my($ANA) = new PerlACE::Process (".$build_directory/ft_analyzer", "-o $ready_file -n $notifier_ior -q -d $detector_ior -r $replica1_ior,$replica2_ior"); @@ -216,35 +216,35 @@ if ($client != 0) { } print "\nTEST: wait for replica 1.\n" if ($verbose); -$replica1 = $REP1->WaitKill (60); +$replica1 = $REP1->WaitKill (5); if ($replica1 != 0) { print STDERR "ERROR: replica returned $replica1\n"; $status = 1; } print "\nTEST: wait for replica 2.\n" if ($verbose); -$replica2 = $REP2->WaitKill (60); +$replica2 = $REP2->WaitKill (5); if ($replica2 != 0) { print STDERR "ERROR: replica returned $replica2\n"; $status = 1; } print "\nTEST: wait for detector factory to leave.\n" if ($verbose); -$detector = $DET->WaitKill (60); +$detector = $DET->WaitKill (20); if ($detector != 0) { print STDERR "ERROR: detector returned $detector\n"; $status = 1; } print "\nTEST: wait for notifier to leave.\n" if ($verbose); -$notifier = $NOT->WaitKill (60); +$notifier = $NOT->WaitKill (20); if ($notifier != 0) { print STDERR "ERROR: notifier returned $notifier\n"; $status = 1; } print "\nTEST: wait for analyzer to leave.\n" if ($verbose); -$analyzer = $ANA->WaitKill (60); +$analyzer = $ANA->WaitKill (20); if ($analyzer != 0) { print STDERR "ERROR: analyzer returned $analyzer\n"; $status = 1; diff --git a/TAO/tao/Utils/Server_Main.cpp b/TAO/tao/Utils/Server_Main.cpp new file mode 100644 index 00000000000..9134023a08e --- /dev/null +++ b/TAO/tao/Utils/Server_Main.cpp @@ -0,0 +1,121 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file Server_Main.cpp + * + * $Id$ + * + * Implements a generic object that acts as "main" for a CORBA server. + * + * @author Dale Wilson <wilson_d@ociweb.com> + */ +//============================================================================= +// +#ifndef TAO_UTILS_SERVER_MAIN_T_CPP +#define TAO_UTILS_SERVER_MAIN_T_CPP + +#include "Server_Main.h" +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +ACE_RCSID(Utils, Server_Main, "$Id$") + +#include <ace/Argv_Type_Converter.h> +#include <tao/ORB.h> + +template <typename SERVANT> +TAO::Utils::Server_Main<SERVANT>::Server_Main(const char * name) + : name_(name) +{ +} + +template <typename SERVANT> +TAO::Utils::Server_Main<SERVANT>::~Server_Main() +{ +} + +template <typename SERVANT> +int TAO::Utils::Server_Main<SERVANT>::run (int argc, ACE_TCHAR *argv[]) +{ + int result = 0; + // hide unicode if necessary. + ACE_Argv_Type_Converter command_line(argc, argv); + + char ** asciiArgv = command_line.get_ASCII_argv(); + + ACE_TRY_NEW_ENV + { + // Initialize the orb + + CORBA::ORB_var orb = CORBA::ORB_init(argc, asciiArgv, name_ ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + if(! CORBA::is_nil(orb)) + { + // create an instance of the servant object and give it a + // chance at the arguments. + SERVANT servant; + result = servant.parse_args (argc, asciiArgv); + if (result == 0) + { + ////////////////////////////////// + // let the servant register itself + result = servant.init(orb); + if (result == 0) + { + ACE_ERROR ((LM_INFO, + "%T %s (%P|%t) Ready %s\n", name_, servant.identity() + )); + + ////////////////////////////////// + // Run the event loop for the ORB. + // Initial run to initialize the orb + ACE_Time_Value tv(1,0); + orb->run (tv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // now run event loop + int quit = 0; + while (result == 0 && ! quit ) + { + ACE_Time_Value work_tv(1,0); + orb->perform_work(work_tv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + quit = servant.idle(result); + } + servant.fini(ACE_ENV_SINGLE_ARG_PARAMETER); + + orb->shutdown(1 ACE_ENV_ARG_PARAMETER); + + ACE_ERROR ((LM_INFO, + "%T %s (%P|%t) Terminated normally. %s\n", name_, servant.identity() + )); + } + else + { + ACE_ERROR ((LM_ERROR, + "%T %s (%P|%t) Registration failed: %p\n", name_ + )); + result = -1; + } + } + else + { + ACE_ERROR ((LM_ERROR, + "%T %s (%P|%t) ORB manager init failed\n", name_ + )); + result = -1; + } + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + name_); + result = -1; + } + ACE_ENDTRY; + return result; +} + +#endif //TAO_UTILS_SERVER_MAIN_T_CPP diff --git a/TAO/tao/Utils/Server_Main.h b/TAO/tao/Utils/Server_Main.h new file mode 100644 index 00000000000..c9beb08557a --- /dev/null +++ b/TAO/tao/Utils/Server_Main.h @@ -0,0 +1,91 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file Server_Main.h + * + * $Id$ + * + * Declares a generic object that acts as "main" for a CORBA server. + * @author Dale Wilson <wilson_d@ociweb.com> + * + * This object supports creation of a relatively simple CORBA server. + * The object implements "main" for a process. + * A single servant is created and initialized as the process begins + * execution. The lifetime of this initial servant is the lifetime of + * the process. + * The servant is free to create other servants as necessary. + * The servant can capture command line options. + * A callback method in the ORB event loop allows the servant to act + * asynchronously if necessary. + * The callback method allows the servant to request process termination + * and specify the status to be returned from the process. + * + * The application should create a C/C++ main that looks something like: + * #include <tao/Utils/Server_Main.h> + * #include "Xyzzy_i.h" + * int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) + * { + * Server_Main<Xyzzy_i> servant ("Xyzzy"); + * return servant.run(argc, argv); + * } + * + * The servant implementation (Xyzzy_i in this case) must implement + * the following methods: + * Xyzzy_i (); // null constructor + * ~Xyzzy_i (); // destructor + * int parse_args (int argc, char * argv[]); + * int init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL_WITH_DEFAULTS); + * int idle(int &result); + * int fini (ACE_ENV_SINGLE_ARG_DECL); + * const char * identity () const; + * + * parse_args, self_register, self_unregister return 0 if ok, nonzero for error. + * idle returns 0 to continue execution; nonzero to exit -- returning "result" from the process + * identity provides a string to identify this servant in log messages. + * + */ +//============================================================================= + +#ifndef TAO_UTILS_SERVANTMAIN_H +#define TAO_UTILS_SERVANTMAIN_H + +#include <ace/ACE.h> +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include /**/ <ace/pre.h> +namespace TAO +{ + namespace Utils + { + template <typename SERVANT> + class Server_Main + { + public: + Server_Main(const char * name); + ~Server_Main(); + + int run (int argc, ACE_TCHAR *argv[]); + + private: + Server_Main( const Server_Main &); + Server_Main & operator = (const Server_Main &); + + private: + const char * name_; + }; + } // namespace UTILS +} // namespace TAO + +#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) +# include "Server_Main.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ + +#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) +# pragma implementation "Server_Main.cpp" +#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ + +#include /**/ <ace/post.h> + +#endif //TAO_UTILS_SERVANTMAIN_H |