From 5c61b128907d04b3e7f49008b4f1bfc520afdbc9 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 26 Feb 2015 15:57:00 +0100 Subject: [PATCH 01/14] 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 6045e0166ba1d66a28c0a2a90de46e7a55ea3f1c Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 2 Mar 2015 21:53:28 +0000 Subject: [PATCH 02/14] 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 d0b71bd2f..e60d91019 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 d3d2820f97a1833ffc0b8ec11d57026a61dd84ef Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 10 Mar 2015 17:15:59 +0100 Subject: [PATCH 03/14] 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 e60d91019..e29d79838 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 0a524bb4c0662086d1fc0e7c43d5819dc06a42f9 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 11:50:40 +0100 Subject: [PATCH 04/14] 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 b3ba5671cf3941a38a8d45df796bc87f19afbe62 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 12:08:55 +0100 Subject: [PATCH 05/14] 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 02626ebf999cd2ffc6b087799751dc8eaeb11d4e Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 13:22:37 +0100 Subject: [PATCH 06/14] 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 26733e5e6becfbf48147203d16e74c9b1159f89e Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 13:58:32 +0100 Subject: [PATCH 07/14] 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 b87140c04cee4af909fff4c80b6eb8f90ce00fc7 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 26 Feb 2015 16:53:45 +0100 Subject: [PATCH 08/14] 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 aaefb6c008b5ecdb4fbfb7268ff98f5db10a934f Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 13 Apr 2015 11:20:25 +0200 Subject: [PATCH 09/14] 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 67b382dde2992fe092ebab431172011a211bfc16 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Wed, 25 Feb 2015 14:12:20 +0100 Subject: [PATCH 10/14] 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 e29d79838..9306bc263 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 f0da156367419605e6ec76f91da21fc04db518a4 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 7 Apr 2015 09:50:17 +0200 Subject: [PATCH 11/14] 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 9ae0ce3747548bf188c10cbe692f6148e4d05a30 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Wed, 4 Mar 2015 17:04:48 +0100 Subject: [PATCH 12/14] 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 9f9045c4d3bacc262de58e4accb7075dd5dd66c8 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 5 Mar 2015 16:09:35 +0100 Subject: [PATCH 13/14] 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 56657e43938fe85a95298582dda638184b3c8fdb Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 2 Apr 2015 11:46:52 +0200 Subject: [PATCH 14/14] 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__":