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..e53abfee6 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -81,8 +81,6 @@ #include "Utility.h" #include #include -#include -#include /** Private macro helper to declare a new context * @@ -137,193 +135,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 +147,7 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge _pvLibRemoteProcessorHandle(NULL), _uiStructureChecksum(0), _pRemoteProcessorServer(NULL), + _commandParser(nullptr), _uiMaxCommandUsageLength(0), _logger(logger), _bForceNoRemoteInterface(false), @@ -352,22 +164,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 +181,6 @@ CParameterMgr::~CParameterMgr() { // Children delete _pRemoteProcessorServer; - delete _pCommandHandler; delete _pMainParameterBlackboard; delete _pElementLibrarySet; @@ -853,841 +648,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) @@ -2576,9 +1536,11 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) return false; } + _commandParser = ParserWrapper{ new command::Parser(*this) }; // 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..eeb146b21 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,14 @@ 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[]; + /** Command parser manager type */ + using ParserWrapper = std::unique_ptr; - // Parser description array size - static const uint32_t guiNbRemoteCommandParserItems; + /** Remote commands Parser */ + 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 new file mode 100644 index 000000000..e81a1c75d --- /dev/null +++ b/parameter/command/include/command/Parser.h @@ -0,0 +1,228 @@ +/* + * 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 */ + using CommandHandler = RemoteCommandHandlerTemplate; + + /** 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 getter */ + CommandHandler::RemoteCommandParserItems &getRemoteParserItems() const; + + /** 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..30241a9cb --- /dev/null +++ b/parameter/command/src/Parser.cpp @@ -0,0 +1,1079 @@ +/* + * 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 +{ + +Parser::Parser(CParameterMgr& parameterMgr) : + mParameterMgr(parameterMgr), mCommandHandler(CommandHandler(*this, getRemoteParserItems())) +{ +} + +Parser::CommandHandler::RemoteCommandParserItems &Parser::getRemoteParserItems() const +{ + static 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() +{ + 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 */ diff --git a/remote-processor/RemoteCommandHandlerTemplate.h b/remote-processor/RemoteCommandHandlerTemplate.h index 0b7428dbf..87129c54e 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,11 +29,17 @@ */ #pragma once -#include #include "RemoteCommandHandler.h" +#include +#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 */ @@ -51,59 +57,78 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler * * @return the command execution status, @see CommandStatus */ - typedef CommandStatus (CCommandParser::*RemoteCommandParser)(const IRemoteCommand& remoteCommand, std::string& strResult); + using RemoteCommandParser = std::function; -private: - // Parser descriptions - class CRemoteCommandParserItem + /** Parser item definition */ + 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 + + /** + * @param parser command handler callback + * @param minArgumentCount command required arguments number + * @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& argumentDescription, + const std::string& description) : + mParser(parser), + mMinArgumentCount(minArgumentCount), + mArgumentDescription(argumentDescription), + mDescription(description) { - return _strCommandName; } + /** Command description string getter + * + * @return the command description string + */ const std::string& getDescription() const { - return _strDescription; + return mDescription; } - // Usage - std::string usage() const + /** Description of each argument of the command + * + * @return the command argument description string + */ + const std::string getArgumentDescription() const { - return _strCommandName + " " + _strHelp; + return mArgumentDescription; } - 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] result the command result + * @result true on success, false otherwise + */ + bool parse(CommandParser& commandParser, + const IRemoteCommand& remoteCommand, + std::string& result) const { // Check enough arguments supplied - if (remoteCommand.getArgumentCount() < _uiMinArgumentCount) { - - strResult = std::string("Not enough arguments supplied\nUsage:\n") + usage(); + if (remoteCommand.getArgumentCount() < mMinArgumentCount) { + result = std::string("Not enough arguments supplied\nUsage:\n") + + getArgumentDescription(); return false; } - switch ((pCommandParser->*_pfnParser)(remoteCommand, strResult)) { + switch (mParser(commandParser, 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 = getArgumentDescription(); + // Fall through intentionally case EFailed: return false; } @@ -112,144 +137,95 @@ class TRemoteCommandHandlerTemplate : public IRemoteCommandHandler } private: - std::string _strCommandName; - RemoteCommandParser _pfnParser; - uint32_t _uiMinArgumentCount; - std::string _strHelp; - std::string _strDescription; - }; -public: - TRemoteCommandHandlerTemplate(CCommandParser* pCommandParser) : _pCommandParser(pCommandParser), _uiMaxCommandUsageLength(0) - { - // Help Command - addCommandParser("help", NULL, 0, "", "Show commands description and usage"); - } - ~TRemoteCommandHandlerTemplate() - { - uint32_t uiIndex; + /** Command Handler callback */ + RemoteCommandParser mParser; - for (uiIndex = 0; uiIndex < _remoteCommandParserVector.size(); uiIndex++) { + /** Needed arguments number */ + uint32_t mMinArgumentCount; - delete _remoteCommandParserVector[uiIndex]; - } - } - - // Parsers - bool addCommandParser(const std::string& strCommandName, - RemoteCommandParser pfnParser, - uint32_t uiMinArgumentCount, - const std::string& strHelp, - const std::string& strDescription) - { - if (findCommandParserItem(strCommandName)) { + /** Command argument description string */ + std::string mArgumentDescription; - // Already exists - return false; - } + /** Command description string */ + std::string mDescription; + }; - // Add command - _remoteCommandParserVector.push_back(new CRemoteCommandParserItem(strCommandName, pfnParser, uiMinArgumentCount, strHelp, strDescription)); + /** Remote command parser container type */ + using RemoteCommandParserItems = std::map; - return true; + /** + * @param commandParser command parser used for command handling + * @param remoteCommandParserItems supported command parser items + */ + RemoteCommandHandlerTemplate(CommandParser& commandParser, + 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: - // Command processing - bool remoteCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult) - { - // Dispatch - const CRemoteCommandParserItem* pRemoteCommandParserItem = findCommandParserItem(remoteCommand.getCommand()); - if (!pRemoteCommandParserItem) { + /** 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, result); + } + catch (const std::out_of_range&) { // Not found - strResult = "Command not found!\nUse \"help\" to show available commands"; + result = "Command not found!\nUse \"help\" to show available commands"; return false; } - - if (remoteCommand.getCommand() == "help") { - - helpCommandProcess(strResult); - - return true; - } - - return pRemoteCommandParserItem->parse(_pCommandParser, remoteCommand, strResult); } - // Max command usage length, use for formatting - void initMaxCommandUsageLength() + /** Format help display + * + * @param result the formatted help string + * + * @return ESucceeded command status + */ + CommandStatus help(std::string& result) { - if (!_uiMaxCommandUsageLength) { - // Show usages - uint32_t uiIndex; - - for (uiIndex = 0; uiIndex < _remoteCommandParserVector.size(); uiIndex++) { - - const CRemoteCommandParserItem* pRemoteCommandParserItem = _remoteCommandParserVector[uiIndex]; - - uint32_t uiRemoteCommandUsageLength = (uint32_t)pRemoteCommandParserItem->usage().length(); - - if (uiRemoteCommandUsageLength > _uiMaxCommandUsageLength) { - - _uiMaxCommandUsageLength = uiRemoteCommandUsageLength; - } - } + struct Help { std::string usage; std::string description; }; + std::vector helps; + size_t maxUsage = 0; + + for (auto& item : _remoteCommandParserItems) { + std::string usage = item.first + ' ' + item.second.getArgumentDescription(); + helps.push_back({ usage, item.second.getDescription() }); + maxUsage = std::max(maxUsage, usage.length()); } - } - - /////////////////// Remote command parsers - /// Help - void helpCommandProcess(std::string& strResult) - { - 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 += " "; - } - - strResult += std::string("=> ") + std::string(pRemoteCommandParserItem->getDescription()) + "\n"; + for (auto& help : helps) { + help.usage.resize(maxUsage, ' '); + result += help.usage + " => " + help.description + '\n'; } + return CommandStatus::ESucceeded; } - const CRemoteCommandParserItem* findCommandParserItem(const std::string& strCommandName) const - { - uint32_t uiIndex; - - for (uiIndex = 0; uiIndex < _remoteCommandParserVector.size(); uiIndex++) { - - const CRemoteCommandParserItem* pRemoteCommandParserItem = _remoteCommandParserVector[uiIndex]; + /** Command parser used during command during command handling */ + CommandParser& _commandParser; - if (pRemoteCommandParserItem->getCommandName() == strCommandName) { - - return pRemoteCommandParserItem; - } - } - return NULL; - } - -private: - CCommandParser* _pCommandParser; - std::vector _remoteCommandParserVector; - uint32_t _uiMaxCommandUsageLength; + /** Remote command parser map */ + RemoteCommandParserItems& _remoteCommandParserItems; }; - 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 317ddf178..ab9d1fa50 100644 --- a/test/test-platform/TestPlatform.cpp +++ b/test/test-platform/TestPlatform.cpp @@ -28,220 +28,50 @@ * 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" using std::string; -using core::criterion::Criterion; -class CParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnector::ILogger +namespace test { -public: - CParameterMgrPlatformConnectorLogger() {} - - virtual void info(const string& log) - { - std::cout << log << std::endl; - } - - virtual void warning(const string& log) - { - std::cerr << log << std::endl; - } -}; - -CTestPlatform::CTestPlatform(const string& strClass, int iPortNumber, sem_t& exitSemaphore) : - _pParameterMgrPlatformConnector(new CParameterMgrPlatformConnector(strClass)), - _pParameterMgrPlatformConnectorLogger(new CParameterMgrPlatformConnectorLogger), - _exitSemaphore(exitSemaphore) +namespace platform { - _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); - - _pParameterMgrPlatformConnector->setLogger(_pParameterMgrPlatformConnectorLogger); -} - -CTestPlatform::~CTestPlatform() +TestPlatform::TestPlatform(const string& configurationFile, int portNumber, sem_t& exitSemaphore) : + mParameterMgrPlatformConnector(configurationFile), + mParameterMgrPlatformConnectorLogger(), + mCommandParser(*this), + mRemoteProcessorServer(portNumber, mCommandParser.getCommandHandler()), + mExitSemaphore(exitSemaphore) { - delete _pRemoteProcessorServer; - delete _pCommandHandler; - delete _pParameterMgrPlatformConnectorLogger; - 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; + mParameterMgrPlatformConnector.setLogger(&mParameterMgrPlatformConnectorLogger); } -bool CTestPlatform::load(std::string& strError) +bool TestPlatform::load(std::string& error) { // Start remote processor server - if (!_pRemoteProcessorServer->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; } -//////////////// 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) +bool TestPlatform::setCriterionState(std::string criterionName, + const IRemoteCommand& remoteCommand, + string& result) { - (void)remoteCommand; - - strResult = (_pParameterMgrPlatformConnector->*getFunction)() ? "true" : "false"; - - return CTestPlatform::CCommandHandler::ESucceeded; -} - -CTestPlatform::CommandReturn CTestPlatform::setCriterionState( - const IRemoteCommand& remoteCommand, string& strResult) -{ - // Get criterion name - std::string strCriterionName = remoteCommand.getArgument(0); - - Criterion* pCriterion = - _pParameterMgrPlatformConnector->getCriterion(strCriterionName); + core::criterion::Criterion* pCriterion = + mParameterMgrPlatformConnector.getCriterion(criterionName); if (!pCriterion) { - strResult = "Unable to retrieve selection criterion: " + strCriterionName; - - return CTestPlatform::CCommandHandler::EFailed; + result = "Unable to retrieve selection criterion: " + criterionName; + return false; } // Get substate number, the first argument (index 0) is the criterion name @@ -253,77 +83,11 @@ 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) { + if (!pCriterion->setState(state, result)) { return false; } - return true; } + +} /** platform namespace */ +} /** test namespace */ diff --git a/test/test-platform/TestPlatform.h b/test/test-platform/TestPlatform.h index 9a5b80f38..d5908e199 100644 --- a/test/test-platform/TestPlatform.h +++ b/test/test-platform/TestPlatform.h @@ -29,121 +29,64 @@ */ #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 +{ + +/** Logger exposed to the parameter-framework */ +class ParameterMgrPlatformConnectorLogger : public CParameterMgrPlatformConnector::ILogger { - typedef TRemoteCommandHandlerTemplate CCommandHandler; - typedef CCommandHandler::CommandStatus CommandReturn; public: - CTestPlatform(const std::string &strclass, int iPortNumber, sem_t& exitSemaphore); - virtual ~CTestPlatform(); + ParameterMgrPlatformConnectorLogger() {} - // Init - bool load(std::string& strError); + virtual void info(const std::string& log) + { + std::cout << log << std::endl; + } -private: - //////////////// Remote command parsers + virtual void warning(const std::string& log) + { + std::cerr << log << std::endl; + } +}; - /** 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); +} /** log namespace */ - /** 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); - - /** 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); +class TestPlatform +{ - /** 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); + /** Remote command parser has access to private command handle function */ + friend class command::Parser; - /** 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); +public: - /** Callback to exit the test-platform. - * - * @param[in] remoteCommand is ignored - * - * @return EDone (never fails) + /** + * @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 */ - CommandReturn exit(const IRemoteCommand& remoteCommand, std::string& strResult); + TestPlatform(const std::string &configurationFile, int portNumber, sem_t& exitSemaphore); - /** 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 + /** Start the test platform * - * @return EDone (never fails) + * @param[out] error the error description if needed + * @return true if success false otherwise */ - template - CommandReturn getter(const IRemoteCommand& remoteCommand, std::string& strResult); + bool load(std::string& error); - // Commands +private: /** @see callback with the same arguments for details and other parameters * @@ -152,11 +95,25 @@ 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) + { + 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 * @@ -168,7 +125,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 @@ -181,21 +148,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 ? + mParameterMgrPlatformConnector.createInclusiveCriterion(name, values, result) : + mParameterMgrPlatformConnector.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& result); - // Connector - CParameterMgrPlatformConnector* _pParameterMgrPlatformConnector; + /** Parameter-Framework Connector */ + CParameterMgrPlatformConnector mParameterMgrPlatformConnector; - // Logger - CParameterMgrPlatformConnectorLogger* _pParameterMgrPlatformConnectorLogger; + /** Parameter-Framework Logger */ + log::ParameterMgrPlatformConnectorLogger mParameterMgrPlatformConnectorLogger; - // Command Handler - CCommandHandler* _pCommandHandler; + /** Command Parser delegate */ + command::Parser mCommandParser; - // Remote Processor Server - CRemoteProcessorServer* _pRemoteProcessorServer; + /** Remote Processor Server */ + 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 */ +} /** 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..c0286b144 --- /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 TestPlatform; + +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(TestPlatform& 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 CommandHandler::RemoteCommandParserItems gRemoteCommandParserItems; + + /** Test PLatform used to delegate parsed commands */ + TestPlatform& 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..2199ab6a5 --- /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 +{ + +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(TestPlatform& 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.mExitSemaphore); + + 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.mParameterMgrPlatformConnector.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.mParameterMgrPlatformConnector.*setFunction)(fail, result) ? + Parser::CommandHandler::EDone : Parser::CommandHandler::EFailed; +} + +template +Parser::CommandReturn Parser::getter(const IRemoteCommand&, std::string& result) +{ + result = (mTestPlatform.mParameterMgrPlatformConnector.*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.mParameterMgrPlatformConnector.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..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 - 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 - 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;