diff options
Diffstat (limited to 'TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp')
-rw-r--r-- | TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp | 251 |
1 files changed, 78 insertions, 173 deletions
diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp b/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp index ec9ba25d4a2..ddcd925f5e2 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp +++ b/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp @@ -10,11 +10,9 @@ #include <fstream> StubFaultAnalyzer::StubFaultAnalyzer () - : replicaIorBuffer_(0) - , readyFile_(0) - , iorDetectorFile_(0) - , iorNotifierFile_(0) - + : readyFile_(0) + , detector_ior_(0) + , notifier_ior_(0) { } @@ -35,59 +33,17 @@ int StubFaultAnalyzer::parse_args (int argc, char * argv[]) { case 'r': { - 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(this->replicaIorBuffer_, - char[repNameLen + 1]); - if ( this->replicaIorBuffer_ != 0) - { - ACE_OS::memcpy(this->replicaIorBuffer_, repNames, repNameLen+1); - - // tokenize the string on ',' - // into iorReplicaFiles_ - char * pos = this->replicaIorBuffer_; - while (pos != 0) - { - this->iorReplicaFiles_.push_back(pos); - // find a comma delimiter, and - // chop the string there. - pos = ACE_OS::strchr (pos, ','); - if (pos != 0) - { - *pos = '\0'; - pos += 1; - } - } - } - else - { - ACE_ERROR ((LM_ERROR, - "Command line option error: -r can't allocate buffer.\n" - )); - optionError = -1; - } - } - else - { - ACE_ERROR ((LM_ERROR, - "Command line option error: -r specified more than once.\n" - )); - optionError = -1; - } + this->replicaIORs.push_back (get_opts.opt_arg ()); break; } case 'd': { - this->iorDetectorFile_ = get_opts.opt_arg (); + this->detector_ior_ = get_opts.opt_arg (); break; } case 'n': { - this->iorNotifierFile_ = get_opts.opt_arg (); + this->notifier_ior_ = get_opts.opt_arg (); break; } case 'o': @@ -107,21 +63,22 @@ int StubFaultAnalyzer::parse_args (int argc, char * argv[]) if(! optionError) { - if (0 == this->replicaIorBuffer_) + if (0 == replicaIORs.size()) { ACE_ERROR ((LM_ERROR, - "-r option is required.\n" + "at least one -r option is required.\n" )); optionError = -1; } - if (0 == this->iorDetectorFile_) + + if (0 == this->detector_ior_) { ACE_ERROR ((LM_ERROR, "-d option is required.\n" )); optionError = -1; } - if (0 == this->iorNotifierFile_) + if (0 == this->notifier_ior_) { ACE_ERROR ((LM_ERROR, "-n option is required.\n" @@ -154,39 +111,21 @@ int StubFaultAnalyzer::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) this->orb_ = orb; ////////////////////////////////////////// // resolve reference to detector factory - CORBA::String_var factoryIOR; - if (readIORFile(this->iorDetectorFile_, factoryIOR)) - { - 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 " << this->iorDetectorFile_ << std::endl; - result = -1; - } - } - else + CORBA::Object_var detector_obj = this->orb_->string_to_object(this->detector_ior_); + this->factory_ = ::FT::FaultDetectorFactory::_narrow(detector_obj); + if (CORBA::is_nil(this->factory_)) { - std::cerr << "Can't read " << this->iorDetectorFile_ << std::endl; + std::cerr << "Can't resolve Detector Factory IOR " << this->detector_ior_ << std::endl; result = -1; } ////////////////////////////////////////// // resolve references to notifier - CORBA::String_var notifierIOR; - if (readIORFile(this->iorNotifierFile_, notifierIOR)) - { - 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 " << this->iorNotifierFile_ << std::endl; - result = -1; - } - } - else + CORBA::Object_var not_obj = this->orb_->string_to_object(this->notifier_ior_); + this->notifier_ = ::FT::FaultNotifier::_narrow(not_obj); + if (CORBA::is_nil(this->notifier_)) { - std::cerr << "Can't read " << this->iorNotifierFile_ << std::endl; + std::cerr << "Can't resolve Notifier IOR " << this->notifier_ior_ << std::endl; result = -1; } @@ -210,83 +149,74 @@ int StubFaultAnalyzer::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) //////////////////////////////////// // resolve references to replicas // create a fault detector for each replica - size_t replicaCount = this->iorReplicaFiles_.size(); + size_t replicaCount = this->replicaIORs.size(); for(size_t nRep = 0; result == 0 && nRep < replicaCount; ++nRep) { - const char * iorName = this->iorReplicaFiles_[nRep]; - CORBA::String_var ior; - if (readIORFile(iorName, ior)) + const char * iorName = this->replicaIORs[nRep]; + CORBA::Object_var rep_obj = this->orb_->string_to_object(iorName); + FT::PullMonitorable_var replica = FT::PullMonitorable::_narrow(rep_obj); + if (CORBA::is_nil(replica)) { - CORBA::Object_var obj = this->orb_->string_to_object(ior); - FT::PullMonitorable_var replica = FT::PullMonitorable::_narrow(obj); - if (CORBA::is_nil(replica)) + std::cerr << "Can't resolve Replica IOR " << iorName << std::endl; + result = -1; + } + else + { + this->replicas_.push_back(replica); + + CORBA::String_var type_id = CORBA::string_dup("FaultDetector"); + + TAO_PG::Properties_Encoder encoder; + + PortableGroup::Value value; + value <<= this->notifier_; + encoder.add(::FT::FT_NOTIFIER, value); + + value <<= replica; + encoder.add(::FT::FT_MONITORABLE, value); + + FT::FTDomainId domain_id = 0; + value <<= domain_id; + encoder.add(::FT::FT_DOMAIN_ID, value); + + FT::Location object_location; + object_location.length(1); + object_location[0].id = CORBA::string_dup("Test location"); + value <<= object_location; + encoder.add(::FT::FT_LOCATION, value); + + FT::TypeId object_type = 0; + value <<= object_type; + encoder.add(::FT::FT_TYPE_ID, value); + + FT::ObjectGroupId group_id = 0; + value <<= group_id; + encoder.add(::FT::FT_GROUP_ID, value); + + // allocate and populate the criteria + FT::Criteria_var criteria; + ACE_NEW_NORETURN (criteria, + FT::Criteria); + if (criteria.ptr() == 0) { - std::cerr << "Can't resolve Replica IOR " << iorName << std::endl; - result = -1; + ACE_ERROR((LM_ERROR, + "Error cannot allocate criteria.\n" + )); + result = -1; } else { - this->replicas_.push_back(replica); - - CORBA::String_var type_id = CORBA::string_dup("FaultDetector"); - - TAO_PG::Properties_Encoder encoder; - - PortableGroup::Value value; - value <<= this->notifier_; - encoder.add(::FT::FT_NOTIFIER, value); - - value <<= replica; - encoder.add(::FT::FT_MONITORABLE, value); - - FT::FTDomainId domain_id = 0; - value <<= domain_id; - encoder.add(::FT::FT_DOMAIN_ID, value); - - FT::Location object_location; - object_location.length(1); - object_location[0].id = CORBA::string_dup("Test location"); - value <<= object_location; - encoder.add(::FT::FT_LOCATION, value); - - FT::TypeId object_type = 0; - value <<= object_type; - encoder.add(::FT::FT_TYPE_ID, value); - - FT::ObjectGroupId group_id = 0; - value <<= group_id; - encoder.add(::FT::FT_GROUP_ID, value); - - // allocate and populate the criteria - FT::Criteria_var criteria; - ACE_NEW_NORETURN (criteria, - FT::Criteria); - if (criteria.ptr() == 0) - { - ACE_ERROR((LM_ERROR, - "Error cannot allocate criteria.\n" - )); - result = -1; - } - else - { - encoder.encode(criteria); - FT::GenericFactory::FactoryCreationId_var factory_creation_id; - - this->factory_->create_object ( - type_id.in(), - criteria.in(), - factory_creation_id - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } + encoder.encode(criteria); + FT::GenericFactory::FactoryCreationId_var factory_creation_id; + + this->factory_->create_object ( + type_id.in(), + criteria.in(), + factory_creation_id + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; } } - else - { - std::cerr << "Can't read " << iorName << std::endl; - result = -1; - } } if (result == 0 && this->readyFile_ != 0) @@ -332,31 +262,6 @@ int StubFaultAnalyzer::idle(int & result) } -int StubFaultAnalyzer::readIORFile(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; -} - - #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) template instantiate ACE_Vector < const char * >; template ACE_Vector < FT::PullMonitorable_var > ; |