diff --git a/.travis.yml b/.travis.yml index 3fec8b16f..b1efbb8ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,6 +47,7 @@ after_success: --exclude "skeleton-subsystem" --exclude "test/test-subsystem" --exclude "bindings/c/Test.cpp" + --exclude "parameter/criterion/test/" --exclude "test/tokenizer" --gcov-options '\--long-file-names --preserve-paths' diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bf533ccc..ef268b92b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ endif(COMMAND cmake_policy) project(parameter-framework) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -std=c++11") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) diff --git a/README.md b/README.md index e041f89f6..3e2ec0728 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # parameter-framework -[![Build Status](https://travis-ci.org/01org/parameter-framework.svg?branch=master)](https://travis-ci.org/01org/parameter-framework) -[![Coverage Status](https://coveralls.io/repos/01org/parameter-framework/badge.svg?branch=master)](https://coveralls.io/r/01org/parameter-framework) +[![Build Status](https://travis-ci.org/01org/parameter-framework.svg?branch=next)](https://travis-ci.org/01org/parameter-framework) +[![Coverage Status](https://coveralls.io/repos/01org/parameter-framework/badge.svg?branch=next)](https://coveralls.io/r/01org/parameter-framework) ## Introduction diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt index 36b6aa943..92eb5f2b0 100644 --- a/bindings/c/CMakeLists.txt +++ b/bindings/c/CMakeLists.txt @@ -28,7 +28,9 @@ add_library(cparameter SHARED ParameterFramework.cpp) -include_directories("${PROJECT_SOURCE_DIR}/parameter/include") +include_directories( + "${PROJECT_SOURCE_DIR}/parameter/criterion/include" + "${PROJECT_SOURCE_DIR}/parameter/include") install(FILES ParameterFramework.h DESTINATION "include/parameter/c") diff --git a/bindings/c/ParameterFramework.cpp b/bindings/c/ParameterFramework.cpp index efc7d9922..f477f630c 100644 --- a/bindings/c/ParameterFramework.cpp +++ b/bindings/c/ParameterFramework.cpp @@ -41,11 +41,12 @@ #include using std::string; +using core::selection::criterion::CriterionInterface; /** Rename long pfw types to short ones in pfw namespace. */ namespace pfw { - typedef ISelectionCriterionInterface Criterion; + typedef CriterionInterface Criterion; typedef std::map Criteria; typedef CParameterMgrPlatformConnector Pfw; } @@ -105,15 +106,24 @@ class LogWrapper : public CParameterMgrPlatformConnector::ILogger LogWrapper() : mLogger() {} virtual ~LogWrapper() {} private: - virtual void log(bool bIsWarning, const string &strLog) + virtual void info(const string &msg) + { + log(pfwLogInfo, msg); + } + + virtual void warning(const string &msg) + { + log(pfwLogWarning, msg); + } + + void log(PfwLogLevel level, const string &strLog) { // A LogWrapper should NOT be register to the pfw (thus log called) // if logCb is NULL. assert(mLogger.logCb != NULL); - mLogger.logCb(mLogger.userCtx, - bIsWarning ? pfwLogWarning : pfwLogInfo, - strLog.c_str()); + mLogger.logCb(mLogger.userCtx, level, strLog.c_str()); } + PfwLogger mLogger; }; @@ -178,10 +188,11 @@ bool PfwHandler::createCriteria(const PfwCriterion criteriaArray[], size_t crite "\" already exist"); } - // Create criterion type - ISelectionCriterionTypeInterface *type = - pfw->createSelectionCriterionType(criterion.inclusive); - assert(type != NULL); + // Create criterion + CriterionInterface *newCriterion = (criterion.inclusive ? + pfw->createInclusiveCriterion(criterion.name) : + pfw->createExclusiveCriterion(criterion.name)); + assert(newCriterion != NULL); // Add criterion values for (size_t valueIndex = 0; criterion.values[valueIndex] != NULL; ++valueIndex) { int value; @@ -196,13 +207,14 @@ bool PfwHandler::createCriteria(const PfwCriterion criteriaArray[], size_t crite value = valueIndex; } const char * valueName = criterion.values[valueIndex]; - if(not type->addValuePair(value, valueName)) { + string error; + if(not newCriterion->addValuePair(value, valueName, error)) { return status.failure("Could not add value " + string(valueName) + - " to criterion " + criterion.name); + " to criterion " + criterion.name + ": " + error); } } - // Create criterion and add it to the pfw - criteria[criterion.name] = pfw->createSelectionCriterion(criterion.name, type); + // Add new criterion to criteria list + criteria[criterion.name] = newCriterion; } return status.success(); } diff --git a/bindings/c/Test.cpp b/bindings/c/Test.cpp index c450e60cb..1002c7f99 100644 --- a/bindings/c/Test.cpp +++ b/bindings/c/Test.cpp @@ -329,6 +329,17 @@ TEST_CASE_METHOD(Test, "Parameter-framework c api use") { REQUIRE(value == 3); } } + WHEN("Set a new value to a criterion without committing first") { + const char *criterionName = criteria[0].name; + REQUIRE_SUCCESS(pfwSetCriterion(pfw, criterionName, 0)); + THEN("A warning message should have been displayed") { + INFO("Previous pfw log: \n" + logLines); + size_t logPos = logLines.find("Warning: Selection criterion " + "'inclusiveCrit' has been modified 1 time(s)" + " without any configuration application"); + CHECK(logPos != std::string::npos); + } + } } WHEN("Commit criteria without a pfw") { REQUIRE(not pfwApplyConfigurations(NULL)); diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index a885febd2..764937dfd 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -36,7 +36,9 @@ find_package(PythonInterp 2.7 REQUIRED) find_package(PythonLibs ${PYTHON_VERSION_STRING} EXACT REQUIRED) include_directories(${PYTHON_INCLUDE_DIRS}) -include_directories(${PROJECT_SOURCE_DIR}/parameter/include) +include_directories( + ${PROJECT_SOURCE_DIR}/parameter/include + ${PROJECT_SOURCE_DIR}/parameter/criterion/include) set_property(SOURCE pfw.i PROPERTY CPLUSPLUS ON) set_property(SOURCE pfw.i PROPERTY SWIG_FLAGS "-Wall" "-Werror") diff --git a/bindings/python/pfw.i b/bindings/python/pfw.i index 9dbccbd8a..d6e63b0c0 100644 --- a/bindings/python/pfw.i +++ b/bindings/python/pfw.i @@ -80,10 +80,14 @@ public: void setLogger(ILogger* pLogger); - ISelectionCriterionTypeInterface* createSelectionCriterionType(bool bIsInclusive); - ISelectionCriterionInterface* createSelectionCriterion(const std::string& strName, - const ISelectionCriterionTypeInterface* pSelectionCriterionType); - ISelectionCriterionInterface* getSelectionCriterion(const std::string& strName); + core::selection::criterion::CriterionInterface* + createExclusiveCriterion(const std::string& name); + + core::selection::criterion::CriterionInterface* + createInclusiveCriterion(const std::string& name); + + core::selection::criterion::CriterionInterface* + getSelectionCriterion(const std::string& name); // Configuration application void applyConfigurations(); @@ -182,7 +186,8 @@ public: class ILogger { public: - virtual void log(bool bIsWarning, const std::string& strLog) = 0; + virtual void info(const std::string& log) = 0; + virtual void warning(const std::string& log) = 0; protected: virtual ~ILogger() {} }; @@ -190,35 +195,35 @@ class ILogger typedef CParameterMgrFullConnector::ILogger ILogger; %} -class ISelectionCriterionTypeInterface +namespace core +{ +namespace selection +{ +namespace criterion { -%{ -#include "SelectionCriterionTypeInterface.h" -%} - -public: - virtual bool addValuePair(int iValue, const std::string& strValue) = 0; - virtual bool getNumericalValue(const std::string& strValue, int& iValue) const = 0; - virtual bool getLiteralValue(int iValue, std::string& strValue) const = 0; - virtual bool isTypeInclusive() const = 0; - virtual std::string getFormattedState(int iValue) const = 0; - -protected: - virtual ~ISelectionCriterionTypeInterface() {} -}; -class ISelectionCriterionInterface +class CriterionInterface { %{ -#include "SelectionCriterionInterface.h" +#include %} public: virtual void setCriterionState(int iState) = 0; virtual int getCriterionState() const = 0; virtual std::string getCriterionName() const = 0; - virtual const ISelectionCriterionTypeInterface* getCriterionType() const = 0; + virtual bool addValuePair(int numericalValue, + const std::string& literalValue, + std::string& error) = 0; + virtual bool getNumericalValue(const std::string& literalValue, int& numericalValue) const = 0; + virtual bool getLiteralValue(int numericalValue, std::string& literalValue) const = 0; + virtual std::string getFormattedState() const = 0; + virtual bool isInclusive() const = 0; protected: - virtual ~ISelectionCriterionInterface() {} + virtual ~CriterionInterface() {} }; + +} /** criterion namespace */ +} /** selection namespace */ +} /** core namespace */ diff --git a/parameter/Android.mk b/parameter/Android.mk index 90e33f09b..22f7b2b21 100644 --- a/parameter/Android.mk +++ b/parameter/Android.mk @@ -1,4 +1,4 @@ -# Copyright (c) 2011-2014, Intel Corporation +# Copyright (c) 2011-2015, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -44,7 +44,6 @@ common_copy_headers := \ common_src_files := \ AreaConfiguration.cpp \ ArrayParameter.cpp \ - AutoLog.cpp \ BaseParameter.cpp \ BinarySerializableElement.cpp \ BinaryStream.cpp \ @@ -129,6 +128,7 @@ common_cflags := \ common_c_includes := \ $(LOCAL_PATH)/include/ \ + $(LOCAL_PATH)/log/include/ \ $(LOCAL_PATH)/../utility/ \ $(LOCAL_PATH)/../xmlserializer/ \ $(LOCAL_PATH)/../remote-processor/ @@ -197,7 +197,10 @@ include $(CLEAR_VARS) LOCAL_MODULE := $(common_module)_includes LOCAL_MODULE_OWNER := intel -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) +LOCAL_EXPORT_C_INCLUDE_DIRS := \ + $(LOCAL_PATH) \ + $(LOCAL_PATH)/log/include + LOCAL_STATIC_LIBRARIES := \ libxmlserializer \ diff --git a/parameter/AreaConfiguration.cpp b/parameter/AreaConfiguration.cpp index b3a556ebd..32eb59d82 100644 --- a/parameter/AreaConfiguration.cpp +++ b/parameter/AreaConfiguration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -54,14 +54,16 @@ void CAreaConfiguration::save(const CParameterBlackboard* pMainBlackboard) } // Apply data to current -bool CAreaConfiguration::restore(CParameterBlackboard* pMainBlackboard, bool bSync, std::list* plstrError) const +bool CAreaConfiguration::restore(CParameterBlackboard* pMainBlackboard, + bool bSync, + core::Results* errors) const { assert(_bValid); copyTo(pMainBlackboard, _pConfigurableElement->getOffset()); // Synchronize if required - return !bSync || _pSyncerSet->sync(*pMainBlackboard, false, plstrError); + return !bSync || _pSyncerSet->sync(*pMainBlackboard, false, errors); } // Ensure validity diff --git a/parameter/AreaConfiguration.h b/parameter/AreaConfiguration.h index 3ea471860..69b1e9ad5 100644 --- a/parameter/AreaConfiguration.h +++ b/parameter/AreaConfiguration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -32,6 +32,7 @@ #include "ParameterBlackboard.h" #include "BinaryStream.h" #include "SyncerSet.h" +#include "Results.h" class CConfigurableElement; class CXmlElement; @@ -48,8 +49,14 @@ class CAreaConfiguration // Save data from current void save(const CParameterBlackboard* pMainBlackboard); - // Apply data to current - bool restore(CParameterBlackboard* pMainBlackboard, bool bSync, std::list* plstrError) const; + /** Restore the configuration area + * + * @param[in] pMainBlackboard the application main blackboard + * @param[in] bSync indicates if a synchronisation has to be done + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool restore(CParameterBlackboard* pMainBlackboard, bool bSync, core::Results* errors) const; // Ensure validity void validate(const CParameterBlackboard* pMainBlackboard); diff --git a/parameter/ArrayParameter.cpp b/parameter/ArrayParameter.cpp index 8561410c3..291b6a13a 100644 --- a/parameter/ArrayParameter.cpp +++ b/parameter/ArrayParameter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -34,6 +34,7 @@ #include "ParameterAccessContext.h" #include "ConfigurationAccessContext.h" #include "ParameterBlackboard.h" +#include "Utility.h" #include #define base CParameter @@ -62,7 +63,7 @@ void CArrayParameter::showProperties(string& strResult) const // Array length strResult += "Array length: "; - strResult += toString(getArrayLength()); + strResult += CUtility::toString(getArrayLength()); strResult += "\n"; } @@ -281,7 +282,8 @@ bool CArrayParameter::setValues(uint32_t uiStartIndex, uint32_t uiBaseOffset, co if (!doSetValue(astrValues[uiValueIndex], uiOffset, parameterAccessContext)) { // Append parameter path to error - parameterAccessContext.appendToError(" " + getPath() + "/" + toString(uiValueIndex + uiStartIndex)); + parameterAccessContext.appendToError(" " + getPath() + "/" + + CUtility::toString(uiValueIndex + uiStartIndex)); return false; } diff --git a/parameter/AutoLog.cpp b/parameter/AutoLog.cpp deleted file mode 100644 index ff7151aaf..000000000 --- a/parameter/AutoLog.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2011-2014, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "AutoLog.h" - -using std::string; - -CAutoLog::CAutoLog(const CElement* pElement, const string& strContext, bool bLogOn) - : _pElement(pElement), _strContext(strContext), _bLogOn(bLogOn) -{ - if (_bLogOn) { - // Log - _pElement->doLog(false, _strContext + " {"); - // Nest - _pElement->nestLog(); - } -} - -CAutoLog::~CAutoLog() -{ - if (_bLogOn) { - // Unnest - _pElement->unnestLog(); - // Log - _pElement->doLog(false, "} " + _strContext); - } -} diff --git a/parameter/BitParameterBlockType.cpp b/parameter/BitParameterBlockType.cpp index 2016b3b70..0d344f23b 100644 --- a/parameter/BitParameterBlockType.cpp +++ b/parameter/BitParameterBlockType.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,6 +29,7 @@ */ #include "BitParameterBlockType.h" #include "BitParameterBlock.h" +#include "Utility.h" #define base CTypeElement @@ -74,7 +75,7 @@ CInstanceConfigurableElement* CBitParameterBlockType::doInstantiate() const void CBitParameterBlockType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Size - xmlElement.setAttributeString("Size", toString(_uiSize * 8)); + xmlElement.setAttributeString("Size", CUtility::toString(_uiSize * 8)); base::toXml(xmlElement, serializingContext); } diff --git a/parameter/BitParameterType.cpp b/parameter/BitParameterType.cpp index 2a400d40f..855ff099c 100644 --- a/parameter/BitParameterType.cpp +++ b/parameter/BitParameterType.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -33,6 +33,7 @@ #include #include "ParameterAccessContext.h" #include "BitParameterBlockType.h" +#include "Utility.h" #define base CTypeElement @@ -55,17 +56,17 @@ void CBitParameterType::showProperties(string& strResult) const // Bit Pos strResult += "Bit pos: "; - strResult += toString(_uiBitPos); + strResult += CUtility::toString(_uiBitPos); strResult += "\n"; // Bit size strResult += "Bit size: "; - strResult += toString(_uiBitSize); + strResult += CUtility::toString(_uiBitSize); strResult += "\n"; // Max strResult += "Max: "; - strResult += toString(_uiMax); + strResult += CUtility::toString(_uiMax); strResult += "\n"; } @@ -245,13 +246,13 @@ bool CBitParameterType::isEncodable(uint64_t uiData) const void CBitParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Position - xmlElement.setAttributeString("Pos", toString(_uiBitPos)); + xmlElement.setAttributeString("Pos", CUtility::toString(_uiBitPos)); // Size - xmlElement.setAttributeString("Size", toString(_uiBitSize)); + xmlElement.setAttributeString("Size", CUtility::toString(_uiBitSize)); // Maximum - xmlElement.setAttributeString("Max", toString(_uiMax)); + xmlElement.setAttributeString("Max", CUtility::toString(_uiMax)); base::toXml(xmlElement, serializingContext); diff --git a/parameter/CMakeLists.txt b/parameter/CMakeLists.txt index 94369fb74..16235d77b 100644 --- a/parameter/CMakeLists.txt +++ b/parameter/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2014, Intel Corporation +# Copyright (c) 2014-2015, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -26,10 +26,11 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +add_subdirectory(criterion) + add_library(parameter SHARED AreaConfiguration.cpp ArrayParameter.cpp - AutoLog.cpp BaseParameter.cpp BinarySerializableElement.cpp BinaryStream.cpp @@ -81,12 +82,7 @@ add_library(parameter SHARED PathNavigator.cpp PluginLocation.cpp RuleParser.cpp - SelectionCriteria.cpp - SelectionCriteriaDefinition.cpp - SelectionCriterion.cpp - SelectionCriterionLibrary.cpp SelectionCriterionRule.cpp - SelectionCriterionType.cpp SimulatedBackSynchronizer.cpp StringParameter.cpp StringParameterType.cpp @@ -107,11 +103,14 @@ include_directories( include "${PROJECT_SOURCE_DIR}/xmlserializer" "${PROJECT_SOURCE_DIR}/utility" - "${PROJECT_SOURCE_DIR}/remote-processor") + "${PROJECT_SOURCE_DIR}/remote-processor" + "${PROJECT_SOURCE_DIR}/parameter/" + "${PROJECT_SOURCE_DIR}/parameter/log/include" + "${PROJECT_SOURCE_DIR}/parameter/criterion/include") # No need to link with libremote-processor: it is accessed via dlopen() find_library(dl dl) -target_link_libraries(parameter xmlserializer pfw_utility dl) +target_link_libraries(parameter xmlserializer pfw_utility criterion) install(TARGETS parameter LIBRARY DESTINATION lib) # Client headers @@ -120,12 +119,9 @@ install(FILES include/ParameterMgrLoggerForward.h include/ParameterMgrFullConnector.h include/ParameterMgrPlatformConnector.h - include/SelectionCriterionInterface.h - include/SelectionCriterionTypeInterface.h DESTINATION "include/parameter/client") # Core (plugin) headers install(FILES - AutoLog.h BitParameterBlockType.h ConfigurableElement.h ConfigurableElementWithMapping.h @@ -138,7 +134,7 @@ install(FILES InstanceConfigurableElement.h Mapper.h MappingContext.h - NamedElementBuilderTemplate.h + LoggingElementBuilderTemplate.h ParameterBlockType.h ParameterType.h PathNavigator.h @@ -151,3 +147,5 @@ install(FILES TypeElement.h VirtualSubsystem.h DESTINATION "include/parameter/plugin") +install(DIRECTORY log/include/log/ + DESTINATION "include/parameter/plugin/log") diff --git a/parameter/CompoundRule.cpp b/parameter/CompoundRule.cpp index addb31ce9..8307de850 100644 --- a/parameter/CompoundRule.cpp +++ b/parameter/CompoundRule.cpp @@ -34,6 +34,8 @@ using std::string; +using namespace core::selection; + // Types const char* CCompoundRule::_apcTypes[2] = { "Any", diff --git a/parameter/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index aa9da51a6..3248842f3 100644 --- a/parameter/ConfigurableDomain.cpp +++ b/parameter/ConfigurableDomain.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -34,6 +34,7 @@ #include "XmlDomainSerializingContext.h" #include "XmlDomainImportContext.h" #include "XmlDomainExportContext.h" +#include "Utility.h" #include #define base CBinarySerializableElement @@ -104,8 +105,6 @@ void CConfigurableDomain::setSequenceAwareness(bool bSequenceAware) { if (_bSequenceAware != bSequenceAware) { - log_info("Making domain \"%s\" sequence %s", getName().c_str(), bSequenceAware ? "aware" : "unaware"); - _bSequenceAware = bSequenceAware; } } @@ -297,8 +296,10 @@ bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElemen return false; } // Add found element to domain - if (!addConfigurableElement(pConfigurableElement, NULL, strError)) { + core::Results infos; + if (!addConfigurableElement(pConfigurableElement, NULL, infos)) { + CUtility::asString(infos, strError); serializingContext.setError(strError); return false; @@ -354,12 +355,16 @@ bool CConfigurableDomain::parseSettings(const CXmlElement& xmlElement, return true; } // Configurable elements association -bool CConfigurableDomain::addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError) +bool CConfigurableDomain::addConfigurableElement(CConfigurableElement* pConfigurableElement, + const CParameterBlackboard* pMainBlackboard, + core::Results& infos) { // Already associated? if (containsConfigurableElement(pConfigurableElement)) { - strError = "Configurable element " + pConfigurableElement->getPath() + " already associated to configuration domain " + getName(); + infos.push_back("Configurable element " + + pConfigurableElement->getPath() + + " already associated to configuration domain " + getName()); return false; } @@ -367,13 +372,15 @@ bool CConfigurableDomain::addConfigurableElement(CConfigurableElement* pConfigur // Already owned? if (pConfigurableElement->belongsTo(this)) { - strError = "Configurable element " + pConfigurableElement->getPath() + " already owned by configuration domain " + getName(); + infos.push_back("Configurable element " + + pConfigurableElement->getPath() + + " already owned by configuration domain " + getName()); return false; } // Do add - doAddConfigurableElement(pConfigurableElement, pMainBlackboard); + doAddConfigurableElement(pConfigurableElement, infos, pMainBlackboard); return true; } @@ -387,7 +394,6 @@ bool CConfigurableDomain::removeConfigurableElement(CConfigurableElement* pConfi return false; } - log_info("Removing configurable element \"%s\" from domain \"%s\"", pConfigurableElement->getPath().c_str(), getName().c_str()); // Do remove doRemoveConfigurableElement(pConfigurableElement, true); @@ -454,23 +460,27 @@ CParameterBlackboard* CConfigurableDomain::findConfigurationBlackboard(const str } // Domain splitting -bool CConfigurableDomain::split(CConfigurableElement* pConfigurableElement, string& strError) +bool CConfigurableDomain::split(CConfigurableElement* pConfigurableElement, + core::Results& infos) { // Not associated? if (!containsConfigurableElement(pConfigurableElement)) { - strError = "Configurable element " + pConfigurableElement->getPath() + " not associated to configuration domain " + getName(); + std::string strError = "Configurable element " + pConfigurableElement->getPath() + + " not associated to configuration domain " + getName(); + infos.push_back(strError); return false; } - log_info("Splitting configurable element \"%s\" domain \"%s\"", pConfigurableElement->getPath().c_str(), getName().c_str()); // Create sub domain areas for all configurable element's children size_t uiNbConfigurableElementChildren = pConfigurableElement->getNbChildren(); if (!uiNbConfigurableElementChildren) { - strError = "Configurable element " + pConfigurableElement->getPath() + " has no children to split configurable domain to"; + std::string strError = "Configurable element " + pConfigurableElement->getPath() + + " has no children to split configurable domain to"; + infos.push_back(strError); return false; } @@ -481,7 +491,7 @@ bool CConfigurableDomain::split(CConfigurableElement* pConfigurableElement, stri CConfigurableElement* pChildConfigurableElement = static_cast(pConfigurableElement->getChild(uiChild)); - doAddConfigurableElement(pChildConfigurableElement); + doAddConfigurableElement(pChildConfigurableElement, infos); } // Delegate to configurations @@ -519,7 +529,10 @@ const CDomainConfiguration* CConfigurableDomain::getPendingConfiguration() const } // Configuration application if required -void CConfigurableDomain::apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForce) const +void CConfigurableDomain::apply(CParameterBlackboard* pParameterBlackboard, + CSyncerSet* pSyncerSet, + bool bForce, + std::string& strInfo) const { // Apply configuration only if the blackboard will // be synchronized either now or by syncerSet. @@ -539,9 +552,8 @@ void CConfigurableDomain::apply(CParameterBlackboard* pParameterBlackboard, CSyn // Check not the last one before applying if (!_pLastAppliedConfiguration || _pLastAppliedConfiguration != pApplicableDomainConfiguration) { - log_info("Applying configuration \"%s\" from domain \"%s\"", - pApplicableDomainConfiguration->getName().c_str(), - getName().c_str()); + strInfo = "Applying configuration '" + pApplicableDomainConfiguration->getName() + + "' from domain '" + getName() + "'"; // Check if we need to synchronize during restore bool bSync = !pSyncerSet && _bSequenceAware; @@ -597,7 +609,6 @@ bool CConfigurableDomain::createConfiguration(const string& strName, const CPara return false; } - log_info("Creating domain configuration \"%s\" into domain \"%s\"", strName.c_str(), getName().c_str()); // Creation CDomainConfiguration* pDomainConfiguration = new CDomainConfiguration(strName); @@ -639,8 +650,6 @@ bool CConfigurableDomain::deleteConfiguration(const string& strName, string& str return false; } - log_info("Deleting configuration \"%s\" from domain \"%s\"", strName.c_str(), getName().c_str()); - // Was the last applied? if (pDomainConfiguration == _pLastAppliedConfiguration) { @@ -680,35 +689,36 @@ bool CConfigurableDomain::renameConfiguration(const string& strName, const strin return false; } - log_info("Renaming domain \"%s\"'s configuration \"%s\" to \"%s\"", getName().c_str(), strName.c_str(), strNewName.c_str()); // Rename return pDomainConfiguration->rename(strNewName, strError); } -bool CConfigurableDomain::restoreConfiguration(const string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, std::list& lstrError) const +bool CConfigurableDomain::restoreConfiguration(const string& configurationName, + CParameterBlackboard* mainBlackboard, + bool autoSync, + core::Results& errors) const { - string strError; + string error; - const CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); + const CDomainConfiguration* configuration = findConfiguration(configurationName, error); - if (!pDomainConfiguration) { + if (configuration == NULL) { - lstrError.push_back(strError); + errors.push_back(error); return false; } - log_info("Restoring domain \"%s\"'s configuration \"%s\" to parameter blackboard", getName().c_str(), pDomainConfiguration->getName().c_str()); // Delegate - bool bSuccess = pDomainConfiguration->restore(pMainBlackboard, bAutoSync && _bSequenceAware, &lstrError); + bool bSuccess = configuration->restore(mainBlackboard, autoSync && _bSequenceAware, &errors); // Record last applied configuration - _pLastAppliedConfiguration = pDomainConfiguration; + _pLastAppliedConfiguration = configuration; // Synchronize - if (bAutoSync && !_bSequenceAware) { + if (autoSync && !_bSequenceAware) { - bSuccess &= _syncerSet.sync(*pMainBlackboard, false, &lstrError); + bSuccess &= _syncerSet.sync(*mainBlackboard, false, &errors); } return bSuccess; } @@ -722,7 +732,6 @@ bool CConfigurableDomain::saveConfiguration(const string& strName, const CParame return false; } - log_info("Saving domain \"%s\"'s configuration \"%s\" from parameter blackboard", getName().c_str(), pDomainConfiguration->getName().c_str()); // Delegate pDomainConfiguration->save(pMainBlackboard); @@ -760,7 +769,10 @@ bool CConfigurableDomain::getElementSequence(const string& strConfiguration, str return true; } -bool CConfigurableDomain::setApplicationRule(const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError) +bool CConfigurableDomain::setApplicationRule(const string& strConfiguration, + const string& strApplicationRule, + const core::selection::criterion::Criteria& criteria, + string& strError) { // Find Domain configuration CDomainConfiguration* pDomainConfiguration = findConfiguration(strConfiguration, strError); @@ -771,7 +783,7 @@ bool CConfigurableDomain::setApplicationRule(const string& strConfiguration, con } // Delegate to configuration - return pDomainConfiguration->setApplicationRule(strApplicationRule, pSelectionCriteriaDefinition, strError); + return pDomainConfiguration->setApplicationRule(strApplicationRule, criteria, strError); } bool CConfigurableDomain::clearApplicationRule(const string& strConfiguration, string& strError) @@ -847,8 +859,6 @@ void CConfigurableDomain::validate(const CParameterBlackboard* pMainBlackboard) // Ensure validity on areas related to configurable element void CConfigurableDomain::validateAreas(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard) { - log_info("Validating domain \"" + getName() + "\" against main blackboard for configurable element \"" + pConfigurableElement->getPath() + "\""); - // Propagate size_t uiNbConfigurations = getNbChildren(); size_t uiChild; @@ -986,7 +996,9 @@ bool CConfigurableDomain::containsConfigurableElement(const CConfigurableElement } // Merge any descended configurable element to this one with this one -void CConfigurableDomain::mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* pNewConfigurableElement) +void CConfigurableDomain::mergeAlreadyAssociatedDescendantConfigurableElements( + CConfigurableElement* newElement, + core::Results& infos) { std::list mergedConfigurableElementList; @@ -997,12 +1009,15 @@ void CConfigurableDomain::mergeAlreadyAssociatedDescendantConfigurableElements(C CConfigurableElement* pConfigurablePotentialDescendantElement = *it; - if (pConfigurablePotentialDescendantElement->isDescendantOf(pNewConfigurableElement)) { + if (pConfigurablePotentialDescendantElement->isDescendantOf(newElement)) { - log_info("In domain \"%s\", merging descendant configurable element's configurations \"%s\" into its ascendant \"%s\" ones", getName().c_str(), pConfigurablePotentialDescendantElement->getName().c_str(), pNewConfigurableElement->getName().c_str()); + infos.push_back("In domain '" + getName() + + "', merging descendant configurable element's configurations '" + + pConfigurablePotentialDescendantElement->getName() + + "' into its ascendant '" + newElement->getName() + "' ones"); // Merge configuration data - mergeConfigurations(pNewConfigurableElement, pConfigurablePotentialDescendantElement); + mergeConfigurations(newElement, pConfigurablePotentialDescendantElement); // Keep track for removal mergedConfigurableElementList.push_back(pConfigurablePotentialDescendantElement); @@ -1036,7 +1051,9 @@ void CConfigurableDomain::mergeConfigurations(CConfigurableElement* pToConfigura } // Configurable elements association -void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard *pMainBlackboard) +void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfigurableElement, + core::Results& infos, + const CParameterBlackboard* pMainBlackboard) { // Inform configurable element pConfigurableElement->addAttachedConfigurableDomain(this); @@ -1067,12 +1084,15 @@ void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfig // Ensure area validity for that configurable element (if main blackboard provided) if (pMainBlackboard) { + infos.push_back("Validating domain '" + getName() + + "' against main blackboard for configurable element '" + + pConfigurableElement->getPath() + "'"); // Need to validate against main blackboard validateAreas(pConfigurableElement, pMainBlackboard); } // Already associated descendend configurable elements need a merge of their configuration data - mergeAlreadyAssociatedDescendantConfigurableElements(pConfigurableElement); + mergeAlreadyAssociatedDescendantConfigurableElements(pConfigurableElement, infos); // Add to list _configurableElementList.push_back(pConfigurableElement); diff --git a/parameter/ConfigurableDomain.h b/parameter/ConfigurableDomain.h index a29c1ba04..bbc683201 100644 --- a/parameter/ConfigurableDomain.h +++ b/parameter/ConfigurableDomain.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -33,6 +33,7 @@ #include "XmlSerializingContext.h" #include "XmlDomainImportContext.h" #include "SyncerSet.h" +#include "Results.h" #include #include #include @@ -41,7 +42,6 @@ class CConfigurableElement; class CDomainConfiguration; class CParameterBlackboard; -class CSelectionCriteriaDefinition; class CConfigurableDomain : public CBinarySerializableElement { @@ -60,11 +60,37 @@ class CConfigurableDomain : public CBinarySerializableElement bool createConfiguration(const std::string& strName, const CParameterBlackboard* pMainBlackboard, std::string& strError); bool deleteConfiguration(const std::string& strName, std::string& strError); bool renameConfiguration(const std::string& strName, const std::string& strNewName, std::string& strError); - bool restoreConfiguration(const std::string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, std::list& strError) const; + + /** Restore a configuration + * + * @param[in] configurationName the configuration name + * @param[in] mainBlackboard the application main blackboard + * @param[in] autoSync boolean which indicates if auto sync mechanism is on + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool restoreConfiguration(const std::string& configurationName, + CParameterBlackboard* mainBlackboard, + bool autoSync, + core::Results& errors) const; + bool saveConfiguration(const std::string& strName, const CParameterBlackboard* pMainBlackboard, std::string& strError); bool setElementSequence(const std::string& strConfiguration, const std::vector& astrNewElementSequence, std::string& strError); bool getElementSequence(const std::string& strConfiguration, std::string& strResult) const; - bool setApplicationRule(const std::string& strConfiguration, const std::string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, std::string& strError); + + /** Create a new rule which apply on a configuration of this domain + * + * @param[in] strConfiguration the configuration name + * @param[in] strApplicationRule the rule to parse + * @param[in] criteria application criteria + * @param[out] error, error encountered during restoration + * @result true is success false otherwise + */ + bool setApplicationRule(const std::string& strConfiguration, + const std::string& strApplicationRule, + const core::selection::criterion::Criteria& criteria, + std::string& strError); + bool clearApplicationRule(const std::string& strConfiguration, std::string& strError); bool getApplicationRule(const std::string& strConfiguration, std::string& strResult) const; @@ -78,8 +104,17 @@ class CConfigurableDomain : public CBinarySerializableElement void gatherConfigurableElements(std::set& configurableElementSet) const; void listAssociatedToElements(std::string& strResult) const; - // Configurable elements association - bool addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, std::string& strError); + /** Add a configurable element to the domain + * + * @param[in] pConfigurableElement pointer to the element to add + * @param[in] pMainBlackboard pointer to the application main blackboard + * @param[out] infos useful information we can provide to client + * @return true if succeed false otherwise + */ + bool addConfigurableElement(CConfigurableElement* pConfigurableElement, + const CParameterBlackboard* pMainBlackboard, + core::Results& infos); + bool removeConfigurableElement(CConfigurableElement* pConfigurableElement, std::string& strError); // Blackboard Configuration and Base Offset retrieval @@ -89,14 +124,29 @@ class CConfigurableDomain : public CBinarySerializableElement bool& bIsLastApplied, std::string& strError) const; - // Domain splitting - bool split(CConfigurableElement* pConfigurableElement, std::string& strError); + /** Split the domain in two. + * Remove an element of a domain and create a new domain which owns the element. + * + * @param[in] pConfigurableElement pointer to the element to remove + * @param[out] infos useful information we can provide to client + * @return true if succeed false otherwise + */ + bool split(CConfigurableElement* pConfigurableElement, core::Results& infos); // Ensure validity on whole domain from main blackboard void validate(const CParameterBlackboard* pMainBlackboard); - // Configuration application if required - void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForced) const; + /** Apply the configuration if required + * + * @param[in] pParameterBlackboard the blackboard to synchronize + * @param[in] pSyncerSet pointer to the set containing application syncers + * @param[in] bForced boolean used to force configuration application + * @param[out] info string containing useful information we can provide to client + */ + void apply(CParameterBlackboard* pParameterBlackboard, + CSyncerSet* pSyncerSet, + bool bForced, + std::string& info) const; // Return applicable configuration validity for given configurable element bool isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const; @@ -148,12 +198,28 @@ class CConfigurableDomain : public CBinarySerializableElement // Check configurable element already attached bool containsConfigurableElement(const CConfigurableElement* pConfigurableCandidateElement) const; - // Merge any descended configurable element to this one - void mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* pNewConfigurableElement); + /** Merge any descended configurable element to this one + * + * @param[in] newElement pointer to element which has potential descendants which can be merged + * @param[out] infos useful information we can provide to client + */ + void mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* newElement, + core::Results& infos); + void mergeConfigurations(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement); - // Configurable elements association - void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard = NULL); + /** Actually realize the association between the domain and a configurable element + * + * @param[in] pConfigurableElement pointer to the element to add + * @param[out] infos useful information we can provide to client + * @param[in] (optional) pMainBlackboard, pointer to the application main blackboard + * Default value is NULL, when provided, blackboard area concerning the configurable + * element are validated. + */ + void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, + core::Results& infos, + const CParameterBlackboard* pMainBlackboard = NULL); + void doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet); // XML parsing diff --git a/parameter/ConfigurableDomains.cpp b/parameter/ConfigurableDomains.cpp index 844ade754..f3b1c0c9a 100644 --- a/parameter/ConfigurableDomains.cpp +++ b/parameter/ConfigurableDomains.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -32,7 +32,6 @@ #include "ConfigurableDomain.h" #include "ConfigurableElement.h" #include "BinaryStream.h" -#include "AutoLog.h" #define base CBinarySerializableElement @@ -68,10 +67,11 @@ void CConfigurableDomains::validate(const CParameterBlackboard* pMainBlackboard) } // Configuration application if required -void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet& syncerSet, bool bForce) const +void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, + CSyncerSet& syncerSet, + bool bForce, + core::Results& infos) const { - CAutoLog autoLog(this, "Applying configurations"); - /// Delegate to domains // Start with domains that can be synchronized all at once (with passed syncer set) @@ -82,8 +82,13 @@ void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, CSy const CConfigurableDomain* pChildConfigurableDomain = static_cast(getChild(uiChild)); + std::string info; // Apply and collect syncers when relevant - pChildConfigurableDomain->apply(pParameterBlackboard, &syncerSet, bForce); + pChildConfigurableDomain->apply(pParameterBlackboard, &syncerSet, bForce, info); + + if (!info.empty()) { + infos.push_back(info); + } } // Synchronize those collected syncers syncerSet.sync(*pParameterBlackboard, false, NULL); @@ -93,8 +98,12 @@ void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, CSy const CConfigurableDomain* pChildConfigurableDomain = static_cast(getChild(uiChild)); + std::string info; // Apply and synchronize when relevant - pChildConfigurableDomain->apply(pParameterBlackboard, NULL, bForce); + pChildConfigurableDomain->apply(pParameterBlackboard, NULL, bForce, info); + if (!info.empty()) { + infos.push_back(info); + } } } @@ -119,8 +128,6 @@ bool CConfigurableDomains::createDomain(const string& strName, string& strError) return false; } - log_info("Creating configurable domain \"%s\"", strName.c_str()); - // Creation/Hierarchy addChild(new CConfigurableDomain(strName)); @@ -145,8 +152,6 @@ bool CConfigurableDomains::addDomain(CConfigurableDomain& domain, bool bOverwrit deleteDomain(*pExistingDomain); } - log_info("Adding configurable domain \"" + strDomainName + "\""); - addChild(&domain); return true; @@ -154,8 +159,6 @@ bool CConfigurableDomains::addDomain(CConfigurableDomain& domain, bool bOverwrit void CConfigurableDomains::deleteDomain(CConfigurableDomain& configurableDomain) { - log_info("Deleting configurable domain \"" + configurableDomain.getName() + "\""); - removeChild(&configurableDomain); delete &configurableDomain; @@ -175,8 +178,6 @@ bool CConfigurableDomains::deleteDomain(const string& strName, string& strError) void CConfigurableDomains::deleteAllDomains() { - log_info("Deleting all configurable domains"); - //remove Children clean(); } @@ -190,8 +191,6 @@ bool CConfigurableDomains::renameDomain(const string& strName, const string& str return false; } - log_info("Renaming configurable domain \"%s\" to \"%s\"", strName.c_str(), strNewName.c_str()); - // Rename return pConfigurableDomain->rename(strNewName, strError); } @@ -293,17 +292,21 @@ bool CConfigurableDomains::listDomainElements(const string& strDomain, string& s return true; } -bool CConfigurableDomains::split(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError) +bool CConfigurableDomains::split(const string& domainName, + CConfigurableElement* element, + core::Results& infos) { // Find domain - CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); + std::string error; + CConfigurableDomain* domain = findConfigurableDomain(domainName, error); - if (!pConfigurableDomain) { + if (domain == NULL) { + infos.push_back(error); return false; } // Delegate - pConfigurableDomain->split(pConfigurableElement, strError); + domain->split(element, infos); return true; } @@ -399,19 +402,23 @@ void CConfigurableDomains::gatherAllOwnedConfigurableElements(std::set& lstrError) const +bool CConfigurableDomains::restoreConfiguration(const string& domainName, + const string& configurationName, + CParameterBlackboard* mainBlackboard, + bool autoSync, + core::Results& errors) const { - string strError; + string error; // Find domain - const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); + const CConfigurableDomain* domain = findConfigurableDomain(domainName, error); - if (!pConfigurableDomain) { + if (domain == NULL) { - lstrError.push_back(strError); + errors.push_back(error); return false; } // Delegate - return pConfigurableDomain->restoreConfiguration(strConfiguration, pMainBlackboard, bAutoSync, lstrError); + return domain->restoreConfiguration(configurationName, mainBlackboard, autoSync, errors); } // Config save @@ -455,17 +462,21 @@ bool CConfigurableDomains::getElementSequence(const string& strDomain, const str return pConfigurableDomain->getElementSequence(strConfiguration, strResult); } -bool CConfigurableDomains::setApplicationRule(const string& strDomain, const string& strConfiguration, const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError) +bool CConfigurableDomains::setApplicationRule(const string& strDomain, + const string& strConfiguration, + const string& strApplicationRule, + const core::selection::criterion::Criteria& criteria, + string& strError) { - CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); + CConfigurableDomain* domain = findConfigurableDomain(strDomain, strError); - if (!pConfigurableDomain) { + if (domain == NULL) { return false; } // Delegate to domain - return pConfigurableDomain->setApplicationRule(strConfiguration, strApplicationRule, pSelectionCriteriaDefinition, strError); + return domain->setApplicationRule(strConfiguration, strApplicationRule, criteria, strError); } bool CConfigurableDomains::clearApplicationRule(const string& strDomain, const string& strConfiguration, string& strError) @@ -510,17 +521,23 @@ void CConfigurableDomains::listLastAppliedConfigurations(string& strResult) cons } // Configurable element - domain association -bool CConfigurableDomains::addConfigurableElementToDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError) +bool +CConfigurableDomains::addConfigurableElementToDomain(const string& domainName, + CConfigurableElement* element, + const CParameterBlackboard* mainBlackboard, + core::Results& infos) { // Find domain - CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); + std::string error; + CConfigurableDomain* domain = findConfigurableDomain(domainName, error); - if (!pConfigurableDomain) { + if (domain == NULL) { + infos.push_back(error); return false; } // Delegate - return pConfigurableDomain->addConfigurableElement(pConfigurableElement, pMainBlackboard, strError); + return domain->addConfigurableElement(element, mainBlackboard, infos); } bool CConfigurableDomains::removeConfigurableElementFromDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError) @@ -543,9 +560,6 @@ CParameterBlackboard* CConfigurableDomains::findConfigurationBlackboard(const st bool& bIsLastApplied, string& strError) const { - log_info("Find configuration blackboard for Domain:%s, Configuration:%s, Element:%s", - strDomain.c_str(), strConfiguration.c_str(), pConfigurableElement->getPath().c_str()); - // Find domain const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); diff --git a/parameter/ConfigurableDomains.h b/parameter/ConfigurableDomains.h index 3cc16df6b..a019f4ae5 100644 --- a/parameter/ConfigurableDomains.h +++ b/parameter/ConfigurableDomains.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -30,8 +30,10 @@ #pragma once #include "BinarySerializableElement.h" +#include "Results.h" +#include + #include -#include #include @@ -39,7 +41,6 @@ class CParameterBlackboard; class CConfigurableElement; class CSyncerSet; class CConfigurableDomain; -class CSelectionCriteriaDefinition; class CConfigurableDomains : public CBinarySerializableElement { @@ -79,7 +80,19 @@ class CConfigurableDomains : public CBinarySerializableElement bool setSequenceAwareness(const std::string& strDomain, bool bSequenceAware, std::string& strError); bool getSequenceAwareness(const std::string& strDomain, bool& bSequenceAware, std::string& strError) const; bool listDomainElements(const std::string& strDomain, std::string& strResult) const; - bool split(const std::string& strDomain, CConfigurableElement* pConfigurableElement, std::string& strError); + + /** Split a domain in two. + * Remove an element of a domain and create a new domain which owns the element. + * + * @param[in] domainName the domain name + * @param[in] element pointer to the element to remove + * @param[out] infos useful information we can provide to client + * @return true if succeed false otherwise + */ + bool split(const std::string& domainName, + CConfigurableElement* element, + core::Results& infos); + void listAssociatedElements(std::string& strResult) const; void listConflictingElements(std::string& strResult) const; void listDomains(std::string& strResult) const; @@ -88,19 +101,60 @@ class CConfigurableDomains : public CBinarySerializableElement bool createConfiguration(const std::string& strDomain, const std::string& strConfiguration, const CParameterBlackboard* pMainBlackboard, std::string& strError); bool deleteConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); bool renameConfiguration(const std::string& strDomain, const std::string& strConfigurationName, const std::string& strNewConfigurationName, std::string& strError); - bool restoreConfiguration(const std::string& strDomain, const std::string& strConfiguration, CParameterBlackboard* pMainBlackboard, bool bAutoSync, std::list& lstrError) const; + + /** Restore a configuration + * + * @param[in] strDomain the domain name + * @param[in] strConfiguration the configuration name + * @param[in] mainBlackboard the application main blackboard + * @param[in] autoSync boolean which indicates if auto sync mechanism is on + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool restoreConfiguration(const std::string& strDomain, + const std::string& strConfiguration, + CParameterBlackboard* pMainBlackboard, + bool bAutoSync, + core::Results& errors) const; + bool saveConfiguration(const std::string& strDomain, const std::string& strConfiguration, const CParameterBlackboard* pMainBlackboard, std::string& strError); bool setElementSequence(const std::string& strDomain, const std::string& strConfiguration, const std::vector& astrNewElementSequence, std::string& strError); bool getElementSequence(const std::string& strDomain, const std::string& strConfiguration, std::string& strResult) const; - bool setApplicationRule(const std::string& strDomain, const std::string& strConfiguration, const std::string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, std::string& strError); + + /** Create a new rule of configuration application + * + * @param[in] strDomain the domain name + * @param[in] strConfiguration the configuration name + * @param[in] strApplicationRule the rule to parse + * @param[in] criteria application criteria + * @param[out] error, error encountered during restoration + * @result true is success false otherwise + */ + bool setApplicationRule(const std::string& strDomain, + const std::string& strConfiguration, + const std::string& strApplicationRule, + const core::selection::criterion::Criteria& criteria, + std::string& strError); + bool clearApplicationRule(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); bool getApplicationRule(const std::string& strDomain, const std::string& strConfiguration, std::string& strResult) const; // Last applied configurations void listLastAppliedConfigurations(std::string& strResult) const; - // Configurable element - domain association - bool addConfigurableElementToDomain(const std::string& strDomain, CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, std::string& strError); + /** Associate a configurable element to a domain + * + * @param[in] domainName the domain name + * @param[in] element pointer to the element to add + * @param[in] mainBlackboard pointer to the application main blackboard + * @param[out] infos useful information we can provide to client + * @return true if succeed false otherwise + */ + bool addConfigurableElementToDomain(const std::string& domainName, + CConfigurableElement* element, + const CParameterBlackboard* mainBlackboard, + core::Results& infos); + bool removeConfigurableElementFromDomain(const std::string& strDomain, CConfigurableElement* pConfigurableElement, std::string& strError); // Configuration Blackboard for element @@ -123,8 +177,17 @@ class CConfigurableDomains : public CBinarySerializableElement // Ensure validity on whole domains from main blackboard void validate(const CParameterBlackboard* pMainBlackboard); - // Configuration application if required - void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet& syncerSet, bool bForce) const; + /** Apply the configuration if required + * + * @param[in] pParameterBlackboard the blackboard to synchronize + * @param[in] pSyncerSet pointer to the set containing application syncers + * @param[in] bForce boolean used to force configuration application + * @param[out] infos useful information we can provide to client + */ + void apply(CParameterBlackboard* pParameterBlackboard, + CSyncerSet& syncerSet, + bool bForce, + core::Results& infos) const; // Class kind virtual std::string getKind() const; diff --git a/parameter/ConfigurableElement.cpp b/parameter/ConfigurableElement.cpp index 754f2077e..66e462e5c 100644 --- a/parameter/ConfigurableElement.cpp +++ b/parameter/ConfigurableElement.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -34,6 +34,7 @@ #include "ConfigurationAccessContext.h" #include "ConfigurableElementAggregator.h" #include "AreaConfiguration.h" +#include "Utility.h" #include #define base CElement @@ -161,7 +162,7 @@ void CConfigurableElement::getListOfElementsWithMapping( { // Check parent const CElement* pParent = getParent(); - if (isOfConfigurableElementType(pParent)) { + if (pParent != NULL) { const CConfigurableElement* pConfigurableElement = static_cast(pParent); @@ -241,7 +242,7 @@ ISyncer* CConfigurableElement::getSyncer() const // Check parent const CElement* pParent = getParent(); - if (isOfConfigurableElementType(pParent)) { + if (pParent != NULL) { return static_cast(pParent)->getSyncer(); } @@ -310,7 +311,7 @@ void CConfigurableElement::getBelongingDomains(std::list(pParent)->getBelongingDomains(configurableDomainList); } @@ -360,7 +361,7 @@ bool CConfigurableElement::isRogue() const std::string CConfigurableElement::getFootprintAsString() const { // Get size as string - return toString(getFootPrint()) + " byte(s)"; + return CUtility::toString(getFootPrint()) + " byte(s)"; } // Matching check for no domain association @@ -465,7 +466,7 @@ bool CConfigurableElement::belongsToDomainAscending(const CConfigurableDomain* p // Check parent const CElement* pParent = getParent(); - if (isOfConfigurableElementType(pParent)) { + if (pParent != NULL) { return static_cast(pParent)->belongsTo(pConfigurableDomain); } @@ -478,7 +479,7 @@ const CSubsystem* CConfigurableElement::getBelongingSubsystem() const const CElement* pParent = getParent(); // Stop at system class - if (!pParent->getParent()) { + if (pParent == NULL) { return NULL; } @@ -491,13 +492,3 @@ bool CConfigurableElement::isParameter() const { return false; } - - -// Check parent is still of current type (by structure knowledge) -bool CConfigurableElement::isOfConfigurableElementType(const CElement* pParent) const -{ - assert(pParent); - - // Up to system class - return !!pParent->getParent(); -} diff --git a/parameter/ConfigurableElement.h b/parameter/ConfigurableElement.h index 18256cfa5..991605ae7 100644 --- a/parameter/ConfigurableElement.h +++ b/parameter/ConfigurableElement.h @@ -141,9 +141,6 @@ class CConfigurableElement : public CElement void getBelongingDomains(std::list& configurableDomainList) const; void listDomains(const std::list& configurableDomainList, std::string& strResult, bool bVertical) const; - // Check parent is still of current type (by structure knowledge) - bool isOfConfigurableElementType(const CElement* pParent) const; - // Offset in main blackboard uint32_t _uiOffset; diff --git a/parameter/DefaultElementLibrary.h b/parameter/DefaultElementLibrary.h index b6966c29d..a85b45c4c 100644 --- a/parameter/DefaultElementLibrary.h +++ b/parameter/DefaultElementLibrary.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -46,16 +46,17 @@ class CDefaultElementLibrary: public CElementLibrary { public: - explicit CDefaultElementLibrary(bool bEnableDefaultMechanism = true); + CDefaultElementLibrary() : _defaultBuilder(NULL) {} virtual ~CDefaultElementLibrary() {} - /** Enable the default builder fallback mechanism. + /** Set the default builder used in fallback mechanism. * @see createElement() for more detail on this mechanism. * - * @param[in] bEnable if true/false, activate/deactivate the default builder mechanism. + * @param[in] defaultBuilder if NULL default builder mechanism, else provided builder is used. */ - void enableDefaultMechanism(bool bEnable) { - _bEnableDefaultMechanism = bEnable; + void setDefaultBuilder(CDefaultElementBuilder* defaultBuilder) + { + _defaultBuilder = defaultBuilder; } @@ -72,15 +73,9 @@ class CDefaultElementLibrary: public CElementLibrary CElement* createElement(const CXmlElement& xmlElement) const; private: - bool _bEnableDefaultMechanism; - CDefaultElementBuilder _DefaultElementBuilder; + CDefaultElementBuilder* _defaultBuilder; }; -template -CDefaultElementLibrary::CDefaultElementLibrary(bool bEnableDefaultMechanism) : - _bEnableDefaultMechanism(bEnableDefaultMechanism), - _DefaultElementBuilder() {} - template CElement* CDefaultElementLibrary::createElement(const CXmlElement& xmlElement) const { @@ -91,12 +86,12 @@ CElement* CDefaultElementLibrary::createElement(const CX return builtElement; } - if (!_bEnableDefaultMechanism) { + if (_defaultBuilder == NULL) { // The default builder mechanism is not enabled return NULL; } // Use the default builder - return _DefaultElementBuilder.createElement(xmlElement); + return _defaultBuilder->createElement(xmlElement); } diff --git a/parameter/DomainConfiguration.cpp b/parameter/DomainConfiguration.cpp index ebf305683..76ec72dc7 100644 --- a/parameter/DomainConfiguration.cpp +++ b/parameter/DomainConfiguration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -288,10 +288,12 @@ void CDomainConfiguration::getElementSequence(string& strResult) const } // Application rule -bool CDomainConfiguration::setApplicationRule(const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, string& strError) +bool CDomainConfiguration::setApplicationRule(const string& strApplicationRule, + const core::selection::criterion::Criteria& criteria, + string& strError) { // Parser - CRuleParser ruleParser(strApplicationRule, pSelectionCriteriaDefinition); + CRuleParser ruleParser(strApplicationRule, criteria); // Attempt to parse it if (!ruleParser.parse(NULL, strError)) { @@ -374,7 +376,9 @@ void CDomainConfiguration::save(const CParameterBlackboard* pMainBlackboard) } // Apply data to current -bool CDomainConfiguration::restore(CParameterBlackboard* pMainBlackboard, bool bSync, std::list* plstrError) const +bool CDomainConfiguration::restore(CParameterBlackboard* pMainBlackboard, + bool bSync, + core::Results* errors) const { bool bSuccess = true; @@ -385,7 +389,7 @@ bool CDomainConfiguration::restore(CParameterBlackboard* pMainBlackboard, bool b const CAreaConfiguration* pAreaConfiguration = *it; - bSuccess &= pAreaConfiguration->restore(pMainBlackboard, bSync, plstrError); + bSuccess &= pAreaConfiguration->restore(pMainBlackboard, bSync, errors); } return bSuccess; diff --git a/parameter/DomainConfiguration.h b/parameter/DomainConfiguration.h index e8b41efc5..ddd14eb27 100644 --- a/parameter/DomainConfiguration.h +++ b/parameter/DomainConfiguration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -30,6 +30,9 @@ #pragma once #include "BinarySerializableElement.h" +#include "Results.h" +#include + #include #include @@ -39,7 +42,6 @@ class CParameterBlackboard; class CConfigurationAccessContext; class CCompoundRule; class CSyncerSet; -class CSelectionCriteriaDefinition; class CDomainConfiguration : public CBinarySerializableElement { @@ -59,8 +61,17 @@ class CDomainConfiguration : public CBinarySerializableElement bool setElementSequence(const std::vector& astrNewElementSequence, std::string& strError); void getElementSequence(std::string& strResult) const; - // Application rule - bool setApplicationRule(const std::string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition, std::string& strError); + /** Create a new application rule for this configuration + * + * @param[in] strApplicationRule the rule to parse + * @param[in] criteria application criteria + * @param[out] error, error encountered during restoration + * @result true is success false otherwise + */ + bool setApplicationRule(const std::string& strApplicationRule, + const core::selection::criterion::Criteria& criteria, + std::string& strError); + void clearApplicationRule(); void getApplicationRule(std::string& strResult) const; @@ -69,8 +80,18 @@ class CDomainConfiguration : public CBinarySerializableElement // Save data from current void save(const CParameterBlackboard* pMainBlackboard); - // Apply data to current - bool restore(CParameterBlackboard* pMainBlackboard, bool bSync, std::list* plstrError = NULL) const; + + /** Restore the configuration + * + * @param[in] pMainBlackboard the application main blackboard + * @param[in] bSync indicates if a synchronisation has to be done + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool restore(CParameterBlackboard* pMainBlackboard, + bool bSync, + core::Results* errors = NULL) const; + // Ensure validity for configurable element area configuration void validate(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard); // Ensure validity of all area configurations diff --git a/parameter/Element.cpp b/parameter/Element.cpp index cacf49b6c..edd093994 100644 --- a/parameter/Element.cpp +++ b/parameter/Element.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -35,7 +35,6 @@ #include #include #include -#include using std::string; @@ -48,81 +47,6 @@ CElement::~CElement() removeChildren(); } -// Logging -void CElement::log_info(const string& strMessage, ...) const -{ - char *pacBuffer; - va_list listPointer; - - va_start(listPointer, strMessage); - - vasprintf(&pacBuffer, strMessage.c_str(), listPointer); - - va_end(listPointer); - - if (pacBuffer != NULL) { - doLog(false, pacBuffer); - } - - free(pacBuffer); -} - -void CElement::log_warning(const string& strMessage, ...) const -{ - char *pacBuffer; - va_list listPointer; - - va_start(listPointer, strMessage); - - vasprintf(&pacBuffer, strMessage.c_str(), listPointer); - - va_end(listPointer); - - if (pacBuffer != NULL) { - doLog(true, pacBuffer); - } - - free(pacBuffer); -} - -// Log each element of the string list -void CElement::log_table(bool bIsWarning, const std::list lstrMessage) const -{ - std::list::const_iterator iterator(lstrMessage.begin()); - std::list::const_iterator end(lstrMessage.end()); - - while (iterator != end) { - // Log current list element - doLog(bIsWarning, iterator->c_str()); - ++iterator; - } -} - -void CElement::doLog(bool bIsWarning, const string& strLog) const -{ - assert(_pParent); - - // Propagate till root - _pParent->doLog(bIsWarning, strLog); -} - -void CElement::nestLog() const -{ - assert(_pParent); - - // Propagate till root - _pParent->nestLog(); -} - -void CElement::unnestLog() const -{ - assert(_pParent); - - // Propagate till root - _pParent->unnestLog(); -} - - void CElement::setDescription(const string& strDescription) { _strDescription = strDescription; @@ -139,23 +63,6 @@ bool CElement::childrenAreDynamic() const return false; } -bool CElement::init(string& strError) -{ - uint32_t uiIndex; - - for (uiIndex = 0; uiIndex < _childArray.size(); uiIndex++) { - - CElement* pElement = _childArray[uiIndex];; - - if (!pElement->init(strError)) { - - return false; - } - } - - return true; -} - void CElement::dumpContent(string& strContent, CErrorContext& errorContext, const uint32_t uiDepth) const { string strIndent; @@ -202,43 +109,6 @@ void CElement::showProperties(string& strResult) const strResult += "Kind: " + getKind() + "\n"; } -// Conversion utilities -string CElement::toString(uint32_t uiValue) -{ - std::ostringstream ostr; - - ostr << uiValue; - - return ostr.str(); -} - -string CElement::toString(uint64_t uiValue) -{ - std::ostringstream ostr; - - ostr << uiValue; - - return ostr.str(); -} - -string CElement::toString(int32_t iValue) -{ - std::ostringstream ostr; - - ostr << iValue; - - return ostr.str(); -} - -string CElement::toString(double dValue) -{ - std::ostringstream ostr; - - ostr << dValue; - - return ostr.str(); -} - // Content dumping void CElement::logValue(string& strValue, CErrorContext& errorContext) const { @@ -661,8 +531,7 @@ const CElement* CElement::findChildOfKind(const string& strKind) const string CElement::getPath() const { - // Take out root element from the path - if (_pParent && _pParent->_pParent) { + if (_pParent != NULL) { return _pParent->getPath() + "/" + getPathName(); } @@ -674,16 +543,6 @@ string CElement::getQualifiedPath() const return getPath() + " [" + getKind() + "]"; } -uint32_t CElement::getDepth() const -{ - if (_pParent) { - - return _pParent->getDepth() + 1; - } - - return 0; -} - // Checksum for integrity checks uint8_t CElement::computeStructureChecksum() const { @@ -712,17 +571,3 @@ uint8_t CElement::computeStructureChecksum() const return uiChecksum; } - -// Utility to underline -void CElement::appendTitle(string& strTo, const string& strTitle) -{ - strTo += "\n" + strTitle + "\n"; - - string::size_type uiLength = strTitle.size(); - - while (uiLength--) { - - strTo += "="; - } - strTo += "\n"; -} diff --git a/parameter/Element.h b/parameter/Element.h index 8423e32be..2033c0943 100644 --- a/parameter/Element.h +++ b/parameter/Element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -32,7 +32,6 @@ #include #include #include -#include #include "XmlSink.h" #include "XmlSource.h" @@ -43,16 +42,10 @@ class CErrorContext; class CElement : public IXmlSink, public IXmlSource { - friend class CAutoLog; public: CElement(const std::string& strName = ""); virtual ~CElement(); - // Logging - void log_info(const std::string& strMessage, ...) const; - void log_warning(const std::string& strMessage, ...) const; - void log_table(bool bIsWarning, const std::list lstrMessage) const; - // Description void setDescription(const std::string& strDescription); const std::string& getDescription() const; @@ -64,8 +57,6 @@ class CElement : public IXmlSink, public IXmlSource std::string getPath() const; std::string getQualifiedPath() const; - // Creation / build - virtual bool init(std::string& strError); virtual void clean(); // Children management @@ -133,12 +124,6 @@ class CElement : public IXmlSink, public IXmlSource // Element properties virtual void showProperties(std::string& strResult) const; - // Conversion utilities - static std::string toString(uint32_t uiValue); - static std::string toString(uint64_t uiValue); - static std::string toString(int32_t iValue); - static std::string toString(double dValue); - // Checksum for integrity checks uint8_t computeStructureChecksum() const; @@ -147,8 +132,6 @@ class CElement : public IXmlSink, public IXmlSource protected: // Content dumping virtual void logValue(std::string& strValue, CErrorContext& errorContext) const; - // Utility to underline - static void appendTitle(std::string& strTo, const std::string& strTitle); // Hierarchy CElement* getParent(); @@ -165,18 +148,12 @@ class CElement : public IXmlSink, public IXmlSource CXmlSerializingContext& elementSerializingContext); private: - // Logging (done by root) - virtual void doLog(bool bIsWarning, const std::string& strLog) const; - virtual void nestLog() const; - virtual void unnestLog() const; // Returns Name or Kind if no Name std::string getPathName() const; // Returns true if children dynamic creation is to be dealt with virtual bool childrenAreDynamic() const; // House keeping void removeChildren(); - // For logging - uint32_t getDepth() const; // Fill XmlElement during XML composing void setXmlNameAttribute(CXmlElement& xmlElement) const; diff --git a/parameter/EnumParameterType.cpp b/parameter/EnumParameterType.cpp index 8cca7d746..147ee95bf 100644 --- a/parameter/EnumParameterType.cpp +++ b/parameter/EnumParameterType.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -35,6 +35,7 @@ #include #include "ParameterAccessContext.h" #include "EnumValuePair.h" +#include "Utility.h" #include #define base CParameterType @@ -344,7 +345,7 @@ bool CEnumParameterType::isValid(int iNumerical, CParameterAccessContext& parame void CEnumParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Size - xmlElement.setAttributeString("Size", toString(getSize() * 8)); + xmlElement.setAttributeString("Size", CUtility::toString(getSize() * 8)); base::toXml(xmlElement, serializingContext); } diff --git a/parameter/EnumValuePair.cpp b/parameter/EnumValuePair.cpp index 81febdd5c..35f4cd236 100644 --- a/parameter/EnumValuePair.cpp +++ b/parameter/EnumValuePair.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -28,6 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "EnumValuePair.h" +#include "Utility.h" #define base CElement @@ -51,7 +52,7 @@ int32_t CEnumValuePair::getNumerical() const string CEnumValuePair::getNumericalAsString() const { - return toString(_iNumerical); + return CUtility::toString(_iNumerical); } // From IXmlSink diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp index e7779a9cb..5189a0719 100644 --- a/parameter/FixedPointParameterType.cpp +++ b/parameter/FixedPointParameterType.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -36,6 +36,7 @@ #include "Parameter.h" #include "ParameterAccessContext.h" #include "ConfigurationAccessContext.h" +#include "Utility.h" #include #include @@ -59,9 +60,9 @@ void CFixedPointParameterType::showProperties(string& strResult) const // Notation strResult += "Notation: Q"; - strResult += toString(_uiIntegral); + strResult += CUtility::toString(_uiIntegral); strResult += "."; - strResult += toString(_uiFractional); + strResult += CUtility::toString(_uiFractional); strResult += "\n"; } @@ -363,13 +364,13 @@ double CFixedPointParameterType::binaryQnmToDouble(int32_t iValue) const void CFixedPointParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Size - xmlElement.setAttributeString("Size", toString(getSize() * 8)); + xmlElement.setAttributeString("Size", CUtility::toString(getSize() * 8)); // Integral - xmlElement.setAttributeString("Integral", toString(_uiIntegral)); + xmlElement.setAttributeString("Integral", CUtility::toString(_uiIntegral)); // Fractional - xmlElement.setAttributeString("Fractional", toString(_uiFractional)); + xmlElement.setAttributeString("Fractional", CUtility::toString(_uiFractional)); base::toXml(xmlElement, serializingContext); } diff --git a/parameter/FormattedSubsystemObject.cpp b/parameter/FormattedSubsystemObject.cpp index 591ef9071..3c51a90d5 100644 --- a/parameter/FormattedSubsystemObject.cpp +++ b/parameter/FormattedSubsystemObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -38,15 +38,17 @@ using std::string; CFormattedSubsystemObject::CFormattedSubsystemObject( - CInstanceConfigurableElement* pInstanceConfigurableElement) - : base(pInstanceConfigurableElement) + CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger) + : base(pInstanceConfigurableElement, logger) { } CFormattedSubsystemObject::CFormattedSubsystemObject( CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger, const string& strMappingValue) - : base(pInstanceConfigurableElement), _strFormattedMappingValue(strMappingValue) + : base(pInstanceConfigurableElement, logger), _strFormattedMappingValue(strMappingValue) { } @@ -54,11 +56,12 @@ CFormattedSubsystemObject::CFormattedSubsystemObject( CFormattedSubsystemObject::CFormattedSubsystemObject( CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger, const string& strMappingValue, uint32_t uiFirstAmendKey, uint32_t uiNbAmendKeys, const CMappingContext& context) - : base(pInstanceConfigurableElement), _strFormattedMappingValue(strMappingValue) + : base(pInstanceConfigurableElement, logger), _strFormattedMappingValue(strMappingValue) { // Cope with quotes in the name if (strMappingValue[0] == '\'' && strMappingValue.length() >= 2) { diff --git a/parameter/FormattedSubsystemObject.h b/parameter/FormattedSubsystemObject.h index c04583be7..d36120988 100644 --- a/parameter/FormattedSubsystemObject.h +++ b/parameter/FormattedSubsystemObject.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -38,23 +38,28 @@ class CFormattedSubsystemObject : public CSubsystemObject * Builds a new CFormattedSubsystemObject instance, without any mapping information. * * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject. + * @param[in] logger the logger provided by the client */ - CFormattedSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement); + CFormattedSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger); /** * Builds a new CFormattedSubsystemObject instance, using a simple mapping value without Amends. * * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject. + * @param[in] logger the logger provided by the client * @param[in] strFormattedMapping A std::string corresponding to the mapping of the element. The * std::string does not contain any Amend (%) and does not need to be formatted. */ CFormattedSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger, const std::string& strFormattedMapping); /** * Builds a new CFormattedSubsystemObject instance, using a mapping value containing Amends. * * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject. + * @param[in] logger the logger provided by the client * @param[in] strMappingValue A std::string corresponding to the mapping of the element. The * std::string contains Amend (%) and needs to be formatted with information from the context. * @param[in] uiFirstAmendKey Index of the first Amend key @@ -62,6 +67,7 @@ class CFormattedSubsystemObject : public CSubsystemObject * @param[in] context Contains values associated to Amend keys */ CFormattedSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger, const std::string& strMappingValue, uint32_t uiFirstAmendKey, uint32_t uiNbAmendKeys, diff --git a/parameter/IntegerParameterType.cpp b/parameter/IntegerParameterType.cpp index edc3d46ac..2d48d53c2 100644 --- a/parameter/IntegerParameterType.cpp +++ b/parameter/IntegerParameterType.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -34,6 +34,7 @@ #include "ParameterAccessContext.h" #include #include "ParameterAdaptation.h" +#include "Utility.h" #include #define base CParameterType @@ -69,12 +70,12 @@ void CIntegerParameterType::showProperties(string& strResult) const // Min strResult += "Min: "; - strResult += _bSigned ? toString((int32_t)_uiMin) : toString(_uiMin); + strResult += _bSigned ? CUtility::toString((int32_t)_uiMin) : CUtility::toString(_uiMin); strResult += "\n"; // Max strResult += "Max: "; - strResult += _bSigned ? toString((int32_t)_uiMax) : toString(_uiMax); + strResult += _bSigned ? CUtility::toString((int32_t)_uiMax) : CUtility::toString(_uiMax); strResult += "\n"; // Check if there's an adaptation object available @@ -439,22 +440,22 @@ void CIntegerParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContex if (_bSigned) { // Mininmum - xmlElement.setAttributeString("Min", toString((int32_t)_uiMin)); + xmlElement.setAttributeString("Min", CUtility::toString((int32_t)_uiMin)); // Maximum - xmlElement.setAttributeString("Max", toString((int32_t)_uiMax)); + xmlElement.setAttributeString("Max", CUtility::toString((int32_t)_uiMax)); } else { // Minimum - xmlElement.setAttributeString("Min", toString(_uiMin)); + xmlElement.setAttributeString("Min", CUtility::toString(_uiMin)); // Maximum - xmlElement.setAttributeString("Max", toString(_uiMax)); + xmlElement.setAttributeString("Max", CUtility::toString(_uiMax)); } // Size - xmlElement.setAttributeString("Size", toString(getSize() * 8)); + xmlElement.setAttributeString("Size", CUtility::toString(getSize() * 8)); base::toXml(xmlElement, serializingContext); diff --git a/parameter/LinearParameterAdaptation.cpp b/parameter/LinearParameterAdaptation.cpp index ea833b3b0..ae925a74a 100644 --- a/parameter/LinearParameterAdaptation.cpp +++ b/parameter/LinearParameterAdaptation.cpp @@ -28,6 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "LinearParameterAdaptation.h" +#include "Utility.h" #define base CParameterAdaptation @@ -49,12 +50,12 @@ void CLinearParameterAdaptation::showProperties(string& strResult) const // SlopeNumerator strResult += " - SlopeNumerator: "; - strResult += toString(_dSlopeNumerator); + strResult += CUtility::toString(_dSlopeNumerator); strResult += "\n"; // SlopeDenominator strResult += " - SlopeDenominator: "; - strResult += toString(_dSlopeDenominator); + strResult += CUtility::toString(_dSlopeDenominator); strResult += "\n"; } diff --git a/parameter/LogarithmicParameterAdaptation.cpp b/parameter/LogarithmicParameterAdaptation.cpp index 688527daa..bca494834 100644 --- a/parameter/LogarithmicParameterAdaptation.cpp +++ b/parameter/LogarithmicParameterAdaptation.cpp @@ -29,6 +29,7 @@ */ #include "LogarithmicParameterAdaptation.h" +#include "Utility.h" #include #define base CLinearParameterAdaptation @@ -45,10 +46,10 @@ void CLogarithmicParameterAdaptation::showProperties(std::string& strResult) con base::showProperties(strResult); strResult += " - LogarithmBase: "; - strResult += toString(_dLogarithmBase); + strResult += CUtility::toString(_dLogarithmBase); strResult += "\n"; strResult += " - FloorValue: "; - strResult += toString(_dFloorValue); + strResult += CUtility::toString(_dFloorValue); strResult += "\n"; } diff --git a/parameter/SelectionCriteriaDefinition.h b/parameter/LoggingElementBuilderTemplate.h similarity index 63% rename from parameter/SelectionCriteriaDefinition.h rename to parameter/LoggingElementBuilderTemplate.h index 617b379a8..653a1e416 100644 --- a/parameter/SelectionCriteriaDefinition.h +++ b/parameter/LoggingElementBuilderTemplate.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,30 +29,42 @@ */ #pragma once -#include "Element.h" -#include "SelectionCriterion.h" +#include "ElementBuilder.h" -class ISelectionCriterionObserver; - -class CSelectionCriteriaDefinition : public CElement +/** + * Builder for elements which need logger at construction + * + * @tparam ElementType the type of the element to build + */ +template +class TLoggingElementBuilderTemplate : public CElementBuilder { public: - CSelectionCriteriaDefinition(); - // Selection Criterion creation - CSelectionCriterion* createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType); + /** + * Class Constructor + * + * @param[in] logger the logger provided by the client + */ + TLoggingElementBuilderTemplate(core::log::Logger& logger) + : CElementBuilder(), mLogger(logger) + { + } - // Selection Criterion access - const CSelectionCriterion* getSelectionCriterion(const std::string& strName) const; - CSelectionCriterion* getSelectionCriterion(const std::string& strName); + /** + * Create a new element + * + * @param[in] xmlElement the description of the object to create + * + * @return pointer to the generated element + */ + virtual CElement* createElement(const CXmlElement& xmlElement) const + { + return new ElementType(xmlElement.getNameAttribute(), mLogger); + } - // List available criteria - void listSelectionCriteria(std::list& lstrResult, bool bWithTypeInfo, bool bHumanReadable) const; +private: - // Base - virtual std::string getKind() const; - - // Reset the modified status of the children - void resetModifiedStatus(); + /** Application Logger */ + core::log::Logger& mLogger; }; - diff --git a/parameter/ParameterAdaptation.cpp b/parameter/ParameterAdaptation.cpp index f1e73c19f..99955f144 100644 --- a/parameter/ParameterAdaptation.cpp +++ b/parameter/ParameterAdaptation.cpp @@ -28,6 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "ParameterAdaptation.h" +#include "Utility.h" #define base CElement @@ -58,7 +59,7 @@ void CParameterAdaptation::showProperties(string& strResult) const // Offset strResult += " - Offset: "; - strResult += toString(_iOffset); + strResult += CUtility::toString(_iOffset); strResult += "\n"; } diff --git a/parameter/ParameterBlockType.cpp b/parameter/ParameterBlockType.cpp index aafa7ca85..ad9488827 100644 --- a/parameter/ParameterBlockType.cpp +++ b/parameter/ParameterBlockType.cpp @@ -29,6 +29,7 @@ */ #include "ParameterBlockType.h" #include "ParameterBlock.h" +#include "Utility.h" #define base CTypeElement @@ -62,7 +63,8 @@ void CParameterBlockType::populate(CElement* pElement) const for (uiChild = 0; uiChild < uiArrayLength; uiChild++) { - CParameterBlock* pChildParameterBlock = new CParameterBlock(toString(uiChild), this); + CParameterBlock* pChildParameterBlock = new CParameterBlock(CUtility::toString(uiChild), + this); pElement->addChild(pChildParameterBlock); diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 45f1ac2d4..41cdbbae6 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -30,17 +30,13 @@ #include "ParameterMgr.h" #include "XmlParameterSerializingContext.h" #include "XmlElementSerializingContext.h" -#include "SystemClass.h" #include "ElementLibrarySet.h" #include "SubsystemLibrary.h" #include "NamedElementBuilderTemplate.h" #include "KindElementBuilderTemplate.h" #include "ElementBuilderTemplate.h" -#include "XmlFileIncluderElement.h" -#include "SelectionCriterionType.h" #include "SubsystemElementBuilder.h" #include "FileIncluderElementBuilder.h" -#include "SelectionCriteria.h" #include "ComponentType.h" #include "ComponentInstance.h" #include "ParameterBlockType.h" @@ -50,13 +46,10 @@ #include "ParameterBlackboard.h" #include "Parameter.h" #include "ParameterAccessContext.h" -#include "XmlFileIncluderElement.h" -#include "ParameterFrameworkConfiguration.h" #include "FrameworkConfigurationGroup.h" #include "PluginLocation.h" #include "SubsystemPlugins.h" #include "FrameworkConfigurationLocation.h" -#include "ConfigurableDomains.h" #include "ConfigurableDomain.h" #include "DomainConfiguration.h" #include "XmlDomainSerializingContext.h" @@ -68,7 +61,6 @@ #include "EnumParameterType.h" #include "RemoteProcessorServerInterface.h" #include "ElementLocator.h" -#include "AutoLog.h" #include "CompoundRule.h" #include "SelectionCriterionRule.h" #include "SimulatedBackSynchronizer.h" @@ -88,14 +80,21 @@ #include "XmlStringDocSource.h" #include "XmlMemoryDocSink.h" #include "XmlMemoryDocSource.h" -#include "SelectionCriteriaDefinition.h" #include "Utility.h" #include #include #include -#include -#define base CElement +/** Private macro helper to declare a new context + * + * Context declaration always need logger and logging prefix to be + * passed as parameters. + * This macro aims to avoid this boring notation. + * This macro should be called only once in a scope. Nested scopes can + * call this macro too, as variable shadowing is supported. + */ +#define LOG_CONTEXT(contextTitle) \ + core::log::Context context(_logger, contextTitle) #ifdef SIMULATION // In simulation, back synchronization of the blackboard won't probably work @@ -111,6 +110,9 @@ using std::list; using std::vector; using std::ostringstream; +// FIXME: integrate ParameterMgr to core namespace +using namespace core; + // Used for remote processor server creation typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler); @@ -304,7 +306,7 @@ const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandPa // Remote command parsers array Size const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]); -CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) : +CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogger& logger) : _bTuningModeIsOn(false), _bValueSpaceIsRaw(false), _bOutputRawFormatIsHex(false), @@ -317,24 +319,21 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) : _uiStructureChecksum(0), _pRemoteProcessorServer(NULL), _uiMaxCommandUsageLength(0), - _pLogger(NULL), - _uiLogDepth(0), + _logger(logger), _bForceNoRemoteInterface(false), _bFailOnMissingSubsystem(true), _bFailOnFailedSettingsLoad(true), - _bValidateSchemasOnStart(false) + _bValidateSchemasOnStart(false), + mPfwConfiguration(), + mCriteria(), + mSystemClass(_logger), + mDomains() { // Tuning Mode Mutex bzero(&_blackboardMutex, sizeof(_blackboardMutex)); pthread_mutex_init(&_blackboardMutex, NULL); - // Deal with children - addChild(new CParameterFrameworkConfiguration); - addChild(new CSelectionCriteria); - addChild(new CSystemClass); - addChild(new CConfigurableDomains); - _pCommandHandler = new CCommandHandler(this); // Add command parsers @@ -387,61 +386,24 @@ string CParameterMgr::getKind() const return "ParameterMgr"; } -// Logging -void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger) -{ - _pLogger = pLogger; -} - -// Logging -void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const -{ - if (_pLogger) { - - // Nest - string strIndent; - - // Level - uint32_t uiNbIndents = _uiLogDepth; - - while (uiNbIndents--) { - - strIndent += " "; - } - - // Log - _pLogger->log(bIsWarning, strIndent + strLog); - } -} - -void CParameterMgr::nestLog() const -{ - _uiLogDepth++; -} - -void CParameterMgr::unnestLog() const -{ - _uiLogDepth--; -} - // Version string CParameterMgr::getVersion() const { string strVersion; // Major - strVersion = toString(guiEditionMajor) + "."; + strVersion = CUtility::toString(guiEditionMajor) + "."; // Minor - strVersion += toString(guiEditionMinor) + "."; + strVersion += CUtility::toString(guiEditionMinor) + "."; // Revision - strVersion += toString(guiRevision); + strVersion += CUtility::toString(guiRevision); return strVersion; } bool CParameterMgr::load(string& strError) { - CAutoLog autoLog(this, "Loading"); + LOG_CONTEXT("Loading"); feedElementLibraries(); @@ -451,9 +413,7 @@ bool CParameterMgr::load(string& strError) return false; } - // Load subsystems - if (!getSystemClass()->loadSubsystems(strError, - _pSubsystemPlugins, !_bFailOnMissingSubsystem)) { + if (!loadSubsystems(strError)) { return false; } @@ -470,40 +430,35 @@ bool CParameterMgr::load(string& strError) return false; } - // Init flow of element tree - if (!init(strError)) { + if (!mSystemClass.initSubsystems(strError)) { return false; } { - CAutoLog autoLog(this, "Main blackboard back synchronization"); + LOG_CONTEXT("Main blackboard back synchronization"); - // Back synchronization for areas in parameter blackboard not covered by any domain - BackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard).sync(); + // Back synchronization for areas in parameter blackboard not covered by any domain + BackSynchronizer(&mSystemClass, _pMainParameterBlackboard).sync(); } // We're done loading the settings and back synchronizing - CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); - // We need to ensure all domains are valid - pConfigurableDomains->validate(_pMainParameterBlackboard); + mDomains.validate(_pMainParameterBlackboard); // Log selection criterion states { - CAutoLog autoLog(this, "Criterion states"); + LOG_CONTEXT("Criterion states"); - const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria(); + list criteria; + mCriteria.listSelectionCriteria(criteria, true, false); - list lstrSelectionCriteron; - selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false); - - log_table(false, lstrSelectionCriteron); + info() << criteria; } // Subsystem can not ask for resync as they have not been synced yet - getSystemClass()->cleanSubsystemsNeedToResync(); + mSystemClass.cleanSubsystemsNeedToResync(); // At initialization, check subsystems that need resync doApplyConfigurations(true); @@ -514,21 +469,23 @@ bool CParameterMgr::load(string& strError) bool CParameterMgr::loadFrameworkConfiguration(string& strError) { - CAutoLog autoLog(this, "Loading framework configuration"); + LOG_CONTEXT("Loading framework configuration"); // Parse Structure XML file CXmlElementSerializingContext elementSerializingContext(strError); - if (!xmlParse(elementSerializingContext, getFrameworkConfiguration(), _strXmlConfigurationFilePath, _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) { + if (!xmlParse(elementSerializingContext, &mPfwConfiguration, _strXmlConfigurationFilePath, + _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) { return false; } // Set class name to system class and configurable domains - getSystemClass()->setName(getConstFrameworkConfiguration()->getSystemClassName()); - getConfigurableDomains()->setName(getConstFrameworkConfiguration()->getSystemClassName()); + mSystemClass.setName(mPfwConfiguration.getSystemClassName()); + mDomains.setName(mPfwConfiguration.getSystemClassName()); // Get subsystem plugins elements - _pSubsystemPlugins = static_cast(getConstFrameworkConfiguration()->findChild("SubsystemPlugins")); + _pSubsystemPlugins = + static_cast(mPfwConfiguration.findChild("SubsystemPlugins")); if (!_pSubsystemPlugins) { @@ -538,24 +495,46 @@ bool CParameterMgr::loadFrameworkConfiguration(string& strError) } // Log tuning availability - log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited"); + info() << "Tuning " << (mPfwConfiguration.isTuningAllowed() ? "allowed" : "prohibited"); return true; } -bool CParameterMgr::loadStructure(string& strError) +bool CParameterMgr::loadSubsystems(std::string& error) { - // Retrieve system to load structure to - CSystemClass* pSystemClass = getSystemClass(); + LOG_CONTEXT("Loading subsystem plugins"); - log_info("Loading " + pSystemClass->getName() + " system class structure"); + // Load subsystems + bool isSuccess = mSystemClass.loadSubsystems(error, + _pSubsystemPlugins, + !_bFailOnMissingSubsystem); + + if (isSuccess) { + info() << "All subsystem plugins successfully loaded"; + + if(!error.empty()) { + // Log missing subsystems as info + info() << error; + } + } else { + warning() << error; + } + return isSuccess; +} + +bool CParameterMgr::loadStructure(string& strError) +{ + LOG_CONTEXT("Loading " + mSystemClass.getName() + " system class structure"); // Get structure description element - const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation")); + const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = + static_cast( + mPfwConfiguration.findChildOfKind("StructureDescriptionFileLocation")); if (!pStructureDescriptionFileLocation) { - strError = "No StructureDescriptionFileLocation element found for SystemClass " + pSystemClass->getName(); + strError = "No StructureDescriptionFileLocation element found for SystemClass " + + mSystemClass.getName(); return false; } @@ -569,18 +548,21 @@ bool CParameterMgr::loadStructure(string& strError) // Parse Structure XML file CXmlParameterSerializingContext parameterBuildContext(strError); - CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath); + { + LOG_CONTEXT("Importing system structure from file " + strXmlStructureFilePath); - if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) { + if (!xmlParse(parameterBuildContext, &mSystemClass, + strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) { - return false; + return false; + } } // Initialize offsets - pSystemClass->setOffset(0); + mSystemClass.setOffset(0); // Initialize main blackboard's size - _pMainParameterBlackboard->setSize(pSystemClass->getFootPrint()); + _pMainParameterBlackboard->setSize(mSystemClass.getFootPrint()); return true; } @@ -592,8 +574,8 @@ bool CParameterMgr::loadSettings(string& strError) if (!success && !_bFailOnFailedSettingsLoad) { // Load can not fail, ie continue but log the load errors - log_info(strLoadError); - log_info("Failed to load settings, continue without domains."); + info() << strLoadError; + info() << "Failed to load settings, continue without domains."; success = true; } @@ -608,10 +590,12 @@ bool CParameterMgr::loadSettings(string& strError) bool CParameterMgr::loadSettingsFromConfigFile(string& strError) { - CAutoLog autoLog(this, "Loading settings"); + LOG_CONTEXT("Loading settings"); // Get settings configuration element - const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration")); + const CFrameworkConfigurationGroup* pParameterConfigurationGroup = + static_cast( + mPfwConfiguration.findChildOfKind("SettingsConfiguration")); if (!pParameterConfigurationGroup) { @@ -635,12 +619,11 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) if (!pConfigurableDomainsFileLocation) { - strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + getSystemClass()->getName(); + strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + + mSystemClass.getName(); return false; } - // Get destination root element - CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); // Get Xml configuration domains file name string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath); @@ -649,28 +632,31 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath); // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary) - CXmlDomainImportContext xmlDomainImportContext(strError, !pBinarySettingsFileLocation, - *getSystemClass()); - - // Selection criteria definition for rule creation - xmlDomainImportContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition()); + CXmlDomainImportContext xmlDomainImportContext(strError, + !pBinarySettingsFileLocation, + mSystemClass, + mCriteria); // Auto validation of configurations if no binary settings provided xmlDomainImportContext.setAutoValidationRequired(!pBinarySettingsFileLocation); - log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with"); + info() << "Importing configurable domains from file " << strXmlConfigurationDomainsFilePath + << " " << ( pBinarySettingsFileLocation ? "without" : "with") << " settings"; // Do parse - if (!xmlParse(xmlDomainImportContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) { + if (!xmlParse(xmlDomainImportContext, &mDomains, + strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, + EParameterConfigurationLibrary, "SystemClassName")) { return false; } // We have loaded the whole system structure, compute checksum - const CSystemClass* pSystemClass = getConstSystemClass(); - _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum(); + _uiStructureChecksum = mSystemClass.computeStructureChecksum() + + mDomains.computeStructureChecksum(); // Load binary settings if any provided - if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) { + if (pBinarySettingsFileLocation && !mDomains.serializeSettings( + strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) { return false; } @@ -681,11 +667,7 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) bool CParameterMgr::importDomainFromFile(const string& strXmlFilePath, bool bOverwrite, string& strError) { - CXmlDomainImportContext xmlDomainImportContext(strError, true, *getSystemClass()); - - // Selection criteria definition for rule creation - xmlDomainImportContext.setSelectionCriteriaDefinition( - getConstSelectionCriteria()->getSelectionCriteriaDefinition()); + CXmlDomainImportContext xmlDomainImportContext(strError, true, mSystemClass, mCriteria); // Auto validation of configurations xmlDomainImportContext.setAutoValidationRequired(true); @@ -700,8 +682,9 @@ bool CParameterMgr::importDomainFromFile(const string& strXmlFilePath, bool bOve return false; } - bSuccess = getConfigurableDomains()->addDomain(*standaloneDomain, bOverwrite, strError); - if (!bSuccess) { + LOG_CONTEXT("Adding configurable domain '" + standaloneDomain->getName() + "'"); + + if (!logResult(mDomains.addDomain(*standaloneDomain, bOverwrite, strError), strError)) { return false; } @@ -748,36 +731,29 @@ bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingCo return true; } -// Init -bool CParameterMgr::init(string& strError) -{ - return base::init(strError); -} - -// Selection criteria interface -CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInclusive) +selection::criterion::Criterion* CParameterMgr::createExclusiveCriterion(const string& name) { // Propagate - return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive); + return mCriteria.createExclusiveCriterion(name, _logger); } -CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType) +selection::criterion::Criterion* CParameterMgr::createInclusiveCriterion(const string& name) { // Propagate - return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType); + return mCriteria.createInclusiveCriterion(name, _logger); } // Selection criterion retrieval -CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName) +selection::criterion::Criterion* CParameterMgr::getSelectionCriterion(const string& strName) { // Propagate - return getSelectionCriteria()->getSelectionCriterion(strName); + return mCriteria.getSelectionCriterion(strName); } // Configuration application void CParameterMgr::applyConfigurations() { - CAutoLog autoLog(this, "Configuration application request"); + LOG_CONTEXT("Configuration application request"); // Lock state CAutoLock autoLock(&_blackboardMutex); @@ -788,7 +764,7 @@ void CParameterMgr::applyConfigurations() doApplyConfigurations(false); } else { - log_warning("Configurations were not applied because the TuningMode is on"); + warning() << "Configurations were not applied because the TuningMode is on"; } } @@ -799,13 +775,13 @@ const CConfigurableElement* CParameterMgr::getConfigurableElement(const string& CPathNavigator pathNavigator(strPath); // Nagivate through system class - if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) { + if (!pathNavigator.navigateThrough(mSystemClass.getName(), strError)) { return NULL; } // Find element - const CElement* pElement = getConstSystemClass()->findDescendant(pathNavigator); + const CElement* pElement = mSystemClass.findDescendant(pathNavigator); if (!pElement) { @@ -900,15 +876,13 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProce CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) { (void)remoteCommand; - // System class - const CSystemClass* pSystemClass = getSystemClass(); // Show status /// General section - appendTitle(strResult, "General:"); + CUtility::appendTitle(strResult, "General:"); // System class strResult += "System Class: "; - strResult += pSystemClass->getName(); + strResult += mSystemClass.getName(); strResult += "\n"; // Tuning mode @@ -932,21 +906,21 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProces strResult += "\n"; /// Subsystem list - appendTitle(strResult, "Subsystems:"); + CUtility::appendTitle(strResult, "Subsystems:"); string strSubsystemList; - pSystemClass->listChildrenPaths(strSubsystemList); + mSystemClass.listChildrenPaths(strSubsystemList); strResult += strSubsystemList; /// Last applied configurations - appendTitle(strResult, "Last Applied [Pending] Configurations:"); + CUtility::appendTitle(strResult, "Last Applied [Pending] Configurations:"); string strLastAppliedConfigurations; - getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations); + mDomains.listLastAppliedConfigurations(strLastAppliedConfigurations); strResult += strLastAppliedConfigurations; /// Criteria states - appendTitle(strResult, "Selection Criteria:"); + CUtility::appendTitle(strResult, "Selection Criteria:"); list lstrSelectionCriteria; - getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true); + mCriteria.listSelectionCriteria(lstrSelectionCriteria, false, true); // Concatenate the criterion list as the command result string strCriteriaStates; CUtility::asString(lstrSelectionCriteria, strCriteriaStates); @@ -1116,11 +1090,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommman } if (strOutputFormat == "XML") { - // Get Root element where to export from - const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition = getConstSelectionCriteria()->getSelectionCriteriaDefinition(); - - if (!exportElementToXMLString(pSelectionCriteriaDefinition, "SelectionCriteria", - strResult)) { + if (!exportElementToXMLString(&mCriteria, "SelectionCriteria", strResult)) { return CCommandHandler::EFailed; } @@ -1133,7 +1103,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommman bool bHumanReadable = strOutputFormat.empty(); list lstrResult; - getSelectionCriteria()->listSelectionCriteria(lstrResult, true, bHumanReadable); + mCriteria.listSelectionCriteria(lstrResult, true, bHumanReadable); // Concatenate the criterion list as the command result CUtility::asString(lstrResult, strResult); @@ -1147,7 +1117,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmand { (void)remoteCommand; - getConfigurableDomains()->listDomains(strResult); + mDomains.listDomains(strResult); return CCommandHandler::ESucceeded; } @@ -1214,7 +1184,8 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenes CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed; + return mDomains.listDomainElements(remoteCommand.getArgument(0), strResult) ? + CCommandHandler::ESucceeded : CCommandHandler::EFailed; } CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) @@ -1235,7 +1206,8 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmand /// Configurations CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed; + return mDomains.listConfigurations(remoteCommand.getArgument(0), strResult) ? + CCommandHandler::ESucceeded : CCommandHandler::EFailed; } CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) @@ -1247,7 +1219,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmand CErrorContext errorContext(strError); // Dump - getConstConfigurableDomains()->dumpContent(strResult, errorContext); + mDomains.dumpContent(strResult, errorContext); return CCommandHandler::ESucceeded; } @@ -1276,10 +1248,10 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCo CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - list lstrResult; - if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) { + core::Results result; + if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), result)) { //Concatenate the error list as the command result - CUtility::asString(lstrResult, strResult); + CUtility::asString(result, strResult); return CCommandHandler::EFailed; } @@ -1307,7 +1279,10 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceC CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { // Delegate to configurable domains - return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed; + return mDomains.getElementSequence(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + strResult) ? + CCommandHandler::ESucceeded : CCommandHandler::EFailed; } CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) @@ -1337,7 +1312,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProc /// Elements/Parameters CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - CElementLocator elementLocator(getSystemClass(), false); + CElementLocator elementLocator(&mSystemClass, false); CElement* pLocatedElement = NULL; @@ -1353,7 +1328,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommman // List from root folder // Return system class qualified name - pLocatedElement = getSystemClass(); + pLocatedElement = &mSystemClass; } // Return sub-elements @@ -1365,7 +1340,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommman /// Elements/Parameters CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - CElementLocator elementLocator(getSystemClass(), false); + CElementLocator elementLocator(&mSystemClass, false); CElement* pLocatedElement = NULL; @@ -1381,7 +1356,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommm // List from root folder // Return system class qualified name - pLocatedElement = getSystemClass(); + pLocatedElement = &mSystemClass; } // Return sub-elements @@ -1392,7 +1367,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommm CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; @@ -1413,7 +1388,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmand CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; @@ -1433,7 +1408,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommm CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; @@ -1475,7 +1450,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommman CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; @@ -1495,7 +1470,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomain CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; @@ -1517,7 +1492,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedEleme { (void)remoteCommand; - getConfigurableDomains()->listAssociatedElements(strResult); + mDomains.listAssociatedElements(strResult); return CCommandHandler::ESucceeded; } @@ -1526,7 +1501,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElem { (void)remoteCommand; - getConfigurableDomains()->listConflictingElements(strResult); + mDomains.listConflictingElements(strResult); return CCommandHandler::ESucceeded; } @@ -1535,7 +1510,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCo { (void)remoteCommand; - getSystemClass()->listRogueElements(strResult); + mSystemClass.listRogueElements(strResult); return CCommandHandler::ESucceeded; } @@ -1682,9 +1657,7 @@ CParameterMgr::CCommandHandler::CommandStatus (void)remoteCommand; // Get Root element where to export from - const CSystemClass* pSystemClass = getSystemClass(); - - if (!exportElementToXMLString(pSystemClass, pSystemClass->getKind(), strResult)) { + if (!exportElementToXMLString(&mSystemClass, mSystemClass.getKind(), strResult)) { return CCommandHandler::EFailed; } @@ -1719,7 +1692,7 @@ bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult CPathNavigator pathNavigator(strPath); // Nagivate through system class - if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strResult)) { + if (!pathNavigator.navigateThrough(mSystemClass.getName(), strResult)) { return false; } @@ -1752,7 +1725,7 @@ bool CParameterMgr::getParameterMapping(const string& strPath, string& strResult // User set/get parameters in specific Configuration BlackBoard bool CParameterMgr::accessConfigurationValue(const string& strDomain, const string& strConfiguration, const string& strPath, string& strValue, bool bSet, string& strError) { - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; @@ -1768,14 +1741,28 @@ bool CParameterMgr::accessConfigurationValue(const string& strDomain, const stri uint32_t uiBaseOffset; bool bIsLastApplied; - CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError); + CParameterBlackboard* pConfigurationBlackboard = NULL; - if (!pConfigurationBlackboard) { - - return false; + { + LOG_CONTEXT("Find configuration blackboard for Domain: " + strDomain + + ", Configuration: " + strConfiguration + + ", Element: " + pConfigurableElement->getPath()); + + pConfigurationBlackboard = mDomains.findConfigurationBlackboard(strDomain, + strConfiguration, + pConfigurableElement, + uiBaseOffset, + bIsLastApplied, + strError); + if (!pConfigurationBlackboard) { + + warning() << "Fail: " << strError; + return false; + } } - log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset); + info() << "Element " << strPath << " in Domain " << strDomain << ", offset: " + << pConfigurableElement->getOffset() << ", base offset: " << uiBaseOffset; /// Update the Configuration Blackboard @@ -1826,7 +1813,7 @@ bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, CPathNavigator pathNavigator(strPath); // Nagivate through system class - if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) { + if (!pathNavigator.navigateThrough(mSystemClass.getName(), strError)) { parameterAccessContext.setError(strError); @@ -1834,14 +1821,14 @@ bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, } // Do the get - return getConstSystemClass()->accessValue(pathNavigator, strValue, bSet, parameterAccessContext); + return mSystemClass.accessValue(pathNavigator, strValue, bSet, parameterAccessContext); } // Tuning mode bool CParameterMgr::setTuningMode(bool bOn, string& strError) { // Tuning allowed? - if (bOn && !getConstFrameworkConfiguration()->isTuningAllowed()) { + if (bOn && !mPfwConfiguration.isTuningAllowed()) { strError = "Tuning prohibited"; @@ -1943,13 +1930,13 @@ bool CParameterMgr::sync(string& strError) // Get syncer set CSyncerSet syncerSet; // ... from system class - getConstSystemClass()->fillSyncerSet(syncerSet); + mSystemClass.fillSyncerSet(syncerSet); // Sync - list lstrError; - if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){ + core::Results error; + if (! syncerSet.sync(*_pMainParameterBlackboard, false, &error)){ - CUtility::asString(lstrError, strError); + CUtility::asString(error, strError); return false; }; @@ -1959,6 +1946,7 @@ bool CParameterMgr::sync(string& strError) // Configuration/Domains handling bool CParameterMgr::createDomain(const string& strName, string& strError) { + LOG_CONTEXT("Creating configurable domain " + strName); // Check tuning mode if (!checkTuningModeOn(strError)) { @@ -1966,129 +1954,167 @@ bool CParameterMgr::createDomain(const string& strName, string& strError) } // Delegate to configurable domains - return getConfigurableDomains()->createDomain(strName, strError); + return logResult(mDomains.createDomain(strName, strError), strError); } bool CParameterMgr::deleteDomain(const string& strName, string& strError) { + LOG_CONTEXT("Deleting configurable domain '" + strName + "'"); + // Check tuning mode if (!checkTuningModeOn(strError)) { + warning() << "Fail: " << strError; return false; } // Delegate to configurable domains - return getConfigurableDomains()->deleteDomain(strName, strError); + return logResult(mDomains.deleteDomain(strName, strError), strError); } bool CParameterMgr::renameDomain(const string& strName, const string& strNewName, string& strError) { + LOG_CONTEXT("Renaming configurable domain '" + strName + "' to '" + strNewName + "'"); + // Delegate to configurable domains - return getConfigurableDomains()->renameDomain(strName, strNewName, strError); + return logResult(mDomains.renameDomain(strName, strNewName, strError), strError); } bool CParameterMgr::deleteAllDomains(string& strError) { + LOG_CONTEXT("Deleting all configurable domains"); + // Check tuning mode if (!checkTuningModeOn(strError)) { + warning() << "Fail: " << strError; return false; } // Delegate to configurable domains - getConfigurableDomains()->deleteAllDomains(); + mDomains.deleteAllDomains(); + info() << "Success"; return true; } bool CParameterMgr::setSequenceAwareness(const string& strName, bool bSequenceAware, string& strResult) { + LOG_CONTEXT("Making domain '" + strName + + "' sequence " + (bSequenceAware ? "aware" : "unaware")); // Check tuning mode if (!checkTuningModeOn(strResult)) { + warning() << "Fail: " << strResult; return false; } - return getConfigurableDomains()->setSequenceAwareness(strName, bSequenceAware, strResult); + return logResult(mDomains.setSequenceAwareness(strName, bSequenceAware, strResult), strResult); } bool CParameterMgr::getSequenceAwareness(const string& strName, bool& bSequenceAware, string& strResult) { - return getConfigurableDomains()->getSequenceAwareness(strName, bSequenceAware, strResult); + return mDomains.getSequenceAwareness(strName, bSequenceAware, strResult); } bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { + LOG_CONTEXT("Creating domain configuration '" + strConfiguration + + "' into domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + warning() << "Fail: " << strError; return false; } // Delegate to configurable domains - return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError); + return logResult(mDomains.createConfiguration( + strDomain, strConfiguration, _pMainParameterBlackboard, strError), strError); } bool CParameterMgr::renameConfiguration(const string& strDomain, const string& strConfiguration, const string& strNewConfiguration, string& strError) { - return getConfigurableDomains()->renameConfiguration(strDomain, strConfiguration, - strNewConfiguration, strError); + LOG_CONTEXT("Renaming domain '" + strDomain + "''s configuration '" + + strConfiguration + "' to '" + strNewConfiguration + "'"); + + return logResult(mDomains.renameConfiguration( + strDomain, strConfiguration, strNewConfiguration, strError), strError); } bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { + LOG_CONTEXT("Deleting configuration '" + strConfiguration + + "' from domain '" + strDomain + "'"); + // Check tuning mode if (!checkTuningModeOn(strError)) { + warning() << "Fail:" << strError; return false; } // Delegate to configurable domains - return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError); + return logResult(mDomains.deleteConfiguration(strDomain, strConfiguration, strError), strError); } -bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list& lstrError) +bool CParameterMgr::restoreConfiguration(const string& strDomain, + const string& strConfiguration, + core::Results& errors) { string strError; + LOG_CONTEXT("Restoring domain '" + strDomain + "''s configuration '" + + strConfiguration + "' to parameter blackboard"); // Check tuning mode if (!checkTuningModeOn(strError)) { - lstrError.push_back(strError); + errors.push_back(strError); + warning() << "Fail:" << strError; return false; } // Delegate to configurable domains - return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError); + return logResult(mDomains.restoreConfiguration( + strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, errors), + strError); } bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { + LOG_CONTEXT("Saving domain '" + strDomain + "' configuration '" + + strConfiguration + "' from parameter blackboard"); // Check tuning mode if (!checkTuningModeOn(strError)) { + warning() << "Fail:" << strError; return false; } // Delegate to configurable domains - return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError); + return logResult(mDomains.saveConfiguration( + strDomain, strConfiguration, _pMainParameterBlackboard, strError), strError); } // Configurable element - domain association bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) { + LOG_CONTEXT("Adding configurable element '" + strConfigurableElementPath + + "to domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + warning() << "Fail: " << strError; return false; } - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { + warning() << "Fail: " << strError; return false; } @@ -2096,23 +2122,39 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError); + core::Results infos; + bool isSuccess = mDomains.addConfigurableElementToDomain( + strDomain, pConfigurableElement, _pMainParameterBlackboard, infos); + + if (isSuccess) { + info() << infos; + } else { + warning() << infos; + } + + CUtility::asString(infos, strError); + return isSuccess; } bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) { + LOG_CONTEXT("Removing configurable element '" + strConfigurableElementPath + + "' from domain '" + strDomain + "'"); + // Check tuning mode if (!checkTuningModeOn(strError)) { + warning() << "Fail:" << strError; return false; } - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { + warning() << "Fail:" << strError; return false; } @@ -2120,23 +2162,28 @@ bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError); + return logResult(mDomains.removeConfigurableElementFromDomain( + strDomain, pConfigurableElement, strError), strError); } bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError) { + LOG_CONTEXT("Splitting configurable element '" + strConfigurableElementPath + + "' domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + warning() << "Fail:" << strError; return false; } - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { + warning() << "Fail: " << strError; return false; } @@ -2144,7 +2191,17 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError); + core::Results infos; + bool isSuccess = mDomains.split(strDomain, pConfigurableElement, infos); + + if (isSuccess) { + info() << infos; + } else { + warning() << infos; + } + + CUtility::asString(infos, strError); + return isSuccess; } bool CParameterMgr::setElementSequence(const string& strDomain, const string& strConfiguration, @@ -2157,28 +2214,27 @@ bool CParameterMgr::setElementSequence(const string& strDomain, const string& st return false; } - return getConfigurableDomains()->setElementSequence(strDomain, strConfiguration, + return mDomains.setElementSequence(strDomain, strConfiguration, astrNewElementSequence, strError); } bool CParameterMgr::getApplicationRule(const string& strDomain, const string& strConfiguration, string& strResult) { - return getConfigurableDomains()->getApplicationRule(strDomain, strConfiguration, strResult); + return mDomains.getApplicationRule(strDomain, strConfiguration, strResult); } bool CParameterMgr::setApplicationRule(const string& strDomain, const string& strConfiguration, const string& strApplicationRule, string& strError) { - return getConfigurableDomains()->setApplicationRule(strDomain, strConfiguration, - strApplicationRule, getConstSelectionCriteria()->getSelectionCriteriaDefinition(), - strError); + return mDomains.setApplicationRule(strDomain, strConfiguration, strApplicationRule, + mCriteria, strError); } bool CParameterMgr::clearApplicationRule(const string& strDomain, const string& strConfiguration, string& strError) { - return getConfigurableDomains()->clearApplicationRule(strDomain, strConfiguration, strError); + return mDomains.clearApplicationRule(strDomain, strConfiguration, strError); } bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSettings, @@ -2197,15 +2253,10 @@ bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSetti return false; } - // Root element - CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); // Context - CXmlDomainImportContext xmlDomainImportContext(strError, bWithSettings, *getSystemClass()); - - // Selection criteria definition for rule creation - xmlDomainImportContext.setSelectionCriteriaDefinition( - getConstSelectionCriteria()->getSelectionCriteriaDefinition()); + CXmlDomainImportContext xmlDomainImportContext(strError, bWithSettings, + mSystemClass, mCriteria); // Init serializing context xmlDomainImportContext.set( @@ -2214,7 +2265,7 @@ bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSetti // Get Schema file associated to root element string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + - pConfigurableDomains->getKind() + ".xsd"; + mDomains.getKind() + ".xsd"; // Xml Source CXmlDocSource* pSource; @@ -2223,36 +2274,36 @@ bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSetti // when importing from a file strXmlSource is the file name pSource = new CXmlFileDocSource(strXmlSource, strXmlSchemaFilePath, - pConfigurableDomains->getKind(), - pConfigurableDomains->getName(), "SystemClassName", + mDomains.getKind(), + mDomains.getName(), "SystemClassName", _bValidateSchemasOnStart); } else { // when importing from an xml string, strXmlSource contains the string pSource = new CXmlStringDocSource(strXmlSource, strXmlSchemaFilePath, - pConfigurableDomains->getKind(), - pConfigurableDomains->getName(), "SystemClassName", + mDomains.getKind(), + mDomains.getName(), "SystemClassName", _bValidateSchemasOnStart); } // Start clean - pConfigurableDomains->clean(); + mDomains.clean(); // Use a doc sink that instantiate Configurable Domains from the given doc source - CXmlMemoryDocSink memorySink(pConfigurableDomains); + CXmlMemoryDocSink memorySink(&mDomains); bool bProcessSuccess = memorySink.process(*pSource, xmlDomainImportContext); if (!bProcessSuccess) { //Cleanup - pConfigurableDomains->clean(); + mDomains.clean(); } else { // Validate domains after XML import - pConfigurableDomains->validate(_pMainParameterBlackboard); + mDomains.validate(_pMainParameterBlackboard); } @@ -2325,8 +2376,6 @@ bool CParameterMgr::serializeElement(string& strXmlDest, bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile, string& strError) const { - const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains(); - CXmlDomainExportContext xmlDomainExportContext(strError, bWithSettings); xmlDomainExportContext.setValueSpaceRaw(_bValueSpaceIsRaw); @@ -2334,18 +2383,15 @@ bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, boo xmlDomainExportContext.setOutputRawFormat(_bOutputRawFormatIsHex); - return serializeElement(strXmlDest, xmlDomainExportContext, bToFile, - *pConfigurableDomains, strError); + return serializeElement(strXmlDest, xmlDomainExportContext, bToFile, mDomains, strError); } bool CParameterMgr::exportSingleDomainXml(string& strXmlDest, const string& strDomainName, bool bWithSettings, bool bToFile, string& strError) const { - const CConfigurableDomains* pAllDomains = getConstConfigurableDomains(); - // Element to be serialized const CConfigurableDomain* pRequestedDomain = - pAllDomains->findConfigurableDomain(strDomainName, strError); + mDomains.findConfigurableDomain(strDomainName, strError); if (!pRequestedDomain) { return false; @@ -2376,11 +2422,9 @@ bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strEr return false; } - // Root element - CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); // Serialize in - return pConfigurableDomains->serializeSettings(strFileName, false, _uiStructureChecksum, strError); + return mDomains.serializeSettings(strFileName, false, _uiStructureChecksum, strError); } bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strError) @@ -2393,11 +2437,8 @@ bool CParameterMgr::exportDomainsBinary(const string& strFileName, string& strEr return false; } - // Root element - CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); - // Serialize out - return pConfigurableDomains->serializeSettings(strFileName, true, _uiStructureChecksum, strError); + return mDomains.serializeSettings(strFileName, true, _uiStructureChecksum, strError); } // For tuning, check we're in tuning mode @@ -2444,7 +2485,8 @@ void CParameterMgr::feedElementLibraries() // Parameter creation CElementLibrary* pParameterCreationLibrary = new CElementLibrary; - pParameterCreationLibrary->addElementBuilder("Subsystem", new CSubsystemElementBuilder(getSystemClass()->getSubsystemLibrary())); + pParameterCreationLibrary->addElementBuilder( + "Subsystem", new CSubsystemElementBuilder(mSystemClass.getSubsystemLibrary())); pParameterCreationLibrary->addElementBuilder("ComponentType", new TNamedElementBuilderTemplate()); pParameterCreationLibrary->addElementBuilder("Component", new TNamedElementBuilderTemplate()); pParameterCreationLibrary->addElementBuilder("BitParameter", new TNamedElementBuilderTemplate()); @@ -2486,7 +2528,7 @@ void CParameterMgr::setForceNoRemoteInterface(bool bForceNoRemoteInterface) // Remote Processor Server connection handling bool CParameterMgr::handleRemoteProcessingInterface(string& strError) { - CAutoLog autoLog(this, "Handling remote processing interface"); + LOG_CONTEXT("Handling remote processing interface"); if (_bForceNoRemoteInterface) { // The user requested not to start the remote interface @@ -2494,9 +2536,9 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) } // Start server if tuning allowed - if (getConstFrameworkConfiguration()->isTuningAllowed()) { + if (mPfwConfiguration.isTuningAllowed()) { - log_info("Loading remote processor library"); + info() << "Loading remote processor library"; // Load library _pvLibRemoteProcessorHandle = dlopen("libremote-processor.so", RTLD_NOW); @@ -2527,15 +2569,16 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) } // Create server - _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler); + _pRemoteProcessorServer = + pfnCreateRemoteProcessorServer(mPfwConfiguration.getServerPort(), _pCommandHandler); - log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort()); + info() << "Starting remote processor server on port " << mPfwConfiguration.getServerPort(); // Start if (!_pRemoteProcessorServer->start()) { ostringstream oss; oss << "ParameterMgr: Unable to start remote processor server on port " - << getConstFrameworkConfiguration()->getServerPort(); + << mPfwConfiguration.getServerPort(); strError = oss.str(); return false; @@ -2545,66 +2588,23 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) return true; } -// Children typwise access -CParameterFrameworkConfiguration* CParameterMgr::getFrameworkConfiguration() -{ - return static_cast(getChild(EFrameworkConfiguration)); -} - -const CParameterFrameworkConfiguration* CParameterMgr::getConstFrameworkConfiguration() -{ - return getFrameworkConfiguration(); -} - -CSelectionCriteria* CParameterMgr::getSelectionCriteria() -{ - return static_cast(getChild(ESelectionCriteria)); -} - -const CSelectionCriteria* CParameterMgr::getConstSelectionCriteria() -{ - return static_cast(getChild(ESelectionCriteria)); -} - -CSystemClass* CParameterMgr::getSystemClass() -{ - return static_cast(getChild(ESystemClass)); -} - -const CSystemClass* CParameterMgr::getConstSystemClass() const -{ - return static_cast(getChild(ESystemClass)); -} - -// Configurable Domains -CConfigurableDomains* CParameterMgr::getConfigurableDomains() -{ - return static_cast(getChild(EConfigurableDomains)); -} - -const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() -{ - return static_cast(getChild(EConfigurableDomains)); -} - -const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const -{ - return static_cast(getChild(EConfigurableDomains)); -} - // Apply configurations void CParameterMgr::doApplyConfigurations(bool bForce) { + LOG_CONTEXT("Applying configurations"); + CSyncerSet syncerSet; + core::Results infos; // Check subsystems that need resync - getSystemClass()->checkForSubsystemsToResync(syncerSet); + mSystemClass.checkForSubsystemsToResync(syncerSet, infos); // Ensure application of currently selected configurations - getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce); + mDomains.apply(_pMainParameterBlackboard, syncerSet, bForce, infos); + info() << infos; // Reset the modified status of the current criteria to indicate that a new configuration has been applied - getSelectionCriteria()->resetModifiedStatus(); + mCriteria.resetModifiedStatus(); } // Export to XML string @@ -2632,3 +2632,26 @@ bool CParameterMgr::exportElementToXMLString(const IXmlSource* pXmlSource, return bProcessSuccess; } + +bool CParameterMgr::logResult(bool isSuccess, const std::string& result) +{ + std::string log = result.empty() ? "" : ": " + result; + + if (isSuccess) { + info() << "Success" << log; + } else { + warning() << "Fail" << log; + } + + return isSuccess; +} + +log::details::Info CParameterMgr::info() +{ + return _logger.info(); +} + +log::details::Warning CParameterMgr::warning() +{ + return _logger.warning(); +} diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index ef834eb7a..a92b1b8a2 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -32,39 +32,35 @@ #include #include #include -#include #include "RemoteCommandHandlerTemplate.h" #include "PathNavigator.h" -#include "SelectionCriterionType.h" -#include "SelectionCriterion.h" #include "Element.h" #include "XmlDocSink.h" #include "XmlDocSource.h" +#include "Results.h" +#include "ParameterFrameworkConfiguration.h" +#include "criterion/Criteria.h" +#include "ConfigurableDomains.h" +#include "SystemClass.h" +#include +#include +#include #include +#include class CElementLibrarySet; class CSubsystemLibrary; -class CSystemClass; -class CSelectionCriteria; -class CParameterFrameworkConfiguration; class CSystemClassConfiguration; class CParameterBlackboard; -class CConfigurableDomains; class IRemoteProcessorServerInterface; class CParameterHandle; class CSubsystemPlugins; class CParameterAccessContext; class CConfigurableElement; -class CParameterMgr : private CElement +class CParameterMgr { - enum ChildElement { - EFrameworkConfiguration, - ESelectionCriteria, - ESystemClass, - EConfigurableDomains - }; enum ElementLibrary { EFrameworkConfigurationLibrary, EParameterCreationLibrary, @@ -93,22 +89,11 @@ class CParameterMgr : private CElement // Parameter handle friendship friend class CParameterHandle; public: - // Logger interface - class ILogger - { - public: - virtual void log(bool bIsWarning, const std::string& strLog) = 0; - protected: - virtual ~ILogger() {} - }; // Construction - CParameterMgr(const std::string& strConfigurationFilePath); + CParameterMgr(const std::string& strConfigurationFilePath, core::log::ILogger& logger); virtual ~CParameterMgr(); - // Logging - void setLogger(ILogger* pLogger); - /** Load plugins, structures and settings from the config file given. * * @param[out] strError is a std::string describing the error if an error occurred @@ -118,11 +103,22 @@ class CParameterMgr : private CElement */ bool load(std::string& strError); - // Selection Criteria - CSelectionCriterionType* createSelectionCriterionType(bool bIsInclusive); - CSelectionCriterion* createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType); + /** Create a new Exclusive criterion + * + * @param[in] name, the criterion name + * @return raw pointer on the created criterion + */ + core::selection::criterion::Criterion* createExclusiveCriterion(const std::string& name); + + /** Create a new Inclusive criterion + * + * @param[in] name, the criterion name + * @return raw pointer on the created criterion + */ + core::selection::criterion::Criterion* createInclusiveCriterion(const std::string& name); + // Selection criterion retrieval - CSelectionCriterion* getSelectionCriterion(const std::string& strName); + core::selection::criterion::Criterion* getSelectionCriterion(const std::string& strName); // Configuration application void applyConfigurations(); @@ -253,8 +249,17 @@ class CParameterMgr : private CElement bool deleteConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); bool renameConfiguration(const std::string& strDomain, const std::string& strConfiguration, const std::string& strNewConfiguration, std::string& strError); - // Save/Restore - bool restoreConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::list& strError); + /** Restore a configuration + * + * @param[in] strDomain the domain name + * @param[in] strConfiguration the configuration name + * @param[out] errors errors encountered during restoration + * @return true if success false otherwise + */ + bool restoreConfiguration(const std::string& strDomain, + const std::string& strConfiguration, + core::Results& errors); + bool saveConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); // Configurable element - domain association @@ -357,14 +362,6 @@ class CParameterMgr : private CElement CParameterMgr(const CParameterMgr&); CParameterMgr& operator=(const CParameterMgr&); - // Init - virtual bool init(std::string& strError); - - // Logging (done by root) - virtual void doLog(bool bIsWarning, const std::string& strLog) const; - virtual void nestLog() const; - virtual void unnestLog() const; - // Version std::string getVersion() const; @@ -508,6 +505,13 @@ class CParameterMgr : private CElement // Framework global configuration loading bool loadFrameworkConfiguration(std::string& strError); + /** Load required subsystems + * + * @param[out] error error description if there is one + * @return true if succeed false otherwise + */ + bool loadSubsystems(std::string& error); + // System class Structure loading bool loadStructure(std::string& strError); @@ -545,24 +549,6 @@ class CParameterMgr : private CElement bool importDomainFromFile(const std::string& strXmlFilePath, bool bOverwrite, std::string& strError); - - // Framework Configuration - CParameterFrameworkConfiguration* getFrameworkConfiguration(); - const CParameterFrameworkConfiguration* getConstFrameworkConfiguration(); - - // Selection Criteria - CSelectionCriteria* getSelectionCriteria(); - const CSelectionCriteria* getConstSelectionCriteria(); - - // System Class - CSystemClass* getSystemClass(); - const CSystemClass* getConstSystemClass() const; - - // Configurable Domains - CConfigurableDomains* getConfigurableDomains(); - const CConfigurableDomains* getConstConfigurableDomains(); - const CConfigurableDomains* getConstConfigurableDomains() const; - // Apply configurations void doApplyConfigurations(bool bForce); @@ -572,6 +558,20 @@ class CParameterMgr : private CElement // Remote Processor Server connection handling bool handleRemoteProcessingInterface(std::string& strError); + /** Log the result of a function + * + * @param[in] isSuccess indicates if the previous function has succeed + * @param[in] result function provided result string + * @return isSuccess parameter + */ + bool logResult(bool isSuccess, const std::string& result); + + /** Info logger call helper */ + inline core::log::details::Info info(); + + /** Warning logger call helper */ + inline core::log::details::Warning warning(); + // Tuning bool _bTuningModeIsOn; @@ -624,9 +624,8 @@ class CParameterMgr : private CElement // Blackboard access mutex pthread_mutex_t _blackboardMutex; - // Logging - ILogger* _pLogger; - mutable uint32_t _uiLogDepth; + /** Application main logger based on the one provided by the client */ + core::log::Logger _logger; /** If set to false, the remote interface won't be started no matter what. * If set to true - the default - it has no impact on the policy for @@ -650,5 +649,17 @@ class CParameterMgr : private CElement * If set to false, no .xml/xsd validation will happen (default behaviour) */ bool _bValidateSchemasOnStart; + + /** Parameter Configuration information */ + CParameterFrameworkConfiguration mPfwConfiguration; + + /** Selection Criteria used in application rules */ + core::selection::criterion::Criteria mCriteria; + + /** Subsystems handler */ + CSystemClass mSystemClass; + + /** Application domains */ + CConfigurableDomains mDomains; }; diff --git a/parameter/ParameterMgrFullConnector.cpp b/parameter/ParameterMgrFullConnector.cpp index 099147580..50ac28526 100644 --- a/parameter/ParameterMgrFullConnector.cpp +++ b/parameter/ParameterMgrFullConnector.cpp @@ -34,12 +34,13 @@ #include using std::string; +using core::selection::criterion::CriterionInterface; CParameterMgrFullConnector::CParameterMgrFullConnector(const string& strConfigurationFilePath) : - _pParameterMgr(new CParameterMgr(strConfigurationFilePath)), _pLogger(NULL) + _pParameterMgrLogger(new CParameterMgrLogger(*this)), + _pParameterMgr(new CParameterMgr(strConfigurationFilePath, *_pParameterMgrLogger)), + _pLogger(NULL) { - _pParameterMgrLogger = new CParameterMgrLogger(*this); - _pParameterMgr->setLogger(_pParameterMgrLogger); } CParameterMgrFullConnector::~CParameterMgrFullConnector() @@ -61,11 +62,19 @@ void CParameterMgrFullConnector::setLogger(CParameterMgrFullConnector::ILogger* } // Private logging -void CParameterMgrFullConnector::doLog(bool bIsWarning, const string& strLog) +void CParameterMgrFullConnector::info(const string& log) { if (_pLogger) { - _pLogger->log(bIsWarning, strLog); + _pLogger->info(log); + } +} + +void CParameterMgrFullConnector::warning(const string& log) +{ + if (_pLogger) { + + _pLogger->warning(log); } } @@ -75,21 +84,17 @@ CParameterHandle* CParameterMgrFullConnector::createParameterHandle(const string return _pParameterMgr->createParameterHandle(strPath, strError); } -ISelectionCriterionTypeInterface* CParameterMgrFullConnector::createSelectionCriterionType( - bool bIsInclusive) +CriterionInterface* CParameterMgrFullConnector::createExclusiveCriterion(const string& name) { - return _pParameterMgr->createSelectionCriterionType(bIsInclusive); + return _pParameterMgr->createExclusiveCriterion(name); } -ISelectionCriterionInterface* CParameterMgrFullConnector::createSelectionCriterion( - const string& strName, - const ISelectionCriterionTypeInterface* pSelectionCriterionType) +CriterionInterface* CParameterMgrFullConnector::createInclusiveCriterion(const string& name) { - return _pParameterMgr->createSelectionCriterion(strName, - static_cast(pSelectionCriterionType)); + return _pParameterMgr->createInclusiveCriterion(name); } -ISelectionCriterionInterface* CParameterMgrFullConnector::getSelectionCriterion( +CriterionInterface* CParameterMgrFullConnector::getSelectionCriterion( const string& strName) { return _pParameterMgr->getSelectionCriterion(strName); @@ -267,9 +272,9 @@ bool CParameterMgrFullConnector::saveConfiguration(const string& strDomain, bool CParameterMgrFullConnector::restoreConfiguration(const string& strDomain, const string& strConfiguration, - std::list& lstrError) + Results& errors) { - return _pParameterMgr->restoreConfiguration(strDomain, strConfiguration, lstrError); + return _pParameterMgr->restoreConfiguration(strDomain, strConfiguration, errors); } bool CParameterMgrFullConnector::setSequenceAwareness(const string& strName, bool bSequenceAware, diff --git a/parameter/ParameterMgrLogger.h b/parameter/ParameterMgrLogger.h index 0e42d8a69..ee445b5aa 100644 --- a/parameter/ParameterMgrLogger.h +++ b/parameter/ParameterMgrLogger.h @@ -30,14 +30,14 @@ #pragma once #include "ParameterMgrLoggerForward.h" -#include "ParameterMgr.h" +#include #include -/* Wrap a class to expose its logging [log(bool, string&)] capabilities +/* Wrap a class to expose its logging [info, warning] capabilities * through ILogger. */ template -class CParameterMgrLogger : public CParameterMgr::ILogger +class CParameterMgrLogger : public core::log::ILogger { public: CParameterMgrLogger(T& parameterMgrConnector) : @@ -45,9 +45,14 @@ class CParameterMgrLogger : public CParameterMgr::ILogger { } - virtual void log(bool bIsWarning, const std::string& strLog) + virtual void info(const std::string& log) { - _parameterMgrConnector.doLog(bIsWarning, strLog); + _parameterMgrConnector.info(log); + } + + virtual void warning(const std::string& log) + { + _parameterMgrConnector.warning(log); } private: diff --git a/parameter/ParameterMgrPlatformConnector.cpp b/parameter/ParameterMgrPlatformConnector.cpp index d49003d7a..74ce4045a 100644 --- a/parameter/ParameterMgrPlatformConnector.cpp +++ b/parameter/ParameterMgrPlatformConnector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -33,15 +33,15 @@ #include using std::string; +using core::selection::criterion::CriterionInterface; // Construction CParameterMgrPlatformConnector::CParameterMgrPlatformConnector( const string& strConfigurationFilePath) : - _pParameterMgr(new CParameterMgr(strConfigurationFilePath)), _bStarted(false), _pLogger(NULL) + _pParameterMgrLogger(new CParameterMgrLogger(*this)), + _pParameterMgr(new CParameterMgr(strConfigurationFilePath, *_pParameterMgrLogger)), + _bStarted(false), _pLogger(NULL) { - // Logging - _pParameterMgrLogger = new CParameterMgrLogger(*this); - _pParameterMgr->setLogger(_pParameterMgrLogger); } CParameterMgrPlatformConnector::~CParameterMgrPlatformConnector() @@ -50,23 +50,22 @@ CParameterMgrPlatformConnector::~CParameterMgrPlatformConnector() delete _pParameterMgrLogger; } -// Selection Criteria interface. Beware returned objects are lent, clients shall not delete them! -ISelectionCriterionTypeInterface* CParameterMgrPlatformConnector::createSelectionCriterionType(bool bIsInclusive) +CriterionInterface* CParameterMgrPlatformConnector::createExclusiveCriterion(const string& name) { assert(!_bStarted); - return _pParameterMgr->createSelectionCriterionType(bIsInclusive); + return _pParameterMgr->createExclusiveCriterion(name); } -ISelectionCriterionInterface* CParameterMgrPlatformConnector::createSelectionCriterion(const string& strName, const ISelectionCriterionTypeInterface* pSelectionCriterionType) +CriterionInterface* CParameterMgrPlatformConnector::createInclusiveCriterion(const string& name) { assert(!_bStarted); - return _pParameterMgr->createSelectionCriterion(strName, static_cast(pSelectionCriterionType)); + return _pParameterMgr->createInclusiveCriterion(name); } -// Selection criterion retrieval -ISelectionCriterionInterface* CParameterMgrPlatformConnector::getSelectionCriterion(const string& strName) const +CriterionInterface* +CParameterMgrPlatformConnector::getSelectionCriterion(const string& strName) const { return _pParameterMgr->getSelectionCriterion(strName); } @@ -187,10 +186,18 @@ bool CParameterMgrPlatformConnector::isStarted() const } // Private logging -void CParameterMgrPlatformConnector::doLog(bool bIsWarning, const string& strLog) +void CParameterMgrPlatformConnector::info(const string& log) { if (_pLogger) { - _pLogger->log(bIsWarning, strLog); + _pLogger->info(log); + } +} + +void CParameterMgrPlatformConnector::warning(const string& log) +{ + if (_pLogger) { + + _pLogger->warning(log); } } diff --git a/parameter/ParameterType.cpp b/parameter/ParameterType.cpp index 01d94aa6e..d58237374 100644 --- a/parameter/ParameterType.cpp +++ b/parameter/ParameterType.cpp @@ -31,6 +31,7 @@ #include "Parameter.h" #include "ArrayParameter.h" #include "ParameterAccessContext.h" +#include "Utility.h" #define base CTypeElement @@ -98,7 +99,7 @@ void CParameterType::showProperties(string& strResult) const } // Scalar size - strResult += "Scalar size: " + toString(getSize()) + " byte(s) \n"; + strResult += "Scalar size: " +CUtility::toString(getSize()) + " byte(s) \n"; } // Default value handling (simulation only) diff --git a/parameter/AutoLog.h b/parameter/Results.h similarity index 79% rename from parameter/AutoLog.h rename to parameter/Results.h index 045451420..4d50cb0d5 100644 --- a/parameter/AutoLog.h +++ b/parameter/Results.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,24 +29,13 @@ */ #pragma once -#include "Element.h" - +#include #include -class CAutoLog +namespace core { -public: - CAutoLog(const CElement* pElement, const std::string& strContext, bool bLogOn = true); - ~CAutoLog(); -private: - CAutoLog(const CAutoLog&); - CAutoLog& operator=(const CAutoLog&); - // Logger element - const CElement* _pElement; - // Context - std::string _strContext; - // Log on - bool _bLogOn; -}; + /** String list type which can hold list of error/info */ + typedef std::list Results; +} /** core namespace */ diff --git a/parameter/RuleParser.cpp b/parameter/RuleParser.cpp index e77b3c8f9..42577c7d9 100644 --- a/parameter/RuleParser.cpp +++ b/parameter/RuleParser.cpp @@ -33,6 +33,7 @@ #include using std::string; +using namespace core::selection; // Matches const char* CRuleParser::_acDelimiters[CRuleParser::ENbStatuses] = { @@ -44,9 +45,9 @@ const char* CRuleParser::_acDelimiters[CRuleParser::ENbStatuses] = { "" // EDone }; -CRuleParser::CRuleParser(const string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition) : +CRuleParser::CRuleParser(const string& strApplicationRule, const criterion::Criteria& criteria) : _strApplicationRule(strApplicationRule), - _pSelectionCriteriaDefinition(pSelectionCriteriaDefinition), + mCriteria(criteria), _uiCurrentPos(0), _uiCurrentDeepness(0), _eStatus(CRuleParser::EInit), @@ -220,9 +221,9 @@ const string& CRuleParser::getType() const } // Criteria defintion -const CSelectionCriteriaDefinition* CRuleParser::getSelectionCriteriaDefinition() const +const criterion::Criteria& CRuleParser::getCriteria() const { - return _pSelectionCriteriaDefinition; + return mCriteria; } // Root rule diff --git a/parameter/RuleParser.h b/parameter/RuleParser.h index 803ea3e35..2e26a005f 100644 --- a/parameter/RuleParser.h +++ b/parameter/RuleParser.h @@ -29,11 +29,14 @@ */ #pragma once +#include + #include #include class CCompoundRule; -class CSelectionCriteriaDefinition; + +// FIXME: Add RuleParser in core::selection namespace class CRuleParser { @@ -49,7 +52,8 @@ class CRuleParser ENbStatuses }; - CRuleParser(const std::string& strApplicationRule, const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition); + CRuleParser(const std::string& strApplicationRule, + const core::selection::criterion::Criteria& criteria); ~CRuleParser(); // Parse @@ -64,8 +68,8 @@ class CRuleParser // Rule type const std::string& getType() const; - // Criteria defintion - const CSelectionCriteriaDefinition* getSelectionCriteriaDefinition() const; + /** Criteria getter */ + const core::selection::criterion::Criteria& getCriteria() const; // Root rule CCompoundRule* grabRootRule(); @@ -76,8 +80,10 @@ class CRuleParser // Rule definition std::string _strApplicationRule; - // Criteria defintion - const CSelectionCriteriaDefinition* _pSelectionCriteriaDefinition; + + /** Criteria definition */ + const core::selection::criterion::Criteria& mCriteria; + /** String iterator */ std::string::size_type _uiCurrentPos; // Deepness diff --git a/parameter/SelectionCriteria.cpp b/parameter/SelectionCriteria.cpp deleted file mode 100644 index 87ad76e52..000000000 --- a/parameter/SelectionCriteria.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2011-2014, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "SelectionCriteria.h" -#include "SelectionCriterionLibrary.h" -#include "SelectionCriteriaDefinition.h" - -#define base CElement - -CSelectionCriteria::CSelectionCriteria() -{ - addChild(new CSelectionCriterionLibrary); - addChild(new CSelectionCriteriaDefinition); -} - -std::string CSelectionCriteria::getKind() const -{ - return "SelectionCriteria"; -} - -// Selection Criteria/Type creation -CSelectionCriterionType* CSelectionCriteria::createSelectionCriterionType(bool bIsInclusive) -{ - return getSelectionCriterionLibrary()->createSelectionCriterionType(bIsInclusive); -} - -CSelectionCriterion* CSelectionCriteria::createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType) -{ - return getSelectionCriteriaDefinition()->createSelectionCriterion(strName, pSelectionCriterionType); -} - -// Selection criterion retrieval -CSelectionCriterion* CSelectionCriteria::getSelectionCriterion(const std::string& strName) -{ - return getSelectionCriteriaDefinition()->getSelectionCriterion(strName); -} - -// List available criteria -void CSelectionCriteria::listSelectionCriteria(std::list& lstrResult, bool bWithTypeInfo, bool bHumanReadable) const -{ - getSelectionCriteriaDefinition()->listSelectionCriteria(lstrResult, bWithTypeInfo, bHumanReadable); -} - -// Reset the modified status of the children -void CSelectionCriteria::resetModifiedStatus() -{ - getSelectionCriteriaDefinition()->resetModifiedStatus(); -} - -// Children access -CSelectionCriterionLibrary* CSelectionCriteria::getSelectionCriterionLibrary() -{ - return static_cast(getChild(ESelectionCriterionLibrary)); -} - -CSelectionCriteriaDefinition* CSelectionCriteria::getSelectionCriteriaDefinition() -{ - return static_cast(getChild(ESelectionCriteriaDefinition)); -} - -const CSelectionCriteriaDefinition* CSelectionCriteria::getSelectionCriteriaDefinition() const -{ - return static_cast(getChild(ESelectionCriteriaDefinition)); -} diff --git a/parameter/SelectionCriteria.h b/parameter/SelectionCriteria.h deleted file mode 100644 index 122b8a234..000000000 --- a/parameter/SelectionCriteria.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2011-2014, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#pragma once - -#include -#include "Element.h" -#include "SelectionCriterionType.h" -#include "SelectionCriterion.h" - -#include - -class CSelectionCriterionLibrary; -class CSelectionCriteriaDefinition; -class ISelectionCriterionObserver; - -class CSelectionCriteria : public CElement -{ - enum ChildElementType { - ESelectionCriterionLibrary, - ESelectionCriteriaDefinition - }; -public: - CSelectionCriteria(); - - // Selection Criteria/Type creation - CSelectionCriterionType* createSelectionCriterionType(bool bIsInclusive); - CSelectionCriterion* createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType); - // Selection criterion retrieval - CSelectionCriterion* getSelectionCriterion(const std::string& strName); - - // Selection Criterion definition - const CSelectionCriteriaDefinition* getSelectionCriteriaDefinition() const; - - // List available criteria - void listSelectionCriteria(std::list& strResult, bool bWithTypeInfo, bool bHumanReadable) const; - - // Base - virtual std::string getKind() const; - - // Reset the modified status of the children - void resetModifiedStatus(); -private: - // Children access - CSelectionCriterionLibrary* getSelectionCriterionLibrary(); - CSelectionCriteriaDefinition* getSelectionCriteriaDefinition(); -}; diff --git a/parameter/SelectionCriteriaDefinition.cpp b/parameter/SelectionCriteriaDefinition.cpp deleted file mode 100644 index d7c422894..000000000 --- a/parameter/SelectionCriteriaDefinition.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2011-2014, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "SelectionCriteriaDefinition.h" -#include "SelectionCriterion.h" - -CSelectionCriteriaDefinition::CSelectionCriteriaDefinition() -{ -} - -std::string CSelectionCriteriaDefinition::getKind() const -{ - return "SelectionCriteriaDefinition"; -} - -// Selection Criterion creation -CSelectionCriterion* CSelectionCriteriaDefinition::createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType) -{ - CSelectionCriterion* pSelectionCriterion = new CSelectionCriterion(strName, pSelectionCriterionType); - - addChild(pSelectionCriterion); - - return pSelectionCriterion; -} - -// Selection Criterion access -const CSelectionCriterion* CSelectionCriteriaDefinition::getSelectionCriterion(const std::string& strName) const -{ - return static_cast(findChild(strName)); -} - -CSelectionCriterion* CSelectionCriteriaDefinition::getSelectionCriterion(const std::string& strName) -{ - return static_cast(findChild(strName)); -} - -// List available criteria -void CSelectionCriteriaDefinition::listSelectionCriteria(std::list& lstrResult, bool bWithTypeInfo, bool bHumanReadable) const -{ - // Propagate - size_t uiNbChildren = getNbChildren(); - size_t uiChild; - - for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { - - const CSelectionCriterion* pSelectionCriterion = static_cast(getChild(uiChild)); - - lstrResult.push_back(pSelectionCriterion->getFormattedDescription(bWithTypeInfo, bHumanReadable)); - } -} - -// Reset the modified status of the children -void CSelectionCriteriaDefinition::resetModifiedStatus() -{ - // Propagate - size_t uiNbChildren = getNbChildren(); - size_t uiChild; - CSelectionCriterion* pSelectionCriterion; - - for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { - - pSelectionCriterion = static_cast(getChild(uiChild)); - - pSelectionCriterion->resetModifiedStatus(); - } -} diff --git a/parameter/SelectionCriterion.cpp b/parameter/SelectionCriterion.cpp deleted file mode 100644 index 781892401..000000000 --- a/parameter/SelectionCriterion.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2011-2014, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "SelectionCriterion.h" -#include "AutoLog.h" - -#define base CElement - -CSelectionCriterion::CSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pType) : base(strName), _iState(0), _pType(pType), _uiNbModifications(0) -{ -} - -std::string CSelectionCriterion::getKind() const -{ - return "SelectionCriterion"; -} - -bool CSelectionCriterion::hasBeenModified() const -{ - return _uiNbModifications != 0; -} - -void CSelectionCriterion::resetModifiedStatus() -{ - _uiNbModifications = 0; -} - -/// From ISelectionCriterionInterface -// State -void CSelectionCriterion::setCriterionState(int iState) -{ - // Check for a change - if (_iState != iState) { - - _iState = iState; - - log_info("Selection criterion changed event: %s", getFormattedDescription(false, false).c_str()); - - // Check if the previous criterion value has been taken into account (i.e. at least one Configuration was applied - // since the last criterion change) - if (_uiNbModifications != 0) { - - log_warning("Selection criterion \"%s\" has been modified %d time(s) without any configuration application", getName().c_str(), _uiNbModifications); - } - - // Track the number of modifications for this criterion - _uiNbModifications++; - } -} - -int CSelectionCriterion::getCriterionState() const -{ - return _iState; -} - -// Name -std::string CSelectionCriterion::getCriterionName() const -{ - return getName(); -} - -// Type -const ISelectionCriterionTypeInterface* CSelectionCriterion::getCriterionType() const -{ - return _pType; -} - -/// Match methods -bool CSelectionCriterion::is(int iState) const -{ - return _iState == iState; -} - -bool CSelectionCriterion::isNot(int iState) const -{ - return _iState != iState; -} - -bool CSelectionCriterion::includes(int iState) const -{ - // For inclusive criterion, Includes checks if ALL the bit sets in iState are set in the - // current _iState. - return (_iState & iState) == iState; -} - -bool CSelectionCriterion::excludes(int iState) const -{ - return (_iState & iState) == 0; -} - -/// User request -std::string CSelectionCriterion::getFormattedDescription(bool bWithTypeInfo, bool bHumanReadable) const -{ - std::string strFormattedDescription; - - if (bHumanReadable) { - - if (bWithTypeInfo) { - - // Display type info - appendTitle(strFormattedDescription, getName() + ":"); - - // States - strFormattedDescription += "Possible states "; - - // Type Kind - strFormattedDescription += "("; - strFormattedDescription += _pType->isTypeInclusive() ? "Inclusive" : "Exclusive"; - strFormattedDescription += "): "; - - // States - strFormattedDescription += _pType->listPossibleValues() + "\n"; - - // Current State - strFormattedDescription += "Current state"; - } else { - // Name only - strFormattedDescription = getName(); - } - - // Current State - strFormattedDescription += " = " + _pType->getFormattedState(_iState); - } else { - // Name - strFormattedDescription = "Criterion name: " + getName(); - - if (bWithTypeInfo) { - // Type Kind - strFormattedDescription += ", type kind: "; - strFormattedDescription += _pType->isTypeInclusive() ? "inclusive" : "exclusive"; - } - - // Current State - strFormattedDescription += ", current state: " + - _pType->getFormattedState(_iState); - - if (bWithTypeInfo) { - // States - strFormattedDescription += ", states: " + - _pType->listPossibleValues(); - } - } - return strFormattedDescription; -} - -// XML export -void CSelectionCriterion::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const -{ - // Current Value - xmlElement.setAttributeString("Value", _pType->getFormattedState(_iState)); - - // Serialize Type node - _pType->toXml(xmlElement, serializingContext); - - base::toXml(xmlElement, serializingContext); -} diff --git a/parameter/SelectionCriterion.h b/parameter/SelectionCriterion.h deleted file mode 100644 index cf9903502..000000000 --- a/parameter/SelectionCriterion.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2011-2014, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#pragma once - -#include "Element.h" -#include "SelectionCriterionType.h" -#include "SelectionCriterionInterface.h" - -#include - -class CSelectionCriterion : public CElement, public ISelectionCriterionInterface -{ -public: - CSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pType); - - /// From ISelectionCriterionInterface - // State - virtual void setCriterionState(int iState); - virtual int getCriterionState() const; - // Name - virtual std::string getCriterionName() const; - // Type - virtual const ISelectionCriterionTypeInterface* getCriterionType() const; - // Modified status - bool hasBeenModified() const; - void resetModifiedStatus(); - - /// Match methods - bool is(int iState) const; - bool isNot(int iState) const; - bool includes(int iState) const; - bool excludes(int iState) const; - - /// User request - std::string getFormattedDescription(bool bWithTypeInfo, bool bHumanReadable) const; - - /// From CElement - virtual std::string getKind() const; - - /** - * Export to XML - * - * @param[in] xmlElement The XML element to export to - * @param[in] serializingContext The serializing context - * - */ - virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; -private: - // Current state - int _iState; - // Type - const CSelectionCriterionType* _pType; - // Counter to know how many modifications have been applied to this criterion - uint8_t _uiNbModifications; -}; - diff --git a/parameter/SelectionCriterionLibrary.cpp b/parameter/SelectionCriterionLibrary.cpp deleted file mode 100644 index 6910e4132..000000000 --- a/parameter/SelectionCriterionLibrary.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2011-2014, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "SelectionCriterionLibrary.h" - -#define base CElement - -CSelectionCriterionLibrary::CSelectionCriterionLibrary() -{ -} - -std::string CSelectionCriterionLibrary::getKind() const -{ - return "SelectionCriterionLibrary"; -} - -// Type creation -CSelectionCriterionType* CSelectionCriterionLibrary::createSelectionCriterionType(bool bIsInclusive) -{ - CSelectionCriterionType* pSelectionCriterionType = new CSelectionCriterionType(bIsInclusive); - - addChild(pSelectionCriterionType); - - return pSelectionCriterionType; -} diff --git a/parameter/SelectionCriterionRule.cpp b/parameter/SelectionCriterionRule.cpp index c376bb303..a86130d07 100644 --- a/parameter/SelectionCriterionRule.cpp +++ b/parameter/SelectionCriterionRule.cpp @@ -28,26 +28,19 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "SelectionCriterionRule.h" -#include "SelectionCriterion.h" #include "XmlDomainSerializingContext.h" #include "XmlDomainImportContext.h" -#include "SelectionCriteriaDefinition.h" -#include "SelectionCriterionTypeInterface.h" #include "RuleParser.h" +#include + #include #define base CRule using std::string; -const CSelectionCriterionRule::SMatchingRuleDescription CSelectionCriterionRule::_astMatchesWhen[CSelectionCriterionRule::ENbMatchesWhen] = { - { "Is", true }, - { "IsNot", true }, - { "Includes", false }, - { "Excludes", false } -}; - -CSelectionCriterionRule::CSelectionCriterionRule() : _pSelectionCriterion(NULL), _eMatchesWhen(CSelectionCriterionRule::EIs), _iMatchValue(0) +CSelectionCriterionRule::CSelectionCriterionRule() : + _pSelectionCriterion(NULL), mMatchesWhenVerb(""), _iMatchValue(0) { } @@ -70,7 +63,7 @@ void CSelectionCriterionRule::logValue(string& strValue, CErrorContext& errorCon bool CSelectionCriterionRule::parse(CRuleParser& ruleParser, string& strError) { // Criterion - _pSelectionCriterion = ruleParser.getSelectionCriteriaDefinition()->getSelectionCriterion(ruleParser.getType()); + _pSelectionCriterion = ruleParser.getCriteria().getSelectionCriterion(ruleParser.getType()); // Check existence if (!_pSelectionCriterion) { @@ -81,9 +74,7 @@ bool CSelectionCriterionRule::parse(CRuleParser& ruleParser, string& strError) } // Verb - string strMatchesWhen; - - if (!ruleParser.next(strMatchesWhen, strError)) { + if (!ruleParser.next(mMatchesWhenVerb, strError)) { return false; } @@ -96,15 +87,17 @@ bool CSelectionCriterionRule::parse(CRuleParser& ruleParser, string& strError) } // Matches when - if (!setMatchesWhen(strMatchesWhen, strError)) { + if (!_pSelectionCriterion->isMatchMethodAvailable(mMatchesWhenVerb)) { - strError = "Verb error: " + strError; + strError = "Matche type: " + mMatchesWhenVerb + " incompatible with " + + (_pSelectionCriterion->isInclusive() ? "inclusive" : "exclusive") + + " criterion: " + _pSelectionCriterion->getCriterionName(); return false; } // Value - if (!_pSelectionCriterion->getCriterionType()->getNumericalValue(strValue, _iMatchValue)) { + if (!_pSelectionCriterion->getNumericalValue(strValue, _iMatchValue)) { strError = "Value error: \"" + strValue + "\" is not part of criterion \"" + _pSelectionCriterion->getCriterionName() + "\""; @@ -119,14 +112,14 @@ bool CSelectionCriterionRule::parse(CRuleParser& ruleParser, string& strError) void CSelectionCriterionRule::dump(string& strResult) const { // Criterion - strResult += _pSelectionCriterion->getName(); + strResult += _pSelectionCriterion->getCriterionName(); strResult += " "; // Verb - strResult += _astMatchesWhen[_eMatchesWhen].pcMatchesWhen; + strResult += mMatchesWhenVerb; strResult += " "; // Value string strValue; - _pSelectionCriterion->getCriterionType()->getLiteralValue(_iMatchValue, strValue); + _pSelectionCriterion->getLiteralValue(_iMatchValue, strValue); strResult += strValue; } @@ -135,19 +128,7 @@ bool CSelectionCriterionRule::matches() const { assert(_pSelectionCriterion); - switch(_eMatchesWhen) { - case EIs: - return _pSelectionCriterion->is(_iMatchValue); - case EIsNot: - return _pSelectionCriterion->isNot(_iMatchValue); - case EIncludes: - return _pSelectionCriterion->includes(_iMatchValue); - case EExcludes: - return _pSelectionCriterion->excludes(_iMatchValue); - default: - assert(0); - return false; - } + return _pSelectionCriterion->match(mMatchesWhenVerb, _iMatchValue); } // From IXmlSink @@ -159,7 +140,8 @@ bool CSelectionCriterionRule::fromXml(const CXmlElement& xmlElement, CXmlSeriali // Get selection criterion string strSelectionCriterion = xmlElement.getAttributeString("SelectionCriterion"); - _pSelectionCriterion = xmlDomainImportContext.getSelectionCriteriaDefinition()->getSelectionCriterion(strSelectionCriterion); + _pSelectionCriterion = + xmlDomainImportContext.getCriteria().getSelectionCriterion(strSelectionCriterion); // Check existence if (!_pSelectionCriterion) { @@ -170,12 +152,14 @@ bool CSelectionCriterionRule::fromXml(const CXmlElement& xmlElement, CXmlSeriali } // Get MatchesWhen - string strMatchesWhen = xmlElement.getAttributeString("MatchesWhen"); + mMatchesWhenVerb = xmlElement.getAttributeString("MatchesWhen"); string strError; - if (!setMatchesWhen(strMatchesWhen, strError)) { + if (!_pSelectionCriterion->isMatchMethodAvailable(mMatchesWhenVerb)) { - xmlDomainImportContext.setError("Wrong MatchesWhen attribute " + strMatchesWhen + " in " + getKind() + " " + xmlElement.getPath() + ": " + strError); + xmlDomainImportContext.setError("Wrong MatchesWhen attribute " + mMatchesWhenVerb + " in " + + getKind() + " " + xmlElement.getPath() + ": " + + _pSelectionCriterion->getCriterionName()); return false; } @@ -183,7 +167,7 @@ bool CSelectionCriterionRule::fromXml(const CXmlElement& xmlElement, CXmlSeriali // Get Value string strValue = xmlElement.getAttributeString("Value"); - if (!_pSelectionCriterion->getCriterionType()->getNumericalValue(strValue, _iMatchValue)) { + if (!_pSelectionCriterion->getNumericalValue(strValue, _iMatchValue)) { xmlDomainImportContext.setError("Wrong Value attribute value " + strValue + " in " + getKind() + " " + xmlElement.getPath()); @@ -202,51 +186,15 @@ void CSelectionCriterionRule::toXml(CXmlElement& xmlElement, CXmlSerializingCont assert(_pSelectionCriterion); // Set selection criterion - xmlElement.setAttributeString("SelectionCriterion", _pSelectionCriterion->getName()); + xmlElement.setAttributeString("SelectionCriterion", _pSelectionCriterion->getCriterionName()); // Set MatchesWhen - xmlElement.setAttributeString("MatchesWhen", _astMatchesWhen[_eMatchesWhen].pcMatchesWhen); + xmlElement.setAttributeString("MatchesWhen", mMatchesWhenVerb); // Set Value string strValue; - _pSelectionCriterion->getCriterionType()->getLiteralValue(_iMatchValue, strValue); + _pSelectionCriterion->getLiteralValue(_iMatchValue, strValue); xmlElement.setAttributeString("Value", strValue); } - -// XML MatchesWhen attribute parsing -bool CSelectionCriterionRule::setMatchesWhen(const string& strMatchesWhen, string& strError) -{ - uint32_t uiMatchesWhen; - - for (uiMatchesWhen = 0; uiMatchesWhen < ENbMatchesWhen; uiMatchesWhen++) { - - const SMatchingRuleDescription* pstMatchingRuleDescription = &_astMatchesWhen[uiMatchesWhen]; - - if (strMatchesWhen == pstMatchingRuleDescription->pcMatchesWhen) { - - // Found it! - - // Get Type - const ISelectionCriterionTypeInterface* pSelectionCriterionType = _pSelectionCriterion->getCriterionType(); - - // Check compatibility if relevant - if (!pSelectionCriterionType->isTypeInclusive() && !pstMatchingRuleDescription->bExclusiveTypeCompatible) { - - strError = "Value incompatible with exclusive kind of type"; - - return false; - } - - // Store - _eMatchesWhen = (MatchesWhen)uiMatchesWhen; - - return true; - } - } - - strError = "Value not found"; - - return false; -} diff --git a/parameter/SelectionCriterionRule.h b/parameter/SelectionCriterionRule.h index 70bddc2cb..5d58d69c2 100644 --- a/parameter/SelectionCriterionRule.h +++ b/parameter/SelectionCriterionRule.h @@ -30,29 +30,14 @@ #pragma once #include "Rule.h" +#include #include -class CSelectionCriterion; +// FIXME: Add SelectionCriterionRule in core::selection namespace class CSelectionCriterionRule : public CRule { - // Matching rules - enum MatchesWhen { - EIs, - EIsNot, - EIncludes, - EExcludes, - - ENbMatchesWhen - }; - // Matching rule description - struct SMatchingRuleDescription - { - const char* pcMatchesWhen; - bool bExclusiveTypeCompatible; - }; - public: CSelectionCriterionRule(); @@ -77,19 +62,18 @@ class CSelectionCriterionRule : public CRule // Content dumping virtual void logValue(std::string& strValue, CErrorContext& errorContext) const; private: - // XML MatchesWhen attribute parsing - bool setMatchesWhen(const std::string& strMatchesWhen, std::string& strError); - // Selection criterion - const CSelectionCriterion* _pSelectionCriterion; + const core::selection::criterion::Criterion* _pSelectionCriterion; - // MatchesWhen - MatchesWhen _eMatchesWhen; + /** Method name used to match the criterion state + * + * FIXME: If performance is critical in this part of the code, it's possible + * to store directly the match method of the criterion as it is retrieved + * at loading time. + */ + std::string mMatchesWhenVerb; // Value int32_t _iMatchValue; - - // Used for XML MatchesWhen attribute parsing - static const SMatchingRuleDescription _astMatchesWhen[ENbMatchesWhen]; }; diff --git a/parameter/SelectionCriterionType.cpp b/parameter/SelectionCriterionType.cpp deleted file mode 100644 index ce633c6f0..000000000 --- a/parameter/SelectionCriterionType.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright (c) 2011-2014, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include "SelectionCriterionType.h" -#include "Tokenizer.h" - -#define base CElement - -const std::string CSelectionCriterionType::_strDelimiter = "|"; - -CSelectionCriterionType::CSelectionCriterionType(bool bIsInclusive) : _bInclusive(bIsInclusive) -{ - // For inclusive criterion type, appends the pair none,0 by default. - if (_bInclusive) { - - _numToLitMap["none"] = 0; - } -} - -std::string CSelectionCriterionType::getKind() const -{ - return "SelectionCriterionType"; -} - -// From ISelectionCriterionTypeInterface -bool CSelectionCriterionType::addValuePair(int iValue, const std::string& strValue) -{ - // Check 1 bit set only for inclusive types - if (_bInclusive && (!iValue || (iValue & (iValue - 1)))) { - - log_warning("Rejecting value pair association: 0x%X - %s for Selection Criterion Type %s", iValue, strValue.c_str(), getName().c_str()); - - return false; - } - - // Check already inserted - if (_numToLitMap.find(strValue) != _numToLitMap.end()) { - - log_warning("Rejecting value pair association (literal already present): 0x%X - %s for Selection Criterion Type %s", iValue, strValue.c_str(), getName().c_str()); - - return false; - } - _numToLitMap[strValue] = iValue; - - return true; -} - -bool CSelectionCriterionType::getNumericalValue(const std::string& strValue, int& iValue) const -{ - if (_bInclusive) { - - Tokenizer tok(strValue, _strDelimiter); - std::vector astrValues = tok.split(); - size_t uiNbValues = astrValues.size(); - int iResult = 0; - size_t uiValueIndex; - iValue = 0; - - // Looping on each std::string delimited by "|" token and adding the associated value - for (uiValueIndex = 0; uiValueIndex < uiNbValues; uiValueIndex++) { - - if (!getAtomicNumericalValue(astrValues[uiValueIndex], iResult)) { - - return false; - } - iValue |= iResult; - } - return true; - } - return getAtomicNumericalValue(strValue, iValue); -} - -bool CSelectionCriterionType::getAtomicNumericalValue(const std::string& strValue, int& iValue) const -{ - NumToLitMapConstIt it = _numToLitMap.find(strValue); - - if (it != _numToLitMap.end()) { - - iValue = it->second; - - return true; - } - return false; -} - -bool CSelectionCriterionType::getLiteralValue(int iValue, std::string& strValue) const -{ - NumToLitMapConstIt it; - - for (it = _numToLitMap.begin(); it != _numToLitMap.end(); ++it) { - - if (it->second == iValue) { - - strValue = it->first; - - return true; - } - } - return false; -} - -bool CSelectionCriterionType::isTypeInclusive() const -{ - return _bInclusive; -} - -// Value list -std::string CSelectionCriterionType::listPossibleValues() const -{ - std::string strValueList = "{"; - - // Get comma seprated list of values - NumToLitMapConstIt it; - bool bFirst = true; - - for (it = _numToLitMap.begin(); it != _numToLitMap.end(); ++it) { - - if (bFirst) { - - bFirst = false; - } else { - strValueList += ", "; - } - strValueList += it->first; - } - - strValueList += "}"; - - return strValueList; -} - -// Formatted state -std::string CSelectionCriterionType::getFormattedState(int iValue) const -{ - std::string strFormattedState; - - if (_bInclusive) { - - // Need to go through all set bit - uint32_t uiBit; - bool bFirst = true; - - for (uiBit = 0; uiBit < sizeof(iValue) * 8; uiBit++) { - - int iSingleBitValue = iValue & (1 << uiBit); - - // Check if current bit is set - if (!iSingleBitValue) { - - continue; - } - - // Simple translation - std::string strSingleValue; - - if (!getLiteralValue(iSingleBitValue, strSingleValue)) { - // Numeric value not part supported values for this criterion type. - continue; - } - - if (bFirst) { - - bFirst = false; - } else { - strFormattedState += "|"; - } - - strFormattedState += strSingleValue; - } - - } else { - // Simple translation - getLiteralValue(iValue, strFormattedState); - } - - // Sometimes nothing is set - if (strFormattedState.empty()) { - - strFormattedState = ""; - } - - return strFormattedState; -} - -// From IXmlSource -void CSelectionCriterionType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const -{ - // Type Kind - xmlElement.setAttributeString("Kind", isTypeInclusive() ? "Inclusive" : "Exclusive"); - - // Value pairs as children - NumToLitMapConstIt it; - - for (it = _numToLitMap.begin(); it != _numToLitMap.end(); ++it) { - - CXmlElement childValuePairElement; - - xmlElement.createChild(childValuePairElement, "ValuePair"); - // Literal - childValuePairElement.setAttributeString("Literal", it->first); - // Numerical - childValuePairElement.setAttributeSignedInteger("Numerical", it->second); - } - - base::toXml(xmlElement, serializingContext); -} diff --git a/parameter/SelectionCriterionType.h b/parameter/SelectionCriterionType.h deleted file mode 100644 index ef4176a3f..000000000 --- a/parameter/SelectionCriterionType.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2011-2014, Intel Corporation - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors - * may be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#pragma once - -#include "Element.h" -#include -#include -#include "SelectionCriterionTypeInterface.h" - -class CSelectionCriterionType : public CElement, public ISelectionCriterionTypeInterface -{ - typedef std::map::const_iterator NumToLitMapConstIt; - -public: - CSelectionCriterionType(bool bIsInclusive); - - // From ISelectionCriterionTypeInterface - virtual bool addValuePair(int iValue, const std::string& strValue); - /** - * Retrieve the numerical value from the std::string representation of the criterion type. - * - * @param[in] strValue: criterion type value represented as a stream. If the criterion is - * inclusive, it supports more than one criterion type value delimited - * by the "|" symbol. - * @param[out] iValue: criterion type value represented as an integer. - * - * @return true if integer value retrieved from the std::string one, false otherwise. - */ - virtual bool getNumericalValue(const std::string& strValue, int& iValue) const; - virtual bool getLiteralValue(int iValue, std::string& strValue) const; - virtual bool isTypeInclusive() const; - - // Value list - std::string listPossibleValues() const; - - // Formatted state - virtual std::string getFormattedState(int iValue) const; - - /** - * Export to XML - * - * @param[in] xmlElement The XML element to export to - * @param[in] serializingContext The serializing context - * - */ - virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; - - // From CElement - virtual std::string getKind() const; -private: - /** - * Retrieve the numerical value from the std::string representation of the criterion type. - * - * @param[in] strValue: criterion type value represented as a stream. If the criterion is - * inclusive, it expects only one criterion type value. - * @param[out] iValue: criterion type value represented as an integer. - * - * @return true if integer value retrieved from the std::string one, false otherwise. - */ - bool getAtomicNumericalValue(const std::string& strValue, int& iValue) const; - bool _bInclusive; - std::map _numToLitMap; - - static const std::string _strDelimiter; /**< Inclusive criterion type delimiter. */ -}; - diff --git a/parameter/StringParameterType.cpp b/parameter/StringParameterType.cpp index d47895d0c..321dc9751 100644 --- a/parameter/StringParameterType.cpp +++ b/parameter/StringParameterType.cpp @@ -29,6 +29,7 @@ */ #include "StringParameterType.h" #include "StringParameter.h" +#include "Utility.h" #define base CTypeElement @@ -51,7 +52,7 @@ void CStringParameterType::showProperties(string& strResult) const // Max length strResult += "Max length: "; - strResult += toString(_uiMaxLength); + strResult += CUtility::toString(_uiMaxLength); strResult += "\n"; } diff --git a/parameter/Subsystem.cpp b/parameter/Subsystem.cpp index 5dbe3a073..0f337d714 100644 --- a/parameter/Subsystem.cpp +++ b/parameter/Subsystem.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -35,6 +35,7 @@ #include "ConfigurationAccessContext.h" #include "SubsystemObjectCreator.h" #include "MappingData.h" +#include "Utility.h" #include #include @@ -44,7 +45,10 @@ using std::string; using std::list; using std::ostringstream; -CSubsystem::CSubsystem(const string& strName) : base(strName), _pComponentLibrary(new CComponentLibrary), _pInstanceDefinition(new CInstanceDefinition), _bBigEndian(false), _pMappingData(NULL) +CSubsystem::CSubsystem(const string& strName, core::log::Logger& logger) + : base(strName), _pComponentLibrary(new CComponentLibrary), + _pInstanceDefinition(new CInstanceDefinition), _bBigEndian(false), _pMappingData(NULL), + _logger(logger) { // Note: A subsystem contains instance components // InstanceDefintion and ComponentLibrary objects are then not chosen to be children @@ -440,7 +444,8 @@ bool CSubsystem::handleSubsystemObjectCreation( pSubsystemObjectCreator->getMaxConfigurableElementSize()) { string strSizeError = "Size should not exceed " + - toString(pSubsystemObjectCreator->getMaxConfigurableElementSize()); + CUtility::toString( + pSubsystemObjectCreator->getMaxConfigurableElementSize()); strError = getMappingError(strKey, strSizeError, pInstanceConfigurableElement); @@ -449,7 +454,7 @@ bool CSubsystem::handleSubsystemObjectCreation( // Do create object and keep its track _subsystemObjectList.push_back(pSubsystemObjectCreator->objectCreate( - *pStrValue, pInstanceConfigurableElement, context)); + *pStrValue, pInstanceConfigurableElement, context, _logger)); // Indicate subsytem creation to caller bHasCreatedSubsystemObject = true; @@ -529,3 +534,9 @@ void CSubsystem::mapEnd() // Unstack context _contextStack.pop(); } + +bool CSubsystem::init(string&) +{ + // Default implementation + return true; +} diff --git a/parameter/Subsystem.h b/parameter/Subsystem.h index e53735299..55d06e9a4 100644 --- a/parameter/Subsystem.h +++ b/parameter/Subsystem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -33,6 +33,8 @@ #include "ConfigurableElementWithMapping.h" #include "Mapper.h" #include "MappingContext.h" +#include + #include #include #include @@ -50,7 +52,14 @@ class CSubsystem : public CConfigurableElementWithMapping, private IMapper // Subsystem objects iterator typedef std::list::const_iterator SubsystemObjectListIterator; public: - CSubsystem(const std::string& strName); + + /** + * Class Constructor + * + * @param[in] strName subsystem name + * @param[in] logger the main logger of the application + */ + CSubsystem(const std::string& strName, core::log::Logger& logger); virtual ~CSubsystem(); // From IXmlSink @@ -89,6 +98,14 @@ class CSubsystem : public CConfigurableElementWithMapping, private IMapper */ virtual std::string getMapping(std::list& configurableElementPath) const; + /** Subsystem init function. + * This function will be launched after structure loading. + * + * @param[out] error, error encountered during initialization + * @return true if succeed, false otherwise + */ + virtual bool init(std::string& error); + protected: // Parameter access virtual bool accessValue(CPathNavigator& pathNavigator, std::string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; @@ -250,4 +267,7 @@ class CSubsystem : public CConfigurableElementWithMapping, private IMapper //! Contains the mapping info at Subsystem level CMappingData* _pMappingData; + + /** Logger which has to be provided to subsystem objects */ + core::log::Logger& _logger; }; diff --git a/parameter/SubsystemLibrary.h b/parameter/SubsystemLibrary.h index 78a497e33..2392b724a 100644 --- a/parameter/SubsystemLibrary.h +++ b/parameter/SubsystemLibrary.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -31,11 +31,11 @@ #include "DefaultElementLibrary.h" #include "VirtualSubsystem.h" -#include "NamedElementBuilderTemplate.h" +#include "LoggingElementBuilderTemplate.h" #include class CSubsystemLibrary : - public CDefaultElementLibrary > + public CDefaultElementLibrary > { private: // Builder type (based on element's name attribute) diff --git a/parameter/SubsystemObject.cpp b/parameter/SubsystemObject.cpp index 76b954907..ebe410097 100644 --- a/parameter/SubsystemObject.cpp +++ b/parameter/SubsystemObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -42,8 +42,10 @@ using std::string; -CSubsystemObject::CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement) - : _pInstanceConfigurableElement(pInstanceConfigurableElement), +CSubsystemObject::CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger) + : _logger(logger), + _pInstanceConfigurableElement(pInstanceConfigurableElement), _uiDataSize(pInstanceConfigurableElement->getFootPrint()), _pucBlackboardLocation(NULL), _uiAccessedIndex(0) @@ -146,11 +148,6 @@ bool CSubsystemObject::sync(CParameterBlackboard& parameterBlackboard, bool bBac // Synchronize to/from HW if (!bIsSubsystemAlive || !accessHW(bBack, strError)) { - strError = string("Unable to ") + (bBack ? "back" : "forward") + " synchronize configurable element " + - _pInstanceConfigurableElement->getPath() + ": " + strError; - - log_warning(strError); - // Fall back to parameter default initialization if (bBack) { @@ -212,43 +209,6 @@ void CSubsystemObject::blackboardWrite(const void* pvData, uint32_t uiSize) _uiAccessedIndex += uiSize; } -// Logging -void CSubsystemObject::log_info(const string& strMessage, ...) const -{ - char *pacBuffer; - va_list listPointer; - - va_start(listPointer, strMessage); - - vasprintf(&pacBuffer, strMessage.c_str(), listPointer); - - va_end(listPointer); - - if (pacBuffer != NULL) { - _pInstanceConfigurableElement->log_info(pacBuffer); - } - - free(pacBuffer); -} - -void CSubsystemObject::log_warning(const string& strMessage, ...) const -{ - char *pacBuffer; - va_list listPointer; - - va_start(listPointer, strMessage); - - vasprintf(&pacBuffer, strMessage.c_str(), listPointer); - - va_end(listPointer); - - if (pacBuffer != NULL) { - _pInstanceConfigurableElement->log_warning(pacBuffer); - } - - free(pacBuffer); -} - // Configurable element retrieval const CInstanceConfigurableElement* CSubsystemObject::getConfigurableElement() const { diff --git a/parameter/SubsystemObject.h b/parameter/SubsystemObject.h index ab085bc02..08f65cf79 100644 --- a/parameter/SubsystemObject.h +++ b/parameter/SubsystemObject.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -30,8 +30,9 @@ #pragma once #include "Syncer.h" -#include +#include +#include #include class CInstanceConfigurableElement; @@ -41,7 +42,8 @@ class CSubsystem; class CSubsystemObject : private ISyncer { public: - CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement); + CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger); virtual ~CSubsystemObject(); /** @@ -82,12 +84,12 @@ class CSubsystemObject : private ISyncer // Blackboard access from subsystems void blackboardRead(void* pvData, uint32_t uiSize); void blackboardWrite(const void* pvData, uint32_t uiSize); - // Logging - void log_info(const std::string& strMessage, ...) const; - void log_warning(const std::string& strMessage, ...) const; // Belonging Subsystem retrieval const CSubsystem* getSubsystem() const; + /** Application Logger */ + core::log::Logger& _logger; + private: // from ISyncer virtual bool sync(CParameterBlackboard& parameterBlackboard, bool bBack, std::string& strError); diff --git a/parameter/SubsystemObjectCreator.h b/parameter/SubsystemObjectCreator.h index ed6e79d9c..55ef0cbb4 100644 --- a/parameter/SubsystemObjectCreator.h +++ b/parameter/SubsystemObjectCreator.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -44,7 +44,11 @@ class CSubsystemObjectCreator uint32_t getMaxConfigurableElementSize() const; // Object creation - virtual CSubsystemObject* objectCreate(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context) const = 0; + virtual CSubsystemObject* objectCreate( + const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger) const = 0; virtual ~CSubsystemObjectCreator() {} diff --git a/parameter/SubsystemObjectFactory.h b/parameter/SubsystemObjectFactory.h index 3ac783544..5e6dcae3a 100644 --- a/parameter/SubsystemObjectFactory.h +++ b/parameter/SubsystemObjectFactory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -39,8 +39,13 @@ class TSubsystemObjectFactory : public CSubsystemObjectCreator TSubsystemObjectFactory(const std::string& strMappingKey, uint32_t uiAncestorIdMask, uint32_t uiMaxConfigurableElementSize = -1) : CSubsystemObjectCreator(strMappingKey, uiAncestorIdMask, uiMaxConfigurableElementSize) {} // Object creation - virtual CSubsystemObject* objectCreate(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context) const + virtual CSubsystemObject* objectCreate( + const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger) const { - return new SubsystemObjectType(strMappingValue, pInstanceConfigurableElement, context); + return new SubsystemObjectType( + strMappingValue, pInstanceConfigurableElement, context, logger); } }; diff --git a/parameter/SyncerSet.cpp b/parameter/SyncerSet.cpp index 9daf2a6a8..093b2df7c 100644 --- a/parameter/SyncerSet.cpp +++ b/parameter/SyncerSet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -56,7 +56,9 @@ void CSyncerSet::clear() _syncerSet.clear(); } -bool CSyncerSet::sync(CParameterBlackboard& parameterBlackboard, bool bBack, std::list* plstrError) const +bool CSyncerSet::sync(CParameterBlackboard& parameterBlackboard, + bool bBack, + core::Results* errors) const { bool bSuccess = true; @@ -71,9 +73,9 @@ bool CSyncerSet::sync(CParameterBlackboard& parameterBlackboard, bool bBack, std if (!pSyncer->sync(parameterBlackboard, bBack, strError)) { - if (plstrError) { + if (errors != NULL) { - plstrError->push_back(strError); + errors->push_back(strError); } bSuccess = false; } diff --git a/parameter/SyncerSet.h b/parameter/SyncerSet.h index 7e37f45b1..1db42e66f 100644 --- a/parameter/SyncerSet.h +++ b/parameter/SyncerSet.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,9 +29,8 @@ */ #pragma once +#include "Results.h" #include -#include -#include class ISyncer; class CParameterBlackboard; @@ -49,8 +48,14 @@ class CSyncerSet // Clearing void clear(); - // Sync - bool sync(CParameterBlackboard& parameterBlackboard, bool bBack, std::list* plstrError) const; + /** Sync the blackboard + * + * @param parameterBlackboard blackboard associated to syncer + * @param[in] bBack indicates if we want to back synchronise or to forward synchronise + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool sync(CParameterBlackboard& parameterBlackboard, bool bBack, core::Results* errors) const; private: std::set _syncerSet; diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp index ae4f74733..51709b7f4 100644 --- a/parameter/SystemClass.cpp +++ b/parameter/SystemClass.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -33,9 +33,8 @@ #include #include "SystemClass.h" #include "SubsystemLibrary.h" -#include "AutoLog.h" #include "VirtualSubsystem.h" -#include "NamedElementBuilderTemplate.h" +#include "LoggingElementBuilderTemplate.h" #include #include "PluginLocation.h" #include "Utility.h" @@ -45,6 +44,9 @@ using std::list; using std::string; +// FIXME: integrate SystemClass to core namespace +using namespace core; + /** * A plugin file name is of the form: * lib-subsystem.so or lib-subsystem._host.so @@ -61,9 +63,10 @@ const char* gpcPluginSymbolPrefix = "get"; const char* gpcPluginSymbolSuffix = "SubsystemBuilder"; // Used by subsystem plugins -typedef void (*GetSubsystemBuilder)(CSubsystemLibrary*); +typedef void (*GetSubsystemBuilder)(CSubsystemLibrary*, core::log::Logger& logger); -CSystemClass::CSystemClass() : _pSubsystemLibrary(new CSubsystemLibrary) +CSystemClass::CSystemClass(log::Logger& logger) + : _pSubsystemLibrary(new CSubsystemLibrary()), _logger(logger) { } @@ -98,38 +101,29 @@ bool CSystemClass::loadSubsystems(string& strError, const CSubsystemPlugins* pSubsystemPlugins, bool bVirtualSubsystemFallback) { - CAutoLog autoLog_info(this, "Loading subsystem plugins"); - // Start clean _pSubsystemLibrary->clean(); + typedef TLoggingElementBuilderTemplate VirtualSubsystemBuilder; // Add virtual subsystem builder - _pSubsystemLibrary->addElementBuilder("Virtual", - new TNamedElementBuilderTemplate()); + _pSubsystemLibrary->addElementBuilder("Virtual", new VirtualSubsystemBuilder(_logger)); // Set virtual subsytem as builder fallback if required - _pSubsystemLibrary->enableDefaultMechanism(bVirtualSubsystemFallback); + if (bVirtualSubsystemFallback) { + _pSubsystemLibrary->setDefaultBuilder(new VirtualSubsystemBuilder(_logger)); + } // Add subsystem defined in shared libraries - list lstrError; - bool bLoadPluginsSuccess = loadSubsystemsFromSharedLibraries(lstrError, pSubsystemPlugins); - - if (bLoadPluginsSuccess) { - log_info("All subsystem plugins successfully loaded"); - } else { - // Log plugin as warning if no fallback available - log_table(!bVirtualSubsystemFallback, lstrError); - } + core::Results errors; + bool bLoadPluginsSuccess = loadSubsystemsFromSharedLibraries(errors, pSubsystemPlugins); - if (!bVirtualSubsystemFallback) { - // Any problem reported is an error as there is no fallback. - // Fill strError for caller. - CUtility::asString(lstrError, strError); - } + // Fill strError for caller, he has to decide if there is a problem depending on + // bVirtualSubsystemFallback value + CUtility::asString(errors, strError); return bLoadPluginsSuccess || bVirtualSubsystemFallback; } -bool CSystemClass::loadSubsystemsFromSharedLibraries(list& lstrError, +bool CSystemClass::loadSubsystemsFromSharedLibraries(core::Results& errors, const CSubsystemPlugins* pSubsystemPlugins) { // Plugin list @@ -167,7 +161,7 @@ bool CSystemClass::loadSubsystemsFromSharedLibraries(list& lstrError, // process failed to load at least one of them // Attempt to load the complete list - if (!loadPlugins(lstrPluginFiles, lstrError)) { + if (!loadPlugins(lstrPluginFiles, errors)) { // Unable to load at least one plugin break; @@ -179,7 +173,7 @@ bool CSystemClass::loadSubsystemsFromSharedLibraries(list& lstrError, string strPluginUnloaded; CUtility::asString(lstrPluginFiles, strPluginUnloaded, ", "); - lstrError.push_back("Unable to load the following plugins: " + strPluginUnloaded + "."); + errors.push_back("Unable to load the following plugins: " + strPluginUnloaded + "."); return false; } @@ -210,7 +204,7 @@ string CSystemClass::getPluginSymbol(const string& strPluginPath) } // Plugin loading -bool CSystemClass::loadPlugins(list& lstrPluginFiles, list& lstrError) +bool CSystemClass::loadPlugins(list& lstrPluginFiles, core::Results& errors) { assert(lstrPluginFiles.size()); @@ -222,8 +216,6 @@ bool CSystemClass::loadPlugins(list& lstrPluginFiles, list& lstr string strPluginFileName = *it; - log_info("Attempting to load subsystem plugin path \"%s\"", strPluginFileName.c_str()); - // Load attempt void* lib_handle = dlopen(strPluginFileName.c_str(), RTLD_LAZY); @@ -232,9 +224,9 @@ bool CSystemClass::loadPlugins(list& lstrPluginFiles, list& lstr const char *err = dlerror(); // Failed if (err == NULL) { - lstrError.push_back("dlerror failed"); + errors.push_back("dlerror failed"); } else { - lstrError.push_back("Plugin load failed: " + string(err)); + errors.push_back("Plugin load failed: " + string(err)); } // Next plugin ++it; @@ -253,8 +245,8 @@ bool CSystemClass::loadPlugins(list& lstrPluginFiles, list& lstr if (!pfnGetSubsystemBuilder) { - lstrError.push_back("Subsystem plugin " + strPluginFileName + - " does not contain " + strPluginSymbol + " symbol."); + errors.push_back("Subsystem plugin " + strPluginFileName + + " does not contain " + strPluginSymbol + " symbol."); continue; } @@ -263,7 +255,7 @@ bool CSystemClass::loadPlugins(list& lstrPluginFiles, list& lstr bAtLeastOneSubsystemPluginSuccessfullyLoaded = true; // Fill library - pfnGetSubsystemBuilder(_pSubsystemLibrary); + pfnGetSubsystemBuilder(_pSubsystemLibrary, _logger); // Remove successfully loaded plugin from list and select next lstrPluginFiles.erase(it++); @@ -277,7 +269,7 @@ const CSubsystemLibrary* CSystemClass::getSubsystemLibrary() const return _pSubsystemLibrary; } -void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet) +void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet, core::Results& infos) { size_t uiNbChildren = getNbChildren(); size_t uiChild; @@ -289,7 +281,7 @@ void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet) // Collect and consume the need for a resync if (pSubsystem->needResync(true)) { - log_info("Resynchronizing subsystem: %s", pSubsystem->getName().c_str()); + infos.push_back("Resynchronizing subsystem: " + pSubsystem->getName()); // get all subsystem syncers pSubsystem->fillSyncerSet(syncerSet); } @@ -309,3 +301,20 @@ void CSystemClass::cleanSubsystemsNeedToResync() pSubsystem->needResync(true); } } + +bool CSystemClass::initSubsystems(std::string& error) +{ + uint32_t uiNbChildren = getNbChildren(); + uint32_t uiChild; + + for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { + + CSubsystem* pSubsystem = static_cast(getChild(uiChild)); + + if (!pSubsystem->init(error)) + { + return false; + } + } + return true; +} diff --git a/parameter/SystemClass.h b/parameter/SystemClass.h index dd215a6f7..dccb509a7 100644 --- a/parameter/SystemClass.h +++ b/parameter/SystemClass.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -31,6 +31,8 @@ #include "ConfigurableElement.h" #include "SubsystemPlugins.h" +#include "Results.h" +#include #include #include @@ -39,7 +41,12 @@ class CSubsystemLibrary; class CSystemClass : public CConfigurableElement { public: - CSystemClass(); + + /** + * @param[in] logger the logger provided by the client + * it need to be given to the subsystem library + */ + CSystemClass(core::log::Logger& logger); virtual ~CSystemClass(); /** Load subsystem plugin and fill the corresponding libraries. @@ -63,14 +70,22 @@ class CSystemClass : public CConfigurableElement * and fill a syncer set with all syncers that need to be resynchronized * * @param[out] syncerSet The syncer set to fill + * @param[out] infos Relevant informations client may want to log */ - void checkForSubsystemsToResync(CSyncerSet& syncerSet); + void checkForSubsystemsToResync(CSyncerSet& syncerSet, core::Results& infos); /** * Reset subsystems need to resync flag. */ void cleanSubsystemsNeedToResync(); + /** Launch init functions of all plugin subsystems + * + * @param[out] error, error encountered during initialization + * @return true if succeed, false otherwise + */ + bool initSubsystems(std::string& error); + // base virtual std::string getKind() const; @@ -82,12 +97,12 @@ class CSystemClass : public CConfigurableElement /** Load shared libraries subsystem plugins. * - * @param[out] lstrError is the list of error that occured during loadings. + * @param[out] errors is the list of error that occured during loadings. * @param[in] pSubsystemPlugins The plugins to load. * * @return true if all plugins have been succesfully loaded, false otherwises. */ - bool loadSubsystemsFromSharedLibraries(std::list& lstrError, + bool loadSubsystemsFromSharedLibraries(core::Results& errors, const CSubsystemPlugins* pSubsystemPlugins); // Plugin symbol computation @@ -97,16 +112,19 @@ class CSystemClass : public CConfigurableElement * * @param[in:out] lstrPluginFiles is the path list of the plugins shared libraries to load. * Successfully loaded plugins are removed from the list. - * @param[out] lstrError is the list of error that occured during loadings. + * @param[out] errors is the list of error that occured during loadings. * * @return true if at least one plugin has been succesfully loaded, false otherwise. * When false is returned, some plugins MIHGT have been loaded * but the lstrPluginFiles is accurate. */ - bool loadPlugins(std::list& lstrPluginFiles, std::list& lstrError); + bool loadPlugins(std::list& lstrPluginFiles, core::Results& errors); // Subsystem factory CSubsystemLibrary* _pSubsystemLibrary; std::list _subsystemLibraryHandleList; /**< Contains the list of all open plugin libs. */ + + /** Application Logger we need to provide to plugins */ + core::log::Logger& _logger; }; diff --git a/parameter/VirtualSubsystem.cpp b/parameter/VirtualSubsystem.cpp index 36027bf53..879dcbd12 100644 --- a/parameter/VirtualSubsystem.cpp +++ b/parameter/VirtualSubsystem.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -34,8 +34,8 @@ using std::string; -CVirtualSubsystem::CVirtualSubsystem(const string& strName) - : base(strName), _pVirtualSyncer(new CVirtualSyncer(this)) +CVirtualSubsystem::CVirtualSubsystem(const string& strName, core::log::Logger& logger) + : base(strName, logger), _pVirtualSyncer(new CVirtualSyncer(this)) { } diff --git a/parameter/VirtualSubsystem.h b/parameter/VirtualSubsystem.h index 3a9c89bc6..962bb62ed 100644 --- a/parameter/VirtualSubsystem.h +++ b/parameter/VirtualSubsystem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -38,7 +38,12 @@ class CVirtualSyncer; class CVirtualSubsystem : public CSubsystem { public: - CVirtualSubsystem(const std::string& strName); + + /** + * @param[in] strName subsystem name + * @param[in] logger the main logger of the application + */ + CVirtualSubsystem(const std::string& strName, core::log::Logger& logger); virtual ~CVirtualSubsystem(); protected: diff --git a/parameter/XmlDomainImportContext.h b/parameter/XmlDomainImportContext.h index 11090b0a8..c25f6f3b5 100644 --- a/parameter/XmlDomainImportContext.h +++ b/parameter/XmlDomainImportContext.h @@ -30,16 +30,21 @@ #pragma once #include "XmlDomainSerializingContext.h" -#include "SelectionCriteriaDefinition.h" #include "SystemClass.h" +#include #include class CXmlDomainImportContext : public CXmlDomainSerializingContext { public: - CXmlDomainImportContext(std::string& strError, bool bWithSettings, CSystemClass& systemClass): - base(strError, bWithSettings), _systemClass(systemClass), _bAutoValidationRequired(true) {} + CXmlDomainImportContext(std::string& strError, + bool bWithSettings, + CSystemClass& systemClass, + const core::selection::criterion::Criteria& criteria) + : base(strError, bWithSettings), _systemClass(systemClass), mCriteria(criteria), + _bAutoValidationRequired(true) + {} // System Class CSystemClass& getSystemClass() const @@ -47,16 +52,9 @@ class CXmlDomainImportContext : public CXmlDomainSerializingContext return _systemClass; } - // Criteria defintion - void setSelectionCriteriaDefinition( - const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition) + const core::selection::criterion::Criteria& getCriteria() const { - _pSelectionCriteriaDefinition = pSelectionCriteriaDefinition; - } - - const CSelectionCriteriaDefinition* getSelectionCriteriaDefinition() const - { - return _pSelectionCriteriaDefinition; + return mCriteria; } // Auto validation of configurations @@ -76,8 +74,8 @@ class CXmlDomainImportContext : public CXmlDomainSerializingContext // System Class CSystemClass& _systemClass; - // Criteria defintion - const CSelectionCriteriaDefinition* _pSelectionCriteriaDefinition; + /** Selection criteria definition for rule creation */ + const core::selection::criterion::Criteria& mCriteria; // Auto validation of configurations bool _bAutoValidationRequired; diff --git a/parameter/XmlFileIncluderElement.cpp b/parameter/XmlFileIncluderElement.cpp index 674a33177..f2943aae0 100644 --- a/parameter/XmlFileIncluderElement.cpp +++ b/parameter/XmlFileIncluderElement.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -32,7 +32,6 @@ #include "XmlMemoryDocSink.h" #include "XmlElementSerializingContext.h" #include "ElementLibrary.h" -#include "AutoLog.h" #include #define base CKindElement @@ -61,9 +60,6 @@ bool CXmlFileIncluderElement::fromXml(const CXmlElement& xmlElement, CXmlSeriali // Instantiate parser std::string strIncludedElementType = getIncludedElementType(); { - // Open a log section titled with loading file path - CAutoLog autolog(this, "Loading " + strPath); - // Use a doc source that load data from a file std::string strPathToXsdFile = elementSerializingContext.getXmlSchemaPathFolder() + "/" + strIncludedElementType + ".xsd"; diff --git a/parameter/criterion/CMakeLists.txt b/parameter/criterion/CMakeLists.txt new file mode 100644 index 000000000..6ec6ff7d4 --- /dev/null +++ b/parameter/criterion/CMakeLists.txt @@ -0,0 +1,70 @@ +# Copyright (c) 2015, Intel Corporation +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation and/or +# other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +add_library(criterion STATIC + src/InclusiveCriterion.cpp + src/Criteria.cpp + src/Criterion.cpp) + +include_directories( + include + "${PROJECT_SOURCE_DIR}/parameter/" # Results.h + "${PROJECT_SOURCE_DIR}/parameter/log/include" + "${PROJECT_SOURCE_DIR}/xmlserializer/" + "${PROJECT_SOURCE_DIR}/utility/") + +target_link_libraries(criterion pfw_utility xmlserializer) + +# '-fPIC' needed for linking against shared libraries (e.g. libparameter) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + +# Client headers +install(FILES + include/criterion/client/CriterionInterface.h + DESTINATION "include/parameter/criterion/client") + +if(BUILD_TESTING) + # Catch header provided by Ubuntu package is not up to date and need + # CATCH_CONFIG_CPP11_NULLPTR flag activated to compare a pointer to nullptr + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCATCH_CONFIG_CPP11_NULLPTR") + + find_path(CATCH_HEADER catch.hpp) + include_directories( + include + ${CATCH_HEADER}) + + # Add unit test + add_executable(criterionUnitTest test/CriterionUnitTest.cpp) + + target_link_libraries(criterionUnitTest criterion) + add_test(NAME criterionUnitTest + COMMAND criterionUnitTest) + + # Custom function defined in the top-level CMakeLists + set_test_env(criterionUnitTest) +endif() diff --git a/parameter/criterion/include/criterion/Criteria.h b/parameter/criterion/include/criterion/Criteria.h new file mode 100644 index 000000000..b4dbd0adf --- /dev/null +++ b/parameter/criterion/include/criterion/Criteria.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2011-2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#include "criterion/Criterion.h" +#include "XmlSource.h" +#include + +#include +#include +#include + +namespace core +{ +namespace selection +{ +namespace criterion +{ + +/** Criteria Handler */ +class Criteria : public IXmlSource +{ +public: + Criteria(); + + /** Create a new Exclusive criterion + * + * @param[in] name the criterion name + * @param[in] logger the application main logger + * @return raw pointer on the created criterion + */ + Criterion* createExclusiveCriterion(const std::string& name, + core::log::Logger& logger); + + /** Create a new Inclusive criterion + * + * @param[in] name the criterion name + * @param[in] logger the application main logger + * @return raw pointer on the created criterion + */ + Criterion* createInclusiveCriterion(const std::string& name, + core::log::Logger& logger); + + /** Criterion Retrieval + * + * @param[in] name the criterion name + * @result pointer to the desired criterion object + */ + Criterion* getSelectionCriterion(const std::string& name); + + /** Const Criterion Retrieval + * + * @param[in] name the criterion name + * @result pointer to the desired const criterion object + */ + const Criterion* getSelectionCriterion(const std::string& name) const; + + /** List available criteria + * + * @param[out] results information container + * @param[in] withTypeInfo indicates if we want to retrieve criterion type information + * @param[in] humanReadable indicates the formatage we want to use + */ + void listSelectionCriteria(std::list& results, + bool withTypeInfo, + bool humanReadable) const; + + /** Reset the modified status of criterions */ + void resetModifiedStatus(); + + /** Xml Serialization method + * + * @param[out] xmlElement the current xml element to fill with data + * @param serializingContext context of the current serialization + */ + virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; + +private: + + /** Internally wrap criterion pointer to not have to handle destruction */ + typedef std::unique_ptr CriterionWrapper; + + /** Criteria instance container type, map which use criterion name as key */ + typedef std::map CriteriaMap; + + /** Confine exception use to smooth code transitions + * Android is not supporting exceptions by default. Nevertheless some + * solutions has emerged. + * This function allows to confine exceptions use in only one function. + * It also allows to easily connect this part of code to the parameter-framework + * which works without exceptions for now. + * + * @param[in] name, name of the criterion to retrieve + * @return pointer to the desired criterion + */ + Criterion* getCriterionPointer(const std::string& name) const; + + /** Criteria instance container */ + CriteriaMap mCriteria; +}; + +} /** criterion namespace */ +} /** selection namespace */ +} /** core namespace */ diff --git a/parameter/criterion/include/criterion/Criterion.h b/parameter/criterion/include/criterion/Criterion.h new file mode 100644 index 000000000..3d42a0123 --- /dev/null +++ b/parameter/criterion/include/criterion/Criterion.h @@ -0,0 +1,184 @@ +/* + * Copyright (c) 2011-2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#include "client/CriterionInterface.h" +#include "XmlSource.h" +#include + +#include +#include +#include + +namespace core +{ +namespace selection +{ +namespace criterion +{ + +/** Criterion object used to apply rules based on system state */ +class Criterion : public IXmlSource, public CriterionInterface +{ +public: + /** @param[in] name the criterion name + * @param[in] logger the main application logger + */ + Criterion(const std::string& name, core::log::Logger& logger); + + virtual void setCriterionState(int iState); + virtual int getCriterionState() const; + virtual std::string getCriterionName() const; + bool hasBeenModified() const; + void resetModifiedStatus(); + + /** Request criterion state match with a desired method + * + * @param[in] method, the desired match method + * @param[in] state, the state to match + * @return true if the current state match the state given in parameter with the desired method + */ + bool match(const std::string& method, int32_t state) const; + + /** Check if a match method is available for this criterion + * + * @param[in] method, the desired match method + * @return true if the method is available, false otherwise + */ + bool isMatchMethodAvailable(const std::string& method) const; + + std::string getFormattedDescription(bool bWithTypeInfo, bool bHumanReadable) const; + + // @{ + /** @see CriterionInterface */ + virtual bool isInclusive() const override; + + virtual bool addValuePair(int numericalValue, + const std::string& literalValue, + std::string& error) override; + + bool getLiteralValue(int numericalValue, std::string& literalValue) const final; + + virtual bool getNumericalValue(const std::string& literalValue, + int& numericalValue) const override; + + virtual std::string getFormattedState() const override; + // @} + + /** List different values a criterion can have + * + * @return formatted string containing criterion possible values + */ + std::string listPossibleValues() const; + + /** Export to XML + * + * @param[in] xmlElement The XML element to export to + * @param[in] serializingContext The serializing context + */ + virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; + +protected: + /** Criterion Match callback type + * + * Those method should take an integer in parameter which represents the state to match + * and returns a boolean which indicates if the current state match the state given in + * parameter. + */ + typedef std::function MatchMethod; + + /** Match method container, MatchMethod are indexed by their name */ + typedef std::map MatchMethods; + + /** Internal type which associate literal and numerical value */ + typedef std::map ValuePairs; + + /** Initializer constructor + * This Constructor initialize class members and should be called by derived class + * in order to add functionalities + * + * @param[in] name the criterion name + * @param[in] logger the main application logger + * @param[in] derivedValuePairs initial value pairs of derived classes + * @param[in] derivedMatchMethods match methods of derived classes + */ + Criterion(const std::string& name, + core::log::Logger& logger, + const ValuePairs& derivedValuePairs, + const MatchMethods& derivedMatchMethods); + + /** Set a "default formatted state" when no criterion state is set + * + * @param formattedState, the formatted state string to check + * @result the reference of the string passed in parameter filled with the default value + * if it was empty + * + * This method returns a reference on his referenced parameter in order to have the easy + * notation. + * return checkFormattedStateEmptyness(myFormattedStateToReturn); + */ + std::string& checkFormattedStateEmptyness(std::string& formattedState) const; + + /** Contains pair association between literal and numerical value */ + ValuePairs mValuePairs; + + /** Available criterion match methods */ + const MatchMethods mMatchMethods; + + /** Current state + * + * FIXME: Use bit set object instead + */ + int32_t mState; + +private: + /** Utility which join derived class MatchMethods container with Base class container + * Derived class may want to exposes more match methods than ones exposed here. + * This method joins MatchMethods container to realize that. + * + * @param[in] matchA, first set of matching + * @param[in] matchB, set of match to join + * @return MatchMethods container with elements of matchA and matchB + */ + MatchMethods gatherMatchMethods(MatchMethods matchA, const MatchMethods& matchB); + + /** Counter to know how many modifications have been applied to this criterion */ + uint32_t _uiNbModifications; + + /** Application logger */ + core::log::Logger& _logger; + + /** Criterion name */ + const std::string mName; +}; + +} /** criterion namespace */ +} /** selection namespace */ +} /** core namespace */ diff --git a/parameter/include/SelectionCriterionInterface.h b/parameter/criterion/include/criterion/InclusiveCriterion.h similarity index 60% rename from parameter/include/SelectionCriterionInterface.h rename to parameter/criterion/include/criterion/InclusiveCriterion.h index d71eff39b..26db791ae 100644 --- a/parameter/include/SelectionCriterionInterface.h +++ b/parameter/criterion/include/criterion/InclusiveCriterion.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,18 +29,41 @@ */ #pragma once -#include +#include "criterion/Criterion.h" -#include "SelectionCriterionTypeInterface.h" +namespace core +{ +namespace selection +{ +namespace criterion +{ -class ISelectionCriterionInterface +/** Criterion we can take several state values at the same time */ +class InclusiveCriterion : public Criterion { public: - virtual void setCriterionState(int iState) = 0; - virtual int getCriterionState() const = 0; - virtual std::string getCriterionName() const = 0; - virtual const ISelectionCriterionTypeInterface* getCriterionType() const = 0; + /** @param[in] name, the criterion name */ + InclusiveCriterion(const std::string& name, core::log::Logger& logger); + + // @{ + /** @see ISelectionCriterionInterface */ + bool isInclusive() const override final; -protected: - virtual ~ISelectionCriterionInterface() {} + bool addValuePair(int numericalValue, + const std::string& literalValue, + std::string& error) override final; + + bool getNumericalValue(const std::string& literalValue, + int& numericalValue) const override final; + + std::string getFormattedState() const override final; + // @} + +private: + /** Inclusive criterion state delimiter. */ + static const std::string gDelimiter; }; + +} /** criterion namespace */ +} /** selection namespace */ +} /** core namespace */ diff --git a/parameter/criterion/include/criterion/client/CriterionInterface.h b/parameter/criterion/include/criterion/client/CriterionInterface.h new file mode 100644 index 000000000..d357280fb --- /dev/null +++ b/parameter/criterion/include/criterion/client/CriterionInterface.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2011-2014, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#include + +namespace core +{ +namespace selection +{ +namespace criterion +{ + +class CriterionInterface +{ +public: + virtual void setCriterionState(int iState) = 0; + virtual int getCriterionState() const = 0; + virtual std::string getCriterionName() const = 0; + + /** Add a new pair [literal, numerical] which represents a criterion + * + * @param[in] numericalValue the numerical value of the criterion + * @param[in] literalValue the literal value of the criterion + * @param[out] error string containing error information we can provide to client + * @return true if succeed false otherwise + */ + virtual bool addValuePair(int numericalValue, + const std::string& literalValue, + std::string& error) = 0; + + /** Retrieve the numerical value from the literal representation of the criterion type. + * + * @param[in] literalValue: criterion state value represented as a stream. If the criterion is + * inclusive, it supports more than one criterion type value delimited + * by the "|" symbol. + * @param[out] numericalValue: criterion state value represented as an integer. + * + * @return true if a numerical value is retrieved from the literal one, false otherwise. + */ + virtual bool getNumericalValue(const std::string& literalValue, int& numericalValue) const = 0; + + /** Retrieve the numerical value from the literal representation of the criterion type. + * + * @param[in] numericalValue: criterion state value represented as an integer. + * @param[out] literalValue: criterion state value represented as a stream. If the criterion is + * inclusive, it supports more than one criterion type value delimited + * by the "|" symbol. + * + * @return true if a numerical value is retrieved from the literal one, false otherwise. + */ + virtual bool getLiteralValue(int numericalValue, std::string& literalValue) const = 0; + + /** Retrieve formatted current criterion state + * + * @return formatted string of criterion state + */ + virtual std::string getFormattedState() const = 0; + + /** Retrieve Criterion type + * + * @return true if the criterion is Inclusive, false if it is Exclusive + */ + virtual bool isInclusive() const = 0; + +protected: + virtual ~CriterionInterface() {} +}; + +} /** criterion namespace */ +} /** selection namespace */ +} /** core namespace */ diff --git a/parameter/criterion/src/Criteria.cpp b/parameter/criterion/src/Criteria.cpp new file mode 100644 index 000000000..57e569a08 --- /dev/null +++ b/parameter/criterion/src/Criteria.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2011-2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "criterion/Criteria.h" +#include "criterion/InclusiveCriterion.h" + +#include + +namespace core +{ +namespace selection +{ +namespace criterion +{ + +Criteria::Criteria() : mCriteria() +{ +} + +Criterion* Criteria::getCriterionPointer(const std::string& name) const +{ + // Bound exception aware code to criteria, others Pfw parts will check nullptr. + try { + return mCriteria.at(name).get(); + } + catch (std::out_of_range& e) { + return nullptr; + } +} + +Criterion* Criteria::createExclusiveCriterion(const std::string& name, core::log::Logger& logger) +{ + mCriteria.emplace(name, CriterionWrapper(new Criterion(name, logger))); + return getCriterionPointer(name); +} + +Criterion* Criteria::createInclusiveCriterion(const std::string& name, core::log::Logger& logger) +{ + mCriteria.emplace(name, CriterionWrapper(new InclusiveCriterion(name, logger))); + return getCriterionPointer(name); +} + +Criterion* Criteria::getSelectionCriterion(const std::string& name) +{ + return getCriterionPointer(name); +} + +const Criterion* Criteria::getSelectionCriterion(const std::string& name) const +{ + return getCriterionPointer(name); +} + +void Criteria::listSelectionCriteria(std::list& results, + bool withTypeInfo, + bool humanReadable) const +{ + for (auto& criterion : mCriteria) { + results.push_back(criterion.second->getFormattedDescription(withTypeInfo, humanReadable)); + } +} + +void Criteria::resetModifiedStatus() +{ + for (auto& criterion : mCriteria) { + criterion.second->resetModifiedStatus(); + } +} + +void Criteria::toXml(CXmlElement& xmlElement, + CXmlSerializingContext& serializingContext) const +{ + for (auto& criterion : mCriteria) { + + CXmlElement xmlChildElement; + xmlElement.createChild(xmlChildElement, "SelectionCriterion"); + criterion.second->toXml(xmlChildElement, serializingContext); + } +} + +} /** criterion namespace */ +} /** selection namespace */ +} /** core namespace */ diff --git a/parameter/criterion/src/Criterion.cpp b/parameter/criterion/src/Criterion.cpp new file mode 100644 index 000000000..b464a7bfb --- /dev/null +++ b/parameter/criterion/src/Criterion.cpp @@ -0,0 +1,279 @@ +/* + * Copyright (c) 2011-2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "criterion/Criterion.h" +#include +#include + +#include +#include + +namespace core +{ +namespace selection +{ +namespace criterion +{ + +Criterion::Criterion(const std::string& name, core::log::Logger& logger) + : Criterion(name, logger, {}, {}) +{ +} + +Criterion::Criterion(const std::string& name, + core::log::Logger& logger, + const ValuePairs& derivedValuePairs, + const MatchMethods& derivedMatchMethods) + : mValuePairs(derivedValuePairs), + mMatchMethods(gatherMatchMethods(MatchMethods{ + {"Is", [&](int state){ return mState == state; }}, + {"IsNot", [&](int state){ return mState != state; }}}, + derivedMatchMethods)), + mState(0), _uiNbModifications(0), _logger(logger), mName(name) +{ +} + +bool Criterion::hasBeenModified() const +{ + return _uiNbModifications != 0; +} + +void Criterion::resetModifiedStatus() +{ + _uiNbModifications = 0; +} + +void Criterion::setCriterionState(int iState) +{ + // Check for a change + if (mState != iState) { + + mState = iState; + + _logger.info() << "Selection criterion changed event: " + << getFormattedDescription(false, false); + + // Check if the previous criterion value has been taken into account + // (i.e. at least one Configuration was applied + // since the last criterion change) + if (_uiNbModifications != 0) { + + _logger.warning() << "Selection criterion '" << mName + << "' has been modified " << _uiNbModifications + << " time(s) without any configuration application"; + } + + // Track the number of modifications for this criterion + _uiNbModifications++; + } +} + +int Criterion::getCriterionState() const +{ + return mState; +} + +std::string Criterion::getCriterionName() const +{ + return mName; +} + +std::string Criterion::getFormattedDescription(bool bWithTypeInfo, bool bHumanReadable) const +{ + std::string strFormattedDescription; + std::string typeName = isInclusive() ? "Inclusive" : "Exclusive"; + + if (bHumanReadable) { + + if (bWithTypeInfo) { + + // Display type info + CUtility::appendTitle(strFormattedDescription, mName + ":"); + + // States + strFormattedDescription += "Possible states "; + + // Type Kind + strFormattedDescription += "("; + strFormattedDescription += typeName; + strFormattedDescription += "): "; + + // States + strFormattedDescription += listPossibleValues() + "\n"; + + // Current State + strFormattedDescription += "Current state"; + } else { + // Name only + strFormattedDescription = mName; + } + + // Current State + strFormattedDescription += " = " + getFormattedState(); + } else { + // Name + strFormattedDescription = "Criterion name: " + mName; + + if (bWithTypeInfo) { + // Type Kind + strFormattedDescription += ", type kind: "; + strFormattedDescription += typeName; + } + + // Current State + strFormattedDescription += ", current state: " + getFormattedState(); + + if (bWithTypeInfo) { + // States + strFormattedDescription += ", states: " + listPossibleValues(); + } + } + return strFormattedDescription; +} + +void Criterion::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const +{ + (void)serializingContext; + xmlElement.setAttributeString("Value", getFormattedState()); + xmlElement.setAttributeString("Name", mName); + xmlElement.setAttributeString("Kind", isInclusive() ? "Inclusive" : "Exclusive"); + + for (auto& valuePair : mValuePairs) { + CXmlElement childValuePairElement; + + xmlElement.createChild(childValuePairElement, "ValuePair"); + childValuePairElement.setAttributeString("Literal", valuePair.first); + childValuePairElement.setAttributeSignedInteger("Numerical", valuePair.second); + } +} + +bool Criterion::isInclusive() const +{ + return false; +} + +bool Criterion::addValuePair(int numericalValue, + const std::string& literalValue, + std::string& error) +{ + // Check already inserted + if (mValuePairs.count(literalValue) == 1) { + + std::ostringstream errorBuf; + errorBuf << "Rejecting value pair association (literal already present): 0x" + << std::hex << numericalValue << " - " << literalValue + << " for Selection Criterion Type"; + error = errorBuf.str(); + + return false; + } + mValuePairs[literalValue] = numericalValue; + + return true; +} + +bool Criterion::getNumericalValue(const std::string& literalValue, + int& numericalValue) const +{ + try { + numericalValue = mValuePairs.at(literalValue); + return true; + } + catch (std::out_of_range& e) { + return false; + } +} + +bool Criterion::getLiteralValue(int numericalValue, std::string& literalValue) const +{ + for (auto& value : mValuePairs) { + if (value.second == numericalValue) { + literalValue = value.first; + return true; + } + } + return false; +} + +std::string Criterion::getFormattedState() const +{ + std::string formattedState; + getLiteralValue(mState, formattedState); + + return Criterion::checkFormattedStateEmptyness(formattedState); +} + +std::string Criterion::listPossibleValues() const +{ + std::string possibleValues = "{"; + + // Get comma separated list of values + bool first = true; + for (auto& value : mValuePairs) { + + if (first) { + first = false; + } else { + possibleValues += ", "; + } + possibleValues += value.first; + } + possibleValues += "}"; + + return possibleValues; +} + +std::string& Criterion::checkFormattedStateEmptyness(std::string& formattedState) const +{ + if (formattedState.empty()) { + formattedState = ""; + } + return formattedState; +} + +bool Criterion::match(const std::string& method, int32_t state) const +{ + return mMatchMethods.at(method) (state); +} + +bool Criterion::isMatchMethodAvailable(const std::string& method) const +{ + return mMatchMethods.count(method) == 1; +} + +Criterion::MatchMethods Criterion::gatherMatchMethods(MatchMethods matchA, + const MatchMethods& matchB) +{ + matchA.insert(matchB.begin(), matchB.end()); + return matchA; +} + +} /** criterion namespace */ +} /** selection namespace */ +} /** core namespace */ diff --git a/parameter/criterion/src/InclusiveCriterion.cpp b/parameter/criterion/src/InclusiveCriterion.cpp new file mode 100644 index 000000000..6ff9368c9 --- /dev/null +++ b/parameter/criterion/src/InclusiveCriterion.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "criterion/InclusiveCriterion.h" +#include "Tokenizer.h" + +#include +#include + +namespace core +{ +namespace selection +{ +namespace criterion +{ + +const std::string InclusiveCriterion::gDelimiter = "|"; + +InclusiveCriterion::InclusiveCriterion(const std::string& name, core::log::Logger& logger) + : Criterion(name, logger, + {{"none", 0}}, + {{"Includes", [&](int state){ return (mState & state) == state; }}, + {"Excludes", [&](int state){ return (mState & state) == 0; }}}) +{ +} + +bool InclusiveCriterion::isInclusive() const +{ + return true; +} + +bool InclusiveCriterion::addValuePair(int numericalValue, + const std::string& literalValue, + std::string& error) +{ + // Check 1 bit set only for inclusive types + // FIXME: unclear test, need rework + if (!numericalValue || (numericalValue & (numericalValue - 1))) { + std::ostringstream errorBuf; + errorBuf << "Rejecting value pair association: 0x" << std::hex << numericalValue + << " - " << literalValue << " for Selection Criterion Type"; + error = errorBuf.str(); + + return false; + } + + return Criterion::addValuePair(numericalValue, literalValue, error); +} + +bool InclusiveCriterion::getNumericalValue(const std::string& literalValue, + int& numericalValue) const +{ + Tokenizer tok(literalValue, gDelimiter); + std::vector literalValues = tok.split(); + numericalValue = 0; + + // Looping on each std::string delimited by "|" token and adding the associated value + for (std::string atomicLiteral : literalValues) { + + int atomicNumerical = 0; + if (!Criterion::getNumericalValue(atomicLiteral, atomicNumerical)) { + return false; + } + numericalValue |= atomicNumerical; + } + return true; +} + +std::string InclusiveCriterion::getFormattedState() const +{ + std::string formattedState; + if (mState == 0) { + // Default inclusive criterion state is always present + assert(getLiteralValue(0, formattedState)); + return formattedState; + } + + uint32_t bit; + bool first = true; + + // Need to go through all set bit + for (bit = 0; bit < sizeof(mState) * 8; bit++) { + int singleBitValue = mState & (1 << bit); + // Check if current bit is set + if (!singleBitValue) { + continue; + } + // Simple translation + std::string atomicState; + getLiteralValue(singleBitValue, atomicState); + + if (first) { + first = false; + } else { + formattedState += gDelimiter; + } + + formattedState += atomicState; + } + + return Criterion::checkFormattedStateEmptyness(formattedState); +} + +} /** criterion namespace */ +} /** selection namespace */ +} /** core namespace */ diff --git a/parameter/criterion/test/CriterionUnitTest.cpp b/parameter/criterion/test/CriterionUnitTest.cpp new file mode 100644 index 000000000..105f9aceb --- /dev/null +++ b/parameter/criterion/test/CriterionUnitTest.cpp @@ -0,0 +1,627 @@ +/* + * Copyright (c) 2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() +#include + +/** Ubuntu keeps using an old catch version where "Method" version of BDD Macros are + * not available. This macro adds this functionality in case that catch version is too old. + */ +#ifndef SCENARIO_METHOD +#define SCENARIO_METHOD( className, name, tags ) \ + INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags ) +#endif + +#include +#include +#include +#include +#include "XmlSerializingContext.h" +#include "XmlStringDocSink.h" +#include "XmlMemoryDocSource.h" + +#include +#include +#include +#include +#include +#include +#include + +using namespace core; +using namespace core::selection::criterion; + +/** Raw logging class Helper */ +class TestLogger : public log::ILogger +{ +public: + void info(const std::string& info) { logBuf << "Info: " << info; }; + void warning(const std::string& warning) { logBuf << "Warning: " << warning; }; + std::string getLog() { return logBuf.str(); }; +private: + std::ostringstream logBuf; +}; + +struct LoggingTest +{ + LoggingTest() : mRawLogger(), mLogger(mRawLogger) {} + + void REQUIRE_FAILURE(bool success, const std::string& result) + { + THEN("It should be an error") { + INFO("Result message was: '" + result + "'"); + CHECK(not success); + CHECK(not result.empty()); + } + } + + void REQUIRE_FAILURE(bool success) + { + THEN("It should be an error") { + CHECK(not success); + } + } + + void REQUIRE_SUCCESS(bool success, const std::string& result = "") + { + THEN("It should be a success") { + INFO("Result message was" + (result.empty() ? " empty" : ": '" + result + "'")); + CHECK(success); + } + } + + inline void removeWhitespaces(std::string &s) + { + s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end()); + } + + /** xml serialization into a string helper */ + void xmlSerialize(std::string& result, IXmlSource* sourceNode, const std::string& nodeName) + { + std::string error; + CXmlElement xmlElement; + CXmlSerializingContext context(error); + CXmlMemoryDocSource source(sourceNode, nodeName, false); + CXmlStringDocSink sink(result); + + // Processing will call XmlSource toXml method + REQUIRE_SUCCESS(sink.process(source, context), error); + } + + /** Raw logger we can check */ + TestLogger mRawLogger; + /** Application standard Logger */ + log::Logger mLogger; +}; + +/** Test fixtures for Criteria */ +struct CriteriaTest : LoggingTest +{ + void checkListCriteria(bool human, bool typeInfo) + { + std::list results, desireds; + for(auto& description : mDescriptions) { + desireds.push_back(description.criterion->getFormattedDescription(true, true)); + } + mCriteria.listSelectionCriteria(results, human, typeInfo); + THEN("Each criterion description should be in the listing") { + for(const auto& result : results) { + CAPTURE(result); + const auto& it = std::find(desireds.begin(), desireds.end(), result); + CHECK(it != desireds.end()); + } + } + } + + /** Structure to describe and test criteria */ + struct CriterionDescription { const std::string name; bool isInclusive; Criterion* criterion; }; + using CriterionDescriptions = std::vector; + + /** Tested descriptions */ + CriterionDescriptions mDescriptions{ + {"A", true, nullptr}, + {"B", false, nullptr}, + {"C", true, nullptr}, + {"D", false, nullptr} + }; + + /** Tested criteria object */ + Criteria mCriteria{}; +}; + +/** Test fixtures for Criterion */ +struct CriterionTest : public LoggingTest +{ + using CriterionValues = std::map; + + /** Help to generate some values */ + CriterionValues generateCriterionValues(bool isInclusive, int nbValues) + { + // 0 is invalid for inclusive criterion + int offset = isInclusive ? 1 : 0; + CriterionValues criterionValues; + + for (int i = offset; i < nbValues; i++) { + // Inclusive criterion should have only one be set + int numericalValue = isInclusive ? 1 << i : i; + criterionValues.emplace(numericalValue, "Crit_" + std::to_string(numericalValue)); + } + + return criterionValues; + } + + void checkUnknownValueGet(Criterion& criterion) + { + WHEN("Getting a literal value from an unknown numerical one") { + std::string result; + std::string literalValue; + REQUIRE_FAILURE(criterion.getLiteralValue(2, literalValue)); + CHECK(literalValue.empty()); + } + WHEN("Getting a numerical value from an unknown literal one") { + std::string result; + int numericalValue = 0; + REQUIRE_FAILURE(criterion.getNumericalValue("UnknowValue", numericalValue)); + CHECK(numericalValue == 0); + } + } + + void checkExistingValueInsertion(Criterion& criterion) + { + WHEN("Adding an existing literal value") { + std::string result; + std::string literalValue = "DoubleState"; + REQUIRE_SUCCESS(criterion.addValuePair(1, literalValue, result), result); + REQUIRE_FAILURE(criterion.addValuePair(2, literalValue, result), result); + } + // FIXME + //WHEN("Adding an existing numerical value") { + // std::string result; + // int numericalValue = 1; + // REQUIRE_SUCCESS(criterion.addValuePair(numericalValue, "State1", result), result); + // REQUIRE_FAILURE(criterion.addValuePair(numericalValue, "State2", result), result); + //} + } + + void checkInclusiveCriterionSet(Criterion& criterion) + { + // CriterionValues contains 32 value as defined previously + WHEN("Setting many inclusive value at the same time") { + std::bitset<32> stateMask("001001001001001"); + std::bitset<32> subStateMask("000001001000001"); + std::bitset<32> almostSubStateMask("100001001000001"); + std::bitset<32> excludeMask("010000010010000"); + + CAPTURE(stateMask.to_ulong()); + criterion.setCriterionState(stateMask.to_ulong()); + + WHEN("Matching with 'Includes' a mask contained in the state mask") { + REQUIRE_SUCCESS(criterion.match("Includes", subStateMask.to_ulong())); + } + WHEN("Matching with 'Includes' a mask with not all its bit set in the current state") { + REQUIRE_FAILURE(criterion.match("Includes", almostSubStateMask.to_ulong())); + } + WHEN("Matching with 'Includes' a mask with no common bit with the current state") { + REQUIRE_FAILURE(criterion.match("Includes", excludeMask.to_ulong())); + } + WHEN("Matching with 'Excludes' a mask contained in the state mask") { + REQUIRE_FAILURE(criterion.match("Excludes", subStateMask.to_ulong())); + } + WHEN("Matching with 'Excludes' a mask with not all its bit set in the current state") { + REQUIRE_FAILURE(criterion.match("Excludes", almostSubStateMask.to_ulong())); + } + WHEN("Matching with 'Excludes' a mask with no common bit with the current state") { + REQUIRE_SUCCESS(criterion.match("Excludes", excludeMask.to_ulong())); + } + } + } + + void checkExclusiveCriterionSet(Criterion& criterion, CriterionValues& criterionValues) + { + WHEN("Setting the current value") { + int currentState = criterion.getCriterionState(); + CAPTURE(currentState); + std::string oldLog = mRawLogger.getLog(); + criterion.setCriterionState(currentState); + THEN("Criterion should not be modified") { + CHECK(not criterion.hasBeenModified()); + } + THEN("No information should be logged") { + CHECK(oldLog == mRawLogger.getLog()); + } + } + + for (auto& value : criterionValues) { + if (value.first != criterion.getCriterionState()) { + WHEN("Setting a new value") { + CAPTURE(value.first); + criterion.setCriterionState(value.first); + + THEN("State should have been updated") { + CHECK(criterion.getCriterionState() == value.first); + CHECK(criterion.getFormattedState() == value.second); + } + THEN("Criterion should be modified") { + CHECK(criterion.hasBeenModified()); + } + THEN("Criterion Is match method should be valid") { + CHECK(criterion.match("Is", value.first)); + } + THEN("Criterion IsNot match method should not be valid") { + CHECK(not criterion.match("IsNot", value.first)); + } + THEN("Criterion update event should be logged") { + size_t logPos = mRawLogger.getLog().find( + "Info: Selection criterion changed event: " + + criterion.getFormattedDescription(false, false)); + CHECK(logPos != std::string::npos); + } + } + } + } + WHEN("Setting many value in a raw") { + // Set value which are valid for inclusive or exclusive criterion + criterion.setCriterionState(2); + criterion.setCriterionState(4); + THEN("Criterion should be modified") { + CHECK(criterion.hasBeenModified()); + } + THEN("Criterion multi modification should be logged") { + size_t logPos = mRawLogger.getLog().find("Warning: Selection criterion '" + + criterion.getCriterionName() + + "' has been modified 1 time(s) without any" + " configuration application"); + CHECK(logPos != std::string::npos); + } + WHEN("Resetting criterion status") { + criterion.resetModifiedStatus(); + THEN("Criterion should not be modified") { + CHECK(not criterion.hasBeenModified()); + } + } + } + } + + void checkSerialization(Criterion& criterion) + { + std::string kind = criterion.isInclusive() ? "Inclusive" : "Exclusive"; + WHEN("Deserializing through xml") { + std::string defaultValue = criterion.isInclusive() ? "none" : "<none>"; + std::string defaultState = criterion.isInclusive() ? + R"()" : ""; + std::string xmlDescription = + R"( + + + + )" + + defaultState + + ""; + + std::string result; + xmlSerialize(result, &criterion, "SelectionCriterion"); + // Remove whitespaces as they are not relevant in xml + removeWhitespaces(result); + removeWhitespaces(xmlDescription); + + THEN("Generated xml match expectation") { + CHECK(result == xmlDescription); + } + } + + std::string defaultState = (criterion.isInclusive() ? "none" : ""); + std::string defaultStateType = criterion.isInclusive() ? ", none}" : "}"; + WHEN("Deserializing through Csv") { + std::string nameInfo = "Criterion name: " + criterion.getCriterionName(); + std::string currentStateInfo = std::string(", current state: ") + defaultState; + + THEN("Generated csv match expectation") { + std::string csvDescription = nameInfo + currentStateInfo; + std::string dump = criterion.getFormattedDescription(false, false); + CHECK(dump == csvDescription); + } + + THEN("Generated csv with type information match expectation") { + std::string csvDescription = nameInfo + ", type kind: " + kind + currentStateInfo + + ", states: {a, b, c" + defaultStateType; + std::string dump = criterion.getFormattedDescription(true, false); + CHECK(dump == csvDescription); + } + } + WHEN("Generating human readable description") { + THEN("Generated description match expectation") { + std::string description = criterion.getCriterionName() + " = " + defaultState; + std::string dump = criterion.getFormattedDescription(false, true); + CHECK(dump == description); + } + + THEN("Generated description with type information match expectation") { + std::string defaultStateHuman = criterion.isInclusive() ? ", none}" : "}"; + std::string description = criterion.getCriterionName() + ":"; + std::string titleDecorator(description.length(), '='); + description = "\n" + description + "\n" + titleDecorator + + "\nPossible states (" + kind + "): {a, b, c" + defaultStateType + + "\n" + "Current state = " + defaultState; + std::string dump = criterion.getFormattedDescription(true, true); + CHECK(dump == description); + } + } + } + + void checkDisplay(Criterion& criterion) + { + std::string possibleValues = std::string("{a, b, c") + + (criterion.isInclusive() ? ", none" : "") + "}"; + WHEN("Adding some criterion value") { + std::string result; + REQUIRE_SUCCESS(criterion.addValuePair(2, "a", result), result); + REQUIRE_SUCCESS(criterion.addValuePair(4, "b", result), result); + REQUIRE_SUCCESS(criterion.addValuePair(8, "c", result), result); + THEN("Possible values match all values added in the criterion") { + CHECK(criterion.listPossibleValues() == possibleValues); + } + + checkSerialization(criterion); + + if (criterion.isInclusive()) { + WHEN("Setting some criterion value") { + std::bitset<32> stateMask("1110"); + criterion.setCriterionState(stateMask.to_ulong()); + THEN("Formatted state contains all set values") { + std::string formattedState = "a|b|c"; + CHECK(criterion.getFormattedState() == formattedState); + } + } + } + } + } + + void checkInsertionBijectivity(Criterion& criterion) + { + WHEN("Adding some criterion value") { + /** Generate 32 values, no more because inclusive criterion cannot handle it + * Unbounded values are tested later for inclusive criterion + */ + CriterionValues criterionValues = generateCriterionValues(criterion.isInclusive(), 32); + + for (auto& value : criterionValues) { + std::string result; + REQUIRE_SUCCESS(criterion.addValuePair(value.first, value.second, result), result); + + THEN("Numerical value should correspond") { + int numericalValue; + REQUIRE_SUCCESS(criterion.getNumericalValue(value.second, numericalValue)); + CHECK(numericalValue == value.first); + } + THEN("Literal value should correspond") { + std::string literalValue; + REQUIRE_SUCCESS(criterion.getLiteralValue(value.first, literalValue)); + CHECK(literalValue == value.second); + } + } + + checkExclusiveCriterionSet(criterion, criterionValues); + if (criterion.isInclusive()) { + // Inclusive criterion has a more evolved setting behavior + checkInclusiveCriterionSet(criterion); + } + } + } + + void checkCriterionBasicBehavior(Criterion& criterion, std::string name) + { + using MatchMethods = std::vector; + /** key indicates if it's available for exclusive criterion */ + const std::map mMatchMethods{ + {true, {"Is", "IsNot"}}, + {false, {"Includes", "Excludes"}} + }; + + THEN("Only corresponding match method are available") { + for(auto& matcher : mMatchMethods) { + for(auto& matchMethod : matcher.second) { + INFO("Checking availibility of '" + matchMethod + "' match method"); + /** A method is authorized if available or if the criterion is not inclusive + * and the method is defined in mMatchMethods as unavailable for exclusive + * criterion + */ + bool isAuthorizedMethod = criterion.isMatchMethodAvailable(matchMethod) or + not (criterion.isInclusive() or matcher.first); + CHECK(isAuthorizedMethod); + } + } + } + + THEN("The criterion has not been modified") { + CHECK(not criterion.hasBeenModified()); + } + THEN("The criterion has the good name") { + CHECK(criterion.getCriterionName() == name); + } + + checkInsertionBijectivity(criterion); + checkExistingValueInsertion(criterion); + checkUnknownValueGet(criterion); + checkDisplay(criterion); + } + +}; + +SCENARIO_METHOD(CriterionTest, "Criterion lifecycle", "[criterion]") { + + GIVEN("An exclusive criterion") { + const std::string criterionName = "ExclusiveCriterion"; + Criterion criterion(criterionName, mLogger); + + THEN("The criterion is not inclusive") { + CHECK(not criterion.isInclusive()); + } + THEN("There is no available states") { + CHECK(criterion.listPossibleValues() == "{}"); + } + THEN("No state is currently set") { + CHECK(criterion.getFormattedState() == ""); + } + + checkCriterionBasicBehavior(criterion, criterionName); + + WHEN("We add an negative numerical value") { + std::string result; + // FIXME: allow only positive numerical value + REQUIRE_SUCCESS(criterion.addValuePair(-3, "Negative", result), result); + } + WHEN("We add a random numerical value") { + std::string result; + std::default_random_engine generator; + // FIXME: use uint32_t internally instead + // Criterion State type is int32_t + std::uniform_int_distribution dist; + int32_t numericalValue = dist(generator); + CAPTURE(numericalValue); + REQUIRE_SUCCESS(criterion.addValuePair(numericalValue, "Random", result), result); + } + } + + GIVEN("An inclusive criterion") { + const std::string criterionName = "InclusiveCriterion"; + InclusiveCriterion criterion(criterionName, mLogger); + + THEN("The criterion is inclusive") { + CHECK(criterion.isInclusive()); + } + THEN("Default state is available") { + const std::string defaultState = "none"; + CHECK(criterion.listPossibleValues() == "{" + defaultState + "}"); + int numericalValue; + REQUIRE_SUCCESS(criterion.getNumericalValue(defaultState, numericalValue)); + CHECK(numericalValue == 0); + std::string literalValue; + REQUIRE_SUCCESS(criterion.getLiteralValue(0, literalValue)); + CHECK(literalValue == defaultState); + } + THEN("Default state is set") { + CHECK(criterion.getCriterionState() == 0); + CHECK(criterion.getFormattedState() == "none"); + } + + checkCriterionBasicBehavior(criterion, criterionName); + + WHEN("We add a state with 0 as numerical value") { + std::string result; + REQUIRE_FAILURE(criterion.addValuePair(0, "Crit_0", result), result); + } + WHEN("We add a numerical value with more than one bit setted") { + std::string result; + REQUIRE_FAILURE(criterion.addValuePair(3, "InvalidMask", result), result); + } + } +} + +SCENARIO_METHOD(CriteriaTest, "Criteria Use", "[criterion]") { + + GIVEN("A criteria object") { + WHEN("Adding some criteria") { + + for(auto& description : mDescriptions) { + Criterion* addedCriterion = (description.isInclusive ? + mCriteria.createInclusiveCriterion(description.name, mLogger): + mCriteria.createExclusiveCriterion(description.name, mLogger)); + description.criterion = addedCriterion; + THEN("Added criteria match the request") { + CAPTURE(description.name); + CHECK(addedCriterion->isInclusive() == description.isInclusive); + CHECK(addedCriterion->getCriterionName() == description.name); + } + } + WHEN("Retrieving added criteria") { + for(auto& description : mDescriptions) { + CAPTURE(description.name); + CHECK(mCriteria.getSelectionCriterion(description.name) == + description.criterion); + const Criterion *criterion = mCriteria.getSelectionCriterion(description.name); + CHECK(criterion == description.criterion); + } + } + WHEN("Retrieving unknown criteria") { + CHECK(mCriteria.getSelectionCriterion("Unknown") == nullptr); + } + WHEN("Modifying criteria") { + for(auto& description : mDescriptions) { + std::string result; + REQUIRE_SUCCESS(description.criterion->addValuePair(1, "State", result), + result); + description.criterion->setCriterionState(1); + CHECK(description.criterion->hasBeenModified()); + } + WHEN("Resetting criteria status") { + mCriteria.resetModifiedStatus(); + THEN("Status of all criteria has been reset") { + for(auto& description : mDescriptions) { + CHECK(not description.criterion->hasBeenModified()); + } + } + } + } + WHEN("Listing criteria") { + checkListCriteria(true, true); + checkListCriteria(true, false); + checkListCriteria(false, true); + checkListCriteria(false, false); + } + WHEN("Deserializing criteria") { + std::string xmlDescription = + R"( + + + + + + + + + + )"; + + std::string result; + xmlSerialize(result, &mCriteria, "SelectionCriteria"); + + // Remove whitespaces as they are not relevant in xml + removeWhitespaces(result); + removeWhitespaces(xmlDescription); + + THEN("Generated xml match expectation") { + CHECK(result == xmlDescription); + } + } + } + } +} diff --git a/parameter/include/ParameterMgrFullConnector.h b/parameter/include/ParameterMgrFullConnector.h index 31022a6db..1e72f6535 100644 --- a/parameter/include/ParameterMgrFullConnector.h +++ b/parameter/include/ParameterMgrFullConnector.h @@ -29,10 +29,9 @@ */ #pragma once -#include "SelectionCriterionTypeInterface.h" -#include "SelectionCriterionInterface.h" #include "ParameterHandle.h" #include "ParameterMgrLoggerForward.h" +#include #include #include @@ -46,13 +45,18 @@ class CParameterMgrFullConnector friend class CParameterMgrLogger; public: + + /** String list type which can hold list of error/info and can be presented to client */ + typedef std::list Results; + CParameterMgrFullConnector(const std::string& strConfigurationFilePath); ~CParameterMgrFullConnector(); class ILogger { public: - virtual void log(bool bIsWarning, const std::string& strLog) = 0; + virtual void info(const std::string& strLog) = 0; + virtual void warning(const std::string& strLog) = 0; protected: virtual ~ILogger() {} }; @@ -66,10 +70,28 @@ class CParameterMgrFullConnector // Dynamic parameter handling CParameterHandle* createParameterHandle(const std::string& strPath, std::string& strError); - ISelectionCriterionTypeInterface* createSelectionCriterionType(bool bIsInclusive); - ISelectionCriterionInterface* createSelectionCriterion(const std::string& strName, - const ISelectionCriterionTypeInterface* pSelectionCriterionType); - ISelectionCriterionInterface* getSelectionCriterion(const std::string& strName); + /** Create a new Exclusive criterion + * Beware returned objects shall not be deleted by client. + * Should be called before start + * + * @param[in] name, the criterion name + * @return raw pointer on the criterion interface + */ + core::selection::criterion::CriterionInterface* + createExclusiveCriterion(const std::string& name); + + /** Create a new Inclusive criterion + * Beware returned objects shall not be deleted by client. + * Should be called before start + * + * @param[in] name, the criterion name + * @return raw pointer on the criterion interface + */ + core::selection::criterion::CriterionInterface* + createInclusiveCriterion(const std::string& name); + + core::selection::criterion::CriterionInterface* + getSelectionCriterion(const std::string& strName); /** Is the remote interface forcefully disabled ? */ @@ -182,8 +204,17 @@ class CParameterMgrFullConnector bool deleteConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); bool renameConfiguration(const std::string& strDomain, const std::string& strConfiguration, const std::string& strNewConfiguration, std::string& strError); - // Save/Restore - bool restoreConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::list& strError); + /** Restore a configuration + * + * @param[in] strDomain the domain name + * @param[in] strConfiguration the configuration name + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool restoreConfiguration(const std::string& strDomain, + const std::string& strConfiguration, + Results& errors); + bool saveConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); // Configurable element - domain association @@ -264,11 +295,13 @@ class CParameterMgrFullConnector CParameterMgrFullConnector(const CParameterMgrFullConnector&); CParameterMgrFullConnector& operator=(const CParameterMgrFullConnector&); - void doLog(bool bIsWarning, const std::string& strLog); + void info(const std::string& log); + void warning(const std::string& log); + + // Log wrapper + CParameterMgrLogger* _pParameterMgrLogger; CParameterMgr* _pParameterMgr; ILogger* _pLogger; - // Log wrapper - CParameterMgrLogger* _pParameterMgrLogger; }; diff --git a/parameter/include/ParameterMgrPlatformConnector.h b/parameter/include/ParameterMgrPlatformConnector.h index cd9921550..7c356f493 100644 --- a/parameter/include/ParameterMgrPlatformConnector.h +++ b/parameter/include/ParameterMgrPlatformConnector.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,10 +29,9 @@ */ #pragma once -#include "SelectionCriterionTypeInterface.h" -#include "SelectionCriterionInterface.h" #include "ParameterHandle.h" #include "ParameterMgrLoggerForward.h" +#include class CParameterMgr; @@ -44,7 +43,8 @@ class CParameterMgrPlatformConnector class ILogger { public: - virtual void log(bool bIsWarning, const std::string& strLog) = 0; + virtual void info(const std::string& strLog) = 0; + virtual void warning(const std::string& strLog) = 0; protected: virtual ~ILogger() {} }; @@ -53,12 +53,29 @@ class CParameterMgrPlatformConnector CParameterMgrPlatformConnector(const std::string& strConfigurationFilePath); ~CParameterMgrPlatformConnector(); // Not virtual since not supposed to be derived! - // Selection Criteria interface. Beware returned objects are lent, clients shall not delete them! - // Should be called before start - ISelectionCriterionTypeInterface* createSelectionCriterionType(bool bIsInclusive = false); - ISelectionCriterionInterface* createSelectionCriterion(const std::string& strName, const ISelectionCriterionTypeInterface* pSelectionCriterionType); + /** Create a new Exclusive criterion + * Beware returned objects shall not be deleted by client. + * Should be called before start + * + * @param[in] name, the criterion name + * @return raw pointer on the criterion interface + */ + core::selection::criterion::CriterionInterface* + createExclusiveCriterion(const std::string& name); + + /** Create a new Inclusive criterion + * Beware returned objects shall not be deleted by client. + * Should be called before start + * + * @param[in] name, the criterion name + * @return raw pointer on the criterion interface + */ + core::selection::criterion::CriterionInterface* + createInclusiveCriterion(const std::string& name); + // Selection criterion retrieval - ISelectionCriterionInterface* getSelectionCriterion(const std::string& strName) const; + core::selection::criterion::CriterionInterface* + getSelectionCriterion(const std::string& strName) const; // Logging // Should be called before start @@ -160,14 +177,15 @@ class CParameterMgrPlatformConnector CParameterMgrPlatformConnector(const CParameterMgrPlatformConnector&); CParameterMgrPlatformConnector& operator=(const CParameterMgrPlatformConnector&); // Private logging - void doLog(bool bIsWarning, const std::string& strLog); + void info(const std::string& log); + void warning(const std::string& log); + // Private logging + CParameterMgrLogger* _pParameterMgrLogger; // Implementation CParameterMgr* _pParameterMgr; // State bool _bStarted; // Logging ILogger* _pLogger; - // Private logging - CParameterMgrLogger* _pParameterMgrLogger; }; diff --git a/parameter/include/SelectionCriterionTypeInterface.h b/parameter/log/include/log/Context.h similarity index 66% rename from parameter/include/SelectionCriterionTypeInterface.h rename to parameter/log/include/log/Context.h index 0b62ee46a..b466ad2d1 100644 --- a/parameter/include/SelectionCriterionTypeInterface.h +++ b/parameter/log/include/log/Context.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,18 +29,45 @@ */ #pragma once +#include "log/Logger.h" #include -class ISelectionCriterionTypeInterface +namespace core { +namespace log +{ + +/** Log formatter which provide context indentation */ +class Context { public: - virtual bool addValuePair(int iValue, const std::string& strValue) = 0; - virtual bool getNumericalValue(const std::string& strValue, int& iValue) const = 0; - virtual bool getLiteralValue(int iValue, std::string& strValue) const = 0; - virtual bool isTypeInclusive() const = 0; - virtual std::string getFormattedState(int iValue) const = 0; - -protected: - virtual ~ISelectionCriterionTypeInterface() {} + + /** + * Class Constructor + * + * @param[in] logger application logger + * @param[in] context name of the context to open + */ + Context(Logger& logger, const std::string& context) + : mLogger(logger) + { + mLogger.info() << context << " {"; + mLogger.mProlog += " "; + } + + /** Class Destructor */ + ~Context() + { + mLogger.mProlog.resize(mLogger.mProlog.size() - 4); + mLogger.info() << "}"; + } + +private: + Context(const Context&); + Context& operator=(const Context&); + + /** Application logger */ + Logger& mLogger; }; +} /** log namespace */ +} /** core namespace */ diff --git a/parameter/SelectionCriterionLibrary.h b/parameter/log/include/log/ILogger.h similarity index 81% rename from parameter/SelectionCriterionLibrary.h rename to parameter/log/include/log/ILogger.h index bb19777fd..895f8e9f6 100644 --- a/parameter/SelectionCriterionLibrary.h +++ b/parameter/log/include/log/ILogger.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,17 +29,22 @@ */ #pragma once -#include "Element.h" -#include "SelectionCriterionType.h" +#include -class CSelectionCriterionLibrary : public CElement +namespace core +{ +namespace log { -public: - CSelectionCriterionLibrary(); - - // Type creation - CSelectionCriterionType* createSelectionCriterionType(bool bIsInclusive); - // CElement - virtual std::string getKind() const; +/** Logger interface provided by client */ +class ILogger +{ +public: + virtual void info(const std::string& strLog) = 0; + virtual void warning(const std::string& strLog) = 0; +protected: + virtual ~ILogger() {} }; + +} /** log namespace */ +} /** core namespace */ diff --git a/parameter/log/include/log/LogWrapper.h b/parameter/log/include/log/LogWrapper.h new file mode 100644 index 000000000..14007d4b7 --- /dev/null +++ b/parameter/log/include/log/LogWrapper.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#include "log/ILogger.h" +#include "Utility.h" +#include +#include +#include +#include + +namespace core +{ +namespace log +{ +namespace details +{ + +/** + * Template log wrapper + * Simulate a stream which can be used instead of basic ILogger API. + * + * @tparam isWarning indicates which log canal to use + */ +template +class LogWrapper +{ +public: + + /** @param logger the ILogger to wrap */ + LogWrapper(ILogger& logger, const std::string& prolog = "") + : mLogger(logger), mProlog(prolog) + {} + + /** + * Class copy constructor + * + * @param[in] logWrapper the instance to copy + */ + LogWrapper(const LogWrapper& logWrapper) + : mLogger(logWrapper.mLogger), mProlog(logWrapper.mProlog) + {} + + /** Class destructor */ + ~LogWrapper() + { + if (!mLog.str().empty()) { + if(isWarning) { + mLogger.warning(mProlog + mLog.str()); + } else { + mLogger.info(mProlog + mLog.str()); + } + } + } + + /** + * Simulate stream behaviour + * + * @tparam T the type of the information to log + * @param[in] log the information to log + */ + template + LogWrapper& operator<<(const T &log) + { + mLog << log; + return *this; + } + + /** + * Simulate stream behaviour for string list + * + * @param[in] logs list of information to log + */ + LogWrapper& operator<<(const std::list& logs) + { + std::string formatedLogs; + std::string separator = "\n" + mProlog; + CUtility::asString(logs, formatedLogs, separator); + + // Check if there is something in the log to know if we have to add a prefix + if (!mLog.str().empty() && mLog.str()[mLog.str().length()-1] == separator[0]) { + *this << mProlog; + } + + *this << formatedLogs; + return *this; + } + +private: + LogWrapper& operator=(const LogWrapper&); + + /** Log stream holder */ + std::ostringstream mLog; + + /** Wrapped logger */ + ILogger& mLogger; + + /** Log Prefix */ + const std::string& mProlog; +}; + +/** Default information logger type */ +typedef details::LogWrapper Info; + +/** Default warning logger type */ +typedef details::LogWrapper Warning; + +} /** details namespace */ +} /** log namespace */ +} /** core namespace */ diff --git a/parameter/log/include/log/Logger.h b/parameter/log/include/log/Logger.h new file mode 100644 index 000000000..c3b40aaaa --- /dev/null +++ b/parameter/log/include/log/Logger.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#include "log/ILogger.h" +#include "log/LogWrapper.h" + +namespace core +{ +namespace log +{ + +/** Application logger object (Thread unsafe) + * Provide contextualisable logging API. + * Streams can be used through Info and Warning objects returned by dedicated + * methods. + * This is the class you want to use to log in the project. + */ +class Logger +{ +public: + + /** Context class is friend let the prolog by externally modified */ + friend class Context; + + /** @param[in] logger, raw logger provided by client */ + Logger(ILogger& logger) : mLogger(logger) {} + + /** + * Retrieve wrapped information logger + * + * @return Info logger + */ + details::Info info() + { + return details::Info(mLogger, mProlog); + } + + /** + * Retrieve wrapped warning logger + * + * @return Warning logger + */ + details::Warning warning() + { + return details::Warning(mLogger, mProlog); + } + +private: + + /** Raw logger provided by client */ + ILogger& mLogger; + + /** Log prolog, owns the context indentation */ + std::string mProlog; +}; + +} /** log namespace */ +} /** core namespace */ diff --git a/skeleton-subsystem/CMakeLists.txt b/skeleton-subsystem/CMakeLists.txt index 6a832233c..b20621b66 100644 --- a/skeleton-subsystem/CMakeLists.txt +++ b/skeleton-subsystem/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2014, Intel Corporation +# Copyright (c) 2015, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -45,8 +45,13 @@ find_path(PFW_CORE_INCLUDE_DIR NAMES Subsystem.h HINTS ${PFW_CORE_ROOT_DIR}/include/parameter/plugin) find_path(PFW_XMLSERIALIZER_INCLUDE_DIR NAMES XmlSink.h HINTS ${PFW_CORE_ROOT_DIR}/include/xmlserializer) +find_path(PFW_UTILITY_INCLUDE_DIR NAMES Utility.h + HINTS ${PFW_CORE_ROOT_DIR}/include/utility) -set(PFW_INCLUDE_DIRS ${PFW_CORE_INCLUDE_DIR} ${PFW_XMLSERIALIZER_INCLUDE_DIR}) +set(PFW_INCLUDE_DIRS + ${PFW_CORE_INCLUDE_DIR} + ${PFW_XMLSERIALIZER_INCLUDE_DIR} + ${PFW_UTILITY_INCLUDE_DIR}) set(PFW_LIBRARIES ${PFW_CORE_LIBRARY}) add_library(skeleton-subsystem SHARED diff --git a/skeleton-subsystem/SkeletonSubsystem.cpp b/skeleton-subsystem/SkeletonSubsystem.cpp index e3cbcbafb..56fedebea 100644 --- a/skeleton-subsystem/SkeletonSubsystem.cpp +++ b/skeleton-subsystem/SkeletonSubsystem.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -35,7 +35,8 @@ #define base CSubsystem // Implementation -CSkeletonSubsystem::CSkeletonSubsystem(const std::string& strName) : base(strName) +CSkeletonSubsystem::CSkeletonSubsystem(const std::string& strName, core::log::Logger& logger) + : base(strName, logger) { // Provide mapping keys to upper layer addContextMappingKey("Owner"); diff --git a/skeleton-subsystem/SkeletonSubsystem.h b/skeleton-subsystem/SkeletonSubsystem.h index 26cd65968..82e6e09a1 100644 --- a/skeleton-subsystem/SkeletonSubsystem.h +++ b/skeleton-subsystem/SkeletonSubsystem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -34,7 +34,7 @@ class CSkeletonSubsystem : public CSubsystem { public: - CSkeletonSubsystem(const std::string& strName); + CSkeletonSubsystem(const std::string& strName, core::log::Logger& logger); }; diff --git a/skeleton-subsystem/SkeletonSubsystemBuilder.cpp b/skeleton-subsystem/SkeletonSubsystemBuilder.cpp index a6aae2d54..553b716e2 100644 --- a/skeleton-subsystem/SkeletonSubsystemBuilder.cpp +++ b/skeleton-subsystem/SkeletonSubsystemBuilder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -28,7 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "SubsystemLibrary.h" -#include "NamedElementBuilderTemplate.h" +#include "LoggingElementBuilderTemplate.h" #include "SkeletonSubsystem.h" @@ -43,8 +43,10 @@ extern "C" * The plugin symbol is of the form: * getSubsystemBuilder */ -void getSKELETONSubsystemBuilder(CSubsystemLibrary* pSubsystemLibrary) +void getSKELETONSubsystemBuilder(CSubsystemLibrary* pSubsystemLibrary, core::log::Logger& logger) { - pSubsystemLibrary->addElementBuilder("Skeleton", new TNamedElementBuilderTemplate()); + pSubsystemLibrary->addElementBuilder( + "Skeleton", + new TLoggingElementBuilderTemplate(logger)); } } diff --git a/skeleton-subsystem/SkeletonSubsystemObject.cpp b/skeleton-subsystem/SkeletonSubsystemObject.cpp index 5ecded90a..1098954c4 100644 --- a/skeleton-subsystem/SkeletonSubsystemObject.cpp +++ b/skeleton-subsystem/SkeletonSubsystemObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -48,9 +48,11 @@ using std::string; CSkeletonSubsystemObject::CSkeletonSubsystemObject( const string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, - const CMappingContext& context + const CMappingContext& context, + core::log::Logger& logger ) : base(pInstanceConfigurableElement, + logger, strMappingValue, EAmend1, EAmendEnd - EAmend1 + 1, diff --git a/skeleton-subsystem/SkeletonSubsystemObject.h b/skeleton-subsystem/SkeletonSubsystemObject.h index f2927746d..9c1cb0b89 100644 --- a/skeleton-subsystem/SkeletonSubsystemObject.h +++ b/skeleton-subsystem/SkeletonSubsystemObject.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -36,7 +36,10 @@ class CMappingContext; class CSkeletonSubsystemObject : public CFormattedSubsystemObject { public: - CSkeletonSubsystemObject(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context); + CSkeletonSubsystemObject(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger); protected: // from CSubsystemObject diff --git a/test/functional-tests/Util/PfwUnitTestLib.py b/test/functional-tests/Util/PfwUnitTestLib.py index d9c2f8ce4..05fc3da01 100644 --- a/test/functional-tests/Util/PfwUnitTestLib.py +++ b/test/functional-tests/Util/PfwUnitTestLib.py @@ -67,10 +67,10 @@ def stopHal(self): subprocess.call("remote-process localhost 5001 exit", shell=True) def createInclusiveCriterion(self, name, nb): - self.sendCmd("createInclusiveSelectionCriterion", name, nb) + self.sendCmd("createInclusiveCriterion", name, nb) def createExclusiveCriterion(self, name, nb): - self.sendCmd("createExclusiveSelectionCriterion", name, nb) + self.sendCmd("createExclusiveCriterion", name, nb) # Starts the Pfw def start(self): diff --git a/test/test-fixed-point-parameter/Main.py b/test/test-fixed-point-parameter/Main.py index 6d7b2922b..31e10a5fb 100755 --- a/test/test-fixed-point-parameter/Main.py +++ b/test/test-fixed-point-parameter/Main.py @@ -39,9 +39,11 @@ def __init__(self): super(PfwLogger, self).__init__() self.__logger = logging.root.getChild("parameter-framework") - def log(self, is_warning, message): - log_func = self.__logger.warning if is_warning else self.__logger.info - log_func(message) + def info(self, message): + self.__logger.info(message) + + def warning(self, message): + self.__logger.warning(message) class FixedPointTester(): """ Made for testing a particular Qn.m number diff --git a/test/test-platform/CMakeLists.txt b/test/test-platform/CMakeLists.txt index b82405703..aebec2e83 100644 --- a/test/test-platform/CMakeLists.txt +++ b/test/test-platform/CMakeLists.txt @@ -34,6 +34,7 @@ add_executable(test-platform set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") include_directories( + "${PROJECT_SOURCE_DIR}/parameter/criterion/include" "${PROJECT_SOURCE_DIR}/parameter/include" "${PROJECT_SOURCE_DIR}/remote-processor" "${PROJECT_SOURCE_DIR}/utility") diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index 9cb45f7ff..2a0768c08 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -41,22 +41,21 @@ #include "RemoteProcessorServer.h" using std::string; +using core::selection::criterion::CriterionInterface; class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnector::ILogger { public: CParameterMgrPlatformConnectorLogger() {} - virtual void log(bool bIsWarning, const string& strLog) + virtual void info(const string& log) { + std::cout << log << std::endl; + } - if (bIsWarning) { - - std::cerr << strLog << std::endl; - } else { - - std::cout << strLog << std::endl; - } + virtual void warning(const string& log) + { + std::cerr << log << std::endl; } }; @@ -72,23 +71,23 @@ CTestPlatform::CTestPlatform(const string& strClass, int iPortNumber, sem_t& exi _pCommandHandler->addCommandParser("exit", &CTestPlatform::exit, 0, "", "Exit TestPlatform"); _pCommandHandler->addCommandParser( - "createExclusiveSelectionCriterionFromStateList", - &CTestPlatform::createExclusiveSelectionCriterionFromStateList, + "createExclusiveCriterionFromStateList", + &CTestPlatform::createExclusiveCriterionFromStateList, 2, " ", "Create inclusive selection criterion from state name list"); _pCommandHandler->addCommandParser( - "createInclusiveSelectionCriterionFromStateList", - &CTestPlatform::createInclusiveSelectionCriterionFromStateList, + "createInclusiveCriterionFromStateList", + &CTestPlatform::createInclusiveCriterionFromStateList, 2, " ", "Create exclusive selection criterion from state name list"); _pCommandHandler->addCommandParser( - "createExclusiveSelectionCriterion", - &CTestPlatform::createExclusiveSelectionCriterion, + "createExclusiveCriterion", + &CTestPlatform::createExclusiveCriterion, 2, " ", "Create inclusive selection criterion"); _pCommandHandler->addCommandParser( - "createInclusiveSelectionCriterion", - &CTestPlatform::createInclusiveSelectionCriterion, + "createInclusiveCriterion", + &CTestPlatform::createInclusiveCriterion, 2, " ", "Create exclusive selection criterion"); _pCommandHandler->addCommandParser("start", &CTestPlatform::startParameterMgr, @@ -177,39 +176,39 @@ bool CTestPlatform::load(std::string& strError) //////////////// Remote command parsers /// Selection Criterion -CTestPlatform::CommandReturn CTestPlatform::createExclusiveSelectionCriterionFromStateList( - const IRemoteCommand& remoteCommand, string& strResult) +CTestPlatform::CommandReturn +CTestPlatform::createExclusiveCriterionFromStateList(const IRemoteCommand& remoteCommand, + string& strResult) { - return createExclusiveSelectionCriterionFromStateList( - remoteCommand.getArgument(0), remoteCommand, strResult) ? + return createExclusiveCriterionFromStateList(remoteCommand.getArgument(0), + remoteCommand, strResult) ? CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; } -CTestPlatform::CommandReturn CTestPlatform::createInclusiveSelectionCriterionFromStateList( +CTestPlatform::CommandReturn CTestPlatform::createInclusiveCriterionFromStateList( const IRemoteCommand& remoteCommand, string& strResult) { - return createInclusiveSelectionCriterionFromStateList( - remoteCommand.getArgument(0), remoteCommand, strResult) ? + return createInclusiveCriterionFromStateList(remoteCommand.getArgument(0), + remoteCommand, strResult) ? CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; } -CTestPlatform::CommandReturn CTestPlatform::createExclusiveSelectionCriterion( - const IRemoteCommand& remoteCommand, string& strResult) +CTestPlatform::CommandReturn +CTestPlatform::createExclusiveCriterion(const IRemoteCommand& remoteCommand, + string& strResult) { - return createExclusiveSelectionCriterion( - remoteCommand.getArgument(0), - strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), - strResult) ? + return createExclusiveCriterion(remoteCommand.getArgument(0), + strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), + strResult) ? CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; } -CTestPlatform::CommandReturn CTestPlatform::createInclusiveSelectionCriterion( - const IRemoteCommand& remoteCommand, string& strResult) +CTestPlatform::CommandReturn +CTestPlatform::createInclusiveCriterion(const IRemoteCommand& remoteCommand, string& strResult) { - return createInclusiveSelectionCriterion( - remoteCommand.getArgument(0), - strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), - strResult) ? + return createInclusiveCriterion(remoteCommand.getArgument(0), + strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), + strResult) ? CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; } @@ -291,18 +290,17 @@ CTestPlatform::CommandReturn CTestPlatform::applyConfigurations(const IRemoteCom //////////////// Remote command handlers -bool CTestPlatform::createExclusiveSelectionCriterionFromStateList( - const string& strName, - const IRemoteCommand& remoteCommand, - string& strResult) +bool CTestPlatform::createExclusiveCriterionFromStateList(const string& strName, + const IRemoteCommand& remoteCommand, + string& strResult) { assert(_pParameterMgrPlatformConnector != NULL); - ISelectionCriterionTypeInterface* pCriterionType = - _pParameterMgrPlatformConnector->createSelectionCriterionType(false); + CriterionInterface* pCriterion = + _pParameterMgrPlatformConnector->createExclusiveCriterion(strName); - assert(pCriterionType != NULL); + assert(pCriterion!= NULL); uint32_t uiNbStates = remoteCommand.getArgumentCount() - 1; uint32_t uiState; @@ -311,30 +309,28 @@ bool CTestPlatform::createExclusiveSelectionCriterionFromStateList( const std::string& strValue = remoteCommand.getArgument(uiState + 1); - if (!pCriterionType->addValuePair(uiState, strValue)) { + if (!pCriterion->addValuePair(uiState, strValue, strResult)) { - strResult = "Unable to add value: " + strValue; + strResult = "Unable to add value: " + strValue + ": " + strResult; return false; } } - _pParameterMgrPlatformConnector->createSelectionCriterion(strName, pCriterionType); return true; } -bool CTestPlatform::createInclusiveSelectionCriterionFromStateList( - const string& strName, - const IRemoteCommand& remoteCommand, - string& strResult) +bool CTestPlatform::createInclusiveCriterionFromStateList(const string& strName, + const IRemoteCommand& remoteCommand, + string& strResult) { assert(_pParameterMgrPlatformConnector != NULL); - ISelectionCriterionTypeInterface* pCriterionType = - _pParameterMgrPlatformConnector->createSelectionCriterionType(true); + CriterionInterface* pCriterion = + _pParameterMgrPlatformConnector->createInclusiveCriterion(strName); - assert(pCriterionType != NULL); + assert(pCriterion != NULL); uint32_t uiNbStates = remoteCommand.getArgumentCount() - 1; @@ -351,26 +347,24 @@ bool CTestPlatform::createInclusiveSelectionCriterionFromStateList( const std::string& strValue = remoteCommand.getArgument(uiState + 1); - if (!pCriterionType->addValuePair(0x1 << uiState, strValue)) { + if (!pCriterion->addValuePair(0x1 << uiState, strValue, strResult)) { - strResult = "Unable to add value: " + strValue; + strResult = "Unable to add value: " + strValue + ": " + strResult; return false; } } - _pParameterMgrPlatformConnector->createSelectionCriterion(strName, pCriterionType); - return true; } -bool CTestPlatform::createExclusiveSelectionCriterion(const string& strName, - uint32_t uiNbStates, - string& strResult) +bool CTestPlatform::createExclusiveCriterion(const string& strName, + uint32_t uiNbStates, + string& strResult) { - ISelectionCriterionTypeInterface* pCriterionType = - _pParameterMgrPlatformConnector->createSelectionCriterionType(false); + CriterionInterface* pCriterion = + _pParameterMgrPlatformConnector->createExclusiveCriterion(strName); uint32_t uistate; @@ -381,25 +375,24 @@ bool CTestPlatform::createExclusiveSelectionCriterion(const string& strName, ostrValue << "State_"; ostrValue << uistate; - if (!pCriterionType->addValuePair(uistate, ostrValue.str())) { + if (!pCriterion->addValuePair(uistate, ostrValue.str(), strResult)) { - strResult = "Unable to add value: " + ostrValue.str(); + strResult = "Unable to add value: " + + ostrValue.str() + ": " + strResult; return false; } } - _pParameterMgrPlatformConnector->createSelectionCriterion(strName, pCriterionType); - return true; } -bool CTestPlatform::createInclusiveSelectionCriterion(const string& strName, - uint32_t uiNbStates, - string& strResult) +bool CTestPlatform::createInclusiveCriterion(const string& strName, + uint32_t uiNbStates, + string& strResult) { - ISelectionCriterionTypeInterface* pCriterionType = - _pParameterMgrPlatformConnector->createSelectionCriterionType(true); + CriterionInterface* pCriterion = + _pParameterMgrPlatformConnector->createInclusiveCriterion(strName); if (uiNbStates > 32) { @@ -417,22 +410,21 @@ bool CTestPlatform::createInclusiveSelectionCriterion(const string& strName, ostrValue << "State_0x"; ostrValue << (0x1 << uiState); - if (!pCriterionType->addValuePair(0x1 << uiState, ostrValue.str())) { + if (!pCriterion->addValuePair(0x1 << uiState, ostrValue.str(), strResult)) { - strResult = "Unable to add value: " + ostrValue.str(); + strResult = "Unable to add value: " + + ostrValue.str() + ": " + strResult; return false; } } - _pParameterMgrPlatformConnector->createSelectionCriterion(strName, pCriterionType); - return true; } bool CTestPlatform::setCriterionState(const string& strName, uint32_t uiState, string& strResult) { - ISelectionCriterionInterface* pCriterion = + CriterionInterface* pCriterion = _pParameterMgrPlatformConnector->getSelectionCriterion(strName); if (!pCriterion) { @@ -454,7 +446,7 @@ bool CTestPlatform::setCriterionStateByLexicalSpace(const IRemoteCommand& remote // Get criterion name std::string strCriterionName = remoteCommand.getArgument(0); - ISelectionCriterionInterface* pCriterion = + CriterionInterface* pCriterion = _pParameterMgrPlatformConnector->getSelectionCriterion(strCriterionName); if (!pCriterion) { @@ -464,14 +456,11 @@ bool CTestPlatform::setCriterionStateByLexicalSpace(const IRemoteCommand& remote return false; } - // Get criterion type - const ISelectionCriterionTypeInterface* pCriterionType = pCriterion->getCriterionType(); - // Get substate number, the first argument (index 0) is the criterion name uint32_t uiNbSubStates = remoteCommand.getArgumentCount() - 1; // Check that exclusive criterion has only one substate - if (!pCriterionType->isTypeInclusive() && uiNbSubStates != 1) { + if (!pCriterion->isInclusive() && uiNbSubStates != 1) { strResult = "Exclusive criterion " + strCriterionName + " can only have one state"; @@ -489,7 +478,7 @@ bool CTestPlatform::setCriterionStateByLexicalSpace(const IRemoteCommand& remote uiLexicalSubStateIndex <= uiNbSubStates; uiLexicalSubStateIndex++) { /* - * getNumericalValue method from ISelectionCriterionTypeInterface strip his parameter + * getNumericalValue method from CriterionInterface strip his parameter * first parameter based on | sign. In case that the user uses multiple parameters * to set InclusiveCriterion value, we aggregate all desired values to be sure * they will be handled correctly. @@ -501,7 +490,7 @@ bool CTestPlatform::setCriterionStateByLexicalSpace(const IRemoteCommand& remote } // Translate lexical to numerical substate - if (!pCriterionType->getNumericalValue(strLexicalState, iNumericalState)) { + if (!pCriterion->getNumericalValue(strLexicalState, iNumericalState)) { strResult = "Unable to find lexical state \"" + strLexicalState + "\" in criteria " + strCriterionName; diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index e9d1dd41a..e9695101a 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -37,7 +37,6 @@ class CParameterMgrPlatformConnectorLogger; class CRemoteProcessorServer; -class ISelectionCriterionInterface; class CTestPlatform { @@ -52,18 +51,50 @@ class CTestPlatform private: //////////////// Remote command parsers - /// Selection Criterion - CommandReturn createExclusiveSelectionCriterionFromStateList( - const IRemoteCommand& remoteCommand, std::string& strResult); - CommandReturn createInclusiveSelectionCriterionFromStateList( - const IRemoteCommand& remoteCommand, std::string& strResult); - CommandReturn createExclusiveSelectionCriterion( - const IRemoteCommand& remoteCommand, std::string& strResult); - CommandReturn createInclusiveSelectionCriterion( - const IRemoteCommand& remoteCommand, std::string& strResult); + /** Callback to create an Exclusive Criterion from possible state list + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * @param[in] remoteCommand the first argument should be the name of the criterion to create. + * the following arguments should be criterion possible values + */ + CommandReturn createExclusiveCriterionFromStateList(const IRemoteCommand& remoteCommand, + std::string& strResult); - /** Callback to set a criterion's value, see ISelectionCriterionInterface::setCriterionState. + /** Callback to create an Inclusive Criterion from possible state list + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * @param[in] remoteCommand the first argument should be the name of the criterion to create. + * the following arguments should be criterion possible values + */ + CommandReturn createInclusiveCriterionFromStateList(const IRemoteCommand& remoteCommand, + std::string& strResult); + + /** Callback to create an Exclusive Criterion + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * @param[in] remoteCommand the first argument should be the name of the criterion to create. + * the second argument should be criterion possible values number + * + * Generated states numerical value will be like: State_0xX, where X is the value number of the + * state. + */ + CommandReturn createExclusiveCriterion(const IRemoteCommand& remoteCommand, + std::string& strResult); + + /** Callback to create an Inclusive Criterion + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * @param[in] remoteCommand the first argument should be the name of the criterion to create. + * the second argument should be criterion possible values number + * + * Generated states numerical value will be like: State_X, where X is the value number of the + * state. + */ + CommandReturn createInclusiveCriterion(const IRemoteCommand& remoteCommand, + std::string& strResult); + + /** Callback to set a criterion's value, see CriterionInterface::setCriterionState. * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return * * @param[in] remoteCommand the first argument should be the name of the criterion to set. @@ -133,11 +164,45 @@ class CTestPlatform CommandReturn getter(const IRemoteCommand& remoteCommand, std::string& strResult); // Commands - bool createExclusiveSelectionCriterionFromStateList(const std::string& strName, const IRemoteCommand& remoteCommand, std::string& strResult); - bool createInclusiveSelectionCriterionFromStateList(const std::string& strName, const IRemoteCommand& remoteCommand, std::string& strResult); - bool createExclusiveSelectionCriterion(const std::string& strName, uint32_t uiNbValues, std::string& strResult); - bool createInclusiveSelectionCriterion(const std::string& strName, uint32_t uiNbValues, std::string& strResult); + /** @see callback with the same name for details and other parameters + * + * @param[out] strResult useful information that client may want to retrieve + * @return true if success, false otherwise + */ + bool createExclusiveCriterionFromStateList(const std::string& strName, + const IRemoteCommand& remoteCommand, + std::string& strResult); + + /** @see callback with the same name for details and other parameters + * + * @param[out] strResult useful information that client may want to retrieve + * @return true if success, false otherwise + */ + bool createInclusiveCriterionFromStateList(const std::string& strName, + const IRemoteCommand& remoteCommand, + std::string& strResult); + + /** @see callback with the same name for details and other parameters + * + * @param[in] uiNbValues number of possible state value the criterion can have + * @param[out] strResult useful information that client may want to retrieve + * @return true if success, false otherwise + */ + bool createExclusiveCriterion(const std::string& strName, + uint32_t uiNbValues, + std::string& strResult); + + /** @see callback with the same name for details and other parameters + * + * @param[in] uiNbValues number of possible state value the criterion can have + * @param[out] strResult useful information that client may want to retrieve + * @return true if success, false otherwise + */ + bool createInclusiveCriterion(const std::string& strName, + uint32_t uiNbValues, + std::string& strResult); + bool setCriterionState(const std::string& strName, uint32_t uiState, std::string& strResult); bool setCriterionStateByLexicalSpace(const IRemoteCommand& remoteCommand, std::string& strResult); diff --git a/test/test-subsystem/CMakeLists.txt b/test/test-subsystem/CMakeLists.txt index 52e66b024..b499923d1 100644 --- a/test/test-subsystem/CMakeLists.txt +++ b/test/test-subsystem/CMakeLists.txt @@ -37,7 +37,8 @@ if (BUILD_TESTING) include_directories( "${PROJECT_SOURCE_DIR}/xmlserializer" - "${PROJECT_SOURCE_DIR}/remote-processor" + "${PROJECT_SOURCE_DIR}/utility" + "${PROJECT_SOURCE_DIR}/parameter/log/include" "${PROJECT_SOURCE_DIR}/parameter") target_link_libraries(test-subsystem parameter) diff --git a/test/test-subsystem/TESTSubsystem.cpp b/test/test-subsystem/TESTSubsystem.cpp index 214fbb762..c2f288131 100644 --- a/test/test-subsystem/TESTSubsystem.cpp +++ b/test/test-subsystem/TESTSubsystem.cpp @@ -43,7 +43,8 @@ const char* gacFwNamePropName = getenv("PFW_RESULT"); // Implementation -CTESTSubsystem::CTESTSubsystem(const std::string& strName) : base(strName) +CTESTSubsystem::CTESTSubsystem(const std::string& strName, core::log::Logger& logger) + : base(strName, logger) { // Provide mapping keys to upper layer addContextMappingKey("Directory"); diff --git a/test/test-subsystem/TESTSubsystem.h b/test/test-subsystem/TESTSubsystem.h index bcd0fbdd7..9dfb10580 100644 --- a/test/test-subsystem/TESTSubsystem.h +++ b/test/test-subsystem/TESTSubsystem.h @@ -34,7 +34,7 @@ class CTESTSubsystem : public CSubsystem { public: - CTESTSubsystem(const std::string& strName); + CTESTSubsystem(const std::string& strName, core::log::Logger& logger); // Susbsystem sanity virtual bool isAlive() const; diff --git a/test/test-subsystem/TESTSubsystemBinary.cpp b/test/test-subsystem/TESTSubsystemBinary.cpp index 540fde806..72dcee320 100644 --- a/test/test-subsystem/TESTSubsystemBinary.cpp +++ b/test/test-subsystem/TESTSubsystemBinary.cpp @@ -35,8 +35,11 @@ #define base CTESTSubsystemObject -CTESTSubsystemBinary::CTESTSubsystemBinary(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context) - : base(strMappingValue, pInstanceConfigurableElement, context) +CTESTSubsystemBinary::CTESTSubsystemBinary(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger) + : base(strMappingValue, pInstanceConfigurableElement, context, logger) { } diff --git a/test/test-subsystem/TESTSubsystemBinary.h b/test/test-subsystem/TESTSubsystemBinary.h index a8d433e04..22a7b3968 100644 --- a/test/test-subsystem/TESTSubsystemBinary.h +++ b/test/test-subsystem/TESTSubsystemBinary.h @@ -34,7 +34,10 @@ class CTESTSubsystemBinary : public CTESTSubsystemObject { public: - CTESTSubsystemBinary(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context); + CTESTSubsystemBinary(const std::string& strMappingValue, + CInstanceConfigurableElement* configurableElement, + const CMappingContext& context, + core::log::Logger& logger); private: // from CTESTSubsystemObject diff --git a/test/test-subsystem/TESTSubsystemBuilder.cpp b/test/test-subsystem/TESTSubsystemBuilder.cpp index bcf2afc1d..a2628dfc1 100644 --- a/test/test-subsystem/TESTSubsystemBuilder.cpp +++ b/test/test-subsystem/TESTSubsystemBuilder.cpp @@ -28,15 +28,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "SubsystemLibrary.h" -#include "NamedElementBuilderTemplate.h" +#include "LoggingElementBuilderTemplate.h" #include "TESTSubsystem.h" extern "C" { -void getTESTSubsystemBuilder(CSubsystemLibrary* pSubsystemLibrary) +void getTESTSubsystemBuilder(CSubsystemLibrary* pSubsystemLibrary, core::log::Logger& logger) { pSubsystemLibrary->addElementBuilder("TEST", - new TNamedElementBuilderTemplate()); + new TLoggingElementBuilderTemplate( + logger)); } } diff --git a/test/test-subsystem/TESTSubsystemObject.cpp b/test/test-subsystem/TESTSubsystemObject.cpp index 706053fed..818eec95f 100644 --- a/test/test-subsystem/TESTSubsystemObject.cpp +++ b/test/test-subsystem/TESTSubsystemObject.cpp @@ -34,11 +34,16 @@ #include "TESTMappingKeys.h" #include "InstanceConfigurableElement.h" #include "TESTSubsystemObject.h" +#include +#include #define base CSubsystemObject -CTESTSubsystemObject::CTESTSubsystemObject(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context) - : base(pInstanceConfigurableElement) +CTESTSubsystemObject::CTESTSubsystemObject(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger) + : base(pInstanceConfigurableElement, logger) { (void)strMappingValue; // Get actual element type @@ -110,10 +115,12 @@ void CTESTSubsystemObject::sendToFile(std::ofstream& outputFile) if (_bIsScalar) { - log_info("TESTSUBSYSTEM: Writing \"%s\" to file %s", strValue.c_str(), _strFilePath.c_str()); + _logger.info() << "TESTSUBSYSTEM: Writing '" << strValue + << "' to file " << _strFilePath; } else { - log_info("TESTSUBSYSTEM: Writing \"%s\" to file %s[%d]", strValue.c_str(), _strFilePath.c_str(), uiIndex); + _logger.info() << "TESTSUBSYSTEM: Writing '" << strValue << "' to file " + << _strFilePath << "[" << uiIndex << "]"; } } } @@ -135,10 +142,12 @@ void CTESTSubsystemObject::receiveFromFile(std::ifstream& inputFile) if (_bIsScalar) { - log_info("TESTSUBSYSTEM: Writing \"%s\" from file %s", strValue.c_str(), _strFilePath.c_str()); + _logger.info() << "TESTSUBSYSTEM: Reading '" << strValue + << "' to file " << _strFilePath; } else { - log_info("TESTSUBSYSTEM: Writing \"%s\" from file %s[%d]", strValue.c_str(), _strFilePath.c_str(), uiIndex); + _logger.info() << "TESTSUBSYSTEM: Reading '" << strValue << "' to file " + << _strFilePath << "[" << uiIndex << "]"; } } diff --git a/test/test-subsystem/TESTSubsystemObject.h b/test/test-subsystem/TESTSubsystemObject.h index 527e55556..17266fac7 100644 --- a/test/test-subsystem/TESTSubsystemObject.h +++ b/test/test-subsystem/TESTSubsystemObject.h @@ -36,7 +36,10 @@ class CMappingContext; class CTESTSubsystemObject : public CSubsystemObject { public: - CTESTSubsystemObject(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context); + CTESTSubsystemObject(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger); protected: // from CSubsystemObject diff --git a/test/test-subsystem/TESTSubsystemString.cpp b/test/test-subsystem/TESTSubsystemString.cpp index 81ed79393..d31bf5a1a 100644 --- a/test/test-subsystem/TESTSubsystemString.cpp +++ b/test/test-subsystem/TESTSubsystemString.cpp @@ -32,8 +32,11 @@ #define base CTESTSubsystemObject -CTESTSubsystemString::CTESTSubsystemString(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context) - : base(strMappingValue, pInstanceConfigurableElement, context) +CTESTSubsystemString::CTESTSubsystemString(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger) + : base(strMappingValue, pInstanceConfigurableElement, context, logger) { } diff --git a/test/test-subsystem/TESTSubsystemString.h b/test/test-subsystem/TESTSubsystemString.h index cf7edb7f5..5ccf3627b 100644 --- a/test/test-subsystem/TESTSubsystemString.h +++ b/test/test-subsystem/TESTSubsystemString.h @@ -34,7 +34,10 @@ class CTESTSubsystemString : public CTESTSubsystemObject { public: - CTESTSubsystemString(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context); + CTESTSubsystemString(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger); private: // from CTESTSubsystemObject diff --git a/tools/xmlGenerator/domainGenerator.py b/tools/xmlGenerator/domainGenerator.py index 3e840f0d7..1d3aca58d 100755 --- a/tools/xmlGenerator/domainGenerator.py +++ b/tools/xmlGenerator/domainGenerator.py @@ -1,6 +1,6 @@ #! /usr/bin/python # -# Copyright (c) 2011-2014, Intel Corporation +# Copyright (c) 2011-2015, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -113,9 +113,11 @@ def __init__(self): super(PfwLogger, self).__init__() self.__logger = logging.root.getChild("parameter-framework") - def log(self, is_warning, message): - log_func = self.__logger.warning if is_warning else self.__logger.info - log_func(message) + def warning(self, message): + self.__logger.warning(message) + + def info(self, message): + self.__logger.info(message) # If this file is directly executed if __name__ == "__main__": diff --git a/utility/CMakeLists.txt b/utility/CMakeLists.txt index 9f81027e8..9a31dc539 100644 --- a/utility/CMakeLists.txt +++ b/utility/CMakeLists.txt @@ -33,3 +33,7 @@ add_library(pfw_utility STATIC # '-fPIC' needed for linking against shared libraries (e.g. libparameter) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + +install(FILES + Utility.h + DESTINATION "include/utility") diff --git a/utility/Utility.cpp b/utility/Utility.cpp index dc0bce1f4..e5f689a1b 100644 --- a/utility/Utility.cpp +++ b/utility/Utility.cpp @@ -32,6 +32,7 @@ #include #include +#include using std::string; @@ -72,3 +73,15 @@ void CUtility::asString(const std::map& mapStr, CUtility::asString(listKeysValues, strOutput, strItemSeparator); } +void CUtility::appendTitle(string& strTo, const string& strTitle) +{ + strTo += "\n" + strTitle + "\n"; + + uint32_t uiLength = strTitle.size(); + + while (uiLength--) { + + strTo += "="; + } + strTo += "\n"; +} diff --git a/utility/Utility.h b/utility/Utility.h index 51f796f02..93acd8205 100644 --- a/utility/Utility.h +++ b/utility/Utility.h @@ -33,6 +33,7 @@ #include #include #include +#include class CUtility { @@ -62,5 +63,21 @@ class CUtility std::string& strOutput, const std::string& strItemSeparator = ", ", const std::string& strKeyValueSeparator = ":"); -}; + /** Utility to easily convert a builtin type into string + * + * FIXME: Should be replaced by std::to_string after C++11 introduction + */ + template + static std::string toString(T uiValue) + { + std::ostringstream ostr; + + ostr << uiValue; + + return ostr.str(); + } + + /** Utility to underline */ + static void appendTitle(std::string& strTo, const std::string& strTitle); +};