Exemple #1
0
 bool CFGManager::setProperty(const cfgPropertyStruct &_propertyS) {
   utils::MutexLocker locker(&mutexCFGParams);
   CFGParam *param = NULL;
   CFGProperty property;
   property.setParamId(_propertyS.paramId);
   property.setPropertyIndex(_propertyS.propertyIndex);
   property.setPropertyType(_propertyS.propertyType);
   switch (_propertyS.propertyType) {
   case boolProperty:
     property.setValue(_propertyS.bValue);
     break;
   case doubleProperty:
     property.setValue(_propertyS.dValue);
     break;
   case intProperty:
     property.setValue(_propertyS.iValue);
     break;
   case stringProperty:
     property.setValue(_propertyS.sValue);
     break;
   default:
     return false;
   } // switch
   if( getParam(&param, _propertyS.paramId) ) {
     return param->setProperty(property);
   } else {
     return false;
   }
 }
Exemple #2
0
 bool CFGParam::getProperty(CFGProperty *property) const {
   unsigned int state = property->getState();
   if( (state & CFGProperty::allSetButValue) == CFGProperty::allSetButValue ) {
     CFGProperty *tmpProperty = propertys.at(property->getPropertyIndex());
     if( tmpProperty->isSameAs(*property) && tmpProperty->isValueSet() ) {
       double dValue = 0.0;
       int iValue = 0;
       bool bValue = false;
       string sValue = "";
       switch( property->getPropertyType() ) {
       case doubleProperty:
         tmpProperty->getValue(&dValue);
         property->setValue(dValue);
         break;
       case intProperty:
         tmpProperty->getValue(&iValue);
         property->setValue(iValue);
         break;
       case boolProperty:
         tmpProperty->getValue(&bValue);
         property->setValue(bValue);
         break;
       case stringProperty:
         tmpProperty->getValue(&sValue);
         property->setValue(sValue);
         break;
       default:
         return false;
       } //switch
       return true;
     } //if
   } //if
   return false;
 }
Exemple #3
0
 bool CFGManager::setProperty(const CFGProperty &_property) {
   utils::MutexLocker locker(&mutexCFGParams);
   CFGParam *param = NULL;
   if( getParam(&param, _property.getParamId()) ) {
     return param->setProperty(_property);
   } else {
     return false;
   }
 }
Exemple #4
0
    void CFGParam::updateClients(const CFGProperty &property) {
      vector<CFGClient*>::iterator iter;
      cfgPropertyStruct tmpS = property.getAsStruct();

      mutexCFGClients.lock();
      for(iter = cfgClients.begin(); iter != cfgClients.end(); ++iter) {
        (*iter)->cfgUpdateProperty(tmpS);
      }
      mutexCFGClients.unlock();
    }
Exemple #5
0
 bool CFGManager::getPropertyValue(cfgParamId paramId,
                                   const string &_propertyName,
                                   string *rValue) const {
   utils::MutexLocker locker(&mutexCFGParams);
   CFGParam *param = NULL;
   if( getParam(&param, paramId) ) {
     CFGProperty property;
     property.setParamId( paramId );
     property.setPropertyIndex( param->getPropertyIndexByName(_propertyName) );
     property.setPropertyType(stringProperty);
     if( getProperty(&property) ) {
       property.getValue(rValue);
       return true;
     } else {
       return false;
     }
   } else {
     return false;
   }
 }
Exemple #6
0
    void CFGParam::writeToYAML(YAML::Emitter &out) const {
      out << YAML::BeginMap;

      out << YAML::Key << "name";
      out << YAML::Value << paramName;

      out << YAML::Key << "type";
      out << YAML::Value << cfgParamTypeString[paramType];

      if (options & userSave) {
        out << YAML::Key << "userSave";
        out << YAML::Value << true;
      }

      if (options & saveOnClose) {
        out << YAML::Key << "saveOnClose";
        out << YAML::Value << true;
      }

      unsigned int i = 0;
      mutexPropertys.lock();
      for(i = 0; i < propertys.size(); ++i) {
        CFGProperty *prop = propertys.at(i);
        if(prop->isValueSet()) {
          out << YAML::Key << getPropertyNameByIndex(i);
          double dValue = 0.0;
          int iValue = 0;
          string sValue = "";
          bool bValue = false;
          switch (prop->getPropertyType()) {
          case intProperty:
            prop->getValue(&iValue);
            out << YAML::Value << iValue;
            break;
          case boolProperty:
            prop->getValue(&bValue);
            out << YAML::Value << bValue;
            break;
          case stringProperty:
            prop->getValue(&sValue);
            out << YAML::Value << sValue;
            break;
          case doubleProperty:
            prop->getValue(&dValue);
            out << YAML::Value << dValue;
            break;
          default:
            out << YAML::Value << "error";
            break;
          } //switch
        }
      }
      mutexPropertys.unlock();

      out << YAML::EndMap;
    }
Exemple #7
0
 bool CFGManager::setPropertyValue(const string &_group,
                                   const string &_name,
                                   const string &_propertyName,
                                   const string &rValue) {
   utils::MutexLocker locker(&mutexCFGParams);
   CFGParam *param = NULL;
   if( getParam(&param, _group, _name) ) {
     CFGProperty property;
     property.setParamId( param->getId() );
     property.setPropertyIndex( param->getPropertyIndexByName(_propertyName) );
     property.setPropertyType(stringProperty);
     property.setValue(rValue);
     if( setProperty(property) ) {
       return true;
     } else {
       return false;
     }
   } else {
     return false;
   }
 }
Exemple #8
0
    void CFGManager::insertParam(CFGParam *newParam) {
      mutexCFGParams.lock();
      cfgParamId id = newParam->getId();
      mapStringToParam::const_iterator iter;
      string stringID = newParam->getGroup() + ":" + newParam->getName();
      iter = cfgParamsByString.find(stringID);

      // is there already this param?
      if( iter != cfgParamsByString.end() ) {
        // then get the values of the properties and override the old ones
        CFGParam* oldParam = iter->second;
        unsigned int i = 0;
        for(i = 0; i < oldParam->getNrOfPropertys(); ++i) {
          CFGProperty myProperty;
          myProperty.setParamId(newParam->getId());
          myProperty.setPropertyIndex(i);
          myProperty.setPropertyType(newParam->getPropertyTypeByIndex(i));
          if( newParam->getProperty(&myProperty) ) {
            if( myProperty.isValueSet() ) {
              myProperty.changeParamId(oldParam->getId());
              oldParam->setProperty(myProperty);
            }
          } //if
        } //for
        // delete the new param which is no more needed
        deleteParam(newParam);
      } else {
        string stringId = newParam->getGroup() + ":" + newParam->getName();
        cfgParamsById.insert(pair<cfgParamId, CFGParam*>(id, newParam));
        cfgParamsByString.insert(pair<string, CFGParam*>(stringId, newParam));
      }
      mutexCFGParams.unlock();
    }