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/ParameterFramework.cpp b/bindings/c/ParameterFramework.cpp index efc7d9922..652ae837e 100644 --- a/bindings/c/ParameterFramework.cpp +++ b/bindings/c/ParameterFramework.cpp @@ -105,15 +105,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; }; @@ -196,9 +205,10 @@ 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 type->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 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/pfw.i b/bindings/python/pfw.i index 9dbccbd8a..f5fd75316 100644 --- a/bindings/python/pfw.i +++ b/bindings/python/pfw.i @@ -182,7 +182,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() {} }; @@ -197,7 +198,7 @@ class ISelectionCriterionTypeInterface %} public: - virtual bool addValuePair(int iValue, const std::string& strValue) = 0; + virtual bool addValuePair(int iValue, const std::string& strValue, std::string& strError) = 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; 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/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..ee009a88f 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, @@ -29,7 +29,6 @@ add_library(parameter SHARED AreaConfiguration.cpp ArrayParameter.cpp - AutoLog.cpp BaseParameter.cpp BinarySerializableElement.cpp BinaryStream.cpp @@ -107,7 +106,8 @@ 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/log/include") # No need to link with libremote-processor: it is accessed via dlopen() find_library(dl dl) @@ -125,7 +125,6 @@ install(FILES DESTINATION "include/parameter/client") # Core (plugin) headers install(FILES - AutoLog.h BitParameterBlockType.h ConfigurableElement.h ConfigurableElementWithMapping.h @@ -138,7 +137,7 @@ install(FILES InstanceConfigurableElement.h Mapper.h MappingContext.h - NamedElementBuilderTemplate.h + LoggingElementBuilderTemplate.h ParameterBlockType.h ParameterType.h PathNavigator.h @@ -151,3 +150,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/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index aa9da51a6..359e010df 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); @@ -847,8 +856,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 +993,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 +1006,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 +1048,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 +1081,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..976d18b77 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 @@ -60,7 +61,20 @@ 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; @@ -78,8 +92,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 +112,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 +186,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..42e83ae6b 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 @@ -510,17 +517,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 +556,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..8e31d2ae8 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,8 @@ #pragma once #include "BinarySerializableElement.h" +#include "Results.h" #include -#include #include @@ -79,7 +79,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,7 +100,22 @@ 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; @@ -99,8 +126,19 @@ class CConfigurableDomains : public CBinarySerializableElement // 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 +161,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..e84cbb0ca 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, @@ -374,7 +374,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 +387,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..7600f3179 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,7 @@ #pragma once #include "BinarySerializableElement.h" +#include "Results.h" #include #include @@ -69,8 +70,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/LoggingElementBuilderTemplate.h b/parameter/LoggingElementBuilderTemplate.h new file mode 100644 index 000000000..653a1e416 --- /dev/null +++ b/parameter/LoggingElementBuilderTemplate.h @@ -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. + */ +#pragma once + +#include "ElementBuilder.h" + +/** + * Builder for elements which need logger at construction + * + * @tparam ElementType the type of the element to build + */ +template +class TLoggingElementBuilderTemplate : public CElementBuilder +{ +public: + + /** + * Class Constructor + * + * @param[in] logger the logger provided by the client + */ + TLoggingElementBuilderTemplate(core::log::Logger& logger) + : CElementBuilder(), mLogger(logger) + { + } + + /** + * 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); + } + +private: + + /** 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..ea5dfabe0 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -30,17 +30,14 @@ #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 +47,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 +62,6 @@ #include "EnumParameterType.h" #include "RemoteProcessorServerInterface.h" #include "ElementLocator.h" -#include "AutoLog.h" #include "CompoundRule.h" #include "SelectionCriterionRule.h" #include "SimulatedBackSynchronizer.h" @@ -93,9 +86,17 @@ #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 +112,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 +308,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 +321,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 +388,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 +415,7 @@ bool CParameterMgr::load(string& strError) return false; } - // Load subsystems - if (!getSystemClass()->loadSubsystems(strError, - _pSubsystemPlugins, !_bFailOnMissingSubsystem)) { + if (!loadSubsystems(strError)) { return false; } @@ -470,40 +432,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"); - - const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria(); + LOG_CONTEXT("Criterion states"); - list lstrSelectionCriteron; - selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false); + list criteria; + mCriteria.listSelectionCriteria(criteria, 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 +471,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 +497,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"); + + // Load subsystems + bool isSuccess = mSystemClass.loadSubsystems(error, + _pSubsystemPlugins, + !_bFailOnMissingSubsystem); - log_info("Loading " + pSystemClass->getName() + " system class structure"); + 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 +550,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 +576,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 +592,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 +621,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 +634,35 @@ 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()); + CXmlDomainImportContext xmlDomainImportContext(strError, + !pBinarySettingsFileLocation, + mSystemClass); // Selection criteria definition for rule creation - xmlDomainImportContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition()); + // FIXME: Avoid const_cast by refactoring criteria subtree + xmlDomainImportContext.setSelectionCriteriaDefinition( + const_cast(mCriteria).getSelectionCriteriaDefinition()); // 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 +673,12 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) bool CParameterMgr::importDomainFromFile(const string& strXmlFilePath, bool bOverwrite, string& strError) { - CXmlDomainImportContext xmlDomainImportContext(strError, true, *getSystemClass()); + CXmlDomainImportContext xmlDomainImportContext(strError, true, mSystemClass); // Selection criteria definition for rule creation + // FIXME: Avoid const_cast by refactoring criteria subtree xmlDomainImportContext.setSelectionCriteriaDefinition( - getConstSelectionCriteria()->getSelectionCriteriaDefinition()); + const_cast(mCriteria).getSelectionCriteriaDefinition()); // Auto validation of configurations xmlDomainImportContext.setAutoValidationRequired(true); @@ -700,8 +693,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 +742,30 @@ 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) { // Propagate - return getSelectionCriteria()->createSelectionCriterionType(bIsInclusive); + return mCriteria.createSelectionCriterionType(bIsInclusive); } CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType) { // Propagate - return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType); + return mCriteria.createSelectionCriterion(strName, pSelectionCriterionType, _logger); } // Selection criterion retrieval CSelectionCriterion* 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 +776,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 +787,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 +888,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 +918,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); @@ -1117,7 +1103,9 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommman if (strOutputFormat == "XML") { // Get Root element where to export from - const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition = getConstSelectionCriteria()->getSelectionCriteriaDefinition(); + // FIXME: Avoid const_cast by refactoring criteria subtree + const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition = + const_cast(mCriteria).getSelectionCriteriaDefinition(); if (!exportElementToXMLString(pSelectionCriteriaDefinition, "SelectionCriteria", strResult)) { @@ -1133,7 +1121,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 +1135,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmand { (void)remoteCommand; - getConfigurableDomains()->listDomains(strResult); + mDomains.listDomains(strResult); return CCommandHandler::ESucceeded; } @@ -1214,7 +1202,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 +1224,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 +1237,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmand CErrorContext errorContext(strError); // Dump - getConstConfigurableDomains()->dumpContent(strResult, errorContext); + mDomains.dumpContent(strResult, errorContext); return CCommandHandler::ESucceeded; } @@ -1276,10 +1266,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 +1297,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 +1330,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 +1346,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommman // List from root folder // Return system class qualified name - pLocatedElement = getSystemClass(); + pLocatedElement = &mSystemClass; } // Return sub-elements @@ -1365,7 +1358,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 +1374,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommm // List from root folder // Return system class qualified name - pLocatedElement = getSystemClass(); + pLocatedElement = &mSystemClass; } // Return sub-elements @@ -1392,7 +1385,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 +1406,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 +1426,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 +1468,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 +1488,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 +1510,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedEleme { (void)remoteCommand; - getConfigurableDomains()->listAssociatedElements(strResult); + mDomains.listAssociatedElements(strResult); return CCommandHandler::ESucceeded; } @@ -1526,7 +1519,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElem { (void)remoteCommand; - getConfigurableDomains()->listConflictingElements(strResult); + mDomains.listConflictingElements(strResult); return CCommandHandler::ESucceeded; } @@ -1535,7 +1528,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCo { (void)remoteCommand; - getSystemClass()->listRogueElements(strResult); + mSystemClass.listRogueElements(strResult); return CCommandHandler::ESucceeded; } @@ -1682,9 +1675,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 +1710,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 +1743,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 +1759,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 +1831,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 +1839,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 +1948,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 +1964,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 +1972,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 +2140,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 +2180,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 +2209,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 +2232,29 @@ 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(), + // FIXME: Avoid const_cast by refactoring criteria subtree + return mDomains.setApplicationRule(strDomain, strConfiguration, strApplicationRule, + const_cast(mCriteria).getSelectionCriteriaDefinition(), 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 +2273,14 @@ bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSetti return false; } - // Root element - CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); // Context - CXmlDomainImportContext xmlDomainImportContext(strError, bWithSettings, *getSystemClass()); + CXmlDomainImportContext xmlDomainImportContext(strError, bWithSettings, mSystemClass); // Selection criteria definition for rule creation + // FIXME: Avoid const_cast by refactoring criteria subtree xmlDomainImportContext.setSelectionCriteriaDefinition( - getConstSelectionCriteria()->getSelectionCriteriaDefinition()); + const_cast(mCriteria).getSelectionCriteriaDefinition()); // Init serializing context xmlDomainImportContext.set( @@ -2214,7 +2289,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 +2298,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 +2400,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 +2407,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 +2446,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 +2461,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 +2509,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 +2552,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 +2560,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 +2593,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 +2612,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 +2656,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..9ee023b86 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,7 +32,6 @@ #include #include #include -#include #include "RemoteCommandHandlerTemplate.h" #include "PathNavigator.h" #include "SelectionCriterionType.h" @@ -40,31 +39,29 @@ #include "Element.h" #include "XmlDocSink.h" #include "XmlDocSource.h" +#include "Results.h" +#include "ParameterFrameworkConfiguration.h" +#include "SelectionCriteria.h" +#include "ConfigurableDomains.h" +#include "SystemClass.h" +#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 +90,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 @@ -253,8 +239,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 +352,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 +495,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 +539,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 +548,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 +614,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 +639,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 */ + CSelectionCriteria mCriteria; + + /** Subsystems handler */ + CSystemClass mSystemClass; + + /** Application domains */ + CConfigurableDomains mDomains; }; diff --git a/parameter/ParameterMgrFullConnector.cpp b/parameter/ParameterMgrFullConnector.cpp index 099147580..bf3214472 100644 --- a/parameter/ParameterMgrFullConnector.cpp +++ b/parameter/ParameterMgrFullConnector.cpp @@ -36,10 +36,10 @@ using std::string; 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 +61,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); } } @@ -267,9 +275,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..2ff577428 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, @@ -37,11 +37,10 @@ using std::string; // 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() @@ -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.cpp b/parameter/Results.h similarity index 73% rename from parameter/AutoLog.cpp rename to parameter/Results.h index ff7151aaf..4d50cb0d5 100644 --- a/parameter/AutoLog.cpp +++ 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, @@ -27,27 +27,15 @@ * (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" +#pragma once -using std::string; +#include +#include -CAutoLog::CAutoLog(const CElement* pElement, const string& strContext, bool bLogOn) - : _pElement(pElement), _strContext(strContext), _bLogOn(bLogOn) +namespace core { - if (_bLogOn) { - // Log - _pElement->doLog(false, _strContext + " {"); - // Nest - _pElement->nestLog(); - } -} -CAutoLog::~CAutoLog() -{ - if (_bLogOn) { - // Unnest - _pElement->unnestLog(); - // Log - _pElement->doLog(false, "} " + _strContext); - } -} + /** String list type which can hold list of error/info */ + typedef std::list Results; + +} /** core namespace */ diff --git a/parameter/SelectionCriteria.cpp b/parameter/SelectionCriteria.cpp index 87ad76e52..5a43fd08c 100644 --- a/parameter/SelectionCriteria.cpp +++ b/parameter/SelectionCriteria.cpp @@ -50,9 +50,12 @@ CSelectionCriterionType* CSelectionCriteria::createSelectionCriterionType(bool b return getSelectionCriterionLibrary()->createSelectionCriterionType(bIsInclusive); } -CSelectionCriterion* CSelectionCriteria::createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType) +CSelectionCriterion* +CSelectionCriteria::createSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger) { - return getSelectionCriteriaDefinition()->createSelectionCriterion(strName, pSelectionCriterionType); + return getSelectionCriteriaDefinition()->createSelectionCriterion(strName, pType, logger); } // Selection criterion retrieval diff --git a/parameter/SelectionCriteria.h b/parameter/SelectionCriteria.h index 122b8a234..e656f376a 100644 --- a/parameter/SelectionCriteria.h +++ b/parameter/SelectionCriteria.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 "Element.h" #include "SelectionCriterionType.h" #include "SelectionCriterion.h" +#include #include @@ -51,7 +52,9 @@ class CSelectionCriteria : public CElement // Selection Criteria/Type creation CSelectionCriterionType* createSelectionCriterionType(bool bIsInclusive); - CSelectionCriterion* createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType); + CSelectionCriterion* createSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger); // Selection criterion retrieval CSelectionCriterion* getSelectionCriterion(const std::string& strName); diff --git a/parameter/SelectionCriteriaDefinition.cpp b/parameter/SelectionCriteriaDefinition.cpp index d7c422894..2eb216bb9 100644 --- a/parameter/SelectionCriteriaDefinition.cpp +++ b/parameter/SelectionCriteriaDefinition.cpp @@ -40,9 +40,12 @@ std::string CSelectionCriteriaDefinition::getKind() const } // Selection Criterion creation -CSelectionCriterion* CSelectionCriteriaDefinition::createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType) +CSelectionCriterion* +CSelectionCriteriaDefinition::createSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger) { - CSelectionCriterion* pSelectionCriterion = new CSelectionCriterion(strName, pSelectionCriterionType); + CSelectionCriterion* pSelectionCriterion = new CSelectionCriterion(strName, pType, logger); addChild(pSelectionCriterion); diff --git a/parameter/SelectionCriteriaDefinition.h b/parameter/SelectionCriteriaDefinition.h index 617b379a8..4bde944fa 100644 --- a/parameter/SelectionCriteriaDefinition.h +++ b/parameter/SelectionCriteriaDefinition.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,7 @@ #include "Element.h" #include "SelectionCriterion.h" +#include class ISelectionCriterionObserver; @@ -40,7 +41,9 @@ class CSelectionCriteriaDefinition : public CElement CSelectionCriteriaDefinition(); // Selection Criterion creation - CSelectionCriterion* createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType); + CSelectionCriterion* createSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger); // Selection Criterion access const CSelectionCriterion* getSelectionCriterion(const std::string& strName) const; diff --git a/parameter/SelectionCriterion.cpp b/parameter/SelectionCriterion.cpp index 781892401..f2dbbe550 100644 --- a/parameter/SelectionCriterion.cpp +++ b/parameter/SelectionCriterion.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,11 +29,18 @@ */ #include "SelectionCriterion.h" -#include "AutoLog.h" +#include +#include +#include "Utility.h" #define base CElement -CSelectionCriterion::CSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pType) : base(strName), _iState(0), _pType(pType), _uiNbModifications(0) +using namespace core; + +CSelectionCriterion::CSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger) + : base(strName), _iState(0), _pType(pType), _uiNbModifications(0), _logger(logger) { } @@ -61,13 +68,16 @@ void CSelectionCriterion::setCriterionState(int iState) _iState = iState; - log_info("Selection criterion changed event: %s", getFormattedDescription(false, false).c_str()); + _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) { - log_warning("Selection criterion \"%s\" has been modified %d time(s) without any configuration application", getName().c_str(), _uiNbModifications); + _logger.warning() << "Selection criterion '" << getName() + << "' has been modified " << _uiNbModifications + << " time(s) without any configuration application"; } // Track the number of modifications for this criterion @@ -125,7 +135,7 @@ std::string CSelectionCriterion::getFormattedDescription(bool bWithTypeInfo, boo if (bWithTypeInfo) { // Display type info - appendTitle(strFormattedDescription, getName() + ":"); + CUtility::appendTitle(strFormattedDescription, getName() + ":"); // States strFormattedDescription += "Possible states "; diff --git a/parameter/SelectionCriterion.h b/parameter/SelectionCriterion.h index cf9903502..e9c2f4950 100644 --- a/parameter/SelectionCriterion.h +++ b/parameter/SelectionCriterion.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,13 +32,16 @@ #include "Element.h" #include "SelectionCriterionType.h" #include "SelectionCriterionInterface.h" +#include #include class CSelectionCriterion : public CElement, public ISelectionCriterionInterface { public: - CSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pType); + CSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger); /// From ISelectionCriterionInterface // State @@ -77,7 +80,11 @@ class CSelectionCriterion : public CElement, public ISelectionCriterionInterface int _iState; // Type const CSelectionCriterionType* _pType; - // Counter to know how many modifications have been applied to this criterion - uint8_t _uiNbModifications; + + /** Counter to know how many modifications have been applied to this criterion */ + uint32_t _uiNbModifications; + + /** Application logger */ + core::log::Logger& _logger; }; diff --git a/parameter/SelectionCriterionType.cpp b/parameter/SelectionCriterionType.cpp index ce633c6f0..ee4d6ae06 100644 --- a/parameter/SelectionCriterionType.cpp +++ b/parameter/SelectionCriterionType.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 "SelectionCriterionType.h" #include "Tokenizer.h" +#include #define base CElement @@ -49,12 +50,17 @@ std::string CSelectionCriterionType::getKind() const } // From ISelectionCriterionTypeInterface -bool CSelectionCriterionType::addValuePair(int iValue, const std::string& strValue) +bool CSelectionCriterionType::addValuePair( + int iValue, const std::string& strValue, std::string& strError) { // 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()); + std::ostringstream error; + error << "Rejecting value pair association: 0x" << std::hex << iValue + << " - " << strValue << " for Selection Criterion Type " + << getName(); + strError = error.str(); return false; } @@ -62,7 +68,11 @@ bool CSelectionCriterionType::addValuePair(int iValue, const std::string& strVal // 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()); + std::ostringstream error; + error << "Rejecting value pair association (literal already present): 0x" + << std::hex << iValue << " - " << strValue + << " for Selection Criterion Type " << getName(); + strError = error.str(); return false; } diff --git a/parameter/SelectionCriterionType.h b/parameter/SelectionCriterionType.h index ef4176a3f..c115eff03 100644 --- a/parameter/SelectionCriterionType.h +++ b/parameter/SelectionCriterionType.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, @@ -42,7 +42,7 @@ class CSelectionCriterionType : public CElement, public ISelectionCriterionTypeI CSelectionCriterionType(bool bIsInclusive); // From ISelectionCriterionTypeInterface - virtual bool addValuePair(int iValue, const std::string& strValue); + virtual bool addValuePair(int iValue, const std::string& strValue, std::string& strError); /** * Retrieve the numerical value from the std::string representation of the criterion type. * 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/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/include/ParameterMgrFullConnector.h b/parameter/include/ParameterMgrFullConnector.h index 31022a6db..a49d4ac86 100644 --- a/parameter/include/ParameterMgrFullConnector.h +++ b/parameter/include/ParameterMgrFullConnector.h @@ -46,13 +46,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() {} }; @@ -182,8 +187,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 +278,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..9885a08f7 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, @@ -44,7 +44,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() {} }; @@ -160,14 +161,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/include/SelectionCriterionTypeInterface.h index 0b62ee46a..168842531 100644 --- a/parameter/include/SelectionCriterionTypeInterface.h +++ b/parameter/include/SelectionCriterionTypeInterface.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,16 @@ class ISelectionCriterionTypeInterface { public: - virtual bool addValuePair(int iValue, const std::string& strValue) = 0; + + /** + * Add a new pair [integer, litteral] which represents a criterion + * + * @param[in] iValue integer value + * @param[in] strValue litteral value + * @param[out] strError string containing error information we can provide to client + * @return true if succeed false otherwise + */ + virtual bool addValuePair(int iValue, const std::string& strValue, std::string& strError) = 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; diff --git a/parameter/log/include/log/Context.h b/parameter/log/include/log/Context.h new file mode 100644 index 000000000..b466ad2d1 --- /dev/null +++ b/parameter/log/include/log/Context.h @@ -0,0 +1,73 @@ +/* + * 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/Logger.h" +#include + +namespace core +{ +namespace log +{ + +/** Log formatter which provide context indentation */ +class Context { +public: + + /** + * 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/AutoLog.h b/parameter/log/include/log/ILogger.h similarity index 80% rename from parameter/AutoLog.h rename to parameter/log/include/log/ILogger.h index 045451420..895f8e9f6 100644 --- a/parameter/AutoLog.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,24 +29,22 @@ */ #pragma once -#include "Element.h" - #include -class CAutoLog +namespace core +{ +namespace log { -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; +/** 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/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/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index 9cb45f7ff..0153514f4 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, @@ -47,16 +47,14 @@ class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnect 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; } }; @@ -311,9 +309,9 @@ bool CTestPlatform::createExclusiveSelectionCriterionFromStateList( const std::string& strValue = remoteCommand.getArgument(uiState + 1); - if (!pCriterionType->addValuePair(uiState, strValue)) { + if (!pCriterionType->addValuePair(uiState, strValue, strResult)) { - strResult = "Unable to add value: " + strValue; + strResult = "Unable to add value: " + strValue + ": " + strResult; return false; } @@ -351,9 +349,10 @@ bool CTestPlatform::createInclusiveSelectionCriterionFromStateList( const std::string& strValue = remoteCommand.getArgument(uiState + 1); - if (!pCriterionType->addValuePair(0x1 << uiState, strValue)) { + if (!pCriterionType->addValuePair( + 0x1 << uiState, strValue, strResult)) { - strResult = "Unable to add value: " + strValue; + strResult = "Unable to add value: " + strValue + ": " + strResult; return false; } @@ -381,9 +380,11 @@ bool CTestPlatform::createExclusiveSelectionCriterion(const string& strName, ostrValue << "State_"; ostrValue << uistate; - if (!pCriterionType->addValuePair(uistate, ostrValue.str())) { + if (!pCriterionType->addValuePair( + uistate, ostrValue.str(), strResult)) { - strResult = "Unable to add value: " + ostrValue.str(); + strResult = "Unable to add value: " + + ostrValue.str() + ": " + strResult; return false; } @@ -417,9 +418,11 @@ bool CTestPlatform::createInclusiveSelectionCriterion(const string& strName, ostrValue << "State_0x"; ostrValue << (0x1 << uiState); - if (!pCriterionType->addValuePair(0x1 << uiState, ostrValue.str())) { + if (!pCriterionType->addValuePair( + 0x1 << uiState, ostrValue.str(), strResult)) { - strResult = "Unable to add value: " + ostrValue.str(); + strResult = "Unable to add value: " + + ostrValue.str() + ": " + strResult; return false; } 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); +};