From df01d8bae7dc2d951d8d7ed526e2d4a86d3c4d74 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 26 Feb 2015 15:57:00 +0100 Subject: [PATCH 01/19] Remove unused AutoLog header from SelectionCriterion class Signed-off-by: Jules Clero --- parameter/SelectionCriterion.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/parameter/SelectionCriterion.cpp b/parameter/SelectionCriterion.cpp index 781892401..975503b90 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,7 +29,6 @@ */ #include "SelectionCriterion.h" -#include "AutoLog.h" #define base CElement From f2dd7678476ca143250cf0bcb8c21cc2d8123c89 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 2 Mar 2015 21:53:28 +0000 Subject: [PATCH 02/19] Move logging up to ParameterMgr Some elements are logging but ParameterMgr is able to do the same. This patch lets the ParameterMgr handle logging whenever it's possible. Signed-off-by: Jules Clero --- parameter/ConfigurableDomain.cpp | 78 +++++++++------ parameter/ConfigurableDomain.h | 62 +++++++++--- parameter/ConfigurableDomains.cpp | 62 ++++++------ parameter/ConfigurableDomains.h | 44 +++++++-- parameter/ParameterMgr.cpp | 158 +++++++++++++++++++++++++----- parameter/ParameterMgr.h | 17 +++- parameter/SystemClass.cpp | 24 ++--- parameter/SystemClass.h | 5 +- 8 files changed, 328 insertions(+), 122 deletions(-) diff --git a/parameter/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index aa9da51a6..68239e64a 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)) { + std::list 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, + std::list& 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, + std::list& 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,7 +689,6 @@ 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); @@ -697,7 +705,6 @@ bool CConfigurableDomain::restoreConfiguration(const string& strName, CParameter lstrError.push_back(strError); 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); @@ -722,7 +729,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 +853,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 +990,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, + std::list& infos) { std::list mergedConfigurableElementList; @@ -997,12 +1003,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 +1045,9 @@ void CConfigurableDomain::mergeConfigurations(CConfigurableElement* pToConfigura } // Configurable elements association -void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard *pMainBlackboard) +void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfigurableElement, + std::list& infos, + const CParameterBlackboard* pMainBlackboard) { // Inform configurable element pConfigurableElement->addAttachedConfigurableDomain(this); @@ -1067,12 +1078,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..6b3a7df8b 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, @@ -78,8 +78,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 string list containing useful information we can provide to client + * @return true if succeed false otherwise + */ + bool addConfigurableElement(CConfigurableElement* pConfigurableElement, + const CParameterBlackboard* pMainBlackboard, + std::list& infos); + bool removeConfigurableElement(CConfigurableElement* pConfigurableElement, std::string& strError); // Blackboard Configuration and Base Offset retrieval @@ -89,14 +98,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 string list containing useful information we can provide to client + * @return true if succeed false otherwise + */ + bool split(CConfigurableElement* pConfigurableElement, std::list& strError); // 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 +172,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 string list containing useful information we can provide to client + */ + void mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* newElement, + std::list& 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, + std::list& 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..fba332990 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, + std::list& 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, + std::list& 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; } @@ -510,17 +513,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, + std::list& 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 +552,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..11ccfa815 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, @@ -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 string list containing useful information we can provide to client + * @return true if succeed false otherwise + */ + bool split(const std::string& domainName, + CConfigurableElement* element, + std::list& infos); + void listAssociatedElements(std::string& strResult) const; void listConflictingElements(std::string& strResult) const; void listDomains(std::string& strResult) const; @@ -99,8 +111,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 string list containing useful information we can provide to client + * @return true if succeed false otherwise + */ + bool addConfigurableElementToDomain(const std::string& domainName, + CConfigurableElement* element, + const CParameterBlackboard* mainBlackboard, + std::list& infos); + bool removeConfigurableElementFromDomain(const std::string& strDomain, CConfigurableElement* pConfigurableElement, std::string& strError); // Configuration Blackboard for element @@ -123,8 +146,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 string list containing useful information we can provide to client + */ + void apply(CParameterBlackboard* pParameterBlackboard, + CSyncerSet& syncerSet, + bool bForce, + std::list& infos) const; // Class kind virtual std::string getKind() const; diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 45f1ac2d4..c612b8e8d 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -451,9 +451,7 @@ bool CParameterMgr::load(string& strError) return false; } - // Load subsystems - if (!getSystemClass()->loadSubsystems(strError, - _pSubsystemPlugins, !_bFailOnMissingSubsystem)) { + if (!loadSubsystems(strError)) { return false; } @@ -543,6 +541,28 @@ bool CParameterMgr::loadFrameworkConfiguration(string& strError) return true; } +bool CParameterMgr::loadSubsystems(std::string& error) +{ + CAutoLog autoLog(this, "Loading subsystem plugins"); + + // Load subsystems + bool isSuccess = getSystemClass()->loadSubsystems(error, + _pSubsystemPlugins, + !_bFailOnMissingSubsystem); + + if (isSuccess) { + log_info("All subsystem plugins successfully loaded"); + + if(!error.empty()) { + // Log missing subsystems as info + log_info(error); + } + } else { + log_warning(error); + } + return isSuccess; +} + bool CParameterMgr::loadStructure(string& strError) { // Retrieve system to load structure to @@ -700,8 +720,10 @@ bool CParameterMgr::importDomainFromFile(const string& strXmlFilePath, bool bOve return false; } - bSuccess = getConfigurableDomains()->addDomain(*standaloneDomain, bOverwrite, strError); - if (!bSuccess) { + CAutoLog autoLog(this, "Adding configurable domain '" + standaloneDomain->getName() + "'"); + + if (!logResult(getConfigurableDomains()->addDomain( + *standaloneDomain, bOverwrite, strError), strError)) { return false; } @@ -1768,11 +1790,26 @@ bool CParameterMgr::accessConfigurationValue(const string& strDomain, const stri uint32_t uiBaseOffset; bool bIsLastApplied; - CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError); - - if (!pConfigurationBlackboard) { + CParameterBlackboard* pConfigurationBlackboard = NULL; - return false; + { + CAutoLog autolog(this, + "Find configuration blackboard for Domain: " + strDomain + + ", Configuration: " + strConfiguration + + ", Element: " + pConfigurableElement->getPath()); + + pConfigurationBlackboard = + getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, + strConfiguration, + pConfigurableElement, + uiBaseOffset, + bIsLastApplied, + strError); + if (!pConfigurationBlackboard) { + + log_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); @@ -1959,6 +1996,7 @@ bool CParameterMgr::sync(string& strError) // Configuration/Domains handling bool CParameterMgr::createDomain(const string& strName, string& strError) { + CAutoLog autoLog(this, "Creating configurable domain " + strName); // Check tuning mode if (!checkTuningModeOn(strError)) { @@ -1966,50 +2004,63 @@ bool CParameterMgr::createDomain(const string& strName, string& strError) } // Delegate to configurable domains - return getConfigurableDomains()->createDomain(strName, strError); + return logResult(getConfigurableDomains()->createDomain(strName, strError), strError); } bool CParameterMgr::deleteDomain(const string& strName, string& strError) { + CAutoLog autoLog(this, "Deleting configurable domain '" + strName + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail:" + strError); return false; } // Delegate to configurable domains - return getConfigurableDomains()->deleteDomain(strName, strError); + return logResult(getConfigurableDomains()->deleteDomain(strName, strError), strError); } bool CParameterMgr::renameDomain(const string& strName, const string& strNewName, string& strError) { + CAutoLog autoLog(this, "Renaming configurable domain '" + strName + + "' to '" + strNewName + "'"); + // Delegate to configurable domains - return getConfigurableDomains()->renameDomain(strName, strNewName, strError); + return logResult(getConfigurableDomains()->renameDomain( + strName, strNewName, strError), strError); } bool CParameterMgr::deleteAllDomains(string& strError) { + CAutoLog autoLog(this, "Deleting all configurable domains"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } // Delegate to configurable domains getConfigurableDomains()->deleteAllDomains(); + log_info("Success"); return true; } bool CParameterMgr::setSequenceAwareness(const string& strName, bool bSequenceAware, string& strResult) { + CAutoLog autoLog(this, "Making domain '" + strName + + "' sequence " + (bSequenceAware ? "aware" : "unaware")); // Check tuning mode if (!checkTuningModeOn(strResult)) { + log_warning("Fail: " + strResult); return false; } - return getConfigurableDomains()->setSequenceAwareness(strName, bSequenceAware, strResult); + return logResult(getConfigurableDomains()->setSequenceAwareness( + strName, bSequenceAware, strResult), strResult); } bool CParameterMgr::getSequenceAwareness(const string& strName, bool& bSequenceAware, @@ -2020,66 +2071,90 @@ bool CParameterMgr::getSequenceAwareness(const string& strName, bool& bSequenceA bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { + CAutoLog autoLog(this, "Creating domain configuration '" + strConfiguration + + "' into domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } // Delegate to configurable domains - return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError); + return logResult(getConfigurableDomains()->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); + CAutoLog autoLog(this, "Renaming domain '" + strDomain + + "''s configuration '" + strConfiguration + "' to '" + strNewConfiguration + "'"); + + return logResult(getConfigurableDomains()->renameConfiguration( + strDomain, strConfiguration, strNewConfiguration, strError), strError); } bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { + CAutoLog autoLog(this, "Deleting configuration '" + strConfiguration + + "' from domain '" + strDomain + "'"); + // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } // Delegate to configurable domains - return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError); + return logResult(getConfigurableDomains()->deleteConfiguration( + strDomain, strConfiguration, strError), strError); } bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list& lstrError) { string strError; + CAutoLog autoLog(this, "Restoring domain '" + strDomain + + "''s configuration '" + strConfiguration + "' to parameter blackboard"); // Check tuning mode if (!checkTuningModeOn(strError)) { lstrError.push_back(strError); + log_warning("Fail: " + strError); return false; } // Delegate to configurable domains - return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError); + return logResult(getConstConfigurableDomains()->restoreConfiguration( + strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError), + strError); } bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { + CAutoLog autoLog(this, "Saving domain '" + strDomain + + "''s configuration '" + strConfiguration + "' from parameter blackboard"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } // Delegate to configurable domains - return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError); + return logResult(getConfigurableDomains()->saveConfiguration( + strDomain, strConfiguration, _pMainParameterBlackboard, strError), strError); } // Configurable element - domain association bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) { + CAutoLog autoLog(this, "Adding configurable element '" + strConfigurableElementPath + + "to domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } @@ -2089,6 +2164,7 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { + log_warning("Fail: " + strError); return false; } @@ -2096,14 +2172,24 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError); + std::list infos; + bool isSuccess = getConfigurableDomains()->addConfigurableElementToDomain( + strDomain, pConfigurableElement, _pMainParameterBlackboard, infos); + + log_table(!isSuccess, infos); + + CUtility::asString(infos, strError); + return isSuccess; } bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) { + CAutoLog autoLog(this, "Removing configurable element '" + strConfigurableElementPath + + "' from domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } @@ -2113,6 +2199,7 @@ bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { + log_warning("Fail: " + strError); return false; } @@ -2120,14 +2207,18 @@ bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError); + return logResult(getConfigurableDomains()->removeConfigurableElementFromDomain( + strDomain, pConfigurableElement, strError), strError); } bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError) { + CAutoLog autoLog(this, "Splitting configurable element '" + strConfigurableElementPath + + "' domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } @@ -2137,6 +2228,7 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { + log_warning("Fail: " + strError); return false; } @@ -2144,7 +2236,12 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError); + std::list infos; + bool isSuccess = getConfigurableDomains()->split(strDomain, pConfigurableElement, infos); + + log_table(isSuccess, infos); + CUtility::asString(infos, strError); + return isSuccess; } bool CParameterMgr::setElementSequence(const string& strDomain, const string& strConfiguration, @@ -2595,13 +2692,17 @@ const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const // Apply configurations void CParameterMgr::doApplyConfigurations(bool bForce) { + CAutoLog autoLog(this, "Applying configurations"); + CSyncerSet syncerSet; + std::list infos; // Check subsystems that need resync - getSystemClass()->checkForSubsystemsToResync(syncerSet); + getSystemClass()->checkForSubsystemsToResync(syncerSet, infos); // Ensure application of currently selected configurations - getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce); + getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce, infos); + log_table(false, infos); // Reset the modified status of the current criteria to indicate that a new configuration has been applied getSelectionCriteria()->resetModifiedStatus(); @@ -2632,3 +2733,12 @@ bool CParameterMgr::exportElementToXMLString(const IXmlSource* pXmlSource, return bProcessSuccess; } + +bool CParameterMgr::logResult(bool isSuccess, const std::string& result) +{ + std::string log(isSuccess ? "Success" : "Fail" ); + log += (result.empty() ? "" : ": " + result); + (this->*(isSuccess ? &CParameterMgr::log_info : &CParameterMgr::log_warning))(log); + + return isSuccess; +} diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index ef834eb7a..491fcbd31 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, @@ -508,6 +508,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); @@ -572,6 +579,14 @@ 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); + // Tuning bool _bTuningModeIsOn; diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp index ae4f74733..d0788fa6c 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,7 +33,6 @@ #include #include "SystemClass.h" #include "SubsystemLibrary.h" -#include "AutoLog.h" #include "VirtualSubsystem.h" #include "NamedElementBuilderTemplate.h" #include @@ -98,8 +97,6 @@ bool CSystemClass::loadSubsystems(string& strError, const CSubsystemPlugins* pSubsystemPlugins, bool bVirtualSubsystemFallback) { - CAutoLog autoLog_info(this, "Loading subsystem plugins"); - // Start clean _pSubsystemLibrary->clean(); @@ -113,18 +110,9 @@ bool CSystemClass::loadSubsystems(string& strError, 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); - } - - 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(lstrError, strError); return bLoadPluginsSuccess || bVirtualSubsystemFallback; } @@ -277,7 +265,7 @@ const CSubsystemLibrary* CSystemClass::getSubsystemLibrary() const return _pSubsystemLibrary; } -void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet) +void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet, std::list& infos) { size_t uiNbChildren = getNbChildren(); size_t uiChild; @@ -289,7 +277,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); } diff --git a/parameter/SystemClass.h b/parameter/SystemClass.h index dd215a6f7..bebc1a1e8 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, @@ -63,8 +63,9 @@ 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, std::list& infos); /** * Reset subsystems need to resync flag. From 249f3286f6c7b00348a6591128d84cac8621fb67 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 10 Mar 2015 17:15:59 +0100 Subject: [PATCH 03/19] Introduce Results type to avoid copy paste String lists are often used as containers for function results. To avoid copy paste, this patch introduces the Results type to replace std::list when relevant. Documentation has been updated on modified prototype. Signed-off-by: Jules Clero --- parameter/AreaConfiguration.cpp | 8 ++-- parameter/AreaConfiguration.h | 13 ++++-- parameter/ConfigurableDomain.cpp | 31 +++++++------- parameter/ConfigurableDomain.h | 30 ++++++++++---- parameter/ConfigurableDomains.cpp | 22 ++++++---- parameter/ConfigurableDomains.h | 31 ++++++++++---- parameter/DomainConfiguration.cpp | 8 ++-- parameter/DomainConfiguration.h | 17 ++++++-- parameter/ParameterMgr.cpp | 26 ++++++------ parameter/ParameterMgr.h | 15 +++++-- parameter/ParameterMgrFullConnector.cpp | 4 +- parameter/Results.h | 41 +++++++++++++++++++ parameter/SyncerSet.cpp | 10 +++-- parameter/SyncerSet.h | 15 ++++--- parameter/SystemClass.cpp | 24 +++++------ parameter/SystemClass.h | 11 ++--- parameter/include/ParameterMgrFullConnector.h | 17 +++++++- 17 files changed, 227 insertions(+), 96 deletions(-) create mode 100644 parameter/Results.h 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/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index 68239e64a..359e010df 100644 --- a/parameter/ConfigurableDomain.cpp +++ b/parameter/ConfigurableDomain.cpp @@ -296,7 +296,7 @@ bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElemen return false; } // Add found element to domain - std::list infos; + core::Results infos; if (!addConfigurableElement(pConfigurableElement, NULL, infos)) { CUtility::asString(infos, strError); @@ -357,7 +357,7 @@ bool CConfigurableDomain::parseSettings(const CXmlElement& xmlElement, // Configurable elements association bool CConfigurableDomain::addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, - std::list& infos) + core::Results& infos) { // Already associated? if (containsConfigurableElement(pConfigurableElement)) { @@ -461,7 +461,7 @@ CParameterBlackboard* CConfigurableDomain::findConfigurationBlackboard(const str // Domain splitting bool CConfigurableDomain::split(CConfigurableElement* pConfigurableElement, - std::list& infos) + core::Results& infos) { // Not associated? if (!containsConfigurableElement(pConfigurableElement)) { @@ -694,28 +694,31 @@ bool CConfigurableDomain::renameConfiguration(const string& strName, const strin 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; } // 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; } @@ -992,7 +995,7 @@ bool CConfigurableDomain::containsConfigurableElement(const CConfigurableElement // Merge any descended configurable element to this one with this one void CConfigurableDomain::mergeAlreadyAssociatedDescendantConfigurableElements( CConfigurableElement* newElement, - std::list& infos) + core::Results& infos) { std::list mergedConfigurableElementList; @@ -1046,7 +1049,7 @@ void CConfigurableDomain::mergeConfigurations(CConfigurableElement* pToConfigura // Configurable elements association void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfigurableElement, - std::list& infos, + core::Results& infos, const CParameterBlackboard* pMainBlackboard) { // Inform configurable element diff --git a/parameter/ConfigurableDomain.h b/parameter/ConfigurableDomain.h index 6b3a7df8b..976d18b77 100644 --- a/parameter/ConfigurableDomain.h +++ b/parameter/ConfigurableDomain.h @@ -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; @@ -82,12 +96,12 @@ class CConfigurableDomain : public CBinarySerializableElement * * @param[in] pConfigurableElement pointer to the element to add * @param[in] pMainBlackboard pointer to the application main blackboard - * @param[out] infos string list containing useful information we can provide to client + * @param[out] infos useful information we can provide to client * @return true if succeed false otherwise */ bool addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, - std::list& infos); + core::Results& infos); bool removeConfigurableElement(CConfigurableElement* pConfigurableElement, std::string& strError); @@ -102,10 +116,10 @@ class CConfigurableDomain : public CBinarySerializableElement * 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 string list containing useful information we can provide to client + * @param[out] infos useful information we can provide to client * @return true if succeed false otherwise */ - bool split(CConfigurableElement* pConfigurableElement, std::list& strError); + bool split(CConfigurableElement* pConfigurableElement, core::Results& infos); // Ensure validity on whole domain from main blackboard void validate(const CParameterBlackboard* pMainBlackboard); @@ -175,10 +189,10 @@ class CConfigurableDomain : public CBinarySerializableElement /** 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 string list containing useful information we can provide to client + * @param[out] infos useful information we can provide to client */ void mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* newElement, - std::list& infos); + core::Results& infos); void mergeConfigurations(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement); @@ -191,7 +205,7 @@ class CConfigurableDomain : public CBinarySerializableElement * element are validated. */ void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, - std::list& infos, + core::Results& infos, const CParameterBlackboard* pMainBlackboard = NULL); void doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet); diff --git a/parameter/ConfigurableDomains.cpp b/parameter/ConfigurableDomains.cpp index fba332990..42e83ae6b 100644 --- a/parameter/ConfigurableDomains.cpp +++ b/parameter/ConfigurableDomains.cpp @@ -70,7 +70,7 @@ void CConfigurableDomains::validate(const CParameterBlackboard* pMainBlackboard) void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet& syncerSet, bool bForce, - std::list& infos) const + core::Results& infos) const { /// Delegate to domains @@ -294,7 +294,7 @@ bool CConfigurableDomains::listDomainElements(const string& strDomain, string& s bool CConfigurableDomains::split(const string& domainName, CConfigurableElement* element, - std::list& infos) + core::Results& infos) { // Find domain std::string error; @@ -402,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 @@ -517,7 +521,7 @@ bool CConfigurableDomains::addConfigurableElementToDomain(const string& domainName, CConfigurableElement* element, const CParameterBlackboard* mainBlackboard, - std::list& infos) + core::Results& infos) { // Find domain std::string error; diff --git a/parameter/ConfigurableDomains.h b/parameter/ConfigurableDomains.h index 11ccfa815..8e31d2ae8 100644 --- a/parameter/ConfigurableDomains.h +++ b/parameter/ConfigurableDomains.h @@ -30,8 +30,8 @@ #pragma once #include "BinarySerializableElement.h" +#include "Results.h" #include -#include #include @@ -85,12 +85,12 @@ class CConfigurableDomains : public CBinarySerializableElement * * @param[in] domainName the domain name * @param[in] element pointer to the element to remove - * @param[out] infos string list containing useful information we can provide to client + * @param[out] infos useful information we can provide to client * @return true if succeed false otherwise */ bool split(const std::string& domainName, CConfigurableElement* element, - std::list& infos); + core::Results& infos); void listAssociatedElements(std::string& strResult) const; void listConflictingElements(std::string& strResult) const; @@ -100,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; @@ -116,13 +131,13 @@ class CConfigurableDomains : public CBinarySerializableElement * @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 string list containing useful information we can provide to client + * @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, - std::list& infos); + core::Results& infos); bool removeConfigurableElementFromDomain(const std::string& strDomain, CConfigurableElement* pConfigurableElement, std::string& strError); @@ -151,12 +166,12 @@ class CConfigurableDomains : public CBinarySerializableElement * @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 string list containing useful information we can provide to client + * @param[out] infos useful information we can provide to client */ void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet& syncerSet, bool bForce, - std::list& infos) const; + core::Results& infos) const; // Class kind virtual std::string getKind() const; 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/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index c612b8e8d..2138f78c8 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -1298,10 +1298,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; } @@ -1983,10 +1983,10 @@ bool CParameterMgr::sync(string& strError) getConstSystemClass()->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; }; @@ -2111,7 +2111,9 @@ bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& s 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; CAutoLog autoLog(this, "Restoring domain '" + strDomain @@ -2119,14 +2121,14 @@ bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& // Check tuning mode if (!checkTuningModeOn(strError)) { - lstrError.push_back(strError); + errors.push_back(strError); log_warning("Fail: " + strError); return false; } // Delegate to configurable domains return logResult(getConstConfigurableDomains()->restoreConfiguration( - strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError), + strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, errors), strError); } @@ -2172,7 +2174,7 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - std::list infos; + core::Results infos; bool isSuccess = getConfigurableDomains()->addConfigurableElementToDomain( strDomain, pConfigurableElement, _pMainParameterBlackboard, infos); @@ -2236,7 +2238,7 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - std::list infos; + core::Results infos; bool isSuccess = getConfigurableDomains()->split(strDomain, pConfigurableElement, infos); log_table(isSuccess, infos); @@ -2696,7 +2698,7 @@ void CParameterMgr::doApplyConfigurations(bool bForce) CSyncerSet syncerSet; - std::list infos; + core::Results infos; // Check subsystems that need resync getSystemClass()->checkForSubsystemsToResync(syncerSet, infos); diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index 491fcbd31..5ced38131 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -32,7 +32,6 @@ #include #include #include -#include #include "RemoteCommandHandlerTemplate.h" #include "PathNavigator.h" #include "SelectionCriterionType.h" @@ -40,6 +39,7 @@ #include "Element.h" #include "XmlDocSink.h" #include "XmlDocSource.h" +#include "Results.h" #include @@ -253,8 +253,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 diff --git a/parameter/ParameterMgrFullConnector.cpp b/parameter/ParameterMgrFullConnector.cpp index 099147580..7ab3f9188 100644 --- a/parameter/ParameterMgrFullConnector.cpp +++ b/parameter/ParameterMgrFullConnector.cpp @@ -267,9 +267,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/Results.h b/parameter/Results.h new file mode 100644 index 000000000..4d50cb0d5 --- /dev/null +++ b/parameter/Results.h @@ -0,0 +1,41 @@ +/* + * 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 +#include + +namespace core +{ + + /** String list type which can hold list of error/info */ + typedef std::list Results; + +} /** core namespace */ 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 d0788fa6c..b756a9e11 100644 --- a/parameter/SystemClass.cpp +++ b/parameter/SystemClass.cpp @@ -107,17 +107,17 @@ bool CSystemClass::loadSubsystems(string& strError, _pSubsystemLibrary->enableDefaultMechanism(bVirtualSubsystemFallback); // Add subsystem defined in shared libraries - list lstrError; - bool bLoadPluginsSuccess = loadSubsystemsFromSharedLibraries(lstrError, pSubsystemPlugins); + core::Results errors; + bool bLoadPluginsSuccess = loadSubsystemsFromSharedLibraries(errors, pSubsystemPlugins); // Fill strError for caller, he has to decide if there is a problem depending on // bVirtualSubsystemFallback value - CUtility::asString(lstrError, strError); + CUtility::asString(errors, strError); return bLoadPluginsSuccess || bVirtualSubsystemFallback; } -bool CSystemClass::loadSubsystemsFromSharedLibraries(list& lstrError, +bool CSystemClass::loadSubsystemsFromSharedLibraries(core::Results& errors, const CSubsystemPlugins* pSubsystemPlugins) { // Plugin list @@ -155,7 +155,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; @@ -167,7 +167,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; } @@ -198,7 +198,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()); @@ -220,9 +220,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; @@ -241,8 +241,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; } @@ -265,7 +265,7 @@ const CSubsystemLibrary* CSystemClass::getSubsystemLibrary() const return _pSubsystemLibrary; } -void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet, std::list& infos) +void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet, core::Results& infos) { size_t uiNbChildren = getNbChildren(); size_t uiChild; diff --git a/parameter/SystemClass.h b/parameter/SystemClass.h index bebc1a1e8..886ed32c6 100644 --- a/parameter/SystemClass.h +++ b/parameter/SystemClass.h @@ -31,6 +31,7 @@ #include "ConfigurableElement.h" #include "SubsystemPlugins.h" +#include "Results.h" #include #include @@ -65,7 +66,7 @@ class CSystemClass : public CConfigurableElement * @param[out] syncerSet The syncer set to fill * @param[out] infos Relevant informations client may want to log */ - void checkForSubsystemsToResync(CSyncerSet& syncerSet, std::list& infos); + void checkForSubsystemsToResync(CSyncerSet& syncerSet, core::Results& infos); /** * Reset subsystems need to resync flag. @@ -83,12 +84,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 @@ -98,13 +99,13 @@ 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; diff --git a/parameter/include/ParameterMgrFullConnector.h b/parameter/include/ParameterMgrFullConnector.h index 31022a6db..cbed5777c 100644 --- a/parameter/include/ParameterMgrFullConnector.h +++ b/parameter/include/ParameterMgrFullConnector.h @@ -46,6 +46,10 @@ 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(); @@ -182,8 +186,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 From c58e51613663e7e73b97d0154b80d77d04511c00 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 11:50:40 +0100 Subject: [PATCH 04/19] Remove plugin load attempt log This log is meaningless, as we know subsystems we are attempting to load. We log only if there is an error. Signed-off-by: Jules Clero --- parameter/SystemClass.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp index b756a9e11..7e0c31cf1 100644 --- a/parameter/SystemClass.cpp +++ b/parameter/SystemClass.cpp @@ -210,8 +210,6 @@ bool CSystemClass::loadPlugins(list& lstrPluginFiles, core::Results& err 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); From 2f66b4fdc5e562642845b35b4d85a90373106df8 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 12:08:55 +0100 Subject: [PATCH 05/19] Remove unused XmlFileIncluderElement header from ParameterMgr Signed-off-by: Jules Clero --- parameter/ParameterMgr.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 2138f78c8..2e12a96cb 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -36,7 +36,6 @@ #include "NamedElementBuilderTemplate.h" #include "KindElementBuilderTemplate.h" #include "ElementBuilderTemplate.h" -#include "XmlFileIncluderElement.h" #include "SelectionCriterionType.h" #include "SubsystemElementBuilder.h" #include "FileIncluderElementBuilder.h" @@ -50,7 +49,6 @@ #include "ParameterBlackboard.h" #include "Parameter.h" #include "ParameterAccessContext.h" -#include "XmlFileIncluderElement.h" #include "ParameterFrameworkConfiguration.h" #include "FrameworkConfigurationGroup.h" #include "PluginLocation.h" From 00a4af2b1883163842179941eabe352a88518d31 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 13:22:37 +0100 Subject: [PATCH 06/19] Remove log from XmlFileIncluderElement This log information is easy to retrieve by looking the structure file. Signed-off-by: Jules Clero --- parameter/XmlFileIncluderElement.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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"; From f9ff872855787b42775485902f0eab0e9e1ca984 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 13:58:32 +0100 Subject: [PATCH 07/19] Delegate addValuePair error logging to client The client may choose if he wants to log the error when adding a criterion. Signed-off-by: Jules Clero --- bindings/c/ParameterFramework.cpp | 5 ++-- bindings/python/pfw.i | 2 +- parameter/SelectionCriterionType.cpp | 18 +++++++++++---- parameter/SelectionCriterionType.h | 4 ++-- .../include/SelectionCriterionTypeInterface.h | 13 +++++++++-- test/test-platform/TestPlatform.cpp | 23 +++++++++++-------- 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/bindings/c/ParameterFramework.cpp b/bindings/c/ParameterFramework.cpp index efc7d9922..dcca5cc00 100644 --- a/bindings/c/ParameterFramework.cpp +++ b/bindings/c/ParameterFramework.cpp @@ -196,9 +196,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/python/pfw.i b/bindings/python/pfw.i index 9dbccbd8a..affae6b92 100644 --- a/bindings/python/pfw.i +++ b/bindings/python/pfw.i @@ -197,7 +197,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/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/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/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index 9cb45f7ff..028dfd396 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, @@ -311,9 +311,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 +351,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 +382,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 +420,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; } From 36b3b1df81390871c0292e4b6334683b68b43e5a Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 26 Feb 2015 16:53:45 +0100 Subject: [PATCH 08/19] Temporarily remove Subsystems logging ability In prevision of logging rework, this patch removes logging from plugins. Signed-off-by: Jules Clero --- parameter/SubsystemObject.cpp | 44 +-------------------- parameter/SubsystemObject.h | 5 +-- test/test-subsystem/TESTSubsystemObject.cpp | 22 ----------- 3 files changed, 2 insertions(+), 69 deletions(-) diff --git a/parameter/SubsystemObject.cpp b/parameter/SubsystemObject.cpp index 76b954907..592ec5628 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, @@ -146,11 +146,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 +207,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..e4ccd19b4 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, @@ -82,9 +82,6 @@ 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; diff --git a/test/test-subsystem/TESTSubsystemObject.cpp b/test/test-subsystem/TESTSubsystemObject.cpp index 706053fed..d17be0bfb 100644 --- a/test/test-subsystem/TESTSubsystemObject.cpp +++ b/test/test-subsystem/TESTSubsystemObject.cpp @@ -105,17 +105,6 @@ void CTESTSubsystemObject::sendToFile(std::ofstream& outputFile) std::string strValue = toString(pvValue, _uiScalarSize); outputFile << strValue << std::endl; - - if (_bLog) { - - if (_bIsScalar) { - - log_info("TESTSUBSYSTEM: Writing \"%s\" to file %s", strValue.c_str(), _strFilePath.c_str()); - } else { - - log_info("TESTSUBSYSTEM: Writing \"%s\" to file %s[%d]", strValue.c_str(), _strFilePath.c_str(), uiIndex); - } - } } } @@ -131,17 +120,6 @@ void CTESTSubsystemObject::receiveFromFile(std::ifstream& inputFile) inputFile >> strValue; - if (_bLog) { - - if (_bIsScalar) { - - log_info("TESTSUBSYSTEM: Writing \"%s\" from file %s", strValue.c_str(), _strFilePath.c_str()); - } else { - - log_info("TESTSUBSYSTEM: Writing \"%s\" from file %s[%d]", strValue.c_str(), _strFilePath.c_str(), uiIndex); - } - } - fromString(strValue, pvValue, _uiScalarSize); // Write Value in Blackboard From 5f56c58df21a1d2af503bdd4679b7a2bab4f7f0a Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 13 Apr 2015 11:20:25 +0200 Subject: [PATCH 09/19] Change Criterion modifications counter type uint8_t type seems to be buggy when we try to log it through stream API. This patch uses uint32_t type instead to count criterion modifications. Signed-off-by: Jules Clero --- parameter/SelectionCriterion.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/parameter/SelectionCriterion.h b/parameter/SelectionCriterion.h index cf9903502..86c96836b 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, @@ -77,7 +77,8 @@ 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; }; From 1554cfef2e4e62e9efc76f6eae180b2239a173ca Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Wed, 25 Feb 2015 14:12:20 +0100 Subject: [PATCH 10/19] Rework project log Logs were provided by Element god class. This patch moves logging in the log library which is used by the ParameterMgr. Logs remains almost identical from before. Context title after context closing bracket has been removed to enhance readability. Change-Id: Ic7dca65c3cc88eb06a1883c4fb01af9809b19e42 Signed-off-by: Jules Clero --- bindings/c/ParameterFramework.cpp | 17 +- bindings/c/Test.cpp | 11 + bindings/python/pfw.i | 3 +- parameter/Android.mk | 9 +- parameter/CMakeLists.txt | 9 +- parameter/Element.cpp | 87 +------ parameter/Element.h | 15 +- parameter/ParameterMgr.cpp | 244 +++++++++--------- parameter/ParameterMgr.h | 32 +-- parameter/ParameterMgrFullConnector.cpp | 18 +- parameter/ParameterMgrLogger.h | 15 +- parameter/ParameterMgrPlatformConnector.cpp | 21 +- parameter/SelectionCriteria.cpp | 7 +- parameter/SelectionCriteria.h | 7 +- parameter/SelectionCriteriaDefinition.cpp | 7 +- parameter/SelectionCriteriaDefinition.h | 7 +- parameter/SelectionCriterion.cpp | 15 +- parameter/SelectionCriterion.h | 8 +- parameter/include/ParameterMgrFullConnector.h | 11 +- .../include/ParameterMgrPlatformConnector.h | 12 +- .../include/log/Context.h} | 58 +++-- .../{AutoLog.h => log/include/log/ILogger.h} | 30 +-- parameter/log/include/log/LogWrapper.h | 137 ++++++++++ parameter/log/include/log/Logger.h | 86 ++++++ test/test-fixed-point-parameter/Main.py | 8 +- test/test-platform/TestPlatform.cpp | 14 +- utility/CMakeLists.txt | 4 + 27 files changed, 557 insertions(+), 335 deletions(-) rename parameter/{AutoLog.cpp => log/include/log/Context.h} (64%) rename parameter/{AutoLog.h => log/include/log/ILogger.h} (80%) create mode 100644 parameter/log/include/log/LogWrapper.h create mode 100644 parameter/log/include/log/Logger.h diff --git a/bindings/c/ParameterFramework.cpp b/bindings/c/ParameterFramework.cpp index dcca5cc00..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; }; 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 affae6b92..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() {} }; 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/CMakeLists.txt b/parameter/CMakeLists.txt index 94369fb74..d5b65219f 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 @@ -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/Element.cpp b/parameter/Element.cpp index cacf49b6c..eb8e6d519 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, @@ -48,81 +48,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; @@ -674,16 +599,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 { diff --git a/parameter/Element.h b/parameter/Element.h index 8423e32be..b3fe4bed4 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; @@ -165,18 +158,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/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 2e12a96cb..4a6431cb5 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -66,7 +66,6 @@ #include "EnumParameterType.h" #include "RemoteProcessorServerInterface.h" #include "ElementLocator.h" -#include "AutoLog.h" #include "CompoundRule.h" #include "SelectionCriterionRule.h" #include "SimulatedBackSynchronizer.h" @@ -91,10 +90,20 @@ #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 // We need to ensure though the blackboard is initialized with valid data @@ -109,6 +118,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); @@ -302,7 +314,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), @@ -315,8 +327,7 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) : _uiStructureChecksum(0), _pRemoteProcessorServer(NULL), _uiMaxCommandUsageLength(0), - _pLogger(NULL), - _uiLogDepth(0), + _logger(logger), _bForceNoRemoteInterface(false), _bFailOnMissingSubsystem(true), _bFailOnFailedSettingsLoad(true), @@ -385,43 +396,6 @@ 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 { @@ -439,7 +413,7 @@ string CParameterMgr::getVersion() const bool CParameterMgr::load(string& strError) { - CAutoLog autoLog(this, "Loading"); + LOG_CONTEXT("Loading"); feedElementLibraries(); @@ -474,7 +448,7 @@ bool CParameterMgr::load(string& strError) { - 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(); @@ -488,14 +462,14 @@ bool CParameterMgr::load(string& strError) // Log selection criterion states { - CAutoLog autoLog(this, "Criterion states"); + LOG_CONTEXT("Criterion states"); const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria(); - list lstrSelectionCriteron; - selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false); + list criteria; + selectionCriteria->listSelectionCriteria(criteria, true, false); - log_table(false, lstrSelectionCriteron); + info() << criteria; } // Subsystem can not ask for resync as they have not been synced yet @@ -510,7 +484,7 @@ 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); @@ -534,14 +508,15 @@ bool CParameterMgr::loadFrameworkConfiguration(string& strError) } // Log tuning availability - log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited"); + info() << "Tuning " + << (getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited"); return true; } bool CParameterMgr::loadSubsystems(std::string& error) { - CAutoLog autoLog(this, "Loading subsystem plugins"); + LOG_CONTEXT("Loading subsystem plugins"); // Load subsystems bool isSuccess = getSystemClass()->loadSubsystems(error, @@ -549,14 +524,14 @@ bool CParameterMgr::loadSubsystems(std::string& error) !_bFailOnMissingSubsystem); if (isSuccess) { - log_info("All subsystem plugins successfully loaded"); + info() << "All subsystem plugins successfully loaded"; if(!error.empty()) { // Log missing subsystems as info - log_info(error); + info() << error; } } else { - log_warning(error); + warning() << error; } return isSuccess; } @@ -566,7 +541,7 @@ bool CParameterMgr::loadStructure(string& strError) // Retrieve system to load structure to CSystemClass* pSystemClass = getSystemClass(); - log_info("Loading " + pSystemClass->getName() + " system class structure"); + LOG_CONTEXT("Loading " + pSystemClass->getName() + " system class structure"); // Get structure description element const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation")); @@ -587,11 +562,13 @@ 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, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) { - return false; + return false; + } } // Initialize offsets @@ -610,8 +587,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; } @@ -626,7 +603,7 @@ 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")); @@ -676,7 +653,8 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) // 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")) { @@ -718,7 +696,7 @@ bool CParameterMgr::importDomainFromFile(const string& strXmlFilePath, bool bOve return false; } - CAutoLog autoLog(this, "Adding configurable domain '" + standaloneDomain->getName() + "'"); + LOG_CONTEXT("Adding configurable domain '" + standaloneDomain->getName() + "'"); if (!logResult(getConfigurableDomains()->addDomain( *standaloneDomain, bOverwrite, strError), strError)) { @@ -784,7 +762,9 @@ CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInc CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType) { // Propagate - return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType); + return getSelectionCriteria()->createSelectionCriterion(strName, + pSelectionCriterionType, + _logger); } // Selection criterion retrieval @@ -797,7 +777,7 @@ CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName) // Configuration application void CParameterMgr::applyConfigurations() { - CAutoLog autoLog(this, "Configuration application request"); + LOG_CONTEXT("Configuration application request"); // Lock state CAutoLock autoLock(&_blackboardMutex); @@ -808,7 +788,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"; } } @@ -1791,10 +1771,9 @@ bool CParameterMgr::accessConfigurationValue(const string& strDomain, const stri CParameterBlackboard* pConfigurationBlackboard = NULL; { - CAutoLog autolog(this, - "Find configuration blackboard for Domain: " + strDomain - + ", Configuration: " + strConfiguration - + ", Element: " + pConfigurableElement->getPath()); + LOG_CONTEXT("Find configuration blackboard for Domain: " + strDomain + + ", Configuration: " + strConfiguration + + ", Element: " + pConfigurableElement->getPath()); pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, @@ -1805,12 +1784,13 @@ bool CParameterMgr::accessConfigurationValue(const string& strDomain, const stri strError); if (!pConfigurationBlackboard) { - log_warning("Fail: " + strError); + 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 @@ -1994,7 +1974,7 @@ bool CParameterMgr::sync(string& strError) // Configuration/Domains handling bool CParameterMgr::createDomain(const string& strName, string& strError) { - CAutoLog autoLog(this, "Creating configurable domain " + strName); + LOG_CONTEXT("Creating configurable domain " + strName); // Check tuning mode if (!checkTuningModeOn(strError)) { @@ -2007,11 +1987,12 @@ bool CParameterMgr::createDomain(const string& strName, string& strError) bool CParameterMgr::deleteDomain(const string& strName, string& strError) { - CAutoLog autoLog(this, "Deleting configurable domain '" + strName + "'"); + LOG_CONTEXT("Deleting configurable domain '" + strName + "'"); + // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail:" + strError); + warning() << "Fail: " << strError; return false; } @@ -2021,8 +2002,7 @@ bool CParameterMgr::deleteDomain(const string& strName, string& strError) bool CParameterMgr::renameDomain(const string& strName, const string& strNewName, string& strError) { - CAutoLog autoLog(this, "Renaming configurable domain '" + strName - + "' to '" + strNewName + "'"); + LOG_CONTEXT("Renaming configurable domain '" + strName + "' to '" + strNewName + "'"); // Delegate to configurable domains return logResult(getConfigurableDomains()->renameDomain( @@ -2031,29 +2011,30 @@ bool CParameterMgr::renameDomain(const string& strName, const string& strNewName bool CParameterMgr::deleteAllDomains(string& strError) { - CAutoLog autoLog(this, "Deleting all configurable domains"); + LOG_CONTEXT("Deleting all configurable domains"); + // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail: " << strError; return false; } // Delegate to configurable domains getConfigurableDomains()->deleteAllDomains(); - log_info("Success"); + info() << "Success"; return true; } bool CParameterMgr::setSequenceAwareness(const string& strName, bool bSequenceAware, string& strResult) { - CAutoLog autoLog(this, "Making domain '" + strName - + "' sequence " + (bSequenceAware ? "aware" : "unaware")); + LOG_CONTEXT("Making domain '" + strName + + "' sequence " + (bSequenceAware ? "aware" : "unaware")); // Check tuning mode if (!checkTuningModeOn(strResult)) { - log_warning("Fail: " + strResult); + warning() << "Fail: " << strResult; return false; } @@ -2069,12 +2050,12 @@ bool CParameterMgr::getSequenceAwareness(const string& strName, bool& bSequenceA bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { - CAutoLog autoLog(this, "Creating domain configuration '" + strConfiguration - + "' into domain '" + strDomain + "'"); + LOG_CONTEXT("Creating domain configuration '" + strConfiguration + + "' into domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail: " << strError; return false; } @@ -2085,8 +2066,8 @@ bool CParameterMgr::createConfiguration(const string& strDomain, const string& s bool CParameterMgr::renameConfiguration(const string& strDomain, const string& strConfiguration, const string& strNewConfiguration, string& strError) { - CAutoLog autoLog(this, "Renaming domain '" + strDomain - + "''s configuration '" + strConfiguration + "' to '" + strNewConfiguration + "'"); + LOG_CONTEXT("Renaming domain '" + strDomain + "''s configuration '" + + strConfiguration + "' to '" + strNewConfiguration + "'"); return logResult(getConfigurableDomains()->renameConfiguration( strDomain, strConfiguration, strNewConfiguration, strError), strError); @@ -2094,13 +2075,13 @@ bool CParameterMgr::renameConfiguration(const string& strDomain, const string& s bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { - CAutoLog autoLog(this, "Deleting configuration '" + strConfiguration - + "' from domain '" + strDomain + "'"); + LOG_CONTEXT("Deleting configuration '" + strConfiguration + + "' from domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2114,13 +2095,13 @@ bool CParameterMgr::restoreConfiguration(const string& strDomain, core::Results& errors) { string strError; - CAutoLog autoLog(this, "Restoring domain '" + strDomain - + "''s configuration '" + strConfiguration + "' to parameter blackboard"); + LOG_CONTEXT("Restoring domain '" + strDomain + "''s configuration '" + + strConfiguration + "' to parameter blackboard"); // Check tuning mode if (!checkTuningModeOn(strError)) { errors.push_back(strError); - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2132,12 +2113,12 @@ bool CParameterMgr::restoreConfiguration(const string& strDomain, bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { - CAutoLog autoLog(this, "Saving domain '" + strDomain - + "''s configuration '" + strConfiguration + "' from parameter blackboard"); + LOG_CONTEXT("Saving domain '" + strDomain + "' configuration '" + + strConfiguration + "' from parameter blackboard"); // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2149,12 +2130,12 @@ bool CParameterMgr::saveConfiguration(const string& strDomain, const string& str // Configurable element - domain association bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) { - CAutoLog autoLog(this, "Adding configurable element '" + strConfigurableElementPath - + "to domain '" + strDomain + "'"); + LOG_CONTEXT("Adding configurable element '" + strConfigurableElementPath + + "to domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail: " << strError; return false; } @@ -2164,7 +2145,7 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { - log_warning("Fail: " + strError); + warning() << "Fail: " << strError; return false; } @@ -2176,7 +2157,11 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons bool isSuccess = getConfigurableDomains()->addConfigurableElementToDomain( strDomain, pConfigurableElement, _pMainParameterBlackboard, infos); - log_table(!isSuccess, infos); + if (isSuccess) { + info() << infos; + } else { + warning() << infos; + } CUtility::asString(infos, strError); return isSuccess; @@ -2184,12 +2169,13 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) { - CAutoLog autoLog(this, "Removing configurable element '" + strConfigurableElementPath - + "' from domain '" + strDomain + "'"); + LOG_CONTEXT("Removing configurable element '" + strConfigurableElementPath + + "' from domain '" + strDomain + "'"); + // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2199,7 +2185,7 @@ bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2213,12 +2199,12 @@ bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError) { - CAutoLog autoLog(this, "Splitting configurable element '" + strConfigurableElementPath - + "' domain '" + strDomain + "'"); + LOG_CONTEXT("Splitting configurable element '" + strConfigurableElementPath + + "' domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2228,7 +2214,7 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { - log_warning("Fail: " + strError); + warning() << "Fail: " << strError; return false; } @@ -2239,7 +2225,12 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable core::Results infos; bool isSuccess = getConfigurableDomains()->split(strDomain, pConfigurableElement, infos); - log_table(isSuccess, infos); + if (isSuccess) { + info() << infos; + } else { + warning() << infos; + } + CUtility::asString(infos, strError); return isSuccess; } @@ -2583,7 +2574,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 @@ -2593,7 +2584,7 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) // Start server if tuning allowed if (getConstFrameworkConfiguration()->isTuningAllowed()) { - log_info("Loading remote processor library"); + info() << "Loading remote processor library"; // Load library _pvLibRemoteProcessorHandle = dlopen("libremote-processor.so", RTLD_NOW); @@ -2626,7 +2617,8 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) // Create server _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler); - log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort()); + info() << "Starting remote processor server on port " + << getConstFrameworkConfiguration()->getServerPort(); // Start if (!_pRemoteProcessorServer->start()) { @@ -2692,7 +2684,7 @@ const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const // Apply configurations void CParameterMgr::doApplyConfigurations(bool bForce) { - CAutoLog autoLog(this, "Applying configurations"); + LOG_CONTEXT("Applying configurations"); CSyncerSet syncerSet; @@ -2702,7 +2694,7 @@ void CParameterMgr::doApplyConfigurations(bool bForce) // Ensure application of currently selected configurations getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce, infos); - log_table(false, infos); + info() << infos; // Reset the modified status of the current criteria to indicate that a new configuration has been applied getSelectionCriteria()->resetModifiedStatus(); @@ -2736,9 +2728,23 @@ bool CParameterMgr::exportElementToXMLString(const IXmlSource* pXmlSource, bool CParameterMgr::logResult(bool isSuccess, const std::string& result) { - std::string log(isSuccess ? "Success" : "Fail" ); - log += (result.empty() ? "" : ": " + result); - (this->*(isSuccess ? &CParameterMgr::log_info : &CParameterMgr::log_warning))(log); + 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 5ced38131..1e0f895fc 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -40,8 +40,11 @@ #include "XmlDocSink.h" #include "XmlDocSource.h" #include "Results.h" +#include +#include #include +#include class CElementLibrarySet; class CSubsystemLibrary; @@ -93,22 +96,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 @@ -369,11 +361,6 @@ class CParameterMgr : private CElement // 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; @@ -596,6 +583,12 @@ class CParameterMgr : private CElement */ 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; @@ -648,9 +641,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 diff --git a/parameter/ParameterMgrFullConnector.cpp b/parameter/ParameterMgrFullConnector.cpp index 7ab3f9188..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); } } 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/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 975503b90..03a04dc7b 100644 --- a/parameter/SelectionCriterion.cpp +++ b/parameter/SelectionCriterion.cpp @@ -29,10 +29,16 @@ */ #include "SelectionCriterion.h" +#include #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) { } @@ -60,13 +66,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 diff --git a/parameter/SelectionCriterion.h b/parameter/SelectionCriterion.h index 86c96836b..e9c2f4950 100644 --- a/parameter/SelectionCriterion.h +++ b/parameter/SelectionCriterion.h @@ -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 @@ -80,5 +83,8 @@ class CSelectionCriterion : public CElement, public ISelectionCriterionInterface /** 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/include/ParameterMgrFullConnector.h b/parameter/include/ParameterMgrFullConnector.h index cbed5777c..a49d4ac86 100644 --- a/parameter/include/ParameterMgrFullConnector.h +++ b/parameter/include/ParameterMgrFullConnector.h @@ -56,7 +56,8 @@ class 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() {} }; @@ -277,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/AutoLog.cpp b/parameter/log/include/log/Context.h similarity index 64% rename from parameter/AutoLog.cpp rename to parameter/log/include/log/Context.h index ff7151aaf..b466ad2d1 100644 --- a/parameter/AutoLog.cpp +++ b/parameter/log/include/log/Context.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -27,27 +27,47 @@ * (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 "log/Logger.h" +#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(); +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 += " "; } -} -CAutoLog::~CAutoLog() -{ - if (_bLogOn) { - // Unnest - _pElement->unnestLog(); - // Log - _pElement->doLog(false, "} " + _strContext); + /** 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/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 028dfd396..0153514f4 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -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; } }; 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") From 8eb4c34ade7e9d8255d10626dcedf57447baa1cf Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 7 Apr 2015 09:50:17 +0200 Subject: [PATCH 11/19] Remove unused remote-processor include location from test-subsystem Signed-off-by: Jules Clero --- test/test-subsystem/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test-subsystem/CMakeLists.txt b/test/test-subsystem/CMakeLists.txt index 52e66b024..ac058834b 100644 --- a/test/test-subsystem/CMakeLists.txt +++ b/test/test-subsystem/CMakeLists.txt @@ -37,7 +37,6 @@ if (BUILD_TESTING) include_directories( "${PROJECT_SOURCE_DIR}/xmlserializer" - "${PROJECT_SOURCE_DIR}/remote-processor" "${PROJECT_SOURCE_DIR}/parameter") target_link_libraries(test-subsystem parameter) From ca361e34d4d3474a898654b5eaf973d60828f923 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Wed, 4 Mar 2015 17:04:48 +0100 Subject: [PATCH 12/19] Enable subsystems logging Plugins are now able to log. An ILogger object is provided to plugins to do that. Signed-off-by: Jules Clero --- parameter/CMakeLists.txt | 2 +- parameter/DefaultElementLibrary.h | 25 +++---- parameter/FormattedSubsystemObject.cpp | 13 ++-- parameter/FormattedSubsystemObject.h | 10 ++- parameter/LoggingElementBuilderTemplate.h | 70 ++++++++++++++++++++ parameter/ParameterMgr.cpp | 2 +- parameter/Subsystem.cpp | 9 ++- parameter/Subsystem.h | 16 ++++- parameter/SubsystemLibrary.h | 6 +- parameter/SubsystemObject.cpp | 6 +- parameter/SubsystemObject.h | 9 ++- parameter/SubsystemObjectCreator.h | 8 ++- parameter/SubsystemObjectFactory.h | 11 ++- parameter/SystemClass.cpp | 20 ++++-- parameter/SystemClass.h | 11 ++- parameter/VirtualSubsystem.cpp | 6 +- parameter/VirtualSubsystem.h | 9 ++- test/test-subsystem/CMakeLists.txt | 2 + test/test-subsystem/TESTSubsystem.cpp | 3 +- test/test-subsystem/TESTSubsystem.h | 2 +- test/test-subsystem/TESTSubsystemBinary.cpp | 7 +- test/test-subsystem/TESTSubsystemBinary.h | 5 +- test/test-subsystem/TESTSubsystemBuilder.cpp | 7 +- test/test-subsystem/TESTSubsystemObject.cpp | 35 +++++++++- test/test-subsystem/TESTSubsystemObject.h | 5 +- test/test-subsystem/TESTSubsystemString.cpp | 7 +- test/test-subsystem/TESTSubsystemString.h | 5 +- 27 files changed, 243 insertions(+), 68 deletions(-) create mode 100644 parameter/LoggingElementBuilderTemplate.h diff --git a/parameter/CMakeLists.txt b/parameter/CMakeLists.txt index d5b65219f..ee009a88f 100644 --- a/parameter/CMakeLists.txt +++ b/parameter/CMakeLists.txt @@ -137,7 +137,7 @@ install(FILES InstanceConfigurableElement.h Mapper.h MappingContext.h - NamedElementBuilderTemplate.h + LoggingElementBuilderTemplate.h ParameterBlockType.h ParameterType.h PathNavigator.h 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/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/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/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 4a6431cb5..cf440780c 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -341,7 +341,7 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge // Deal with children addChild(new CParameterFrameworkConfiguration); addChild(new CSelectionCriteria); - addChild(new CSystemClass); + addChild(new CSystemClass(_logger)); addChild(new CConfigurableDomains); _pCommandHandler = new CCommandHandler(this); diff --git a/parameter/Subsystem.cpp b/parameter/Subsystem.cpp index 5dbe3a073..fc9f39fef 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, @@ -44,7 +44,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 @@ -449,7 +452,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; diff --git a/parameter/Subsystem.h b/parameter/Subsystem.h index e53735299..2943ff816 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 @@ -250,4 +259,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 592ec5628..ebe410097 100644 --- a/parameter/SubsystemObject.cpp +++ b/parameter/SubsystemObject.cpp @@ -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) diff --git a/parameter/SubsystemObject.h b/parameter/SubsystemObject.h index e4ccd19b4..08f65cf79 100644 --- a/parameter/SubsystemObject.h +++ b/parameter/SubsystemObject.h @@ -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(); /** @@ -85,6 +87,9 @@ class CSubsystemObject : private ISyncer // 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/SystemClass.cpp b/parameter/SystemClass.cpp index 7e0c31cf1..e98fd5045 100644 --- a/parameter/SystemClass.cpp +++ b/parameter/SystemClass.cpp @@ -34,7 +34,7 @@ #include "SystemClass.h" #include "SubsystemLibrary.h" #include "VirtualSubsystem.h" -#include "NamedElementBuilderTemplate.h" +#include "LoggingElementBuilderTemplate.h" #include #include "PluginLocation.h" #include "Utility.h" @@ -44,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 @@ -60,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) { } @@ -100,11 +104,13 @@ bool CSystemClass::loadSubsystems(string& strError, // 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 core::Results errors; @@ -249,7 +255,7 @@ bool CSystemClass::loadPlugins(list& lstrPluginFiles, core::Results& err bAtLeastOneSubsystemPluginSuccessfullyLoaded = true; // Fill library - pfnGetSubsystemBuilder(_pSubsystemLibrary); + pfnGetSubsystemBuilder(_pSubsystemLibrary, _logger); // Remove successfully loaded plugin from list and select next lstrPluginFiles.erase(it++); diff --git a/parameter/SystemClass.h b/parameter/SystemClass.h index 886ed32c6..a6531b0df 100644 --- a/parameter/SystemClass.h +++ b/parameter/SystemClass.h @@ -32,6 +32,7 @@ #include "ConfigurableElement.h" #include "SubsystemPlugins.h" #include "Results.h" +#include #include #include @@ -40,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. @@ -110,5 +116,8 @@ class CSystemClass : public CConfigurableElement // 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/test/test-subsystem/CMakeLists.txt b/test/test-subsystem/CMakeLists.txt index ac058834b..b499923d1 100644 --- a/test/test-subsystem/CMakeLists.txt +++ b/test/test-subsystem/CMakeLists.txt @@ -37,6 +37,8 @@ if (BUILD_TESTING) include_directories( "${PROJECT_SOURCE_DIR}/xmlserializer" + "${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 d17be0bfb..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 @@ -105,6 +110,19 @@ void CTESTSubsystemObject::sendToFile(std::ofstream& outputFile) std::string strValue = toString(pvValue, _uiScalarSize); outputFile << strValue << std::endl; + + if (_bLog) { + + if (_bIsScalar) { + + _logger.info() << "TESTSUBSYSTEM: Writing '" << strValue + << "' to file " << _strFilePath; + } else { + + _logger.info() << "TESTSUBSYSTEM: Writing '" << strValue << "' to file " + << _strFilePath << "[" << uiIndex << "]"; + } + } } } @@ -120,6 +138,19 @@ void CTESTSubsystemObject::receiveFromFile(std::ifstream& inputFile) inputFile >> strValue; + if (_bLog) { + + if (_bIsScalar) { + + _logger.info() << "TESTSUBSYSTEM: Reading '" << strValue + << "' to file " << _strFilePath; + } else { + + _logger.info() << "TESTSUBSYSTEM: Reading '" << strValue << "' to file " + << _strFilePath << "[" << uiIndex << "]"; + } + } + fromString(strValue, pvValue, _uiScalarSize); // Write Value in Blackboard 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 From e85bd0668730c5d4a2bc90b4542cf5cad99f090a Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 5 Mar 2015 16:09:35 +0100 Subject: [PATCH 13/19] Update Skeleton Subsystem for log ability. Signed-off-by: Jules Clero --- skeleton-subsystem/CMakeLists.txt | 9 +++++++-- skeleton-subsystem/SkeletonSubsystem.cpp | 5 +++-- skeleton-subsystem/SkeletonSubsystem.h | 4 ++-- skeleton-subsystem/SkeletonSubsystemBuilder.cpp | 10 ++++++---- skeleton-subsystem/SkeletonSubsystemObject.cpp | 6 ++++-- skeleton-subsystem/SkeletonSubsystemObject.h | 7 +++++-- 6 files changed, 27 insertions(+), 14 deletions(-) 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 From 390f97c0ce86b1ea29f1f849a8d995d72b03c934 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 2 Apr 2015 11:46:52 +0200 Subject: [PATCH 14/19] Update domainGenerator python script to use the new log API Change-Id: Ib31547b3f899f96b837ac125ea7b0feb8c946760 Signed-off-by: Jules Clero --- tools/xmlGenerator/domainGenerator.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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__": From 8b3253dbc3ebc4b0acd6a032805579a7311bfb28 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Tue, 14 Apr 2015 17:27:57 +0200 Subject: [PATCH 15/19] README: change url to CI badges for the 'next' branch Signed-off-by: David Wagner --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From f6f1acf377bffa4fa2aea4868bf1da8aad09ab3b Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Wed, 11 Mar 2015 14:11:21 +0100 Subject: [PATCH 16/19] Remove init function member from Element init function is defined in Element god class but is used only for plugins initialization after structure and settings loading. This patch delegate Subsystem initialization to SystemClass which is the direct parent. Signed-off-by: Jules Clero --- parameter/Element.cpp | 17 ----------------- parameter/Element.h | 2 -- parameter/ParameterMgr.cpp | 9 +-------- parameter/ParameterMgr.h | 3 --- parameter/Subsystem.cpp | 6 ++++++ parameter/Subsystem.h | 8 ++++++++ parameter/SystemClass.cpp | 17 +++++++++++++++++ parameter/SystemClass.h | 7 +++++++ 8 files changed, 39 insertions(+), 30 deletions(-) diff --git a/parameter/Element.cpp b/parameter/Element.cpp index eb8e6d519..e446fbeba 100644 --- a/parameter/Element.cpp +++ b/parameter/Element.cpp @@ -64,23 +64,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; diff --git a/parameter/Element.h b/parameter/Element.h index b3fe4bed4..dd57584c8 100644 --- a/parameter/Element.h +++ b/parameter/Element.h @@ -57,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 diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index cf440780c..f8b9f8463 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -440,8 +440,7 @@ bool CParameterMgr::load(string& strError) return false; } - // Init flow of element tree - if (!init(strError)) { + if (!getSystemClass()->initSubsystems(strError)) { return false; } @@ -746,12 +745,6 @@ 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) { diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index 1e0f895fc..c4e196121 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -358,9 +358,6 @@ class CParameterMgr : private CElement CParameterMgr(const CParameterMgr&); CParameterMgr& operator=(const CParameterMgr&); - // Init - virtual bool init(std::string& strError); - // Version std::string getVersion() const; diff --git a/parameter/Subsystem.cpp b/parameter/Subsystem.cpp index fc9f39fef..4b085e0a5 100644 --- a/parameter/Subsystem.cpp +++ b/parameter/Subsystem.cpp @@ -532,3 +532,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 2943ff816..55d06e9a4 100644 --- a/parameter/Subsystem.h +++ b/parameter/Subsystem.h @@ -98,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; diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp index e98fd5045..51709b7f4 100644 --- a/parameter/SystemClass.cpp +++ b/parameter/SystemClass.cpp @@ -301,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 a6531b0df..dccb509a7 100644 --- a/parameter/SystemClass.h +++ b/parameter/SystemClass.h @@ -79,6 +79,13 @@ class CSystemClass : public CConfigurableElement */ 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; From b3ef21a201692a6def531c89d0641bf4425cdfe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Gonzalve?= Date: Sat, 28 Feb 2015 21:39:08 +0100 Subject: [PATCH 17/19] Move toString and appendtitle out of element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The element class really looks like a god class with stuff that has really nothing to do with its role. toString and appendTitle are good example of stuff that should be move away from it. This patch move those two functions into utility where they seems to belong. Signed-off-by: Sébastien Gonzalve Signed-off-by: Jules Clero --- parameter/ArrayParameter.cpp | 8 +-- parameter/BitParameterBlockType.cpp | 5 +- parameter/BitParameterType.cpp | 15 +++--- parameter/ConfigurableElement.cpp | 5 +- parameter/Element.cpp | 52 -------------------- parameter/Element.h | 8 --- parameter/EnumParameterType.cpp | 5 +- parameter/EnumValuePair.cpp | 5 +- parameter/FixedPointParameterType.cpp | 13 ++--- parameter/IntegerParameterType.cpp | 17 ++++--- parameter/LinearParameterAdaptation.cpp | 5 +- parameter/LogarithmicParameterAdaptation.cpp | 5 +- parameter/ParameterAdaptation.cpp | 3 +- parameter/ParameterBlockType.cpp | 4 +- parameter/ParameterMgr.cpp | 14 +++--- parameter/ParameterType.cpp | 3 +- parameter/SelectionCriterion.cpp | 4 +- parameter/StringParameterType.cpp | 3 +- parameter/Subsystem.cpp | 4 +- utility/Utility.cpp | 13 +++++ utility/Utility.h | 19 ++++++- 21 files changed, 100 insertions(+), 110 deletions(-) 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/ConfigurableElement.cpp b/parameter/ConfigurableElement.cpp index 754f2077e..08a01223a 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 @@ -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 diff --git a/parameter/Element.cpp b/parameter/Element.cpp index e446fbeba..98b33c1fb 100644 --- a/parameter/Element.cpp +++ b/parameter/Element.cpp @@ -35,7 +35,6 @@ #include #include #include -#include using std::string; @@ -110,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 { @@ -610,17 +572,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 dd57584c8..2033c0943 100644 --- a/parameter/Element.h +++ b/parameter/Element.h @@ -124,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; @@ -138,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(); 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/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/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 f8b9f8463..0cc3cd08c 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -402,11 +402,11 @@ 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; } @@ -898,7 +898,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProces // Show status /// General section - appendTitle(strResult, "General:"); + CUtility::appendTitle(strResult, "General:"); // System class strResult += "System Class: "; strResult += pSystemClass->getName(); @@ -925,19 +925,19 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProces strResult += "\n"; /// Subsystem list - appendTitle(strResult, "Subsystems:"); + CUtility::appendTitle(strResult, "Subsystems:"); string strSubsystemList; pSystemClass->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); strResult += strLastAppliedConfigurations; /// Criteria states - appendTitle(strResult, "Selection Criteria:"); + CUtility::appendTitle(strResult, "Selection Criteria:"); list lstrSelectionCriteria; getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true); // Concatenate the criterion list as the command result 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/SelectionCriterion.cpp b/parameter/SelectionCriterion.cpp index 03a04dc7b..f2dbbe550 100644 --- a/parameter/SelectionCriterion.cpp +++ b/parameter/SelectionCriterion.cpp @@ -30,6 +30,8 @@ #include "SelectionCriterion.h" #include +#include +#include "Utility.h" #define base CElement @@ -133,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/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 4b085e0a5..0f337d714 100644 --- a/parameter/Subsystem.cpp +++ b/parameter/Subsystem.cpp @@ -35,6 +35,7 @@ #include "ConfigurationAccessContext.h" #include "SubsystemObjectCreator.h" #include "MappingData.h" +#include "Utility.h" #include #include @@ -443,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); 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); +}; From b64f7c5fafda800bcf81d6e669908accd43ab37d Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 12 Mar 2015 17:35:12 +0100 Subject: [PATCH 18/19] Remove SelectionCriteria based subtree from structure checksum. SelectionCriteria class is dependant from Element class because of the checksum calculation algorithm which is based on child name. In preparation of a rework, we exclude it from the structure checksum calculation. Moreover the criterion mechanism is not a part of the parameter-framework structure. Thus, this decision is fair. Signed-off-by: Jules Clero --- parameter/ParameterMgr.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 0cc3cd08c..195a8c7ca 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -662,7 +662,8 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) } // We have loaded the whole system structure, compute checksum const CSystemClass* pSystemClass = getConstSystemClass(); - _uiStructureChecksum = pSystemClass->computeStructureChecksum() + getConfigurableDomains()->computeStructureChecksum() + getSelectionCriteria()->computeStructureChecksum(); + _uiStructureChecksum = pSystemClass->computeStructureChecksum() + + getConfigurableDomains()->computeStructureChecksum(); // Load binary settings if any provided if (pBinarySettingsFileLocation && !pConfigurableDomains->serializeSettings(strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) { From ce012c816b9d95168d83c6b35eba795bc0a0626d Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Wed, 11 Mar 2015 14:15:26 +0100 Subject: [PATCH 19/19] Avoid ParameterManager inheritance to Element god class. ParameterManager does not have to be a part of the Element tree. Indeed, it is not represented in any xml file. This patch avoids this inheritance and removes some "tricks" which was used to forget the ParameterMgr root element. Signed-off-by: Jules Clero --- parameter/ConfigurableElement.cpp | 20 +- parameter/ConfigurableElement.h | 3 - parameter/Element.cpp | 3 +- parameter/ParameterMgr.cpp | 363 ++++++++++++------------------ parameter/ParameterMgr.h | 46 ++-- 5 files changed, 173 insertions(+), 262 deletions(-) diff --git a/parameter/ConfigurableElement.cpp b/parameter/ConfigurableElement.cpp index 08a01223a..66e462e5c 100644 --- a/parameter/ConfigurableElement.cpp +++ b/parameter/ConfigurableElement.cpp @@ -162,7 +162,7 @@ void CConfigurableElement::getListOfElementsWithMapping( { // Check parent const CElement* pParent = getParent(); - if (isOfConfigurableElementType(pParent)) { + if (pParent != NULL) { const CConfigurableElement* pConfigurableElement = static_cast(pParent); @@ -242,7 +242,7 @@ ISyncer* CConfigurableElement::getSyncer() const // Check parent const CElement* pParent = getParent(); - if (isOfConfigurableElementType(pParent)) { + if (pParent != NULL) { return static_cast(pParent)->getSyncer(); } @@ -311,7 +311,7 @@ void CConfigurableElement::getBelongingDomains(std::list(pParent)->getBelongingDomains(configurableDomainList); } @@ -466,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); } @@ -479,7 +479,7 @@ const CSubsystem* CConfigurableElement::getBelongingSubsystem() const const CElement* pParent = getParent(); // Stop at system class - if (!pParent->getParent()) { + if (pParent == NULL) { return NULL; } @@ -492,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/Element.cpp b/parameter/Element.cpp index 98b33c1fb..edd093994 100644 --- a/parameter/Element.cpp +++ b/parameter/Element.cpp @@ -531,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(); } diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 195a8c7ca..ea5dfabe0 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -30,7 +30,6 @@ #include "ParameterMgr.h" #include "XmlParameterSerializingContext.h" #include "XmlElementSerializingContext.h" -#include "SystemClass.h" #include "ElementLibrarySet.h" #include "SubsystemLibrary.h" #include "NamedElementBuilderTemplate.h" @@ -39,7 +38,6 @@ #include "SelectionCriterionType.h" #include "SubsystemElementBuilder.h" #include "FileIncluderElementBuilder.h" -#include "SelectionCriteria.h" #include "ComponentType.h" #include "ComponentInstance.h" #include "ParameterBlockType.h" @@ -49,12 +47,10 @@ #include "ParameterBlackboard.h" #include "Parameter.h" #include "ParameterAccessContext.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" @@ -91,8 +87,6 @@ #include #include -#define base CElement - /** Private macro helper to declare a new context * * Context declaration always need logger and logging prefix to be @@ -331,19 +325,17 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge _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(_logger)); - addChild(new CConfigurableDomains); - _pCommandHandler = new CCommandHandler(this); // Add command parsers @@ -440,7 +432,7 @@ bool CParameterMgr::load(string& strError) return false; } - if (!getSystemClass()->initSubsystems(strError)) { + if (!mSystemClass.initSubsystems(strError)) { return false; } @@ -449,30 +441,26 @@ bool CParameterMgr::load(string& strError) { 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 { LOG_CONTEXT("Criterion states"); - const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria(); - list criteria; - selectionCriteria->listSelectionCriteria(criteria, true, false); + mCriteria.listSelectionCriteria(criteria, true, false); 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); @@ -488,16 +476,18 @@ bool CParameterMgr::loadFrameworkConfiguration(string& strError) // 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) { @@ -507,8 +497,7 @@ bool CParameterMgr::loadFrameworkConfiguration(string& strError) } // Log tuning availability - info() << "Tuning " - << (getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited"); + info() << "Tuning " << (mPfwConfiguration.isTuningAllowed() ? "allowed" : "prohibited"); return true; } @@ -518,9 +507,9 @@ bool CParameterMgr::loadSubsystems(std::string& error) LOG_CONTEXT("Loading subsystem plugins"); // Load subsystems - bool isSuccess = getSystemClass()->loadSubsystems(error, - _pSubsystemPlugins, - !_bFailOnMissingSubsystem); + bool isSuccess = mSystemClass.loadSubsystems(error, + _pSubsystemPlugins, + !_bFailOnMissingSubsystem); if (isSuccess) { info() << "All subsystem plugins successfully loaded"; @@ -537,17 +526,17 @@ bool CParameterMgr::loadSubsystems(std::string& error) bool CParameterMgr::loadStructure(string& strError) { - // Retrieve system to load structure to - CSystemClass* pSystemClass = getSystemClass(); - - LOG_CONTEXT("Loading " + pSystemClass->getName() + " system class structure"); + 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; } @@ -564,17 +553,18 @@ bool CParameterMgr::loadStructure(string& strError) { LOG_CONTEXT("Importing system structure from file " + strXmlStructureFilePath); - if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) { + if (!xmlParse(parameterBuildContext, &mSystemClass, + strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) { 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; } @@ -605,7 +595,9 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) 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) { @@ -629,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); @@ -643,11 +634,14 @@ 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); @@ -656,17 +650,19 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) << " " << ( 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(); + _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; } @@ -677,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); @@ -698,8 +695,7 @@ bool CParameterMgr::importDomainFromFile(const string& strXmlFilePath, bool bOve LOG_CONTEXT("Adding configurable domain '" + standaloneDomain->getName() + "'"); - if (!logResult(getConfigurableDomains()->addDomain( - *standaloneDomain, bOverwrite, strError), strError)) { + if (!logResult(mDomains.addDomain(*standaloneDomain, bOverwrite, strError), strError)) { return false; } @@ -750,22 +746,20 @@ bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingCo 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, - _logger); + 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 @@ -793,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) { @@ -894,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 CUtility::appendTitle(strResult, "General:"); // System class strResult += "System Class: "; - strResult += pSystemClass->getName(); + strResult += mSystemClass.getName(); strResult += "\n"; // Tuning mode @@ -928,19 +920,19 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProces /// Subsystem list CUtility::appendTitle(strResult, "Subsystems:"); string strSubsystemList; - pSystemClass->listChildrenPaths(strSubsystemList); + mSystemClass.listChildrenPaths(strSubsystemList); strResult += strSubsystemList; /// Last applied configurations CUtility::appendTitle(strResult, "Last Applied [Pending] Configurations:"); string strLastAppliedConfigurations; - getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations); + mDomains.listLastAppliedConfigurations(strLastAppliedConfigurations); strResult += strLastAppliedConfigurations; /// Criteria states 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); @@ -1111,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)) { @@ -1127,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); @@ -1141,7 +1135,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmand { (void)remoteCommand; - getConfigurableDomains()->listDomains(strResult); + mDomains.listDomains(strResult); return CCommandHandler::ESucceeded; } @@ -1208,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) @@ -1229,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) @@ -1241,7 +1237,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmand CErrorContext errorContext(strError); // Dump - getConstConfigurableDomains()->dumpContent(strResult, errorContext); + mDomains.dumpContent(strResult, errorContext); return CCommandHandler::ESucceeded; } @@ -1301,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) @@ -1331,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; @@ -1347,7 +1346,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommman // List from root folder // Return system class qualified name - pLocatedElement = getSystemClass(); + pLocatedElement = &mSystemClass; } // Return sub-elements @@ -1359,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; @@ -1375,7 +1374,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommm // List from root folder // Return system class qualified name - pLocatedElement = getSystemClass(); + pLocatedElement = &mSystemClass; } // Return sub-elements @@ -1386,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; @@ -1407,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; @@ -1427,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; @@ -1469,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; @@ -1489,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; @@ -1511,7 +1510,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedEleme { (void)remoteCommand; - getConfigurableDomains()->listAssociatedElements(strResult); + mDomains.listAssociatedElements(strResult); return CCommandHandler::ESucceeded; } @@ -1520,7 +1519,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElem { (void)remoteCommand; - getConfigurableDomains()->listConflictingElements(strResult); + mDomains.listConflictingElements(strResult); return CCommandHandler::ESucceeded; } @@ -1529,7 +1528,7 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCo { (void)remoteCommand; - getSystemClass()->listRogueElements(strResult); + mSystemClass.listRogueElements(strResult); return CCommandHandler::ESucceeded; } @@ -1676,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; } @@ -1713,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; } @@ -1746,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; @@ -1769,13 +1766,12 @@ bool CParameterMgr::accessConfigurationValue(const string& strDomain, const stri ", Configuration: " + strConfiguration + ", Element: " + pConfigurableElement->getPath()); - pConfigurationBlackboard = - getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, - strConfiguration, - pConfigurableElement, - uiBaseOffset, - bIsLastApplied, - strError); + pConfigurationBlackboard = mDomains.findConfigurationBlackboard(strDomain, + strConfiguration, + pConfigurableElement, + uiBaseOffset, + bIsLastApplied, + strError); if (!pConfigurationBlackboard) { warning() << "Fail: " << strError; @@ -1835,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); @@ -1843,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"; @@ -1952,7 +1948,7 @@ bool CParameterMgr::sync(string& strError) // Get syncer set CSyncerSet syncerSet; // ... from system class - getConstSystemClass()->fillSyncerSet(syncerSet); + mSystemClass.fillSyncerSet(syncerSet); // Sync core::Results error; @@ -1976,7 +1972,7 @@ bool CParameterMgr::createDomain(const string& strName, string& strError) } // Delegate to configurable domains - return logResult(getConfigurableDomains()->createDomain(strName, strError), strError); + return logResult(mDomains.createDomain(strName, strError), strError); } bool CParameterMgr::deleteDomain(const string& strName, string& strError) @@ -1991,7 +1987,7 @@ bool CParameterMgr::deleteDomain(const string& strName, string& strError) } // Delegate to configurable domains - return logResult(getConfigurableDomains()->deleteDomain(strName, strError), strError); + return logResult(mDomains.deleteDomain(strName, strError), strError); } bool CParameterMgr::renameDomain(const string& strName, const string& strNewName, string& strError) @@ -1999,8 +1995,7 @@ bool CParameterMgr::renameDomain(const string& strName, const string& strNewName LOG_CONTEXT("Renaming configurable domain '" + strName + "' to '" + strNewName + "'"); // Delegate to configurable domains - return logResult(getConfigurableDomains()->renameDomain( - strName, strNewName, strError), strError); + return logResult(mDomains.renameDomain(strName, strNewName, strError), strError); } bool CParameterMgr::deleteAllDomains(string& strError) @@ -2015,7 +2010,7 @@ bool CParameterMgr::deleteAllDomains(string& strError) } // Delegate to configurable domains - getConfigurableDomains()->deleteAllDomains(); + mDomains.deleteAllDomains(); info() << "Success"; return true; @@ -2032,14 +2027,13 @@ bool CParameterMgr::setSequenceAwareness(const string& strName, bool bSequenceAw return false; } - return logResult(getConfigurableDomains()->setSequenceAwareness( - strName, bSequenceAware, strResult), 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) @@ -2054,7 +2048,7 @@ bool CParameterMgr::createConfiguration(const string& strDomain, const string& s } // Delegate to configurable domains - return logResult(getConfigurableDomains()->createConfiguration( + return logResult(mDomains.createConfiguration( strDomain, strConfiguration, _pMainParameterBlackboard, strError), strError); } bool CParameterMgr::renameConfiguration(const string& strDomain, const string& strConfiguration, @@ -2063,7 +2057,7 @@ bool CParameterMgr::renameConfiguration(const string& strDomain, const string& s LOG_CONTEXT("Renaming domain '" + strDomain + "''s configuration '" + strConfiguration + "' to '" + strNewConfiguration + "'"); - return logResult(getConfigurableDomains()->renameConfiguration( + return logResult(mDomains.renameConfiguration( strDomain, strConfiguration, strNewConfiguration, strError), strError); } @@ -2080,8 +2074,7 @@ bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& s } // Delegate to configurable domains - return logResult(getConfigurableDomains()->deleteConfiguration( - strDomain, strConfiguration, strError), strError); + return logResult(mDomains.deleteConfiguration(strDomain, strConfiguration, strError), strError); } bool CParameterMgr::restoreConfiguration(const string& strDomain, @@ -2100,7 +2093,7 @@ bool CParameterMgr::restoreConfiguration(const string& strDomain, } // Delegate to configurable domains - return logResult(getConstConfigurableDomains()->restoreConfiguration( + return logResult(mDomains.restoreConfiguration( strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, errors), strError); } @@ -2117,7 +2110,7 @@ bool CParameterMgr::saveConfiguration(const string& strDomain, const string& str } // Delegate to configurable domains - return logResult(getConfigurableDomains()->saveConfiguration( + return logResult(mDomains.saveConfiguration( strDomain, strConfiguration, _pMainParameterBlackboard, strError), strError); } @@ -2133,7 +2126,7 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons return false; } - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; @@ -2148,7 +2141,7 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons // Delegate core::Results infos; - bool isSuccess = getConfigurableDomains()->addConfigurableElementToDomain( + bool isSuccess = mDomains.addConfigurableElementToDomain( strDomain, pConfigurableElement, _pMainParameterBlackboard, infos); if (isSuccess) { @@ -2173,7 +2166,7 @@ bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, return false; } - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; @@ -2187,7 +2180,7 @@ bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - return logResult(getConfigurableDomains()->removeConfigurableElementFromDomain( + return logResult(mDomains.removeConfigurableElementFromDomain( strDomain, pConfigurableElement, strError), strError); } @@ -2202,7 +2195,7 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable return false; } - CElementLocator elementLocator(getSystemClass()); + CElementLocator elementLocator(&mSystemClass); CElement* pLocatedElement = NULL; @@ -2217,7 +2210,7 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable // Delegate core::Results infos; - bool isSuccess = getConfigurableDomains()->split(strDomain, pConfigurableElement, infos); + bool isSuccess = mDomains.split(strDomain, pConfigurableElement, infos); if (isSuccess) { info() << infos; @@ -2239,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, @@ -2279,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( @@ -2296,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; @@ -2305,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); } @@ -2407,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); @@ -2416,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; @@ -2458,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) @@ -2475,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 @@ -2526,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()); @@ -2576,7 +2560,7 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) } // Start server if tuning allowed - if (getConstFrameworkConfiguration()->isTuningAllowed()) { + if (mPfwConfiguration.isTuningAllowed()) { info() << "Loading remote processor library"; @@ -2609,16 +2593,16 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) } // Create server - _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler); + _pRemoteProcessorServer = + pfnCreateRemoteProcessorServer(mPfwConfiguration.getServerPort(), _pCommandHandler); - info() << "Starting remote processor server on port " - << 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; @@ -2628,53 +2612,6 @@ 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) { @@ -2684,14 +2621,14 @@ void CParameterMgr::doApplyConfigurations(bool bForce) core::Results infos; // Check subsystems that need resync - getSystemClass()->checkForSubsystemsToResync(syncerSet, infos); + mSystemClass.checkForSubsystemsToResync(syncerSet, infos); // Ensure application of currently selected configurations - getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce, infos); + 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 diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index c4e196121..9ee023b86 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -40,6 +40,10 @@ #include "XmlDocSink.h" #include "XmlDocSource.h" #include "Results.h" +#include "ParameterFrameworkConfiguration.h" +#include "SelectionCriteria.h" +#include "ConfigurableDomains.h" +#include "SystemClass.h" #include #include @@ -48,26 +52,16 @@ 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, @@ -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); @@ -663,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; };