From c6f604a9f770e3690908a288965e2e5f95a211ed Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 19 Feb 2015 18:33:47 +0100 Subject: [PATCH 01/13] 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 | 1046 +------------------ parameter/ParameterMgr.h | 178 +--- parameter/command/include/command/Parser.h | 245 +++++ parameter/command/src/Parser.cpp | 1073 ++++++++++++++++++++ 5 files changed, 1340 insertions(+), 1207 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 a9fe3c2b8..d67bd4df8 100644 --- a/parameter/CMakeLists.txt +++ b/parameter/CMakeLists.txt @@ -97,10 +97,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 8e645f64b..6e9f52669 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -81,8 +81,7 @@ #include "Utility.h" #include #include -#include -#include +#include /** Private macro helper to declare a new context * @@ -137,193 +136,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::setTuningModeCommandProcess, 1, - "on|off*", "Turn on or off Tuning Mode" }, - { "getTuningMode", &CParameterMgr::getTuningModeCommandProcess, 0, - "", "Show Tuning Mode" }, - - /// Value Space - { "setValueSpace", &CParameterMgr::setValueSpaceCommandProcess, 1, - "raw|real*", "Assigns Value Space used for parameter value interpretation" }, - { "getValueSpace", &CParameterMgr::getValueSpaceCommandProcess, 0, - "", "Show Value Space" }, - - /// Output Raw Format - { "setOutputRawFormat", &CParameterMgr::setOutputRawFormatCommandProcess, 1, - "dec*|hex", "Assigns format used to output parameter values when in raw Value Space" }, - { "getOutputRawFormat", &CParameterMgr::getOutputRawFormatCommandProcess, 0, - "", "Show Output Raw Format" }, - - /// Sync - { "setAutoSync", &CParameterMgr::setAutoSyncCommandProcess, 1, - "on*|off", "Turn on or off automatic synchronization to hardware while in Tuning Mode" }, - { "getAutoSync", &CParameterMgr::getAutoSyncCommandProcess, 0, - "", "Show Auto Sync state" }, - { "sync", &CParameterMgr::syncCommandProcess, 0, - "", "Synchronize current settings to hardware while in Tuning Mode and Auto Sync off" }, - - /// Criteria - { "listCriteria", &CParameterMgr::listCriteriaCommandProcess, 0, - "[CSV|XML]", "List selection criteria" }, - - /// Domains - { "listDomains", &CParameterMgr::listDomainsCommandProcess, 0, - "", "List configurable domains" }, - { "dumpDomains", &CParameterMgr::dumpDomainsCommandProcess, 0, - "", "Show all domains and configurations, including applicability conditions" }, - { "createDomain", &CParameterMgr::createDomainCommandProcess, 1, - "", "Create new configurable domain" }, - { "deleteDomain", &CParameterMgr::deleteDomainCommandProcess, 1, - "", "Delete configurable domain" }, - { "deleteAllDomains", &CParameterMgr::deleteAllDomainsCommandProcess, 0, - "", "Delete all configurable domains" }, - { "renameDomain", &CParameterMgr::renameDomainCommandProcess, 2, - " ", "Rename configurable domain" }, - { "setSequenceAwareness", &CParameterMgr::setSequenceAwarenessCommandProcess, 1, - " true|false*", "Set configurable domain sequence awareness" }, - { "getSequenceAwareness", &CParameterMgr::getSequenceAwarenessCommandProcess, 1, - "", "Get configurable domain sequence awareness" }, - { "listDomainElements", &CParameterMgr::listDomainElementsCommandProcess, 1, - "", "List elements associated to configurable domain" }, - { "addElement", &CParameterMgr::addElementCommandProcess, 2, - " ", "Associate element at given path to configurable domain" }, - { "removeElement", &CParameterMgr::removeElementCommandProcess, 2, - " ", "Dissociate element at given path from configurable domain" }, - { "splitDomain", &CParameterMgr::splitDomainCommandProcess, 2, - " ", "Split configurable domain at given associated element path" }, - - /// Configurations - { "listConfigurations", &CParameterMgr::listConfigurationsCommandProcess, 1, - "", "List domain configurations" }, - { "createConfiguration", &CParameterMgr::createConfigurationCommandProcess, 2, - " ", "Create new domain configuration" }, - { "deleteConfiguration", &CParameterMgr::deleteConfigurationCommandProcess, 2, - " ", "Delete domain configuration" }, - { "renameConfiguration", &CParameterMgr::renameConfigurationCommandProcess, 3, - " ", "Rename domain configuration" }, - { "saveConfiguration", &CParameterMgr::saveConfigurationCommandProcess, 2, - " ", "Save current settings into configuration" }, - { "restoreConfiguration", &CParameterMgr::restoreConfigurationCommandProcess, 2, - " ", "Restore current settings from configuration" }, - { "setElementSequence", &CParameterMgr::setElementSequenceCommandProcess, 3, - " ", - "Set element application order for configuration" }, - { "getElementSequence", &CParameterMgr::getElementSequenceCommandProcess, 2, - " ", "Get element application order for configuration" }, - { "setRule", &CParameterMgr::setRuleCommandProcess, 3, - " ", "Set configuration application rule" }, - { "clearRule", &CParameterMgr::clearRuleCommandProcess, 2, - " ", "Clear configuration application rule" }, - { "getRule", &CParameterMgr::getRuleCommandProcess, 2, - " ", "Get configuration application rule" }, - - /// Elements/Parameters - { "listElements", &CParameterMgr::listElementsCommandProcess, 1, - "|/", "List elements under element at given path or root" }, - { "listParameters", &CParameterMgr::listParametersCommandProcess, 1, - "|/", "List parameters under element at given path or root" }, - { "dumpElement", &CParameterMgr::dumpElementCommandProcess, 1, - "", "Dump structure and content of element at given path" }, - { "getElementSize", &CParameterMgr::getElementSizeCommandProcess, 1, - "", "Show size of element at given path" }, - { "showProperties", &CParameterMgr::showPropertiesCommandProcess, 1, - "", "Show properties of element at given path" }, - { "getParameter", &CParameterMgr::getParameterCommandProcess, 1, - "", "Get value for parameter at given path" }, - { "setParameter", &CParameterMgr::setParameterCommandProcess, 2, - " ", "Set value for parameter at given path" }, - { "listBelongingDomains", &CParameterMgr::listBelongingDomainsCommandProcess, 1, - "", "List domain(s) element at given path belongs to" }, - { "listAssociatedDomains", &CParameterMgr::listAssociatedDomainsCommandProcess, 1, - "", "List domain(s) element at given path is associated to" }, - { "getConfigurationParameter", &CParameterMgr::getConfigurationParameterCommandProcess, 3, - " ", - "Get value for parameter at given path from configuration" }, - { "setConfigurationParameter", &CParameterMgr::setConfigurationParameterCommandProcess, 4, - " ", - "Set value for parameter at given path to configuration" }, - { "showMapping", &CParameterMgr::showMappingCommandProcess, 1, - "", "Show mapping for an element at given path" }, - - /// Browse - { "listAssociatedElements", &CParameterMgr::listAssociatedElementsCommandProcess, 0, - "", "List element sub-trees associated to at least one configurable domain" }, - { "listConflictingElements", &CParameterMgr::listConflictingElementsCommandProcess, 0, - "", "List element sub-trees contained in more than one configurable domain" }, - { "listRogueElements", &CParameterMgr::listRogueElementsCommandProcess, 0, - "", "List element sub-trees owned by no configurable domain" }, - - /// Settings Import/Export - { "exportDomainsXML", &CParameterMgr::exportDomainsXMLCommandProcess, 1, - " ", "Export domains to an XML file (provide an absolute path or relative" - "to the client's working directory)" }, - { "importDomainsXML", &CParameterMgr::importDomainsXMLCommandProcess, 1, - "", "Import domains from an XML file (provide an absolute path or relative" - "to the client's working directory)" }, - { "exportDomainsWithSettingsXML", - &CParameterMgr::exportDomainsWithSettingsXMLCommandProcess, 1, - " ", "Export domains including settings to XML file (provide an absolute path or relative" - "to the client's working directory)" }, - { "exportDomainWithSettingsXML", - &CParameterMgr::exportDomainWithSettingsXMLCommandProcess, 2, - " ", "Export a single given domain including settings to XML file" - " (provide an absolute path or relative to the client's" - " working directory)" }, - { "importDomainsWithSettingsXML", - &CParameterMgr::importDomainsWithSettingsXMLCommandProcess, 1, - "", "Import domains including settings from XML file (provide an absolute path or relative" - "to the client's working directory)" }, - { "importDomainWithSettingsXML", - &CParameterMgr::importDomainWithSettingsXMLCommandProcess, 1, - " [overwrite]", "Import a single domain including settings from XML file." - " Does not overwrite an existing domain unless 'overwrite' is passed as second" - " argument. Provide an absolute path or relative to the client's working directory)" }, - { "exportSettings", &CParameterMgr::exportSettingsCommandProcess, 1, - "", "Export settings to binary file (provide an absolute path or relative" - "to the client's working directory)" }, - { "importSettings", &CParameterMgr::importSettingsCommandProcess, 1, - "", "Import settings from binary file (provide an absolute path or relative" - "to the client's working directory)" }, - { "getDomainsWithSettingsXML", - &CParameterMgr::getDomainsWithSettingsXMLCommandProcess, 0, - "", "Print domains including settings as XML" }, - { "getDomainWithSettingsXML", - &CParameterMgr::getDomainWithSettingsXMLCommandProcess, 1, - "", "Print the given domain including settings as XML" }, - { "setDomainsWithSettingsXML", - &CParameterMgr::setDomainsWithSettingsXMLCommandProcess, 1, - "", "Import domains including settings from XML string" }, - { "setDomainWithSettingsXML", - &CParameterMgr::setDomainWithSettingsXMLCommandProcess, 1, - " [overwrite]", "Import domains including settings from XML" - " string. Does not overwrite an existing domain unless 'overwrite' is passed as second" - " argument" }, - /// Structure Export - { "getSystemClassXML", &CParameterMgr::getSystemClassXMLCommandProcess, 0 , - "", "Print parameter structure as XML" }, - /// Deprecated Commands - { "getDomainsXML", - &CParameterMgr::getDomainsWithSettingsXMLCommandProcess, 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), @@ -336,6 +148,7 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge _pvLibRemoteProcessorHandle(NULL), _uiStructureChecksum(0), _pRemoteProcessorServer(NULL), + _commandParser(*this), _uiMaxCommandUsageLength(0), _logger(logger), _bForceNoRemoteInterface(false), @@ -352,22 +165,6 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge bzero(&_blackboardMutex, sizeof(_blackboardMutex)); pthread_mutex_init(&_blackboardMutex, NULL); - _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) { @@ -385,7 +182,6 @@ CParameterMgr::~CParameterMgr() { // Children delete _pRemoteProcessorServer; - delete _pCommandHandler; delete _pMainParameterBlackboard; delete _pElementLibrarySet; @@ -853,841 +649,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; - - // Show status - /// General section - CUtility::appendTitle(strResult, "General:"); - // System class - strResult += "System Class: "; - strResult += _systemClass.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 - CUtility::appendTitle(strResult, "Subsystems:"); - string strSubsystemList; - _systemClass.listChildrenPaths(strSubsystemList); - strResult += strSubsystemList; - - /// Last applied configurations - CUtility::appendTitle(strResult, "Last Applied [Pending] Configurations:"); - string strLastAppliedConfigurations; - _domains.listLastAppliedConfigurations(strLastAppliedConfigurations); - strResult += strLastAppliedConfigurations; - - /// Criteria states - CUtility::appendTitle(strResult, "Selection Criteria:"); - list lstrSelectionCriteria; - _criteria.listCriteria(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::setTuningModeCommandProcess(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::getTuningModeCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - strResult = tuningModeOn() ? "on" : "off"; - - return CCommandHandler::ESucceeded; -} - -/// Value Space -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setValueSpaceCommandProcess(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::getValueSpaceCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - strResult = valueSpaceIsRaw() ? "raw" : "real"; - - return CCommandHandler::ESucceeded; -} - -/// Output Raw Format -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setOutputRawFormatCommandProcess(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::getOutputRawFormatCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - strResult = outputRawFormatIsHex() ? "hex" : "dec"; - - return CCommandHandler::ESucceeded; -} - -/// Sync -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setAutoSyncCommandProcess(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::getAutoSyncCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - strResult = autoSyncOn() ? "on" : "off"; - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - return sync(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -/// Criteria -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommandProcess(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") { - if (!exportElementToXMLString(&_criteria, "Criteria", 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; - _criteria.listCriteria(lstrResult, true, bHumanReadable); - - // Concatenate the criterion list as the command result - CUtility::asString(lstrResult, strResult); - - return CCommandHandler::ESucceeded; - } -} - -/// Domains -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listDomainsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - _domains.listDomains(strResult); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createDomainCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return createDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteDomainCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return deleteDomain(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteAllDomainsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - return deleteAllDomains(strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameDomainCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return renameDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setSequenceAwarenessCommandProcess(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::getSequenceAwarenessCommandProcess(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::listDomainElementsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return _domains.listDomainElements(remoteCommand.getArgument(0), strResult) ? - CCommandHandler::ESucceeded : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::addElementCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return addConfigurableElementToDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::removeElementCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return removeConfigurableElementFromDomain(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::splitDomainCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return split(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -/// Configurations -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConfigurationsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return _domains.listConfigurations(remoteCommand.getArgument(0), strResult) ? - CCommandHandler::ESucceeded : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpDomainsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - // Dummy error context - string strError; - CErrorContext errorContext(strError); - - // Dump - _domains.dumpContent(strResult, errorContext); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::createConfigurationCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return createConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::deleteConfigurationCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return deleteConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::renameConfigurationCommandProcess(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::saveConfigurationCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return saveConfiguration(remoteCommand.getArgument(0), remoteCommand.getArgument(1), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::restoreConfigurationCommandProcess(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::setElementSequenceCommandProcess(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::getElementSequenceCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - // Delegate to configurable domains - return _domains.getElementSequence(remoteCommand.getArgument(0), - remoteCommand.getArgument(1), - strResult) ? - CCommandHandler::ESucceeded : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setRuleCommandProcess(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::clearRuleCommandProcess(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::getRuleCommandProcess(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::listElementsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(&_systemClass, 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 = &_systemClass; - } - - // Return sub-elements - strResult += pLocatedElement->listQualifiedPaths(false); - - return CCommandHandler::ESucceeded; -} - -/// Elements/Parameters -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listParametersCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(&_systemClass, 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 = &_systemClass; - } - - // Return sub-elements - strResult += pLocatedElement->listQualifiedPaths(true); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::dumpElementCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(&_systemClass); - - 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::getElementSizeCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(&_systemClass); - - 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::showPropertiesCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(&_systemClass); - - 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::getParameterCommandProcess(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::setParameterCommandProcess(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::listBelongingDomainsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(&_systemClass); - - 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::listAssociatedDomainsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - CElementLocator elementLocator(&_systemClass); - - 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::listAssociatedElementsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - _domains.listAssociatedElements(strResult); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listConflictingElementsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - _domains.listConflictingElements(strResult); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listRogueElementsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - _systemClass.listRogueElements(strResult); - - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::getConfigurationParameterCommandProcess(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::setConfigurationParameterCommandProcess(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::showMappingCommandProcess( - const IRemoteCommand& remoteCommand, - string& strResult) -{ - if (!getParameterMapping(remoteCommand.getArgument(0), strResult)) { - - return CCommandHandler::EFailed; - } - - return CCommandHandler::ESucceeded; -} - -/// Settings Import/Export -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::exportDomainsXMLCommandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - string strFileName = remoteCommand.getArgument(0); - return exportDomainsXml(strFileName, false, true, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::importDomainsXMLCommandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - return importDomainsXml(remoteCommand.getArgument(0), false, true, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::exportDomainsWithSettingsXMLCommandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - string strFileName = remoteCommand.getArgument(0); - return exportDomainsXml(strFileName, true, true, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::exportDomainWithSettingsXMLCommandProcess( - const IRemoteCommand& remoteCommand, string& result) -{ - string domainName = remoteCommand.getArgument(0); - string fileName = remoteCommand.getArgument(1); - return exportSingleDomainXml(fileName, domainName, true, true, result) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importDomainsWithSettingsXMLCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importDomainWithSettingsXMLCommandProcess(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, true, true, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importSettingsCommandProcess(const IRemoteCommand& remoteCommand, string& strResult) -{ - return importDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::getDomainsWithSettingsXMLCommandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - if (!exportDomainsXml(strResult, true, false, strResult)) { - - return CCommandHandler::EFailed; - } - // Succeeded - return CCommandHandler::ESucceeded; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::getDomainWithSettingsXMLCommandProcess( - 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::setDomainsWithSettingsXMLCommandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - return importDomainsXml(remoteCommand.getArgument(0), true, false, strResult) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::setDomainWithSettingsXMLCommandProcess( - const IRemoteCommand& remoteCommand, string& result) -{ - bool overwrite = false; - - if (remoteCommand.getArgumentCount() > 1) { - - if (remoteCommand.getArgument(1) == "overwrite") { - - overwrite = true; - } else { - // Show usage - return CCommandHandler::EShowUsage; - } - } - - return importSingleDomainXml(remoteCommand.getArgument(0), overwrite, true, false, result) ? - CCommandHandler::EDone : CCommandHandler::EFailed; -} - -CParameterMgr::CCommandHandler::CommandStatus - CParameterMgr::getSystemClassXMLCommandProcess( - const IRemoteCommand& remoteCommand, string& strResult) -{ - (void)remoteCommand; - - // Get Root element where to export from - if (!exportElementToXMLString(&_systemClass, _systemClass.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) @@ -2578,7 +1539,8 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) // Create server _pRemoteProcessorServer = - pfnCreateRemoteProcessorServer(_pfwConfiguration.getServerPort(), _pCommandHandler); + pfnCreateRemoteProcessorServer(_pfwConfiguration.getServerPort(), + _commandParser.getCommandHandler()); info() << "Starting remote processor server on port " << _pfwConfiguration.getServerPort(); // Start diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index cba8526f5..98de68497 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 "Element.h" #include "XmlDocSink.h" @@ -70,20 +71,6 @@ class CParameterMgr 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 = 2; static const uint32_t guiEditionMinor = 6; @@ -91,6 +78,16 @@ class CParameterMgr // 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 @@ -383,147 +380,6 @@ class CParameterMgr // 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 setTuningModeCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getTuningModeCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Value Space - CCommandHandler::CommandStatus setValueSpaceCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getValueSpaceCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Output Raw Format - CCommandHandler::CommandStatus setOutputRawFormatCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getOutputRawFormatCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Sync - CCommandHandler::CommandStatus setAutoSyncCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getAutoSyncCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus syncCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Criteria - CCommandHandler::CommandStatus listCriteriaCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Domains - CCommandHandler::CommandStatus listDomainsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus createDomainCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus deleteDomainCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus deleteAllDomainsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus renameDomainCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus setSequenceAwarenessCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getSequenceAwarenessCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listDomainElementsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus addElementCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus removeElementCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus splitDomainCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Configurations - CCommandHandler::CommandStatus listConfigurationsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus dumpDomainsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus createConfigurationCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus deleteConfigurationCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus renameConfigurationCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus saveConfigurationCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus restoreConfigurationCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus setElementSequenceCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getElementSequenceCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus setRuleCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus clearRuleCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getRuleCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Elements/Parameters - CCommandHandler::CommandStatus listElementsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listParametersCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus dumpElementCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getElementSizeCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus showPropertiesCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getParameterCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus setParameterCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus getConfigurationParameterCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus setConfigurationParameterCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listBelongingDomainsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listAssociatedDomainsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus showMappingCommandProcess(const IRemoteCommand& remoteCommand, - std::string& strResult); - /// Browse - CCommandHandler::CommandStatus listAssociatedElementsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listConflictingElementsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus listRogueElementsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /// Settings Import/Export - CCommandHandler::CommandStatus exportDomainsXMLCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus importDomainsXMLCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus exportDomainsWithSettingsXMLCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus importDomainsWithSettingsXMLCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - /** - * Command handler method for exportDomainWithSettingsXML command. - * - * @param[in] remoteCommand contains the arguments of the received command. - * @param[out] result a std::string containing the result of the command - * - * @return CCommandHandler::ESucceeded if command succeeded or CCommandHandler::EFailed - * in the other case - */ - CCommandHandler::CommandStatus exportDomainWithSettingsXMLCommandProcess(const IRemoteCommand& remoteCommand, std::string& result); - CCommandHandler::CommandStatus importDomainWithSettingsXMLCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus exportSettingsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - CCommandHandler::CommandStatus importSettingsCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); - - /** - * Command handler method for getDomainsWithSettings 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 getDomainsWithSettingsXMLCommandProcess( - const IRemoteCommand& remoteCommand, std::string& strResult); - - /** - * Command handler method for getDomainWithSettings 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 getDomainWithSettingsXMLCommandProcess( - const IRemoteCommand& remoteCommand, std::string& strResult); - - /** - * Command handler method for setDomainsWithSettings 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 setDomainsWithSettingsXMLCommandProcess( - const IRemoteCommand& remoteCommand, std::string& strResult); - - /** - * Command handler method for setDomainWithSettings command. - * - * @param[in] remoteCommand contains the arguments of the received command. - * @param[out] result a std::string containing the result of the command - * - * @return CCommandHandler::ESucceeded if command succeeded or CCommandHandler::EFailed - * in the other case - */ - CCommandHandler::CommandStatus setDomainWithSettingsXMLCommandProcess( - const IRemoteCommand& remoteCommand, std::string& result); - - /** - * 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 getSystemClassXMLCommandProcess( - const IRemoteCommand& remoteCommand, std::string& strResult); // Max command usage length, use for formatting void setMaxCommandUsageLength(); @@ -715,17 +571,11 @@ class CParameterMgr // 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..2c143dfac --- /dev/null +++ b/parameter/command/include/command/Parser.h @@ -0,0 +1,245 @@ +/* + * 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 */ + using CommandReturn = CommandHandler::CommandStatus; + + //@{ + /** 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 exportConfigurableDomainWithSettingsToXML(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 setConfigurableDomainWithSettingsXML(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..14a6e8329 --- /dev/null +++ b/parameter/command/src/Parser.cpp @@ -0,0 +1,1073 @@ +/* + * 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 "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 (provide an absolute path or relative to the" + " client's working directory)" }, + { "importDomainsXML", &Parser::importConfigurableDomainsFromXML, 1, + "", "Import domains from XML file (provide an absolute path or relative to the" + " client's working directory)" }, + { "exportDomainsWithSettingsXML", + &Parser::exportConfigurableDomainsWithSettingsToXML, 1, + " ", "Export domains including settings to XML file (provide an absolute path or" + " relative to the client's working directory)" }, + { "exportDomainWithSettingsXML", + &Parser::exportConfigurableDomainWithSettingsToXML, 1, + " ", "Export a single given domain including settings to an XML file" + " (provide an absolute path or relative to the client's working" + " directory)" }, + { "importDomainsWithSettingsXML", + &Parser::importConfigurableDomainsWithSettingsFromXML, 1, + "", "Import domains including settings from XML file (provide an absolute path or" + " relative to the client's working directory)" }, + { "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 (provide an absolute path or relative" + " to the client's working directory)" }, + { "exportSettings", &Parser::exportSettings, 1, + "", "Export settings to binary file (provide an absolute path or relative to the" + " client's working directory)" }, + { "importSettings", &Parser::importSettings, 1, + "", "Import settings from binary file (provide an absolute path or relative to" + " the client's working directory)" }, + { "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" }, + { "setDomainWithSettingsXML", + &Parser::setConfigurableDomainWithSettingsXML, 1, + " [overwrite]", "Import a single domain including settings from an" + " XML string. Does not overwrite an existing domain" + " unless 'overwrite' is passed as second argument" }, + /// 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 &systemClass = mParameterMgr._systemClass; + + // Show status + /// General section + CUtility::appendTitle(result, "General:"); + // System class + result += "System Class: "; + result += systemClass.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 + CUtility::appendTitle(result, "Subsystems:"); + std::string strSubsystemList; + systemClass.listChildrenPaths(strSubsystemList); + result += strSubsystemList; + + /// Last applied configurations + CUtility::appendTitle(result, "Last Applied [Pending] Configurations:"); + std::string strLastAppliedConfigurations; + mParameterMgr._domains.listLastAppliedConfigurations( + strLastAppliedConfigurations); + result += strLastAppliedConfigurations; + + /// Criteria states + CUtility::appendTitle(result, "Selection Criteria:"); + std::list lstrSelectionCriteria; + mParameterMgr._criteria.listCriteria(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") { + if (!mParameterMgr.exportElementToXMLString( + &mParameterMgr._criteria, "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._criteria.listCriteria(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._domains.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._domains.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._domains.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._domains.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._domains.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._systemClass, 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._systemClass; + } + // Return sub-elements + result += pLocatedElement->listQualifiedPaths(false); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::listParameters(const IRemoteCommand& remoteCommand, + std::string& result) +{ + CElementLocator elementLocator(&mParameterMgr._systemClass, 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._systemClass; + } + // Return sub-elements + result += pLocatedElement->listQualifiedPaths(true); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::dumpElement(const IRemoteCommand& remoteCommand, + std::string& result) +{ + CElementLocator elementLocator(&mParameterMgr._systemClass); + 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._systemClass); + 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._systemClass); + 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._systemClass); + 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._systemClass); + 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._domains.listAssociatedElements(result); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::listConflictingElements(const IRemoteCommand&, std::string& result) +{ + mParameterMgr._domains.listConflictingElements(result); + return CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::listRogueElements(const IRemoteCommand&, std::string& result) +{ + mParameterMgr._systemClass.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::exportConfigurableDomainWithSettingsToXML(const IRemoteCommand& remoteCommand, + std::string& result) +{ + std::string domainName = remoteCommand.getArgument(0); + std::string fileName = remoteCommand.getArgument(1); + return mParameterMgr.exportSingleDomainXml(fileName, domainName, 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) +{ + std::string domainName = remoteCommand.getArgument(0); + bool overwrite = false; + + // Look for optional arguments + if (remoteCommand.getArgumentCount() > 1) { + + if (remoteCommand.getArgument(1) == "overwrite") { + + overwrite = true; + } else { + // Show usage + return CommandHandler::EShowUsage; + } + } + + return mParameterMgr.importSingleDomainXml(domainName, overwrite, true, true, 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::setConfigurableDomainWithSettingsXML(const IRemoteCommand& remoteCommand, + std::string& result) +{ + std::string domainName = remoteCommand.getArgument(0); + bool overwrite = false; + + // Look for optional arguments + if (remoteCommand.getArgumentCount() > 1) { + + if (remoteCommand.getArgument(1) == "overwrite") { + + overwrite = true; + } else { + // Show usage + return CommandHandler::EShowUsage; + } + } + + return mParameterMgr.importSingleDomainXml(domainName, overwrite, 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 &systemClass = mParameterMgr._systemClass; + + if (!mParameterMgr.exportElementToXMLString( + &systemClass, systemClass.getKind(), result)) { + + return CommandHandler::EFailed; + } + // Succeeded + return CommandHandler::ESucceeded; +} + +} /** command namespace */ +} /** core namespace */ From fa554519f071155994216ff60e8f1915121e3539 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Fri, 20 Feb 2015 18:13:46 +0100 Subject: [PATCH 02/13] 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 14a6e8329..2ac1e436a 100644 --- a/parameter/command/src/Parser.cpp +++ b/parameter/command/src/Parser.cpp @@ -220,11 +220,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 e3b62e733be7746e3d4d5c27b96b9fd9026bce77 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 23 Feb 2015 08:53:31 +0100 Subject: [PATCH 03/13] 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 2c143dfac..414123777 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 dbbe19de657012c43278badbc72f2228be746892 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 23 Feb 2015 10:00:14 +0100 Subject: [PATCH 04/13] 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 | 382 +++++++++--------- .../RemoteCommandHandlerTemplate.h | 192 +++------ test/test-platform/TestPlatform.cpp | 122 +++--- test/test-platform/TestPlatform.h | 5 +- 5 files changed, 317 insertions(+), 402 deletions(-) diff --git a/parameter/command/include/command/Parser.h b/parameter/command/include/command/Parser.h index 414123777..4e11450c0 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 @@ -225,11 +214,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 2ac1e436a..1ea8a650b 100644 --- a/parameter/command/src/Parser.cpp +++ b/parameter/command/src/Parser.cpp @@ -44,205 +44,211 @@ 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 (provide an absolute path or relative to the" - " client's working directory)" }, - { "importDomainsXML", &Parser::importConfigurableDomainsFromXML, 1, - "", "Import domains from XML file (provide an absolute path or relative to the" - " client's working directory)" }, +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 (provide an absolute path or relative to the client's working" + " directory)" } }, + { "importDomainsXML", + { &Parser::importConfigurableDomainsFromXML, 1, "", + "Import domains from XML file (provide an absolute path or relative to the client's " + "working directory)" } }, { "exportDomainsWithSettingsXML", - &Parser::exportConfigurableDomainsWithSettingsToXML, 1, - " ", "Export domains including settings to XML file (provide an absolute path or" - " relative to the client's working directory)" }, - { "exportDomainWithSettingsXML", - &Parser::exportConfigurableDomainWithSettingsToXML, 1, - " ", "Export a single given domain including settings to an XML file" - " (provide an absolute path or relative to the client's working" - " directory)" }, + { &Parser::exportConfigurableDomainsWithSettingsToXML, 1, " ", + "Export domains including settings to XML file (provide an absolute path or relative to" + " the client's working directory)" } }, { "importDomainsWithSettingsXML", - &Parser::importConfigurableDomainsWithSettingsFromXML, 1, - "", "Import domains including settings from XML file (provide an absolute path or" - " relative to the client's working directory)" }, + { &Parser::importConfigurableDomainsWithSettingsFromXML, 1, "", + "Import domains including settings from XML file (provide an absolute path or relative to" + " the client's working directory)" } }, + { "exportDomainWithSettingsXML", + { &Parser::exportConfigurableDomainWithSettingsToXML, 1, " ", + "Export a single given domain including settings to an XML file (provide an absolute path" + " or relative to the client's working directory)" } }, { "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 (provide an absolute path or relative" - " to the client's working directory)" }, - { "exportSettings", &Parser::exportSettings, 1, - "", "Export settings to binary file (provide an absolute path or relative to the" - " client's working directory)" }, - { "importSettings", &Parser::importSettings, 1, - "", "Import settings from binary file (provide an absolute path or relative to" - " the client's working directory)" }, + { &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 (provide an absolute path or relative to the client's working directory)" } }, + { "exportSettings", + { &Parser::exportSettings, 1, "", + "Export settings to binary file (provide an absolute path or relative to the client's " + "working directory)" } }, + { "importSettings", + { &Parser::importSettings, 1, "", + "Import settings from binary file (provide an absolute path or relative to the client's " + "working directory)" } }, { "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" }, + { &Parser::setConfigurableDomainsWithSettingsXML, 1, "", + "Import domains including settings from XML string" } }, { "setDomainWithSettingsXML", - &Parser::setConfigurableDomainWithSettingsXML, 1, - " [overwrite]", "Import a single domain including settings from an" - " XML string. Does not overwrite an existing domain" - " unless 'overwrite' is passed as second argument" }, - /// Structure Export - { "getSystemClassXML", &Parser::getSystemClassXML, 0, - "", "Print parameter structure as XML" }, + { &Parser::setConfigurableDomainWithSettingsXML, 1, " [overwrite]", + "Import a single domain including settings from an XML string. Does not overwrite an" + " existing domain unless 'overwrite' is passed as second argument" } }, + { "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..d98aba8ef 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 */ + using RemoteCommandParserItems = std::map; - 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 317ddf178..ae44af524 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -59,82 +59,63 @@ class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnect } }; +const CTestPlatform::CCommandHandler::RemoteCommandParserItems CTestPlatform:: +gRemoteCommandParserItems = { + { "exit", { &CTestPlatform::exit, 0, "", "Exit TestPlatform" } }, + { "createExclusiveCriterionFromStateList", + { &CTestPlatform::createCriterionFromStateList, 2, " ", + "Create inclusive selection criterion from state name list" } }, + { "createInclusiveCriterionFromStateList", + { &CTestPlatform::createCriterionFromStateList, 2, " ", + "Create exclusive selection criterion from state name list" } }, + { "createExclusiveCriterion", + { &CTestPlatform::createCriterionCommand, 2, " ", + "Create inclusive selection criterion" } }, + { "createInclusiveCriterion", + { &CTestPlatform::createCriterionCommand, 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), _exitSemaphore(exitSemaphore) { - _pCommandHandler = new CCommandHandler(this); - - // Add command parsers - _pCommandHandler->addCommandParser("exit", &CTestPlatform::exit, - 0, "", "Exit TestPlatform"); - _pCommandHandler->addCommandParser( - "createExclusiveCriterionFromStateList", - &CTestPlatform::createCriterionFromStateList, - 2, " ", - "Create inclusive selection criterion from state name list"); - _pCommandHandler->addCommandParser( - "createInclusiveCriterionFromStateList", - &CTestPlatform::createCriterionFromStateList, - 2, " ", - "Create exclusive selection criterion from state name list"); - - _pCommandHandler->addCommandParser( - "createExclusiveCriterion", - &CTestPlatform::createCriterionCommand, - 2, " ", "Create inclusive selection criterion"); - _pCommandHandler->addCommandParser( - "createInclusiveCriterion", - &CTestPlatform::createCriterionCommand, - 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 9a5b80f38..1cbf54d9d 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -190,12 +190,15 @@ class CTestPlatform CParameterMgrPlatformConnectorLogger* _pParameterMgrPlatformConnectorLogger; // Command Handler - CCommandHandler* _pCommandHandler; + CCommandHandler _commandHandler; // Remote Processor Server CRemoteProcessorServer* _pRemoteProcessorServer; // Semaphore used by calling thread to avoid exiting sem_t& _exitSemaphore; + + /** Parsing information for remote command */ + static const CCommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; }; From 8d5da2a7133ff43b9537fb3548800b4c73a18878 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 16 Jun 2015 16:18:46 +0200 Subject: [PATCH 05/13] Optimize command data handling Parsing data for remote command are always loaded even when the tuning is not allowed. This patch optimizes the memory handling by avoiding the command parser's load when the tuning is not allowed. Signed-off-by: Jules Clero --- parameter/ParameterMgr.cpp | 6 +- parameter/ParameterMgr.h | 5 +- parameter/command/include/command/Parser.h | 4 +- parameter/command/src/Parser.cpp | 413 +++++++++++---------- 4 files changed, 218 insertions(+), 210 deletions(-) diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 6e9f52669..e53abfee6 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -81,7 +81,6 @@ #include "Utility.h" #include #include -#include /** Private macro helper to declare a new context * @@ -148,7 +147,7 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge _pvLibRemoteProcessorHandle(NULL), _uiStructureChecksum(0), _pRemoteProcessorServer(NULL), - _commandParser(*this), + _commandParser(nullptr), _uiMaxCommandUsageLength(0), _logger(logger), _bForceNoRemoteInterface(false), @@ -1537,10 +1536,11 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) return false; } + _commandParser = ParserWrapper{ new command::Parser(*this) }; // Create server _pRemoteProcessorServer = pfnCreateRemoteProcessorServer(_pfwConfiguration.getServerPort(), - _commandParser.getCommandHandler()); + _commandParser->getCommandHandler()); info() << "Starting remote processor server on port " << _pfwConfiguration.getServerPort(); // Start diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index 98de68497..eeb146b21 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -574,8 +574,11 @@ class CParameterMgr // Remote Processor Server IRemoteProcessorServerInterface* _pRemoteProcessorServer; + /** Command parser manager type */ + using ParserWrapper = std::unique_ptr; + /** Remote commands Parser */ - core::command::Parser _commandParser; + ParserWrapper _commandParser; // Maximum command usage length uint32_t _uiMaxCommandUsageLength; diff --git a/parameter/command/include/command/Parser.h b/parameter/command/include/command/Parser.h index 4e11450c0..e48260bc5 100644 --- a/parameter/command/include/command/Parser.h +++ b/parameter/command/include/command/Parser.h @@ -214,8 +214,8 @@ class Parser CommandReturn getSystemClassXML(const IRemoteCommand& remoteCommand, std::string& result); //@} - /** Parser items map */ - static const CommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; + /** Parser items getter */ + const CommandHandler::RemoteCommandParserItems &getRemoteParserItems() const; /** Parameter Manager used to delegate parsed commands */ CParameterMgr& mParameterMgr; diff --git a/parameter/command/src/Parser.cpp b/parameter/command/src/Parser.cpp index 1ea8a650b..fd3851246 100644 --- a/parameter/command/src/Parser.cpp +++ b/parameter/command/src/Parser.cpp @@ -44,211 +44,216 @@ namespace core namespace command { -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 (provide an absolute path or relative to the client's working" - " directory)" } }, - { "importDomainsXML", - { &Parser::importConfigurableDomainsFromXML, 1, "", - "Import domains from XML file (provide an absolute path or relative to the client's " - "working directory)" } }, - { "exportDomainsWithSettingsXML", - { &Parser::exportConfigurableDomainsWithSettingsToXML, 1, " ", - "Export domains including settings to XML file (provide an absolute path or relative to" - " the client's working directory)" } }, - { "importDomainsWithSettingsXML", - { &Parser::importConfigurableDomainsWithSettingsFromXML, 1, "", - "Import domains including settings from XML file (provide an absolute path or relative to" - " the client's working directory)" } }, - { "exportDomainWithSettingsXML", - { &Parser::exportConfigurableDomainWithSettingsToXML, 1, " ", - "Export a single given domain including settings to an XML file (provide an absolute path" - " or relative to the client's working directory)" } }, - { "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 (provide an absolute path or relative to the client's working directory)" } }, - { "exportSettings", - { &Parser::exportSettings, 1, "", - "Export settings to binary file (provide an absolute path or relative to the client's " - "working directory)" } }, - { "importSettings", - { &Parser::importSettings, 1, "", - "Import settings from binary file (provide an absolute path or relative to the client's " - "working directory)" } }, - { "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" } }, - { "setDomainWithSettingsXML", - { &Parser::setConfigurableDomainWithSettingsXML, 1, " [overwrite]", - "Import a single domain including settings from an XML string. Does not overwrite an" - " existing domain unless 'overwrite' is passed as second argument" } }, - { "getSystemClassXML", - { &Parser::getSystemClassXML, 0, "", - "Print parameter structure as XML" } }, -}; - Parser::Parser(CParameterMgr& parameterMgr) : - mParameterMgr(parameterMgr), mCommandHandler(CommandHandler(this, gRemoteCommandParserItems)) -{ + mParameterMgr(parameterMgr), mCommandHandler(CommandHandler(this, getRemoteParserItems())) +{ +} + +const Parser::CommandHandler::RemoteCommandParserItems &Parser::getRemoteParserItems() const +{ + static const CommandHandler::RemoteCommandParserItems remoteCommandParserItems = { + { "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 (provide an absolute path or relative to the client's working" + " directory)" } }, + { "importDomainsXML", + { &Parser::importConfigurableDomainsFromXML, 1, "", + "Import domains from XML file (provide an absolute path or relative to the client's " + "working directory)" } }, + { "exportDomainsWithSettingsXML", + { &Parser::exportConfigurableDomainsWithSettingsToXML, 1, " ", + "Export domains including settings to XML file (provide an absolute path or relative to" + " the client's working directory)" } }, + { "importDomainsWithSettingsXML", + { &Parser::importConfigurableDomainsWithSettingsFromXML, 1, "", + "Import domains including settings from XML file (provide an absolute path or relative to" + " the client's working directory)" } }, + { "exportDomainWithSettingsXML", + { &Parser::exportConfigurableDomainWithSettingsToXML, 1, " ", + "Export a single given domain including settings to an XML file (provide an absolute path" + " or relative to the client's working directory)" } }, + { "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 (provide an absolute path or relative to the client's working directory)" } }, + { "exportSettings", + { &Parser::exportSettings, 1, "", + "Export settings to binary file (provide an absolute path or relative to the client's " + "working directory)" } }, + { "importSettings", + { &Parser::importSettings, 1, "", + "Import settings from binary file (provide an absolute path or relative to the client's " + "working directory)" } }, + { "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" } }, + { "setDomainWithSettingsXML", + { &Parser::setConfigurableDomainWithSettingsXML, 1, " [overwrite]", + "Import a single domain including settings from an XML string. Does not overwrite an" + " existing domain unless 'overwrite' is passed as second argument" } }, + { "getSystemClassXML", + { &Parser::getSystemClassXML, 0, "", + "Print parameter structure as XML" } } + }; + + return remoteCommandParserItems; } Parser::CommandHandler* Parser::getCommandHandler() From f57e62f214ebcbf1b389d19d93fc7a0e30f0fcc1 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 9 Mar 2015 14:16:06 +0100 Subject: [PATCH 06/13] 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 fd3851246..1c2568e49 100644 --- a/parameter/command/src/Parser.cpp +++ b/parameter/command/src/Parser.cpp @@ -45,7 +45,7 @@ namespace command { Parser::Parser(CParameterMgr& parameterMgr) : - mParameterMgr(parameterMgr), mCommandHandler(CommandHandler(this, getRemoteParserItems())) + mParameterMgr(parameterMgr), mCommandHandler(CommandHandler(*this, getRemoteParserItems())) { } diff --git a/remote-processor/RemoteCommandHandlerTemplate.h b/remote-processor/RemoteCommandHandlerTemplate.h index d98aba8ef..152f4f7f4 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 using RemoteCommandParserItems = std::map; /** - * @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 ae44af524..98dcedb18 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -111,7 +111,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), _exitSemaphore(exitSemaphore) { // Create server From b576c41505260d7bad474d69d18ca81c3e489b7e Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 9 Mar 2015 15:11:09 +0100 Subject: [PATCH 07/13] 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 e48260bc5..1bfecc40f 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; + using CommandHandler = RemoteCommandHandlerTemplate; /** Class constructor * diff --git a/remote-processor/RemoteCommandHandlerTemplate.h b/remote-processor/RemoteCommandHandlerTemplate.h index 152f4f7f4..9f6219d4a 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 */ using RemoteCommandParserItems = std::map; @@ -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 1cbf54d9d..1f25524fa 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -40,7 +40,7 @@ class CRemoteProcessorServer; class CTestPlatform { - typedef TRemoteCommandHandlerTemplate CCommandHandler; + typedef RemoteCommandHandlerTemplate CCommandHandler; typedef CCommandHandler::CommandStatus CommandReturn; public: CTestPlatform(const std::string &strclass, int iPortNumber, sem_t& exitSemaphore); From 0a80612d455f89c371d31c2b9f761b7f8e26dcb8 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Mon, 30 Mar 2015 09:19:20 +0200 Subject: [PATCH 08/13] 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 98dcedb18..595d8d8fc 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 1f25524fa..56b0c95ea 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 df91f3be49c459d4d32870ee72e80f9cc53de62b Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Fri, 27 Mar 2015 17:35:40 +0100 Subject: [PATCH 09/13] Delegate Test-platform command Parser behavior Signed-off-by: Jules Clero --- test/test-platform/CMakeLists.txt | 8 +- test/test-platform/TestPlatform.cpp | 236 ++---------------- test/test-platform/TestPlatform.h | 199 +++++++-------- .../command/include/command/Parser.h | 172 +++++++++++++ test/test-platform/command/src/Parser.cpp | 174 +++++++++++++ test/test-platform/main.cpp | 4 +- 6 files changed, 461 insertions(+), 332 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 aebec2e83..487017479 100644 --- a/test/test-platform/CMakeLists.txt +++ b/test/test-platform/CMakeLists.txt @@ -28,12 +28,12 @@ add_executable(test-platform main.cpp - TestPlatform.cpp) - -# FIXME: Supress the need for the -Wno-unused-parameter -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") + TestPlatform.cpp + command/src/Parser.cpp) include_directories( + "." + "command/include" "${PROJECT_SOURCE_DIR}/parameter/criterion/include" "${PROJECT_SOURCE_DIR}/parameter/include" "${PROJECT_SOURCE_DIR}/remote-processor" diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index 595d8d8fc..232e9cabd 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -28,90 +28,26 @@ * 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; -using core::criterion::Criterion; -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" } }, - { "createExclusiveCriterionFromStateList", - { &CTestPlatform::createCriterionFromStateList, 2, " ", - "Create inclusive selection criterion from state name list" } }, - { "createInclusiveCriterionFromStateList", - { &CTestPlatform::createCriterionFromStateList, 2, " ", - "Create exclusive selection criterion from state name list" } }, - { "createExclusiveCriterion", - { &CTestPlatform::createCriterionCommand, 2, " ", - "Create inclusive selection criterion" } }, - { "createInclusiveCriterion", - { &CTestPlatform::createCriterionCommand, 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), _exitSemaphore(exitSemaphore) { // Create server - _pRemoteProcessorServer = new CRemoteProcessorServer(iPortNumber, &_commandHandler); + _pRemoteProcessorServer = new CRemoteProcessorServer(iPortNumber, + _commandParser.getCommandHandler()); _pParameterMgrPlatformConnector->setLogger(_pParameterMgrPlatformConnectorLogger); } @@ -123,17 +59,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 @@ -146,78 +71,17 @@ bool CTestPlatform::load(std::string& strError) return true; } -//////////////// Remote command parsers -/// Criterion - -template CTestPlatform::CommandReturn -CTestPlatform::createCriterionFromStateList(const IRemoteCommand& remoteCommand, - string& strResult) -{ - return createCriterion(remoteCommand.getArgument(0), - remoteCommand, strResult) ? - CTestPlatform::CCommandHandler::EDone : CTestPlatform::CCommandHandler::EFailed; -} - -template CTestPlatform::CommandReturn -CTestPlatform::createCriterionCommand(const IRemoteCommand& remoteCommand, string& strResult) -{ - return createCriterion( - remoteCommand.getArgument(0), - (uint32_t) 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 CTestPlatform::setCriterionState(std::string criterionName, + const IRemoteCommand& remoteCommand, + string& strResult) { - // Get criterion name - std::string strCriterionName = remoteCommand.getArgument(0); - - Criterion* pCriterion = - _pParameterMgrPlatformConnector->getCriterion(strCriterionName); + core::criterion::Criterion* pCriterion = + _pParameterMgrPlatformConnector->getCriterion(criterionName); if (!pCriterion) { - strResult = "Unable to retrieve selection criterion: " + strCriterionName; - - return CTestPlatform::CCommandHandler::EFailed; + strResult = "Unable to retrieve selection criterion: " + criterionName; + return false; } // Get substate number, the first argument (index 0) is the criterion name @@ -230,76 +94,10 @@ CTestPlatform::CommandReturn CTestPlatform::setCriterionState( // Set criterion new state if (!pCriterion->setState(state, strResult)) { - return CTestPlatform::CCommandHandler::EFailed; - } - - return CTestPlatform::CCommandHandler::EDone; -} - -CTestPlatform::CommandReturn CTestPlatform::applyConfigurations(const IRemoteCommand& remoteCommand, - string& strResult) -{ - (void)remoteCommand; - (void)strResult; - - _pParameterMgrPlatformConnector->applyConfigurations(); - - return CTestPlatform::CCommandHandler::EDone; -} - -//////////////// Remote command handlers - -template -bool CTestPlatform::createCriterion(const string& name, - const IRemoteCommand& remoteCommand, - string& result) -{ - - assert(_pParameterMgrPlatformConnector != NULL); - - uint32_t nbStates = remoteCommand.getArgumentCount() - 1; - - using namespace core::criterion; - Values values; - - for (uint32_t state = 0; state < nbStates; state++) { - - const std::string& value = remoteCommand.getArgument(state + 1); - values.emplace_back(value); - } - return createCriterion(name, values, result); -} - -template -bool CTestPlatform::createCriterion(const string& name, - uint32_t nbStates, - string& result) -{ - using namespace core::criterion; - Values values; - - for (uint32_t state = 0; state < nbStates; state++) { - // Generate value names, those name are legacy and should be uniformized - // after functionnal tests rework - values.emplace_back((isInclusive ? "State_0x" + std::to_string(state + 1) : - "State_" + std::to_string(state))); - } - return createCriterion(name, values, result); -} - -template -bool CTestPlatform::createCriterion(const string& name, - const core::criterion::Values &values, - string& result) -{ - Criterion* criterion = (isInclusive ? - _pParameterMgrPlatformConnector->createInclusiveCriterion(name, values, result) : - _pParameterMgrPlatformConnector->createExclusiveCriterion(name, values, result)); - - - if (criterion == nullptr) { return false; } - return true; } + +} /** platform namespace */ +} /** test namespace */ diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index 56b0c95ea..2e4adc0a4 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -29,120 +29,56 @@ */ #pragma once +#include "command/Parser.h" #include "ParameterMgrPlatformConnector.h" -#include "RemoteCommandHandlerTemplate.h" +#include "RemoteProcessorServer.h" +#include #include #include +#include -class CParameterMgrPlatformConnectorLogger; class CRemoteProcessorServer; -class CTestPlatform +namespace test +{ +namespace platform +{ +namespace log { - typedef RemoteCommandHandlerTemplate CCommandHandler; - typedef CCommandHandler::CommandStatus CommandReturn; -public: - CTestPlatform(const std::string &strclass, int iPortNumber, sem_t& exitSemaphore); - virtual ~CTestPlatform(); - - // Init - bool load(std::string& strError); -private: - //////////////// Remote command parsers +/** Logger exposed to the parameter-framework */ +class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnector::ILogger +{ +public: + CParameterMgrPlatformConnectorLogger() {} - /** Callback to create a Criterion from possible state list - * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return - * - * @tparam isInclusive true for creating inclusive criterion, false for an exclusive one - * @param[in] remoteCommand the first argument should be the name of the criterion to create. - * the following arguments should be criterion possible values - */ - template - CommandReturn createCriterionFromStateList(const IRemoteCommand& remoteCommand, - std::string& strResult); + virtual void info(const std::string& log) + { + std::cout << log << std::endl; + } - /** Callback to create a Criterion - * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return - * - * @tparam isInclusive true for creating inclusive criterion, false for an exclusive one - * @param[in] remoteCommand the first argument should be the name of the criterion to create. - * the second argument should be criterion possible values number - * - * Generated states numerical value will be like: State_0xX, where X is the value number of the - * state. - */ - template - CommandReturn createCriterionCommand(const IRemoteCommand& remoteCommand, - std::string& strResult); + virtual void warning(const std::string& log) + { + std::cerr << log << std::endl; + } +}; - /** Callback to set a criterion's value, see CriterionInterface::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. - * the following arguments should be criterion new values - */ - CommandReturn setCriterionState( - const IRemoteCommand& remoteCommand, std::string& strResult); +} /** log namespace */ - /** 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); +class CTestPlatform +{ - /** 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); + /** Remote command parser has access to private command handle function */ + friend class command::Parser; - /** Callback to exit the test-platform. - * - * @param[in] remoteCommand is ignored - * - * @return EDone (never fails) - */ - CommandReturn exit(const IRemoteCommand& remoteCommand, std::string& strResult); +public: + CTestPlatform(const std::string &strclass, int iPortNumber, sem_t& exitSemaphore); + virtual ~CTestPlatform(); - /** 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); + // Init + bool load(std::string& strError); - // Commands +private: /** @see callback with the same arguments for details and other parameters * @@ -151,11 +87,27 @@ class CTestPlatform * @param[in] name the criterion name * @param[out] result useful information that client may want to retrieve * @return true if success, false otherwise + * + * FIXME: remote command should only appear in parser, we need an easy way + * to retrieve a vector of argument */ template bool createCriterion(const std::string& name, const IRemoteCommand& command, - std::string& result); + std::string& result) + { + assert(_pParameterMgrPlatformConnector != NULL); + + uint32_t nbStates = command.getArgumentCount() - 1; + + core::criterion::Values values; + for (uint32_t state = 0; state < nbStates; state++) { + + const std::string& value = command.getArgument(state + 1); + values.emplace_back(value); + } + return createCriterion(name, values, result); + } /** Create a criterion by generating a given number of values * @@ -167,7 +119,17 @@ class CTestPlatform * @return true if success, false otherwise */ template - bool createCriterion(const std::string& name, uint32_t nbValues, std::string& result); + bool createCriterion(const std::string& name, uint32_t nbValues, std::string& result) + { + core::criterion::Values values; + for (uint32_t state = 0; state < nbValues; state++) { + // Generate value names, those name are legacy and should be uniformized + // after functionnal tests rework + values.emplace_back((isInclusive ? "State_0x" + std::to_string(state + 1) : + "State_" + std::to_string(state))); + } + return createCriterion(name, values, result); + } /** Create a criterion with desired values * @tparam isInclusive true for creating inclusive criterion, false for an exclusive one @@ -180,24 +142,47 @@ class CTestPlatform template bool createCriterion(const std::string& name, const core::criterion::Values &values, - std::string& result); + std::string& result) + { + core::criterion::Criterion* criterion = (isInclusive ? + _pParameterMgrPlatformConnector->createInclusiveCriterion(name, values, result) : + _pParameterMgrPlatformConnector->createExclusiveCriterion(name, values, result)); + + if (criterion == nullptr) { + return false; + } + + return true; + } + + /** @see callback with the same arguments for details and other parameters + * + * @param[in] name the criterion name + * @param[out] result useful information that client may want to retrieve + * @return true if success, false otherwise + * + * FIXME: remote command should only appear in parser, we need an easy way + * to retrieve a vector of argument + */ + bool setCriterionState(std::string criterionName, + const IRemoteCommand& remoteCommand, + std::string& strResult); // Connector CParameterMgrPlatformConnector* _pParameterMgrPlatformConnector; // Logger - CParameterMgrPlatformConnectorLogger* _pParameterMgrPlatformConnectorLogger; + log::CParameterMgrPlatformConnectorLogger* _pParameterMgrPlatformConnectorLogger; - // Command Handler - CCommandHandler _commandHandler; + /** Command Parser delegate */ + command::Parser _commandParser; // Remote Processor Server CRemoteProcessorServer* _pRemoteProcessorServer; // 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..6d9843a72 --- /dev/null +++ b/test/test-platform/command/include/command/Parser.h @@ -0,0 +1,172 @@ +/* + * 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 */ + using CommandHandler = RemoteCommandHandlerTemplate; + + /** Class constructor + * + * @param test-platform reference + */ + Parser(CTestPlatform& testPlatform); + + /** Internal command handler getter + * + * @return pointer on the internal command handler + */ + CommandHandler* getCommandHandler(); + +private: + + /** Command handler method return type */ + using CommandReturn = CommandHandler::CommandStatus; + + /** Callback to create a Criterion from possible state list + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * @tparam isInclusive true for creating inclusive criterion, false for an exclusive one + * @param[in] remoteCommand the first argument should be the name of the criterion to create. + * the following arguments should be criterion possible values + */ + template + CommandReturn createCriterionFromStateList(const IRemoteCommand& remoteCommand, + std::string& result); + + /** Callback to create a Criterion + * @see CCommandHandler::RemoteCommandParser for detail on each arguments and return + * + * @tparam isInclusive true for creating inclusive criterion, false for an exclusive one + * @param[in] remoteCommand the first argument should be the name of the criterion to create. + * the second argument should be criterion possible values number + * + * Generated states numerical value will be like: State_0xX, where X is the value number of the + * state. + */ + template + CommandReturn createCriterion(const IRemoteCommand& remoteCommand, std::string& result); + + /** Callback to set a criterion's value, see core::criterion::Criterion::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. + * the following arguments should be criterion new values + */ + CommandReturn setCriterionState(const IRemoteCommand& remoteCommand, std::string& result); + + /** 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& result); + + /** 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& result); + + /** Callback to exit the test-platform. + * + * @param[in] remoteCommand is ignored + * + * @return EDone (never fails) + */ + CommandReturn exit(const IRemoteCommand& remoteCommand, std::string& result); + + /** The type of a CParameterMgrPlatformConnector boolean setter. */ + using setter_t = bool (CParameterMgrPlatformConnector::*)(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& result); + + /** The type of a CParameterMgrPlatformConnector boolean getter. */ + using getter_t = bool (CParameterMgrPlatformConnector::*)(); + + /** 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& result); + + /** 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..2217bf436 --- /dev/null +++ b/test/test-platform/command/src/Parser.cpp @@ -0,0 +1,174 @@ +/* + * 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" } }, + { "createExclusiveCriterionFromStateList", + { &Parser::createCriterionFromStateList, 2, " ", + "Create inclusive selection criterion from state name list" } }, + { "createInclusiveCriterionFromStateList", + { &Parser::createCriterionFromStateList, 2, " ", + "Create exclusive selection criterion from state name list" } }, + { "createExclusiveCriterion", + { &Parser::createCriterion, 2, " ", + "Create inclusive selection criterion" } }, + { "createInclusiveCriterion", + { &Parser::createCriterion, 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; +} + +template Parser::CommandReturn +Parser::createCriterion(const IRemoteCommand& remoteCommand, std::string& result) +{ + uint32_t nbValues = 0; + if(!convertTo(remoteCommand.getArgument(1), nbValues)) { + return Parser::CommandHandler::EShowUsage; + } + return mTestPlatform.createCriterion(remoteCommand.getArgument(0), + nbValues, result) ? + Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; +} + +template Parser::CommandReturn +Parser::createCriterionFromStateList(const IRemoteCommand& remoteCommand, std::string& result) +{ + return mTestPlatform.createCriterion(remoteCommand.getArgument(0), + remoteCommand, result) ? + Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; +} + +Parser::CommandReturn Parser::startParameterMgr(const IRemoteCommand&, std::string& result) +{ + return mTestPlatform._pParameterMgrPlatformConnector->start(result) ? + Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; +} + +template +Parser::CommandReturn Parser::setter(const IRemoteCommand& remoteCommand, std::string& result) +{ + bool fail; + if(!convertTo(remoteCommand.getArgument(0), fail)) { + return Parser::CommandHandler::EShowUsage; + } + return (mTestPlatform._pParameterMgrPlatformConnector->*setFunction)(fail, result) ? + Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; +} + +template +Parser::CommandReturn Parser::getter(const IRemoteCommand&, std::string& result) +{ + result = (mTestPlatform._pParameterMgrPlatformConnector->*getFunction)() ? "true" : "false"; + return Parser::CommandHandler::ESucceeded; +} + +Parser::CommandReturn Parser::setCriterionState(const IRemoteCommand& remoteCommand, + std::string& result) +{ + return mTestPlatform.setCriterionState(remoteCommand.getArgument(0), + remoteCommand, + result) ? + 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 6a79597f5..ca620439b 100644 --- a/test/test-platform/main.cpp +++ b/test/test-platform/main.cpp @@ -53,7 +53,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)) { @@ -116,7 +116,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 loadSuccess = testPlatform.load(strError); From a6e6d22d93ac7db683f07908e78437d9a0cad812 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Fri, 27 Mar 2015 16:39:06 +0100 Subject: [PATCH 10/13] 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 | 4 +- .../RemoteCommandHandlerTemplate.h | 52 ++++++++----------- .../command/include/command/Parser.h | 2 +- test/test-platform/command/src/Parser.cpp | 2 +- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/parameter/command/include/command/Parser.h b/parameter/command/include/command/Parser.h index 1bfecc40f..e81a1c75d 100644 --- a/parameter/command/include/command/Parser.h +++ b/parameter/command/include/command/Parser.h @@ -215,7 +215,7 @@ class Parser //@} /** Parser items getter */ - const CommandHandler::RemoteCommandParserItems &getRemoteParserItems() const; + CommandHandler::RemoteCommandParserItems &getRemoteParserItems() const; /** Parameter Manager used to delegate parsed commands */ CParameterMgr& mParameterMgr; diff --git a/parameter/command/src/Parser.cpp b/parameter/command/src/Parser.cpp index 1c2568e49..30241a9cb 100644 --- a/parameter/command/src/Parser.cpp +++ b/parameter/command/src/Parser.cpp @@ -49,9 +49,9 @@ Parser::Parser(CParameterMgr& parameterMgr) : { } -const Parser::CommandHandler::RemoteCommandParserItems &Parser::getRemoteParserItems() const +Parser::CommandHandler::RemoteCommandParserItems &Parser::getRemoteParserItems() const { - static const CommandHandler::RemoteCommandParserItems remoteCommandParserItems = { + static CommandHandler::RemoteCommandParserItems remoteCommandParserItems = { { "version", { &Parser::version, 0, "", "Show version" } }, diff --git a/remote-processor/RemoteCommandHandlerTemplate.h b/remote-processor/RemoteCommandHandlerTemplate.h index 9f6219d4a..fd32e0ba1 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 6d9843a72..79564f6ed 100644 --- a/test/test-platform/command/include/command/Parser.h +++ b/test/test-platform/command/include/command/Parser.h @@ -158,7 +158,7 @@ class Parser CommandReturn getter(const IRemoteCommand& remoteCommand, std::string& result); /** 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 2217bf436..eeb92316f 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" } }, From 5ae092aa8cedd4dea927d9db3d1c0e771203fdd6 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Tue, 16 Jun 2015 14:56:21 +0200 Subject: [PATCH 11/13] Rename remote command 'help' string to 'argument description' Previous name was not clear as the help of a command can be many thing. This patch renames it 'argument description' as it describe exactly what we are waiting. Signed-off-by: Jules Clero --- .../RemoteCommandHandlerTemplate.h | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/remote-processor/RemoteCommandHandlerTemplate.h b/remote-processor/RemoteCommandHandlerTemplate.h index fd32e0ba1..87129c54e 100644 --- a/remote-processor/RemoteCommandHandlerTemplate.h +++ b/remote-processor/RemoteCommandHandlerTemplate.h @@ -69,16 +69,16 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler /** * @param parser command handler callback * @param minArgumentCount command required arguments number - * @param help string containing command help + * @param argumentDescription string containing the description of each command argument * @param description string containing command description */ RemoteCommandParserItem(RemoteCommandParser parser, uint32_t minArgumentCount, - const std::string& help, + const std::string& argumentDescription, const std::string& description) : mParser(parser), mMinArgumentCount(minArgumentCount), - mHelp(help), + mArgumentDescription(argumentDescription), mDescription(description) { } @@ -92,13 +92,13 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler return mDescription; } - /** Command help string getter + /** Description of each argument of the command * - * @return the command help string + * @return the command argument description string */ - const std::string getHelp() const + const std::string getArgumentDescription() const { - return mHelp; + return mArgumentDescription; } /** Parse and launch a remote command @@ -115,8 +115,8 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler // Check enough arguments supplied if (remoteCommand.getArgumentCount() < mMinArgumentCount) { - result = std::string("Not enough arguments supplied\nUsage:\n") + getHelp(); - + result = std::string("Not enough arguments supplied\nUsage:\n") + + getArgumentDescription(); return false; } @@ -127,7 +127,7 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler case ESucceeded: return true; case EShowUsage: - result = getHelp(); + result = getArgumentDescription(); // Fall through intentionally case EFailed: return false; @@ -144,8 +144,8 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler /** Needed arguments number */ uint32_t mMinArgumentCount; - /** Command help string */ - std::string mHelp; + /** Command argument description string */ + std::string mArgumentDescription; /** Command description string */ std::string mDescription; @@ -211,7 +211,7 @@ class RemoteCommandHandlerTemplate : public IRemoteCommandHandler size_t maxUsage = 0; for (auto& item : _remoteCommandParserItems) { - std::string usage = item.first + ' ' + item.second.getHelp(); + std::string usage = item.first + ' ' + item.second.getArgumentDescription(); helps.push_back({ usage, item.second.getDescription() }); maxUsage = std::max(maxUsage, usage.length()); } From f19f6c7e194618b152374c447bb2df37af3ba2f8 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Wed, 17 Jun 2015 11:57:48 +0200 Subject: [PATCH 12/13] test-platform: stop using pointer without reason Signed-off-by: Jules Clero --- test/test-platform/TestPlatform.cpp | 22 ++++++---------------- test/test-platform/TestPlatform.h | 20 ++++++++------------ test/test-platform/command/src/Parser.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index 232e9cabd..58183f3d6 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -40,29 +40,19 @@ namespace platform { CTestPlatform::CTestPlatform(const string& strClass, int iPortNumber, sem_t& exitSemaphore) : - _pParameterMgrPlatformConnector(new CParameterMgrPlatformConnector(strClass)), - _pParameterMgrPlatformConnectorLogger(new log::CParameterMgrPlatformConnectorLogger), + _parameterMgrPlatformConnector(strClass), + _parameterMgrPlatformConnectorLogger(), _commandParser(*this), + _remoteProcessorServer(iPortNumber, _commandParser.getCommandHandler()), _exitSemaphore(exitSemaphore) { - // Create server - _pRemoteProcessorServer = new CRemoteProcessorServer(iPortNumber, - _commandParser.getCommandHandler()); - - _pParameterMgrPlatformConnector->setLogger(_pParameterMgrPlatformConnectorLogger); -} - -CTestPlatform::~CTestPlatform() -{ - delete _pRemoteProcessorServer; - delete _pParameterMgrPlatformConnectorLogger; - delete _pParameterMgrPlatformConnector; + _parameterMgrPlatformConnector.setLogger(&_parameterMgrPlatformConnectorLogger); } bool CTestPlatform::load(std::string& strError) { // Start remote processor server - if (!_pRemoteProcessorServer->start(strError)) { + if (!_remoteProcessorServer.start(strError)) { strError = "TestPlatform: Unable to start remote processor server: " + strError; return false; @@ -76,7 +66,7 @@ bool CTestPlatform::setCriterionState(std::string criterionName, string& strResult) { core::criterion::Criterion* pCriterion = - _pParameterMgrPlatformConnector->getCriterion(criterionName); + _parameterMgrPlatformConnector.getCriterion(criterionName); if (!pCriterion) { diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index 2e4adc0a4..3176e9ad8 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -32,7 +32,6 @@ #include "command/Parser.h" #include "ParameterMgrPlatformConnector.h" #include "RemoteProcessorServer.h" -#include #include #include #include @@ -73,7 +72,6 @@ class CTestPlatform public: CTestPlatform(const std::string &strclass, int iPortNumber, sem_t& exitSemaphore); - virtual ~CTestPlatform(); // Init bool load(std::string& strError); @@ -96,8 +94,6 @@ class CTestPlatform const IRemoteCommand& command, std::string& result) { - assert(_pParameterMgrPlatformConnector != NULL); - uint32_t nbStates = command.getArgumentCount() - 1; core::criterion::Values values; @@ -145,8 +141,8 @@ class CTestPlatform std::string& result) { core::criterion::Criterion* criterion = (isInclusive ? - _pParameterMgrPlatformConnector->createInclusiveCriterion(name, values, result) : - _pParameterMgrPlatformConnector->createExclusiveCriterion(name, values, result)); + _parameterMgrPlatformConnector.createInclusiveCriterion(name, values, result) : + _parameterMgrPlatformConnector.createExclusiveCriterion(name, values, result)); if (criterion == nullptr) { return false; @@ -168,17 +164,17 @@ class CTestPlatform const IRemoteCommand& remoteCommand, std::string& strResult); - // Connector - CParameterMgrPlatformConnector* _pParameterMgrPlatformConnector; + /** Parameter-Framework Connector */ + CParameterMgrPlatformConnector _parameterMgrPlatformConnector; - // Logger - log::CParameterMgrPlatformConnectorLogger* _pParameterMgrPlatformConnectorLogger; + /** Parameter-Framework Logger */ + log::CParameterMgrPlatformConnectorLogger _parameterMgrPlatformConnectorLogger; /** Command Parser delegate */ command::Parser _commandParser; - // Remote Processor Server - CRemoteProcessorServer* _pRemoteProcessorServer; + /** Remote Processor Server */ + CRemoteProcessorServer _remoteProcessorServer; // Semaphore used by calling thread to avoid exiting sem_t& _exitSemaphore; diff --git a/test/test-platform/command/src/Parser.cpp b/test/test-platform/command/src/Parser.cpp index eeb92316f..449925266 100644 --- a/test/test-platform/command/src/Parser.cpp +++ b/test/test-platform/command/src/Parser.cpp @@ -131,7 +131,7 @@ Parser::createCriterionFromStateList(const IRemoteCommand& remoteCommand, std::s Parser::CommandReturn Parser::startParameterMgr(const IRemoteCommand&, std::string& result) { - return mTestPlatform._pParameterMgrPlatformConnector->start(result) ? + return mTestPlatform._parameterMgrPlatformConnector.start(result) ? Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; } @@ -142,14 +142,14 @@ Parser::CommandReturn Parser::setter(const IRemoteCommand& remoteCommand, std::s if(!convertTo(remoteCommand.getArgument(0), fail)) { return Parser::CommandHandler::EShowUsage; } - return (mTestPlatform._pParameterMgrPlatformConnector->*setFunction)(fail, result) ? + return (mTestPlatform._parameterMgrPlatformConnector.*setFunction)(fail, result) ? Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; } template Parser::CommandReturn Parser::getter(const IRemoteCommand&, std::string& result) { - result = (mTestPlatform._pParameterMgrPlatformConnector->*getFunction)() ? "true" : "false"; + result = (mTestPlatform._parameterMgrPlatformConnector.*getFunction)() ? "true" : "false"; return Parser::CommandHandler::ESucceeded; } @@ -164,7 +164,7 @@ Parser::CommandReturn Parser::setCriterionState(const IRemoteCommand& remoteComm Parser::CommandReturn Parser::applyConfigurations(const IRemoteCommand&, std::string&) { - mTestPlatform._pParameterMgrPlatformConnector->applyConfigurations(); + mTestPlatform._parameterMgrPlatformConnector.applyConfigurations(); return Parser::CommandHandler::EDone; } From 8e90acadf4431fc930e7053468e04094dc782d2d Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Wed, 17 Jun 2015 15:37:51 +0200 Subject: [PATCH 13/13] test-platform: Shift to the new naming convention Signed-off-by: Jules Clero --- test/test-platform/TestPlatform.cpp | 30 +++++++------- test/test-platform/TestPlatform.h | 40 ++++++++++++------- .../command/include/command/Parser.h | 6 +-- test/test-platform/command/src/Parser.cpp | 12 +++--- test/test-platform/main.cpp | 31 +++++++------- 5 files changed, 65 insertions(+), 54 deletions(-) diff --git a/test/test-platform/TestPlatform.cpp b/test/test-platform/TestPlatform.cpp index 58183f3d6..ab9d1fa50 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -39,38 +39,38 @@ namespace test namespace platform { -CTestPlatform::CTestPlatform(const string& strClass, int iPortNumber, sem_t& exitSemaphore) : - _parameterMgrPlatformConnector(strClass), - _parameterMgrPlatformConnectorLogger(), - _commandParser(*this), - _remoteProcessorServer(iPortNumber, _commandParser.getCommandHandler()), - _exitSemaphore(exitSemaphore) +TestPlatform::TestPlatform(const string& configurationFile, int portNumber, sem_t& exitSemaphore) : + mParameterMgrPlatformConnector(configurationFile), + mParameterMgrPlatformConnectorLogger(), + mCommandParser(*this), + mRemoteProcessorServer(portNumber, mCommandParser.getCommandHandler()), + mExitSemaphore(exitSemaphore) { - _parameterMgrPlatformConnector.setLogger(&_parameterMgrPlatformConnectorLogger); + mParameterMgrPlatformConnector.setLogger(&mParameterMgrPlatformConnectorLogger); } -bool CTestPlatform::load(std::string& strError) +bool TestPlatform::load(std::string& error) { // Start remote processor server - if (!_remoteProcessorServer.start(strError)) { + if (!mRemoteProcessorServer.start(error)) { - strError = "TestPlatform: Unable to start remote processor server: " + strError; + error = "TestPlatform: Unable to start remote processor server: " + error; return false; } return true; } -bool CTestPlatform::setCriterionState(std::string criterionName, +bool TestPlatform::setCriterionState(std::string criterionName, const IRemoteCommand& remoteCommand, - string& strResult) + string& result) { core::criterion::Criterion* pCriterion = - _parameterMgrPlatformConnector.getCriterion(criterionName); + mParameterMgrPlatformConnector.getCriterion(criterionName); if (!pCriterion) { - strResult = "Unable to retrieve selection criterion: " + criterionName; + result = "Unable to retrieve selection criterion: " + criterionName; return false; } @@ -83,7 +83,7 @@ bool CTestPlatform::setCriterionState(std::string criterionName, } // Set criterion new state - if (!pCriterion->setState(state, strResult)) { + if (!pCriterion->setState(state, result)) { return false; } return true; diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index 3176e9ad8..d5908e199 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -46,10 +46,10 @@ namespace log { /** Logger exposed to the parameter-framework */ -class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnector::ILogger +class ParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnector::ILogger { public: - CParameterMgrPlatformConnectorLogger() {} + ParameterMgrPlatformConnectorLogger() {} virtual void info(const std::string& log) { @@ -64,17 +64,27 @@ class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnect } /** log namespace */ -class CTestPlatform +class TestPlatform { /** 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); - // Init - bool load(std::string& strError); + /** + * @param[in] configurationFile the Parameter-Framework configuration file + * @param[in] portNumber the tcp port used by the command server + * @param[in] exitSemaphore the semaphore to notify closing event to the parent thread + */ + TestPlatform(const std::string &configurationFile, int portNumber, sem_t& exitSemaphore); + + /** Start the test platform + * + * @param[out] error the error description if needed + * @return true if success false otherwise + */ + bool load(std::string& error); private: @@ -141,8 +151,8 @@ class CTestPlatform std::string& result) { core::criterion::Criterion* criterion = (isInclusive ? - _parameterMgrPlatformConnector.createInclusiveCriterion(name, values, result) : - _parameterMgrPlatformConnector.createExclusiveCriterion(name, values, result)); + mParameterMgrPlatformConnector.createInclusiveCriterion(name, values, result) : + mParameterMgrPlatformConnector.createExclusiveCriterion(name, values, result)); if (criterion == nullptr) { return false; @@ -162,22 +172,22 @@ class CTestPlatform */ bool setCriterionState(std::string criterionName, const IRemoteCommand& remoteCommand, - std::string& strResult); + std::string& result); /** Parameter-Framework Connector */ - CParameterMgrPlatformConnector _parameterMgrPlatformConnector; + CParameterMgrPlatformConnector mParameterMgrPlatformConnector; /** Parameter-Framework Logger */ - log::CParameterMgrPlatformConnectorLogger _parameterMgrPlatformConnectorLogger; + log::ParameterMgrPlatformConnectorLogger mParameterMgrPlatformConnectorLogger; /** Command Parser delegate */ - command::Parser _commandParser; + command::Parser mCommandParser; /** Remote Processor Server */ - CRemoteProcessorServer _remoteProcessorServer; + CRemoteProcessorServer mRemoteProcessorServer; - // Semaphore used by calling thread to avoid exiting - sem_t& _exitSemaphore; + /** Semaphore used by calling thread to avoid exiting */ + sem_t& mExitSemaphore; }; } /** platform namespace */ diff --git a/test/test-platform/command/include/command/Parser.h b/test/test-platform/command/include/command/Parser.h index 79564f6ed..c0286b144 100644 --- a/test/test-platform/command/include/command/Parser.h +++ b/test/test-platform/command/include/command/Parser.h @@ -38,7 +38,7 @@ namespace test namespace platform { -class CTestPlatform; +class TestPlatform; namespace command { @@ -56,7 +56,7 @@ class Parser * * @param test-platform reference */ - Parser(CTestPlatform& testPlatform); + Parser(TestPlatform& testPlatform); /** Internal command handler getter * @@ -161,7 +161,7 @@ class Parser static CommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; /** Test PLatform used to delegate parsed commands */ - CTestPlatform& mTestPlatform; + TestPlatform& mTestPlatform; /** Command Handler */ CommandHandler mCommandHandler; diff --git a/test/test-platform/command/src/Parser.cpp b/test/test-platform/command/src/Parser.cpp index 449925266..2199ab6a5 100644 --- a/test/test-platform/command/src/Parser.cpp +++ b/test/test-platform/command/src/Parser.cpp @@ -91,7 +91,7 @@ Parser::CommandHandler::RemoteCommandParserItems Parser::gRemoteCommandParserIte "Get policy for schema validation based on .xsd files." } } }; -Parser::Parser(CTestPlatform& testPlatform) : +Parser::Parser(TestPlatform& testPlatform) : mTestPlatform(testPlatform), mCommandHandler(CommandHandler(*this, gRemoteCommandParserItems)) { } @@ -104,7 +104,7 @@ Parser::CommandHandler* Parser::getCommandHandler() Parser::CommandReturn Parser::exit(const IRemoteCommand&, std::string&) { // Release the main blocking semaphore to quit application - sem_post(&mTestPlatform._exitSemaphore); + sem_post(&mTestPlatform.mExitSemaphore); return Parser::CommandHandler::EDone; } @@ -131,7 +131,7 @@ Parser::createCriterionFromStateList(const IRemoteCommand& remoteCommand, std::s Parser::CommandReturn Parser::startParameterMgr(const IRemoteCommand&, std::string& result) { - return mTestPlatform._parameterMgrPlatformConnector.start(result) ? + return mTestPlatform.mParameterMgrPlatformConnector.start(result) ? Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; } @@ -142,14 +142,14 @@ Parser::CommandReturn Parser::setter(const IRemoteCommand& remoteCommand, std::s if(!convertTo(remoteCommand.getArgument(0), fail)) { return Parser::CommandHandler::EShowUsage; } - return (mTestPlatform._parameterMgrPlatformConnector.*setFunction)(fail, result) ? + return (mTestPlatform.mParameterMgrPlatformConnector.*setFunction)(fail, result) ? Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; } template Parser::CommandReturn Parser::getter(const IRemoteCommand&, std::string& result) { - result = (mTestPlatform._parameterMgrPlatformConnector.*getFunction)() ? "true" : "false"; + result = (mTestPlatform.mParameterMgrPlatformConnector.*getFunction)() ? "true" : "false"; return Parser::CommandHandler::ESucceeded; } @@ -164,7 +164,7 @@ Parser::CommandReturn Parser::setCriterionState(const IRemoteCommand& remoteComm Parser::CommandReturn Parser::applyConfigurations(const IRemoteCommand&, std::string&) { - mTestPlatform._parameterMgrPlatformConnector.applyConfigurations(); + mTestPlatform.mParameterMgrPlatformConnector.applyConfigurations(); return Parser::CommandHandler::EDone; } diff --git a/test/test-platform/main.cpp b/test/test-platform/main.cpp index ca620439b..a0a9989e2 100644 --- a/test/test-platform/main.cpp +++ b/test/test-platform/main.cpp @@ -44,7 +44,7 @@ using namespace std; const int iDefaultPortNumber = 5001; // Starts test-platform in blocking mode -static bool startBlockingTestPlatform(const char *filePath, int portNumber, string &strError) +static bool startBlockingTestPlatform(const char *filePath, int portNumber, string &error) { // Init semaphore @@ -53,10 +53,10 @@ static bool startBlockingTestPlatform(const char *filePath, int portNumber, stri sem_init(&sem, false, 0); // Create param mgr - test::platform::CTestPlatform testPlatform(filePath, portNumber, sem); + test::platform::TestPlatform testPlatform(filePath, portNumber, sem); // Start platformmgr - if (!testPlatform.load(strError)) { + if (!testPlatform.load(error)) { sem_destroy(&sem); @@ -82,14 +82,14 @@ static void notifyParent(int parentFd, bool success) } // Starts test-platform in daemon mode -static bool startDaemonTestPlatform(const char *filePath, int portNumber, string &strError) +static bool startDaemonTestPlatform(const char *filePath, int portNumber, string &error) { // Pipe used for communication between the child and the parent processes int pipefd[2]; if (pipe(pipefd) == -1) { - strError = "pipe failed"; + error = "pipe failed"; return false; } @@ -100,7 +100,7 @@ static bool startDaemonTestPlatform(const char *filePath, int portNumber, string if (pid < 0) { - strError = "fork failed!"; + error = "fork failed!"; return false; } else if (pid == 0) { @@ -116,14 +116,14 @@ static bool startDaemonTestPlatform(const char *filePath, int portNumber, string sem_init(&sem, false, 0); // Create param mgr - test::platform::CTestPlatform testPlatform(filePath, portNumber, sem); + test::platform::TestPlatform testPlatform(filePath, portNumber, sem); // Message to send to parent process - bool loadSuccess = testPlatform.load(strError); + bool loadSuccess = testPlatform.load(error); if (!loadSuccess) { - cerr << strError << endl; + cerr << error << endl; // Notify parent of failure; notifyParent(pipefd[1], false); @@ -152,7 +152,7 @@ static bool startDaemonTestPlatform(const char *filePath, int portNumber, string bool msgFromChild = false; if (not utility::fullRead(pipefd[0], &msgFromChild, sizeof(msgFromChild))) { - strError = "Read pipe failed"; + error = "Read pipe failed"; return false; } @@ -176,7 +176,8 @@ static void showInvalidUsage() static void showHelp() { showUsage(); - cerr << " must be a valid .xml file, oftenly ParameterFrameworkConfiguration.xml" << endl; + cerr << " must be a valid .xml file, oftenly ParameterFrameworkConfiguration.xml" + << endl; cerr << "Arguments:" << endl << " -d starts as a deamon" << endl << " -h display this help and exit" << endl; @@ -224,19 +225,19 @@ int main(int argc, char *argv[]) // Choose either blocking or daemon test-platform bool startError; - string strError; + string error; if (isDaemon) { - startError = startDaemonTestPlatform(filePath, portNumber, strError); + startError = startDaemonTestPlatform(filePath, portNumber, error); } else { - startError = startBlockingTestPlatform(filePath, portNumber, strError); + startError = startBlockingTestPlatform(filePath, portNumber, error); } if (!startError) { - cerr << "Test-platform error:" << strError.c_str() << endl; + cerr << "Test-platform error:" << error.c_str() << endl; return -1; } return 0;