diff options
author | David Wagner <david.wagner@intel.com> | 2014-12-04 18:38:52 +0100 |
---|---|---|
committer | David Wagner <david.wagner@intel.com> | 2015-01-22 11:53:52 +0100 |
commit | ed744eb61b3fced13193fb59f728f26847748179 (patch) | |
tree | 2d7e412bb2df30a499eab98b1361574aacf92394 /parameter | |
parent | d8a53107d5f965c8ca406ee95f5999efd6694730 (diff) | |
download | external_parameter-framework-ed744eb61b3fced13193fb59f728f26847748179.zip external_parameter-framework-ed744eb61b3fced13193fb59f728f26847748179.tar.gz external_parameter-framework-ed744eb61b3fced13193fb59f728f26847748179.tar.bz2 |
New remote command for exporting a single domain
The command is used as follows:
getDomainWithSettingsXML <domain>
and outputs the requested domain to the standard output.
In that end, the const version of CConfigurableDomains::findConfigurableDomain
is made public. This somewhat breaks encapsulation but since the returned
domain is const, this has limited impact.
Change-Id: I9b854040a5d59913b9b405c8e38d29a3018a6079
Signed-off-by: David Wagner <david.wagner@intel.com>
Diffstat (limited to 'parameter')
-rw-r--r-- | parameter/ConfigurableDomains.h | 4 | ||||
-rw-r--r-- | parameter/ParameterMgr.cpp | 76 | ||||
-rw-r--r-- | parameter/ParameterMgr.h | 53 |
3 files changed, 110 insertions, 23 deletions
diff --git a/parameter/ConfigurableDomains.h b/parameter/ConfigurableDomains.h index 01c94ac..8016cb9 100644 --- a/parameter/ConfigurableDomains.h +++ b/parameter/ConfigurableDomains.h @@ -87,6 +87,9 @@ public: bool& bIsLastApplied, std::string& strError) const; + const CConfigurableDomain* findConfigurableDomain(const std::string& strDomain, + std::string& strError) const; + // Binary settings load/store bool serializeSettings(const std::string& strBinarySettingsFilePath, bool bOut, uint8_t uiStructureChecksum, std::string& strError); @@ -108,6 +111,5 @@ private: void gatherAllOwnedConfigurableElements(std::set<const CConfigurableElement*>& configurableElementSet) const; // Domain retrieval CConfigurableDomain* findConfigurableDomain(const std::string& strDomain, std::string& strError); - const CConfigurableDomain* findConfigurableDomain(const std::string& strDomain, std::string& strError) const; }; diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 8a6adf0..9b01c85 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -266,6 +266,9 @@ const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandPa { "getDomainsWithSettingsXML", &CParameterMgr::getConfigurableDomainsWithSettingsXMLCommmandProcess, 0, "", "Print domains including settings as XML" }, + { "getDomainWithSettingsXML", + &CParameterMgr::getConfigurableDomainWithSettingsXMLCommmandProcess, 1, + "<domain>", "Print the given domain including settings as XML" }, { "setDomainsWithSettingsXML", &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1, "<xml configurable domains>", "Import domains including settings from XML string" }, @@ -1541,6 +1544,16 @@ CParameterMgr::CCommandHandler::CommandStatus } CParameterMgr::CCommandHandler::CommandStatus + CParameterMgr::getConfigurableDomainWithSettingsXMLCommmandProcess( + const IRemoteCommand& remoteCommand, string& strResult) +{ + string strDomainName = remoteCommand.getArgument(0); + + return exportSingleDomainXml(strResult, strDomainName, true, false, strResult) ? + CCommandHandler::ESucceeded : CCommandHandler::EFailed; +} + +CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess( const IRemoteCommand& remoteCommand, string& strResult) { @@ -2072,8 +2085,9 @@ bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSetti return bProcessSuccess; } -bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile, - string& strError) const +bool CParameterMgr::serializeElement(string& strXmlDest, + CXmlSerializingContext& xmlSerializingContext, bool bToFile, + const CElement& element, string& strError) const { // check path is absolute if (bToFile && strXmlDest[0] != '/') { @@ -2083,24 +2097,12 @@ bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, boo return false; } - // Root element - const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains(); - // Get Schema file associated to root element string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + - pConfigurableDomains->getKind() + ".xsd"; - - // Context - CXmlDomainExportContext xmlDomainExportContext(strError, bWithSettings); - - // Value space - xmlDomainExportContext.setValueSpaceRaw(_bValueSpaceIsRaw); - - // Output raw format - xmlDomainExportContext.setOutputRawFormat(_bOutputRawFormatIsHex); + element.getKind() + ".xsd"; // Use a doc source by loading data from instantiated Configurable Domains - CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), + CXmlMemoryDocSource memorySource(&element, element.getKind(), strXmlSchemaFilePath, "parameter-framework", getVersion(), _bValidateSchemasOnStart); @@ -2115,15 +2117,55 @@ bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, boo } else { // Use a doc sink to write the doc data in a string + // TODO: use a stream rather than a string pSink = new CXmlStringDocSink(strXmlDest); } - bool bProcessSuccess = pSink->process(memorySource, xmlDomainExportContext); + bool bProcessSuccess = pSink->process(memorySource, xmlSerializingContext); delete pSink; return bProcessSuccess; } +bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, bool bToFile, + string& strError) const +{ + const CConfigurableDomains* pConfigurableDomains = getConstConfigurableDomains(); + + CXmlDomainExportContext xmlDomainExportContext(strError, bWithSettings); + + xmlDomainExportContext.setValueSpaceRaw(_bValueSpaceIsRaw); + + xmlDomainExportContext.setOutputRawFormat(_bOutputRawFormatIsHex); + + + return serializeElement(strXmlDest, xmlDomainExportContext, bToFile, + *pConfigurableDomains, strError); +} + +bool CParameterMgr::exportSingleDomainXml(string& strXmlDest, const string& strDomainName, + bool bWithSettings, bool bToFile, string& strError) const +{ + const CConfigurableDomains* pAllDomains = getConstConfigurableDomains(); + + // Element to be serialized + const CConfigurableDomain* pRequestedDomain = + pAllDomains->findConfigurableDomain(strDomainName, strError); + + if (!pRequestedDomain) { + return false; + } + + CXmlDomainExportContext xmlDomainExportContext(strError, bWithSettings); + + xmlDomainExportContext.setValueSpaceRaw(_bValueSpaceIsRaw); + + xmlDomainExportContext.setOutputRawFormat(_bOutputRawFormatIsHex); + + return serializeElement(strXmlDest, xmlDomainExportContext, bToFile, + *pRequestedDomain, strError); +} + // Binary Import/Export bool CParameterMgr::importDomainsBinary(const string& strFileName, string& strError) { diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index 9e4a3fb..cd1c468 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -250,23 +250,54 @@ public: bool importDomainsXml(const std::string& strXmlSource, bool bWithSettings, bool bFromFile, std::string& strError); + + /** + * Export an element object to an Xml destination. + * + * + * @param[in,out] strXmlDest a string containing an xml description or a path to an xml file. + * @param[in] xmlSerializingContext the serializing context + * @param[in] bToFile a boolean that determines if the destination is an xml description in + * strXmlDest or contained in a file. In that case strXmlDest is just the file path. + * @param[in] element object to be serialized. + * @param[out] strError is used as the error output. + * + * @return false if any error occurs, true otherwise. + */ + bool serializeElement(std::string& strXmlDest, CXmlSerializingContext& xmlSerializingContext, + bool bToFile, const CElement& element, std::string& strError) const; + /** * Method that exports Configurable Domains to an Xml destination. - * If bToFile is false, the xml description from the xml document will be written - * in strXmlDest. Otherwise it will be written in a file located at the path in strXmlDest * - * @param[in:out] strXmlDest a std::string containing an xml description or a path to an xml file + * @param[in,out] strXmlDest a string containing an xml description or a path to an xml file * @param[in] bWithSettings a boolean that determines if the settings should be used in the * xml description * @param[in] bToFile a boolean that determines if the destination is an xml description in * strXmlDest or contained in a file. In that case strXmlDest is just the file path. * @param[out] strError is used as the error output * - * @return false if any error occures + * @return false if any error occurs, true otherwise. */ bool exportDomainsXml(std::string& strXmlDest, bool bWithSettings, bool bToFile, std::string& strError) const; + /** + * Method that exports a given Configurable Domain to an Xml destination. + * + * @param[in,out] strXmlDest a string containing an xml description or a path to an xml file + * @param[in] strDomainName the name of the domain to be exported + * @param[in] bWithSettings a boolean that determines if the settings should be used in the + * xml description + * @param[in] bToFile a boolean that determines if the destination is an xml description in + * strXmlDest or contained in a file. In that case strXmlDest is just the file path. + * @param[out] strError is used as the error output + * + * @return false if any error occurs, true otherwise. + */ + bool exportSingleDomainXml(std::string& strXmlDest, const std::string& strDomainName, + bool bWithSettings, bool bToFile, std::string& strError) const; + // Binary Import/Export bool importDomainsBinary(const std::string& strFileName, std::string& strError); bool exportDomainsBinary(const std::string& strFileName, std::string& strError); @@ -371,7 +402,7 @@ private: CCommandHandler::CommandStatus importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); /** - * Command handler method for getConfigurableDomainWithSettings command. + * Command handler method for getConfigurableDomainsWithSettings command. * * @param[in] remoteCommand contains the arguments of the received command. * @param[out] strResult a std::string containing the result of the command @@ -383,6 +414,18 @@ private: const IRemoteCommand& remoteCommand, std::string& strResult); /** + * Command handler method for getConfigurableDomainWithSettings command. + * + * @param[in] remoteCommand contains the arguments of the received command. + * @param[out] strResult a string containing the result of the command + * + * @return CCommandHandler::ESucceeded if command succeeded or CCommandHandler::EFailed + * in the other case + */ + CCommandHandler::CommandStatus getConfigurableDomainWithSettingsXMLCommmandProcess( + const IRemoteCommand& remoteCommand, std::string& strResult); + + /** * Command handler method for setConfigurableDomainWithSettings command. * * @param[in] remoteCommand contains the arguments of the received command. |