From df01d8bae7dc2d951d8d7ed526e2d4a86d3c4d74 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 26 Feb 2015 15:57:00 +0100 Subject: [PATCH 01/30] Remove unused AutoLog header from SelectionCriterion class Signed-off-by: Jules Clero --- parameter/SelectionCriterion.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/parameter/SelectionCriterion.cpp b/parameter/SelectionCriterion.cpp index 781892401..975503b90 100644 --- a/parameter/SelectionCriterion.cpp +++ b/parameter/SelectionCriterion.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,7 +29,6 @@ */ #include "SelectionCriterion.h" -#include "AutoLog.h" #define base CElement From f2dd7678476ca143250cf0bcb8c21cc2d8123c89 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 2 Mar 2015 21:53:28 +0000 Subject: [PATCH 02/30] Move logging up to ParameterMgr Some elements are logging but ParameterMgr is able to do the same. This patch lets the ParameterMgr handle logging whenever it's possible. Signed-off-by: Jules Clero --- parameter/ConfigurableDomain.cpp | 78 +++++++++------ parameter/ConfigurableDomain.h | 62 +++++++++--- parameter/ConfigurableDomains.cpp | 62 ++++++------ parameter/ConfigurableDomains.h | 44 +++++++-- parameter/ParameterMgr.cpp | 158 +++++++++++++++++++++++++----- parameter/ParameterMgr.h | 17 +++- parameter/SystemClass.cpp | 24 ++--- parameter/SystemClass.h | 5 +- 8 files changed, 328 insertions(+), 122 deletions(-) diff --git a/parameter/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index aa9da51a6..68239e64a 100644 --- a/parameter/ConfigurableDomain.cpp +++ b/parameter/ConfigurableDomain.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -34,6 +34,7 @@ #include "XmlDomainSerializingContext.h" #include "XmlDomainImportContext.h" #include "XmlDomainExportContext.h" +#include "Utility.h" #include #define base CBinarySerializableElement @@ -104,8 +105,6 @@ void CConfigurableDomain::setSequenceAwareness(bool bSequenceAware) { if (_bSequenceAware != bSequenceAware) { - log_info("Making domain \"%s\" sequence %s", getName().c_str(), bSequenceAware ? "aware" : "unaware"); - _bSequenceAware = bSequenceAware; } } @@ -297,8 +296,10 @@ bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElemen return false; } // Add found element to domain - if (!addConfigurableElement(pConfigurableElement, NULL, strError)) { + std::list infos; + if (!addConfigurableElement(pConfigurableElement, NULL, infos)) { + CUtility::asString(infos, strError); serializingContext.setError(strError); return false; @@ -354,12 +355,16 @@ bool CConfigurableDomain::parseSettings(const CXmlElement& xmlElement, return true; } // Configurable elements association -bool CConfigurableDomain::addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError) +bool CConfigurableDomain::addConfigurableElement(CConfigurableElement* pConfigurableElement, + const CParameterBlackboard* pMainBlackboard, + std::list& infos) { // Already associated? if (containsConfigurableElement(pConfigurableElement)) { - strError = "Configurable element " + pConfigurableElement->getPath() + " already associated to configuration domain " + getName(); + infos.push_back("Configurable element " + + pConfigurableElement->getPath() + + " already associated to configuration domain " + getName()); return false; } @@ -367,13 +372,15 @@ bool CConfigurableDomain::addConfigurableElement(CConfigurableElement* pConfigur // Already owned? if (pConfigurableElement->belongsTo(this)) { - strError = "Configurable element " + pConfigurableElement->getPath() + " already owned by configuration domain " + getName(); + infos.push_back("Configurable element " + + pConfigurableElement->getPath() + + " already owned by configuration domain " + getName()); return false; } // Do add - doAddConfigurableElement(pConfigurableElement, pMainBlackboard); + doAddConfigurableElement(pConfigurableElement, infos, pMainBlackboard); return true; } @@ -387,7 +394,6 @@ bool CConfigurableDomain::removeConfigurableElement(CConfigurableElement* pConfi return false; } - log_info("Removing configurable element \"%s\" from domain \"%s\"", pConfigurableElement->getPath().c_str(), getName().c_str()); // Do remove doRemoveConfigurableElement(pConfigurableElement, true); @@ -454,23 +460,27 @@ CParameterBlackboard* CConfigurableDomain::findConfigurationBlackboard(const str } // Domain splitting -bool CConfigurableDomain::split(CConfigurableElement* pConfigurableElement, string& strError) +bool CConfigurableDomain::split(CConfigurableElement* pConfigurableElement, + std::list& infos) { // Not associated? if (!containsConfigurableElement(pConfigurableElement)) { - strError = "Configurable element " + pConfigurableElement->getPath() + " not associated to configuration domain " + getName(); + std::string strError = "Configurable element " + pConfigurableElement->getPath() + + " not associated to configuration domain " + getName(); + infos.push_back(strError); return false; } - log_info("Splitting configurable element \"%s\" domain \"%s\"", pConfigurableElement->getPath().c_str(), getName().c_str()); // Create sub domain areas for all configurable element's children size_t uiNbConfigurableElementChildren = pConfigurableElement->getNbChildren(); if (!uiNbConfigurableElementChildren) { - strError = "Configurable element " + pConfigurableElement->getPath() + " has no children to split configurable domain to"; + std::string strError = "Configurable element " + pConfigurableElement->getPath() + + " has no children to split configurable domain to"; + infos.push_back(strError); return false; } @@ -481,7 +491,7 @@ bool CConfigurableDomain::split(CConfigurableElement* pConfigurableElement, stri CConfigurableElement* pChildConfigurableElement = static_cast(pConfigurableElement->getChild(uiChild)); - doAddConfigurableElement(pChildConfigurableElement); + doAddConfigurableElement(pChildConfigurableElement, infos); } // Delegate to configurations @@ -519,7 +529,10 @@ const CDomainConfiguration* CConfigurableDomain::getPendingConfiguration() const } // Configuration application if required -void CConfigurableDomain::apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForce) const +void CConfigurableDomain::apply(CParameterBlackboard* pParameterBlackboard, + CSyncerSet* pSyncerSet, + bool bForce, + std::string& strInfo) const { // Apply configuration only if the blackboard will // be synchronized either now or by syncerSet. @@ -539,9 +552,8 @@ void CConfigurableDomain::apply(CParameterBlackboard* pParameterBlackboard, CSyn // Check not the last one before applying if (!_pLastAppliedConfiguration || _pLastAppliedConfiguration != pApplicableDomainConfiguration) { - log_info("Applying configuration \"%s\" from domain \"%s\"", - pApplicableDomainConfiguration->getName().c_str(), - getName().c_str()); + strInfo = "Applying configuration '" + pApplicableDomainConfiguration->getName() + + "' from domain '" + getName() + "'"; // Check if we need to synchronize during restore bool bSync = !pSyncerSet && _bSequenceAware; @@ -597,7 +609,6 @@ bool CConfigurableDomain::createConfiguration(const string& strName, const CPara return false; } - log_info("Creating domain configuration \"%s\" into domain \"%s\"", strName.c_str(), getName().c_str()); // Creation CDomainConfiguration* pDomainConfiguration = new CDomainConfiguration(strName); @@ -639,8 +650,6 @@ bool CConfigurableDomain::deleteConfiguration(const string& strName, string& str return false; } - log_info("Deleting configuration \"%s\" from domain \"%s\"", strName.c_str(), getName().c_str()); - // Was the last applied? if (pDomainConfiguration == _pLastAppliedConfiguration) { @@ -680,7 +689,6 @@ bool CConfigurableDomain::renameConfiguration(const string& strName, const strin return false; } - log_info("Renaming domain \"%s\"'s configuration \"%s\" to \"%s\"", getName().c_str(), strName.c_str(), strNewName.c_str()); // Rename return pDomainConfiguration->rename(strNewName, strError); @@ -697,7 +705,6 @@ bool CConfigurableDomain::restoreConfiguration(const string& strName, CParameter lstrError.push_back(strError); return false; } - log_info("Restoring domain \"%s\"'s configuration \"%s\" to parameter blackboard", getName().c_str(), pDomainConfiguration->getName().c_str()); // Delegate bool bSuccess = pDomainConfiguration->restore(pMainBlackboard, bAutoSync && _bSequenceAware, &lstrError); @@ -722,7 +729,6 @@ bool CConfigurableDomain::saveConfiguration(const string& strName, const CParame return false; } - log_info("Saving domain \"%s\"'s configuration \"%s\" from parameter blackboard", getName().c_str(), pDomainConfiguration->getName().c_str()); // Delegate pDomainConfiguration->save(pMainBlackboard); @@ -847,8 +853,6 @@ void CConfigurableDomain::validate(const CParameterBlackboard* pMainBlackboard) // Ensure validity on areas related to configurable element void CConfigurableDomain::validateAreas(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard) { - log_info("Validating domain \"" + getName() + "\" against main blackboard for configurable element \"" + pConfigurableElement->getPath() + "\""); - // Propagate size_t uiNbConfigurations = getNbChildren(); size_t uiChild; @@ -986,7 +990,9 @@ bool CConfigurableDomain::containsConfigurableElement(const CConfigurableElement } // Merge any descended configurable element to this one with this one -void CConfigurableDomain::mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* pNewConfigurableElement) +void CConfigurableDomain::mergeAlreadyAssociatedDescendantConfigurableElements( + CConfigurableElement* newElement, + std::list& infos) { std::list mergedConfigurableElementList; @@ -997,12 +1003,15 @@ void CConfigurableDomain::mergeAlreadyAssociatedDescendantConfigurableElements(C CConfigurableElement* pConfigurablePotentialDescendantElement = *it; - if (pConfigurablePotentialDescendantElement->isDescendantOf(pNewConfigurableElement)) { + if (pConfigurablePotentialDescendantElement->isDescendantOf(newElement)) { - log_info("In domain \"%s\", merging descendant configurable element's configurations \"%s\" into its ascendant \"%s\" ones", getName().c_str(), pConfigurablePotentialDescendantElement->getName().c_str(), pNewConfigurableElement->getName().c_str()); + infos.push_back("In domain '" + getName() + + "', merging descendant configurable element's configurations '" + + pConfigurablePotentialDescendantElement->getName() + + "' into its ascendant '" + newElement->getName() + "' ones"); // Merge configuration data - mergeConfigurations(pNewConfigurableElement, pConfigurablePotentialDescendantElement); + mergeConfigurations(newElement, pConfigurablePotentialDescendantElement); // Keep track for removal mergedConfigurableElementList.push_back(pConfigurablePotentialDescendantElement); @@ -1036,7 +1045,9 @@ void CConfigurableDomain::mergeConfigurations(CConfigurableElement* pToConfigura } // Configurable elements association -void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard *pMainBlackboard) +void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfigurableElement, + std::list& infos, + const CParameterBlackboard* pMainBlackboard) { // Inform configurable element pConfigurableElement->addAttachedConfigurableDomain(this); @@ -1067,12 +1078,15 @@ void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfig // Ensure area validity for that configurable element (if main blackboard provided) if (pMainBlackboard) { + infos.push_back("Validating domain '" + getName() + + "' against main blackboard for configurable element '" + + pConfigurableElement->getPath() + "'"); // Need to validate against main blackboard validateAreas(pConfigurableElement, pMainBlackboard); } // Already associated descendend configurable elements need a merge of their configuration data - mergeAlreadyAssociatedDescendantConfigurableElements(pConfigurableElement); + mergeAlreadyAssociatedDescendantConfigurableElements(pConfigurableElement, infos); // Add to list _configurableElementList.push_back(pConfigurableElement); diff --git a/parameter/ConfigurableDomain.h b/parameter/ConfigurableDomain.h index a29c1ba04..6b3a7df8b 100644 --- a/parameter/ConfigurableDomain.h +++ b/parameter/ConfigurableDomain.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -78,8 +78,17 @@ class CConfigurableDomain : public CBinarySerializableElement void gatherConfigurableElements(std::set& configurableElementSet) const; void listAssociatedToElements(std::string& strResult) const; - // Configurable elements association - bool addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, std::string& strError); + /** Add a configurable element to the domain + * + * @param[in] pConfigurableElement pointer to the element to add + * @param[in] pMainBlackboard pointer to the application main blackboard + * @param[out] infos string list containing useful information we can provide to client + * @return true if succeed false otherwise + */ + bool addConfigurableElement(CConfigurableElement* pConfigurableElement, + const CParameterBlackboard* pMainBlackboard, + std::list& infos); + bool removeConfigurableElement(CConfigurableElement* pConfigurableElement, std::string& strError); // Blackboard Configuration and Base Offset retrieval @@ -89,14 +98,29 @@ class CConfigurableDomain : public CBinarySerializableElement bool& bIsLastApplied, std::string& strError) const; - // Domain splitting - bool split(CConfigurableElement* pConfigurableElement, std::string& strError); + /** Split the domain in two. + * Remove an element of a domain and create a new domain which owns the element. + * + * @param[in] pConfigurableElement pointer to the element to remove + * @param[out] infos string list containing useful information we can provide to client + * @return true if succeed false otherwise + */ + bool split(CConfigurableElement* pConfigurableElement, std::list& strError); // Ensure validity on whole domain from main blackboard void validate(const CParameterBlackboard* pMainBlackboard); - // Configuration application if required - void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet* pSyncerSet, bool bForced) const; + /** Apply the configuration if required + * + * @param[in] pParameterBlackboard the blackboard to synchronize + * @param[in] pSyncerSet pointer to the set containing application syncers + * @param[in] bForced boolean used to force configuration application + * @param[out] info string containing useful information we can provide to client + */ + void apply(CParameterBlackboard* pParameterBlackboard, + CSyncerSet* pSyncerSet, + bool bForced, + std::string& info) const; // Return applicable configuration validity for given configurable element bool isApplicableConfigurationValid(const CConfigurableElement* pConfigurableElement) const; @@ -148,12 +172,28 @@ class CConfigurableDomain : public CBinarySerializableElement // Check configurable element already attached bool containsConfigurableElement(const CConfigurableElement* pConfigurableCandidateElement) const; - // Merge any descended configurable element to this one - void mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* pNewConfigurableElement); + /** Merge any descended configurable element to this one + * + * @param[in] newElement pointer to element which has potential descendants which can be merged + * @param[out] infos string list containing useful information we can provide to client + */ + void mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* newElement, + std::list& infos); + void mergeConfigurations(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement); - // Configurable elements association - void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard = NULL); + /** Actually realize the association between the domain and a configurable element + * + * @param[in] pConfigurableElement pointer to the element to add + * @param[out] infos useful information we can provide to client + * @param[in] (optional) pMainBlackboard, pointer to the application main blackboard + * Default value is NULL, when provided, blackboard area concerning the configurable + * element are validated. + */ + void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, + std::list& infos, + const CParameterBlackboard* pMainBlackboard = NULL); + void doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet); // XML parsing diff --git a/parameter/ConfigurableDomains.cpp b/parameter/ConfigurableDomains.cpp index 844ade754..fba332990 100644 --- a/parameter/ConfigurableDomains.cpp +++ b/parameter/ConfigurableDomains.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -32,7 +32,6 @@ #include "ConfigurableDomain.h" #include "ConfigurableElement.h" #include "BinaryStream.h" -#include "AutoLog.h" #define base CBinarySerializableElement @@ -68,10 +67,11 @@ void CConfigurableDomains::validate(const CParameterBlackboard* pMainBlackboard) } // Configuration application if required -void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet& syncerSet, bool bForce) const +void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, + CSyncerSet& syncerSet, + bool bForce, + std::list& infos) const { - CAutoLog autoLog(this, "Applying configurations"); - /// Delegate to domains // Start with domains that can be synchronized all at once (with passed syncer set) @@ -82,8 +82,13 @@ void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, CSy const CConfigurableDomain* pChildConfigurableDomain = static_cast(getChild(uiChild)); + std::string info; // Apply and collect syncers when relevant - pChildConfigurableDomain->apply(pParameterBlackboard, &syncerSet, bForce); + pChildConfigurableDomain->apply(pParameterBlackboard, &syncerSet, bForce, info); + + if (!info.empty()) { + infos.push_back(info); + } } // Synchronize those collected syncers syncerSet.sync(*pParameterBlackboard, false, NULL); @@ -93,8 +98,12 @@ void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, CSy const CConfigurableDomain* pChildConfigurableDomain = static_cast(getChild(uiChild)); + std::string info; // Apply and synchronize when relevant - pChildConfigurableDomain->apply(pParameterBlackboard, NULL, bForce); + pChildConfigurableDomain->apply(pParameterBlackboard, NULL, bForce, info); + if (!info.empty()) { + infos.push_back(info); + } } } @@ -119,8 +128,6 @@ bool CConfigurableDomains::createDomain(const string& strName, string& strError) return false; } - log_info("Creating configurable domain \"%s\"", strName.c_str()); - // Creation/Hierarchy addChild(new CConfigurableDomain(strName)); @@ -145,8 +152,6 @@ bool CConfigurableDomains::addDomain(CConfigurableDomain& domain, bool bOverwrit deleteDomain(*pExistingDomain); } - log_info("Adding configurable domain \"" + strDomainName + "\""); - addChild(&domain); return true; @@ -154,8 +159,6 @@ bool CConfigurableDomains::addDomain(CConfigurableDomain& domain, bool bOverwrit void CConfigurableDomains::deleteDomain(CConfigurableDomain& configurableDomain) { - log_info("Deleting configurable domain \"" + configurableDomain.getName() + "\""); - removeChild(&configurableDomain); delete &configurableDomain; @@ -175,8 +178,6 @@ bool CConfigurableDomains::deleteDomain(const string& strName, string& strError) void CConfigurableDomains::deleteAllDomains() { - log_info("Deleting all configurable domains"); - //remove Children clean(); } @@ -190,8 +191,6 @@ bool CConfigurableDomains::renameDomain(const string& strName, const string& str return false; } - log_info("Renaming configurable domain \"%s\" to \"%s\"", strName.c_str(), strNewName.c_str()); - // Rename return pConfigurableDomain->rename(strNewName, strError); } @@ -293,17 +292,21 @@ bool CConfigurableDomains::listDomainElements(const string& strDomain, string& s return true; } -bool CConfigurableDomains::split(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError) +bool CConfigurableDomains::split(const string& domainName, + CConfigurableElement* element, + std::list& infos) { // Find domain - CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); + std::string error; + CConfigurableDomain* domain = findConfigurableDomain(domainName, error); - if (!pConfigurableDomain) { + if (domain == NULL) { + infos.push_back(error); return false; } // Delegate - pConfigurableDomain->split(pConfigurableElement, strError); + domain->split(element, infos); return true; } @@ -510,17 +513,23 @@ void CConfigurableDomains::listLastAppliedConfigurations(string& strResult) cons } // Configurable element - domain association -bool CConfigurableDomains::addConfigurableElementToDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, string& strError) +bool +CConfigurableDomains::addConfigurableElementToDomain(const string& domainName, + CConfigurableElement* element, + const CParameterBlackboard* mainBlackboard, + std::list& infos) { // Find domain - CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); + std::string error; + CConfigurableDomain* domain = findConfigurableDomain(domainName, error); - if (!pConfigurableDomain) { + if (domain == NULL) { + infos.push_back(error); return false; } // Delegate - return pConfigurableDomain->addConfigurableElement(pConfigurableElement, pMainBlackboard, strError); + return domain->addConfigurableElement(element, mainBlackboard, infos); } bool CConfigurableDomains::removeConfigurableElementFromDomain(const string& strDomain, CConfigurableElement* pConfigurableElement, string& strError) @@ -543,9 +552,6 @@ CParameterBlackboard* CConfigurableDomains::findConfigurationBlackboard(const st bool& bIsLastApplied, string& strError) const { - log_info("Find configuration blackboard for Domain:%s, Configuration:%s, Element:%s", - strDomain.c_str(), strConfiguration.c_str(), pConfigurableElement->getPath().c_str()); - // Find domain const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); diff --git a/parameter/ConfigurableDomains.h b/parameter/ConfigurableDomains.h index 3cc16df6b..11ccfa815 100644 --- a/parameter/ConfigurableDomains.h +++ b/parameter/ConfigurableDomains.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -79,7 +79,19 @@ class CConfigurableDomains : public CBinarySerializableElement bool setSequenceAwareness(const std::string& strDomain, bool bSequenceAware, std::string& strError); bool getSequenceAwareness(const std::string& strDomain, bool& bSequenceAware, std::string& strError) const; bool listDomainElements(const std::string& strDomain, std::string& strResult) const; - bool split(const std::string& strDomain, CConfigurableElement* pConfigurableElement, std::string& strError); + + /** Split a domain in two. + * Remove an element of a domain and create a new domain which owns the element. + * + * @param[in] domainName the domain name + * @param[in] element pointer to the element to remove + * @param[out] infos string list containing useful information we can provide to client + * @return true if succeed false otherwise + */ + bool split(const std::string& domainName, + CConfigurableElement* element, + std::list& infos); + void listAssociatedElements(std::string& strResult) const; void listConflictingElements(std::string& strResult) const; void listDomains(std::string& strResult) const; @@ -99,8 +111,19 @@ class CConfigurableDomains : public CBinarySerializableElement // Last applied configurations void listLastAppliedConfigurations(std::string& strResult) const; - // Configurable element - domain association - bool addConfigurableElementToDomain(const std::string& strDomain, CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, std::string& strError); + /** Associate a configurable element to a domain + * + * @param[in] domainName the domain name + * @param[in] element pointer to the element to add + * @param[in] mainBlackboard pointer to the application main blackboard + * @param[out] infos string list containing useful information we can provide to client + * @return true if succeed false otherwise + */ + bool addConfigurableElementToDomain(const std::string& domainName, + CConfigurableElement* element, + const CParameterBlackboard* mainBlackboard, + std::list& infos); + bool removeConfigurableElementFromDomain(const std::string& strDomain, CConfigurableElement* pConfigurableElement, std::string& strError); // Configuration Blackboard for element @@ -123,8 +146,17 @@ class CConfigurableDomains : public CBinarySerializableElement // Ensure validity on whole domains from main blackboard void validate(const CParameterBlackboard* pMainBlackboard); - // Configuration application if required - void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet& syncerSet, bool bForce) const; + /** Apply the configuration if required + * + * @param[in] pParameterBlackboard the blackboard to synchronize + * @param[in] pSyncerSet pointer to the set containing application syncers + * @param[in] bForce boolean used to force configuration application + * @param[out] infos string list containing useful information we can provide to client + */ + void apply(CParameterBlackboard* pParameterBlackboard, + CSyncerSet& syncerSet, + bool bForce, + std::list& infos) const; // Class kind virtual std::string getKind() const; diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 45f1ac2d4..c612b8e8d 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -451,9 +451,7 @@ bool CParameterMgr::load(string& strError) return false; } - // Load subsystems - if (!getSystemClass()->loadSubsystems(strError, - _pSubsystemPlugins, !_bFailOnMissingSubsystem)) { + if (!loadSubsystems(strError)) { return false; } @@ -543,6 +541,28 @@ bool CParameterMgr::loadFrameworkConfiguration(string& strError) return true; } +bool CParameterMgr::loadSubsystems(std::string& error) +{ + CAutoLog autoLog(this, "Loading subsystem plugins"); + + // Load subsystems + bool isSuccess = getSystemClass()->loadSubsystems(error, + _pSubsystemPlugins, + !_bFailOnMissingSubsystem); + + if (isSuccess) { + log_info("All subsystem plugins successfully loaded"); + + if(!error.empty()) { + // Log missing subsystems as info + log_info(error); + } + } else { + log_warning(error); + } + return isSuccess; +} + bool CParameterMgr::loadStructure(string& strError) { // Retrieve system to load structure to @@ -700,8 +720,10 @@ bool CParameterMgr::importDomainFromFile(const string& strXmlFilePath, bool bOve return false; } - bSuccess = getConfigurableDomains()->addDomain(*standaloneDomain, bOverwrite, strError); - if (!bSuccess) { + CAutoLog autoLog(this, "Adding configurable domain '" + standaloneDomain->getName() + "'"); + + if (!logResult(getConfigurableDomains()->addDomain( + *standaloneDomain, bOverwrite, strError), strError)) { return false; } @@ -1768,11 +1790,26 @@ bool CParameterMgr::accessConfigurationValue(const string& strDomain, const stri uint32_t uiBaseOffset; bool bIsLastApplied; - CParameterBlackboard* pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, strConfiguration, pConfigurableElement, uiBaseOffset, bIsLastApplied, strError); - - if (!pConfigurationBlackboard) { + CParameterBlackboard* pConfigurationBlackboard = NULL; - return false; + { + CAutoLog autolog(this, + "Find configuration blackboard for Domain: " + strDomain + + ", Configuration: " + strConfiguration + + ", Element: " + pConfigurableElement->getPath()); + + pConfigurationBlackboard = + getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, + strConfiguration, + pConfigurableElement, + uiBaseOffset, + bIsLastApplied, + strError); + if (!pConfigurationBlackboard) { + + log_warning("Fail: " + strError); + return false; + } } log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset); @@ -1959,6 +1996,7 @@ bool CParameterMgr::sync(string& strError) // Configuration/Domains handling bool CParameterMgr::createDomain(const string& strName, string& strError) { + CAutoLog autoLog(this, "Creating configurable domain " + strName); // Check tuning mode if (!checkTuningModeOn(strError)) { @@ -1966,50 +2004,63 @@ bool CParameterMgr::createDomain(const string& strName, string& strError) } // Delegate to configurable domains - return getConfigurableDomains()->createDomain(strName, strError); + return logResult(getConfigurableDomains()->createDomain(strName, strError), strError); } bool CParameterMgr::deleteDomain(const string& strName, string& strError) { + CAutoLog autoLog(this, "Deleting configurable domain '" + strName + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail:" + strError); return false; } // Delegate to configurable domains - return getConfigurableDomains()->deleteDomain(strName, strError); + return logResult(getConfigurableDomains()->deleteDomain(strName, strError), strError); } bool CParameterMgr::renameDomain(const string& strName, const string& strNewName, string& strError) { + CAutoLog autoLog(this, "Renaming configurable domain '" + strName + + "' to '" + strNewName + "'"); + // Delegate to configurable domains - return getConfigurableDomains()->renameDomain(strName, strNewName, strError); + return logResult(getConfigurableDomains()->renameDomain( + strName, strNewName, strError), strError); } bool CParameterMgr::deleteAllDomains(string& strError) { + CAutoLog autoLog(this, "Deleting all configurable domains"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } // Delegate to configurable domains getConfigurableDomains()->deleteAllDomains(); + log_info("Success"); return true; } bool CParameterMgr::setSequenceAwareness(const string& strName, bool bSequenceAware, string& strResult) { + CAutoLog autoLog(this, "Making domain '" + strName + + "' sequence " + (bSequenceAware ? "aware" : "unaware")); // Check tuning mode if (!checkTuningModeOn(strResult)) { + log_warning("Fail: " + strResult); return false; } - return getConfigurableDomains()->setSequenceAwareness(strName, bSequenceAware, strResult); + return logResult(getConfigurableDomains()->setSequenceAwareness( + strName, bSequenceAware, strResult), strResult); } bool CParameterMgr::getSequenceAwareness(const string& strName, bool& bSequenceAware, @@ -2020,66 +2071,90 @@ bool CParameterMgr::getSequenceAwareness(const string& strName, bool& bSequenceA bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { + CAutoLog autoLog(this, "Creating domain configuration '" + strConfiguration + + "' into domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } // Delegate to configurable domains - return getConfigurableDomains()->createConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError); + return logResult(getConfigurableDomains()->createConfiguration( + strDomain, strConfiguration, _pMainParameterBlackboard, strError), strError); } bool CParameterMgr::renameConfiguration(const string& strDomain, const string& strConfiguration, const string& strNewConfiguration, string& strError) { - return getConfigurableDomains()->renameConfiguration(strDomain, strConfiguration, - strNewConfiguration, strError); + CAutoLog autoLog(this, "Renaming domain '" + strDomain + + "''s configuration '" + strConfiguration + "' to '" + strNewConfiguration + "'"); + + return logResult(getConfigurableDomains()->renameConfiguration( + strDomain, strConfiguration, strNewConfiguration, strError), strError); } bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { + CAutoLog autoLog(this, "Deleting configuration '" + strConfiguration + + "' from domain '" + strDomain + "'"); + // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } // Delegate to configurable domains - return getConfigurableDomains()->deleteConfiguration(strDomain, strConfiguration, strError); + return logResult(getConfigurableDomains()->deleteConfiguration( + strDomain, strConfiguration, strError), strError); } bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list& lstrError) { string strError; + CAutoLog autoLog(this, "Restoring domain '" + strDomain + + "''s configuration '" + strConfiguration + "' to parameter blackboard"); // Check tuning mode if (!checkTuningModeOn(strError)) { lstrError.push_back(strError); + log_warning("Fail: " + strError); return false; } // Delegate to configurable domains - return getConstConfigurableDomains()->restoreConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError); + return logResult(getConstConfigurableDomains()->restoreConfiguration( + strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError), + strError); } bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { + CAutoLog autoLog(this, "Saving domain '" + strDomain + + "''s configuration '" + strConfiguration + "' from parameter blackboard"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } // Delegate to configurable domains - return getConfigurableDomains()->saveConfiguration(strDomain, strConfiguration, _pMainParameterBlackboard, strError); + return logResult(getConfigurableDomains()->saveConfiguration( + strDomain, strConfiguration, _pMainParameterBlackboard, strError), strError); } // Configurable element - domain association bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) { + CAutoLog autoLog(this, "Adding configurable element '" + strConfigurableElementPath + + "to domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } @@ -2089,6 +2164,7 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { + log_warning("Fail: " + strError); return false; } @@ -2096,14 +2172,24 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - return getConfigurableDomains()->addConfigurableElementToDomain(strDomain, pConfigurableElement, _pMainParameterBlackboard, strError); + std::list infos; + bool isSuccess = getConfigurableDomains()->addConfigurableElementToDomain( + strDomain, pConfigurableElement, _pMainParameterBlackboard, infos); + + log_table(!isSuccess, infos); + + CUtility::asString(infos, strError); + return isSuccess; } bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) { + CAutoLog autoLog(this, "Removing configurable element '" + strConfigurableElementPath + + "' from domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } @@ -2113,6 +2199,7 @@ bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { + log_warning("Fail: " + strError); return false; } @@ -2120,14 +2207,18 @@ bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - return getConfigurableDomains()->removeConfigurableElementFromDomain(strDomain, pConfigurableElement, strError); + return logResult(getConfigurableDomains()->removeConfigurableElementFromDomain( + strDomain, pConfigurableElement, strError), strError); } bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError) { + CAutoLog autoLog(this, "Splitting configurable element '" + strConfigurableElementPath + + "' domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { + log_warning("Fail: " + strError); return false; } @@ -2137,6 +2228,7 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { + log_warning("Fail: " + strError); return false; } @@ -2144,7 +2236,12 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - return getConfigurableDomains()->split(strDomain, pConfigurableElement, strError); + std::list infos; + bool isSuccess = getConfigurableDomains()->split(strDomain, pConfigurableElement, infos); + + log_table(isSuccess, infos); + CUtility::asString(infos, strError); + return isSuccess; } bool CParameterMgr::setElementSequence(const string& strDomain, const string& strConfiguration, @@ -2595,13 +2692,17 @@ const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const // Apply configurations void CParameterMgr::doApplyConfigurations(bool bForce) { + CAutoLog autoLog(this, "Applying configurations"); + CSyncerSet syncerSet; + std::list infos; // Check subsystems that need resync - getSystemClass()->checkForSubsystemsToResync(syncerSet); + getSystemClass()->checkForSubsystemsToResync(syncerSet, infos); // Ensure application of currently selected configurations - getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce); + getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce, infos); + log_table(false, infos); // Reset the modified status of the current criteria to indicate that a new configuration has been applied getSelectionCriteria()->resetModifiedStatus(); @@ -2632,3 +2733,12 @@ bool CParameterMgr::exportElementToXMLString(const IXmlSource* pXmlSource, return bProcessSuccess; } + +bool CParameterMgr::logResult(bool isSuccess, const std::string& result) +{ + std::string log(isSuccess ? "Success" : "Fail" ); + log += (result.empty() ? "" : ": " + result); + (this->*(isSuccess ? &CParameterMgr::log_info : &CParameterMgr::log_warning))(log); + + return isSuccess; +} diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index ef834eb7a..491fcbd31 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -508,6 +508,13 @@ class CParameterMgr : private CElement // Framework global configuration loading bool loadFrameworkConfiguration(std::string& strError); + /** Load required subsystems + * + * @param[out] error error description if there is one + * @return true if succeed false otherwise + */ + bool loadSubsystems(std::string& error); + // System class Structure loading bool loadStructure(std::string& strError); @@ -572,6 +579,14 @@ class CParameterMgr : private CElement // Remote Processor Server connection handling bool handleRemoteProcessingInterface(std::string& strError); + /** Log the result of a function + * + * @param[in] isSuccess indicates if the previous function has succeed + * @param[in] result function provided result string + * @return isSuccess parameter + */ + bool logResult(bool isSuccess, const std::string& result); + // Tuning bool _bTuningModeIsOn; diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp index ae4f74733..d0788fa6c 100644 --- a/parameter/SystemClass.cpp +++ b/parameter/SystemClass.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -33,7 +33,6 @@ #include #include "SystemClass.h" #include "SubsystemLibrary.h" -#include "AutoLog.h" #include "VirtualSubsystem.h" #include "NamedElementBuilderTemplate.h" #include @@ -98,8 +97,6 @@ bool CSystemClass::loadSubsystems(string& strError, const CSubsystemPlugins* pSubsystemPlugins, bool bVirtualSubsystemFallback) { - CAutoLog autoLog_info(this, "Loading subsystem plugins"); - // Start clean _pSubsystemLibrary->clean(); @@ -113,18 +110,9 @@ bool CSystemClass::loadSubsystems(string& strError, list lstrError; bool bLoadPluginsSuccess = loadSubsystemsFromSharedLibraries(lstrError, pSubsystemPlugins); - if (bLoadPluginsSuccess) { - log_info("All subsystem plugins successfully loaded"); - } else { - // Log plugin as warning if no fallback available - log_table(!bVirtualSubsystemFallback, lstrError); - } - - if (!bVirtualSubsystemFallback) { - // Any problem reported is an error as there is no fallback. - // Fill strError for caller. - CUtility::asString(lstrError, strError); - } + // Fill strError for caller, he has to decide if there is a problem depending on + // bVirtualSubsystemFallback value + CUtility::asString(lstrError, strError); return bLoadPluginsSuccess || bVirtualSubsystemFallback; } @@ -277,7 +265,7 @@ const CSubsystemLibrary* CSystemClass::getSubsystemLibrary() const return _pSubsystemLibrary; } -void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet) +void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet, std::list& infos) { size_t uiNbChildren = getNbChildren(); size_t uiChild; @@ -289,7 +277,7 @@ void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet) // Collect and consume the need for a resync if (pSubsystem->needResync(true)) { - log_info("Resynchronizing subsystem: %s", pSubsystem->getName().c_str()); + infos.push_back("Resynchronizing subsystem: " + pSubsystem->getName()); // get all subsystem syncers pSubsystem->fillSyncerSet(syncerSet); } diff --git a/parameter/SystemClass.h b/parameter/SystemClass.h index dd215a6f7..bebc1a1e8 100644 --- a/parameter/SystemClass.h +++ b/parameter/SystemClass.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -63,8 +63,9 @@ class CSystemClass : public CConfigurableElement * and fill a syncer set with all syncers that need to be resynchronized * * @param[out] syncerSet The syncer set to fill + * @param[out] infos Relevant informations client may want to log */ - void checkForSubsystemsToResync(CSyncerSet& syncerSet); + void checkForSubsystemsToResync(CSyncerSet& syncerSet, std::list& infos); /** * Reset subsystems need to resync flag. From 249f3286f6c7b00348a6591128d84cac8621fb67 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 10 Mar 2015 17:15:59 +0100 Subject: [PATCH 03/30] Introduce Results type to avoid copy paste String lists are often used as containers for function results. To avoid copy paste, this patch introduces the Results type to replace std::list when relevant. Documentation has been updated on modified prototype. Signed-off-by: Jules Clero --- parameter/AreaConfiguration.cpp | 8 ++-- parameter/AreaConfiguration.h | 13 ++++-- parameter/ConfigurableDomain.cpp | 31 +++++++------- parameter/ConfigurableDomain.h | 30 ++++++++++---- parameter/ConfigurableDomains.cpp | 22 ++++++---- parameter/ConfigurableDomains.h | 31 ++++++++++---- parameter/DomainConfiguration.cpp | 8 ++-- parameter/DomainConfiguration.h | 17 ++++++-- parameter/ParameterMgr.cpp | 26 ++++++------ parameter/ParameterMgr.h | 15 +++++-- parameter/ParameterMgrFullConnector.cpp | 4 +- parameter/Results.h | 41 +++++++++++++++++++ parameter/SyncerSet.cpp | 10 +++-- parameter/SyncerSet.h | 15 ++++--- parameter/SystemClass.cpp | 24 +++++------ parameter/SystemClass.h | 11 ++--- parameter/include/ParameterMgrFullConnector.h | 17 +++++++- 17 files changed, 227 insertions(+), 96 deletions(-) create mode 100644 parameter/Results.h diff --git a/parameter/AreaConfiguration.cpp b/parameter/AreaConfiguration.cpp index b3a556ebd..32eb59d82 100644 --- a/parameter/AreaConfiguration.cpp +++ b/parameter/AreaConfiguration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -54,14 +54,16 @@ void CAreaConfiguration::save(const CParameterBlackboard* pMainBlackboard) } // Apply data to current -bool CAreaConfiguration::restore(CParameterBlackboard* pMainBlackboard, bool bSync, std::list* plstrError) const +bool CAreaConfiguration::restore(CParameterBlackboard* pMainBlackboard, + bool bSync, + core::Results* errors) const { assert(_bValid); copyTo(pMainBlackboard, _pConfigurableElement->getOffset()); // Synchronize if required - return !bSync || _pSyncerSet->sync(*pMainBlackboard, false, plstrError); + return !bSync || _pSyncerSet->sync(*pMainBlackboard, false, errors); } // Ensure validity diff --git a/parameter/AreaConfiguration.h b/parameter/AreaConfiguration.h index 3ea471860..69b1e9ad5 100644 --- a/parameter/AreaConfiguration.h +++ b/parameter/AreaConfiguration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -32,6 +32,7 @@ #include "ParameterBlackboard.h" #include "BinaryStream.h" #include "SyncerSet.h" +#include "Results.h" class CConfigurableElement; class CXmlElement; @@ -48,8 +49,14 @@ class CAreaConfiguration // Save data from current void save(const CParameterBlackboard* pMainBlackboard); - // Apply data to current - bool restore(CParameterBlackboard* pMainBlackboard, bool bSync, std::list* plstrError) const; + /** Restore the configuration area + * + * @param[in] pMainBlackboard the application main blackboard + * @param[in] bSync indicates if a synchronisation has to be done + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool restore(CParameterBlackboard* pMainBlackboard, bool bSync, core::Results* errors) const; // Ensure validity void validate(const CParameterBlackboard* pMainBlackboard); diff --git a/parameter/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index 68239e64a..359e010df 100644 --- a/parameter/ConfigurableDomain.cpp +++ b/parameter/ConfigurableDomain.cpp @@ -296,7 +296,7 @@ bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElemen return false; } // Add found element to domain - std::list infos; + core::Results infos; if (!addConfigurableElement(pConfigurableElement, NULL, infos)) { CUtility::asString(infos, strError); @@ -357,7 +357,7 @@ bool CConfigurableDomain::parseSettings(const CXmlElement& xmlElement, // Configurable elements association bool CConfigurableDomain::addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, - std::list& infos) + core::Results& infos) { // Already associated? if (containsConfigurableElement(pConfigurableElement)) { @@ -461,7 +461,7 @@ CParameterBlackboard* CConfigurableDomain::findConfigurationBlackboard(const str // Domain splitting bool CConfigurableDomain::split(CConfigurableElement* pConfigurableElement, - std::list& infos) + core::Results& infos) { // Not associated? if (!containsConfigurableElement(pConfigurableElement)) { @@ -694,28 +694,31 @@ bool CConfigurableDomain::renameConfiguration(const string& strName, const strin return pDomainConfiguration->rename(strNewName, strError); } -bool CConfigurableDomain::restoreConfiguration(const string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, std::list& lstrError) const +bool CConfigurableDomain::restoreConfiguration(const string& configurationName, + CParameterBlackboard* mainBlackboard, + bool autoSync, + core::Results& errors) const { - string strError; + string error; - const CDomainConfiguration* pDomainConfiguration = findConfiguration(strName, strError); + const CDomainConfiguration* configuration = findConfiguration(configurationName, error); - if (!pDomainConfiguration) { + if (configuration == NULL) { - lstrError.push_back(strError); + errors.push_back(error); return false; } // Delegate - bool bSuccess = pDomainConfiguration->restore(pMainBlackboard, bAutoSync && _bSequenceAware, &lstrError); + bool bSuccess = configuration->restore(mainBlackboard, autoSync && _bSequenceAware, &errors); // Record last applied configuration - _pLastAppliedConfiguration = pDomainConfiguration; + _pLastAppliedConfiguration = configuration; // Synchronize - if (bAutoSync && !_bSequenceAware) { + if (autoSync && !_bSequenceAware) { - bSuccess &= _syncerSet.sync(*pMainBlackboard, false, &lstrError); + bSuccess &= _syncerSet.sync(*mainBlackboard, false, &errors); } return bSuccess; } @@ -992,7 +995,7 @@ bool CConfigurableDomain::containsConfigurableElement(const CConfigurableElement // Merge any descended configurable element to this one with this one void CConfigurableDomain::mergeAlreadyAssociatedDescendantConfigurableElements( CConfigurableElement* newElement, - std::list& infos) + core::Results& infos) { std::list mergedConfigurableElementList; @@ -1046,7 +1049,7 @@ void CConfigurableDomain::mergeConfigurations(CConfigurableElement* pToConfigura // Configurable elements association void CConfigurableDomain::doAddConfigurableElement(CConfigurableElement* pConfigurableElement, - std::list& infos, + core::Results& infos, const CParameterBlackboard* pMainBlackboard) { // Inform configurable element diff --git a/parameter/ConfigurableDomain.h b/parameter/ConfigurableDomain.h index 6b3a7df8b..976d18b77 100644 --- a/parameter/ConfigurableDomain.h +++ b/parameter/ConfigurableDomain.h @@ -33,6 +33,7 @@ #include "XmlSerializingContext.h" #include "XmlDomainImportContext.h" #include "SyncerSet.h" +#include "Results.h" #include #include #include @@ -60,7 +61,20 @@ class CConfigurableDomain : public CBinarySerializableElement bool createConfiguration(const std::string& strName, const CParameterBlackboard* pMainBlackboard, std::string& strError); bool deleteConfiguration(const std::string& strName, std::string& strError); bool renameConfiguration(const std::string& strName, const std::string& strNewName, std::string& strError); - bool restoreConfiguration(const std::string& strName, CParameterBlackboard* pMainBlackboard, bool bAutoSync, std::list& strError) const; + + /** Restore a configuration + * + * @param[in] configurationName the configuration name + * @param[in] mainBlackboard the application main blackboard + * @param[in] autoSync boolean which indicates if auto sync mechanism is on + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool restoreConfiguration(const std::string& configurationName, + CParameterBlackboard* mainBlackboard, + bool autoSync, + core::Results& errors) const; + bool saveConfiguration(const std::string& strName, const CParameterBlackboard* pMainBlackboard, std::string& strError); bool setElementSequence(const std::string& strConfiguration, const std::vector& astrNewElementSequence, std::string& strError); bool getElementSequence(const std::string& strConfiguration, std::string& strResult) const; @@ -82,12 +96,12 @@ class CConfigurableDomain : public CBinarySerializableElement * * @param[in] pConfigurableElement pointer to the element to add * @param[in] pMainBlackboard pointer to the application main blackboard - * @param[out] infos string list containing useful information we can provide to client + * @param[out] infos useful information we can provide to client * @return true if succeed false otherwise */ bool addConfigurableElement(CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard, - std::list& infos); + core::Results& infos); bool removeConfigurableElement(CConfigurableElement* pConfigurableElement, std::string& strError); @@ -102,10 +116,10 @@ class CConfigurableDomain : public CBinarySerializableElement * Remove an element of a domain and create a new domain which owns the element. * * @param[in] pConfigurableElement pointer to the element to remove - * @param[out] infos string list containing useful information we can provide to client + * @param[out] infos useful information we can provide to client * @return true if succeed false otherwise */ - bool split(CConfigurableElement* pConfigurableElement, std::list& strError); + bool split(CConfigurableElement* pConfigurableElement, core::Results& infos); // Ensure validity on whole domain from main blackboard void validate(const CParameterBlackboard* pMainBlackboard); @@ -175,10 +189,10 @@ class CConfigurableDomain : public CBinarySerializableElement /** Merge any descended configurable element to this one * * @param[in] newElement pointer to element which has potential descendants which can be merged - * @param[out] infos string list containing useful information we can provide to client + * @param[out] infos useful information we can provide to client */ void mergeAlreadyAssociatedDescendantConfigurableElements(CConfigurableElement* newElement, - std::list& infos); + core::Results& infos); void mergeConfigurations(CConfigurableElement* pToConfigurableElement, CConfigurableElement* pFromConfigurableElement); @@ -191,7 +205,7 @@ class CConfigurableDomain : public CBinarySerializableElement * element are validated. */ void doAddConfigurableElement(CConfigurableElement* pConfigurableElement, - std::list& infos, + core::Results& infos, const CParameterBlackboard* pMainBlackboard = NULL); void doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet); diff --git a/parameter/ConfigurableDomains.cpp b/parameter/ConfigurableDomains.cpp index fba332990..42e83ae6b 100644 --- a/parameter/ConfigurableDomains.cpp +++ b/parameter/ConfigurableDomains.cpp @@ -70,7 +70,7 @@ void CConfigurableDomains::validate(const CParameterBlackboard* pMainBlackboard) void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet& syncerSet, bool bForce, - std::list& infos) const + core::Results& infos) const { /// Delegate to domains @@ -294,7 +294,7 @@ bool CConfigurableDomains::listDomainElements(const string& strDomain, string& s bool CConfigurableDomains::split(const string& domainName, CConfigurableElement* element, - std::list& infos) + core::Results& infos) { // Find domain std::string error; @@ -402,19 +402,23 @@ void CConfigurableDomains::gatherAllOwnedConfigurableElements(std::set& lstrError) const +bool CConfigurableDomains::restoreConfiguration(const string& domainName, + const string& configurationName, + CParameterBlackboard* mainBlackboard, + bool autoSync, + core::Results& errors) const { - string strError; + string error; // Find domain - const CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strDomain, strError); + const CConfigurableDomain* domain = findConfigurableDomain(domainName, error); - if (!pConfigurableDomain) { + if (domain == NULL) { - lstrError.push_back(strError); + errors.push_back(error); return false; } // Delegate - return pConfigurableDomain->restoreConfiguration(strConfiguration, pMainBlackboard, bAutoSync, lstrError); + return domain->restoreConfiguration(configurationName, mainBlackboard, autoSync, errors); } // Config save @@ -517,7 +521,7 @@ bool CConfigurableDomains::addConfigurableElementToDomain(const string& domainName, CConfigurableElement* element, const CParameterBlackboard* mainBlackboard, - std::list& infos) + core::Results& infos) { // Find domain std::string error; diff --git a/parameter/ConfigurableDomains.h b/parameter/ConfigurableDomains.h index 11ccfa815..8e31d2ae8 100644 --- a/parameter/ConfigurableDomains.h +++ b/parameter/ConfigurableDomains.h @@ -30,8 +30,8 @@ #pragma once #include "BinarySerializableElement.h" +#include "Results.h" #include -#include #include @@ -85,12 +85,12 @@ class CConfigurableDomains : public CBinarySerializableElement * * @param[in] domainName the domain name * @param[in] element pointer to the element to remove - * @param[out] infos string list containing useful information we can provide to client + * @param[out] infos useful information we can provide to client * @return true if succeed false otherwise */ bool split(const std::string& domainName, CConfigurableElement* element, - std::list& infos); + core::Results& infos); void listAssociatedElements(std::string& strResult) const; void listConflictingElements(std::string& strResult) const; @@ -100,7 +100,22 @@ class CConfigurableDomains : public CBinarySerializableElement bool createConfiguration(const std::string& strDomain, const std::string& strConfiguration, const CParameterBlackboard* pMainBlackboard, std::string& strError); bool deleteConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); bool renameConfiguration(const std::string& strDomain, const std::string& strConfigurationName, const std::string& strNewConfigurationName, std::string& strError); - bool restoreConfiguration(const std::string& strDomain, const std::string& strConfiguration, CParameterBlackboard* pMainBlackboard, bool bAutoSync, std::list& lstrError) const; + + /** Restore a configuration + * + * @param[in] strDomain the domain name + * @param[in] strConfiguration the configuration name + * @param[in] mainBlackboard the application main blackboard + * @param[in] autoSync boolean which indicates if auto sync mechanism is on + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool restoreConfiguration(const std::string& strDomain, + const std::string& strConfiguration, + CParameterBlackboard* pMainBlackboard, + bool bAutoSync, + core::Results& errors) const; + bool saveConfiguration(const std::string& strDomain, const std::string& strConfiguration, const CParameterBlackboard* pMainBlackboard, std::string& strError); bool setElementSequence(const std::string& strDomain, const std::string& strConfiguration, const std::vector& astrNewElementSequence, std::string& strError); bool getElementSequence(const std::string& strDomain, const std::string& strConfiguration, std::string& strResult) const; @@ -116,13 +131,13 @@ class CConfigurableDomains : public CBinarySerializableElement * @param[in] domainName the domain name * @param[in] element pointer to the element to add * @param[in] mainBlackboard pointer to the application main blackboard - * @param[out] infos string list containing useful information we can provide to client + * @param[out] infos useful information we can provide to client * @return true if succeed false otherwise */ bool addConfigurableElementToDomain(const std::string& domainName, CConfigurableElement* element, const CParameterBlackboard* mainBlackboard, - std::list& infos); + core::Results& infos); bool removeConfigurableElementFromDomain(const std::string& strDomain, CConfigurableElement* pConfigurableElement, std::string& strError); @@ -151,12 +166,12 @@ class CConfigurableDomains : public CBinarySerializableElement * @param[in] pParameterBlackboard the blackboard to synchronize * @param[in] pSyncerSet pointer to the set containing application syncers * @param[in] bForce boolean used to force configuration application - * @param[out] infos string list containing useful information we can provide to client + * @param[out] infos useful information we can provide to client */ void apply(CParameterBlackboard* pParameterBlackboard, CSyncerSet& syncerSet, bool bForce, - std::list& infos) const; + core::Results& infos) const; // Class kind virtual std::string getKind() const; diff --git a/parameter/DomainConfiguration.cpp b/parameter/DomainConfiguration.cpp index ebf305683..e84cbb0ca 100644 --- a/parameter/DomainConfiguration.cpp +++ b/parameter/DomainConfiguration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -374,7 +374,9 @@ void CDomainConfiguration::save(const CParameterBlackboard* pMainBlackboard) } // Apply data to current -bool CDomainConfiguration::restore(CParameterBlackboard* pMainBlackboard, bool bSync, std::list* plstrError) const +bool CDomainConfiguration::restore(CParameterBlackboard* pMainBlackboard, + bool bSync, + core::Results* errors) const { bool bSuccess = true; @@ -385,7 +387,7 @@ bool CDomainConfiguration::restore(CParameterBlackboard* pMainBlackboard, bool b const CAreaConfiguration* pAreaConfiguration = *it; - bSuccess &= pAreaConfiguration->restore(pMainBlackboard, bSync, plstrError); + bSuccess &= pAreaConfiguration->restore(pMainBlackboard, bSync, errors); } return bSuccess; diff --git a/parameter/DomainConfiguration.h b/parameter/DomainConfiguration.h index e8b41efc5..7600f3179 100644 --- a/parameter/DomainConfiguration.h +++ b/parameter/DomainConfiguration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -30,6 +30,7 @@ #pragma once #include "BinarySerializableElement.h" +#include "Results.h" #include #include @@ -69,8 +70,18 @@ class CDomainConfiguration : public CBinarySerializableElement // Save data from current void save(const CParameterBlackboard* pMainBlackboard); - // Apply data to current - bool restore(CParameterBlackboard* pMainBlackboard, bool bSync, std::list* plstrError = NULL) const; + + /** Restore the configuration + * + * @param[in] pMainBlackboard the application main blackboard + * @param[in] bSync indicates if a synchronisation has to be done + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool restore(CParameterBlackboard* pMainBlackboard, + bool bSync, + core::Results* errors = NULL) const; + // Ensure validity for configurable element area configuration void validate(const CConfigurableElement* pConfigurableElement, const CParameterBlackboard* pMainBlackboard); // Ensure validity of all area configurations diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index c612b8e8d..2138f78c8 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -1298,10 +1298,10 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCo CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { - list lstrResult; - if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), lstrResult)) { + core::Results result; + if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), result)) { //Concatenate the error list as the command result - CUtility::asString(lstrResult, strResult); + CUtility::asString(result, strResult); return CCommandHandler::EFailed; } @@ -1983,10 +1983,10 @@ bool CParameterMgr::sync(string& strError) getConstSystemClass()->fillSyncerSet(syncerSet); // Sync - list lstrError; - if (! syncerSet.sync(*_pMainParameterBlackboard, false, &lstrError)){ + core::Results error; + if (! syncerSet.sync(*_pMainParameterBlackboard, false, &error)){ - CUtility::asString(lstrError, strError); + CUtility::asString(error, strError); return false; }; @@ -2111,7 +2111,9 @@ bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& s strDomain, strConfiguration, strError), strError); } -bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& strConfiguration, list& lstrError) +bool CParameterMgr::restoreConfiguration(const string& strDomain, + const string& strConfiguration, + core::Results& errors) { string strError; CAutoLog autoLog(this, "Restoring domain '" + strDomain @@ -2119,14 +2121,14 @@ bool CParameterMgr::restoreConfiguration(const string& strDomain, const string& // Check tuning mode if (!checkTuningModeOn(strError)) { - lstrError.push_back(strError); + errors.push_back(strError); log_warning("Fail: " + strError); return false; } // Delegate to configurable domains return logResult(getConstConfigurableDomains()->restoreConfiguration( - strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, lstrError), + strDomain, strConfiguration, _pMainParameterBlackboard, _bAutoSyncOn, errors), strError); } @@ -2172,7 +2174,7 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - std::list infos; + core::Results infos; bool isSuccess = getConfigurableDomains()->addConfigurableElementToDomain( strDomain, pConfigurableElement, _pMainParameterBlackboard, infos); @@ -2236,7 +2238,7 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); // Delegate - std::list infos; + core::Results infos; bool isSuccess = getConfigurableDomains()->split(strDomain, pConfigurableElement, infos); log_table(isSuccess, infos); @@ -2696,7 +2698,7 @@ void CParameterMgr::doApplyConfigurations(bool bForce) CSyncerSet syncerSet; - std::list infos; + core::Results infos; // Check subsystems that need resync getSystemClass()->checkForSubsystemsToResync(syncerSet, infos); diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index 491fcbd31..5ced38131 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -32,7 +32,6 @@ #include #include #include -#include #include "RemoteCommandHandlerTemplate.h" #include "PathNavigator.h" #include "SelectionCriterionType.h" @@ -40,6 +39,7 @@ #include "Element.h" #include "XmlDocSink.h" #include "XmlDocSource.h" +#include "Results.h" #include @@ -253,8 +253,17 @@ class CParameterMgr : private CElement bool deleteConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); bool renameConfiguration(const std::string& strDomain, const std::string& strConfiguration, const std::string& strNewConfiguration, std::string& strError); - // Save/Restore - bool restoreConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::list& strError); + /** Restore a configuration + * + * @param[in] strDomain the domain name + * @param[in] strConfiguration the configuration name + * @param[out] errors errors encountered during restoration + * @return true if success false otherwise + */ + bool restoreConfiguration(const std::string& strDomain, + const std::string& strConfiguration, + core::Results& errors); + bool saveConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); // Configurable element - domain association diff --git a/parameter/ParameterMgrFullConnector.cpp b/parameter/ParameterMgrFullConnector.cpp index 099147580..7ab3f9188 100644 --- a/parameter/ParameterMgrFullConnector.cpp +++ b/parameter/ParameterMgrFullConnector.cpp @@ -267,9 +267,9 @@ bool CParameterMgrFullConnector::saveConfiguration(const string& strDomain, bool CParameterMgrFullConnector::restoreConfiguration(const string& strDomain, const string& strConfiguration, - std::list& lstrError) + Results& errors) { - return _pParameterMgr->restoreConfiguration(strDomain, strConfiguration, lstrError); + return _pParameterMgr->restoreConfiguration(strDomain, strConfiguration, errors); } bool CParameterMgrFullConnector::setSequenceAwareness(const string& strName, bool bSequenceAware, diff --git a/parameter/Results.h b/parameter/Results.h new file mode 100644 index 000000000..4d50cb0d5 --- /dev/null +++ b/parameter/Results.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#include +#include + +namespace core +{ + + /** String list type which can hold list of error/info */ + typedef std::list Results; + +} /** core namespace */ diff --git a/parameter/SyncerSet.cpp b/parameter/SyncerSet.cpp index 9daf2a6a8..093b2df7c 100644 --- a/parameter/SyncerSet.cpp +++ b/parameter/SyncerSet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -56,7 +56,9 @@ void CSyncerSet::clear() _syncerSet.clear(); } -bool CSyncerSet::sync(CParameterBlackboard& parameterBlackboard, bool bBack, std::list* plstrError) const +bool CSyncerSet::sync(CParameterBlackboard& parameterBlackboard, + bool bBack, + core::Results* errors) const { bool bSuccess = true; @@ -71,9 +73,9 @@ bool CSyncerSet::sync(CParameterBlackboard& parameterBlackboard, bool bBack, std if (!pSyncer->sync(parameterBlackboard, bBack, strError)) { - if (plstrError) { + if (errors != NULL) { - plstrError->push_back(strError); + errors->push_back(strError); } bSuccess = false; } diff --git a/parameter/SyncerSet.h b/parameter/SyncerSet.h index 7e37f45b1..1db42e66f 100644 --- a/parameter/SyncerSet.h +++ b/parameter/SyncerSet.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,9 +29,8 @@ */ #pragma once +#include "Results.h" #include -#include -#include class ISyncer; class CParameterBlackboard; @@ -49,8 +48,14 @@ class CSyncerSet // Clearing void clear(); - // Sync - bool sync(CParameterBlackboard& parameterBlackboard, bool bBack, std::list* plstrError) const; + /** Sync the blackboard + * + * @param parameterBlackboard blackboard associated to syncer + * @param[in] bBack indicates if we want to back synchronise or to forward synchronise + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool sync(CParameterBlackboard& parameterBlackboard, bool bBack, core::Results* errors) const; private: std::set _syncerSet; diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp index d0788fa6c..b756a9e11 100644 --- a/parameter/SystemClass.cpp +++ b/parameter/SystemClass.cpp @@ -107,17 +107,17 @@ bool CSystemClass::loadSubsystems(string& strError, _pSubsystemLibrary->enableDefaultMechanism(bVirtualSubsystemFallback); // Add subsystem defined in shared libraries - list lstrError; - bool bLoadPluginsSuccess = loadSubsystemsFromSharedLibraries(lstrError, pSubsystemPlugins); + core::Results errors; + bool bLoadPluginsSuccess = loadSubsystemsFromSharedLibraries(errors, pSubsystemPlugins); // Fill strError for caller, he has to decide if there is a problem depending on // bVirtualSubsystemFallback value - CUtility::asString(lstrError, strError); + CUtility::asString(errors, strError); return bLoadPluginsSuccess || bVirtualSubsystemFallback; } -bool CSystemClass::loadSubsystemsFromSharedLibraries(list& lstrError, +bool CSystemClass::loadSubsystemsFromSharedLibraries(core::Results& errors, const CSubsystemPlugins* pSubsystemPlugins) { // Plugin list @@ -155,7 +155,7 @@ bool CSystemClass::loadSubsystemsFromSharedLibraries(list& lstrError, // process failed to load at least one of them // Attempt to load the complete list - if (!loadPlugins(lstrPluginFiles, lstrError)) { + if (!loadPlugins(lstrPluginFiles, errors)) { // Unable to load at least one plugin break; @@ -167,7 +167,7 @@ bool CSystemClass::loadSubsystemsFromSharedLibraries(list& lstrError, string strPluginUnloaded; CUtility::asString(lstrPluginFiles, strPluginUnloaded, ", "); - lstrError.push_back("Unable to load the following plugins: " + strPluginUnloaded + "."); + errors.push_back("Unable to load the following plugins: " + strPluginUnloaded + "."); return false; } @@ -198,7 +198,7 @@ string CSystemClass::getPluginSymbol(const string& strPluginPath) } // Plugin loading -bool CSystemClass::loadPlugins(list& lstrPluginFiles, list& lstrError) +bool CSystemClass::loadPlugins(list& lstrPluginFiles, core::Results& errors) { assert(lstrPluginFiles.size()); @@ -220,9 +220,9 @@ bool CSystemClass::loadPlugins(list& lstrPluginFiles, list& lstr const char *err = dlerror(); // Failed if (err == NULL) { - lstrError.push_back("dlerror failed"); + errors.push_back("dlerror failed"); } else { - lstrError.push_back("Plugin load failed: " + string(err)); + errors.push_back("Plugin load failed: " + string(err)); } // Next plugin ++it; @@ -241,8 +241,8 @@ bool CSystemClass::loadPlugins(list& lstrPluginFiles, list& lstr if (!pfnGetSubsystemBuilder) { - lstrError.push_back("Subsystem plugin " + strPluginFileName + - " does not contain " + strPluginSymbol + " symbol."); + errors.push_back("Subsystem plugin " + strPluginFileName + + " does not contain " + strPluginSymbol + " symbol."); continue; } @@ -265,7 +265,7 @@ const CSubsystemLibrary* CSystemClass::getSubsystemLibrary() const return _pSubsystemLibrary; } -void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet, std::list& infos) +void CSystemClass::checkForSubsystemsToResync(CSyncerSet& syncerSet, core::Results& infos) { size_t uiNbChildren = getNbChildren(); size_t uiChild; diff --git a/parameter/SystemClass.h b/parameter/SystemClass.h index bebc1a1e8..886ed32c6 100644 --- a/parameter/SystemClass.h +++ b/parameter/SystemClass.h @@ -31,6 +31,7 @@ #include "ConfigurableElement.h" #include "SubsystemPlugins.h" +#include "Results.h" #include #include @@ -65,7 +66,7 @@ class CSystemClass : public CConfigurableElement * @param[out] syncerSet The syncer set to fill * @param[out] infos Relevant informations client may want to log */ - void checkForSubsystemsToResync(CSyncerSet& syncerSet, std::list& infos); + void checkForSubsystemsToResync(CSyncerSet& syncerSet, core::Results& infos); /** * Reset subsystems need to resync flag. @@ -83,12 +84,12 @@ class CSystemClass : public CConfigurableElement /** Load shared libraries subsystem plugins. * - * @param[out] lstrError is the list of error that occured during loadings. + * @param[out] errors is the list of error that occured during loadings. * @param[in] pSubsystemPlugins The plugins to load. * * @return true if all plugins have been succesfully loaded, false otherwises. */ - bool loadSubsystemsFromSharedLibraries(std::list& lstrError, + bool loadSubsystemsFromSharedLibraries(core::Results& errors, const CSubsystemPlugins* pSubsystemPlugins); // Plugin symbol computation @@ -98,13 +99,13 @@ class CSystemClass : public CConfigurableElement * * @param[in:out] lstrPluginFiles is the path list of the plugins shared libraries to load. * Successfully loaded plugins are removed from the list. - * @param[out] lstrError is the list of error that occured during loadings. + * @param[out] errors is the list of error that occured during loadings. * * @return true if at least one plugin has been succesfully loaded, false otherwise. * When false is returned, some plugins MIHGT have been loaded * but the lstrPluginFiles is accurate. */ - bool loadPlugins(std::list& lstrPluginFiles, std::list& lstrError); + bool loadPlugins(std::list& lstrPluginFiles, core::Results& errors); // Subsystem factory CSubsystemLibrary* _pSubsystemLibrary; diff --git a/parameter/include/ParameterMgrFullConnector.h b/parameter/include/ParameterMgrFullConnector.h index 31022a6db..cbed5777c 100644 --- a/parameter/include/ParameterMgrFullConnector.h +++ b/parameter/include/ParameterMgrFullConnector.h @@ -46,6 +46,10 @@ class CParameterMgrFullConnector friend class CParameterMgrLogger; public: + + /** String list type which can hold list of error/info and can be presented to client */ + typedef std::list Results; + CParameterMgrFullConnector(const std::string& strConfigurationFilePath); ~CParameterMgrFullConnector(); @@ -182,8 +186,17 @@ class CParameterMgrFullConnector bool deleteConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); bool renameConfiguration(const std::string& strDomain, const std::string& strConfiguration, const std::string& strNewConfiguration, std::string& strError); - // Save/Restore - bool restoreConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::list& strError); + /** Restore a configuration + * + * @param[in] strDomain the domain name + * @param[in] strConfiguration the configuration name + * @param[out] errors, errors encountered during restoration + * @return true if success false otherwise + */ + bool restoreConfiguration(const std::string& strDomain, + const std::string& strConfiguration, + Results& errors); + bool saveConfiguration(const std::string& strDomain, const std::string& strConfiguration, std::string& strError); // Configurable element - domain association From c58e51613663e7e73b97d0154b80d77d04511c00 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 11:50:40 +0100 Subject: [PATCH 04/30] Remove plugin load attempt log This log is meaningless, as we know subsystems we are attempting to load. We log only if there is an error. Signed-off-by: Jules Clero --- parameter/SystemClass.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp index b756a9e11..7e0c31cf1 100644 --- a/parameter/SystemClass.cpp +++ b/parameter/SystemClass.cpp @@ -210,8 +210,6 @@ bool CSystemClass::loadPlugins(list& lstrPluginFiles, core::Results& err string strPluginFileName = *it; - log_info("Attempting to load subsystem plugin path \"%s\"", strPluginFileName.c_str()); - // Load attempt void* lib_handle = dlopen(strPluginFileName.c_str(), RTLD_LAZY); From 2f66b4fdc5e562642845b35b4d85a90373106df8 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 12:08:55 +0100 Subject: [PATCH 05/30] Remove unused XmlFileIncluderElement header from ParameterMgr Signed-off-by: Jules Clero --- parameter/ParameterMgr.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 2138f78c8..2e12a96cb 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -36,7 +36,6 @@ #include "NamedElementBuilderTemplate.h" #include "KindElementBuilderTemplate.h" #include "ElementBuilderTemplate.h" -#include "XmlFileIncluderElement.h" #include "SelectionCriterionType.h" #include "SubsystemElementBuilder.h" #include "FileIncluderElementBuilder.h" @@ -50,7 +49,6 @@ #include "ParameterBlackboard.h" #include "Parameter.h" #include "ParameterAccessContext.h" -#include "XmlFileIncluderElement.h" #include "ParameterFrameworkConfiguration.h" #include "FrameworkConfigurationGroup.h" #include "PluginLocation.h" From 00a4af2b1883163842179941eabe352a88518d31 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 13:22:37 +0100 Subject: [PATCH 06/30] Remove log from XmlFileIncluderElement This log information is easy to retrieve by looking the structure file. Signed-off-by: Jules Clero --- parameter/XmlFileIncluderElement.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/parameter/XmlFileIncluderElement.cpp b/parameter/XmlFileIncluderElement.cpp index 674a33177..f2943aae0 100644 --- a/parameter/XmlFileIncluderElement.cpp +++ b/parameter/XmlFileIncluderElement.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -32,7 +32,6 @@ #include "XmlMemoryDocSink.h" #include "XmlElementSerializingContext.h" #include "ElementLibrary.h" -#include "AutoLog.h" #include #define base CKindElement @@ -61,9 +60,6 @@ bool CXmlFileIncluderElement::fromXml(const CXmlElement& xmlElement, CXmlSeriali // Instantiate parser std::string strIncludedElementType = getIncludedElementType(); { - // Open a log section titled with loading file path - CAutoLog autolog(this, "Loading " + strPath); - // Use a doc source that load data from a file std::string strPathToXsdFile = elementSerializingContext.getXmlSchemaPathFolder() + "/" + strIncludedElementType + ".xsd"; From f9ff872855787b42775485902f0eab0e9e1ca984 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 3 Mar 2015 13:58:32 +0100 Subject: [PATCH 07/30] Delegate addValuePair error logging to client The client may choose if he wants to log the error when adding a criterion. Signed-off-by: Jules Clero --- bindings/c/ParameterFramework.cpp | 5 ++-- bindings/python/pfw.i | 2 +- parameter/SelectionCriterionType.cpp | 18 +++++++++++---- parameter/SelectionCriterionType.h | 4 ++-- .../include/SelectionCriterionTypeInterface.h | 13 +++++++++-- test/test-platform/TestPlatform.cpp | 23 +++++++++++-------- 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/bindings/c/ParameterFramework.cpp b/bindings/c/ParameterFramework.cpp index efc7d9922..dcca5cc00 100644 --- a/bindings/c/ParameterFramework.cpp +++ b/bindings/c/ParameterFramework.cpp @@ -196,9 +196,10 @@ bool PfwHandler::createCriteria(const PfwCriterion criteriaArray[], size_t crite value = valueIndex; } const char * valueName = criterion.values[valueIndex]; - if(not type->addValuePair(value, valueName)) { + string error; + if(not type->addValuePair(value, valueName, error)) { return status.failure("Could not add value " + string(valueName) + - " to criterion " + criterion.name); + " to criterion " + criterion.name + ": " + error); } } // Create criterion and add it to the pfw diff --git a/bindings/python/pfw.i b/bindings/python/pfw.i index 9dbccbd8a..affae6b92 100644 --- a/bindings/python/pfw.i +++ b/bindings/python/pfw.i @@ -197,7 +197,7 @@ class ISelectionCriterionTypeInterface %} public: - virtual bool addValuePair(int iValue, const std::string& strValue) = 0; + virtual bool addValuePair(int iValue, const std::string& strValue, std::string& strError) = 0; virtual bool getNumericalValue(const std::string& strValue, int& iValue) const = 0; virtual bool getLiteralValue(int iValue, std::string& strValue) const = 0; virtual bool isTypeInclusive() const = 0; diff --git a/parameter/SelectionCriterionType.cpp b/parameter/SelectionCriterionType.cpp index ce633c6f0..ee4d6ae06 100644 --- a/parameter/SelectionCriterionType.cpp +++ b/parameter/SelectionCriterionType.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,6 +29,7 @@ */ #include "SelectionCriterionType.h" #include "Tokenizer.h" +#include #define base CElement @@ -49,12 +50,17 @@ std::string CSelectionCriterionType::getKind() const } // From ISelectionCriterionTypeInterface -bool CSelectionCriterionType::addValuePair(int iValue, const std::string& strValue) +bool CSelectionCriterionType::addValuePair( + int iValue, const std::string& strValue, std::string& strError) { // Check 1 bit set only for inclusive types if (_bInclusive && (!iValue || (iValue & (iValue - 1)))) { - log_warning("Rejecting value pair association: 0x%X - %s for Selection Criterion Type %s", iValue, strValue.c_str(), getName().c_str()); + std::ostringstream error; + error << "Rejecting value pair association: 0x" << std::hex << iValue + << " - " << strValue << " for Selection Criterion Type " + << getName(); + strError = error.str(); return false; } @@ -62,7 +68,11 @@ bool CSelectionCriterionType::addValuePair(int iValue, const std::string& strVal // Check already inserted if (_numToLitMap.find(strValue) != _numToLitMap.end()) { - log_warning("Rejecting value pair association (literal already present): 0x%X - %s for Selection Criterion Type %s", iValue, strValue.c_str(), getName().c_str()); + std::ostringstream error; + error << "Rejecting value pair association (literal already present): 0x" + << std::hex << iValue << " - " << strValue + << " for Selection Criterion Type " << getName(); + strError = error.str(); return false; } diff --git a/parameter/SelectionCriterionType.h b/parameter/SelectionCriterionType.h index ef4176a3f..c115eff03 100644 --- a/parameter/SelectionCriterionType.h +++ b/parameter/SelectionCriterionType.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -42,7 +42,7 @@ class CSelectionCriterionType : public CElement, public ISelectionCriterionTypeI CSelectionCriterionType(bool bIsInclusive); // From ISelectionCriterionTypeInterface - virtual bool addValuePair(int iValue, const std::string& strValue); + virtual bool addValuePair(int iValue, const std::string& strValue, std::string& strError); /** * Retrieve the numerical value from the std::string representation of the criterion type. * diff --git a/parameter/include/SelectionCriterionTypeInterface.h b/parameter/include/SelectionCriterionTypeInterface.h index 0b62ee46a..168842531 100644 --- a/parameter/include/SelectionCriterionTypeInterface.h +++ b/parameter/include/SelectionCriterionTypeInterface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -34,7 +34,16 @@ class ISelectionCriterionTypeInterface { public: - virtual bool addValuePair(int iValue, const std::string& strValue) = 0; + + /** + * Add a new pair [integer, litteral] which represents a criterion + * + * @param[in] iValue integer value + * @param[in] strValue litteral value + * @param[out] strError string containing error information we can provide to client + * @return true if succeed false otherwise + */ + virtual bool addValuePair(int iValue, const std::string& strValue, std::string& strError) = 0; virtual bool getNumericalValue(const std::string& strValue, int& iValue) const = 0; virtual bool getLiteralValue(int iValue, std::string& strValue) const = 0; virtual bool isTypeInclusive() const = 0; diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index 9cb45f7ff..028dfd396 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -311,9 +311,9 @@ bool CTestPlatform::createExclusiveSelectionCriterionFromStateList( const std::string& strValue = remoteCommand.getArgument(uiState + 1); - if (!pCriterionType->addValuePair(uiState, strValue)) { + if (!pCriterionType->addValuePair(uiState, strValue, strResult)) { - strResult = "Unable to add value: " + strValue; + strResult = "Unable to add value: " + strValue + ": " + strResult; return false; } @@ -351,9 +351,10 @@ bool CTestPlatform::createInclusiveSelectionCriterionFromStateList( const std::string& strValue = remoteCommand.getArgument(uiState + 1); - if (!pCriterionType->addValuePair(0x1 << uiState, strValue)) { + if (!pCriterionType->addValuePair( + 0x1 << uiState, strValue, strResult)) { - strResult = "Unable to add value: " + strValue; + strResult = "Unable to add value: " + strValue + ": " + strResult; return false; } @@ -381,9 +382,11 @@ bool CTestPlatform::createExclusiveSelectionCriterion(const string& strName, ostrValue << "State_"; ostrValue << uistate; - if (!pCriterionType->addValuePair(uistate, ostrValue.str())) { + if (!pCriterionType->addValuePair( + uistate, ostrValue.str(), strResult)) { - strResult = "Unable to add value: " + ostrValue.str(); + strResult = "Unable to add value: " + + ostrValue.str() + ": " + strResult; return false; } @@ -417,9 +420,11 @@ bool CTestPlatform::createInclusiveSelectionCriterion(const string& strName, ostrValue << "State_0x"; ostrValue << (0x1 << uiState); - if (!pCriterionType->addValuePair(0x1 << uiState, ostrValue.str())) { + if (!pCriterionType->addValuePair( + 0x1 << uiState, ostrValue.str(), strResult)) { - strResult = "Unable to add value: " + ostrValue.str(); + strResult = "Unable to add value: " + + ostrValue.str() + ": " + strResult; return false; } From 36b3b1df81390871c0292e4b6334683b68b43e5a Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 26 Feb 2015 16:53:45 +0100 Subject: [PATCH 08/30] Temporarily remove Subsystems logging ability In prevision of logging rework, this patch removes logging from plugins. Signed-off-by: Jules Clero --- parameter/SubsystemObject.cpp | 44 +-------------------- parameter/SubsystemObject.h | 5 +-- test/test-subsystem/TESTSubsystemObject.cpp | 22 ----------- 3 files changed, 2 insertions(+), 69 deletions(-) diff --git a/parameter/SubsystemObject.cpp b/parameter/SubsystemObject.cpp index 76b954907..592ec5628 100644 --- a/parameter/SubsystemObject.cpp +++ b/parameter/SubsystemObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -146,11 +146,6 @@ bool CSubsystemObject::sync(CParameterBlackboard& parameterBlackboard, bool bBac // Synchronize to/from HW if (!bIsSubsystemAlive || !accessHW(bBack, strError)) { - strError = string("Unable to ") + (bBack ? "back" : "forward") + " synchronize configurable element " + - _pInstanceConfigurableElement->getPath() + ": " + strError; - - log_warning(strError); - // Fall back to parameter default initialization if (bBack) { @@ -212,43 +207,6 @@ void CSubsystemObject::blackboardWrite(const void* pvData, uint32_t uiSize) _uiAccessedIndex += uiSize; } -// Logging -void CSubsystemObject::log_info(const string& strMessage, ...) const -{ - char *pacBuffer; - va_list listPointer; - - va_start(listPointer, strMessage); - - vasprintf(&pacBuffer, strMessage.c_str(), listPointer); - - va_end(listPointer); - - if (pacBuffer != NULL) { - _pInstanceConfigurableElement->log_info(pacBuffer); - } - - free(pacBuffer); -} - -void CSubsystemObject::log_warning(const string& strMessage, ...) const -{ - char *pacBuffer; - va_list listPointer; - - va_start(listPointer, strMessage); - - vasprintf(&pacBuffer, strMessage.c_str(), listPointer); - - va_end(listPointer); - - if (pacBuffer != NULL) { - _pInstanceConfigurableElement->log_warning(pacBuffer); - } - - free(pacBuffer); -} - // Configurable element retrieval const CInstanceConfigurableElement* CSubsystemObject::getConfigurableElement() const { diff --git a/parameter/SubsystemObject.h b/parameter/SubsystemObject.h index ab085bc02..e4ccd19b4 100644 --- a/parameter/SubsystemObject.h +++ b/parameter/SubsystemObject.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -82,9 +82,6 @@ class CSubsystemObject : private ISyncer // Blackboard access from subsystems void blackboardRead(void* pvData, uint32_t uiSize); void blackboardWrite(const void* pvData, uint32_t uiSize); - // Logging - void log_info(const std::string& strMessage, ...) const; - void log_warning(const std::string& strMessage, ...) const; // Belonging Subsystem retrieval const CSubsystem* getSubsystem() const; diff --git a/test/test-subsystem/TESTSubsystemObject.cpp b/test/test-subsystem/TESTSubsystemObject.cpp index 706053fed..d17be0bfb 100644 --- a/test/test-subsystem/TESTSubsystemObject.cpp +++ b/test/test-subsystem/TESTSubsystemObject.cpp @@ -105,17 +105,6 @@ void CTESTSubsystemObject::sendToFile(std::ofstream& outputFile) std::string strValue = toString(pvValue, _uiScalarSize); outputFile << strValue << std::endl; - - if (_bLog) { - - if (_bIsScalar) { - - log_info("TESTSUBSYSTEM: Writing \"%s\" to file %s", strValue.c_str(), _strFilePath.c_str()); - } else { - - log_info("TESTSUBSYSTEM: Writing \"%s\" to file %s[%d]", strValue.c_str(), _strFilePath.c_str(), uiIndex); - } - } } } @@ -131,17 +120,6 @@ void CTESTSubsystemObject::receiveFromFile(std::ifstream& inputFile) inputFile >> strValue; - if (_bLog) { - - if (_bIsScalar) { - - log_info("TESTSUBSYSTEM: Writing \"%s\" from file %s", strValue.c_str(), _strFilePath.c_str()); - } else { - - log_info("TESTSUBSYSTEM: Writing \"%s\" from file %s[%d]", strValue.c_str(), _strFilePath.c_str(), uiIndex); - } - } - fromString(strValue, pvValue, _uiScalarSize); // Write Value in Blackboard From 5f56c58df21a1d2af503bdd4679b7a2bab4f7f0a Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 13 Apr 2015 11:20:25 +0200 Subject: [PATCH 09/30] Change Criterion modifications counter type uint8_t type seems to be buggy when we try to log it through stream API. This patch uses uint32_t type instead to count criterion modifications. Signed-off-by: Jules Clero --- parameter/SelectionCriterion.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/parameter/SelectionCriterion.h b/parameter/SelectionCriterion.h index cf9903502..86c96836b 100644 --- a/parameter/SelectionCriterion.h +++ b/parameter/SelectionCriterion.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -77,7 +77,8 @@ class CSelectionCriterion : public CElement, public ISelectionCriterionInterface int _iState; // Type const CSelectionCriterionType* _pType; - // Counter to know how many modifications have been applied to this criterion - uint8_t _uiNbModifications; + + /** Counter to know how many modifications have been applied to this criterion */ + uint32_t _uiNbModifications; }; From 1554cfef2e4e62e9efc76f6eae180b2239a173ca Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Wed, 25 Feb 2015 14:12:20 +0100 Subject: [PATCH 10/30] Rework project log Logs were provided by Element god class. This patch moves logging in the log library which is used by the ParameterMgr. Logs remains almost identical from before. Context title after context closing bracket has been removed to enhance readability. Change-Id: Ic7dca65c3cc88eb06a1883c4fb01af9809b19e42 Signed-off-by: Jules Clero --- bindings/c/ParameterFramework.cpp | 17 +- bindings/c/Test.cpp | 11 + bindings/python/pfw.i | 3 +- parameter/Android.mk | 9 +- parameter/CMakeLists.txt | 9 +- parameter/Element.cpp | 87 +------ parameter/Element.h | 15 +- parameter/ParameterMgr.cpp | 244 +++++++++--------- parameter/ParameterMgr.h | 32 +-- parameter/ParameterMgrFullConnector.cpp | 18 +- parameter/ParameterMgrLogger.h | 15 +- parameter/ParameterMgrPlatformConnector.cpp | 21 +- parameter/SelectionCriteria.cpp | 7 +- parameter/SelectionCriteria.h | 7 +- parameter/SelectionCriteriaDefinition.cpp | 7 +- parameter/SelectionCriteriaDefinition.h | 7 +- parameter/SelectionCriterion.cpp | 15 +- parameter/SelectionCriterion.h | 8 +- parameter/include/ParameterMgrFullConnector.h | 11 +- .../include/ParameterMgrPlatformConnector.h | 12 +- .../include/log/Context.h} | 58 +++-- .../{AutoLog.h => log/include/log/ILogger.h} | 30 +-- parameter/log/include/log/LogWrapper.h | 137 ++++++++++ parameter/log/include/log/Logger.h | 86 ++++++ test/test-fixed-point-parameter/Main.py | 8 +- test/test-platform/TestPlatform.cpp | 14 +- utility/CMakeLists.txt | 4 + 27 files changed, 557 insertions(+), 335 deletions(-) rename parameter/{AutoLog.cpp => log/include/log/Context.h} (64%) rename parameter/{AutoLog.h => log/include/log/ILogger.h} (80%) create mode 100644 parameter/log/include/log/LogWrapper.h create mode 100644 parameter/log/include/log/Logger.h diff --git a/bindings/c/ParameterFramework.cpp b/bindings/c/ParameterFramework.cpp index dcca5cc00..652ae837e 100644 --- a/bindings/c/ParameterFramework.cpp +++ b/bindings/c/ParameterFramework.cpp @@ -105,15 +105,24 @@ class LogWrapper : public CParameterMgrPlatformConnector::ILogger LogWrapper() : mLogger() {} virtual ~LogWrapper() {} private: - virtual void log(bool bIsWarning, const string &strLog) + virtual void info(const string &msg) + { + log(pfwLogInfo, msg); + } + + virtual void warning(const string &msg) + { + log(pfwLogWarning, msg); + } + + void log(PfwLogLevel level, const string &strLog) { // A LogWrapper should NOT be register to the pfw (thus log called) // if logCb is NULL. assert(mLogger.logCb != NULL); - mLogger.logCb(mLogger.userCtx, - bIsWarning ? pfwLogWarning : pfwLogInfo, - strLog.c_str()); + mLogger.logCb(mLogger.userCtx, level, strLog.c_str()); } + PfwLogger mLogger; }; diff --git a/bindings/c/Test.cpp b/bindings/c/Test.cpp index c450e60cb..1002c7f99 100644 --- a/bindings/c/Test.cpp +++ b/bindings/c/Test.cpp @@ -329,6 +329,17 @@ TEST_CASE_METHOD(Test, "Parameter-framework c api use") { REQUIRE(value == 3); } } + WHEN("Set a new value to a criterion without committing first") { + const char *criterionName = criteria[0].name; + REQUIRE_SUCCESS(pfwSetCriterion(pfw, criterionName, 0)); + THEN("A warning message should have been displayed") { + INFO("Previous pfw log: \n" + logLines); + size_t logPos = logLines.find("Warning: Selection criterion " + "'inclusiveCrit' has been modified 1 time(s)" + " without any configuration application"); + CHECK(logPos != std::string::npos); + } + } } WHEN("Commit criteria without a pfw") { REQUIRE(not pfwApplyConfigurations(NULL)); diff --git a/bindings/python/pfw.i b/bindings/python/pfw.i index affae6b92..f5fd75316 100644 --- a/bindings/python/pfw.i +++ b/bindings/python/pfw.i @@ -182,7 +182,8 @@ public: class ILogger { public: - virtual void log(bool bIsWarning, const std::string& strLog) = 0; + virtual void info(const std::string& log) = 0; + virtual void warning(const std::string& log) = 0; protected: virtual ~ILogger() {} }; diff --git a/parameter/Android.mk b/parameter/Android.mk index 90e33f09b..22f7b2b21 100644 --- a/parameter/Android.mk +++ b/parameter/Android.mk @@ -1,4 +1,4 @@ -# Copyright (c) 2011-2014, Intel Corporation +# Copyright (c) 2011-2015, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -44,7 +44,6 @@ common_copy_headers := \ common_src_files := \ AreaConfiguration.cpp \ ArrayParameter.cpp \ - AutoLog.cpp \ BaseParameter.cpp \ BinarySerializableElement.cpp \ BinaryStream.cpp \ @@ -129,6 +128,7 @@ common_cflags := \ common_c_includes := \ $(LOCAL_PATH)/include/ \ + $(LOCAL_PATH)/log/include/ \ $(LOCAL_PATH)/../utility/ \ $(LOCAL_PATH)/../xmlserializer/ \ $(LOCAL_PATH)/../remote-processor/ @@ -197,7 +197,10 @@ include $(CLEAR_VARS) LOCAL_MODULE := $(common_module)_includes LOCAL_MODULE_OWNER := intel -LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) +LOCAL_EXPORT_C_INCLUDE_DIRS := \ + $(LOCAL_PATH) \ + $(LOCAL_PATH)/log/include + LOCAL_STATIC_LIBRARIES := \ libxmlserializer \ diff --git a/parameter/CMakeLists.txt b/parameter/CMakeLists.txt index 94369fb74..d5b65219f 100644 --- a/parameter/CMakeLists.txt +++ b/parameter/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2014, Intel Corporation +# Copyright (c) 2014-2015, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -29,7 +29,6 @@ add_library(parameter SHARED AreaConfiguration.cpp ArrayParameter.cpp - AutoLog.cpp BaseParameter.cpp BinarySerializableElement.cpp BinaryStream.cpp @@ -107,7 +106,8 @@ include_directories( include "${PROJECT_SOURCE_DIR}/xmlserializer" "${PROJECT_SOURCE_DIR}/utility" - "${PROJECT_SOURCE_DIR}/remote-processor") + "${PROJECT_SOURCE_DIR}/remote-processor" + "${PROJECT_SOURCE_DIR}/parameter/log/include") # No need to link with libremote-processor: it is accessed via dlopen() find_library(dl dl) @@ -125,7 +125,6 @@ install(FILES DESTINATION "include/parameter/client") # Core (plugin) headers install(FILES - AutoLog.h BitParameterBlockType.h ConfigurableElement.h ConfigurableElementWithMapping.h @@ -151,3 +150,5 @@ install(FILES TypeElement.h VirtualSubsystem.h DESTINATION "include/parameter/plugin") +install(DIRECTORY log/include/log/ + DESTINATION "include/parameter/plugin/log") diff --git a/parameter/Element.cpp b/parameter/Element.cpp index cacf49b6c..eb8e6d519 100644 --- a/parameter/Element.cpp +++ b/parameter/Element.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -48,81 +48,6 @@ CElement::~CElement() removeChildren(); } -// Logging -void CElement::log_info(const string& strMessage, ...) const -{ - char *pacBuffer; - va_list listPointer; - - va_start(listPointer, strMessage); - - vasprintf(&pacBuffer, strMessage.c_str(), listPointer); - - va_end(listPointer); - - if (pacBuffer != NULL) { - doLog(false, pacBuffer); - } - - free(pacBuffer); -} - -void CElement::log_warning(const string& strMessage, ...) const -{ - char *pacBuffer; - va_list listPointer; - - va_start(listPointer, strMessage); - - vasprintf(&pacBuffer, strMessage.c_str(), listPointer); - - va_end(listPointer); - - if (pacBuffer != NULL) { - doLog(true, pacBuffer); - } - - free(pacBuffer); -} - -// Log each element of the string list -void CElement::log_table(bool bIsWarning, const std::list lstrMessage) const -{ - std::list::const_iterator iterator(lstrMessage.begin()); - std::list::const_iterator end(lstrMessage.end()); - - while (iterator != end) { - // Log current list element - doLog(bIsWarning, iterator->c_str()); - ++iterator; - } -} - -void CElement::doLog(bool bIsWarning, const string& strLog) const -{ - assert(_pParent); - - // Propagate till root - _pParent->doLog(bIsWarning, strLog); -} - -void CElement::nestLog() const -{ - assert(_pParent); - - // Propagate till root - _pParent->nestLog(); -} - -void CElement::unnestLog() const -{ - assert(_pParent); - - // Propagate till root - _pParent->unnestLog(); -} - - void CElement::setDescription(const string& strDescription) { _strDescription = strDescription; @@ -674,16 +599,6 @@ string CElement::getQualifiedPath() const return getPath() + " [" + getKind() + "]"; } -uint32_t CElement::getDepth() const -{ - if (_pParent) { - - return _pParent->getDepth() + 1; - } - - return 0; -} - // Checksum for integrity checks uint8_t CElement::computeStructureChecksum() const { diff --git a/parameter/Element.h b/parameter/Element.h index 8423e32be..b3fe4bed4 100644 --- a/parameter/Element.h +++ b/parameter/Element.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -32,7 +32,6 @@ #include #include #include -#include #include "XmlSink.h" #include "XmlSource.h" @@ -43,16 +42,10 @@ class CErrorContext; class CElement : public IXmlSink, public IXmlSource { - friend class CAutoLog; public: CElement(const std::string& strName = ""); virtual ~CElement(); - // Logging - void log_info(const std::string& strMessage, ...) const; - void log_warning(const std::string& strMessage, ...) const; - void log_table(bool bIsWarning, const std::list lstrMessage) const; - // Description void setDescription(const std::string& strDescription); const std::string& getDescription() const; @@ -165,18 +158,12 @@ class CElement : public IXmlSink, public IXmlSource CXmlSerializingContext& elementSerializingContext); private: - // Logging (done by root) - virtual void doLog(bool bIsWarning, const std::string& strLog) const; - virtual void nestLog() const; - virtual void unnestLog() const; // Returns Name or Kind if no Name std::string getPathName() const; // Returns true if children dynamic creation is to be dealt with virtual bool childrenAreDynamic() const; // House keeping void removeChildren(); - // For logging - uint32_t getDepth() const; // Fill XmlElement during XML composing void setXmlNameAttribute(CXmlElement& xmlElement) const; diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 2e12a96cb..4a6431cb5 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -66,7 +66,6 @@ #include "EnumParameterType.h" #include "RemoteProcessorServerInterface.h" #include "ElementLocator.h" -#include "AutoLog.h" #include "CompoundRule.h" #include "SelectionCriterionRule.h" #include "SimulatedBackSynchronizer.h" @@ -91,10 +90,20 @@ #include #include #include -#include #define base CElement +/** Private macro helper to declare a new context + * + * Context declaration always need logger and logging prefix to be + * passed as parameters. + * This macro aims to avoid this boring notation. + * This macro should be called only once in a scope. Nested scopes can + * call this macro too, as variable shadowing is supported. + */ +#define LOG_CONTEXT(contextTitle) \ + core::log::Context context(_logger, contextTitle) + #ifdef SIMULATION // In simulation, back synchronization of the blackboard won't probably work // We need to ensure though the blackboard is initialized with valid data @@ -109,6 +118,9 @@ using std::list; using std::vector; using std::ostringstream; +// FIXME: integrate ParameterMgr to core namespace +using namespace core; + // Used for remote processor server creation typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler); @@ -302,7 +314,7 @@ const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandPa // Remote command parsers array Size const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]); -CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) : +CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogger& logger) : _bTuningModeIsOn(false), _bValueSpaceIsRaw(false), _bOutputRawFormatIsHex(false), @@ -315,8 +327,7 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath) : _uiStructureChecksum(0), _pRemoteProcessorServer(NULL), _uiMaxCommandUsageLength(0), - _pLogger(NULL), - _uiLogDepth(0), + _logger(logger), _bForceNoRemoteInterface(false), _bFailOnMissingSubsystem(true), _bFailOnFailedSettingsLoad(true), @@ -385,43 +396,6 @@ string CParameterMgr::getKind() const return "ParameterMgr"; } -// Logging -void CParameterMgr::setLogger(CParameterMgr::ILogger* pLogger) -{ - _pLogger = pLogger; -} - -// Logging -void CParameterMgr::doLog(bool bIsWarning, const string& strLog) const -{ - if (_pLogger) { - - // Nest - string strIndent; - - // Level - uint32_t uiNbIndents = _uiLogDepth; - - while (uiNbIndents--) { - - strIndent += " "; - } - - // Log - _pLogger->log(bIsWarning, strIndent + strLog); - } -} - -void CParameterMgr::nestLog() const -{ - _uiLogDepth++; -} - -void CParameterMgr::unnestLog() const -{ - _uiLogDepth--; -} - // Version string CParameterMgr::getVersion() const { @@ -439,7 +413,7 @@ string CParameterMgr::getVersion() const bool CParameterMgr::load(string& strError) { - CAutoLog autoLog(this, "Loading"); + LOG_CONTEXT("Loading"); feedElementLibraries(); @@ -474,7 +448,7 @@ bool CParameterMgr::load(string& strError) { - CAutoLog autoLog(this, "Main blackboard back synchronization"); + LOG_CONTEXT("Main blackboard back synchronization"); // Back synchronization for areas in parameter blackboard not covered by any domain BackSynchronizer(getConstSystemClass(), _pMainParameterBlackboard).sync(); @@ -488,14 +462,14 @@ bool CParameterMgr::load(string& strError) // Log selection criterion states { - CAutoLog autoLog(this, "Criterion states"); + LOG_CONTEXT("Criterion states"); const CSelectionCriteria* selectionCriteria = getConstSelectionCriteria(); - list lstrSelectionCriteron; - selectionCriteria->listSelectionCriteria(lstrSelectionCriteron, true, false); + list criteria; + selectionCriteria->listSelectionCriteria(criteria, true, false); - log_table(false, lstrSelectionCriteron); + info() << criteria; } // Subsystem can not ask for resync as they have not been synced yet @@ -510,7 +484,7 @@ bool CParameterMgr::load(string& strError) bool CParameterMgr::loadFrameworkConfiguration(string& strError) { - CAutoLog autoLog(this, "Loading framework configuration"); + LOG_CONTEXT("Loading framework configuration"); // Parse Structure XML file CXmlElementSerializingContext elementSerializingContext(strError); @@ -534,14 +508,15 @@ bool CParameterMgr::loadFrameworkConfiguration(string& strError) } // Log tuning availability - log_info("Tuning %s", getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited"); + info() << "Tuning " + << (getConstFrameworkConfiguration()->isTuningAllowed() ? "allowed" : "prohibited"); return true; } bool CParameterMgr::loadSubsystems(std::string& error) { - CAutoLog autoLog(this, "Loading subsystem plugins"); + LOG_CONTEXT("Loading subsystem plugins"); // Load subsystems bool isSuccess = getSystemClass()->loadSubsystems(error, @@ -549,14 +524,14 @@ bool CParameterMgr::loadSubsystems(std::string& error) !_bFailOnMissingSubsystem); if (isSuccess) { - log_info("All subsystem plugins successfully loaded"); + info() << "All subsystem plugins successfully loaded"; if(!error.empty()) { // Log missing subsystems as info - log_info(error); + info() << error; } } else { - log_warning(error); + warning() << error; } return isSuccess; } @@ -566,7 +541,7 @@ bool CParameterMgr::loadStructure(string& strError) // Retrieve system to load structure to CSystemClass* pSystemClass = getSystemClass(); - log_info("Loading " + pSystemClass->getName() + " system class structure"); + LOG_CONTEXT("Loading " + pSystemClass->getName() + " system class structure"); // Get structure description element const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = static_cast(getConstFrameworkConfiguration()->findChildOfKind("StructureDescriptionFileLocation")); @@ -587,11 +562,13 @@ bool CParameterMgr::loadStructure(string& strError) // Parse Structure XML file CXmlParameterSerializingContext parameterBuildContext(strError); - CAutoLog autolog(pSystemClass, "Importing system structure from file " + strXmlStructureFilePath); + { + LOG_CONTEXT("Importing system structure from file " + strXmlStructureFilePath); - if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) { + if (!xmlParse(parameterBuildContext, pSystemClass, strXmlStructureFilePath, strXmlStructureFolder, EParameterCreationLibrary)) { - return false; + return false; + } } // Initialize offsets @@ -610,8 +587,8 @@ bool CParameterMgr::loadSettings(string& strError) if (!success && !_bFailOnFailedSettingsLoad) { // Load can not fail, ie continue but log the load errors - log_info(strLoadError); - log_info("Failed to load settings, continue without domains."); + info() << strLoadError; + info() << "Failed to load settings, continue without domains."; success = true; } @@ -626,7 +603,7 @@ bool CParameterMgr::loadSettings(string& strError) bool CParameterMgr::loadSettingsFromConfigFile(string& strError) { - CAutoLog autoLog(this, "Loading settings"); + LOG_CONTEXT("Loading settings"); // Get settings configuration element const CFrameworkConfigurationGroup* pParameterConfigurationGroup = static_cast(getConstFrameworkConfiguration()->findChildOfKind("SettingsConfiguration")); @@ -676,7 +653,8 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) // Auto validation of configurations if no binary settings provided xmlDomainImportContext.setAutoValidationRequired(!pBinarySettingsFileLocation); - log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with"); + info() << "Importing configurable domains from file " << strXmlConfigurationDomainsFilePath + << " " << ( pBinarySettingsFileLocation ? "without" : "with") << " settings"; // Do parse if (!xmlParse(xmlDomainImportContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) { @@ -718,7 +696,7 @@ bool CParameterMgr::importDomainFromFile(const string& strXmlFilePath, bool bOve return false; } - CAutoLog autoLog(this, "Adding configurable domain '" + standaloneDomain->getName() + "'"); + LOG_CONTEXT("Adding configurable domain '" + standaloneDomain->getName() + "'"); if (!logResult(getConfigurableDomains()->addDomain( *standaloneDomain, bOverwrite, strError), strError)) { @@ -784,7 +762,9 @@ CSelectionCriterionType* CParameterMgr::createSelectionCriterionType(bool bIsInc CSelectionCriterion* CParameterMgr::createSelectionCriterion(const string& strName, const CSelectionCriterionType* pSelectionCriterionType) { // Propagate - return getSelectionCriteria()->createSelectionCriterion(strName, pSelectionCriterionType); + return getSelectionCriteria()->createSelectionCriterion(strName, + pSelectionCriterionType, + _logger); } // Selection criterion retrieval @@ -797,7 +777,7 @@ CSelectionCriterion* CParameterMgr::getSelectionCriterion(const string& strName) // Configuration application void CParameterMgr::applyConfigurations() { - CAutoLog autoLog(this, "Configuration application request"); + LOG_CONTEXT("Configuration application request"); // Lock state CAutoLock autoLock(&_blackboardMutex); @@ -808,7 +788,7 @@ void CParameterMgr::applyConfigurations() doApplyConfigurations(false); } else { - log_warning("Configurations were not applied because the TuningMode is on"); + warning() << "Configurations were not applied because the TuningMode is on"; } } @@ -1791,10 +1771,9 @@ bool CParameterMgr::accessConfigurationValue(const string& strDomain, const stri CParameterBlackboard* pConfigurationBlackboard = NULL; { - CAutoLog autolog(this, - "Find configuration blackboard for Domain: " + strDomain - + ", Configuration: " + strConfiguration - + ", Element: " + pConfigurableElement->getPath()); + LOG_CONTEXT("Find configuration blackboard for Domain: " + strDomain + + ", Configuration: " + strConfiguration + + ", Element: " + pConfigurableElement->getPath()); pConfigurationBlackboard = getConstConfigurableDomains()->findConfigurationBlackboard(strDomain, @@ -1805,12 +1784,13 @@ bool CParameterMgr::accessConfigurationValue(const string& strDomain, const stri strError); if (!pConfigurationBlackboard) { - log_warning("Fail: " + strError); + warning() << "Fail: " << strError; return false; } } - log_info("Element %s in Domain %s, offset: %d, base offset: %d", strPath.c_str(), strDomain.c_str(), pConfigurableElement->getOffset(), uiBaseOffset); + info() << "Element " << strPath << " in Domain " << strDomain << ", offset: " + << pConfigurableElement->getOffset() << ", base offset: " << uiBaseOffset; /// Update the Configuration Blackboard @@ -1994,7 +1974,7 @@ bool CParameterMgr::sync(string& strError) // Configuration/Domains handling bool CParameterMgr::createDomain(const string& strName, string& strError) { - CAutoLog autoLog(this, "Creating configurable domain " + strName); + LOG_CONTEXT("Creating configurable domain " + strName); // Check tuning mode if (!checkTuningModeOn(strError)) { @@ -2007,11 +1987,12 @@ bool CParameterMgr::createDomain(const string& strName, string& strError) bool CParameterMgr::deleteDomain(const string& strName, string& strError) { - CAutoLog autoLog(this, "Deleting configurable domain '" + strName + "'"); + LOG_CONTEXT("Deleting configurable domain '" + strName + "'"); + // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail:" + strError); + warning() << "Fail: " << strError; return false; } @@ -2021,8 +2002,7 @@ bool CParameterMgr::deleteDomain(const string& strName, string& strError) bool CParameterMgr::renameDomain(const string& strName, const string& strNewName, string& strError) { - CAutoLog autoLog(this, "Renaming configurable domain '" + strName - + "' to '" + strNewName + "'"); + LOG_CONTEXT("Renaming configurable domain '" + strName + "' to '" + strNewName + "'"); // Delegate to configurable domains return logResult(getConfigurableDomains()->renameDomain( @@ -2031,29 +2011,30 @@ bool CParameterMgr::renameDomain(const string& strName, const string& strNewName bool CParameterMgr::deleteAllDomains(string& strError) { - CAutoLog autoLog(this, "Deleting all configurable domains"); + LOG_CONTEXT("Deleting all configurable domains"); + // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail: " << strError; return false; } // Delegate to configurable domains getConfigurableDomains()->deleteAllDomains(); - log_info("Success"); + info() << "Success"; return true; } bool CParameterMgr::setSequenceAwareness(const string& strName, bool bSequenceAware, string& strResult) { - CAutoLog autoLog(this, "Making domain '" + strName - + "' sequence " + (bSequenceAware ? "aware" : "unaware")); + LOG_CONTEXT("Making domain '" + strName + + "' sequence " + (bSequenceAware ? "aware" : "unaware")); // Check tuning mode if (!checkTuningModeOn(strResult)) { - log_warning("Fail: " + strResult); + warning() << "Fail: " << strResult; return false; } @@ -2069,12 +2050,12 @@ bool CParameterMgr::getSequenceAwareness(const string& strName, bool& bSequenceA bool CParameterMgr::createConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { - CAutoLog autoLog(this, "Creating domain configuration '" + strConfiguration - + "' into domain '" + strDomain + "'"); + LOG_CONTEXT("Creating domain configuration '" + strConfiguration + + "' into domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail: " << strError; return false; } @@ -2085,8 +2066,8 @@ bool CParameterMgr::createConfiguration(const string& strDomain, const string& s bool CParameterMgr::renameConfiguration(const string& strDomain, const string& strConfiguration, const string& strNewConfiguration, string& strError) { - CAutoLog autoLog(this, "Renaming domain '" + strDomain - + "''s configuration '" + strConfiguration + "' to '" + strNewConfiguration + "'"); + LOG_CONTEXT("Renaming domain '" + strDomain + "''s configuration '" + + strConfiguration + "' to '" + strNewConfiguration + "'"); return logResult(getConfigurableDomains()->renameConfiguration( strDomain, strConfiguration, strNewConfiguration, strError), strError); @@ -2094,13 +2075,13 @@ bool CParameterMgr::renameConfiguration(const string& strDomain, const string& s bool CParameterMgr::deleteConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { - CAutoLog autoLog(this, "Deleting configuration '" + strConfiguration - + "' from domain '" + strDomain + "'"); + LOG_CONTEXT("Deleting configuration '" + strConfiguration + + "' from domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2114,13 +2095,13 @@ bool CParameterMgr::restoreConfiguration(const string& strDomain, core::Results& errors) { string strError; - CAutoLog autoLog(this, "Restoring domain '" + strDomain - + "''s configuration '" + strConfiguration + "' to parameter blackboard"); + LOG_CONTEXT("Restoring domain '" + strDomain + "''s configuration '" + + strConfiguration + "' to parameter blackboard"); // Check tuning mode if (!checkTuningModeOn(strError)) { errors.push_back(strError); - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2132,12 +2113,12 @@ bool CParameterMgr::restoreConfiguration(const string& strDomain, bool CParameterMgr::saveConfiguration(const string& strDomain, const string& strConfiguration, string& strError) { - CAutoLog autoLog(this, "Saving domain '" + strDomain - + "''s configuration '" + strConfiguration + "' from parameter blackboard"); + LOG_CONTEXT("Saving domain '" + strDomain + "' configuration '" + + strConfiguration + "' from parameter blackboard"); // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2149,12 +2130,12 @@ bool CParameterMgr::saveConfiguration(const string& strDomain, const string& str // Configurable element - domain association bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) { - CAutoLog autoLog(this, "Adding configurable element '" + strConfigurableElementPath - + "to domain '" + strDomain + "'"); + LOG_CONTEXT("Adding configurable element '" + strConfigurableElementPath + + "to domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail: " << strError; return false; } @@ -2164,7 +2145,7 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { - log_warning("Fail: " + strError); + warning() << "Fail: " << strError; return false; } @@ -2176,7 +2157,11 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons bool isSuccess = getConfigurableDomains()->addConfigurableElementToDomain( strDomain, pConfigurableElement, _pMainParameterBlackboard, infos); - log_table(!isSuccess, infos); + if (isSuccess) { + info() << infos; + } else { + warning() << infos; + } CUtility::asString(infos, strError); return isSuccess; @@ -2184,12 +2169,13 @@ bool CParameterMgr::addConfigurableElementToDomain(const string& strDomain, cons bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, const string& strConfigurableElementPath, string& strError) { - CAutoLog autoLog(this, "Removing configurable element '" + strConfigurableElementPath - + "' from domain '" + strDomain + "'"); + LOG_CONTEXT("Removing configurable element '" + strConfigurableElementPath + + "' from domain '" + strDomain + "'"); + // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2199,7 +2185,7 @@ bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2213,12 +2199,12 @@ bool CParameterMgr::removeConfigurableElementFromDomain(const string& strDomain, bool CParameterMgr::split(const string& strDomain, const string& strConfigurableElementPath, string& strError) { - CAutoLog autoLog(this, "Splitting configurable element '" + strConfigurableElementPath - + "' domain '" + strDomain + "'"); + LOG_CONTEXT("Splitting configurable element '" + strConfigurableElementPath + + "' domain '" + strDomain + "'"); // Check tuning mode if (!checkTuningModeOn(strError)) { - log_warning("Fail: " + strError); + warning() << "Fail:" << strError; return false; } @@ -2228,7 +2214,7 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable if (!elementLocator.locate(strConfigurableElementPath, &pLocatedElement, strError)) { - log_warning("Fail: " + strError); + warning() << "Fail: " << strError; return false; } @@ -2239,7 +2225,12 @@ bool CParameterMgr::split(const string& strDomain, const string& strConfigurable core::Results infos; bool isSuccess = getConfigurableDomains()->split(strDomain, pConfigurableElement, infos); - log_table(isSuccess, infos); + if (isSuccess) { + info() << infos; + } else { + warning() << infos; + } + CUtility::asString(infos, strError); return isSuccess; } @@ -2583,7 +2574,7 @@ void CParameterMgr::setForceNoRemoteInterface(bool bForceNoRemoteInterface) // Remote Processor Server connection handling bool CParameterMgr::handleRemoteProcessingInterface(string& strError) { - CAutoLog autoLog(this, "Handling remote processing interface"); + LOG_CONTEXT("Handling remote processing interface"); if (_bForceNoRemoteInterface) { // The user requested not to start the remote interface @@ -2593,7 +2584,7 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) // Start server if tuning allowed if (getConstFrameworkConfiguration()->isTuningAllowed()) { - log_info("Loading remote processor library"); + info() << "Loading remote processor library"; // Load library _pvLibRemoteProcessorHandle = dlopen("libremote-processor.so", RTLD_NOW); @@ -2626,7 +2617,8 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) // Create server _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler); - log_info("Starting remote processor server on port %d", getConstFrameworkConfiguration()->getServerPort()); + info() << "Starting remote processor server on port " + << getConstFrameworkConfiguration()->getServerPort(); // Start if (!_pRemoteProcessorServer->start()) { @@ -2692,7 +2684,7 @@ const CConfigurableDomains* CParameterMgr::getConstConfigurableDomains() const // Apply configurations void CParameterMgr::doApplyConfigurations(bool bForce) { - CAutoLog autoLog(this, "Applying configurations"); + LOG_CONTEXT("Applying configurations"); CSyncerSet syncerSet; @@ -2702,7 +2694,7 @@ void CParameterMgr::doApplyConfigurations(bool bForce) // Ensure application of currently selected configurations getConfigurableDomains()->apply(_pMainParameterBlackboard, syncerSet, bForce, infos); - log_table(false, infos); + info() << infos; // Reset the modified status of the current criteria to indicate that a new configuration has been applied getSelectionCriteria()->resetModifiedStatus(); @@ -2736,9 +2728,23 @@ bool CParameterMgr::exportElementToXMLString(const IXmlSource* pXmlSource, bool CParameterMgr::logResult(bool isSuccess, const std::string& result) { - std::string log(isSuccess ? "Success" : "Fail" ); - log += (result.empty() ? "" : ": " + result); - (this->*(isSuccess ? &CParameterMgr::log_info : &CParameterMgr::log_warning))(log); + std::string log = result.empty() ? "" : ": " + result; + + if (isSuccess) { + info() << "Success" << log; + } else { + warning() << "Fail" << log; + } return isSuccess; } + +log::details::Info CParameterMgr::info() +{ + return _logger.info(); +} + +log::details::Warning CParameterMgr::warning() +{ + return _logger.warning(); +} diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index 5ced38131..1e0f895fc 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -40,8 +40,11 @@ #include "XmlDocSink.h" #include "XmlDocSource.h" #include "Results.h" +#include +#include #include +#include class CElementLibrarySet; class CSubsystemLibrary; @@ -93,22 +96,11 @@ class CParameterMgr : private CElement // Parameter handle friendship friend class CParameterHandle; public: - // Logger interface - class ILogger - { - public: - virtual void log(bool bIsWarning, const std::string& strLog) = 0; - protected: - virtual ~ILogger() {} - }; // Construction - CParameterMgr(const std::string& strConfigurationFilePath); + CParameterMgr(const std::string& strConfigurationFilePath, core::log::ILogger& logger); virtual ~CParameterMgr(); - // Logging - void setLogger(ILogger* pLogger); - /** Load plugins, structures and settings from the config file given. * * @param[out] strError is a std::string describing the error if an error occurred @@ -369,11 +361,6 @@ class CParameterMgr : private CElement // Init virtual bool init(std::string& strError); - // Logging (done by root) - virtual void doLog(bool bIsWarning, const std::string& strLog) const; - virtual void nestLog() const; - virtual void unnestLog() const; - // Version std::string getVersion() const; @@ -596,6 +583,12 @@ class CParameterMgr : private CElement */ bool logResult(bool isSuccess, const std::string& result); + /** Info logger call helper */ + inline core::log::details::Info info(); + + /** Warning logger call helper */ + inline core::log::details::Warning warning(); + // Tuning bool _bTuningModeIsOn; @@ -648,9 +641,8 @@ class CParameterMgr : private CElement // Blackboard access mutex pthread_mutex_t _blackboardMutex; - // Logging - ILogger* _pLogger; - mutable uint32_t _uiLogDepth; + /** Application main logger based on the one provided by the client */ + core::log::Logger _logger; /** If set to false, the remote interface won't be started no matter what. * If set to true - the default - it has no impact on the policy for diff --git a/parameter/ParameterMgrFullConnector.cpp b/parameter/ParameterMgrFullConnector.cpp index 7ab3f9188..bf3214472 100644 --- a/parameter/ParameterMgrFullConnector.cpp +++ b/parameter/ParameterMgrFullConnector.cpp @@ -36,10 +36,10 @@ using std::string; CParameterMgrFullConnector::CParameterMgrFullConnector(const string& strConfigurationFilePath) : - _pParameterMgr(new CParameterMgr(strConfigurationFilePath)), _pLogger(NULL) + _pParameterMgrLogger(new CParameterMgrLogger(*this)), + _pParameterMgr(new CParameterMgr(strConfigurationFilePath, *_pParameterMgrLogger)), + _pLogger(NULL) { - _pParameterMgrLogger = new CParameterMgrLogger(*this); - _pParameterMgr->setLogger(_pParameterMgrLogger); } CParameterMgrFullConnector::~CParameterMgrFullConnector() @@ -61,11 +61,19 @@ void CParameterMgrFullConnector::setLogger(CParameterMgrFullConnector::ILogger* } // Private logging -void CParameterMgrFullConnector::doLog(bool bIsWarning, const string& strLog) +void CParameterMgrFullConnector::info(const string& log) { if (_pLogger) { - _pLogger->log(bIsWarning, strLog); + _pLogger->info(log); + } +} + +void CParameterMgrFullConnector::warning(const string& log) +{ + if (_pLogger) { + + _pLogger->warning(log); } } diff --git a/parameter/ParameterMgrLogger.h b/parameter/ParameterMgrLogger.h index 0e42d8a69..ee445b5aa 100644 --- a/parameter/ParameterMgrLogger.h +++ b/parameter/ParameterMgrLogger.h @@ -30,14 +30,14 @@ #pragma once #include "ParameterMgrLoggerForward.h" -#include "ParameterMgr.h" +#include #include -/* Wrap a class to expose its logging [log(bool, string&)] capabilities +/* Wrap a class to expose its logging [info, warning] capabilities * through ILogger. */ template -class CParameterMgrLogger : public CParameterMgr::ILogger +class CParameterMgrLogger : public core::log::ILogger { public: CParameterMgrLogger(T& parameterMgrConnector) : @@ -45,9 +45,14 @@ class CParameterMgrLogger : public CParameterMgr::ILogger { } - virtual void log(bool bIsWarning, const std::string& strLog) + virtual void info(const std::string& log) { - _parameterMgrConnector.doLog(bIsWarning, strLog); + _parameterMgrConnector.info(log); + } + + virtual void warning(const std::string& log) + { + _parameterMgrConnector.warning(log); } private: diff --git a/parameter/ParameterMgrPlatformConnector.cpp b/parameter/ParameterMgrPlatformConnector.cpp index d49003d7a..2ff577428 100644 --- a/parameter/ParameterMgrPlatformConnector.cpp +++ b/parameter/ParameterMgrPlatformConnector.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -37,11 +37,10 @@ using std::string; // Construction CParameterMgrPlatformConnector::CParameterMgrPlatformConnector( const string& strConfigurationFilePath) : - _pParameterMgr(new CParameterMgr(strConfigurationFilePath)), _bStarted(false), _pLogger(NULL) + _pParameterMgrLogger(new CParameterMgrLogger(*this)), + _pParameterMgr(new CParameterMgr(strConfigurationFilePath, *_pParameterMgrLogger)), + _bStarted(false), _pLogger(NULL) { - // Logging - _pParameterMgrLogger = new CParameterMgrLogger(*this); - _pParameterMgr->setLogger(_pParameterMgrLogger); } CParameterMgrPlatformConnector::~CParameterMgrPlatformConnector() @@ -187,10 +186,18 @@ bool CParameterMgrPlatformConnector::isStarted() const } // Private logging -void CParameterMgrPlatformConnector::doLog(bool bIsWarning, const string& strLog) +void CParameterMgrPlatformConnector::info(const string& log) { if (_pLogger) { - _pLogger->log(bIsWarning, strLog); + _pLogger->info(log); + } +} + +void CParameterMgrPlatformConnector::warning(const string& log) +{ + if (_pLogger) { + + _pLogger->warning(log); } } diff --git a/parameter/SelectionCriteria.cpp b/parameter/SelectionCriteria.cpp index 87ad76e52..5a43fd08c 100644 --- a/parameter/SelectionCriteria.cpp +++ b/parameter/SelectionCriteria.cpp @@ -50,9 +50,12 @@ CSelectionCriterionType* CSelectionCriteria::createSelectionCriterionType(bool b return getSelectionCriterionLibrary()->createSelectionCriterionType(bIsInclusive); } -CSelectionCriterion* CSelectionCriteria::createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType) +CSelectionCriterion* +CSelectionCriteria::createSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger) { - return getSelectionCriteriaDefinition()->createSelectionCriterion(strName, pSelectionCriterionType); + return getSelectionCriteriaDefinition()->createSelectionCriterion(strName, pType, logger); } // Selection criterion retrieval diff --git a/parameter/SelectionCriteria.h b/parameter/SelectionCriteria.h index 122b8a234..e656f376a 100644 --- a/parameter/SelectionCriteria.h +++ b/parameter/SelectionCriteria.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -33,6 +33,7 @@ #include "Element.h" #include "SelectionCriterionType.h" #include "SelectionCriterion.h" +#include #include @@ -51,7 +52,9 @@ class CSelectionCriteria : public CElement // Selection Criteria/Type creation CSelectionCriterionType* createSelectionCriterionType(bool bIsInclusive); - CSelectionCriterion* createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType); + CSelectionCriterion* createSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger); // Selection criterion retrieval CSelectionCriterion* getSelectionCriterion(const std::string& strName); diff --git a/parameter/SelectionCriteriaDefinition.cpp b/parameter/SelectionCriteriaDefinition.cpp index d7c422894..2eb216bb9 100644 --- a/parameter/SelectionCriteriaDefinition.cpp +++ b/parameter/SelectionCriteriaDefinition.cpp @@ -40,9 +40,12 @@ std::string CSelectionCriteriaDefinition::getKind() const } // Selection Criterion creation -CSelectionCriterion* CSelectionCriteriaDefinition::createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType) +CSelectionCriterion* +CSelectionCriteriaDefinition::createSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger) { - CSelectionCriterion* pSelectionCriterion = new CSelectionCriterion(strName, pSelectionCriterionType); + CSelectionCriterion* pSelectionCriterion = new CSelectionCriterion(strName, pType, logger); addChild(pSelectionCriterion); diff --git a/parameter/SelectionCriteriaDefinition.h b/parameter/SelectionCriteriaDefinition.h index 617b379a8..4bde944fa 100644 --- a/parameter/SelectionCriteriaDefinition.h +++ b/parameter/SelectionCriteriaDefinition.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -31,6 +31,7 @@ #include "Element.h" #include "SelectionCriterion.h" +#include class ISelectionCriterionObserver; @@ -40,7 +41,9 @@ class CSelectionCriteriaDefinition : public CElement CSelectionCriteriaDefinition(); // Selection Criterion creation - CSelectionCriterion* createSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pSelectionCriterionType); + CSelectionCriterion* createSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger); // Selection Criterion access const CSelectionCriterion* getSelectionCriterion(const std::string& strName) const; diff --git a/parameter/SelectionCriterion.cpp b/parameter/SelectionCriterion.cpp index 975503b90..03a04dc7b 100644 --- a/parameter/SelectionCriterion.cpp +++ b/parameter/SelectionCriterion.cpp @@ -29,10 +29,16 @@ */ #include "SelectionCriterion.h" +#include #define base CElement -CSelectionCriterion::CSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pType) : base(strName), _iState(0), _pType(pType), _uiNbModifications(0) +using namespace core; + +CSelectionCriterion::CSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger) + : base(strName), _iState(0), _pType(pType), _uiNbModifications(0), _logger(logger) { } @@ -60,13 +66,16 @@ void CSelectionCriterion::setCriterionState(int iState) _iState = iState; - log_info("Selection criterion changed event: %s", getFormattedDescription(false, false).c_str()); + _logger.info() << "Selection criterion changed event: " + << getFormattedDescription(false, false); // Check if the previous criterion value has been taken into account (i.e. at least one Configuration was applied // since the last criterion change) if (_uiNbModifications != 0) { - log_warning("Selection criterion \"%s\" has been modified %d time(s) without any configuration application", getName().c_str(), _uiNbModifications); + _logger.warning() << "Selection criterion '" << getName() + << "' has been modified " << _uiNbModifications + << " time(s) without any configuration application"; } // Track the number of modifications for this criterion diff --git a/parameter/SelectionCriterion.h b/parameter/SelectionCriterion.h index 86c96836b..e9c2f4950 100644 --- a/parameter/SelectionCriterion.h +++ b/parameter/SelectionCriterion.h @@ -32,13 +32,16 @@ #include "Element.h" #include "SelectionCriterionType.h" #include "SelectionCriterionInterface.h" +#include #include class CSelectionCriterion : public CElement, public ISelectionCriterionInterface { public: - CSelectionCriterion(const std::string& strName, const CSelectionCriterionType* pType); + CSelectionCriterion(const std::string& strName, + const CSelectionCriterionType* pType, + core::log::Logger& logger); /// From ISelectionCriterionInterface // State @@ -80,5 +83,8 @@ class CSelectionCriterion : public CElement, public ISelectionCriterionInterface /** Counter to know how many modifications have been applied to this criterion */ uint32_t _uiNbModifications; + + /** Application logger */ + core::log::Logger& _logger; }; diff --git a/parameter/include/ParameterMgrFullConnector.h b/parameter/include/ParameterMgrFullConnector.h index cbed5777c..a49d4ac86 100644 --- a/parameter/include/ParameterMgrFullConnector.h +++ b/parameter/include/ParameterMgrFullConnector.h @@ -56,7 +56,8 @@ class CParameterMgrFullConnector class ILogger { public: - virtual void log(bool bIsWarning, const std::string& strLog) = 0; + virtual void info(const std::string& strLog) = 0; + virtual void warning(const std::string& strLog) = 0; protected: virtual ~ILogger() {} }; @@ -277,11 +278,13 @@ class CParameterMgrFullConnector CParameterMgrFullConnector(const CParameterMgrFullConnector&); CParameterMgrFullConnector& operator=(const CParameterMgrFullConnector&); - void doLog(bool bIsWarning, const std::string& strLog); + void info(const std::string& log); + void warning(const std::string& log); + + // Log wrapper + CParameterMgrLogger* _pParameterMgrLogger; CParameterMgr* _pParameterMgr; ILogger* _pLogger; - // Log wrapper - CParameterMgrLogger* _pParameterMgrLogger; }; diff --git a/parameter/include/ParameterMgrPlatformConnector.h b/parameter/include/ParameterMgrPlatformConnector.h index cd9921550..9885a08f7 100644 --- a/parameter/include/ParameterMgrPlatformConnector.h +++ b/parameter/include/ParameterMgrPlatformConnector.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -44,7 +44,8 @@ class CParameterMgrPlatformConnector class ILogger { public: - virtual void log(bool bIsWarning, const std::string& strLog) = 0; + virtual void info(const std::string& strLog) = 0; + virtual void warning(const std::string& strLog) = 0; protected: virtual ~ILogger() {} }; @@ -160,14 +161,15 @@ class CParameterMgrPlatformConnector CParameterMgrPlatformConnector(const CParameterMgrPlatformConnector&); CParameterMgrPlatformConnector& operator=(const CParameterMgrPlatformConnector&); // Private logging - void doLog(bool bIsWarning, const std::string& strLog); + void info(const std::string& log); + void warning(const std::string& log); + // Private logging + CParameterMgrLogger* _pParameterMgrLogger; // Implementation CParameterMgr* _pParameterMgr; // State bool _bStarted; // Logging ILogger* _pLogger; - // Private logging - CParameterMgrLogger* _pParameterMgrLogger; }; diff --git a/parameter/AutoLog.cpp b/parameter/log/include/log/Context.h similarity index 64% rename from parameter/AutoLog.cpp rename to parameter/log/include/log/Context.h index ff7151aaf..b466ad2d1 100644 --- a/parameter/AutoLog.cpp +++ b/parameter/log/include/log/Context.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -27,27 +27,47 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "AutoLog.h" +#pragma once -using std::string; +#include "log/Logger.h" +#include -CAutoLog::CAutoLog(const CElement* pElement, const string& strContext, bool bLogOn) - : _pElement(pElement), _strContext(strContext), _bLogOn(bLogOn) +namespace core { - if (_bLogOn) { - // Log - _pElement->doLog(false, _strContext + " {"); - // Nest - _pElement->nestLog(); +namespace log +{ + +/** Log formatter which provide context indentation */ +class Context { +public: + + /** + * Class Constructor + * + * @param[in] logger application logger + * @param[in] context name of the context to open + */ + Context(Logger& logger, const std::string& context) + : mLogger(logger) + { + mLogger.info() << context << " {"; + mLogger.mProlog += " "; } -} -CAutoLog::~CAutoLog() -{ - if (_bLogOn) { - // Unnest - _pElement->unnestLog(); - // Log - _pElement->doLog(false, "} " + _strContext); + /** Class Destructor */ + ~Context() + { + mLogger.mProlog.resize(mLogger.mProlog.size() - 4); + mLogger.info() << "}"; } -} + +private: + Context(const Context&); + Context& operator=(const Context&); + + /** Application logger */ + Logger& mLogger; +}; + +} /** log namespace */ +} /** core namespace */ diff --git a/parameter/AutoLog.h b/parameter/log/include/log/ILogger.h similarity index 80% rename from parameter/AutoLog.h rename to parameter/log/include/log/ILogger.h index 045451420..895f8e9f6 100644 --- a/parameter/AutoLog.h +++ b/parameter/log/include/log/ILogger.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,24 +29,22 @@ */ #pragma once -#include "Element.h" - #include -class CAutoLog +namespace core +{ +namespace log { -public: - CAutoLog(const CElement* pElement, const std::string& strContext, bool bLogOn = true); - ~CAutoLog(); -private: - CAutoLog(const CAutoLog&); - CAutoLog& operator=(const CAutoLog&); - // Logger element - const CElement* _pElement; - // Context - std::string _strContext; - // Log on - bool _bLogOn; +/** Logger interface provided by client */ +class ILogger +{ +public: + virtual void info(const std::string& strLog) = 0; + virtual void warning(const std::string& strLog) = 0; +protected: + virtual ~ILogger() {} }; +} /** log namespace */ +} /** core namespace */ diff --git a/parameter/log/include/log/LogWrapper.h b/parameter/log/include/log/LogWrapper.h new file mode 100644 index 000000000..14007d4b7 --- /dev/null +++ b/parameter/log/include/log/LogWrapper.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#include "log/ILogger.h" +#include "Utility.h" +#include +#include +#include +#include + +namespace core +{ +namespace log +{ +namespace details +{ + +/** + * Template log wrapper + * Simulate a stream which can be used instead of basic ILogger API. + * + * @tparam isWarning indicates which log canal to use + */ +template +class LogWrapper +{ +public: + + /** @param logger the ILogger to wrap */ + LogWrapper(ILogger& logger, const std::string& prolog = "") + : mLogger(logger), mProlog(prolog) + {} + + /** + * Class copy constructor + * + * @param[in] logWrapper the instance to copy + */ + LogWrapper(const LogWrapper& logWrapper) + : mLogger(logWrapper.mLogger), mProlog(logWrapper.mProlog) + {} + + /** Class destructor */ + ~LogWrapper() + { + if (!mLog.str().empty()) { + if(isWarning) { + mLogger.warning(mProlog + mLog.str()); + } else { + mLogger.info(mProlog + mLog.str()); + } + } + } + + /** + * Simulate stream behaviour + * + * @tparam T the type of the information to log + * @param[in] log the information to log + */ + template + LogWrapper& operator<<(const T &log) + { + mLog << log; + return *this; + } + + /** + * Simulate stream behaviour for string list + * + * @param[in] logs list of information to log + */ + LogWrapper& operator<<(const std::list& logs) + { + std::string formatedLogs; + std::string separator = "\n" + mProlog; + CUtility::asString(logs, formatedLogs, separator); + + // Check if there is something in the log to know if we have to add a prefix + if (!mLog.str().empty() && mLog.str()[mLog.str().length()-1] == separator[0]) { + *this << mProlog; + } + + *this << formatedLogs; + return *this; + } + +private: + LogWrapper& operator=(const LogWrapper&); + + /** Log stream holder */ + std::ostringstream mLog; + + /** Wrapped logger */ + ILogger& mLogger; + + /** Log Prefix */ + const std::string& mProlog; +}; + +/** Default information logger type */ +typedef details::LogWrapper Info; + +/** Default warning logger type */ +typedef details::LogWrapper Warning; + +} /** details namespace */ +} /** log namespace */ +} /** core namespace */ diff --git a/parameter/log/include/log/Logger.h b/parameter/log/include/log/Logger.h new file mode 100644 index 000000000..c3b40aaaa --- /dev/null +++ b/parameter/log/include/log/Logger.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#include "log/ILogger.h" +#include "log/LogWrapper.h" + +namespace core +{ +namespace log +{ + +/** Application logger object (Thread unsafe) + * Provide contextualisable logging API. + * Streams can be used through Info and Warning objects returned by dedicated + * methods. + * This is the class you want to use to log in the project. + */ +class Logger +{ +public: + + /** Context class is friend let the prolog by externally modified */ + friend class Context; + + /** @param[in] logger, raw logger provided by client */ + Logger(ILogger& logger) : mLogger(logger) {} + + /** + * Retrieve wrapped information logger + * + * @return Info logger + */ + details::Info info() + { + return details::Info(mLogger, mProlog); + } + + /** + * Retrieve wrapped warning logger + * + * @return Warning logger + */ + details::Warning warning() + { + return details::Warning(mLogger, mProlog); + } + +private: + + /** Raw logger provided by client */ + ILogger& mLogger; + + /** Log prolog, owns the context indentation */ + std::string mProlog; +}; + +} /** log namespace */ +} /** core namespace */ diff --git a/test/test-fixed-point-parameter/Main.py b/test/test-fixed-point-parameter/Main.py index 6d7b2922b..31e10a5fb 100755 --- a/test/test-fixed-point-parameter/Main.py +++ b/test/test-fixed-point-parameter/Main.py @@ -39,9 +39,11 @@ def __init__(self): super(PfwLogger, self).__init__() self.__logger = logging.root.getChild("parameter-framework") - def log(self, is_warning, message): - log_func = self.__logger.warning if is_warning else self.__logger.info - log_func(message) + def info(self, message): + self.__logger.info(message) + + def warning(self, message): + self.__logger.warning(message) class FixedPointTester(): """ Made for testing a particular Qn.m number diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index 028dfd396..0153514f4 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -47,16 +47,14 @@ class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnect public: CParameterMgrPlatformConnectorLogger() {} - virtual void log(bool bIsWarning, const string& strLog) + virtual void info(const string& log) { + std::cout << log << std::endl; + } - if (bIsWarning) { - - std::cerr << strLog << std::endl; - } else { - - std::cout << strLog << std::endl; - } + virtual void warning(const string& log) + { + std::cerr << log << std::endl; } }; diff --git a/utility/CMakeLists.txt b/utility/CMakeLists.txt index 9f81027e8..9a31dc539 100644 --- a/utility/CMakeLists.txt +++ b/utility/CMakeLists.txt @@ -33,3 +33,7 @@ add_library(pfw_utility STATIC # '-fPIC' needed for linking against shared libraries (e.g. libparameter) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + +install(FILES + Utility.h + DESTINATION "include/utility") From 8eb4c34ade7e9d8255d10626dcedf57447baa1cf Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 7 Apr 2015 09:50:17 +0200 Subject: [PATCH 11/30] Remove unused remote-processor include location from test-subsystem Signed-off-by: Jules Clero --- test/test-subsystem/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test-subsystem/CMakeLists.txt b/test/test-subsystem/CMakeLists.txt index 52e66b024..ac058834b 100644 --- a/test/test-subsystem/CMakeLists.txt +++ b/test/test-subsystem/CMakeLists.txt @@ -37,7 +37,6 @@ if (BUILD_TESTING) include_directories( "${PROJECT_SOURCE_DIR}/xmlserializer" - "${PROJECT_SOURCE_DIR}/remote-processor" "${PROJECT_SOURCE_DIR}/parameter") target_link_libraries(test-subsystem parameter) From ca361e34d4d3474a898654b5eaf973d60828f923 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Wed, 4 Mar 2015 17:04:48 +0100 Subject: [PATCH 12/30] Enable subsystems logging Plugins are now able to log. An ILogger object is provided to plugins to do that. Signed-off-by: Jules Clero --- parameter/CMakeLists.txt | 2 +- parameter/DefaultElementLibrary.h | 25 +++---- parameter/FormattedSubsystemObject.cpp | 13 ++-- parameter/FormattedSubsystemObject.h | 10 ++- parameter/LoggingElementBuilderTemplate.h | 70 ++++++++++++++++++++ parameter/ParameterMgr.cpp | 2 +- parameter/Subsystem.cpp | 9 ++- parameter/Subsystem.h | 16 ++++- parameter/SubsystemLibrary.h | 6 +- parameter/SubsystemObject.cpp | 6 +- parameter/SubsystemObject.h | 9 ++- parameter/SubsystemObjectCreator.h | 8 ++- parameter/SubsystemObjectFactory.h | 11 ++- parameter/SystemClass.cpp | 20 ++++-- parameter/SystemClass.h | 11 ++- parameter/VirtualSubsystem.cpp | 6 +- parameter/VirtualSubsystem.h | 9 ++- test/test-subsystem/CMakeLists.txt | 2 + test/test-subsystem/TESTSubsystem.cpp | 3 +- test/test-subsystem/TESTSubsystem.h | 2 +- test/test-subsystem/TESTSubsystemBinary.cpp | 7 +- test/test-subsystem/TESTSubsystemBinary.h | 5 +- test/test-subsystem/TESTSubsystemBuilder.cpp | 7 +- test/test-subsystem/TESTSubsystemObject.cpp | 35 +++++++++- test/test-subsystem/TESTSubsystemObject.h | 5 +- test/test-subsystem/TESTSubsystemString.cpp | 7 +- test/test-subsystem/TESTSubsystemString.h | 5 +- 27 files changed, 243 insertions(+), 68 deletions(-) create mode 100644 parameter/LoggingElementBuilderTemplate.h diff --git a/parameter/CMakeLists.txt b/parameter/CMakeLists.txt index d5b65219f..ee009a88f 100644 --- a/parameter/CMakeLists.txt +++ b/parameter/CMakeLists.txt @@ -137,7 +137,7 @@ install(FILES InstanceConfigurableElement.h Mapper.h MappingContext.h - NamedElementBuilderTemplate.h + LoggingElementBuilderTemplate.h ParameterBlockType.h ParameterType.h PathNavigator.h diff --git a/parameter/DefaultElementLibrary.h b/parameter/DefaultElementLibrary.h index b6966c29d..a85b45c4c 100644 --- a/parameter/DefaultElementLibrary.h +++ b/parameter/DefaultElementLibrary.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -46,16 +46,17 @@ class CDefaultElementLibrary: public CElementLibrary { public: - explicit CDefaultElementLibrary(bool bEnableDefaultMechanism = true); + CDefaultElementLibrary() : _defaultBuilder(NULL) {} virtual ~CDefaultElementLibrary() {} - /** Enable the default builder fallback mechanism. + /** Set the default builder used in fallback mechanism. * @see createElement() for more detail on this mechanism. * - * @param[in] bEnable if true/false, activate/deactivate the default builder mechanism. + * @param[in] defaultBuilder if NULL default builder mechanism, else provided builder is used. */ - void enableDefaultMechanism(bool bEnable) { - _bEnableDefaultMechanism = bEnable; + void setDefaultBuilder(CDefaultElementBuilder* defaultBuilder) + { + _defaultBuilder = defaultBuilder; } @@ -72,15 +73,9 @@ class CDefaultElementLibrary: public CElementLibrary CElement* createElement(const CXmlElement& xmlElement) const; private: - bool _bEnableDefaultMechanism; - CDefaultElementBuilder _DefaultElementBuilder; + CDefaultElementBuilder* _defaultBuilder; }; -template -CDefaultElementLibrary::CDefaultElementLibrary(bool bEnableDefaultMechanism) : - _bEnableDefaultMechanism(bEnableDefaultMechanism), - _DefaultElementBuilder() {} - template CElement* CDefaultElementLibrary::createElement(const CXmlElement& xmlElement) const { @@ -91,12 +86,12 @@ CElement* CDefaultElementLibrary::createElement(const CX return builtElement; } - if (!_bEnableDefaultMechanism) { + if (_defaultBuilder == NULL) { // The default builder mechanism is not enabled return NULL; } // Use the default builder - return _DefaultElementBuilder.createElement(xmlElement); + return _defaultBuilder->createElement(xmlElement); } diff --git a/parameter/FormattedSubsystemObject.cpp b/parameter/FormattedSubsystemObject.cpp index 591ef9071..3c51a90d5 100644 --- a/parameter/FormattedSubsystemObject.cpp +++ b/parameter/FormattedSubsystemObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -38,15 +38,17 @@ using std::string; CFormattedSubsystemObject::CFormattedSubsystemObject( - CInstanceConfigurableElement* pInstanceConfigurableElement) - : base(pInstanceConfigurableElement) + CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger) + : base(pInstanceConfigurableElement, logger) { } CFormattedSubsystemObject::CFormattedSubsystemObject( CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger, const string& strMappingValue) - : base(pInstanceConfigurableElement), _strFormattedMappingValue(strMappingValue) + : base(pInstanceConfigurableElement, logger), _strFormattedMappingValue(strMappingValue) { } @@ -54,11 +56,12 @@ CFormattedSubsystemObject::CFormattedSubsystemObject( CFormattedSubsystemObject::CFormattedSubsystemObject( CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger, const string& strMappingValue, uint32_t uiFirstAmendKey, uint32_t uiNbAmendKeys, const CMappingContext& context) - : base(pInstanceConfigurableElement), _strFormattedMappingValue(strMappingValue) + : base(pInstanceConfigurableElement, logger), _strFormattedMappingValue(strMappingValue) { // Cope with quotes in the name if (strMappingValue[0] == '\'' && strMappingValue.length() >= 2) { diff --git a/parameter/FormattedSubsystemObject.h b/parameter/FormattedSubsystemObject.h index c04583be7..d36120988 100644 --- a/parameter/FormattedSubsystemObject.h +++ b/parameter/FormattedSubsystemObject.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -38,23 +38,28 @@ class CFormattedSubsystemObject : public CSubsystemObject * Builds a new CFormattedSubsystemObject instance, without any mapping information. * * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject. + * @param[in] logger the logger provided by the client */ - CFormattedSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement); + CFormattedSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger); /** * Builds a new CFormattedSubsystemObject instance, using a simple mapping value without Amends. * * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject. + * @param[in] logger the logger provided by the client * @param[in] strFormattedMapping A std::string corresponding to the mapping of the element. The * std::string does not contain any Amend (%) and does not need to be formatted. */ CFormattedSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger, const std::string& strFormattedMapping); /** * Builds a new CFormattedSubsystemObject instance, using a mapping value containing Amends. * * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject. + * @param[in] logger the logger provided by the client * @param[in] strMappingValue A std::string corresponding to the mapping of the element. The * std::string contains Amend (%) and needs to be formatted with information from the context. * @param[in] uiFirstAmendKey Index of the first Amend key @@ -62,6 +67,7 @@ class CFormattedSubsystemObject : public CSubsystemObject * @param[in] context Contains values associated to Amend keys */ CFormattedSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger, const std::string& strMappingValue, uint32_t uiFirstAmendKey, uint32_t uiNbAmendKeys, diff --git a/parameter/LoggingElementBuilderTemplate.h b/parameter/LoggingElementBuilderTemplate.h new file mode 100644 index 000000000..653a1e416 --- /dev/null +++ b/parameter/LoggingElementBuilderTemplate.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#pragma once + +#include "ElementBuilder.h" + +/** + * Builder for elements which need logger at construction + * + * @tparam ElementType the type of the element to build + */ +template +class TLoggingElementBuilderTemplate : public CElementBuilder +{ +public: + + /** + * Class Constructor + * + * @param[in] logger the logger provided by the client + */ + TLoggingElementBuilderTemplate(core::log::Logger& logger) + : CElementBuilder(), mLogger(logger) + { + } + + /** + * Create a new element + * + * @param[in] xmlElement the description of the object to create + * + * @return pointer to the generated element + */ + virtual CElement* createElement(const CXmlElement& xmlElement) const + { + return new ElementType(xmlElement.getNameAttribute(), mLogger); + } + +private: + + /** Application Logger */ + core::log::Logger& mLogger; +}; diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 4a6431cb5..cf440780c 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -341,7 +341,7 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge // Deal with children addChild(new CParameterFrameworkConfiguration); addChild(new CSelectionCriteria); - addChild(new CSystemClass); + addChild(new CSystemClass(_logger)); addChild(new CConfigurableDomains); _pCommandHandler = new CCommandHandler(this); diff --git a/parameter/Subsystem.cpp b/parameter/Subsystem.cpp index 5dbe3a073..fc9f39fef 100644 --- a/parameter/Subsystem.cpp +++ b/parameter/Subsystem.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -44,7 +44,10 @@ using std::string; using std::list; using std::ostringstream; -CSubsystem::CSubsystem(const string& strName) : base(strName), _pComponentLibrary(new CComponentLibrary), _pInstanceDefinition(new CInstanceDefinition), _bBigEndian(false), _pMappingData(NULL) +CSubsystem::CSubsystem(const string& strName, core::log::Logger& logger) + : base(strName), _pComponentLibrary(new CComponentLibrary), + _pInstanceDefinition(new CInstanceDefinition), _bBigEndian(false), _pMappingData(NULL), + _logger(logger) { // Note: A subsystem contains instance components // InstanceDefintion and ComponentLibrary objects are then not chosen to be children @@ -449,7 +452,7 @@ bool CSubsystem::handleSubsystemObjectCreation( // Do create object and keep its track _subsystemObjectList.push_back(pSubsystemObjectCreator->objectCreate( - *pStrValue, pInstanceConfigurableElement, context)); + *pStrValue, pInstanceConfigurableElement, context, _logger)); // Indicate subsytem creation to caller bHasCreatedSubsystemObject = true; diff --git a/parameter/Subsystem.h b/parameter/Subsystem.h index e53735299..2943ff816 100644 --- a/parameter/Subsystem.h +++ b/parameter/Subsystem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -33,6 +33,8 @@ #include "ConfigurableElementWithMapping.h" #include "Mapper.h" #include "MappingContext.h" +#include + #include #include #include @@ -50,7 +52,14 @@ class CSubsystem : public CConfigurableElementWithMapping, private IMapper // Subsystem objects iterator typedef std::list::const_iterator SubsystemObjectListIterator; public: - CSubsystem(const std::string& strName); + + /** + * Class Constructor + * + * @param[in] strName subsystem name + * @param[in] logger the main logger of the application + */ + CSubsystem(const std::string& strName, core::log::Logger& logger); virtual ~CSubsystem(); // From IXmlSink @@ -250,4 +259,7 @@ class CSubsystem : public CConfigurableElementWithMapping, private IMapper //! Contains the mapping info at Subsystem level CMappingData* _pMappingData; + + /** Logger which has to be provided to subsystem objects */ + core::log::Logger& _logger; }; diff --git a/parameter/SubsystemLibrary.h b/parameter/SubsystemLibrary.h index 78a497e33..2392b724a 100644 --- a/parameter/SubsystemLibrary.h +++ b/parameter/SubsystemLibrary.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -31,11 +31,11 @@ #include "DefaultElementLibrary.h" #include "VirtualSubsystem.h" -#include "NamedElementBuilderTemplate.h" +#include "LoggingElementBuilderTemplate.h" #include class CSubsystemLibrary : - public CDefaultElementLibrary > + public CDefaultElementLibrary > { private: // Builder type (based on element's name attribute) diff --git a/parameter/SubsystemObject.cpp b/parameter/SubsystemObject.cpp index 592ec5628..ebe410097 100644 --- a/parameter/SubsystemObject.cpp +++ b/parameter/SubsystemObject.cpp @@ -42,8 +42,10 @@ using std::string; -CSubsystemObject::CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement) - : _pInstanceConfigurableElement(pInstanceConfigurableElement), +CSubsystemObject::CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger) + : _logger(logger), + _pInstanceConfigurableElement(pInstanceConfigurableElement), _uiDataSize(pInstanceConfigurableElement->getFootPrint()), _pucBlackboardLocation(NULL), _uiAccessedIndex(0) diff --git a/parameter/SubsystemObject.h b/parameter/SubsystemObject.h index e4ccd19b4..08f65cf79 100644 --- a/parameter/SubsystemObject.h +++ b/parameter/SubsystemObject.h @@ -30,8 +30,9 @@ #pragma once #include "Syncer.h" -#include +#include +#include #include class CInstanceConfigurableElement; @@ -41,7 +42,8 @@ class CSubsystem; class CSubsystemObject : private ISyncer { public: - CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement); + CSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement, + core::log::Logger& logger); virtual ~CSubsystemObject(); /** @@ -85,6 +87,9 @@ class CSubsystemObject : private ISyncer // Belonging Subsystem retrieval const CSubsystem* getSubsystem() const; + /** Application Logger */ + core::log::Logger& _logger; + private: // from ISyncer virtual bool sync(CParameterBlackboard& parameterBlackboard, bool bBack, std::string& strError); diff --git a/parameter/SubsystemObjectCreator.h b/parameter/SubsystemObjectCreator.h index ed6e79d9c..55ef0cbb4 100644 --- a/parameter/SubsystemObjectCreator.h +++ b/parameter/SubsystemObjectCreator.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -44,7 +44,11 @@ class CSubsystemObjectCreator uint32_t getMaxConfigurableElementSize() const; // Object creation - virtual CSubsystemObject* objectCreate(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context) const = 0; + virtual CSubsystemObject* objectCreate( + const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger) const = 0; virtual ~CSubsystemObjectCreator() {} diff --git a/parameter/SubsystemObjectFactory.h b/parameter/SubsystemObjectFactory.h index 3ac783544..5e6dcae3a 100644 --- a/parameter/SubsystemObjectFactory.h +++ b/parameter/SubsystemObjectFactory.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -39,8 +39,13 @@ class TSubsystemObjectFactory : public CSubsystemObjectCreator TSubsystemObjectFactory(const std::string& strMappingKey, uint32_t uiAncestorIdMask, uint32_t uiMaxConfigurableElementSize = -1) : CSubsystemObjectCreator(strMappingKey, uiAncestorIdMask, uiMaxConfigurableElementSize) {} // Object creation - virtual CSubsystemObject* objectCreate(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context) const + virtual CSubsystemObject* objectCreate( + const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger) const { - return new SubsystemObjectType(strMappingValue, pInstanceConfigurableElement, context); + return new SubsystemObjectType( + strMappingValue, pInstanceConfigurableElement, context, logger); } }; diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp index 7e0c31cf1..e98fd5045 100644 --- a/parameter/SystemClass.cpp +++ b/parameter/SystemClass.cpp @@ -34,7 +34,7 @@ #include "SystemClass.h" #include "SubsystemLibrary.h" #include "VirtualSubsystem.h" -#include "NamedElementBuilderTemplate.h" +#include "LoggingElementBuilderTemplate.h" #include #include "PluginLocation.h" #include "Utility.h" @@ -44,6 +44,9 @@ using std::list; using std::string; +// FIXME: integrate SystemClass to core namespace +using namespace core; + /** * A plugin file name is of the form: * lib-subsystem.so or lib-subsystem._host.so @@ -60,9 +63,10 @@ const char* gpcPluginSymbolPrefix = "get"; const char* gpcPluginSymbolSuffix = "SubsystemBuilder"; // Used by subsystem plugins -typedef void (*GetSubsystemBuilder)(CSubsystemLibrary*); +typedef void (*GetSubsystemBuilder)(CSubsystemLibrary*, core::log::Logger& logger); -CSystemClass::CSystemClass() : _pSubsystemLibrary(new CSubsystemLibrary) +CSystemClass::CSystemClass(log::Logger& logger) + : _pSubsystemLibrary(new CSubsystemLibrary()), _logger(logger) { } @@ -100,11 +104,13 @@ bool CSystemClass::loadSubsystems(string& strError, // Start clean _pSubsystemLibrary->clean(); + typedef TLoggingElementBuilderTemplate VirtualSubsystemBuilder; // Add virtual subsystem builder - _pSubsystemLibrary->addElementBuilder("Virtual", - new TNamedElementBuilderTemplate()); + _pSubsystemLibrary->addElementBuilder("Virtual", new VirtualSubsystemBuilder(_logger)); // Set virtual subsytem as builder fallback if required - _pSubsystemLibrary->enableDefaultMechanism(bVirtualSubsystemFallback); + if (bVirtualSubsystemFallback) { + _pSubsystemLibrary->setDefaultBuilder(new VirtualSubsystemBuilder(_logger)); + } // Add subsystem defined in shared libraries core::Results errors; @@ -249,7 +255,7 @@ bool CSystemClass::loadPlugins(list& lstrPluginFiles, core::Results& err bAtLeastOneSubsystemPluginSuccessfullyLoaded = true; // Fill library - pfnGetSubsystemBuilder(_pSubsystemLibrary); + pfnGetSubsystemBuilder(_pSubsystemLibrary, _logger); // Remove successfully loaded plugin from list and select next lstrPluginFiles.erase(it++); diff --git a/parameter/SystemClass.h b/parameter/SystemClass.h index 886ed32c6..a6531b0df 100644 --- a/parameter/SystemClass.h +++ b/parameter/SystemClass.h @@ -32,6 +32,7 @@ #include "ConfigurableElement.h" #include "SubsystemPlugins.h" #include "Results.h" +#include #include #include @@ -40,7 +41,12 @@ class CSubsystemLibrary; class CSystemClass : public CConfigurableElement { public: - CSystemClass(); + + /** + * @param[in] logger the logger provided by the client + * it need to be given to the subsystem library + */ + CSystemClass(core::log::Logger& logger); virtual ~CSystemClass(); /** Load subsystem plugin and fill the corresponding libraries. @@ -110,5 +116,8 @@ class CSystemClass : public CConfigurableElement // Subsystem factory CSubsystemLibrary* _pSubsystemLibrary; std::list _subsystemLibraryHandleList; /**< Contains the list of all open plugin libs. */ + + /** Application Logger we need to provide to plugins */ + core::log::Logger& _logger; }; diff --git a/parameter/VirtualSubsystem.cpp b/parameter/VirtualSubsystem.cpp index 36027bf53..879dcbd12 100644 --- a/parameter/VirtualSubsystem.cpp +++ b/parameter/VirtualSubsystem.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -34,8 +34,8 @@ using std::string; -CVirtualSubsystem::CVirtualSubsystem(const string& strName) - : base(strName), _pVirtualSyncer(new CVirtualSyncer(this)) +CVirtualSubsystem::CVirtualSubsystem(const string& strName, core::log::Logger& logger) + : base(strName, logger), _pVirtualSyncer(new CVirtualSyncer(this)) { } diff --git a/parameter/VirtualSubsystem.h b/parameter/VirtualSubsystem.h index 3a9c89bc6..962bb62ed 100644 --- a/parameter/VirtualSubsystem.h +++ b/parameter/VirtualSubsystem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -38,7 +38,12 @@ class CVirtualSyncer; class CVirtualSubsystem : public CSubsystem { public: - CVirtualSubsystem(const std::string& strName); + + /** + * @param[in] strName subsystem name + * @param[in] logger the main logger of the application + */ + CVirtualSubsystem(const std::string& strName, core::log::Logger& logger); virtual ~CVirtualSubsystem(); protected: diff --git a/test/test-subsystem/CMakeLists.txt b/test/test-subsystem/CMakeLists.txt index ac058834b..b499923d1 100644 --- a/test/test-subsystem/CMakeLists.txt +++ b/test/test-subsystem/CMakeLists.txt @@ -37,6 +37,8 @@ if (BUILD_TESTING) include_directories( "${PROJECT_SOURCE_DIR}/xmlserializer" + "${PROJECT_SOURCE_DIR}/utility" + "${PROJECT_SOURCE_DIR}/parameter/log/include" "${PROJECT_SOURCE_DIR}/parameter") target_link_libraries(test-subsystem parameter) diff --git a/test/test-subsystem/TESTSubsystem.cpp b/test/test-subsystem/TESTSubsystem.cpp index 214fbb762..c2f288131 100644 --- a/test/test-subsystem/TESTSubsystem.cpp +++ b/test/test-subsystem/TESTSubsystem.cpp @@ -43,7 +43,8 @@ const char* gacFwNamePropName = getenv("PFW_RESULT"); // Implementation -CTESTSubsystem::CTESTSubsystem(const std::string& strName) : base(strName) +CTESTSubsystem::CTESTSubsystem(const std::string& strName, core::log::Logger& logger) + : base(strName, logger) { // Provide mapping keys to upper layer addContextMappingKey("Directory"); diff --git a/test/test-subsystem/TESTSubsystem.h b/test/test-subsystem/TESTSubsystem.h index bcd0fbdd7..9dfb10580 100644 --- a/test/test-subsystem/TESTSubsystem.h +++ b/test/test-subsystem/TESTSubsystem.h @@ -34,7 +34,7 @@ class CTESTSubsystem : public CSubsystem { public: - CTESTSubsystem(const std::string& strName); + CTESTSubsystem(const std::string& strName, core::log::Logger& logger); // Susbsystem sanity virtual bool isAlive() const; diff --git a/test/test-subsystem/TESTSubsystemBinary.cpp b/test/test-subsystem/TESTSubsystemBinary.cpp index 540fde806..72dcee320 100644 --- a/test/test-subsystem/TESTSubsystemBinary.cpp +++ b/test/test-subsystem/TESTSubsystemBinary.cpp @@ -35,8 +35,11 @@ #define base CTESTSubsystemObject -CTESTSubsystemBinary::CTESTSubsystemBinary(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context) - : base(strMappingValue, pInstanceConfigurableElement, context) +CTESTSubsystemBinary::CTESTSubsystemBinary(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger) + : base(strMappingValue, pInstanceConfigurableElement, context, logger) { } diff --git a/test/test-subsystem/TESTSubsystemBinary.h b/test/test-subsystem/TESTSubsystemBinary.h index a8d433e04..22a7b3968 100644 --- a/test/test-subsystem/TESTSubsystemBinary.h +++ b/test/test-subsystem/TESTSubsystemBinary.h @@ -34,7 +34,10 @@ class CTESTSubsystemBinary : public CTESTSubsystemObject { public: - CTESTSubsystemBinary(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context); + CTESTSubsystemBinary(const std::string& strMappingValue, + CInstanceConfigurableElement* configurableElement, + const CMappingContext& context, + core::log::Logger& logger); private: // from CTESTSubsystemObject diff --git a/test/test-subsystem/TESTSubsystemBuilder.cpp b/test/test-subsystem/TESTSubsystemBuilder.cpp index bcf2afc1d..a2628dfc1 100644 --- a/test/test-subsystem/TESTSubsystemBuilder.cpp +++ b/test/test-subsystem/TESTSubsystemBuilder.cpp @@ -28,15 +28,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "SubsystemLibrary.h" -#include "NamedElementBuilderTemplate.h" +#include "LoggingElementBuilderTemplate.h" #include "TESTSubsystem.h" extern "C" { -void getTESTSubsystemBuilder(CSubsystemLibrary* pSubsystemLibrary) +void getTESTSubsystemBuilder(CSubsystemLibrary* pSubsystemLibrary, core::log::Logger& logger) { pSubsystemLibrary->addElementBuilder("TEST", - new TNamedElementBuilderTemplate()); + new TLoggingElementBuilderTemplate( + logger)); } } diff --git a/test/test-subsystem/TESTSubsystemObject.cpp b/test/test-subsystem/TESTSubsystemObject.cpp index d17be0bfb..818eec95f 100644 --- a/test/test-subsystem/TESTSubsystemObject.cpp +++ b/test/test-subsystem/TESTSubsystemObject.cpp @@ -34,11 +34,16 @@ #include "TESTMappingKeys.h" #include "InstanceConfigurableElement.h" #include "TESTSubsystemObject.h" +#include +#include #define base CSubsystemObject -CTESTSubsystemObject::CTESTSubsystemObject(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context) - : base(pInstanceConfigurableElement) +CTESTSubsystemObject::CTESTSubsystemObject(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger) + : base(pInstanceConfigurableElement, logger) { (void)strMappingValue; // Get actual element type @@ -105,6 +110,19 @@ void CTESTSubsystemObject::sendToFile(std::ofstream& outputFile) std::string strValue = toString(pvValue, _uiScalarSize); outputFile << strValue << std::endl; + + if (_bLog) { + + if (_bIsScalar) { + + _logger.info() << "TESTSUBSYSTEM: Writing '" << strValue + << "' to file " << _strFilePath; + } else { + + _logger.info() << "TESTSUBSYSTEM: Writing '" << strValue << "' to file " + << _strFilePath << "[" << uiIndex << "]"; + } + } } } @@ -120,6 +138,19 @@ void CTESTSubsystemObject::receiveFromFile(std::ifstream& inputFile) inputFile >> strValue; + if (_bLog) { + + if (_bIsScalar) { + + _logger.info() << "TESTSUBSYSTEM: Reading '" << strValue + << "' to file " << _strFilePath; + } else { + + _logger.info() << "TESTSUBSYSTEM: Reading '" << strValue << "' to file " + << _strFilePath << "[" << uiIndex << "]"; + } + } + fromString(strValue, pvValue, _uiScalarSize); // Write Value in Blackboard diff --git a/test/test-subsystem/TESTSubsystemObject.h b/test/test-subsystem/TESTSubsystemObject.h index 527e55556..17266fac7 100644 --- a/test/test-subsystem/TESTSubsystemObject.h +++ b/test/test-subsystem/TESTSubsystemObject.h @@ -36,7 +36,10 @@ class CMappingContext; class CTESTSubsystemObject : public CSubsystemObject { public: - CTESTSubsystemObject(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context); + CTESTSubsystemObject(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger); protected: // from CSubsystemObject diff --git a/test/test-subsystem/TESTSubsystemString.cpp b/test/test-subsystem/TESTSubsystemString.cpp index 81ed79393..d31bf5a1a 100644 --- a/test/test-subsystem/TESTSubsystemString.cpp +++ b/test/test-subsystem/TESTSubsystemString.cpp @@ -32,8 +32,11 @@ #define base CTESTSubsystemObject -CTESTSubsystemString::CTESTSubsystemString(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context) - : base(strMappingValue, pInstanceConfigurableElement, context) +CTESTSubsystemString::CTESTSubsystemString(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger) + : base(strMappingValue, pInstanceConfigurableElement, context, logger) { } diff --git a/test/test-subsystem/TESTSubsystemString.h b/test/test-subsystem/TESTSubsystemString.h index cf7edb7f5..5ccf3627b 100644 --- a/test/test-subsystem/TESTSubsystemString.h +++ b/test/test-subsystem/TESTSubsystemString.h @@ -34,7 +34,10 @@ class CTESTSubsystemString : public CTESTSubsystemObject { public: - CTESTSubsystemString(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context); + CTESTSubsystemString(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger); private: // from CTESTSubsystemObject From e85bd0668730c5d4a2bc90b4542cf5cad99f090a Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 5 Mar 2015 16:09:35 +0100 Subject: [PATCH 13/30] Update Skeleton Subsystem for log ability. Signed-off-by: Jules Clero --- skeleton-subsystem/CMakeLists.txt | 9 +++++++-- skeleton-subsystem/SkeletonSubsystem.cpp | 5 +++-- skeleton-subsystem/SkeletonSubsystem.h | 4 ++-- skeleton-subsystem/SkeletonSubsystemBuilder.cpp | 10 ++++++---- skeleton-subsystem/SkeletonSubsystemObject.cpp | 6 ++++-- skeleton-subsystem/SkeletonSubsystemObject.h | 7 +++++-- 6 files changed, 27 insertions(+), 14 deletions(-) diff --git a/skeleton-subsystem/CMakeLists.txt b/skeleton-subsystem/CMakeLists.txt index 6a832233c..b20621b66 100644 --- a/skeleton-subsystem/CMakeLists.txt +++ b/skeleton-subsystem/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2014, Intel Corporation +# Copyright (c) 2015, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -45,8 +45,13 @@ find_path(PFW_CORE_INCLUDE_DIR NAMES Subsystem.h HINTS ${PFW_CORE_ROOT_DIR}/include/parameter/plugin) find_path(PFW_XMLSERIALIZER_INCLUDE_DIR NAMES XmlSink.h HINTS ${PFW_CORE_ROOT_DIR}/include/xmlserializer) +find_path(PFW_UTILITY_INCLUDE_DIR NAMES Utility.h + HINTS ${PFW_CORE_ROOT_DIR}/include/utility) -set(PFW_INCLUDE_DIRS ${PFW_CORE_INCLUDE_DIR} ${PFW_XMLSERIALIZER_INCLUDE_DIR}) +set(PFW_INCLUDE_DIRS + ${PFW_CORE_INCLUDE_DIR} + ${PFW_XMLSERIALIZER_INCLUDE_DIR} + ${PFW_UTILITY_INCLUDE_DIR}) set(PFW_LIBRARIES ${PFW_CORE_LIBRARY}) add_library(skeleton-subsystem SHARED diff --git a/skeleton-subsystem/SkeletonSubsystem.cpp b/skeleton-subsystem/SkeletonSubsystem.cpp index e3cbcbafb..56fedebea 100644 --- a/skeleton-subsystem/SkeletonSubsystem.cpp +++ b/skeleton-subsystem/SkeletonSubsystem.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -35,7 +35,8 @@ #define base CSubsystem // Implementation -CSkeletonSubsystem::CSkeletonSubsystem(const std::string& strName) : base(strName) +CSkeletonSubsystem::CSkeletonSubsystem(const std::string& strName, core::log::Logger& logger) + : base(strName, logger) { // Provide mapping keys to upper layer addContextMappingKey("Owner"); diff --git a/skeleton-subsystem/SkeletonSubsystem.h b/skeleton-subsystem/SkeletonSubsystem.h index 26cd65968..82e6e09a1 100644 --- a/skeleton-subsystem/SkeletonSubsystem.h +++ b/skeleton-subsystem/SkeletonSubsystem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -34,7 +34,7 @@ class CSkeletonSubsystem : public CSubsystem { public: - CSkeletonSubsystem(const std::string& strName); + CSkeletonSubsystem(const std::string& strName, core::log::Logger& logger); }; diff --git a/skeleton-subsystem/SkeletonSubsystemBuilder.cpp b/skeleton-subsystem/SkeletonSubsystemBuilder.cpp index a6aae2d54..553b716e2 100644 --- a/skeleton-subsystem/SkeletonSubsystemBuilder.cpp +++ b/skeleton-subsystem/SkeletonSubsystemBuilder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -28,7 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "SubsystemLibrary.h" -#include "NamedElementBuilderTemplate.h" +#include "LoggingElementBuilderTemplate.h" #include "SkeletonSubsystem.h" @@ -43,8 +43,10 @@ extern "C" * The plugin symbol is of the form: * getSubsystemBuilder */ -void getSKELETONSubsystemBuilder(CSubsystemLibrary* pSubsystemLibrary) +void getSKELETONSubsystemBuilder(CSubsystemLibrary* pSubsystemLibrary, core::log::Logger& logger) { - pSubsystemLibrary->addElementBuilder("Skeleton", new TNamedElementBuilderTemplate()); + pSubsystemLibrary->addElementBuilder( + "Skeleton", + new TLoggingElementBuilderTemplate(logger)); } } diff --git a/skeleton-subsystem/SkeletonSubsystemObject.cpp b/skeleton-subsystem/SkeletonSubsystemObject.cpp index 5ecded90a..1098954c4 100644 --- a/skeleton-subsystem/SkeletonSubsystemObject.cpp +++ b/skeleton-subsystem/SkeletonSubsystemObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -48,9 +48,11 @@ using std::string; CSkeletonSubsystemObject::CSkeletonSubsystemObject( const string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, - const CMappingContext& context + const CMappingContext& context, + core::log::Logger& logger ) : base(pInstanceConfigurableElement, + logger, strMappingValue, EAmend1, EAmendEnd - EAmend1 + 1, diff --git a/skeleton-subsystem/SkeletonSubsystemObject.h b/skeleton-subsystem/SkeletonSubsystemObject.h index f2927746d..9c1cb0b89 100644 --- a/skeleton-subsystem/SkeletonSubsystemObject.h +++ b/skeleton-subsystem/SkeletonSubsystemObject.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2011-2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -36,7 +36,10 @@ class CMappingContext; class CSkeletonSubsystemObject : public CFormattedSubsystemObject { public: - CSkeletonSubsystemObject(const std::string& strMappingValue, CInstanceConfigurableElement* pInstanceConfigurableElement, const CMappingContext& context); + CSkeletonSubsystemObject(const std::string& strMappingValue, + CInstanceConfigurableElement* pInstanceConfigurableElement, + const CMappingContext& context, + core::log::Logger& logger); protected: // from CSubsystemObject From 390f97c0ce86b1ea29f1f849a8d995d72b03c934 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 2 Apr 2015 11:46:52 +0200 Subject: [PATCH 14/30] Update domainGenerator python script to use the new log API Change-Id: Ib31547b3f899f96b837ac125ea7b0feb8c946760 Signed-off-by: Jules Clero --- tools/xmlGenerator/domainGenerator.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/xmlGenerator/domainGenerator.py b/tools/xmlGenerator/domainGenerator.py index 3e840f0d7..1d3aca58d 100755 --- a/tools/xmlGenerator/domainGenerator.py +++ b/tools/xmlGenerator/domainGenerator.py @@ -1,6 +1,6 @@ #! /usr/bin/python # -# Copyright (c) 2011-2014, Intel Corporation +# Copyright (c) 2011-2015, Intel Corporation # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -113,9 +113,11 @@ def __init__(self): super(PfwLogger, self).__init__() self.__logger = logging.root.getChild("parameter-framework") - def log(self, is_warning, message): - log_func = self.__logger.warning if is_warning else self.__logger.info - log_func(message) + def warning(self, message): + self.__logger.warning(message) + + def info(self, message): + self.__logger.info(message) # If this file is directly executed if __name__ == "__main__": From 8b3253dbc3ebc4b0acd6a032805579a7311bfb28 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Tue, 14 Apr 2015 17:27:57 +0200 Subject: [PATCH 15/30] README: change url to CI badges for the 'next' branch Signed-off-by: David Wagner --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e041f89f6..3e2ec0728 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # parameter-framework -[![Build Status](https://travis-ci.org/01org/parameter-framework.svg?branch=master)](https://travis-ci.org/01org/parameter-framework) -[![Coverage Status](https://coveralls.io/repos/01org/parameter-framework/badge.svg?branch=master)](https://coveralls.io/r/01org/parameter-framework) +[![Build Status](https://travis-ci.org/01org/parameter-framework.svg?branch=next)](https://travis-ci.org/01org/parameter-framework) +[![Coverage Status](https://coveralls.io/repos/01org/parameter-framework/badge.svg?branch=next)](https://coveralls.io/r/01org/parameter-framework) ## Introduction From 3270f6a64f4fe85f9b0854f2cbc2801962faabc4 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 23 Mar 2015 17:06:52 +0100 Subject: [PATCH 16/30] Remove -Wno-unused-but-set-variable flag for python binding compilation Swig does not any more generates code which require this flag. Moreover this flag is not present in clang compiler. Change-Id: I386ab576e93003d69dcf2c593670245070770024 Signed-off-by: Jules Clero --- bindings/python/Android.mk | 4 +--- bindings/python/CMakeLists.txt | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/bindings/python/Android.mk b/bindings/python/Android.mk index 05583447c..2736a02a1 100644 --- a/bindings/python/Android.mk +++ b/bindings/python/Android.mk @@ -46,13 +46,11 @@ LOCAL_C_INCLUDES := \ prebuilts/python/linux-x86/2.7.5/include/python2.7 \ $(HOST_OUT_HEADERS)/parameter -# The 'unused-but-set-variable' warning must be disabled because SWIG generates -# files that do not respect that constraint. # '-DSWIG_PYTHON_SILENT_MEMLEAK' is needed because the "memleak" warning # pollutes the standard output. At the time of writing, the only warning is # spurious anyway, as it relates to "ILogger *" which is an abstract # class/interface class and as such cannot be destroyed. -LOCAL_CFLAGS := -Wno-unused-but-set-variable -fexceptions -DSWIG_PYTHON_SILENT_MEMLEAK +LOCAL_CFLAGS := -fexceptions -DSWIG_PYTHON_SILENT_MEMLEAK # Undefined symbols will be resolved at runtime LOCAL_ALLOW_UNDEFINED_SYMBOLS := true diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index a885febd2..4f47fb1c6 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -54,13 +54,11 @@ swig_link_libraries(PyPfw parameter ${PYTHON_LIBRARIES}) # ${CMAKE_CURRENT_BINARY_DIR}. set_property(TARGET _PyPfw PROPERTY LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -# The 'unused-but-set-variable' warning must be disabled because SWIG generates -# files that do not respect that contraint. # '-DSWIG_PYTHON_SILENT_MEMLEAK' is needed because the "memleak" warning # pollutes the standard output. At the time of writing, the only warning is # spurious anyway, as it relates to "ILogger *" which is an abstract # class/interface class and as such cannot be destroyed. -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable -DSWIG_PYTHON_SILENT_MEMLEAK") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSWIG_PYTHON_SILENT_MEMLEAK") # Find the python modules install path. From 66b5c5eef995c45c94ec5e930f6b519fa74e6545 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 23 Mar 2015 00:05:18 +0000 Subject: [PATCH 17/30] Fix hidden overloaded virtual function in BitParameter.h accessAsInteger function prototype is defined in BaseParameter abstract class with an uint32_t type. Nevertheless in BitParameter the overloaded function take an uin64_t. It seems that GCC accepts wrongly this mistake but clang don't. This patch corrects the function prototype accordingly to the one defined in BaseParameter. It allows the project to be compiled with clang. Signed-off-by: Jules Clero --- parameter/BitParameter.cpp | 4 ++-- parameter/BitParameter.h | 2 +- parameter/BitParameterType.cpp | 2 +- parameter/BitParameterType.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/parameter/BitParameter.cpp b/parameter/BitParameter.cpp index fb853e479..2a53afd90 100644 --- a/parameter/BitParameter.cpp +++ b/parameter/BitParameter.cpp @@ -87,7 +87,7 @@ bool CBitParameter::accessAsBoolean(bool& bValue, bool bSet, CParameterAccessCon } // Rely on integer access - uint64_t uiValue; + uint32_t uiValue; if (bSet) { @@ -108,7 +108,7 @@ bool CBitParameter::accessAsBoolean(bool& bValue, bool bSet, CParameterAccessCon } // Integer Access -bool CBitParameter::accessAsInteger(uint64_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const +bool CBitParameter::accessAsInteger(uint32_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const { uint32_t uiOffset = getOffset(); diff --git a/parameter/BitParameter.h b/parameter/BitParameter.h index 436f32118..f9e2b9d2d 100644 --- a/parameter/BitParameter.h +++ b/parameter/BitParameter.h @@ -49,7 +49,7 @@ class CBitParameter : public CBaseParameter virtual bool accessAsBoolean(bool& bValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; // Integer Access - virtual bool accessAsInteger(uint64_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; + virtual bool accessAsInteger(uint32_t& uiValue, bool bSet, CParameterAccessContext& parameterAccessContext) const; // AreaConfiguration creation virtual CAreaConfiguration* createAreaConfiguration(const CSyncerSet* pSyncerSet) const; diff --git a/parameter/BitParameterType.cpp b/parameter/BitParameterType.cpp index 2a400d40f..8488c18b5 100644 --- a/parameter/BitParameterType.cpp +++ b/parameter/BitParameterType.cpp @@ -191,7 +191,7 @@ bool CBitParameterType::toBlackboard(uint64_t uiUserValue, uint64_t& uiValue, CP return true; } -void CBitParameterType::fromBlackboard(uint64_t& uiUserValue, uint64_t uiValue, CParameterAccessContext& parameterAccessContext) const +void CBitParameterType::fromBlackboard(uint32_t& uiUserValue, uint64_t uiValue, CParameterAccessContext& parameterAccessContext) const { (void)parameterAccessContext; diff --git a/parameter/BitParameterType.h b/parameter/BitParameterType.h index 8f147e655..4c91a1a15 100644 --- a/parameter/BitParameterType.h +++ b/parameter/BitParameterType.h @@ -53,7 +53,7 @@ class CBitParameterType : public CTypeElement void fromBlackboard(std::string& strValue, const uint64_t& uiValue, CParameterAccessContext& parameterAccessContext) const; // Integer bool toBlackboard(uint64_t uiUserValue, uint64_t& uiValue, CParameterAccessContext& parameterAccessContext) const; - void fromBlackboard(uint64_t& uiUserValue, uint64_t uiValue, CParameterAccessContext& parameterAccessContext) const; + void fromBlackboard(uint32_t& uiUserValue, uint64_t uiValue, CParameterAccessContext& parameterAccessContext) const; // Access from area configuration uint64_t merge(uint64_t uiOriginData, uint64_t uiNewData) const; From 055a166cb73cae541cef3ad3430c68689d12c4a6 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 30 Mar 2015 09:03:51 +0200 Subject: [PATCH 18/30] Update Android.mk files to use Clang Clang compiler allows to use some great features in the Android PDK (like c++11). Change-Id: Ic80c04b0aff88aa947b3a07c6f35314cc4a7de28 Signed-off-by: Jules Clero --- bindings/python/Android.mk | 2 ++ parameter/Android.mk | 7 ++++--- remote-process/Android.mk | 5 ++++- remote-processor/Android.mk | 7 +++++-- test/test-platform/Android.mk | 7 +++++-- utility/Android.mk | 5 ++++- xmlserializer/Android.mk | 5 ++++- 7 files changed, 28 insertions(+), 10 deletions(-) diff --git a/bindings/python/Android.mk b/bindings/python/Android.mk index 2736a02a1..9cc56d2bc 100644 --- a/bindings/python/Android.mk +++ b/bindings/python/Android.mk @@ -80,5 +80,7 @@ $(generated-sources-dir)/pfw_wrap.cxx: $(LOCAL_PATH)/pfw.i -Iprebuilts/misc/common/swig/include/2.0.11/ \ -Wall -Werror -v -python -c++ -outdir $(HOST_LIBRARY_PATH)/ -o $@ $^ +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_HOST_SHARED_LIBRARY) diff --git a/parameter/Android.mk b/parameter/Android.mk index 22f7b2b21..843e89541 100644 --- a/parameter/Android.mk +++ b/parameter/Android.mk @@ -158,8 +158,8 @@ LOCAL_STATIC_LIBRARIES := libxmlserializer libpfw_utility libxml2 LOCAL_REQUIRED_MODULES := libremote-processor -LOCAL_CLANG := false -include external/stlport/libstlport.mk +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_SHARED_LIBRARY) ############################## @@ -186,7 +186,8 @@ LOCAL_STATIC_LIBRARIES := libxmlserializer_host libpfw_utility_host libxml2 LOCAL_LDLIBS += -ldl -LOCAL_CLANG := false +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_HOST_SHARED_LIBRARY) ################################ diff --git a/remote-process/Android.mk b/remote-process/Android.mk index c842b2d24..ddafcd552 100644 --- a/remote-process/Android.mk +++ b/remote-process/Android.mk @@ -68,7 +68,8 @@ LOCAL_SHARED_LIBRARIES := $(common_shared_libraries) LOCAL_STATIC_LIBRARIES := $(common_static_libraries) -include external/stlport/libstlport.mk +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_EXECUTABLE) ############################## @@ -92,4 +93,6 @@ LOCAL_SHARED_LIBRARIES := $(foreach shared_library, $(common_shared_libraries), LOCAL_STATIC_LIBRARIES := $(foreach static_library, $(common_static_libraries), \ $(static_library)_host) +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_HOST_EXECUTABLE) diff --git a/remote-processor/Android.mk b/remote-processor/Android.mk index d3e524648..d3f6bb1f8 100644 --- a/remote-processor/Android.mk +++ b/remote-processor/Android.mk @@ -51,7 +51,7 @@ common_cflags := \ -Wno-unused-parameter \ -pthread -common_ldlibs := -pthread +common_ldlibs := -lpthread ############################# # Target build @@ -67,7 +67,8 @@ LOCAL_MODULE := $(common_module) LOCAL_MODULE_OWNER := intel LOCAL_MODULE_TAGS := $(common_module_tags) -include external/stlport/libstlport.mk +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_SHARED_LIBRARY) ############################## @@ -85,4 +86,6 @@ LOCAL_MODULE_OWNER := intel LOCAL_MODULE_TAGS := $(common_module_tags) +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_HOST_SHARED_LIBRARY) diff --git a/test/test-platform/Android.mk b/test/test-platform/Android.mk index a8dc619e4..9c45695ac 100644 --- a/test/test-platform/Android.mk +++ b/test/test-platform/Android.mk @@ -43,7 +43,7 @@ common_c_includes := \ $(LOCAL_PATH)/../../parameter/include \ $(LOCAL_PATH)/../../remote-processor/ -common_ldlibs := -pthread +common_ldlibs := -lpthread common_shared_libraries := libparameter libremote-processor ############################# @@ -63,7 +63,8 @@ LOCAL_LDLIBS := $(common_ldlibs) LOCAL_STATIC_LIBRARIES := libpfw_utility LOCAL_SHARED_LIBRARIES := $(common_shared_libraries) -include external/stlport/libstlport.mk +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_EXECUTABLE) ############################## @@ -84,4 +85,6 @@ LOCAL_STATIC_LIBRARIES := libpfw_utility_host LOCAL_SHARED_LIBRARIES := $(foreach shared_library, $(common_shared_libraries), \ $(shared_library)_host) +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_HOST_EXECUTABLE) diff --git a/utility/Android.mk b/utility/Android.mk index 85b6c4205..7f9b1355a 100644 --- a/utility/Android.mk +++ b/utility/Android.mk @@ -60,7 +60,8 @@ LOCAL_MODULE_TAGS := $(common_module_tags) LOCAL_CFLAGS := $(common_cflags) -include external/stlport/libstlport.mk +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_STATIC_LIBRARY) ############################## @@ -78,4 +79,6 @@ LOCAL_MODULE_TAGS := $(common_module_tags) LOCAL_CFLAGS := $(common_cflags) +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_HOST_STATIC_LIBRARY) diff --git a/xmlserializer/Android.mk b/xmlserializer/Android.mk index 769acf805..89e2a2d11 100644 --- a/xmlserializer/Android.mk +++ b/xmlserializer/Android.mk @@ -79,7 +79,8 @@ LOCAL_STATIC_LIBRARIES := $(common_static_libraries) LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) -include external/stlport/libstlport.mk +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_STATIC_LIBRARY) ############################## @@ -102,6 +103,8 @@ LOCAL_STATIC_LIBRARIES := libxml2 LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH) +LOCAL_CLANG := true +include external/libcxx/libcxx.mk include $(BUILD_HOST_STATIC_LIBRARY) ################################ From 97ed4953ce77dbb420aeb82a0a9877e0d18a84e7 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 31 Mar 2015 10:22:32 +0200 Subject: [PATCH 19/30] Add clang compilation to travis configuration Swig has been updated in order to avoid the use of Wno-unused-but-set-variable flag which is not present in Clang. The coverage is not supported for now due to gcov compatibility problems with clang. The debug build his also built in a different directory to avoid an empty error of python bindings with clang. Signed-off-by: Jules Clero --- .travis.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3fec8b16f..790d2df49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ language: cpp compiler: - gcc -# - clang # not supported yet + - clang # Install a recent gcc, gcov and cmake, # it will not be necessary once travis worker is based on ubuntu > 12.04. -# Install SWIG for bindings generation +# Download recent SWIG for bindings generation before_install: + - wget http://mirrors.kernel.org/ubuntu/pool/main/s/swig2.0/swig2.0_2.0.12-1ubuntu1_amd64.deb - sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test - sudo add-apt-repository --yes ppa:kalakris/cmake # Non official cmake backport - sudo apt-get update -qq - sudo pip install cpp-coveralls install: - - sudo apt-get install --yes swig cmake valgrind g++-4.8 - - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 100 - - sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-4.8 100 + - sudo apt-get install --yes cmake valgrind + - if [ "$CXX" = "g++" ] ; then + sudo apt-get install --yes g++-4.8 && + sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 100 && + sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-4.8 100 ; + fi - sudo wget --directory-prefix /usr/include/ https://raw.github.com/philsquared/Catch/master/single_include/catch.hpp + - sudo dpkg -i swig2.0_2.0.12-1ubuntu1_amd64.deb # how to build script: From 2cfe044c7c29365fb892578d5ac020ea53dcdaae Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 23 Feb 2015 15:34:37 +0100 Subject: [PATCH 20/30] Enable C++11 C++11 is now available on Android, thus we can start to use it in the parameter-framework. Signed-off-by: Jules Clero --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bf533ccc..ef268b92b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ endif(COMMAND cmake_policy) project(parameter-framework) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra -std=c++11") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) From c83030cca9904f65f348172257cd177b328a165f Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 19 Feb 2015 18:33:47 +0100 Subject: [PATCH 21/30] Delegate ParameterMgr Command Parsing behavior ParameterMgr is offered as template parser to the RemoteCommandHandlerTemplate class. This is not his primary job and make the class hard to read. This patch introduces the CommandParser class which handle this job. Signed-off-by: Jules Clero --- parameter/CMakeLists.txt | 5 +- parameter/ParameterMgr.cpp | 1005 +------------------ parameter/ParameterMgr.h | 156 +-- parameter/command/include/command/Parser.h | 239 +++++ parameter/command/src/Parser.cpp | 1030 ++++++++++++++++++++ 5 files changed, 1292 insertions(+), 1143 deletions(-) create mode 100644 parameter/command/include/command/Parser.h create mode 100644 parameter/command/src/Parser.cpp diff --git a/parameter/CMakeLists.txt b/parameter/CMakeLists.txt index ee009a88f..4fc6bf5b4 100644 --- a/parameter/CMakeLists.txt +++ b/parameter/CMakeLists.txt @@ -100,10 +100,13 @@ add_library(parameter SHARED VirtualSyncer.cpp XmlElementSerializingContext.cpp XmlFileIncluderElement.cpp - XmlParameterSerializingContext.cpp) + XmlParameterSerializingContext.cpp + command/src/Parser.cpp) include_directories( include + command/include + "${PROJECT_SOURCE_DIR}/parameter" "${PROJECT_SOURCE_DIR}/xmlserializer" "${PROJECT_SOURCE_DIR}/utility" "${PROJECT_SOURCE_DIR}/remote-processor" diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index cf440780c..70c51b8b9 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -30,7 +30,6 @@ #include "ParameterMgr.h" #include "XmlParameterSerializingContext.h" #include "XmlElementSerializingContext.h" -#include "SystemClass.h" #include "ElementLibrarySet.h" #include "SubsystemLibrary.h" #include "NamedElementBuilderTemplate.h" @@ -85,11 +84,9 @@ #include "XmlStringDocSource.h" #include "XmlMemoryDocSink.h" #include "XmlMemoryDocSource.h" -#include "SelectionCriteriaDefinition.h" #include "Utility.h" #include -#include -#include +#include #define base CElement @@ -143,177 +140,6 @@ const char* gacSystemSchemasSubFolder = "Schemas"; // `-- .xml* // -------------------------------------------- - -// Remote command parser array -const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandParserItems[] = { - - /// Version - { "version", &CParameterMgr::versionCommandProcess, 0, - "", "Show version" }, - - /// Status - { "status", &CParameterMgr::statusCommandProcess, 0, "", - "Show current status" }, - - /// Tuning Mode - { "setTuningMode", &CParameterMgr::setTuningModeCommmandProcess, 1, - "on|off*", "Turn on or off Tuning Mode" }, - { "getTuningMode", &CParameterMgr::getTuningModeCommmandProcess, 0, - "", "Show Tuning Mode" }, - - /// Value Space - { "setValueSpace", &CParameterMgr::setValueSpaceCommmandProcess, 1, - "raw|real*", "Assigns Value Space used for parameter value interpretation" }, - { "getValueSpace", &CParameterMgr::getValueSpaceCommmandProcess, 0, - "", "Show Value Space" }, - - /// Output Raw Format - { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommmandProcess, 1, - "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" }, - { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommmandProcess, 0, - "", "Show Output Raw Format" }, - - /// Sync - { "setAutoSync", &CParameterMgr::setAutoSyncCommmandProcess, 1, - "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" }, - { "getAutoSync", &CParameterMgr::getAutoSyncCommmandProcess, 0, - "", "Show Auto Sync state" }, - { "sync", &CParameterMgr::syncCommmandProcess, 0, - "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" }, - - /// Criteria - { "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0, - "[CSV|XML]", "List selection criteria" }, - - /// Domains - { "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0, - "", "List configurable domains" }, - { "dumpDomains", &CParameterMgr::dumpDomainsCommmandProcess, 0, - "", "Show all domains and configurations, including applicability conditions" }, - { "createDomain", &CParameterMgr::createDomainCommmandProcess, 1, - "", "Create new configurable domain" }, - { "deleteDomain", &CParameterMgr::deleteDomainCommmandProcess, 1, - "", "Delete configurable domain" }, - { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommmandProcess, 0, - "", "Delete all configurable domains" }, - { "renameDomain", &CParameterMgr::renameDomainCommmandProcess, 2, - " ", "Rename configurable domain" }, - { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommmandProcess, 1, - " true|false*", "Set configurable domain sequence awareness" }, - { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommmandProcess, 1, - "", "Get configurable domain sequence awareness" }, - { "listDomainElements", &CParameterMgr::listDomainElementsCommmandProcess, 1, - "", "List elements associated to configurable domain" }, - { "addElement", &CParameterMgr::addElementCommmandProcess, 2, - " ", "Associate element at given path to configurable domain" }, - { "removeElement", &CParameterMgr::removeElementCommmandProcess, 2, - " ", "Dissociate element at given path from configurable domain" }, - { "splitDomain", &CParameterMgr::splitDomainCommmandProcess, 2, - " ", "Split configurable domain at given associated element path" }, - - /// Configurations - { "listConfigurations", &CParameterMgr::listConfigurationsCommmandProcess, 1, - "", "List domain configurations" }, - { "createConfiguration", &CParameterMgr::createConfigurationCommmandProcess, 2, - " ", "Create new domain configuration" }, - { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommmandProcess, 2, - " ", "Delete domain configuration" }, - { "renameConfiguration", &CParameterMgr::renameConfigurationCommmandProcess, 3, - " ", "Rename domain configuration" }, - { "saveConfiguration", &CParameterMgr::saveConfigurationCommmandProcess, 2, - " ", "Save current settings into configuration" }, - { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommmandProcess, 2, - " ", "Restore current settings from configuration" }, - { "setElementSequence", &CParameterMgr::setElementSequenceCommmandProcess, 3, - " ", - "Set element application order for configuration" }, - { "getElementSequence", &CParameterMgr::getElementSequenceCommmandProcess, 2, - " ", "Get element application order for configuration" }, - { "setRule", &CParameterMgr::setRuleCommmandProcess, 3, - " ", "Set configuration application rule" }, - { "clearRule", &CParameterMgr::clearRuleCommmandProcess, 2, - " ", "Clear configuration application rule" }, - { "getRule", &CParameterMgr::getRuleCommmandProcess, 2, - " ", "Get configuration application rule" }, - - /// Elements/Parameters - { "listElements", &CParameterMgr::listElementsCommmandProcess, 1, - "|/", "List elements under element at given path or root" }, - { "listParameters", &CParameterMgr::listParametersCommmandProcess, 1, - "|/", "List parameters under element at given path or root" }, - { "dumpElement", &CParameterMgr::dumpElementCommmandProcess, 1, - "", "Dump structure and content of element at given path" }, - { "getElementSize", &CParameterMgr::getElementSizeCommmandProcess, 1, - "", "Show size of element at given path" }, - { "showProperties", &CParameterMgr::showPropertiesCommmandProcess, 1, - "", "Show properties of element at given path" }, - { "getParameter", &CParameterMgr::getParameterCommmandProcess, 1, - "", "Get value for parameter at given path" }, - { "setParameter", &CParameterMgr::setParameterCommmandProcess, 2, - " ", "Set value for parameter at given path" }, - { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommmandProcess, 1, - "", "List domain(s) element at given path belongs to" }, - { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommmandProcess, 1, - "", "List domain(s) element at given path is associated to" }, - { "getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommmandProcess, 3, - " ", - "Get value for parameter at given path from configuration" }, - { "setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommmandProcess, 4, - " ", - "Set value for parameter at given path to configuration" }, - { "showMapping", &CParameterMgr::showMappingCommmandProcess, 1, - "", "Show mapping for an element at given path" }, - - /// Browse - { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommmandProcess, 0, - "", "List element sub-trees associated to at least one configurable domain" }, - { "listConflictingElements", &CParameterMgr::listConflictingElementsCommmandProcess, 0, - "", "List element sub-trees contained in more than one configurable domain" }, - { "listRogueElements", &CParameterMgr::listRogueElementsCommmandProcess, 0, - "", "List element sub-trees owned by no configurable domain" }, - - /// Settings Import/Export - { "exportDomainsXML", &CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess, 1, - " ", "Export domains to XML file" }, - { "importDomainsXML", &CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess, 1, - "", "Import domains from XML file" }, - { "exportDomainsWithSettingsXML", - &CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess, 1, - " ", "Export domains including settings to XML file" }, - { "importDomainsWithSettingsXML", - &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, - "", "Import domains including settings from XML file" }, - { "importDomainWithSettingsXML", - &CParameterMgr::importConfigurableDomainWithSettingsFromXMLCommmandProcess, 1, - " [overwrite]", "Import a single domain including settings from XML file." - " Does not overwrite an existing domain unless 'overwrite' is passed as second" - " argument" }, - { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, - "", "Export settings to binary file" }, - { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, - "", "Import settings from binary file" }, - { "getDomainsWithSettingsXML", - &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0, - "", "Print domains including settings as XML" }, - { "getDomainWithSettingsXML", - &CParameterMgr::getConfigurableDomainWithSettingsXMLCommmandProcess, 1, - "", "Print the given domain including settings as XML" }, - { "setDomainsWithSettingsXML", - &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1, - "", "Import domains including settings from XML string" }, - /// Structure Export - { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommmandProcess, 0 , - "", "Print parameter structure as XML" }, - /// Deprecated Commands - { "getDomainsXML", - &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0, - "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" }, - -}; - -// Remote command parsers array Size -const uint32_t CParameterMgr::guiNbRemoteCommandParserItems = sizeof(gastRemoteCommandParserItems) / sizeof(gastRemoteCommandParserItems[0]); - CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogger& logger) : _bTuningModeIsOn(false), _bValueSpaceIsRaw(false), @@ -326,6 +152,7 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge _pvLibRemoteProcessorHandle(NULL), _uiStructureChecksum(0), _pRemoteProcessorServer(NULL), + _commandParser(*this), _uiMaxCommandUsageLength(0), _logger(logger), _bForceNoRemoteInterface(false), @@ -344,22 +171,6 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge addChild(new CSystemClass(_logger)); addChild(new CConfigurableDomains); - _pCommandHandler = new CCommandHandler(this); - - // Add command parsers - uint32_t uiRemoteCommandParserItem; - - for (uiRemoteCommandParserItem = 0; uiRemoteCommandParserItem < guiNbRemoteCommandParserItems; uiRemoteCommandParserItem++) { - - const SRemoteCommandParserItem* pRemoteCommandParserItem = &gastRemoteCommandParserItems[uiRemoteCommandParserItem]; - - _pCommandHandler->addCommandParser(pRemoteCommandParserItem->_pcCommandName, - pRemoteCommandParserItem->_pfnParser, - pRemoteCommandParserItem->_uiMinArgumentCount, - pRemoteCommandParserItem->_pcHelp, - pRemoteCommandParserItem->_pcDescription); - } - // Configuration file folder std::string::size_type slashPos = _strXmlConfigurationFilePath.rfind('/', -1); if(slashPos == std::string::npos) { @@ -377,7 +188,6 @@ CParameterMgr::~CParameterMgr() { // Children delete _pRemoteProcessorServer; - delete _pCommandHandler; delete _pMainParameterBlackboard; delete _pElementLibrarySet; @@ -884,813 +694,6 @@ bool CParameterMgr::getValidateSchemasOnStart() const return _bValidateSchemasOnStart; } -/////////////////// Remote command parsers -/// Version -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::versionCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - // Show version - strResult = getVersion(); - - return CCommandHandler::ESucceeded; -} - -/// Status -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::statusCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - // System class - const CSystemClass* pSystemClass = getSystemClass(); - - // Show status - /// General section - appendTitle(strResult, "General:"); - // System class - strResult += "System Class: "; - strResult += pSystemClass->getName(); - strResult += "\n"; - - // Tuning mode - strResult += "Tuning Mode: "; - strResult += tuningModeOn() ? "on" : "off"; - strResult += "\n"; - - // Value space - strResult += "Value Space: "; - strResult += valueSpaceIsRaw() ? "raw" : "real"; - strResult += "\n"; - - // Output raw format - strResult += "Output Raw Format: "; - strResult += outputRawFormatIsHex() ? "hex" : "dec"; - strResult += "\n"; - - // Auto Sync - strResult += "Auto Sync: "; - strResult += autoSyncOn() ? "on" : "off"; - strResult += "\n"; - - /// Subsystem list - appendTitle(strResult, "Subsystems:"); - string strSubsystemList; - pSystemClass->listChildrenPaths(strSubsystemList); - strResult += strSubsystemList; - - /// Last applied configurations - appendTitle(strResult, "Last Applied [Pending] Configurations:"); - string strLastAppliedConfigurations; - getConfigurableDomains()->listLastAppliedConfigurations(strLastAppliedConfigurations); - strResult += strLastAppliedConfigurations; - - /// Criteria states - appendTitle(strResult, "Selection Criteria:"); - list lstrSelectionCriteria; - getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true); - // Concatenate the criterion list as the command result - string strCriteriaStates; - CUtility::asString(lstrSelectionCriteria, strCriteriaStates); - strResult += strCriteriaStates; - - return CCommandHandler::ESucceeded; -} - -/// Tuning Mode -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - if (remoteCommand.getArgument(0) == "on") { - - if (setTuningMode(true, strResult)) { - - return CCommandHandler::EDone; - } - } else if (remoteCommand.getArgument(0) == "off") { - - if (setTuningMode(false, strResult)) { - - return CCommandHandler::EDone; - } - } else { - // Show usage - return CCommandHandler::EShowUsage; - } - return CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - strResult = tuningModeOn() ? "on" : "off"; - - return CCommandHandler::ESucceeded; -} - -/// Value Space -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)strResult; - - if (remoteCommand.getArgument(0) == "raw") { - - setValueSpace(true); - - return CCommandHandler::EDone; - - } else if (remoteCommand.getArgument(0) == "real") { - - setValueSpace(false); - - return CCommandHandler::EDone; - - } else { - // Show usage - return CCommandHandler::EShowUsage; - } - return CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - strResult = valueSpaceIsRaw() ? "raw" : "real"; - - return CCommandHandler::ESucceeded; -} - -/// Output Raw Format -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)strResult; - - if (remoteCommand.getArgument(0) == "hex") { - - setOutputRawFormat(true); - - return CCommandHandler::EDone; - - } else if (remoteCommand.getArgument(0) == "dec") { - - setOutputRawFormat(false); - - return CCommandHandler::EDone; - - } else { - // Show usage - return CCommandHandler::EShowUsage; - } - return CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - strResult = outputRawFormatIsHex() ? "hex" : "dec"; - - return CCommandHandler::ESucceeded; -} - -/// Sync -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - if (remoteCommand.getArgument(0) == "on") { - - if (setAutoSync(true, strResult)) { - - return CCommandHandler::EDone; - } - } else if (remoteCommand.getArgument(0) == "off") { - - if (setAutoSync(false, strResult)) { - - return CCommandHandler::EDone; - } - } else { - // Show usage - return CCommandHandler::EShowUsage; - } - return CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - strResult = autoSyncOn() ? "on" : "off"; - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -/// Criteria -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - if (remoteCommand.getArgumentCount() > 1) { - - return CCommandHandler::EShowUsage; - } - - string strOutputFormat; - - // Look for optional arguments - if (remoteCommand.getArgumentCount() == 1) { - - // Get requested format - strOutputFormat = remoteCommand.getArgument(0); - - // Capitalize - std::transform(strOutputFormat.begin(), strOutputFormat.end(), strOutputFormat.begin(), ::toupper); - - if (strOutputFormat != "XML" && strOutputFormat != "CSV") { - - return CCommandHandler::EShowUsage; - } - } - - if (strOutputFormat == "XML") { - // Get Root element where to export from - const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition = getConstSelectionCriteria()->getSelectionCriteriaDefinition(); - - if (!exportElementToXMLString(pSelectionCriteriaDefinition, "SelectionCriteria", - strResult)) { - - return CCommandHandler::EFailed; - } - - // Succeeded - return CCommandHandler::ESucceeded; - } else { - - // Requested format will be either CSV or human readable based on strOutputFormat content - bool bHumanReadable = strOutputFormat.empty(); - - list lstrResult; - getSelectionCriteria()->listSelectionCriteria(lstrResult, true, bHumanReadable); - - // Concatenate the criterion list as the command result - CUtility::asString(lstrResult, strResult); - - return CCommandHandler::ESucceeded; - } -} - -/// Domains -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - getConfigurableDomains()->listDomains(strResult); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - // Set property - bool bSequenceAware; - - if (remoteCommand.getArgument(1) == "true") { - - bSequenceAware = true; - - } else if (remoteCommand.getArgument(1) == "false") { - - bSequenceAware = false; - - } else { - // Show usage - return CCommandHandler::EShowUsage; - } - - return setSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - // Get property - bool bSequenceAware; - - if (!getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, strResult)) { - - return CCommandHandler::EFailed; - } - - strResult = bSequenceAware ? "true" : "false"; - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -/// Configurations -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return getConstConfigurableDomains()->listConfigurations(remoteCommand.getArgument(0), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - // Dummy error context - string strError; - CErrorContext errorContext(strError); - - // Dump - getConstConfigurableDomains()->dumpContent(strResult, errorContext); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return renameConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), - remoteCommand.getArgument(2), strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - core::Results result; - if (!restoreConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), result)) { - //Concatenate the error list as the command result - CUtility::asString(result, strResult); - - return CCommandHandler::EFailed; - } - return CCommandHandler::EDone; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - // Build configurable element path list - std::vector astrNewElementSequence; - - uint32_t uiArgument; - - for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) { - - astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument)); - } - - // Delegate to configurable domains - return setElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), - astrNewElementSequence, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - // Delegate to configurable domains - return getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::ESucceeded : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - // Delegate to configurable domains - return setApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), - remoteCommand.packArguments(2, remoteCommand.getArgumentCount() - 2), strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - // Delegate to configurable domains - return clearApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), - strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getRuleCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - // Delegate to configurable domains - return getApplicationRule(remoteCommand.getArgument(0), remoteCommand.getArgument(1), - strResult) ? - CCommandHandler::ESucceeded : CCommandHandler::EFailed; -} - -/// Elements/Parameters -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(getSystemClass(), false); - - CElement* pLocatedElement = NULL; - - if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { - - return CCommandHandler::EFailed; - } - - strResult = string("\n"); - - if (!pLocatedElement) { - - // List from root folder - - // Return system class qualified name - pLocatedElement = getSystemClass(); - } - - // Return sub-elements - strResult += pLocatedElement->listQualifiedPaths(false); - - return CCommandHandler::ESucceeded; -} - -/// Elements/Parameters -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(getSystemClass(), false); - - CElement* pLocatedElement = NULL; - - if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { - - return CCommandHandler::EFailed; - } - - strResult = string("\n"); - - if (!pLocatedElement) { - - // List from root folder - - // Return system class qualified name - pLocatedElement = getSystemClass(); - } - - // Return sub-elements - strResult += pLocatedElement->listQualifiedPaths(true); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(getSystemClass()); - - CElement* pLocatedElement = NULL; - - if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { - - return CCommandHandler::EFailed; - } - - string strError; - - CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, _bValueSpaceIsRaw, _bOutputRawFormatIsHex); - - // Dump elements - pLocatedElement->dumpContent(strResult, parameterAccessContext); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(getSystemClass()); - - CElement* pLocatedElement = NULL; - - if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { - - return CCommandHandler::EFailed; - } - - // Converted to actual sizable element - const CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); - - // Get size as string - strResult = pConfigurableElement->getFootprintAsString(); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(getSystemClass()); - - CElement* pLocatedElement = NULL; - - if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { - - return CCommandHandler::EFailed; - } - - // Convert element - const CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); - - // Return element properties - pConfigurableElement->showProperties(strResult); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - string strValue; - - if (!accessParameterValue(remoteCommand.getArgument(0), strValue, false, strResult)) { - - return CCommandHandler::EFailed; - } - // Succeeded - strResult = strValue; - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - // Get value to set - string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1); - - return accessParameterValue(remoteCommand.getArgument(0), strValue, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(getSystemClass()); - - CElement* pLocatedElement = NULL; - - if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { - - return CCommandHandler::EFailed; - } - - // Convert element - const CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); - - // Return element belonging domains - pConfigurableElement->listBelongingDomains(strResult); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(getSystemClass()); - - CElement* pLocatedElement = NULL; - - if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { - - return CCommandHandler::EFailed; - } - - // Convert element - const CConfigurableElement* pConfigurableElement = static_cast(pLocatedElement); - - // Return element belonging domains - pConfigurableElement->listAssociatedDomains(strResult); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - getConfigurableDomains()->listAssociatedElements(strResult); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - getConfigurableDomains()->listConflictingElements(strResult); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - getSystemClass()->listRogueElements(strResult); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - string strOutputValue; - string strError; - - if (!accessConfigurationValue(remoteCommand.getArgument(0), remoteCommand.getArgument(1), remoteCommand.getArgument(2), strOutputValue, false, strError)) { - - strResult = strError; - return CCommandHandler::EFailed; - } - // Succeeded - strResult = strOutputValue; - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - // Get value to set - string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3); - - bool bSuccess = accessConfigurationValue(remoteCommand.getArgument(0), - remoteCommand.getArgument(1), - remoteCommand.getArgument(2), - strValue, true, strResult); - - return bSuccess ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommmandProcess( - const IRemoteCommand& remoteCommand, - string& strResult) -{ - if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) { - - return CCommandHandler::EFailed; - } - - return CCommandHandler::ESucceeded; -} - -/// Settings Import/Export -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::exportConfigurableDomainsToXMLCommmandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - string strFileName = remoteCommand.getArgument(0); - return exportDomainsXml(strFileName, false, true, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::importConfigurableDomainsFromXMLCommmandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::exportConfigurableDomainsWithSettingsToXMLCommmandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - string strFileName = remoteCommand.getArgument(0); - return exportDomainsXml(strFileName, true, true, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - bool bOverwrite = false; - - // Look for optional arguments - if (remoteCommand.getArgumentCount() > 1) { - - if (remoteCommand.getArgument(1) == "overwrite") { - - bOverwrite = true; - } else { - // Show usage - return CCommandHandler::EShowUsage; - } - } - - return importSingleDomainXml(remoteCommand.getArgument(0), bOverwrite, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - if (!exportDomainsXml(strResult, true, false, strResult)) { - - return CCommandHandler::EFailed; - } - // Succeeded - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::getConfigurableDomainWithSettingsXMLCommmandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - string strDomainName = remoteCommand.getArgument(0); - - return exportSingleDomainXml(strResult, strDomainName, true, false, strResult) ? - CCommandHandler::ESucceeded : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::getSystemClassXMLCommmandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - // Get Root element where to export from - const CSystemClass* pSystemClass = getSystemClass(); - - if (!exportElementToXMLString(pSystemClass, pSystemClass->getKind(), strResult)) { - - return CCommandHandler::EFailed; - } - // Succeeded - return CCommandHandler::ESucceeded; -} // User set/get parameters in main BlackBoard bool CParameterMgr::accessParameterValue(const string& strPath, string& strValue, bool bSet, string& strError) @@ -2615,7 +1618,9 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) } // Create server - _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), _pCommandHandler); + _pRemoteProcessorServer = + pfnCreateRemoteProcessorServer(getConstFrameworkConfiguration()->getServerPort(), + _commandParser.getCommandHandler()); info() << "Starting remote processor server on port " << getConstFrameworkConfiguration()->getServerPort(); diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index 1e0f895fc..b754b94d4 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -32,7 +32,8 @@ #include #include #include -#include "RemoteCommandHandlerTemplate.h" +#include +#include "command/Parser.h" #include "PathNavigator.h" #include "SelectionCriterionType.h" #include "SelectionCriterion.h" @@ -74,20 +75,6 @@ class CParameterMgr : private CElement EParameterConfigurationLibrary }; - // Remote command parsers - typedef TRemoteCommandHandlerTemplate CCommandHandler; - - typedef CCommandHandler::CommandStatus (CParameterMgr::*RemoteCommandParser)(const IRemoteCommand& remoteCommand, std::string& strResult); - - // Parser descriptions - struct SRemoteCommandParserItem - { - const char* _pcCommandName; - CParameterMgr::RemoteCommandParser _pfnParser; - uint32_t _uiMinArgumentCount; - const char* _pcHelp; - const char* _pcDescription; - }; // Version static const uint32_t guiEditionMajor = 0x2; static const uint32_t guiEditionMinor = 0x4; @@ -95,6 +82,16 @@ class CParameterMgr : private CElement // Parameter handle friendship friend class CParameterHandle; + + /** + * FIXME: Avoid friendship with Parser + * + * This friendship can be avoided by implementing new APIs + * which can be used in both ParameterMgrFullConnector and + * Parser class. + */ + friend class core::command::Parser; + public: // Construction @@ -364,125 +361,6 @@ class CParameterMgr : private CElement // Version std::string getVersion() const; - ////////////////:: Remote command parsers - /// Version - CCommandHandler::CommandStatus versionCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Status - CCommandHandler::CommandStatus statusCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Tuning Mode - CCommandHandler::CommandStatus setTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getTuningModeCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Value Space - CCommandHandler::CommandStatus setValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getValueSpaceCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Output Raw Format - CCommandHandler::CommandStatus setOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getOutputRawFormatCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Sync - CCommandHandler::CommandStatus setAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getAutoSyncCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus syncCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Criteria - CCommandHandler::CommandStatus listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Domains - CCommandHandler::CommandStatus listDomainsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus createDomainCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus deleteDomainCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus deleteAllDomainsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus renameDomainCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus setSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getSequenceAwarenessCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listDomainElementsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus addElementCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus removeElementCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus splitDomainCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Configurations - CCommandHandler::CommandStatus listConfigurationsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus dumpDomainsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus createConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus deleteConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus renameConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus saveConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus restoreConfigurationCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus setElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getElementSequenceCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus setRuleCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus clearRuleCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getRuleCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Elements/Parameters - CCommandHandler::CommandStatus listElementsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listParametersCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus dumpElementCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getElementSizeCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus showPropertiesCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getParameterCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus setParameterCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus setConfigurationParameterCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listBelongingDomainsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listAssociatedDomainsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus showMappingCommmandProcess(const IRemoteCommand& remoteCommand, - std::string& strResult); - /// Browse - CCommandHandler::CommandStatus listAssociatedElementsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listConflictingElementsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listRogueElementsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Settings Import/Export - CCommandHandler::CommandStatus exportConfigurableDomainsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus importConfigurableDomainWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - - /** - * Command handler method for getConfigurableDomainsWithSettings command. - * - * @param[in] remoteCommand contains the arguments of the received command. - * @param[out] strResult a std::string containing the result of the command - * - * @return CCommandHandler::ESucceeded if command succeeded or CCommandHandler::EFailed - * in the other case - */ - CCommandHandler::CommandStatus getConfigurableDomainsWithSettingsXMLCommmandProcess( - const IRemoteCommand& remoteCommand, std::string& strResult); - - /** - * Command handler method for getConfigurableDomainWithSettings command. - * - * @param[in] remoteCommand contains the arguments of the received command. - * @param[out] strResult a string containing the result of the command - * - * @return CCommandHandler::ESucceeded if command succeeded or CCommandHandler::EFailed - * in the other case - */ - CCommandHandler::CommandStatus getConfigurableDomainWithSettingsXMLCommmandProcess( - const IRemoteCommand& remoteCommand, std::string& strResult); - - /** - * Command handler method for setConfigurableDomainWithSettings command. - * - * @param[in] remoteCommand contains the arguments of the received command. - * @param[out] strResult a std::string containing the result of the command - * - * @return CCommandHandler::ESucceeded if command succeeded or CCommandHandler::EFailed - * in the other case - */ - CCommandHandler::CommandStatus setConfigurableDomainsWithSettingsXMLCommmandProcess( - const IRemoteCommand& remoteCommand, std::string& strResult); - - /** - * Command handler method for getSystemClass command. - * - * @param[in] remoteCommand contains the arguments of the received command. - * @param[out] strResult a std::string containing the result of the command - * - * @return CCommandHandler::ESucceeded if command succeeded or CCommandHandler::EFailed - * in the other case - */ - CCommandHandler::CommandStatus getSystemClassXMLCommmandProcess( - const IRemoteCommand& remoteCommand, std::string& strResult); // Max command usage length, use for formatting void setMaxCommandUsageLength(); @@ -623,17 +501,11 @@ class CParameterMgr : private CElement // Whole system structure checksum uint8_t _uiStructureChecksum; - // Command Handler - CCommandHandler* _pCommandHandler; - // Remote Processor Server IRemoteProcessorServerInterface* _pRemoteProcessorServer; - // Parser description array - static const SRemoteCommandParserItem gastRemoteCommandParserItems[]; - - // Parser description array size - static const uint32_t guiNbRemoteCommandParserItems; + /** Remote commands Parser */ + core::command::Parser _commandParser; // Maximum command usage length uint32_t _uiMaxCommandUsageLength; diff --git a/parameter/command/include/command/Parser.h b/parameter/command/include/command/Parser.h new file mode 100644 index 000000000..244a73872 --- /dev/null +++ b/parameter/command/include/command/Parser.h @@ -0,0 +1,239 @@ +/* + * 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 "RemoteCommandHandlerTemplate.h" +#include + +class CParameterMgr; + +namespace core +{ +namespace command +{ + +/** Parse remote commands and delegate actions to Parameter Manager */ +class Parser +{ + +public: + + /** Remote command Handler type */ + typedef TRemoteCommandHandlerTemplate CommandHandler; + + typedef CommandHandler::CommandStatus + (Parser::*RemoteCommandParser)( + const IRemoteCommand& remoteCommand, std::string& result); + + /** Parser items description */ + struct RemoteCommandParserItem + { + const char* _pcCommandName; + Parser::RemoteCommandParser _pfnParser; + uint32_t _uiMinArgumentCount; + const char* _pcHelp; + const char* _pcDescription; + }; + + /** Class constructor + * + * @param parameterMgr pointer + */ + Parser(CParameterMgr& parameterMgr); + + /** Internal command handler getter + * + * @return pointer on the internal command handler + */ + CommandHandler* getCommandHandler(); + +private: + + /** Command handler method return type */ + typedef CommandHandler::CommandStatus CommandReturn; + + //@{ + /** Command handler methods for remote commands. + * + * @param[in] remoteCommand contains the arguments of the received command. + * @param[out] result a std::string containing the result of the command + * + * @return CommandHandler::ESucceeded if command succeeded or CommandHandler::EFailed + * in the other case + */ + CommandReturn version(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn status(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn setTuningMode(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn getTuningMode(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn setValueSpace(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn getValueSpace(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn setOutputRawFormat(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn getOutputRawFormat(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn setAutoSync(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn getAutoSync(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn sync(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn listCriteria(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn listDomains(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn createDomain(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn deleteDomain(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn deleteAllDomains(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn renameDomain(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn setSequenceAwareness(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn getSequenceAwareness(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn listDomainElements(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn addElement(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn removeElement(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn splitDomain(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn listConfigurations(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn dumpDomains(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn createConfiguration(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn deleteConfiguration(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn renameConfiguration(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn saveConfiguration(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn restoreConfiguration(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn setElementSequence(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn getElementSequence(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn setRule(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn clearRule(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn getRule(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn listElements(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn listParameters(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn dumpElement(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn getElementSize(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn showProperties(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn getParameter(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn setParameter(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn getConfigurationParameter(const IRemoteCommand& remoteCommand, + std::string& result); + + CommandReturn setConfigurationParameter(const IRemoteCommand& remoteCommand, + std::string& result); + + CommandReturn listBelongingDomains(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn listAssociatedDomains(const IRemoteCommand& remoteCommand, + std::string& result); + + CommandReturn showMapping(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn listAssociatedElements(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn listConflictingElements(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn listRogueElements(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn exportConfigurableDomainsToXML(const IRemoteCommand& remoteCommand, + std::string& result); + + CommandReturn importConfigurableDomainsFromXML(const IRemoteCommand& remoteCommand, + std::string& result); + + CommandReturn exportConfigurableDomainsWithSettingsToXML(const IRemoteCommand& remoteCommand, + std::string& result); + + CommandReturn importConfigurableDomainsWithSettingsFromXML(const IRemoteCommand& remoteCommand, + std::string& result); + + CommandReturn importConfigurableDomainWithSettingsFromXML(const IRemoteCommand& remoteCommand, + std::string& result); + + CommandReturn exportSettings(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn importSettings(const IRemoteCommand& remoteCommand, std::string& result); + + CommandReturn getConfigurableDomainsWithSettingsXML(const IRemoteCommand& remoteCommand, + std::string& result); + + CommandReturn getConfigurableDomainWithSettingsXML(const IRemoteCommand& remoteCommand, + std::string& result); + + CommandReturn setConfigurableDomainsWithSettingsXML(const IRemoteCommand& remoteCommand, + std::string& result); + + CommandReturn getSystemClassXML(const IRemoteCommand& remoteCommand, std::string& result); + //@} + + /** Parser items array */ + static const RemoteCommandParserItem gRemoteCommandParserItems[]; + + /** Parser items array size */ + static const uint32_t gNbRemoteCommandParserItems; + + /** Parameter Manager used to delegate parsed commands */ + CParameterMgr& mParameterMgr; + + /** Command Handler */ + CommandHandler mCommandHandler; +}; + +} /** command namespace */ +} /** core namespace */ diff --git a/parameter/command/src/Parser.cpp b/parameter/command/src/Parser.cpp new file mode 100644 index 000000000..89283728d --- /dev/null +++ b/parameter/command/src/Parser.cpp @@ -0,0 +1,1030 @@ +/* + * Copyright (c) 2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "command/Parser.h" +#include "ParameterMgr.h" +#include "ConfigurableDomains.h" +#include "ElementLocator.h" +#include "ErrorContext.h" +#include "ParameterAccessContext.h" +#include "SelectionCriteria.h" +#include "SelectionCriteriaDefinition.h" +#include "SystemClass.h" +#include "Utility.h" +#include +#include +#include + +namespace core +{ +namespace command +{ + +const Parser::RemoteCommandParserItem Parser::gRemoteCommandParserItems[] = { + + /// Version + { "version", &Parser::version, 0, + "", "Show version" }, + + /// Status + { "status", &Parser::status, 0, "", + "Show current status" }, + + /// Tuning Mode + { "setTuningMode", &Parser::setTuningMode, 1, + "on|off*", "Turn on or off Tuning Mode" }, + { "getTuningMode", &Parser::getTuningMode, 0, + "", "Show Tuning Mode" }, + + /// Value Space + { "setValueSpace", &Parser::setValueSpace, 1, + "raw|real*", "Assigns Value Space used for parameter value interpretation" }, + { "getValueSpace", &Parser::getValueSpace, 0, + "", "Show Value Space" }, + + /// Output Raw Format + { "setOutputRawFormat", &Parser::setOutputRawFormat, 1, + "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" }, + { "getOutputRawFormat", &Parser::getOutputRawFormat, 0, + "", "Show Output Raw Format" }, + + /// Sync + { "setAutoSync", &Parser::setAutoSync, 1, + "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" }, + { "getAutoSync", &Parser::getAutoSync, 0, + "", "Show Auto Sync state" }, + { "sync", &Parser::sync, 0, + "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" }, + + /// Criteria + { "listCriteria", &Parser::listCriteria, 0, + "[CSV|XML]", "List selection criteria" }, + + /// Domains + { "listDomains", &Parser::listDomains, 0, + "", "List configurable domains" }, + { "dumpDomains", &Parser::dumpDomains, 0, + "", "Show all domains and configurations, including applicability conditions" }, + { "createDomain", &Parser::createDomain, 1, + "", "Create new configurable domain" }, + { "deleteDomain", &Parser::deleteDomain, 1, + "", "Delete configurable domain" }, + { "deleteAllDomains", &Parser::deleteAllDomains, 0, + "", "Delete all configurable domains" }, + { "renameDomain", &Parser::renameDomain, 2, + " ", "Rename configurable domain" }, + { "setSequenceAwareness", &Parser::setSequenceAwareness, 1, + " true|false*", "Set configurable domain sequence awareness" }, + { "getSequenceAwareness", &Parser::getSequenceAwareness, 1, + "", "Get configurable domain sequence awareness" }, + { "listDomainElements", &Parser::listDomainElements, 1, + "", "List elements associated to configurable domain" }, + { "addElement", &Parser::addElement, 2, + " ", "Associate element at given path to configurable domain" }, + { "removeElement", &Parser::removeElement, 2, + " ", "Dissociate element at given path from configurable domain" }, + { "splitDomain", &Parser::splitDomain, 2, + " ", "Split configurable domain at given associated element path" }, + + /// Configurations + { "listConfigurations", &Parser::listConfigurations, 1, + "", "List domain configurations" }, + { "createConfiguration", &Parser::createConfiguration, 2, + " ", "Create new domain configuration" }, + { "deleteConfiguration", &Parser::deleteConfiguration, 2, + " ", "Delete domain configuration" }, + { "renameConfiguration", &Parser::renameConfiguration, 3, + " ", "Rename domain configuration" }, + { "saveConfiguration", &Parser::saveConfiguration, 2, + " ", "Save current settings into configuration" }, + { "restoreConfiguration", &Parser::restoreConfiguration, 2, + " ", "Restore current settings from configuration" }, + { "setElementSequence", &Parser::setElementSequence, 3, + " ", + "Set element application order for configuration" }, + { "getElementSequence", &Parser::getElementSequence, 2, + " ", "Get element application order for configuration" }, + { "setRule", &Parser::setRule, 3, + " ", "Set configuration application rule" }, + { "clearRule", &Parser::clearRule, 2, + " ", "Clear configuration application rule" }, + { "getRule", &Parser::getRule, 2, + " ", "Get configuration application rule" }, + + /// Elements/Parameters + { "listElements", &Parser::listElements, 1, + "|/", "List elements under element at given path or root" }, + { "listParameters", &Parser::listParameters, 1, + "|/", "List parameters under element at given path or root" }, + { "dumpElement", &Parser::dumpElement, 1, + "", "Dump structure and content of element at given path" }, + { "getElementSize", &Parser::getElementSize, 1, + "", "Show size of element at given path" }, + { "showProperties", &Parser::showProperties, 1, + "", "Show properties of element at given path" }, + { "getParameter", &Parser::getParameter, 1, + "", "Get value for parameter at given path" }, + { "setParameter", &Parser::setParameter, 2, + " ", "Set value for parameter at given path" }, + { "listBelongingDomains", &Parser::listBelongingDomains, 1, + "", "List domain(s) element at given path belongs to" }, + { "listAssociatedDomains", &Parser::listAssociatedDomains, 1, + "", "List domain(s) element at given path is associated to" }, + { "getConfigurationParameter", &Parser::getConfigurationParameter, 3, + " ", + "Get value for parameter at given path from configuration" }, + { "setConfigurationParameter", &Parser::setConfigurationParameter, 4, + " ", + "Set value for parameter at given path to configuration" }, + { "showMapping", &Parser::showMapping, 1, + "", "Show mapping for an element at given path" }, + + /// Browse + { "listAssociatedElements", &Parser::listAssociatedElements, 0, + "", "List element sub-trees associated to at least one configurable domain" }, + { "listConflictingElements", &Parser::listConflictingElements, 0, + "", "List element sub-trees contained in more than one configurable domain" }, + { "listRogueElements", &Parser::listRogueElements, 0, + "", "List element sub-trees owned by no configurable domain" }, + + /// Settings Import/Export + { "exportDomainsXML", &Parser::exportConfigurableDomainsToXML, 1, + " ", "Export domains to XML file" }, + { "importDomainsXML", &Parser::importConfigurableDomainsFromXML, 1, + "", "Import domains from XML file" }, + { "exportDomainsWithSettingsXML", + &Parser::exportConfigurableDomainsWithSettingsToXML, 1, + " ", "Export domains including settings to XML file" }, + { "importDomainsWithSettingsXML", + &Parser::importConfigurableDomainsWithSettingsFromXML, 1, + "", "Import domains including settings from XML file" }, + { "importDomainWithSettingsXML", + &Parser::importConfigurableDomainWithSettingsFromXML, 1, + " [overwrite]", "Import a single domain including settings from XML file." + " Does not overwrite an existing domain unless 'overwrite' is passed as second" + " argument" }, + { "exportSettings", &Parser::exportSettings, 1, + "", "Export settings to binary file" }, + { "importSettings", &Parser::importSettings, 1, + "", "Import settings from binary file" }, + { "getDomainsWithSettingsXML", + &Parser::getConfigurableDomainsWithSettingsXML, 0, + "", "Print domains including settings as XML" }, + { "getDomainWithSettingsXML", + &Parser::getConfigurableDomainWithSettingsXML, 1, + "", "Print the given domain including settings as XML" }, + { "setDomainsWithSettingsXML", + &Parser::setConfigurableDomainsWithSettingsXML, 1, + "", "Import domains including settings from XML string" }, + /// Structure Export + { "getSystemClassXML", &Parser::getSystemClassXML, 0, + "", "Print parameter structure as XML" }, + /// Deprecated Commands + { "getDomainsXML", + &Parser::getConfigurableDomainsWithSettingsXML, 0, + "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" }, + +}; + +// Remote command parsers array Size +const uint32_t Parser::gNbRemoteCommandParserItems = + sizeof(gRemoteCommandParserItems) / sizeof(gRemoteCommandParserItems[0]); + +Parser::Parser(CParameterMgr& parameterMgr) : + mParameterMgr(parameterMgr), mCommandHandler(CommandHandler(this)) +{ + // Add command parsers + uint32_t uiRemoteCommandParserItem; + + for (uiRemoteCommandParserItem = 0; + uiRemoteCommandParserItem < gNbRemoteCommandParserItems; uiRemoteCommandParserItem++) { + const RemoteCommandParserItem* pRemoteCommandParserItem = + &gRemoteCommandParserItems[uiRemoteCommandParserItem]; + + mCommandHandler.addCommandParser(pRemoteCommandParserItem->_pcCommandName, + pRemoteCommandParserItem->_pfnParser, + pRemoteCommandParserItem->_uiMinArgumentCount, + pRemoteCommandParserItem->_pcHelp, + pRemoteCommandParserItem->_pcDescription); + } +} + +Parser::CommandHandler* Parser::getCommandHandler() +{ + return &mCommandHandler; +} + +Parser::CommandReturn Parser::version(const IRemoteCommand&, std::string& result) +{ + // Show version + result = mParameterMgr.getVersion(); + + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::status(const IRemoteCommand&, std::string& result) +{ + // System class + const CSystemClass* pSystemClass = mParameterMgr.getSystemClass(); + + // Show status + /// General section + mParameterMgr.appendTitle(result, "General:"); + // System class + result += "System Class: "; + result += pSystemClass->getName(); + result += "\n"; + + // Tuning mode + result += "Tuning Mode: "; + result += mParameterMgr.tuningModeOn() ? "on" : "off"; + result += "\n"; + + // Value space + result += "Value Space: "; + result += mParameterMgr.valueSpaceIsRaw() ? "raw" : "real"; + result += "\n"; + + // Output raw format + result += "Output Raw Format: "; + result += mParameterMgr.outputRawFormatIsHex() ? "hex" : "dec"; + result += "\n"; + + // Auto Sync + result += "Auto Sync: "; + result += mParameterMgr.autoSyncOn() ? "on" : "off"; + result += "\n"; + + /// Subsystem list + mParameterMgr.appendTitle(result, "Subsystems:"); + std::string strSubsystemList; + pSystemClass->listChildrenPaths(strSubsystemList); + result += strSubsystemList; + + /// Last applied configurations + mParameterMgr.appendTitle(result, "Last Applied [Pending] Configurations:"); + std::string strLastAppliedConfigurations; + mParameterMgr.getConfigurableDomains()->listLastAppliedConfigurations( + strLastAppliedConfigurations); + result += strLastAppliedConfigurations; + + /// Criteria states + mParameterMgr.appendTitle(result, "Selection Criteria:"); + std::list lstrSelectionCriteria; + mParameterMgr.getSelectionCriteria()->listSelectionCriteria(lstrSelectionCriteria, false, true); + // Concatenate the criterion list as the command result + std::string strCriteriaStates; + CUtility::asString(lstrSelectionCriteria, strCriteriaStates); + result += strCriteriaStates; + + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::setTuningMode(const IRemoteCommand& remoteCommand, + std::string& result) +{ + if (remoteCommand.getArgument(0) == "on") { + + if (mParameterMgr.setTuningMode(true, result)) { + + return CommandHandler::EDone; + } + } else if (remoteCommand.getArgument(0) == "off") { + + if (mParameterMgr.setTuningMode(false, result)) { + + return CommandHandler::EDone; + } + } else { + // Show usage + return CommandHandler::EShowUsage; + } + return CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::getTuningMode(const IRemoteCommand&, std::string& result) +{ + result = mParameterMgr.tuningModeOn() ? "on" : "off"; + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::setValueSpace(const IRemoteCommand& remoteCommand, std::string&) +{ + if (remoteCommand.getArgument(0) == "raw") { + + mParameterMgr.setValueSpace(true); + + return CommandHandler::EDone; + + } else if (remoteCommand.getArgument(0) == "real") { + + mParameterMgr.setValueSpace(false); + + return CommandHandler::EDone; + + } else { + // Show usage + return CommandHandler::EShowUsage; + } + return CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::getValueSpace(const IRemoteCommand&, std::string& result) +{ + result = mParameterMgr.valueSpaceIsRaw() ? "raw" : "real"; + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::setOutputRawFormat(const IRemoteCommand& remoteCommand, std::string&) +{ + if (remoteCommand.getArgument(0) == "hex") { + + mParameterMgr.setOutputRawFormat(true); + + return CommandHandler::EDone; + + } else if (remoteCommand.getArgument(0) == "dec") { + + mParameterMgr.setOutputRawFormat(false); + + return CommandHandler::EDone; + + } else { + // Show usage + return CommandHandler::EShowUsage; + } + return CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::getOutputRawFormat(const IRemoteCommand&, std::string& result) +{ + result = mParameterMgr.outputRawFormatIsHex() ? "hex" : "dec"; + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::setAutoSync(const IRemoteCommand& remoteCommand, + std::string& result) +{ + if (remoteCommand.getArgument(0) == "on") { + + if (mParameterMgr.setAutoSync(true, result)) { + + return CommandHandler::EDone; + } + } else if (remoteCommand.getArgument(0) == "off") { + + if (mParameterMgr.setAutoSync(false, result)) { + + return CommandHandler::EDone; + } + } else { + // Show usage + return CommandHandler::EShowUsage; + } + return CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::getAutoSync(const IRemoteCommand&, std::string& result) +{ + result = mParameterMgr.autoSyncOn() ? "on" : "off"; + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::sync(const IRemoteCommand&, std::string& result) +{ + return mParameterMgr.sync(result) ? CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::listCriteria(const IRemoteCommand& remoteCommand, + std::string& result) +{ + if (remoteCommand.getArgumentCount() > 1) { + + return CommandHandler::EShowUsage; + } + + std::string format; + // Look for optional arguments + if (remoteCommand.getArgumentCount() == 1) { + + // Get requested format + format = remoteCommand.getArgument(0); + // Capitalize + std::transform(format.begin(), format.end(), format.begin(), ::toupper); + if (format != "XML" && format != "CSV") { + return CommandHandler::EShowUsage; + } + } + + if (format == "XML") { + // Get Root element where to export from + const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition = + mParameterMgr.getConstSelectionCriteria()->getSelectionCriteriaDefinition(); + + if (!mParameterMgr.exportElementToXMLString( + pSelectionCriteriaDefinition, "SelectionCriteria", result)) { + + return CommandHandler::EFailed; + } + // Succeeded + return CommandHandler::ESucceeded; + } else { + + // Requested format will be either CSV or human readable based on format content + bool bHumanReadable = format.empty(); + + std::list results; + mParameterMgr.getSelectionCriteria()->listSelectionCriteria(results, true, bHumanReadable); + + // Concatenate the criterion list as the command result + CUtility::asString(results, result); + return CommandHandler::ESucceeded; + } +} + +Parser::CommandReturn Parser::listDomains(const IRemoteCommand&, std::string& result) +{ + mParameterMgr.getConfigurableDomains()->listDomains(result); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::createDomain(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.createDomain(remoteCommand.getArgument(0), + result) ? CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::deleteDomain(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.deleteDomain(remoteCommand.getArgument(0), + result) ? CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::deleteAllDomains(const IRemoteCommand&, std::string& result) +{ + return mParameterMgr.deleteAllDomains(result) ? CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::renameDomain(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.renameDomain(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + result) ? CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::setSequenceAwareness(const IRemoteCommand& remoteCommand, std::string& result) +{ + // Set property + bool bSequenceAware; + + if (remoteCommand.getArgument(1) == "true") { + + bSequenceAware = true; + + } else if (remoteCommand.getArgument(1) == "false") { + + bSequenceAware = false; + + } else { + // Show usage + return CommandHandler::EShowUsage; + } + + return mParameterMgr.setSequenceAwareness(remoteCommand.getArgument(0), + bSequenceAware, + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::getSequenceAwareness(const IRemoteCommand& remoteCommand, std::string& result) +{ + // Get property + bool bSequenceAware; + + if (!mParameterMgr.getSequenceAwareness(remoteCommand.getArgument(0), bSequenceAware, result)) { + return CommandHandler::EFailed; + } + result = bSequenceAware ? "true" : "false"; + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::listDomainElements(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.getConfigurableDomains()->listDomainElements(remoteCommand.getArgument(0), + result) ? + CommandHandler::ESucceeded : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::addElement(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.addConfigurableElementToDomain(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::removeElement(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.removeConfigurableElementFromDomain(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::splitDomain(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.split(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + result) ? CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::listConfigurations(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.getConstConfigurableDomains()->listConfigurations( + remoteCommand.getArgument(0), result) ? + CommandHandler::ESucceeded : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::dumpDomains(const IRemoteCommand&, std::string& result) +{ + // Dummy error context + std::string strError; + CErrorContext errorContext(strError); + // Dump + mParameterMgr.getConstConfigurableDomains()->dumpContent(result, errorContext); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::createConfiguration(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.createConfiguration(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::deleteConfiguration(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.deleteConfiguration(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::renameConfiguration(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.renameConfiguration(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + remoteCommand.getArgument(2), + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::saveConfiguration(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.saveConfiguration(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::restoreConfiguration(const IRemoteCommand& remoteCommand, std::string& result) +{ + core::Results results; + if (!mParameterMgr.restoreConfiguration( + remoteCommand.getArgument(0), remoteCommand.getArgument(1), results)) { + // Concatenate the error list as the command result + CUtility::asString(results, result); + return CommandHandler::EFailed; + } + return CommandHandler::EDone; +} + +Parser::CommandReturn Parser::setElementSequence(const IRemoteCommand& remoteCommand, + std::string& result) +{ + // Build configurable element path list + std::vector astrNewElementSequence; + + uint32_t uiArgument; + + for (uiArgument = 2; uiArgument < remoteCommand.getArgumentCount(); uiArgument++) { + + astrNewElementSequence.push_back(remoteCommand.getArgument(uiArgument)); + } + + // Delegate to configurable domains + return mParameterMgr.setElementSequence(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + astrNewElementSequence, + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::getElementSequence(const IRemoteCommand& remoteCommand, + std::string& result) +{ + // Delegate to configurable domains + return mParameterMgr.getConfigurableDomains()->getElementSequence(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + result) ? + CommandHandler::ESucceeded : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::setRule(const IRemoteCommand& remoteCommand, + std::string& result) +{ + // Delegate to configurable domains + return mParameterMgr.setApplicationRule(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + remoteCommand.packArguments( + 2, remoteCommand.getArgumentCount() - 2), + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::clearRule(const IRemoteCommand& remoteCommand, + std::string& result) +{ + // Delegate to configurable domains + return mParameterMgr.clearApplicationRule(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::getRule(const IRemoteCommand& remoteCommand, + std::string& result) +{ + // Delegate to configurable domains + return mParameterMgr.getApplicationRule(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + result) ? + CommandHandler::ESucceeded : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::listElements(const IRemoteCommand& remoteCommand, + std::string& result) +{ + CElementLocator elementLocator(mParameterMgr.getSystemClass(), false); + CElement* pLocatedElement = NULL; + + if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, result)) { + return CommandHandler::EFailed; + } + + result = std::string("\n"); + if (!pLocatedElement) { + // List from root folder + // Return system class qualified name + pLocatedElement = mParameterMgr.getSystemClass(); + } + // Return sub-elements + result += pLocatedElement->listQualifiedPaths(false); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::listParameters(const IRemoteCommand& remoteCommand, + std::string& result) +{ + CElementLocator elementLocator(mParameterMgr.getSystemClass(), false); + CElement* pLocatedElement = NULL; + + if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, result)) { + return CommandHandler::EFailed; + } + + result = std::string("\n"); + if (!pLocatedElement) { + // List from root folder + // Return system class qualified name + pLocatedElement = mParameterMgr.getSystemClass(); + } + // Return sub-elements + result += pLocatedElement->listQualifiedPaths(true); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::dumpElement(const IRemoteCommand& remoteCommand, + std::string& result) +{ + CElementLocator elementLocator(mParameterMgr.getSystemClass()); + CElement* pLocatedElement = NULL; + + if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, result)) { + return CommandHandler::EFailed; + } + + std::string strError; + CParameterAccessContext parameterAccessContext(strError, + mParameterMgr._pMainParameterBlackboard, + mParameterMgr._bValueSpaceIsRaw, + mParameterMgr._bOutputRawFormatIsHex); + // Dump elements + pLocatedElement->dumpContent(result, parameterAccessContext); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::getElementSize(const IRemoteCommand& remoteCommand, + std::string& result) +{ + CElementLocator elementLocator(mParameterMgr.getSystemClass()); + CElement* pLocatedElement = NULL; + + if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, result)) { + return CommandHandler::EFailed; + } + + // Converted to actual sizable element + const CConfigurableElement* pConfigurableElement = + static_cast(pLocatedElement); + // Get size as string + result = pConfigurableElement->getFootprintAsString(); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::showProperties(const IRemoteCommand& remoteCommand, + std::string& result) +{ + CElementLocator elementLocator(mParameterMgr.getSystemClass()); + CElement* pLocatedElement = NULL; + + if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, result)) { + return CommandHandler::EFailed; + } + + // Convert element + const CConfigurableElement* pConfigurableElement = + static_cast(pLocatedElement); + // Return element properties + pConfigurableElement->showProperties(result); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::getParameter(const IRemoteCommand& remoteCommand, + std::string& result) +{ + if (!mParameterMgr.accessParameterValue(remoteCommand.getArgument(0), result, false, result)) { + return CommandHandler::EFailed; + } + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::setParameter(const IRemoteCommand& remoteCommand, + std::string& result) +{ + // Get value to set + std::string strValue = remoteCommand.packArguments(1, remoteCommand.getArgumentCount() - 1); + + return mParameterMgr.accessParameterValue(remoteCommand.getArgument(0), + strValue, + true, + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::listBelongingDomains(const IRemoteCommand& remoteCommand, std::string& result) +{ + CElementLocator elementLocator(mParameterMgr.getSystemClass()); + CElement* pLocatedElement = NULL; + + if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, result)) { + return CommandHandler::EFailed; + } + + // Convert element + const CConfigurableElement* pConfigurableElement = + static_cast(pLocatedElement); + // Return element belonging domains + pConfigurableElement->listBelongingDomains(result); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn +Parser::listAssociatedDomains(const IRemoteCommand& remoteCommand, std::string& result) +{ + CElementLocator elementLocator(mParameterMgr.getSystemClass()); + CElement* pLocatedElement = NULL; + + if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, result)) { + return CommandHandler::EFailed; + } + // Convert element + const CConfigurableElement* pConfigurableElement = + static_cast(pLocatedElement); + // Return element belonging domains + pConfigurableElement->listAssociatedDomains(result); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::listAssociatedElements(const IRemoteCommand&, std::string& result) +{ + mParameterMgr.getConfigurableDomains()->listAssociatedElements(result); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::listConflictingElements(const IRemoteCommand&, std::string& result) +{ + mParameterMgr.getConfigurableDomains()->listConflictingElements(result); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::listRogueElements(const IRemoteCommand&, std::string& result) +{ + mParameterMgr.getSystemClass()->listRogueElements(result); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::getConfigurationParameter(const IRemoteCommand& remoteCommand, + std::string& result) +{ + std::string output; + if (!mParameterMgr.accessConfigurationValue( + remoteCommand.getArgument(0), remoteCommand.getArgument(1), + remoteCommand.getArgument(2), output, false, result)) { + return CommandHandler::EFailed; + } + // Succeeded + result = output; + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn +Parser::setConfigurationParameter(const IRemoteCommand& remoteCommand, std::string& result) +{ + // Get value to set + std::string strValue = remoteCommand.packArguments(3, remoteCommand.getArgumentCount() - 3); + + bool bSuccess = mParameterMgr.accessConfigurationValue(remoteCommand.getArgument(0), + remoteCommand.getArgument(1), + remoteCommand.getArgument(2), + strValue, true, result); + + return bSuccess ? CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::showMapping(const IRemoteCommand& remoteCommand, std::string& result) +{ + if (!mParameterMgr.getParameterMapping(remoteCommand.getArgument(0), result)) { + return CommandHandler::EFailed; + } + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn +Parser::exportConfigurableDomainsToXML(const IRemoteCommand& remoteCommand, std::string& result) +{ + std::string strFileName = remoteCommand.getArgument(0); + return mParameterMgr.exportDomainsXml(strFileName, false, true, result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::importConfigurableDomainsFromXML(const IRemoteCommand& remoteCommand, std::string& result) +{ + return mParameterMgr.importDomainsXml(remoteCommand.getArgument(0), false, true, result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::exportConfigurableDomainsWithSettingsToXML(const IRemoteCommand& remoteCommand, + std::string& result) +{ + std::string strFileName = remoteCommand.getArgument(0); + return mParameterMgr.exportDomainsXml(strFileName, true, true, result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::importConfigurableDomainsWithSettingsFromXML(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.importDomainsXml(remoteCommand.getArgument(0), true, true, result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::importConfigurableDomainWithSettingsFromXML(const IRemoteCommand& remoteCommand, + std::string& result) +{ + bool bOverwrite = false; + + // Look for optional arguments + if (remoteCommand.getArgumentCount() > 1) { + + if (remoteCommand.getArgument(1) == "overwrite") { + + bOverwrite = true; + } else { + // Show usage + return CommandHandler::EShowUsage; + } + } + + return mParameterMgr.importSingleDomainXml(remoteCommand.getArgument(0), + bOverwrite, + result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::exportSettings(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.exportDomainsBinary(remoteCommand.getArgument(0), result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::importSettings(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.importDomainsBinary(remoteCommand.getArgument(0), result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::getConfigurableDomainsWithSettingsXML(const IRemoteCommand&, + std::string& result) +{ + if (!mParameterMgr.exportDomainsXml(result, true, false, result)) { + + return CommandHandler::EFailed; + } + // Succeeded + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn +Parser::getConfigurableDomainWithSettingsXML(const IRemoteCommand& remoteCommand, + std::string& result) +{ + std::string strDomainName = remoteCommand.getArgument(0); + + return mParameterMgr.exportSingleDomainXml(result, strDomainName, true, false, result) ? + CommandHandler::ESucceeded : CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::setConfigurableDomainsWithSettingsXML(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mParameterMgr.importDomainsXml(remoteCommand.getArgument(0), true, false, result) ? + CommandHandler::EDone : CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::getSystemClassXML(const IRemoteCommand&, std::string& result) +{ + // Get Root element where to export from + const CSystemClass* pSystemClass = mParameterMgr.getSystemClass(); + + if (!mParameterMgr.exportElementToXMLString( + pSystemClass, pSystemClass->getKind(), result)) { + + return CommandHandler::EFailed; + } + // Succeeded + return CommandHandler::ESucceeded; +} + +} /** command namespace */ +} /** core namespace */ From b5ce6ec1d07203dd86e454d4f91e68c239c1b3f9 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Fri, 20 Feb 2015 18:13:46 +0100 Subject: [PATCH 22/30] Remove deprecated getDomainsXml command support Signed-off-by: Jules Clero --- parameter/command/src/Parser.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/parameter/command/src/Parser.cpp b/parameter/command/src/Parser.cpp index 89283728d..2c5fda838 100644 --- a/parameter/command/src/Parser.cpp +++ b/parameter/command/src/Parser.cpp @@ -205,11 +205,6 @@ const Parser::RemoteCommandParserItem Parser::gRemoteCommandParserItems[] = { /// Structure Export { "getSystemClassXML", &Parser::getSystemClassXML, 0, "", "Print parameter structure as XML" }, - /// Deprecated Commands - { "getDomainsXML", - &Parser::getConfigurableDomainsWithSettingsXML, 0, - "", "DEPRECATED COMMAND, please use getDomainsWithSettingsXML" }, - }; // Remote command parsers array Size From efc558ceec5cf5bc41138b9c1f3b7cab3499f916 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 23 Feb 2015 08:53:31 +0100 Subject: [PATCH 23/30] Remove RemoteCommandParser callback definition of CommandParser This typedef is already defined in RemoteCommandHandlerTemplate class. As we include its header, we can use it directly. Signed-off-by: Jules Clero --- parameter/command/include/command/Parser.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/parameter/command/include/command/Parser.h b/parameter/command/include/command/Parser.h index 244a73872..91bc3e299 100644 --- a/parameter/command/include/command/Parser.h +++ b/parameter/command/include/command/Parser.h @@ -48,15 +48,12 @@ class Parser /** Remote command Handler type */ typedef TRemoteCommandHandlerTemplate CommandHandler; - typedef CommandHandler::CommandStatus - (Parser::*RemoteCommandParser)( - const IRemoteCommand& remoteCommand, std::string& result); /** Parser items description */ struct RemoteCommandParserItem { const char* _pcCommandName; - Parser::RemoteCommandParser _pfnParser; + CommandHandler::RemoteCommandParser _pfnParser; uint32_t _uiMinArgumentCount; const char* _pcHelp; const char* _pcDescription; From 6bf14335edb279aab202e27400ae5395982edb18 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 23 Feb 2015 10:00:14 +0100 Subject: [PATCH 24/30] Refactor remote commands handling Remote commands was organised through a vector and browsed many times. This patch introduces the use of a map to use only one command structure and to enhance browsing. Signed-off-by: Jules Clero --- parameter/command/include/command/Parser.h | 18 +- parameter/command/src/Parser.cpp | 339 +++++++++--------- .../RemoteCommandHandlerTemplate.h | 192 ++++------ test/test-platform/TestPlatform.cpp | 122 +++---- test/test-platform/TestPlatform.h | 7 +- 5 files changed, 291 insertions(+), 387 deletions(-) diff --git a/parameter/command/include/command/Parser.h b/parameter/command/include/command/Parser.h index 91bc3e299..f1e099a3e 100644 --- a/parameter/command/include/command/Parser.h +++ b/parameter/command/include/command/Parser.h @@ -48,17 +48,6 @@ class Parser /** Remote command Handler type */ typedef TRemoteCommandHandlerTemplate CommandHandler; - - /** Parser items description */ - struct RemoteCommandParserItem - { - const char* _pcCommandName; - CommandHandler::RemoteCommandParser _pfnParser; - uint32_t _uiMinArgumentCount; - const char* _pcHelp; - const char* _pcDescription; - }; - /** Class constructor * * @param parameterMgr pointer @@ -219,11 +208,8 @@ class Parser CommandReturn getSystemClassXML(const IRemoteCommand& remoteCommand, std::string& result); //@} - /** Parser items array */ - static const RemoteCommandParserItem gRemoteCommandParserItems[]; - - /** Parser items array size */ - static const uint32_t gNbRemoteCommandParserItems; + /** Parser items map */ + static const CommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; /** Parameter Manager used to delegate parsed commands */ CParameterMgr& mParameterMgr; diff --git a/parameter/command/src/Parser.cpp b/parameter/command/src/Parser.cpp index 2c5fda838..7e07b0818 100644 --- a/parameter/command/src/Parser.cpp +++ b/parameter/command/src/Parser.cpp @@ -46,188 +46,183 @@ namespace core namespace command { -const Parser::RemoteCommandParserItem Parser::gRemoteCommandParserItems[] = { - - /// Version - { "version", &Parser::version, 0, - "", "Show version" }, - - /// Status - { "status", &Parser::status, 0, "", - "Show current status" }, - - /// Tuning Mode - { "setTuningMode", &Parser::setTuningMode, 1, - "on|off*", "Turn on or off Tuning Mode" }, - { "getTuningMode", &Parser::getTuningMode, 0, - "", "Show Tuning Mode" }, - - /// Value Space - { "setValueSpace", &Parser::setValueSpace, 1, - "raw|real*", "Assigns Value Space used for parameter value interpretation" }, - { "getValueSpace", &Parser::getValueSpace, 0, - "", "Show Value Space" }, - - /// Output Raw Format - { "setOutputRawFormat", &Parser::setOutputRawFormat, 1, - "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" }, - { "getOutputRawFormat", &Parser::getOutputRawFormat, 0, - "", "Show Output Raw Format" }, - - /// Sync - { "setAutoSync", &Parser::setAutoSync, 1, - "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" }, - { "getAutoSync", &Parser::getAutoSync, 0, - "", "Show Auto Sync state" }, - { "sync", &Parser::sync, 0, - "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" }, - - /// Criteria - { "listCriteria", &Parser::listCriteria, 0, - "[CSV|XML]", "List selection criteria" }, - - /// Domains - { "listDomains", &Parser::listDomains, 0, - "", "List configurable domains" }, - { "dumpDomains", &Parser::dumpDomains, 0, - "", "Show all domains and configurations, including applicability conditions" }, - { "createDomain", &Parser::createDomain, 1, - "", "Create new configurable domain" }, - { "deleteDomain", &Parser::deleteDomain, 1, - "", "Delete configurable domain" }, - { "deleteAllDomains", &Parser::deleteAllDomains, 0, - "", "Delete all configurable domains" }, - { "renameDomain", &Parser::renameDomain, 2, - " ", "Rename configurable domain" }, - { "setSequenceAwareness", &Parser::setSequenceAwareness, 1, - " true|false*", "Set configurable domain sequence awareness" }, - { "getSequenceAwareness", &Parser::getSequenceAwareness, 1, - "", "Get configurable domain sequence awareness" }, - { "listDomainElements", &Parser::listDomainElements, 1, - "", "List elements associated to configurable domain" }, - { "addElement", &Parser::addElement, 2, - " ", "Associate element at given path to configurable domain" }, - { "removeElement", &Parser::removeElement, 2, - " ", "Dissociate element at given path from configurable domain" }, - { "splitDomain", &Parser::splitDomain, 2, - " ", "Split configurable domain at given associated element path" }, - - /// Configurations - { "listConfigurations", &Parser::listConfigurations, 1, - "", "List domain configurations" }, - { "createConfiguration", &Parser::createConfiguration, 2, - " ", "Create new domain configuration" }, - { "deleteConfiguration", &Parser::deleteConfiguration, 2, - " ", "Delete domain configuration" }, - { "renameConfiguration", &Parser::renameConfiguration, 3, - " ", "Rename domain configuration" }, - { "saveConfiguration", &Parser::saveConfiguration, 2, - " ", "Save current settings into configuration" }, - { "restoreConfiguration", &Parser::restoreConfiguration, 2, - " ", "Restore current settings from configuration" }, - { "setElementSequence", &Parser::setElementSequence, 3, - " ", - "Set element application order for configuration" }, - { "getElementSequence", &Parser::getElementSequence, 2, - " ", "Get element application order for configuration" }, - { "setRule", &Parser::setRule, 3, - " ", "Set configuration application rule" }, - { "clearRule", &Parser::clearRule, 2, - " ", "Clear configuration application rule" }, - { "getRule", &Parser::getRule, 2, - " ", "Get configuration application rule" }, - - /// Elements/Parameters - { "listElements", &Parser::listElements, 1, - "|/", "List elements under element at given path or root" }, - { "listParameters", &Parser::listParameters, 1, - "|/", "List parameters under element at given path or root" }, - { "dumpElement", &Parser::dumpElement, 1, - "", "Dump structure and content of element at given path" }, - { "getElementSize", &Parser::getElementSize, 1, - "", "Show size of element at given path" }, - { "showProperties", &Parser::showProperties, 1, - "", "Show properties of element at given path" }, - { "getParameter", &Parser::getParameter, 1, - "", "Get value for parameter at given path" }, - { "setParameter", &Parser::setParameter, 2, - " ", "Set value for parameter at given path" }, - { "listBelongingDomains", &Parser::listBelongingDomains, 1, - "", "List domain(s) element at given path belongs to" }, - { "listAssociatedDomains", &Parser::listAssociatedDomains, 1, - "", "List domain(s) element at given path is associated to" }, - { "getConfigurationParameter", &Parser::getConfigurationParameter, 3, - " ", - "Get value for parameter at given path from configuration" }, - { "setConfigurationParameter", &Parser::setConfigurationParameter, 4, - " ", - "Set value for parameter at given path to configuration" }, - { "showMapping", &Parser::showMapping, 1, - "", "Show mapping for an element at given path" }, - - /// Browse - { "listAssociatedElements", &Parser::listAssociatedElements, 0, - "", "List element sub-trees associated to at least one configurable domain" }, - { "listConflictingElements", &Parser::listConflictingElements, 0, - "", "List element sub-trees contained in more than one configurable domain" }, - { "listRogueElements", &Parser::listRogueElements, 0, - "", "List element sub-trees owned by no configurable domain" }, - - /// Settings Import/Export - { "exportDomainsXML", &Parser::exportConfigurableDomainsToXML, 1, - " ", "Export domains to XML file" }, - { "importDomainsXML", &Parser::importConfigurableDomainsFromXML, 1, - "", "Import domains from XML file" }, +const Parser::CommandHandler::RemoteCommandParserItems Parser::gRemoteCommandParserItems = { + { "version", { &Parser::version, 0, "", "Show version" } }, + { "status", { &Parser::status, 0, "", "Show current status" } }, + { "setTuningMode", + { &Parser::setTuningMode, 1, "on|off*", "Turn on or off Tuning Mode" } }, + { "getTuningMode", { &Parser::getTuningMode, 0, "", "Show Tuning Mode" } }, + { "setValueSpace", + { &Parser::setValueSpace, 1, "raw|real*", + "Assigns Value Space used for parameter value interpretation" } }, + { "getValueSpace", { &Parser::getValueSpace, 0, "", "Show Value Space" } }, + { "setOutputRawFormat", + { &Parser::setOutputRawFormat, 1, "dec*|hex", + "Assigns format used to output parameter values when in raw Value Space" } }, + { "getOutputRawFormat", + { &Parser::getOutputRawFormat, 0, "", "Show Output Raw Format" } }, + { "setAutoSync", + { &Parser::setAutoSync, 1, "on*|off", + "Turn on or off automatic synchronization to hardware while in Tuning Mode" } }, + { "getAutoSync", { &Parser::getAutoSync, 0, "", "Show Auto Sync state" } }, + { "sync", + { &Parser::sync, 0, "", + "Synchronize current settings to hardware while in Tuning Mode " + "and Auto Sync off" } }, + { "listCriteria", { &Parser::listCriteria, 0, "[CSV|XML]", "List selection criteria" } }, + { "listDomains", { &Parser::listDomains, 0, "", "List configurable domains" } }, + { "dumpDomains", + { &Parser::dumpDomains, 0, "", + "Show all domains and configurations, including applicability conditions" } }, + { "createDomain", + { &Parser::createDomain, 1, "", "Create new configurable domain" } }, + { "deleteDomain", + { &Parser::deleteDomain, 1, "", "Delete configurable domain" } }, + { "deleteAllDomains", + { &Parser::deleteAllDomains, 0, "", "Delete all configurable domains" } }, + { "renameDomain", + { &Parser::renameDomain, 2, " ", + "Rename configurable domain" } }, + { "setSequenceAwareness", + { &Parser::setSequenceAwareness, 1, " true|false*", + "Set configurable domain sequence awareness" } }, + { "getSequenceAwareness", + { &Parser::getSequenceAwareness, 1, "", + "Get configurable domain sequence awareness" } }, + { "listDomainElements", + { &Parser::listDomainElements, 1, "", + "List elements associated to configurable domain" } }, + { "addElement", + { &Parser::addElement, 2, " ", + "Associate element at given path to configurable domain" } }, + { "removeElement", + { &Parser::removeElement, 2, " ", + "Dissociate element at given path from configurable domain" } }, + { "splitDomain", + { &Parser::splitDomain, 2, " ", + "Split configurable domain at given associated element path" } }, + { "listConfigurations", + { &Parser::listConfigurations, 1, "", + "List domain configurations" } }, + { "createConfiguration", + { &Parser::createConfiguration, 2, " ", + "Create new domain configuration" } }, + { "deleteConfiguration", + { &Parser::deleteConfiguration, 2, " ", + "Delete domain configuration" } }, + { "renameConfiguration", + { &Parser::renameConfiguration, 3, " ", + "Rename domain configuration" } }, + { "saveConfiguration", + { &Parser::saveConfiguration, 2, " ", + "Save current settings into configuration" } }, + { "restoreConfiguration", + { &Parser::restoreConfiguration, 2, " ", + "Restore current settings from configuration" } }, + { "setElementSequence", + { &Parser::setElementSequence, 3, + " ", + "Set element application order for configuration" } }, + { "getElementSequence", + { &Parser::getElementSequence, 2, " ", + "Get element application order for configuration" } }, + { "setRule", + { &Parser::setRule, 3, " ", + "Set configuration application rule" } }, + { "clearRule", + { &Parser::clearRule, 2, " ", + "Clear configuration application rule" } }, + { "getRule", + { &Parser::getRule, 2, " ", + "Get configuration application rule" } }, + { "listElements", + { &Parser::listElements, 1, "|/", + "List elements under element at given path or root" } }, + { "listParameters", + { &Parser::listParameters, 1, "|/", + "List parameters under element at given path or root" } }, + { "dumpElement", + { &Parser::dumpElement, 1, "", + "Dump structure and content of element at given path" } }, + { "getElementSize", + { &Parser::getElementSize, 1, "", + "Show size of element at given path" } }, + { "showProperties", + { &Parser::showProperties, 1, "", + "Show properties of element at given path" } }, + { "getParameter", + { &Parser::getParameter, 1, "", + "Get value for parameter at given path" } }, + { "setParameter", + { &Parser::setParameter, 2, " ", + "Set value for parameter at given path" } }, + { "listBelongingDomains", + { &Parser::listBelongingDomains, 1, "", + "List domain(s) element at given path belongs to" } }, + { "listAssociatedDomains", + { &Parser::listAssociatedDomains, 1, "", + "List domain(s) element at given path is associated to" } }, + { "getConfigurationParameter", + { &Parser::getConfigurationParameter, 3, + " ", + "Get value for parameter at given path from configuration" } }, + { "setConfigurationParameter", + { &Parser::setConfigurationParameter, 4, + " ", + "Set value for parameter at given path to configuration" } }, + { "showMapping", + { &Parser::showMapping, 1, "", + "Show mapping for an element at given path" } }, + { "listAssociatedElements", + { &Parser::listAssociatedElements, 0, "", + "List element sub-trees associated to at least one configurable domain" } }, + { "listConflictingElements", + { &Parser::listConflictingElements, 0, "", + "List element sub-trees contained in more than one configurable domain" } }, + { "listRogueElements", + { &Parser::listRogueElements, 0, "", + "List element sub-trees owned by no configurable domain" } }, + { "exportDomainsXML", + { &Parser::exportConfigurableDomainsToXML, 1, " ", + "Export domains to XML file" } }, + { "importDomainsXML", + { &Parser::importConfigurableDomainsFromXML, 1, "", + "Import domains from XML file" } }, { "exportDomainsWithSettingsXML", - &Parser::exportConfigurableDomainsWithSettingsToXML, 1, - " ", "Export domains including settings to XML file" }, + { &Parser::exportConfigurableDomainsWithSettingsToXML, 1, " ", + "Export domains including settings to XML file" } }, { "importDomainsWithSettingsXML", - &Parser::importConfigurableDomainsWithSettingsFromXML, 1, - "", "Import domains including settings from XML file" }, + { &Parser::importConfigurableDomainsWithSettingsFromXML, 1, "", + "Import domains including settings from XML file" } }, { "importDomainWithSettingsXML", - &Parser::importConfigurableDomainWithSettingsFromXML, 1, - " [overwrite]", "Import a single domain including settings from XML file." - " Does not overwrite an existing domain unless 'overwrite' is passed as second" - " argument" }, - { "exportSettings", &Parser::exportSettings, 1, - "", "Export settings to binary file" }, - { "importSettings", &Parser::importSettings, 1, - "", "Import settings from binary file" }, + { &Parser::importConfigurableDomainWithSettingsFromXML, 1, + " [overwrite]", + "Import a single domain including settings from XML file." + " Does not overwrite an existing domain unless 'overwrite' is passed as second" + " argument" } }, + { "exportSettings", + { &Parser::exportSettings, 1, "", + "Export settings to binary file" } }, + { "importSettings", + { &Parser::importSettings, 1, "", + "Import settings from binary file" } }, { "getDomainsWithSettingsXML", - &Parser::getConfigurableDomainsWithSettingsXML, 0, - "", "Print domains including settings as XML" }, + { &Parser::getConfigurableDomainsWithSettingsXML, 0, "", + "Print domains including settings as XML" } }, { "getDomainWithSettingsXML", - &Parser::getConfigurableDomainWithSettingsXML, 1, - "", "Print the given domain including settings as XML" }, + { &Parser::getConfigurableDomainWithSettingsXML, 1, "", + "Print the given domain including settings as XML" } }, { "setDomainsWithSettingsXML", - &Parser::setConfigurableDomainsWithSettingsXML, 1, - "", "Import domains including settings from XML string" }, - /// Structure Export - { "getSystemClassXML", &Parser::getSystemClassXML, 0, - "", "Print parameter structure as XML" }, + { &Parser::setConfigurableDomainsWithSettingsXML, 1, + "", + "Import domains including settings from XML string" } }, + { "getSystemClassXML", + { &Parser::getSystemClassXML, 0, "", "Print parameter structure as XML" } }, }; -// Remote command parsers array Size -const uint32_t Parser::gNbRemoteCommandParserItems = - sizeof(gRemoteCommandParserItems) / sizeof(gRemoteCommandParserItems[0]); - Parser::Parser(CParameterMgr& parameterMgr) : - mParameterMgr(parameterMgr), mCommandHandler(CommandHandler(this)) + mParameterMgr(parameterMgr), mCommandHandler(CommandHandler(this, gRemoteCommandParserItems)) { - // Add command parsers - uint32_t uiRemoteCommandParserItem; - - for (uiRemoteCommandParserItem = 0; - uiRemoteCommandParserItem < gNbRemoteCommandParserItems; uiRemoteCommandParserItem++) { - const RemoteCommandParserItem* pRemoteCommandParserItem = - &gRemoteCommandParserItems[uiRemoteCommandParserItem]; - - mCommandHandler.addCommandParser(pRemoteCommandParserItem->_pcCommandName, - pRemoteCommandParserItem->_pfnParser, - pRemoteCommandParserItem->_uiMinArgumentCount, - pRemoteCommandParserItem->_pcHelp, - pRemoteCommandParserItem->_pcDescription); - } } Parser::CommandHandler* Parser::getCommandHandler() diff --git a/remote-processor/RemoteCommandHandlerTemplate.h b/remote-processor/RemoteCommandHandlerTemplate.h index 0b7428dbf..17502a706 100644 --- a/remote-processor/RemoteCommandHandlerTemplate.h +++ b/remote-processor/RemoteCommandHandlerTemplate.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,8 +29,9 @@ */ #pragma once -#include #include "RemoteCommandHandler.h" +#include +#include template class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler @@ -53,26 +54,18 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler */ typedef CommandStatus (CCommandParser::*RemoteCommandParser)(const IRemoteCommand& remoteCommand, std::string& strResult); -private: // Parser descriptions - class CRemoteCommandParserItem + class RemoteCommandParserItem { public: - CRemoteCommandParserItem(const std::string& strCommandName, - RemoteCommandParser pfnParser, - uint32_t uiMinArgumentCount, - const std::string& strHelp, - const std::string& strDescription) - : _strCommandName(strCommandName), - _pfnParser(pfnParser), - _uiMinArgumentCount(uiMinArgumentCount), - _strHelp(strHelp), - _strDescription(strDescription) {} - - const std::string& getCommandName() const - { - return _strCommandName; - } + RemoteCommandParserItem(RemoteCommandParser pfnParser, + uint32_t uiMinArgumentCount, + const std::string& strHelp, + const std::string& strDescription) : + _pfnParser(pfnParser), + _uiMinArgumentCount(uiMinArgumentCount), + _strHelp(strHelp), + _strDescription(strDescription) {} const std::string& getDescription() const { @@ -82,7 +75,7 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler // Usage std::string usage() const { - return _strCommandName + " " + _strHelp; + return _strHelp; } bool parse(CCommandParser* pCommandParser, const IRemoteCommand& remoteCommand, std::string& strResult) const @@ -112,7 +105,6 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler } private: - std::string _strCommandName; RemoteCommandParser _pfnParser; uint32_t _uiMinArgumentCount; std::string _strHelp; @@ -120,136 +112,84 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler }; public: - TRemoteCommandHandlerTemplate(CCommandParser* pCommandParser) : _pCommandParser(pCommandParser), _uiMaxCommandUsageLength(0) - { - // Help Command - addCommandParser("help", NULL, 0, "", "Show commands description and usage"); - } - ~TRemoteCommandHandlerTemplate() - { - uint32_t uiIndex; - for (uiIndex = 0; uiIndex < _remoteCommandParserVector.size(); uiIndex++) { + /** Remote command parser container type */ + typedef std::map RemoteCommandParserItems; - delete _remoteCommandParserVector[uiIndex]; - } - } - - // Parsers - bool addCommandParser(const std::string& strCommandName, - RemoteCommandParser pfnParser, - uint32_t uiMinArgumentCount, - const std::string& strHelp, - const std::string& strDescription) + /** + * @param pCommandParser pointer on command parser used for command handling + * @param remoteCommandParserItems supported command parser items + */ + TRemoteCommandHandlerTemplate(CCommandParser* pCommandParser, + const RemoteCommandParserItems& remoteCommandParserItems) : + _pCommandParser(pCommandParser), _remoteCommandParserItems(remoteCommandParserItems) { - if (findCommandParserItem(strCommandName)) { - - // Already exists - return false; - } - - // Add command - _remoteCommandParserVector.push_back(new CRemoteCommandParserItem(strCommandName, pfnParser, uiMinArgumentCount, strHelp, strDescription)); - - return true; } private: // Command processing bool remoteCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult) { - // Dispatch - const CRemoteCommandParserItem* pRemoteCommandParserItem = findCommandParserItem(remoteCommand.getCommand()); - - if (!pRemoteCommandParserItem) { - - // Not found - strResult = "Command not found!\nUse \"help\" to show available commands"; + try { + // Dispatch + const RemoteCommandParserItem& remoteCommandParserItem = + _remoteCommandParserItems.at(remoteCommand.getCommand()); - return false; + return remoteCommandParserItem.parse(_pCommandParser, remoteCommand, strResult); } + catch (const std::out_of_range&) { - if (remoteCommand.getCommand() == "help") { - - helpCommandProcess(strResult); - - return true; - } - - return pRemoteCommandParserItem->parse(_pCommandParser, remoteCommand, strResult); - } - - // Max command usage length, use for formatting - void initMaxCommandUsageLength() - { - if (!_uiMaxCommandUsageLength) { - // Show usages - uint32_t uiIndex; - - for (uiIndex = 0; uiIndex < _remoteCommandParserVector.size(); uiIndex++) { + if (remoteCommand.getCommand() == helpCommand) { - const CRemoteCommandParserItem* pRemoteCommandParserItem = _remoteCommandParserVector[uiIndex]; + help(strResult); - uint32_t uiRemoteCommandUsageLength = (uint32_t)pRemoteCommandParserItem->usage().length(); + return true; + } - if (uiRemoteCommandUsageLength > _uiMaxCommandUsageLength) { + // Not found + strResult = "Command not found!\nUse \"help\" to show available commands"; - _uiMaxCommandUsageLength = uiRemoteCommandUsageLength; - } - } + return false; } } - /////////////////// Remote command parsers - /// Help - void helpCommandProcess(std::string& strResult) + /** Format help display + * + * @param result the formatted help string + */ + void help(std::string& result) { - initMaxCommandUsageLength(); - - strResult = "\n"; - - // Show usages - uint32_t uiIndex; - - for (uiIndex = 0; uiIndex < _remoteCommandParserVector.size(); uiIndex++) { - - const CRemoteCommandParserItem* pRemoteCommandParserItem = _remoteCommandParserVector[uiIndex]; - - std::string strUsage = pRemoteCommandParserItem->usage(); - - strResult += strUsage; - - // Align - uint32_t uiToSpacesAdd = _uiMaxCommandUsageLength + 5 - (uint32_t)strUsage.length(); - - while (uiToSpacesAdd--) { - - strResult += " "; - } + struct Help { std::string usage; std::string description; }; + std::vector helps{ { helpCommand, helpCommandDescription } }; + size_t maxUsage = helpCommand.length(); + + for (auto& item : _remoteCommandParserItems) { + std::string usage = item.first + ' ' + item.second.usage(); + helps.push_back({ usage, item.second.getDescription() }); + maxUsage = std::max(maxUsage, usage.length()); + } - strResult += std::string("=> ") + std::string(pRemoteCommandParserItem->getDescription()) + "\n"; + for (auto& help : helps) { + help.usage.resize(maxUsage, ' '); + result += help.usage + " => " + help.description + '\n'; } } - const CRemoteCommandParserItem* findCommandParserItem(const std::string& strCommandName) const - { - uint32_t uiIndex; - - for (uiIndex = 0; uiIndex < _remoteCommandParserVector.size(); uiIndex++) { - - const CRemoteCommandParserItem* pRemoteCommandParserItem = _remoteCommandParserVector[uiIndex]; + /** Help command name */ + static const std::string helpCommand; - if (pRemoteCommandParserItem->getCommandName() == strCommandName) { + /** Help command description */ + static const std::string helpCommandDescription; - return pRemoteCommandParserItem; - } - } - return NULL; - } - -private: CCommandParser* _pCommandParser; - std::vector _remoteCommandParserVector; - uint32_t _uiMaxCommandUsageLength; + + /** Remote command parser map */ + const RemoteCommandParserItems& _remoteCommandParserItems; }; +template +const std::string TRemoteCommandHandlerTemplate::helpCommand = "help"; + +template +const std::string TRemoteCommandHandlerTemplate::helpCommandDescription = + "Show commands description and usage"; diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index 0153514f4..a0574f509 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -58,83 +58,64 @@ class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnect } }; +const CTestPlatform::CCommandHandler::RemoteCommandParserItems CTestPlatform:: +gRemoteCommandParserItems = { + { "exit", { &CTestPlatform::exit, 0, "", "Exit TestPlatform" } }, + { "createExclusiveSelectionCriterionFromStateList", + { &CTestPlatform::createExclusiveSelectionCriterionFromStateList, 2, " ", + "Create inclusive selection criterion from state name list" } }, + { "createInclusiveSelectionCriterionFromStateList", + { &CTestPlatform::createInclusiveSelectionCriterionFromStateList, 2, " ", + "Create exclusive selection criterion from state name list" } }, + { "createExclusiveSelectionCriterion", + { &CTestPlatform::createExclusiveSelectionCriterion, 2, " ", + "Create inclusive selection criterion" } }, + { "createInclusiveSelectionCriterion", + { &CTestPlatform::createInclusiveSelectionCriterion, 2, " ", + "Create exclusive selection criterion" } }, + { "start", { &CTestPlatform::startParameterMgr, 0, "", "Start ParameterMgr" } }, + { "setCriterionState", + { &CTestPlatform::setCriterionState, 2, " ", + "Set the current state of a selection criterion" } }, + { "applyConfigurations", + { &CTestPlatform::applyConfigurations, 0, "", + "Apply configurations selected by current selection criteria states" } }, + { "setFailureOnMissingSubsystem", + { &CTestPlatform::setter<& CParameterMgrPlatformConnector::setFailureOnMissingSubsystem>, 1, + "true|false", + "Set policy for missing subsystems, " + "either abort start or fallback on virtual subsystem." } }, + { "getMissingSubsystemPolicy", + { &CTestPlatform::getter<& CParameterMgrPlatformConnector::getFailureOnMissingSubsystem>, 0, + "", + "Get policy for missing subsystems, " + "either abort start or fallback on virtual subsystem." } }, + { "setFailureOnFailedSettingsLoad", + { &CTestPlatform::setter<& CParameterMgrPlatformConnector::setFailureOnFailedSettingsLoad>, + 1, "true|false", + "Set policy for failed settings load, either abort start or continue without domains." }}, + { "getFailedSettingsLoadPolicy", + { &CTestPlatform::getter<& CParameterMgrPlatformConnector::getFailureOnFailedSettingsLoad>, + 0, "", + "Get policy for failed settings load, either abort start or continue without domains." }}, + { "setValidateSchemasOnStart", + { &CTestPlatform::setter<& CParameterMgrPlatformConnector::setValidateSchemasOnStart>, 1, + "true|false", + "Set policy for schema validation based on .xsd files (false by default)." } }, + { "getValidateSchemasOnStart", + { &CTestPlatform::getter<& CParameterMgrPlatformConnector::getValidateSchemasOnStart>, 0, + "", "Get policy for schema validation based on .xsd files." } } +}; + CTestPlatform::CTestPlatform(const string& strClass, int iPortNumber, sem_t& exitSemaphore) : _pParameterMgrPlatformConnector(new CParameterMgrPlatformConnector(strClass)), _pParameterMgrPlatformConnectorLogger(new CParameterMgrPlatformConnectorLogger), + _commandHandler(this, gRemoteCommandParserItems), _portNumber(iPortNumber), _exitSemaphore(exitSemaphore) { - _pCommandHandler = new CCommandHandler(this); - - // Add command parsers - _pCommandHandler->addCommandParser("exit", &CTestPlatform::exit, - 0, "", "Exit TestPlatform"); - _pCommandHandler->addCommandParser( - "createExclusiveSelectionCriterionFromStateList", - &CTestPlatform::createExclusiveSelectionCriterionFromStateList, - 2, " ", - "Create inclusive selection criterion from state name list"); - _pCommandHandler->addCommandParser( - "createInclusiveSelectionCriterionFromStateList", - &CTestPlatform::createInclusiveSelectionCriterionFromStateList, - 2, " ", - "Create exclusive selection criterion from state name list"); - - _pCommandHandler->addCommandParser( - "createExclusiveSelectionCriterion", - &CTestPlatform::createExclusiveSelectionCriterion, - 2, " ", "Create inclusive selection criterion"); - _pCommandHandler->addCommandParser( - "createInclusiveSelectionCriterion", - &CTestPlatform::createInclusiveSelectionCriterion, - 2, " ", "Create exclusive selection criterion"); - - _pCommandHandler->addCommandParser("start", &CTestPlatform::startParameterMgr, - 0, "", "Start ParameterMgr"); - - _pCommandHandler->addCommandParser("setCriterionState", &CTestPlatform::setCriterionState, - 2, " ", - "Set the current state of a selection criterion"); - _pCommandHandler->addCommandParser( - "applyConfigurations", - &CTestPlatform::applyConfigurations, - 0, "", "Apply configurations selected by current selection criteria states"); - - _pCommandHandler->addCommandParser( - "setFailureOnMissingSubsystem", - &CTestPlatform::setter<& CParameterMgrPlatformConnector::setFailureOnMissingSubsystem>, - 1, "true|false", "Set policy for missing subsystems, " - "either abort start or fallback on virtual subsystem."); - _pCommandHandler->addCommandParser( - "getMissingSubsystemPolicy", - &CTestPlatform::getter<& CParameterMgrPlatformConnector::getFailureOnMissingSubsystem>, - 0, "", "Get policy for missing subsystems, " - "either abort start or fallback on virtual subsystem."); - - _pCommandHandler->addCommandParser( - "setFailureOnFailedSettingsLoad", - &CTestPlatform::setter<& CParameterMgrPlatformConnector::setFailureOnFailedSettingsLoad>, - 1, "true|false", - "Set policy for failed settings load, either abort start or continue without domains."); - _pCommandHandler->addCommandParser( - "getFailedSettingsLoadPolicy", - &CTestPlatform::getter<& CParameterMgrPlatformConnector::getFailureOnFailedSettingsLoad>, - 0, "", - "Get policy for failed settings load, either abort start or continue without domains."); - - _pCommandHandler->addCommandParser( - "setValidateSchemasOnStart", - &CTestPlatform::setter<& CParameterMgrPlatformConnector::setValidateSchemasOnStart>, - 1, "true|false", - "Set policy for schema validation based on .xsd files (false by default)."); - _pCommandHandler->addCommandParser( - "getValidateSchemasOnStart", - &CTestPlatform::getter<& CParameterMgrPlatformConnector::getValidateSchemasOnStart>, - 0, "", - "Get policy for schema validation based on .xsd files."); - // Create server - _pRemoteProcessorServer = new CRemoteProcessorServer(iPortNumber, _pCommandHandler); + _pRemoteProcessorServer = new CRemoteProcessorServer(iPortNumber, &_commandHandler); _pParameterMgrPlatformConnector->setLogger(_pParameterMgrPlatformConnectorLogger); } @@ -142,7 +123,6 @@ CTestPlatform::CTestPlatform(const string& strClass, int iPortNumber, sem_t& exi CTestPlatform::~CTestPlatform() { delete _pRemoteProcessorServer; - delete _pCommandHandler; delete _pParameterMgrPlatformConnectorLogger; delete _pParameterMgrPlatformConnector; } diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index e9d1dd41a..d32d0c7c1 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.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, @@ -148,7 +148,7 @@ class CTestPlatform CParameterMgrPlatformConnectorLogger* _pParameterMgrPlatformConnectorLogger; // Command Handler - CCommandHandler* _pCommandHandler; + CCommandHandler _commandHandler; // Remote Processor Server CRemoteProcessorServer* _pRemoteProcessorServer; @@ -158,5 +158,8 @@ class CTestPlatform // Semaphore used by calling thread to avoid exiting sem_t& _exitSemaphore; + + /** Parsing information for remote command */ + static const CCommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; }; From f4723cdf522e6ddb3afb48034fee2d86952de463 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 9 Mar 2015 14:16:06 +0100 Subject: [PATCH 25/30] Use a reference instead of a pointer for command parsers. There is no need of using a pointer. Signed-off-by: Jules Clero --- parameter/command/src/Parser.cpp | 2 +- .../RemoteCommandHandlerTemplate.h | 24 +++++++++++++------ test/test-platform/TestPlatform.cpp | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/parameter/command/src/Parser.cpp b/parameter/command/src/Parser.cpp index 7e07b0818..c8d5474f8 100644 --- a/parameter/command/src/Parser.cpp +++ b/parameter/command/src/Parser.cpp @@ -221,7 +221,7 @@ const Parser::CommandHandler::RemoteCommandParserItems Parser::gRemoteCommandPar }; Parser::Parser(CParameterMgr& parameterMgr) : - mParameterMgr(parameterMgr), mCommandHandler(CommandHandler(this, gRemoteCommandParserItems)) + mParameterMgr(parameterMgr), mCommandHandler(CommandHandler(*this, gRemoteCommandParserItems)) { } diff --git a/remote-processor/RemoteCommandHandlerTemplate.h b/remote-processor/RemoteCommandHandlerTemplate.h index 17502a706..c0f728054 100644 --- a/remote-processor/RemoteCommandHandlerTemplate.h +++ b/remote-processor/RemoteCommandHandlerTemplate.h @@ -78,7 +78,16 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler return _strHelp; } - bool parse(CCommandParser* pCommandParser, const IRemoteCommand& remoteCommand, std::string& strResult) const + /** Parse and launch a remote command + * + * @param[in] commandParser the parser used to handle the command + * @param[in] remoteCommand the command received from client + * @param[out] strResult the command result + * @result true on success, false otherwise + */ + bool parse(CCommandParser& commandParser, + const IRemoteCommand& remoteCommand, + std::string& strResult) const { // Check enough arguments supplied if (remoteCommand.getArgumentCount() < _uiMinArgumentCount) { @@ -88,7 +97,7 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler return false; } - switch ((pCommandParser->*_pfnParser)(remoteCommand, strResult)) { + switch ((commandParser.*_pfnParser)(remoteCommand, strResult)) { case EDone: strResult = "Done"; // Fall through intentionally @@ -117,12 +126,12 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler typedef std::map RemoteCommandParserItems; /** - * @param pCommandParser pointer on command parser used for command handling + * @param commandParser command parser used for command handling * @param remoteCommandParserItems supported command parser items */ - TRemoteCommandHandlerTemplate(CCommandParser* pCommandParser, + TRemoteCommandHandlerTemplate(CCommandParser& commandParser, const RemoteCommandParserItems& remoteCommandParserItems) : - _pCommandParser(pCommandParser), _remoteCommandParserItems(remoteCommandParserItems) + _commandParser(commandParser), _remoteCommandParserItems(remoteCommandParserItems) { } @@ -135,7 +144,7 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler const RemoteCommandParserItem& remoteCommandParserItem = _remoteCommandParserItems.at(remoteCommand.getCommand()); - return remoteCommandParserItem.parse(_pCommandParser, remoteCommand, strResult); + return remoteCommandParserItem.parse(_commandParser, remoteCommand, strResult); } catch (const std::out_of_range&) { @@ -181,7 +190,8 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler /** Help command description */ static const std::string helpCommandDescription; - CCommandParser* _pCommandParser; + /** Command parser used during command during command handling */ + CCommandParser& _commandParser; /** Remote command parser map */ const RemoteCommandParserItems& _remoteCommandParserItems; diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index a0574f509..e24907a7e 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -110,7 +110,7 @@ gRemoteCommandParserItems = { CTestPlatform::CTestPlatform(const string& strClass, int iPortNumber, sem_t& exitSemaphore) : _pParameterMgrPlatformConnector(new CParameterMgrPlatformConnector(strClass)), _pParameterMgrPlatformConnectorLogger(new CParameterMgrPlatformConnectorLogger), - _commandHandler(this, gRemoteCommandParserItems), + _commandHandler(*this, gRemoteCommandParserItems), _portNumber(iPortNumber), _exitSemaphore(exitSemaphore) { From 2933993ffae798e949c54f617f17f4ff7215a1dc Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 9 Mar 2015 15:11:09 +0100 Subject: [PATCH 26/30] Fix coding style of RemoteCommandHandlerTemplate class. As RemoteCommandHandlerTemplate has been almost completely rewritten, the entire file has been commented and modified to follow new coding style rules. Signed-off-by: Jules Clero --- parameter/command/include/command/Parser.h | 2 +- .../RemoteCommandHandlerTemplate.h | 120 +++++++++++------- test/test-platform/TestPlatform.h | 2 +- 3 files changed, 79 insertions(+), 45 deletions(-) diff --git a/parameter/command/include/command/Parser.h b/parameter/command/include/command/Parser.h index f1e099a3e..978544ed2 100644 --- a/parameter/command/include/command/Parser.h +++ b/parameter/command/include/command/Parser.h @@ -46,7 +46,7 @@ class Parser public: /** Remote command Handler type */ - typedef TRemoteCommandHandlerTemplate CommandHandler; + typedef RemoteCommandHandlerTemplate CommandHandler; /** Class constructor * diff --git a/remote-processor/RemoteCommandHandlerTemplate.h b/remote-processor/RemoteCommandHandlerTemplate.h index c0f728054..ebc1d48cf 100644 --- a/remote-processor/RemoteCommandHandlerTemplate.h +++ b/remote-processor/RemoteCommandHandlerTemplate.h @@ -33,8 +33,12 @@ #include #include -template -class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler +/** Handle command of server side application + * + * @tparam CommandParser type of the parser used to handle remote commands + */ +template +class RemoteCommandHandlerTemplate : public IRemoteCommandHandler { public: /** Remote command parser execution return status */ @@ -52,60 +56,78 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler * * @return the command execution status, @see CommandStatus */ - typedef CommandStatus (CCommandParser::*RemoteCommandParser)(const IRemoteCommand& remoteCommand, std::string& strResult); + typedef CommandStatus (CommandParser::* RemoteCommandParser)(const IRemoteCommand& + remoteCommand, + std::string& strResult); - // Parser descriptions + /** Parser item definition */ class RemoteCommandParserItem { public: - RemoteCommandParserItem(RemoteCommandParser pfnParser, - uint32_t uiMinArgumentCount, - const std::string& strHelp, - const std::string& strDescription) : - _pfnParser(pfnParser), - _uiMinArgumentCount(uiMinArgumentCount), - _strHelp(strHelp), - _strDescription(strDescription) {} + /** + * @param parser command handler callback + * @param minArgumentCount command required arguments number + * @param help string containing command help + * @param description string containing command description + */ + RemoteCommandParserItem(RemoteCommandParser parser, + uint32_t minArgumentCount, + const std::string& help, + const std::string& description) : + mParser(parser), + mMinArgumentCount(minArgumentCount), + mHelp(help), + mDescription(description) + { + } + + /** Command description string getter + * + * @return the command description string + */ const std::string& getDescription() const { - return _strDescription; + return mDescription; } - // Usage - std::string usage() const + /** Command help string getter + * + * @return the command help string + */ + const std::string getHelp() const { - return _strHelp; + return mHelp; } /** Parse and launch a remote command * * @param[in] commandParser the parser used to handle the command * @param[in] remoteCommand the command received from client - * @param[out] strResult the command result + * @param[out] result the command result * @result true on success, false otherwise */ - bool parse(CCommandParser& commandParser, + bool parse(CommandParser& commandParser, const IRemoteCommand& remoteCommand, - std::string& strResult) const + std::string& result) const { // Check enough arguments supplied - if (remoteCommand.getArgumentCount() < _uiMinArgumentCount) { + if (remoteCommand.getArgumentCount() < mMinArgumentCount) { - strResult = std::string("Not enough arguments supplied\nUsage:\n") + usage(); + result = std::string("Not enough arguments supplied\nUsage:\n") + getHelp(); return false; } - switch ((commandParser.*_pfnParser)(remoteCommand, strResult)) { + switch ((commandParser.*mParser)(remoteCommand, result)) { case EDone: - strResult = "Done"; - // Fall through intentionally + result = "Done"; + // Fall through intentionally case ESucceeded: return true; case EShowUsage: - strResult = usage(); - // Fall through intentionally + result = getHelp(); + // Fall through intentionally case EFailed: return false; } @@ -114,13 +136,19 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler } private: - RemoteCommandParser _pfnParser; - uint32_t _uiMinArgumentCount; - std::string _strHelp; - std::string _strDescription; - }; -public: + /** Command Handler callback */ + RemoteCommandParser mParser; + + /** Needed arguments number */ + uint32_t mMinArgumentCount; + + /** Command help string */ + std::string mHelp; + + /** Command description string */ + std::string mDescription; + }; /** Remote command parser container type */ typedef std::map RemoteCommandParserItems; @@ -129,34 +157,40 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler * @param commandParser command parser used for command handling * @param remoteCommandParserItems supported command parser items */ - TRemoteCommandHandlerTemplate(CCommandParser& commandParser, - const RemoteCommandParserItems& remoteCommandParserItems) : + RemoteCommandHandlerTemplate(CommandParser& commandParser, + const RemoteCommandParserItems& remoteCommandParserItems) : _commandParser(commandParser), _remoteCommandParserItems(remoteCommandParserItems) { } private: - // Command processing - bool remoteCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult) + + /** Handle a remote command + * + * @param[in] remoteCommand the remote command to handle + * @param[out] result string containing the result of the handled command + * @result true on success, false otherwise + */ + bool remoteCommandProcess(const IRemoteCommand& remoteCommand, std::string& result) { try { // Dispatch const RemoteCommandParserItem& remoteCommandParserItem = _remoteCommandParserItems.at(remoteCommand.getCommand()); - return remoteCommandParserItem.parse(_commandParser, remoteCommand, strResult); + return remoteCommandParserItem.parse(_commandParser, remoteCommand, result); } catch (const std::out_of_range&) { if (remoteCommand.getCommand() == helpCommand) { - help(strResult); + help(result); return true; } // Not found - strResult = "Command not found!\nUse \"help\" to show available commands"; + result = "Command not found!\nUse \"help\" to show available commands"; return false; } @@ -173,7 +207,7 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler size_t maxUsage = helpCommand.length(); for (auto& item : _remoteCommandParserItems) { - std::string usage = item.first + ' ' + item.second.usage(); + std::string usage = item.first + ' ' + item.second.getHelp(); helps.push_back({ usage, item.second.getDescription() }); maxUsage = std::max(maxUsage, usage.length()); } @@ -191,15 +225,15 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler static const std::string helpCommandDescription; /** Command parser used during command during command handling */ - CCommandParser& _commandParser; + CommandParser& _commandParser; /** Remote command parser map */ const RemoteCommandParserItems& _remoteCommandParserItems; }; template -const std::string TRemoteCommandHandlerTemplate::helpCommand = "help"; +const std::string RemoteCommandHandlerTemplate::helpCommand = "help"; template -const std::string TRemoteCommandHandlerTemplate::helpCommandDescription = +const std::string RemoteCommandHandlerTemplate::helpCommandDescription = "Show commands description and usage"; diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index d32d0c7c1..6b59f505d 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -41,7 +41,7 @@ class ISelectionCriterionInterface; class CTestPlatform { - typedef TRemoteCommandHandlerTemplate CCommandHandler; + typedef RemoteCommandHandlerTemplate CCommandHandler; typedef CCommandHandler::CommandStatus CommandReturn; public: CTestPlatform(const std::string &strclass, int iPortNumber, sem_t& exitSemaphore); From 9fac0a4cfcd232036310f61e7e9dc4655e86046d Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 30 Mar 2015 09:19:20 +0200 Subject: [PATCH 27/30] Remove unused header from TestPlatorm Some headers in TestPlatorm implementation was present but unused, this patch removes them. Signed-off-by: Jules Clero --- test/test-platform/TestPlatform.cpp | 4 ---- test/test-platform/TestPlatform.h | 1 - 2 files changed, 5 deletions(-) diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index e24907a7e..adf593a03 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -28,14 +28,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include -#include #include #include -#include #include -#include #include "TestPlatform.h" #include "ParameterMgrPlatformConnector.h" #include "RemoteProcessorServer.h" diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index 6b59f505d..48cb38a95 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -32,7 +32,6 @@ #include "ParameterMgrPlatformConnector.h" #include "RemoteCommandHandlerTemplate.h" #include -#include #include class CParameterMgrPlatformConnectorLogger; From 45dc84c55dee324914ddffcdca3c8aed53f32c67 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Fri, 27 Mar 2015 17:35:40 +0100 Subject: [PATCH 28/30] Delegate Test-platform command Parser behavior Signed-off-by: Jules Clero --- test/test-platform/CMakeLists.txt | 8 +- test/test-platform/TestPlatform.cpp | 203 +---------------- test/test-platform/TestPlatform.h | 128 ++++------- .../command/include/command/Parser.h | 161 +++++++++++++ test/test-platform/command/src/Parser.cpp | 215 ++++++++++++++++++ test/test-platform/main.cpp | 4 +- 6 files changed, 431 insertions(+), 288 deletions(-) create mode 100644 test/test-platform/command/include/command/Parser.h create mode 100644 test/test-platform/command/src/Parser.cpp diff --git a/test/test-platform/CMakeLists.txt b/test/test-platform/CMakeLists.txt index b82405703..527053fc5 100644 --- a/test/test-platform/CMakeLists.txt +++ b/test/test-platform/CMakeLists.txt @@ -28,12 +28,14 @@ add_executable(test-platform main.cpp - TestPlatform.cpp) + TestPlatform.cpp + command/src/Parser.cpp) -# FIXME: Supress the need for the -Wno-unused-parameter -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") include_directories( + "./" + "command/include" "${PROJECT_SOURCE_DIR}/parameter/include" "${PROJECT_SOURCE_DIR}/remote-processor" "${PROJECT_SOURCE_DIR}/utility") diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index adf593a03..13a1853dd 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -28,90 +28,29 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include -#include #include "TestPlatform.h" #include "ParameterMgrPlatformConnector.h" #include "RemoteProcessorServer.h" using std::string; -class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnector::ILogger +namespace test +{ +namespace platform { -public: - CParameterMgrPlatformConnectorLogger() {} - - virtual void info(const string& log) - { - std::cout << log << std::endl; - } - - virtual void warning(const string& log) - { - std::cerr << log << std::endl; - } -}; - -const CTestPlatform::CCommandHandler::RemoteCommandParserItems CTestPlatform:: -gRemoteCommandParserItems = { - { "exit", { &CTestPlatform::exit, 0, "", "Exit TestPlatform" } }, - { "createExclusiveSelectionCriterionFromStateList", - { &CTestPlatform::createExclusiveSelectionCriterionFromStateList, 2, " ", - "Create inclusive selection criterion from state name list" } }, - { "createInclusiveSelectionCriterionFromStateList", - { &CTestPlatform::createInclusiveSelectionCriterionFromStateList, 2, " ", - "Create exclusive selection criterion from state name list" } }, - { "createExclusiveSelectionCriterion", - { &CTestPlatform::createExclusiveSelectionCriterion, 2, " ", - "Create inclusive selection criterion" } }, - { "createInclusiveSelectionCriterion", - { &CTestPlatform::createInclusiveSelectionCriterion, 2, " ", - "Create exclusive selection criterion" } }, - { "start", { &CTestPlatform::startParameterMgr, 0, "", "Start ParameterMgr" } }, - { "setCriterionState", - { &CTestPlatform::setCriterionState, 2, " ", - "Set the current state of a selection criterion" } }, - { "applyConfigurations", - { &CTestPlatform::applyConfigurations, 0, "", - "Apply configurations selected by current selection criteria states" } }, - { "setFailureOnMissingSubsystem", - { &CTestPlatform::setter<& CParameterMgrPlatformConnector::setFailureOnMissingSubsystem>, 1, - "true|false", - "Set policy for missing subsystems, " - "either abort start or fallback on virtual subsystem." } }, - { "getMissingSubsystemPolicy", - { &CTestPlatform::getter<& CParameterMgrPlatformConnector::getFailureOnMissingSubsystem>, 0, - "", - "Get policy for missing subsystems, " - "either abort start or fallback on virtual subsystem." } }, - { "setFailureOnFailedSettingsLoad", - { &CTestPlatform::setter<& CParameterMgrPlatformConnector::setFailureOnFailedSettingsLoad>, - 1, "true|false", - "Set policy for failed settings load, either abort start or continue without domains." }}, - { "getFailedSettingsLoadPolicy", - { &CTestPlatform::getter<& CParameterMgrPlatformConnector::getFailureOnFailedSettingsLoad>, - 0, "", - "Get policy for failed settings load, either abort start or continue without domains." }}, - { "setValidateSchemasOnStart", - { &CTestPlatform::setter<& CParameterMgrPlatformConnector::setValidateSchemasOnStart>, 1, - "true|false", - "Set policy for schema validation based on .xsd files (false by default)." } }, - { "getValidateSchemasOnStart", - { &CTestPlatform::getter<& CParameterMgrPlatformConnector::getValidateSchemasOnStart>, 0, - "", "Get policy for schema validation based on .xsd files." } } -}; CTestPlatform::CTestPlatform(const string& strClass, int iPortNumber, sem_t& exitSemaphore) : _pParameterMgrPlatformConnector(new CParameterMgrPlatformConnector(strClass)), - _pParameterMgrPlatformConnectorLogger(new CParameterMgrPlatformConnectorLogger), - _commandHandler(*this, gRemoteCommandParserItems), + _pParameterMgrPlatformConnectorLogger(new log::CParameterMgrPlatformConnectorLogger), + _commandParser(*this), _portNumber(iPortNumber), _exitSemaphore(exitSemaphore) { // Create server - _pRemoteProcessorServer = new CRemoteProcessorServer(iPortNumber, &_commandHandler); + _pRemoteProcessorServer = new CRemoteProcessorServer(iPortNumber, + _commandParser.getCommandHandler()); _pParameterMgrPlatformConnector->setLogger(_pParameterMgrPlatformConnectorLogger); } @@ -123,17 +62,6 @@ CTestPlatform::~CTestPlatform() delete _pParameterMgrPlatformConnector; } -CTestPlatform::CommandReturn CTestPlatform::exit( - const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - // Release the main blocking semaphore to quit application - sem_post(&_exitSemaphore); - - return CTestPlatform::CCommandHandler::EDone; -} - bool CTestPlatform::load(std::string& strError) { // Start remote processor server @@ -149,120 +77,6 @@ bool CTestPlatform::load(std::string& strError) return true; } -//////////////// Remote command parsers -/// Selection Criterion -CTestPlatform::CommandReturn CTestPlatform::createExclusiveSelectionCriterionFromStateList( - const IRemoteCommand& remoteCommand, string& strResult) -{ - return createExclusiveSelectionCriterionFromStateList( - remoteCommand.getArgument(0), remoteCommand, strResult) ? - CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; -} - -CTestPlatform::CommandReturn CTestPlatform::createInclusiveSelectionCriterionFromStateList( - const IRemoteCommand& remoteCommand, string& strResult) -{ - return createInclusiveSelectionCriterionFromStateList( - remoteCommand.getArgument(0), remoteCommand, strResult) ? - CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; -} - -CTestPlatform::CommandReturn CTestPlatform::createExclusiveSelectionCriterion( - const IRemoteCommand& remoteCommand, string& strResult) -{ - return createExclusiveSelectionCriterion( - remoteCommand.getArgument(0), - strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), - strResult) ? - CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; -} - -CTestPlatform::CommandReturn CTestPlatform::createInclusiveSelectionCriterion( - const IRemoteCommand& remoteCommand, string& strResult) -{ - return createInclusiveSelectionCriterion( - remoteCommand.getArgument(0), - strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), - strResult) ? - CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; -} - -CTestPlatform::CommandReturn CTestPlatform::startParameterMgr( - const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - return _pParameterMgrPlatformConnector->start(strResult) ? - CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; -} - -template -CTestPlatform::CommandReturn CTestPlatform::setter( - const IRemoteCommand& remoteCommand, string& strResult) -{ - const string& strAbort = remoteCommand.getArgument(0); - - bool bFail; - - if(!convertTo(strAbort, bFail)) { - return CTestPlatform::CCommandHandler::EShowUsage; - } - - return (_pParameterMgrPlatformConnector->*setFunction)(bFail, strResult) ? - CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; -} - -template -CTestPlatform::CommandReturn CTestPlatform::getter( - const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - strResult = (_pParameterMgrPlatformConnector->*getFunction)() ? "true" : "false"; - - return CTestPlatform::CCommandHandler::ESucceeded; -} - -CTestPlatform::CommandReturn CTestPlatform::setCriterionState( - const IRemoteCommand& remoteCommand, string& strResult) -{ - - bool bSuccess; - - const char* pcState = remoteCommand.getArgument(1).c_str(); - - char* pcStrEnd; - - // Reset errno to check if it is updated during the conversion (strtol/strtoul) - errno = 0; - - uint32_t state = strtoul(pcState, &pcStrEnd, 0); - - if (!errno && (*pcStrEnd == '\0')) { - // Sucessfull conversion, set criterion state by numerical state - bSuccess = setCriterionState(remoteCommand.getArgument(0), state, strResult); - - } else { - // Conversion failed, set criterion state by lexical state - bSuccess = setCriterionStateByLexicalSpace(remoteCommand, strResult); - } - - return bSuccess ? CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler:: - EFailed; - -} - -CTestPlatform::CommandReturn CTestPlatform::applyConfigurations(const IRemoteCommand& remoteCommand, - string& strResult) -{ - (void)remoteCommand; - (void)strResult; - - _pParameterMgrPlatformConnector->applyConfigurations(); - - return CTestPlatform::CCommandHandler::EDone; -} - //////////////// Remote command handlers bool CTestPlatform::createExclusiveSelectionCriterionFromStateList( @@ -493,3 +307,6 @@ bool CTestPlatform::setCriterionStateByLexicalSpace(const IRemoteCommand& remote return true; } + +} /** platform namespace */ +} /** test namespace */ diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index 48cb38a95..31b0d3d92 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -29,19 +29,47 @@ */ #pragma once +#include "command/Parser.h" #include "ParameterMgrPlatformConnector.h" -#include "RemoteCommandHandlerTemplate.h" #include #include +#include -class CParameterMgrPlatformConnectorLogger; class CRemoteProcessorServer; class ISelectionCriterionInterface; +namespace test +{ +namespace platform +{ +namespace log +{ + +/** Logger exposed to the parameter-framework */ +class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnector::ILogger +{ +public: + CParameterMgrPlatformConnectorLogger() {} + + virtual void info(const std::string& log) + { + std::cout << log << std::endl; + } + + virtual void warning(const std::string& log) + { + std::cerr << log << std::endl; + } +}; + +} /** log namespace */ + class CTestPlatform { - typedef RemoteCommandHandlerTemplate CCommandHandler; - typedef CCommandHandler::CommandStatus CommandReturn; + + /** Remote command parser has access to private command handle function */ + friend class command::Parser; + public: CTestPlatform(const std::string &strclass, int iPortNumber, sem_t& exitSemaphore); virtual ~CTestPlatform(); @@ -50,88 +78,9 @@ class CTestPlatform bool load(std::string& strError); private: - //////////////// Remote command parsers - /// Selection Criterion - CommandReturn createExclusiveSelectionCriterionFromStateList( - const IRemoteCommand& remoteCommand, std::string& strResult); - CommandReturn createInclusiveSelectionCriterionFromStateList( - const IRemoteCommand& remoteCommand, std::string& strResult); - - CommandReturn createExclusiveSelectionCriterion( - const IRemoteCommand& remoteCommand, std::string& strResult); - CommandReturn createInclusiveSelectionCriterion( - const IRemoteCommand& remoteCommand, std::string& strResult); - - /** Callback to set a criterion's value, see ISelectionCriterionInterface::setCriterionState. - * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return - * - * @param[in] remoteCommand the first argument should be the name of the criterion to set. - * if the criterion is provided in lexical space, - * the following arguments should be criterion new values - * if the criterion is provided in numerical space, - * the second argument should be the criterion new value - */ - CommandReturn setCriterionState( - const IRemoteCommand& remoteCommand, std::string& strResult); - - /** Callback to start the PFW, see CParameterMgrPlatformConnector::start. - * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return - * - * @param[in] remoteCommand is ignored - */ - CommandReturn startParameterMgr( - const IRemoteCommand& remoteCommand, std::string& strResult); - - /** Callback to apply PFW configuration, see CParameterMgrPlatformConnector::applyConfiguration. - * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return - * - * @param[in] remoteCommand is ignored - * - * @return EDone (never fails) - */ - CommandReturn applyConfigurations( - const IRemoteCommand& remoteCommand, std::string& strResult); - - /** Callback to exit the test-platform. - * - * @param[in] remoteCommand is ignored - * - * @return EDone (never fails) - */ - CommandReturn exit(const IRemoteCommand& remoteCommand, std::string& strResult); - - /** The type of a CParameterMgrPlatformConnector boolean setter. */ - typedef bool (CParameterMgrPlatformConnector::*setter_t)(bool, std::string&); - /** Template callback to create a _pParameterMgrPlatformConnector boolean setter callback. - * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return - * - * Convert the remoteCommand first argument to a boolean and call the - * template parameter function with this value. - * - * @tparam the boolean setter method. - * @param[in] remoteCommand the first argument should be ether "on" or "off". - */ - template - CommandReturn setter( - const IRemoteCommand& remoteCommand, std::string& strResult); - - /** The type of a CParameterMgrPlatformConnector boolean getter. */ - typedef bool (CParameterMgrPlatformConnector::*getter_t)(); - /** Template callback to create a ParameterMgrPlatformConnector boolean getter callback. - * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return - * - * Convert to boolean returned by the template parameter function converted to a - * std::string ("True", "False") and return it. - * - * @param the boolean getter method. - * @param[in] remoteCommand is ignored - * - * @return EDone (never fails) - */ - template - CommandReturn getter(const IRemoteCommand& remoteCommand, std::string& strResult); // Commands + // FIXME: IRemoteCommand object should be used only in command::Parser bool createExclusiveSelectionCriterionFromStateList(const std::string& strName, const IRemoteCommand& remoteCommand, std::string& strResult); bool createInclusiveSelectionCriterionFromStateList(const std::string& strName, const IRemoteCommand& remoteCommand, std::string& strResult); @@ -144,10 +93,10 @@ class CTestPlatform CParameterMgrPlatformConnector* _pParameterMgrPlatformConnector; // Logger - CParameterMgrPlatformConnectorLogger* _pParameterMgrPlatformConnectorLogger; + log::CParameterMgrPlatformConnectorLogger* _pParameterMgrPlatformConnectorLogger; - // Command Handler - CCommandHandler _commandHandler; + /** Command Parser delegate */ + command::Parser _commandParser; // Remote Processor Server CRemoteProcessorServer* _pRemoteProcessorServer; @@ -157,8 +106,7 @@ class CTestPlatform // Semaphore used by calling thread to avoid exiting sem_t& _exitSemaphore; - - /** Parsing information for remote command */ - static const CCommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; }; +} /** platform namespace */ +} /** test namespace */ diff --git a/test/test-platform/command/include/command/Parser.h b/test/test-platform/command/include/command/Parser.h new file mode 100644 index 000000000..e3aa86f0c --- /dev/null +++ b/test/test-platform/command/include/command/Parser.h @@ -0,0 +1,161 @@ +/* + * 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 "RemoteCommandHandlerTemplate.h" +#include "ParameterMgrPlatformConnector.h" +#include + +namespace test +{ +namespace platform +{ + +class CTestPlatform; + +namespace command +{ + +/** Parse remote commands and delegate actions to Test Platform */ +class Parser +{ + +public: + + /** Remote command Handler type */ + typedef RemoteCommandHandlerTemplate CommandHandler; + + /** Class constructor + * + * @param parameterMgr pointer + */ + Parser(CTestPlatform& testPlatform); + + /** Internal command handler getter + * + * @return pointer on the internal command handler + */ + CommandHandler* getCommandHandler(); + +private: + + /** Command handler method return type */ + typedef CommandHandler::CommandStatus CommandReturn; + + CommandReturn createExclusiveSelectionCriterionFromStateList( + const IRemoteCommand& remoteCommand, std::string& strResult); + CommandReturn createInclusiveSelectionCriterionFromStateList( + const IRemoteCommand& remoteCommand, std::string& strResult); + + CommandReturn createExclusiveSelectionCriterion( + const IRemoteCommand& remoteCommand, std::string& strResult); + CommandReturn createInclusiveSelectionCriterion( + const IRemoteCommand& remoteCommand, std::string& strResult); + + /** Callback to set a criterion's value, see ISelectionCriterionInterface::setCriterionState. + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * @param[in] remoteCommand the first argument should be the name of the criterion to set. + * if the criterion is provided in lexical space, + * the following arguments should be criterion new values + * if the criterion is provided in numerical space, + * the second argument should be the criterion new value + */ + CommandReturn setCriterionState(const IRemoteCommand& remoteCommand, std::string& strResult); + + /** Callback to start the PFW, see CParameterMgrPlatformConnector::start. + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * @param[in] remoteCommand is ignored + */ + CommandReturn startParameterMgr(const IRemoteCommand& remoteCommand, std::string& strResult); + + /** Callback to apply PFW configuration, see CParameterMgrPlatformConnector::applyConfiguration. + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * @param[in] remoteCommand is ignored + * + * @return EDone (never fails) + */ + CommandReturn applyConfigurations(const IRemoteCommand& remoteCommand, std::string& strResult); + + /** Callback to exit the test-platform. + * + * @param[in] remoteCommand is ignored + * + * @return EDone (never fails) + */ + CommandReturn exit(const IRemoteCommand& remoteCommand, std::string& strResult); + + /** The type of a CParameterMgrPlatformConnector boolean setter. */ + typedef bool (CParameterMgrPlatformConnector::*setter_t)(bool, std::string&); + + /** Template callback to create a _pParameterMgrPlatformConnector boolean setter callback. + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * Convert the remoteCommand first argument to a boolean and call the + * template parameter function with this value. + * + * @tparam the boolean setter method. + * @param[in] remoteCommand the first argument should be ether "on" or "off". + */ + template + CommandReturn setter(const IRemoteCommand& remoteCommand, std::string& strResult); + + /** The type of a CParameterMgrPlatformConnector boolean getter. */ + typedef bool (CParameterMgrPlatformConnector::*getter_t)(); + + /** Template callback to create a ParameterMgrPlatformConnector boolean getter callback. + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * Convert to boolean returned by the template parameter function converted to a + * std::string ("True", "False") and return it. + * + * @param the boolean getter method. + * @param[in] remoteCommand is ignored + * + * @return EDone (never fails) + */ + template + CommandReturn getter(const IRemoteCommand& remoteCommand, std::string& strResult); + + /** Parser items map */ + static const CommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; + + /** Test PLatform used to delegate parsed commands */ + CTestPlatform& mTestPlatform; + + /** Command Handler */ + CommandHandler mCommandHandler; +}; + +} /** command namespace */ +} /** platform namespace */ +} /** test namespace */ diff --git a/test/test-platform/command/src/Parser.cpp b/test/test-platform/command/src/Parser.cpp new file mode 100644 index 000000000..43f561744 --- /dev/null +++ b/test/test-platform/command/src/Parser.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2015, Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "command/Parser.h" +#include "TestPlatform.h" +#include "RemoteProcessorServer.h" +#include "ParameterMgrPlatformConnector.h" +#include "convert.hpp" + +namespace test +{ +namespace platform +{ +namespace command +{ + +const Parser::CommandHandler::RemoteCommandParserItems Parser::gRemoteCommandParserItems = { + { "exit", { &Parser::exit, 0, "", "Exit TestPlatform" } }, + { "createExclusiveSelectionCriterionFromStateList", + { &Parser::createExclusiveSelectionCriterionFromStateList, 2, " ", + "Create inclusive selection criterion from state name list" } }, + { "createInclusiveSelectionCriterionFromStateList", + { &Parser::createInclusiveSelectionCriterionFromStateList, 2, " ", + "Create exclusive selection criterion from state name list" } }, + { "createExclusiveSelectionCriterion", + { &Parser::createExclusiveSelectionCriterion, 2, " ", + "Create inclusive selection criterion" } }, + { "createInclusiveSelectionCriterion", + { &Parser::createInclusiveSelectionCriterion, 2, " ", + "Create exclusive selection criterion" } }, + { "start", { &Parser::startParameterMgr, 0, "", "Start ParameterMgr" } }, + { "setCriterionState", + { &Parser::setCriterionState, 2, " ", + "Set the current state of a selection criterion" } }, + { "applyConfigurations", + { &Parser::applyConfigurations, 0, "", + "Apply configurations selected by current selection criteria states" } }, + { "setFailureOnMissingSubsystem", + { &Parser::setter<& CParameterMgrPlatformConnector::setFailureOnMissingSubsystem>, 1, + "true|false", + "Set policy for missing subsystems, " + "either abort start or fallback on virtual subsystem." } }, + { "getMissingSubsystemPolicy", + { &Parser::getter<& CParameterMgrPlatformConnector::getFailureOnMissingSubsystem>, 0, + "", + "Get policy for missing subsystems, " + "either abort start or fallback on virtual subsystem." } }, + { "setFailureOnFailedSettingsLoad", + { &Parser::setter<& CParameterMgrPlatformConnector::setFailureOnFailedSettingsLoad>, + 1, "true|false", + "Set policy for failed settings load, either abort start or continue without domains." }}, + { "getFailedSettingsLoadPolicy", + { &Parser::getter<& CParameterMgrPlatformConnector::getFailureOnFailedSettingsLoad>, + 0, "", + "Get policy for failed settings load, either abort start or continue without domains." }}, + { "setValidateSchemasOnStart", + { &Parser::setter<& CParameterMgrPlatformConnector::setValidateSchemasOnStart>, 1, + "true|false", + "Set policy for schema validation based on .xsd files (false by default)." } }, + { "getValidateSchemasOnStart", + { &Parser::getter<& CParameterMgrPlatformConnector::getValidateSchemasOnStart>, 0, + "", "Get policy for schema validation based on .xsd files." } } +}; + +Parser::Parser(CTestPlatform& testPlatform) : + mTestPlatform(testPlatform), mCommandHandler(CommandHandler(*this, gRemoteCommandParserItems)) +{ +} + +Parser::CommandHandler* Parser::getCommandHandler() +{ + return &mCommandHandler; +} + +Parser::CommandReturn Parser::exit(const IRemoteCommand&, std::string&) +{ + // Release the main blocking semaphore to quit application + sem_post(&mTestPlatform._exitSemaphore); + + return Parser::CommandHandler::EDone; +} + +Parser::CommandReturn +Parser::createExclusiveSelectionCriterionFromStateList(const IRemoteCommand& remoteCommand, + std::string& strResult) +{ + return mTestPlatform.createExclusiveSelectionCriterionFromStateList( + remoteCommand.getArgument(0), remoteCommand, strResult) ? + Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::createInclusiveSelectionCriterionFromStateList(const IRemoteCommand& remoteCommand, + std::string& strResult) +{ + return mTestPlatform.createInclusiveSelectionCriterionFromStateList( + remoteCommand.getArgument(0), remoteCommand, strResult) ? + Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::createExclusiveSelectionCriterion(const IRemoteCommand& remoteCommand, + std::string& strResult) +{ + return mTestPlatform.createExclusiveSelectionCriterion( + remoteCommand.getArgument(0), + strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), + strResult) ? + Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; +} + +Parser::CommandReturn +Parser::createInclusiveSelectionCriterion(const IRemoteCommand& remoteCommand, + std::string& strResult) +{ + return mTestPlatform.createInclusiveSelectionCriterion( + remoteCommand.getArgument(0), + strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), + strResult) ? + Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::startParameterMgr(const IRemoteCommand&, std::string& strResult) +{ + return mTestPlatform._pParameterMgrPlatformConnector->start(strResult) ? + Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; +} + +template +Parser::CommandReturn Parser::setter(const IRemoteCommand& remoteCommand, std::string& strResult) +{ + const std::string& strAbort = remoteCommand.getArgument(0); + + bool bFail; + + if(!convertTo(strAbort, bFail)) { + return Parser::CommandHandler::EShowUsage; + } + + return (mTestPlatform._pParameterMgrPlatformConnector->*setFunction)(bFail, strResult) ? + Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; +} + +template +Parser::CommandReturn Parser::getter(const IRemoteCommand&, std::string& strResult) +{ + strResult = (mTestPlatform._pParameterMgrPlatformConnector->*getFunction)() ? "true" : "false"; + + return Parser::CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::setCriterionState(const IRemoteCommand& remoteCommand, + std::string& strResult) +{ + bool bSuccess; + + const char* pcState = remoteCommand.getArgument(1).c_str(); + + char* pcStrEnd; + + // Reset errno to check if it is updated during the conversion (strtol/strtoul) + errno = 0; + + uint32_t state = strtoul(pcState, &pcStrEnd, 0); + + if (!errno && (*pcStrEnd == '\0')) { + // Sucessfull conversion, set criterion state by numerical state + bSuccess = mTestPlatform.setCriterionState(remoteCommand.getArgument(0), state, strResult); + + } else { + // Conversion failed, set criterion state by lexical state + bSuccess = mTestPlatform.setCriterionStateByLexicalSpace(remoteCommand, strResult); + } + + return bSuccess ? Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; + +} + +Parser::CommandReturn Parser::applyConfigurations(const IRemoteCommand&, std::string&) +{ + mTestPlatform._pParameterMgrPlatformConnector->applyConfigurations(); + + return Parser::CommandHandler::EDone; +} + +} /** command namespace */ +} /** platform namespace */ +} /** test namespace */ diff --git a/test/test-platform/main.cpp b/test/test-platform/main.cpp index a3f50be01..f525893f7 100644 --- a/test/test-platform/main.cpp +++ b/test/test-platform/main.cpp @@ -50,7 +50,7 @@ static bool startBlockingTestPlatform(const char *filePath, int portNumber, stri sem_init(&sem, false, 0); // Create param mgr - CTestPlatform testPlatform(filePath, portNumber, sem); + test::platform::CTestPlatform testPlatform(filePath, portNumber, sem); // Start platformmgr if (!testPlatform.load(strError)) { @@ -103,7 +103,7 @@ static bool startDaemonTestPlatform(const char *filePath, int portNumber, string sem_init(&sem, false, 0); // Create param mgr - CTestPlatform testPlatform(filePath, portNumber, sem); + test::platform::CTestPlatform testPlatform(filePath, portNumber, sem); // Message to send to parent process bool msgToParent; From 89059c0d973a01eb317a48c3a13c5e985cb1a4ef Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 30 Mar 2015 14:58:29 +0200 Subject: [PATCH 29/30] Avoid code duplication when parsing criterion creation command Parsing method of criterion creation was duplicated for inclusive and exclusive criterion. This patch uses template method to avoid that. Signed-off-by: Jules Clero --- .../command/include/command/Parser.h | 42 +++++++++++--- test/test-platform/command/src/Parser.cpp | 56 +++++++------------ 2 files changed, 53 insertions(+), 45 deletions(-) diff --git a/test/test-platform/command/include/command/Parser.h b/test/test-platform/command/include/command/Parser.h index e3aa86f0c..76da2ccaf 100644 --- a/test/test-platform/command/include/command/Parser.h +++ b/test/test-platform/command/include/command/Parser.h @@ -69,15 +69,39 @@ class Parser /** Command handler method return type */ typedef CommandHandler::CommandStatus CommandReturn; - CommandReturn createExclusiveSelectionCriterionFromStateList( - const IRemoteCommand& remoteCommand, std::string& strResult); - CommandReturn createInclusiveSelectionCriterionFromStateList( - const IRemoteCommand& remoteCommand, std::string& strResult); - - CommandReturn createExclusiveSelectionCriterion( - const IRemoteCommand& remoteCommand, std::string& strResult); - CommandReturn createInclusiveSelectionCriterion( - const IRemoteCommand& remoteCommand, std::string& strResult); + /** Type of criterion factory which use a state list */ + using CreateCriterionFromStateList = bool (CTestPlatform::*)(const std::string&, + const IRemoteCommand&, + std::string&); + + /** Callback to create a criterion from a state list + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * @tparam factory method, can be either for inclusive or exclusive criterion + * + * @param[in] remoteCommand the first argument should be the name of the criterion to set. + * others arguments should be state names. + */ + template + CommandReturn createCriterionFromStateList(const IRemoteCommand& remoteCommand, + std::string& strResult); + + /** Type of criterion factory which use the state number */ + using CreateCriterion = bool (CTestPlatform::*)(const std::string&, + uint32_t, + std::string&); + + /** Callback to create a criterion from a state number + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * @tparam factory method, can be either for inclusive or exclusive criterion + * + * @param[in] remoteCommand the first argument should be the name of the criterion to set. + * the second argument should be the criterion state number. + */ + template + CommandReturn createCriterion(const IRemoteCommand& remoteCommand, + std::string& strResult); /** Callback to set a criterion's value, see ISelectionCriterionInterface::setCriterionState. * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return diff --git a/test/test-platform/command/src/Parser.cpp b/test/test-platform/command/src/Parser.cpp index 43f561744..152f75d94 100644 --- a/test/test-platform/command/src/Parser.cpp +++ b/test/test-platform/command/src/Parser.cpp @@ -44,16 +44,22 @@ namespace command const Parser::CommandHandler::RemoteCommandParserItems Parser::gRemoteCommandParserItems = { { "exit", { &Parser::exit, 0, "", "Exit TestPlatform" } }, { "createExclusiveSelectionCriterionFromStateList", - { &Parser::createExclusiveSelectionCriterionFromStateList, 2, " ", + { &Parser::createCriterionFromStateList< + &CTestPlatform::createExclusiveSelectionCriterionFromStateList>, + 2, " ", "Create inclusive selection criterion from state name list" } }, { "createInclusiveSelectionCriterionFromStateList", - { &Parser::createInclusiveSelectionCriterionFromStateList, 2, " ", + { &Parser::createCriterionFromStateList< + &CTestPlatform::createInclusiveSelectionCriterionFromStateList>, + 2, " ", "Create exclusive selection criterion from state name list" } }, { "createExclusiveSelectionCriterion", - { &Parser::createExclusiveSelectionCriterion, 2, " ", + { &Parser::createCriterion<&CTestPlatform::createExclusiveSelectionCriterion>, + 2, " ", "Create inclusive selection criterion" } }, { "createInclusiveSelectionCriterion", - { &Parser::createInclusiveSelectionCriterion, 2, " ", + { &Parser::createCriterion<&CTestPlatform::createInclusiveSelectionCriterion>, + 2, " ", "Create exclusive selection criterion" } }, { "start", { &Parser::startParameterMgr, 0, "", "Start ParameterMgr" } }, { "setCriterionState", @@ -107,43 +113,21 @@ Parser::CommandReturn Parser::exit(const IRemoteCommand&, std::string&) return Parser::CommandHandler::EDone; } -Parser::CommandReturn -Parser::createExclusiveSelectionCriterionFromStateList(const IRemoteCommand& remoteCommand, - std::string& strResult) +template +Parser::CommandReturn Parser::createCriterionFromStateList(const IRemoteCommand& remoteCommand, + std::string& strResult) { - return mTestPlatform.createExclusiveSelectionCriterionFromStateList( - remoteCommand.getArgument(0), remoteCommand, strResult) ? + return (mTestPlatform.*factory)(remoteCommand.getArgument(0), remoteCommand, strResult) ? Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; } -Parser::CommandReturn -Parser::createInclusiveSelectionCriterionFromStateList(const IRemoteCommand& remoteCommand, - std::string& strResult) +template +Parser::CommandReturn Parser::createCriterion(const IRemoteCommand& remoteCommand, + std::string& strResult) { - return mTestPlatform.createInclusiveSelectionCriterionFromStateList( - remoteCommand.getArgument(0), remoteCommand, strResult) ? - Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; -} - -Parser::CommandReturn -Parser::createExclusiveSelectionCriterion(const IRemoteCommand& remoteCommand, - std::string& strResult) -{ - return mTestPlatform.createExclusiveSelectionCriterion( - remoteCommand.getArgument(0), - strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), - strResult) ? - Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; -} - -Parser::CommandReturn -Parser::createInclusiveSelectionCriterion(const IRemoteCommand& remoteCommand, - std::string& strResult) -{ - return mTestPlatform.createInclusiveSelectionCriterion( - remoteCommand.getArgument(0), - strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), - strResult) ? + return (mTestPlatform.*factory)(remoteCommand.getArgument(0), + strtoul(remoteCommand.getArgument(1).c_str(), NULL, 0), + strResult) ? Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; } From 31b49c0b0d0d916a2f360cebd451d987527044fc Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Fri, 27 Mar 2015 16:39:06 +0100 Subject: [PATCH 30/30] Refactor command callback definition in RemoteCommandHandler RemoteCommandHandler was using old style function pointer to keep commands. This patch introduces the use of function object. The help command is now handled as any other commands thanks to partial function definition. Signed-off-by: Jules Clero --- parameter/command/include/command/Parser.h | 2 +- parameter/command/src/Parser.cpp | 2 +- .../RemoteCommandHandlerTemplate.h | 52 ++++++++----------- .../command/include/command/Parser.h | 2 +- test/test-platform/command/src/Parser.cpp | 2 +- 5 files changed, 26 insertions(+), 34 deletions(-) diff --git a/parameter/command/include/command/Parser.h b/parameter/command/include/command/Parser.h index 978544ed2..a971c1f6f 100644 --- a/parameter/command/include/command/Parser.h +++ b/parameter/command/include/command/Parser.h @@ -209,7 +209,7 @@ class Parser //@} /** Parser items map */ - static const CommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; + static CommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; /** Parameter Manager used to delegate parsed commands */ CParameterMgr& mParameterMgr; diff --git a/parameter/command/src/Parser.cpp b/parameter/command/src/Parser.cpp index c8d5474f8..6c8dedc9a 100644 --- a/parameter/command/src/Parser.cpp +++ b/parameter/command/src/Parser.cpp @@ -46,7 +46,7 @@ namespace core namespace command { -const Parser::CommandHandler::RemoteCommandParserItems Parser::gRemoteCommandParserItems = { +Parser::CommandHandler::RemoteCommandParserItems Parser::gRemoteCommandParserItems = { { "version", { &Parser::version, 0, "", "Show version" } }, { "status", { &Parser::status, 0, "", "Show current status" } }, { "setTuningMode", diff --git a/remote-processor/RemoteCommandHandlerTemplate.h b/remote-processor/RemoteCommandHandlerTemplate.h index ebc1d48cf..bde8a8ec4 100644 --- a/remote-processor/RemoteCommandHandlerTemplate.h +++ b/remote-processor/RemoteCommandHandlerTemplate.h @@ -32,6 +32,7 @@ #include "RemoteCommandHandler.h" #include #include +#include /** Handle command of server side application * @@ -56,9 +57,9 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler * * @return the command execution status, @see CommandStatus */ - typedef CommandStatus (CommandParser::* RemoteCommandParser)(const IRemoteCommand& - remoteCommand, - std::string& strResult); + using RemoteCommandParser = std::function; /** Parser item definition */ class RemoteCommandParserItem @@ -119,7 +120,7 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler return false; } - switch ((commandParser.*mParser)(remoteCommand, result)) { + switch (mParser(commandParser, remoteCommand, result)) { case EDone: result = "Done"; // Fall through intentionally @@ -158,9 +159,18 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler * @param remoteCommandParserItems supported command parser items */ RemoteCommandHandlerTemplate(CommandParser& commandParser, - const RemoteCommandParserItems& remoteCommandParserItems) : + RemoteCommandParserItems& remoteCommandParserItems) : _commandParser(commandParser), _remoteCommandParserItems(remoteCommandParserItems) { + /* Add the help command and specialize the help function + * to match RemoteCommandParser prototype + */ + _remoteCommandParserItems.emplace( + "help", + RemoteCommandParserItem( + [this](CommandParser&, + const IRemoteCommand&, std::string& result){ return help(result); }, + 0, "", "Show commands description and usage")); } private: @@ -181,14 +191,6 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler return remoteCommandParserItem.parse(_commandParser, remoteCommand, result); } catch (const std::out_of_range&) { - - if (remoteCommand.getCommand() == helpCommand) { - - help(result); - - return true; - } - // Not found result = "Command not found!\nUse \"help\" to show available commands"; @@ -199,12 +201,14 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler /** Format help display * * @param result the formatted help string + * + * @return ESucceeded command status */ - void help(std::string& result) + CommandStatus help(std::string& result) { struct Help { std::string usage; std::string description; }; - std::vector helps{ { helpCommand, helpCommandDescription } }; - size_t maxUsage = helpCommand.length(); + std::vector helps; + size_t maxUsage = 0; for (auto& item : _remoteCommandParserItems) { std::string usage = item.first + ' ' + item.second.getHelp(); @@ -216,24 +220,12 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler help.usage.resize(maxUsage, ' '); result += help.usage + " => " + help.description + '\n'; } + return CommandStatus::ESucceeded; } - /** Help command name */ - static const std::string helpCommand; - - /** Help command description */ - static const std::string helpCommandDescription; - /** Command parser used during command during command handling */ CommandParser& _commandParser; /** Remote command parser map */ - const RemoteCommandParserItems& _remoteCommandParserItems; + RemoteCommandParserItems& _remoteCommandParserItems; }; - -template -const std::string RemoteCommandHandlerTemplate::helpCommand = "help"; - -template -const std::string RemoteCommandHandlerTemplate::helpCommandDescription = - "Show commands description and usage"; diff --git a/test/test-platform/command/include/command/Parser.h b/test/test-platform/command/include/command/Parser.h index 76da2ccaf..046fc23f0 100644 --- a/test/test-platform/command/include/command/Parser.h +++ b/test/test-platform/command/include/command/Parser.h @@ -171,7 +171,7 @@ class Parser CommandReturn getter(const IRemoteCommand& remoteCommand, std::string& strResult); /** Parser items map */ - static const CommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; + static CommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; /** Test PLatform used to delegate parsed commands */ CTestPlatform& mTestPlatform; diff --git a/test/test-platform/command/src/Parser.cpp b/test/test-platform/command/src/Parser.cpp index 152f75d94..bbccb9ff0 100644 --- a/test/test-platform/command/src/Parser.cpp +++ b/test/test-platform/command/src/Parser.cpp @@ -41,7 +41,7 @@ namespace platform namespace command { -const Parser::CommandHandler::RemoteCommandParserItems Parser::gRemoteCommandParserItems = { +Parser::CommandHandler::RemoteCommandParserItems Parser::gRemoteCommandParserItems = { { "exit", { &Parser::exit, 0, "", "Exit TestPlatform" } }, { "createExclusiveSelectionCriterionFromStateList", { &Parser::createCriterionFromStateList<