Example #1
0
void TinyConfig::AddEntry(const std::string & key, int val, bool uniq)
{
    iterator it = end();

    if(uniq &&
	(end() != (it = find(ModifyKey(key)))))
	it->second = GetString(val);
    else
	insert(std::pair<std::string, std::string>(ModifyKey(key), GetString(val)));
}
Example #2
0
bool ConfigurableImpl::RemoveParameter( const uint64 & actualKey ) {
    uint64 key = ModifyKey( actualKey );
    if ( mTreatKeyAsCaseInsensitiveCharBuffer )
        key = ConvertToLowerCase( key );
    AutoSharedLock lock( GetMutex(), true );
    bool returnValue = mMap.erase( key ) >= 1 ? true : false;
    return returnValue;
}
Example #3
0
IConfigurable::eDataType ConfigurableImpl::GetDataType( const uint64 & actualKey ) const {
    uint64 key = ModifyKey( actualKey );
    if ( mTreatKeyAsCaseInsensitiveCharBuffer )
        key = ConvertToLowerCase( key );
    AutoSharedLock lock( GetMutex() );
    auto it = mMap.find( key );
    if ( it == mMap.end() )
        return kDTNone;
    else
        return it->second.first;
}
Example #4
0
std::list<int> TinyConfig::ListInt(const std::string & key) const
{
    std::pair<const_iterator, const_iterator> ret = equal_range(ModifyKey(key));
    std::list<int> res;

    for(const_iterator
	it = ret.first; it != ret.second; ++it)
	res.push_back(GetInt(it->second));

    return res;
}
Example #5
0
//definition of class methods
void ConfigurableImpl::SetParameter( const uint64 & actualKey, eDataType type, const CombinedDataValue & value ) {
    uint64 key = ModifyKey( actualKey );
    if ( mTreatKeyAsCaseInsensitiveCharBuffer )
        key = ConvertToLowerCase( key );
    eConfigurableErrorCode validKey = ValidateKey( key );
    eDataType oldType = kDTNone;
    CombinedDataValue oldValue;
    if ( validKey == kCECNone ) {
        AutoSharedLock lock( GetMutex(), true );
        if ( mKeysSet ) {
            auto it = mKeysSet->find( key );
            if ( it == mKeysSet->end() )
                NotifyError( "Key is not supported", key, kCECKeyNotSupported, type, value, oldType, oldValue );
        }

        eConfigurableErrorCode validValue = ValidateValue( key, type, value );

        if ( validValue == kCECNone && mKeyValueTypeMap ) {
            auto it = mKeyValueTypeMap->find( key );
            if ( it != mKeyValueTypeMap->end() ) {
                if ( type != it->second ) {
                    validValue = kCECValueTypeNotSupported;
                }
            }
        }

        if ( validValue == kCECNone && !mAllowDifferentValueTypesForExistingEntries ) {
            auto it = mMap.find( key );
            if ( it != mMap.end() && it->second.first != type )
                validValue = kCECPreviousTypeDifferent;
        }

        if ( validValue == kCECNone ) {
            TypeValuePair pair;
            pair.first = type;
            pair.second = value;
            mMap[ key ] = pair;
        } else {
            auto it = mMap.find( key );
            if ( it != mMap.end() ) {
                oldType = it->second.first;
                oldValue = it->second.second;
            }
            NotifyError( "Validation failed for the parameter, type and value combination", key, validValue, type,
                         value, oldType, oldValue );
        }
    } else {
        NotifyError( "Key is not valid", key, validKey, type, value, oldType, oldValue );
    }
}
Example #6
0
void APICALL ConfigurableImpl::SetAllowedValueTypesForKeys( KeyValueTypePair * keyValueTypePairTable, sizet sizeOfTable ) {
    AutoSharedLock lock( GetMutex(), true );
    if ( mKeyValueTypeMap ) {
        delete mKeyValueTypeMap;
        mKeyValueTypeMap = NULL;
    }
    if ( sizeOfTable > 0 && keyValueTypePairTable != NULL ) {
        mKeyValueTypeMap = new keyValueTypeMap();
        for ( sizet i = 0; i < sizeOfTable; i++ ) {
            uint64 key = keyValueTypePairTable[i].first;
            key = ModifyKey( key );
            if ( mTreatKeyAsCaseInsensitiveCharBuffer )
                key = ConvertToLowerCase( key );
            ( *mKeyValueTypeMap )[ key ] = keyValueTypePairTable[i].second;
        }
    }
}
Example #7
0
void APICALL ConfigurableImpl::SetAllowedKeys( uint64 * keysTable, sizet sizeOfTable ) {
    AutoSharedLock lock ( GetMutex(), true );
    if ( mKeysSet ) {
        delete mKeysSet;
        mKeysSet = NULL;
    }
    if ( sizeOfTable > 0 && keysTable != NULL ) {
        mKeysSet = new KeysSet();
        for ( sizet i = 0; i < sizeOfTable; i++ ) {
            uint64 key = keysTable[ i ];
            key = ModifyKey( key );
            if ( mTreatKeyAsCaseInsensitiveCharBuffer )
                key = ConvertToLowerCase( key );
            mKeysSet->insert( key );
        }
    }
}
Example #8
0
bool ConfigurableImpl::GetParameter( const uint64 & actualKey, eDataType type, CombinedDataValue & value ) const {
    uint64 key = ModifyKey( actualKey );
    if ( mTreatKeyAsCaseInsensitiveCharBuffer )
        key = ConvertToLowerCase( key );
    AutoSharedLock lock( GetMutex() );
    auto it = mMap.find( key );
    if ( it == mMap.end() )
        return false;
    if ( it->second.first != type ) {
        NOTIFY_ERROR( IError_v1::kEDConfigurable, kCECValueTypeMismatch,
                      "Type mismatch for a parameter", IError_v1::kESOperationFatal,
                      true, key, true, static_cast< uint64 >( it->second.first ), true, static_cast< uint64 >( type ) );
        return false;
    }
    value = it->second.second;
    return true;
}
Example #9
0
bool TinyConfig::Exists(const std::string & key) const
{
    return end() != find(ModifyKey(key));
}
Example #10
0
std::string TinyConfig::StrParams(const std::string & key) const
{
    const_iterator it = find(ModifyKey(key));
    return it != end() ? it->second : "";
}
Example #11
0
int TinyConfig::IntParams(const std::string & key) const
{
    const_iterator it = find(ModifyKey(key));
    return it != end() ? GetInt(it->second) : 0;
}