From f41401e93a5efab0b01c5513203a1570eae78539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Poncabar=C3=A9?= Date: Mon, 2 May 2016 13:53:37 +0200 Subject: [PATCH] Add listMappings command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List all the mapping under a given path Example with the MusicLibrary form the Getting Started wiki : $ remote-process localhost 5000 listMappings /MusicLibrary/my_library/artists/IronMaiden /MusicLibrary/my_library/artists/IronMaiden [Directory:/home/fponcabx/pfw/install-examples/libraries, File:ironMaiden, File:ironMaiden] Signed-off-by: Florian Poncabaré --- parameter/Element.cpp | 9 +++++++++ parameter/Element.h | 1 + parameter/ParameterMgr.cpp | 33 +++++++++++++++++++++++++++++++++ parameter/ParameterMgr.h | 2 ++ 4 files changed, 45 insertions(+) diff --git a/parameter/Element.cpp b/parameter/Element.cpp index 831729948..c88577850 100644 --- a/parameter/Element.cpp +++ b/parameter/Element.cpp @@ -356,6 +356,15 @@ string CElement::listQualifiedPaths(bool bDive, size_t level) const return strResult; } +void CElement::getSubpaths(std::vector &results) const +{ + results.push_back(getPath()); + + for (CElement *pChild : _childArray) { + pChild->getSubpaths(results); + } +} + void CElement::listChildrenPaths(string &strChildList) const { // Get list of children paths diff --git a/parameter/Element.h b/parameter/Element.h index b7cdc6d2a..4eab323b2 100644 --- a/parameter/Element.h +++ b/parameter/Element.h @@ -72,6 +72,7 @@ class PARAMETER_EXPORT CElement : public IXmlSink, public IXmlSource void listChildren(std::string &strChildList) const; std::string listQualifiedPaths(bool bDive, size_t level = 0) const; void listChildrenPaths(std::string &strChildPathList) const; + void getSubpaths(std::vector &results) const; // Hierarchy query size_t getNbChildren() const; diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index d56277c03..2523c0a1d 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -269,6 +269,8 @@ const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandPa "Set value for parameter at given path to configuration"}, {"showMapping", &CParameterMgr::showMappingCommandProcess, 1, "", "Show mapping for an element at given path"}, + {"listMappings", &CParameterMgr::listMappingsCommandProcess, 1, "|/", + "List mappings under element at given path or root"}, /// Browse {"listAssociatedElements", &CParameterMgr::listAssociatedElementsCommandProcess, 0, "", @@ -1820,6 +1822,37 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::showMappingCommandP return CCommandHandler::ESucceeded; } +CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listMappingsCommandProcess( + const IRemoteCommand &remoteCommand, string &strResult) +{ + CElementLocator elementLocator(getSystemClass(), false); + + CElement *pLocatedElement = nullptr; + + if (!elementLocator.locate(remoteCommand.getArgument(0), &pLocatedElement, strResult)) { + return CCommandHandler::EFailed; + } + + if (!pLocatedElement) { + // List from root folder + pLocatedElement = getSystemClass(); + } + + vector paths; + pLocatedElement->getSubpaths(paths); + + for (string path : paths) { + string mapping; + if (getParameterMapping(path, mapping)) { + strResult += path + " [" + mapping + "]\n"; + } else { + strResult += path + "\n"; + } + } + + return CCommandHandler::ESucceeded; +} + /// Settings Import/Export CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportDomainsXMLCommandProcess( const IRemoteCommand &remoteCommand, string &strResult) diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index bc0726dfe..8ef3840b4 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -533,6 +533,8 @@ class CParameterMgr : private CElement const IRemoteCommand &remoteCommand, std::string &strResult); CCommandHandler::CommandStatus showMappingCommandProcess(const IRemoteCommand &remoteCommand, std::string &strResult); + CCommandHandler::CommandStatus listMappingsCommandProcess(const IRemoteCommand &remoteCommand, + std::string &strResult); /// Browse CCommandHandler::CommandStatus listAssociatedElementsCommandProcess( const IRemoteCommand &remoteCommand, std::string &strResult);