📄 configmanager.cpp
字号:
} return propertyOwner->isValid(name, value);}/**Get default value of the specified property.*/String ConfigManager::getDefaultValue(const String& name) const{ // // Check for a property with a fixed value // const char* fixedValue; if (_propertyTable->fixedValueTable.lookup(name, fixedValue)) { return fixedValue; } // // get property owner object from config table // ConfigPropertyOwner* propertyOwner; if (!_propertyTable->ownerTable.lookup(name, propertyOwner)) { throw UnrecognizedConfigProperty(name); } return propertyOwner->getDefaultValue(name);}/** Get current value of the specified property.*/String ConfigManager::getCurrentValue(const String& name) const{ // // Check for a property with a fixed value // const char* fixedValue; if (_propertyTable->fixedValueTable.lookup(name, fixedValue)) { return fixedValue; } // // get property owner object from config table // ConfigPropertyOwner* propertyOwner; if (!_propertyTable->ownerTable.lookup(name, propertyOwner)) { throw UnrecognizedConfigProperty(name); } return propertyOwner->getCurrentValue(name);}/**Get planned value of the specified property.*/String ConfigManager::getPlannedValue(const String& name) const{ // // Check for a property with a fixed value // const char* fixedValue; if (_propertyTable->fixedValueTable.lookup(name, fixedValue)) { return fixedValue; } // // get property owner object from config table // ConfigPropertyOwner* propertyOwner; if (!_propertyTable->ownerTable.lookup(name, propertyOwner)) { throw UnrecognizedConfigProperty(name); } return propertyOwner->getPlannedValue(name);}/**Get all the attributes of the specified property.*/void ConfigManager::getPropertyInfo( const String& name, Array<String>& propertyInfo) const{ // // get property owner object from config table // ConfigPropertyOwner* propertyOwner; if (!_propertyTable->ownerTable.lookup(name, propertyOwner)) { throw UnrecognizedConfigProperty(name); } propertyOwner->getPropertyInfo(name, propertyInfo);}/**Get a list of all property names.*/void ConfigManager::getAllPropertyNames( Array<String>& propertyNames, Boolean includeHiddenProperties) const{ Array<String> propertyInfo; propertyNames.clear(); for (OwnerTable::Iterator i = _propertyTable->ownerTable.start(); i; i++) { if (includeHiddenProperties) { propertyNames.append(i.key()); } else { // // Check if property is to be externally visible or not. // If the property should not be externally visible do not list the // property information. // propertyInfo.clear(); getPropertyInfo(i.key(), propertyInfo); if (propertyInfo[5] == STRING_TRUE) { propertyNames.append(i.key()); } } }}/** Merge the config properties from the specified planned config file with the properties in the specified current config file.*/void ConfigManager::mergeConfigFiles( const String& currentFile, const String& plannedFile){ PEGASUS_ASSERT(useConfigFiles); _configFileHandler.reset(new ConfigFileHandler(currentFile, plannedFile)); _loadConfigProperties();}/** Merge the config properties from the default planned config file with the properties in the default current config file.*/void ConfigManager::mergeConfigFiles(){ PEGASUS_ASSERT(useConfigFiles); _configFileHandler.reset(new ConfigFileHandler()); _loadConfigProperties();}/** Merge config properties specified on the command line*/void ConfigManager::mergeCommandLine(int& argc, char**& argv){ // Remove the command name from the command line if (argc > 0) { memmove(&argv[0], &argv[1], (argc) * sizeof(char*)); argc--; } // // Merge properties from the command line // for (Sint32 i = 0; i < argc; ) { const char* arg = argv[i]; if (*arg == '-') { throw UnrecognizedCommandLineOption(); } // Get the config option //const char* configOption = argv[i]; if (!_initPropertyWithCommandLineOption(arg)) { throw UnrecognizedConfigProperty(arg); } // Remove the option from the command line memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*)); argc--; }}/** load config properties from the file*/void ConfigManager::_loadConfigProperties(){ PEGASUS_ASSERT(useConfigFiles); // // copy the contents of planned config file over // the current config file // _configFileHandler->copyPlannedFileOverCurrentFile(); // // load all the properties from the current and planned // config files in to tables. // _configFileHandler->loadAllConfigProperties(); Array<CIMName> propertyNames; Array<String> propertyValues; _configFileHandler->getAllCurrentProperties(propertyNames, propertyValues); Uint32 size = propertyNames.size(); // // initialize all the property owners with the values // from the config files. // for (Uint32 i = 0; i < size; i++) { // // initialize the current value of the property owner // with the value from the config file handler // try { // // get property owner object from the config table. // ConfigPropertyOwner* propertyOwner; String propertyName = propertyNames[i].getString(); if (_propertyTable->ownerTable.lookup( propertyName, propertyOwner)) { if (propertyOwner->isValid( propertyName, propertyValues[i])) { propertyOwner->initCurrentValue( propertyName, propertyValues[i]); propertyOwner->initPlannedValue( propertyName, propertyValues[i]); } else { throw InvalidPropertyValue(propertyName, propertyValues[i]); } } else { // if the property is a fixed property then just log that // this property is not supported and continue. In all other // cases terminate the cimserver if (_propertyTable->fixedValueTable.contains(propertyName)) { Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING, "Config.ConfigManager.NOTSUPPORTED_CONFIG_PROPERTY", "Configuration property $0 is not supported. " "Setting ignored.", propertyName); } else { throw UnrecognizedConfigProperty(propertyName); } } } catch (UnrecognizedConfigProperty& ucp) { PEG_TRACE_STRING(TRC_CONFIG, Tracer::LEVEL2, ucp.getMessage()); throw; } catch (InvalidPropertyValue& ipv) { PEG_TRACE_STRING(TRC_CONFIG, Tracer::LEVEL2, ipv.getMessage()); throw; } }}/** Initialize config property with the value specified in the command line.*/Boolean ConfigManager::_initPropertyWithCommandLineOption( const String& option){ Uint32 pos = option.find('='); if (pos == PEG_NOT_FOUND) { // // The property value was not specified // throw UnrecognizedConfigProperty(option); } // // Get the property name and value // String propertyName = option.subString(0, pos); String propertyValue = option.subString(pos + 1); return initCurrentValue(propertyName, propertyValue);}/** Initialize config property owners and add them to the property owner table*/void ConfigManager::_initPropertyTable(){ // // add config property and its fixed value to fixed value table // for (Uint32 i = 0; i < NUM_FIXED_PROPERTIES; i++) { _propertyTable->fixedValueTable.insert(_fixedValues[i].propertyName, _fixedValues[i].fixedValue); } // // add config property and its owner object to owners table (but only if // the property is not also listed in the fixed value table. // for (Uint32 i = 0; i < NUM_PROPERTIES; i++) { const char* fixedValue = 0; _properties[i].propertyOwner->initialize(); if (!_propertyTable->fixedValueTable.lookup( _properties[i].propertyName, fixedValue)) { _propertyTable->ownerTable.insert(_properties[i].propertyName, _properties[i].propertyOwner); } else { // // Set the value for the fixed properties // _properties[i].propertyOwner->initCurrentValue( _properties[i].propertyName, fixedValue); } }}/** Get Pegasus Home*/String ConfigManager::getPegasusHome(){ return _pegasusHome;}/** Set Pegasus Home variable*/void ConfigManager::setPegasusHome(const String& home){ if (home != String::EMPTY) { _pegasusHome = home; }}/** Get the homed path for a given property.*/String ConfigManager::getHomedPath(const String& value){ String homedPath = String::EMPTY; if (value != String::EMPTY) { if (System::is_absolute_path((const char *)value.getCString())) { return value; } // // Get the pegasusHome and prepend it // String temp = value; Uint32 pos = 0; Uint32 token = 0; do { if ((pos = temp.find(FileSystem::getPathDelimiter())) == PEG_NOT_FOUND) { pos = temp.size(); token = 0; } else { token = 1; } if (System::is_absolute_path( (const char *)temp.subString(0, pos).getCString())) { homedPath.append(temp.subString(0,pos)); } else { homedPath.append(_pegasusHome + "/" + temp.subString(0, pos)); } if (token == 1) homedPath.append(FileSystem::getPathDelimiter()); temp.remove(0, pos + token); } while (temp.size() > 0); } return homedPath;}Boolean ConfigManager::parseBooleanValue(const String& propertyValue){ return String::equalNoCase(propertyValue, "true");}PEGASUS_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -