From 8cb5d8815da673747b729d5e0a05a5cdc11a9081 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Tue, 9 Dec 2014 15:26:06 +0100 Subject: Allow more flexibility in overriding CElement::toXml The toXml method has a default implementation that recursively calls toXml on the children and set their "Name" attribute. With this approach, the toplevel element's name isn't set unless its overrided implementation explicitly does so. A first approach for fixing that is to set the XmlElement's name and recursively call toXml on children (without setting their name because it will be done by their toXml method). However, the "CXmlElement" being created may or may not be the object on which the toXml method is called, in which case the name will be set on the wrong XmlElement. Instead, in CElement::toXml, we set the XmlElement's name and call a new virtual method, childrenToXml which only recursively call toXml on children. This gives full flexibility to elements to choose how they want to serialize themselves and how they want to serialize their children. CConfigurableDomain::toXml is modified to take that change into account. Change-Id: Id12a1023e91cb000e55c242c13643b1db7d46871 Signed-off-by: David Wagner --- parameter/ConfigurableDomain.cpp | 8 +++++++- parameter/ConfigurableDomain.h | 2 ++ parameter/ConfigurableDomains.cpp | 2 +- parameter/Element.cpp | 14 ++++++++------ parameter/Element.h | 14 ++++++++++++++ 5 files changed, 32 insertions(+), 8 deletions(-) (limited to 'parameter') diff --git a/parameter/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index 61a8d5b..f81baec 100644 --- a/parameter/ConfigurableDomain.cpp +++ b/parameter/ConfigurableDomain.cpp @@ -111,9 +111,15 @@ bool CConfigurableDomain::getSequenceAwareness() const // From IXmlSource void CConfigurableDomain::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { + base::toXml(xmlElement, serializingContext); + // Sequence awareness xmlElement.setAttributeBoolean("SequenceAware", _bSequenceAware); +} +void CConfigurableDomain::childrenToXml(CXmlElement& xmlElement, + CXmlSerializingContext& serializingContext) const +{ // Configurations composeDomainConfigurations(xmlElement, serializingContext); @@ -133,7 +139,7 @@ void CConfigurableDomain::composeDomainConfigurations(CXmlElement& xmlElement, C xmlElement.createChild(xmlConfigurationsElement, "Configurations"); // Delegate to base - base::toXml(xmlConfigurationsElement, serializingContext); + base::childrenToXml(xmlConfigurationsElement, serializingContext); } void CConfigurableDomain::composeConfigurableElements(CXmlElement& xmlElement) const diff --git a/parameter/ConfigurableDomain.h b/parameter/ConfigurableDomain.h index e91a5cb..a7cbf73 100644 --- a/parameter/ConfigurableDomain.h +++ b/parameter/ConfigurableDomain.h @@ -103,6 +103,8 @@ public: // From IXmlSource virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; + virtual void childrenToXml(CXmlElement& xmlElement, + CXmlSerializingContext& serializingContext) const; // Class kind virtual std::string getKind() const; diff --git a/parameter/ConfigurableDomains.cpp b/parameter/ConfigurableDomains.cpp index f11a155..dd7ede3 100644 --- a/parameter/ConfigurableDomains.cpp +++ b/parameter/ConfigurableDomains.cpp @@ -104,7 +104,7 @@ void CConfigurableDomains::toXml(CXmlElement& xmlElement, CXmlSerializingContext // Set attribute xmlElement.setAttributeString("SystemClassName", getName()); - base::toXml(xmlElement, serializingContext); + base::childrenToXml(xmlElement, serializingContext); } // Configuration/Domains handling diff --git a/parameter/Element.cpp b/parameter/Element.cpp index 2c8393d..4ccf149 100755 --- a/parameter/Element.cpp +++ b/parameter/Element.cpp @@ -292,8 +292,8 @@ bool CElement::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& se return true; } -// From IXmlSource -void CElement::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const +void CElement::childrenToXml(CXmlElement& xmlElement, + CXmlSerializingContext& serializingContext) const { // Browse children and propagate uint32_t uiNbChildren = getNbChildren(); @@ -308,15 +308,17 @@ void CElement::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializin xmlElement.createChild(xmlChildElement, pChild->getKind()); - // Set attributes - pChild->setXmlNameAttribute(xmlChildElement); - - // Propagate pChild->toXml(xmlChildElement, serializingContext); } } +void CElement::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const +{ + setXmlNameAttribute(xmlElement); + childrenToXml(xmlElement, serializingContext); +} + void CElement::setXmlNameAttribute(CXmlElement& xmlElement) const { // By default, set Name attribute if any diff --git a/parameter/Element.h b/parameter/Element.h index 8469ab6..4636dbd 100644 --- a/parameter/Element.h +++ b/parameter/Element.h @@ -94,6 +94,20 @@ public: // From IXmlSource virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; + /** + * Serialize the children to XML + * + * This method is virtual, to be derived in case a special treatment is + * needed before doing so. + * + * @param[in,out] xmlElement the XML Element below which the children must + * be serialized (which may or may not be the CElement + * object upon which this method is called) + * @param[in,out] serializingContext information about the serialization + */ + virtual void childrenToXml(CXmlElement& xmlElement, + CXmlSerializingContext& serializingContext) const; + // Content structure dump void dumpContent(std::string& strContent, CErrorContext& errorContext, const uint32_t uiDepth = 0) const; -- cgit v1.1 From 12de2f264c693736a0157847578f6231309cf395 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Thu, 4 Dec 2014 11:40:00 +0100 Subject: Remove const/non-const code duplication in CConfigurableDomains Implement the non-const method of findConfigurableDomain by calling the const version, as described in Effective C++ Item 3. Change-Id: Ib7b58100dc817d02092299923edf2e6c7ce2f117 Signed-off-by: David Wagner --- parameter/ConfigurableDomains.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'parameter') diff --git a/parameter/ConfigurableDomains.cpp b/parameter/ConfigurableDomains.cpp index dd7ede3..8dff45a 100644 --- a/parameter/ConfigurableDomains.cpp +++ b/parameter/ConfigurableDomains.cpp @@ -566,17 +566,10 @@ bool CConfigurableDomains::serializeSettings(const string& strBinarySettingsFile // Domain retrieval CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError) { - // Find domain - CConfigurableDomain* pConfigurableDomain = static_cast(findChild(strDomain)); - - if (!pConfigurableDomain) { - - strError = "Configurable domain " + strDomain + " not found"; - - return NULL; - } - - return pConfigurableDomain; + // Call the const equivalent + return const_cast( + static_cast(this)->findConfigurableDomain(strDomain, strError) + ); } const CConfigurableDomain* CConfigurableDomains::findConfigurableDomain(const string& strDomain, string& strError) const -- cgit v1.1 From 29fa61fc5bc02f72f99e66ad50e4de8cb6b8490b Mon Sep 17 00:00:00 2001 From: David Wagner Date: Fri, 19 Dec 2014 11:15:02 +0100 Subject: Extract and specialize domain import- and export-specific contexts Import and Export of ConfigurableDomains have different context needs: e.g. the value representation is only used for export; auto-validation is only meaningful for import whereas the "with settings" context is common to both. We create two new classes, derived from XmlDomainSerializingContext and move most of its content to each class it belongs to. Change-Id: I56589cdb3a8ea417e11d2ed98ccd055d7cdead67 Signed-off-by: David Wagner --- parameter/Android.mk | 1 - parameter/CMakeLists.txt | 2 - parameter/ConfigurableDomain.cpp | 36 ++++++++----- parameter/ConfigurableDomain.h | 38 +++++++++++-- parameter/DomainConfiguration.cpp | 17 +++--- parameter/ParameterMgr.cpp | 26 ++++----- parameter/SelectionCriterionRule.cpp | 11 ++-- parameter/XmlDomainExportContext.h | 72 +++++++++++++++++++++++++ parameter/XmlDomainImportContext.h | 75 ++++++++++++++++++++++++++ parameter/XmlDomainSerializingContext.cpp | 89 ------------------------------- parameter/XmlDomainSerializingContext.h | 36 +++---------- 11 files changed, 242 insertions(+), 161 deletions(-) create mode 100644 parameter/XmlDomainExportContext.h create mode 100644 parameter/XmlDomainImportContext.h delete mode 100644 parameter/XmlDomainSerializingContext.cpp (limited to 'parameter') diff --git a/parameter/Android.mk b/parameter/Android.mk index 2027e97..aaa40ea 100644 --- a/parameter/Android.mk +++ b/parameter/Android.mk @@ -85,7 +85,6 @@ common_src_files := \ ConfigurationAccessContext.cpp \ XmlElementSerializingContext.cpp \ XmlParameterSerializingContext.cpp \ - XmlDomainSerializingContext.cpp \ BinarySerializableElement.cpp \ BitwiseAreaConfiguration.cpp \ BitParameterBlockType.cpp \ diff --git a/parameter/CMakeLists.txt b/parameter/CMakeLists.txt index f98848f..50fc15b 100644 --- a/parameter/CMakeLists.txt +++ b/parameter/CMakeLists.txt @@ -72,7 +72,6 @@ add_library(parameter SHARED ConfigurationAccessContext.cpp XmlElementSerializingContext.cpp XmlParameterSerializingContext.cpp - XmlDomainSerializingContext.cpp BinarySerializableElement.cpp BitwiseAreaConfiguration.cpp BitParameterBlockType.cpp @@ -147,7 +146,6 @@ add_library(parameter SHARED ConfigurationAccessContext.cpp XmlElementSerializingContext.cpp XmlParameterSerializingContext.cpp - XmlDomainSerializingContext.cpp BinarySerializableElement.cpp BitwiseAreaConfiguration.cpp BitParameterBlockType.cpp diff --git a/parameter/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index f81baec..c3fa1f9 100644 --- a/parameter/ConfigurableDomain.cpp +++ b/parameter/ConfigurableDomain.cpp @@ -32,6 +32,8 @@ #include "ConfigurableElement.h" #include "ConfigurationAccessContext.h" #include "XmlDomainSerializingContext.h" +#include "XmlDomainImportContext.h" +#include "XmlDomainExportContext.h" #include #define base CBinarySerializableElement @@ -169,9 +171,10 @@ void CConfigurableDomain::composeConfigurableElements(CXmlElement& xmlElement) c void CConfigurableDomain::composeSettings(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Context - const CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast(serializingContext); + const CXmlDomainExportContext& xmlDomainExportContext = + static_cast(serializingContext); - if (!xmlDomainSerializingContext.withSettings()) { + if (!xmlDomainExportContext.withSettings()) { return; } @@ -206,20 +209,23 @@ void CConfigurableDomain::composeSettings(CXmlElement& xmlElement, CXmlSerializi bool CConfigurableDomain::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Context - CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast(serializingContext); + CXmlDomainImportContext& xmlDomainImportContext = + static_cast(serializingContext); // Sequence awareness (optional) _bSequenceAware = xmlElement.hasAttribute("SequenceAware") && xmlElement.getAttributeBoolean("SequenceAware"); // Local parsing. Do not dig - if (!parseDomainConfigurations(xmlElement, serializingContext) || !parseConfigurableElements(xmlElement, serializingContext) || !parseSettings(xmlElement, serializingContext)) { + if (!parseDomainConfigurations(xmlElement, xmlDomainImportContext) || + !parseConfigurableElements(xmlElement, xmlDomainImportContext) || + !parseSettings(xmlElement, xmlDomainImportContext)) { return false; } // All provided configurations are parsed // Attempt validation on areas of non provided configurations for all configurable elements if required - if (xmlDomainSerializingContext.autoValidationRequired()) { + if (xmlDomainImportContext.autoValidationRequired()) { autoValidateAll(); } @@ -228,7 +234,8 @@ bool CConfigurableDomain::fromXml(const CXmlElement& xmlElement, CXmlSerializing } // XML parsing -bool CConfigurableDomain::parseDomainConfigurations(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) +bool CConfigurableDomain::parseDomainConfigurations(const CXmlElement& xmlElement, + CXmlDomainImportContext& serializingContext) { // We're supposedly clean assert(_configurableElementList.empty()); @@ -243,7 +250,8 @@ bool CConfigurableDomain::parseDomainConfigurations(const CXmlElement& xmlElemen } // Parse configurable elements -bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) +bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElement, + CXmlDomainImportContext& serializingContext) { // Get System Class Element CElement* pRootElement = getRoot(); @@ -298,13 +306,11 @@ bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElemen } // Parse settings -bool CConfigurableDomain::parseSettings(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) +bool CConfigurableDomain::parseSettings(const CXmlElement& xmlElement, + CXmlDomainImportContext& serializingContext) { - // Context - CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast(serializingContext); - // Check we actually need to parse configuration settings - if (!xmlDomainSerializingContext.withSettings()) { + if (!serializingContext.withSettings()) { // No parsing required return true; @@ -329,12 +335,14 @@ bool CConfigurableDomain::parseSettings(const CXmlElement& xmlElement, CXmlSeria if (!pDomainConfiguration) { - xmlDomainSerializingContext.setError("Could not find domain configuration referred to by configurable domain " + getName()); + serializingContext.setError("Could not find domain configuration referred to by" + " configurable domain \"" + getName() + "\"."); return false; } // Have domain configuration parse settings for all configurable elements - if (!pDomainConfiguration->parseSettings(xmlConfigurationSettingsElement, xmlDomainSerializingContext)) { + if (!pDomainConfiguration->parseSettings(xmlConfigurationSettingsElement, + serializingContext)) { return false; } diff --git a/parameter/ConfigurableDomain.h b/parameter/ConfigurableDomain.h index a7cbf73..084c187 100644 --- a/parameter/ConfigurableDomain.h +++ b/parameter/ConfigurableDomain.h @@ -30,6 +30,8 @@ #pragma once #include "BinarySerializableElement.h" +#include "XmlSerializingContext.h" +#include "XmlDomainImportContext.h" #include "SyncerSet.h" #include #include @@ -154,9 +156,39 @@ private: void doRemoveConfigurableElement(CConfigurableElement* pConfigurableElement, bool bRecomputeSyncSet); // XML parsing - bool parseDomainConfigurations(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); - bool parseConfigurableElements(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); - bool parseSettings(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); + /** + * Deserialize domain configurations from an Xml document and add them to + * the domain. + * + * @param[in] xmlElement the XML element to be parsed + * @param[in] serializingContext context for the deserialization + * + * @return false if an error occurs, true otherwise. + */ + bool parseDomainConfigurations(const CXmlElement& xmlElement, + CXmlDomainImportContext& serializingContext); + /** + * Deserialize domain elements from an Xml document and add them to + * the domain. + * + * @param[in] xmlElement the XML element to be parsed + * @param[in] serializingContext context for the deserialization + * + * @return false if an error occurs, true otherwise. + */ + bool parseConfigurableElements(const CXmlElement& xmlElement, + CXmlDomainImportContext& serializingContext); + /** + * Deserialize settings from an Xml document and add them to + * the domain. + * + * @param[in] xmlElement the XML element to be parsed + * @param[in] xmlDomainImportContext context for the deserialization + * + * @return false if an error occurs, true otherwise. + */ + bool parseSettings(const CXmlElement& xmlElement, + CXmlDomainImportContext& serializingContext); // XML composing void composeDomainConfigurations(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const; diff --git a/parameter/DomainConfiguration.cpp b/parameter/DomainConfiguration.cpp index 41ffeef..9c353ee 100644 --- a/parameter/DomainConfiguration.cpp +++ b/parameter/DomainConfiguration.cpp @@ -33,6 +33,8 @@ #include "CompoundRule.h" #include "Subsystem.h" #include "XmlDomainSerializingContext.h" +#include "XmlDomainImportContext.h" +#include "XmlDomainExportContext.h" #include "ConfigurationAccessContext.h" #include #include "RuleParser.h" @@ -71,7 +73,7 @@ bool CDomainConfiguration::childrenAreDynamic() const bool CDomainConfiguration::parseSettings(CXmlElement& xmlConfigurationSettingsElement, CXmlSerializingContext& serializingContext) { // Actual XML context - CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast(serializingContext); + CXmlDomainImportContext& xmlDomainImportContext = static_cast(serializingContext); // Take care of configurable elements / area configurations ranks std::list areaConfigurationList; @@ -90,7 +92,7 @@ bool CDomainConfiguration::parseSettings(CXmlElement& xmlConfigurationSettingsEl if (!pAreaConfiguration) { - xmlDomainSerializingContext.setError("Configurable Element " + strConfigurableElementPath + " referred to by Configuration " + getPath() + " not associated to Domain"); + xmlDomainImportContext.setError("Configurable Element " + strConfigurableElementPath + " referred to by Configuration " + getPath() + " not associated to Domain"); return false; } @@ -98,7 +100,7 @@ bool CDomainConfiguration::parseSettings(CXmlElement& xmlConfigurationSettingsEl areaConfigurationList.push_back(pAreaConfiguration); // Parse - if (!serializeConfigurableElementSettings(pAreaConfiguration, xmlConfigurableElementSettingsElement, xmlDomainSerializingContext, false)) { + if (!serializeConfigurableElementSettings(pAreaConfiguration, xmlConfigurableElementSettingsElement, xmlDomainImportContext, false)) { return false; } @@ -140,7 +142,8 @@ void CDomainConfiguration::composeSettings(CXmlElement& xmlConfigurationSettings bool CDomainConfiguration::serializeConfigurableElementSettings(CAreaConfiguration* pAreaConfiguration, CXmlElement& xmlConfigurableElementSettingsElement, CXmlSerializingContext& serializingContext, bool bSerializeOut) { // Actual XML context - CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast(serializingContext); + CXmlDomainExportContext& xmlDomainExportContext = + static_cast(serializingContext); // Configurable Element const CConfigurableElement* pConfigurableElement = pAreaConfiguration->getConfigurableElement(); @@ -183,10 +186,10 @@ bool CDomainConfiguration::serializeConfigurableElementSettings(CAreaConfigurati CConfigurationAccessContext configurationAccessContext(strError, bSerializeOut); // Provide current value space - configurationAccessContext.setValueSpaceRaw(xmlDomainSerializingContext.valueSpaceIsRaw()); + configurationAccessContext.setValueSpaceRaw(xmlDomainExportContext.valueSpaceIsRaw()); // Provide current output raw format - configurationAccessContext.setOutputRawFormat(xmlDomainSerializingContext.outputRawFormatIsHex()); + configurationAccessContext.setOutputRawFormat(xmlDomainExportContext.outputRawFormatIsHex()); // Get subsystem const CSubsystem* pSubsystem = pConfigurableElement->getBelongingSubsystem(); @@ -203,7 +206,7 @@ bool CDomainConfiguration::serializeConfigurableElementSettings(CAreaConfigurati if (!pAreaConfiguration->serializeXmlSettings(xmlConfigurableElementSettingsElementContent, configurationAccessContext)) { // Forward error - xmlDomainSerializingContext.setError(strError); + xmlDomainExportContext.setError(strError); return false; } diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index b707225..749aacd 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -60,6 +60,8 @@ #include "ConfigurableDomain.h" #include "DomainConfiguration.h" #include "XmlDomainSerializingContext.h" +#include "XmlDomainExportContext.h" +#include "XmlDomainImportContext.h" #include "BitParameterBlockType.h" #include "BitParameterType.h" #include "StringParameterType.h" @@ -620,18 +622,18 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath); // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary) - CXmlDomainSerializingContext xmlDomainSerializingContext(strError, !pBinarySettingsFileLocation); + CXmlDomainImportContext xmlDomainImportContext(strError, !pBinarySettingsFileLocation); // Selection criteria definition for rule creation - xmlDomainSerializingContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition()); + xmlDomainImportContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition()); // Auto validation of configurations if no binary settings provided - xmlDomainSerializingContext.setAutoValidationRequired(!pBinarySettingsFileLocation); + xmlDomainImportContext.setAutoValidationRequired(!pBinarySettingsFileLocation); log_info("Importing configurable domains from file %s %s settings", strXmlConfigurationDomainsFilePath.c_str(), pBinarySettingsFileLocation ? "without" : "with"); // Do parse - if (!xmlParse(xmlDomainSerializingContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) { + if (!xmlParse(xmlDomainImportContext, pConfigurableDomains, strXmlConfigurationDomainsFilePath, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) { return false; } @@ -2009,14 +2011,14 @@ bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSetti CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); // Context - CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings); + CXmlDomainImportContext xmlDomainImportContext(strError, bWithSettings); // Selection criteria definition for rule creation - xmlDomainSerializingContext.setSelectionCriteriaDefinition( + xmlDomainImportContext.setSelectionCriteriaDefinition( getConstSelectionCriteria()->getSelectionCriteriaDefinition()); // Init serializing context - xmlDomainSerializingContext.set( + xmlDomainImportContext.set( _pElementLibrarySet->getElementLibrary(EParameterConfigurationLibrary), "", _strSchemaFolderLocation); @@ -2050,7 +2052,7 @@ bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSetti // Use a doc sink that instantiate Configurable Domains from the given doc source CXmlMemoryDocSink memorySink(pConfigurableDomains); - bool bProcessSuccess = memorySink.process(*pSource, xmlDomainSerializingContext); + bool bProcessSuccess = memorySink.process(*pSource, xmlDomainImportContext); if (!bProcessSuccess) { @@ -2088,13 +2090,13 @@ bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, boo pConfigurableDomains->getKind() + ".xsd"; // Context - CXmlDomainSerializingContext xmlDomainSerializingContext(strError, bWithSettings); + CXmlDomainExportContext xmlDomainExportContext(strError, bWithSettings); // Value space - xmlDomainSerializingContext.setValueSpaceRaw(_bValueSpaceIsRaw); + xmlDomainExportContext.setValueSpaceRaw(_bValueSpaceIsRaw); // Output raw format - xmlDomainSerializingContext.setOutputRawFormat(_bOutputRawFormatIsHex); + xmlDomainExportContext.setOutputRawFormat(_bOutputRawFormatIsHex); // Use a doc source by loading data from instantiated Configurable Domains CXmlMemoryDocSource memorySource(pConfigurableDomains, pConfigurableDomains->getKind(), @@ -2115,7 +2117,7 @@ bool CParameterMgr::exportDomainsXml(string& strXmlDest, bool bWithSettings, boo pSink = new CXmlStringDocSink(strXmlDest); } - bool bProcessSuccess = pSink->process(memorySource, xmlDomainSerializingContext); + bool bProcessSuccess = pSink->process(memorySource, xmlDomainExportContext); delete pSink; return bProcessSuccess; diff --git a/parameter/SelectionCriterionRule.cpp b/parameter/SelectionCriterionRule.cpp index 6f350c3..b6df7aa 100644 --- a/parameter/SelectionCriterionRule.cpp +++ b/parameter/SelectionCriterionRule.cpp @@ -30,6 +30,7 @@ #include "SelectionCriterionRule.h" #include "SelectionCriterion.h" #include "XmlDomainSerializingContext.h" +#include "XmlDomainImportContext.h" #include "SelectionCriteriaDefinition.h" #include "SelectionCriterionTypeInterface.h" #include "RuleParser.h" @@ -152,17 +153,17 @@ bool CSelectionCriterionRule::matches() const bool CSelectionCriterionRule::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Retrieve actual context - CXmlDomainSerializingContext& xmlDomainSerializingContext = static_cast(serializingContext); + CXmlDomainImportContext& xmlDomainImportContext = static_cast(serializingContext); // Get selection criterion string strSelectionCriterion = xmlElement.getAttributeString("SelectionCriterion"); - _pSelectionCriterion = xmlDomainSerializingContext.getSelectionCriteriaDefinition()->getSelectionCriterion(strSelectionCriterion); + _pSelectionCriterion = xmlDomainImportContext.getSelectionCriteriaDefinition()->getSelectionCriterion(strSelectionCriterion); // Check existence if (!_pSelectionCriterion) { - xmlDomainSerializingContext.setError("Couldn't find selection criterion " + strSelectionCriterion + " in " + getKind() + " " + xmlElement.getPath()); + xmlDomainImportContext.setError("Couldn't find selection criterion " + strSelectionCriterion + " in " + getKind() + " " + xmlElement.getPath()); return false; } @@ -173,7 +174,7 @@ bool CSelectionCriterionRule::fromXml(const CXmlElement& xmlElement, CXmlSeriali if (!setMatchesWhen(strMatchesWhen, strError)) { - xmlDomainSerializingContext.setError("Wrong MatchesWhen attribute " + strMatchesWhen + " in " + getKind() + " " + xmlElement.getPath() + ": " + strError); + xmlDomainImportContext.setError("Wrong MatchesWhen attribute " + strMatchesWhen + " in " + getKind() + " " + xmlElement.getPath() + ": " + strError); return false; } @@ -183,7 +184,7 @@ bool CSelectionCriterionRule::fromXml(const CXmlElement& xmlElement, CXmlSeriali if (!_pSelectionCriterion->getCriterionType()->getNumericalValue(strValue, _iMatchValue)) { - xmlDomainSerializingContext.setError("Wrong Value attribute value " + strValue + " in " + getKind() + " " + xmlElement.getPath()); + xmlDomainImportContext.setError("Wrong Value attribute value " + strValue + " in " + getKind() + " " + xmlElement.getPath()); return false; } diff --git a/parameter/XmlDomainExportContext.h b/parameter/XmlDomainExportContext.h new file mode 100644 index 0000000..6a95d97 --- /dev/null +++ b/parameter/XmlDomainExportContext.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2014, 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 "XmlDomainSerializingContext.h" +#include + +class CXmlDomainExportContext : public CXmlDomainSerializingContext +{ +public: + CXmlDomainExportContext(std::string& strError, bool bWithSettings): + base(strError, bWithSettings) {} + + // Value interpretation as Real or Raw + void setValueSpaceRaw(bool bIsRaw) + { + _bValueSpaceIsRaw = bIsRaw; + } + + bool valueSpaceIsRaw() const + { + return _bValueSpaceIsRaw; + } + + // Output Raw Format for user get value interpretation + void setOutputRawFormat(bool bIsHex) + { + _bOutputRawFormatIsHex = bIsHex; + } + + bool outputRawFormatIsHex() const + { + return _bOutputRawFormatIsHex; + } + +private: + typedef CXmlDomainSerializingContext base; + + // Value Space + bool _bValueSpaceIsRaw; + + // Output Raw Format + bool _bOutputRawFormatIsHex; + +}; diff --git a/parameter/XmlDomainImportContext.h b/parameter/XmlDomainImportContext.h new file mode 100644 index 0000000..ed48122 --- /dev/null +++ b/parameter/XmlDomainImportContext.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2014, 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 "XmlDomainSerializingContext.h" +#include "SelectionCriteriaDefinition.h" + +#include + +class CXmlDomainImportContext : public CXmlDomainSerializingContext +{ +public: + CXmlDomainImportContext(std::string& strError, bool bWithSettings): + base(strError, bWithSettings), _bAutoValidationRequired(true) {} + + // Criteria defintion + void setSelectionCriteriaDefinition( + const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition) + { + _pSelectionCriteriaDefinition = pSelectionCriteriaDefinition; + } + + const CSelectionCriteriaDefinition* getSelectionCriteriaDefinition() const + { + return _pSelectionCriteriaDefinition; + } + + // Auto validation of configurations + void setAutoValidationRequired(bool bAutoValidationRequired) + { + _bAutoValidationRequired = bAutoValidationRequired; + } + + bool autoValidationRequired() const + { + return _bAutoValidationRequired; + } + +private: + typedef CXmlDomainSerializingContext base; + + // Criteria defintion + const CSelectionCriteriaDefinition* _pSelectionCriteriaDefinition; + + // Auto validation of configurations + bool _bAutoValidationRequired; +}; + diff --git a/parameter/XmlDomainSerializingContext.cpp b/parameter/XmlDomainSerializingContext.cpp deleted file mode 100644 index c159fbf..0000000 --- a/parameter/XmlDomainSerializingContext.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2011-2014, 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 "XmlDomainSerializingContext.h" - -#define base CXmlElementSerializingContext - -using std::string; - -CXmlDomainSerializingContext::CXmlDomainSerializingContext(string& strError, bool bWithSettings) - : base(strError), _bWithSettings(bWithSettings), _bValueSpaceIsRaw(false), _bOutputRawFormatIsHex(false), _pSelectionCriteriaDefinition(NULL), _bAutoValidationRequired(true) -{ -} - -// Settings to be loaded or not -bool CXmlDomainSerializingContext::withSettings() const -{ - return _bWithSettings; -} - -// Value Space -void CXmlDomainSerializingContext::setValueSpaceRaw(bool bIsRaw) -{ - _bValueSpaceIsRaw = bIsRaw; -} - -bool CXmlDomainSerializingContext::valueSpaceIsRaw() const -{ - return _bValueSpaceIsRaw; -} - -// Output Raw Format for user get value interpretation -void CXmlDomainSerializingContext::setOutputRawFormat(bool bIsHex) -{ - _bOutputRawFormatIsHex = bIsHex; -} - -bool CXmlDomainSerializingContext::outputRawFormatIsHex() -{ - return _bOutputRawFormatIsHex; -} - -// Criteria defintion -void CXmlDomainSerializingContext::setSelectionCriteriaDefinition(const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition) -{ - _pSelectionCriteriaDefinition = pSelectionCriteriaDefinition; -} - -const CSelectionCriteriaDefinition* CXmlDomainSerializingContext::getSelectionCriteriaDefinition() const -{ - return _pSelectionCriteriaDefinition; -} - -// Auto validation of configurations -void CXmlDomainSerializingContext::setAutoValidationRequired(bool bAutoValidationRequired) -{ - _bAutoValidationRequired = bAutoValidationRequired; -} - -bool CXmlDomainSerializingContext::autoValidationRequired() const -{ - return _bAutoValidationRequired; -} diff --git a/parameter/XmlDomainSerializingContext.h b/parameter/XmlDomainSerializingContext.h index 88d2b5f..955d939 100644 --- a/parameter/XmlDomainSerializingContext.h +++ b/parameter/XmlDomainSerializingContext.h @@ -33,41 +33,21 @@ #include -class CParameterBlackboard; -class CSelectionCriteriaDefinition; - class CXmlDomainSerializingContext : public CXmlElementSerializingContext { public: - CXmlDomainSerializingContext(std::string& strError, bool bWithSettings); + CXmlDomainSerializingContext(std::string& strError, bool bWithSettings): + base(strError), _bWithSettings(bWithSettings) {} // Settings to be serialized or not - bool withSettings() const; - - // Value interpretation as Real or Raw - void setValueSpaceRaw(bool bIsRaw); - bool valueSpaceIsRaw() const; - - // Output Raw Format for user get value interpretation - void setOutputRawFormat(bool bIsHex); - bool outputRawFormatIsHex(); + bool withSettings() const + { + return _bWithSettings; + } - // Criteria defintion - void setSelectionCriteriaDefinition(const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition); - const CSelectionCriteriaDefinition* getSelectionCriteriaDefinition() const; - - // Auto validation of configurations - void setAutoValidationRequired(bool bAutoValidationRequired); - bool autoValidationRequired() const; private: + typedef CXmlElementSerializingContext base; + // Indicate wheter or not to import settings bool _bWithSettings; - // Value Space - bool _bValueSpaceIsRaw; - // Output Raw Format - bool _bOutputRawFormatIsHex; - // Criteria defintion - const CSelectionCriteriaDefinition* _pSelectionCriteriaDefinition; - // Auto validation of configurations - bool _bAutoValidationRequired; }; -- cgit v1.1 From d8a53107d5f965c8ca406ee95f5999efd6694730 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Wed, 10 Dec 2014 14:49:23 +0100 Subject: Pass the SystemClass as deserialization context for Domains This allows diminishing the dependency on the parent element when creating a Domain element from an XML document: the parent was used to get a handle to the system class in order to check the existence of ConfigurableElements included in the Domain. Change-Id: Icba7c3c4db2b9728c0fb7c6840a254de9775f6a4 Signed-off-by: David Wagner --- parameter/ConfigurableDomain.cpp | 12 ++++-------- parameter/ParameterMgr.cpp | 5 +++-- parameter/XmlDomainImportContext.h | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 12 deletions(-) (limited to 'parameter') diff --git a/parameter/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index c3fa1f9..bdcddd4 100644 --- a/parameter/ConfigurableDomain.cpp +++ b/parameter/ConfigurableDomain.cpp @@ -253,12 +253,7 @@ bool CConfigurableDomain::parseDomainConfigurations(const CXmlElement& xmlElemen bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElement, CXmlDomainImportContext& serializingContext) { - // Get System Class Element - CElement* pRootElement = getRoot(); - - CElement* pSystemClassElement = pRootElement->findChildOfKind("SystemClass"); - - assert(pSystemClassElement); + CSystemClass& systemClass = serializingContext.getSystemClass(); // Get ConfigurableElements element CXmlElement xmlConfigurableElementsElement; @@ -278,14 +273,15 @@ bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElemen string strError; // Is there an element and does it match system class name? - if (!pathNavigator.navigateThrough(pSystemClassElement->getName(), strError)) { + if (!pathNavigator.navigateThrough(systemClass.getName(), strError)) { serializingContext.setError("Could not find configurable element of path " + strConfigurableElementPath + " from ConfigurableDomain description " + getName() + " (" + strError + ")"); return false; } // Browse system class for configurable element - CConfigurableElement* pConfigurableElement = static_cast(pSystemClassElement->findDescendant(pathNavigator)); + CConfigurableElement* pConfigurableElement = + static_cast(systemClass.findDescendant(pathNavigator)); if (!pConfigurableElement) { diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 749aacd..8a6adf0 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -622,7 +622,8 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath); // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary) - CXmlDomainImportContext xmlDomainImportContext(strError, !pBinarySettingsFileLocation); + CXmlDomainImportContext xmlDomainImportContext(strError, !pBinarySettingsFileLocation, + *getSystemClass()); // Selection criteria definition for rule creation xmlDomainImportContext.setSelectionCriteriaDefinition(getConstSelectionCriteria()->getSelectionCriteriaDefinition()); @@ -2011,7 +2012,7 @@ bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSetti CConfigurableDomains* pConfigurableDomains = getConfigurableDomains(); // Context - CXmlDomainImportContext xmlDomainImportContext(strError, bWithSettings); + CXmlDomainImportContext xmlDomainImportContext(strError, bWithSettings, *getSystemClass()); // Selection criteria definition for rule creation xmlDomainImportContext.setSelectionCriteriaDefinition( diff --git a/parameter/XmlDomainImportContext.h b/parameter/XmlDomainImportContext.h index ed48122..11090b0 100644 --- a/parameter/XmlDomainImportContext.h +++ b/parameter/XmlDomainImportContext.h @@ -31,14 +31,21 @@ #include "XmlDomainSerializingContext.h" #include "SelectionCriteriaDefinition.h" +#include "SystemClass.h" #include class CXmlDomainImportContext : public CXmlDomainSerializingContext { public: - CXmlDomainImportContext(std::string& strError, bool bWithSettings): - base(strError, bWithSettings), _bAutoValidationRequired(true) {} + CXmlDomainImportContext(std::string& strError, bool bWithSettings, CSystemClass& systemClass): + base(strError, bWithSettings), _systemClass(systemClass), _bAutoValidationRequired(true) {} + + // System Class + CSystemClass& getSystemClass() const + { + return _systemClass; + } // Criteria defintion void setSelectionCriteriaDefinition( @@ -66,6 +73,9 @@ public: private: typedef CXmlDomainSerializingContext base; + // System Class + CSystemClass& _systemClass; + // Criteria defintion const CSelectionCriteriaDefinition* _pSelectionCriteriaDefinition; -- cgit v1.1 From ed744eb61b3fced13193fb59f728f26847748179 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Thu, 4 Dec 2014 18:38:52 +0100 Subject: New remote command for exporting a single domain The command is used as follows: getDomainWithSettingsXML 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 --- parameter/ConfigurableDomains.h | 4 ++- parameter/ParameterMgr.cpp | 76 ++++++++++++++++++++++++++++++++--------- parameter/ParameterMgr.h | 53 +++++++++++++++++++++++++--- 3 files changed, 110 insertions(+), 23 deletions(-) (limited to 'parameter') 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& 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, + "", "Print the given domain including settings as XML" }, { "setDomainsWithSettingsXML", &CParameterMgr::setConfigurableDomainsWithSettingsXMLCommmandProcess, 1, "", "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. -- cgit v1.1 From fd21197b84f46ba53ace3a1b9d0c05596815dd51 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Wed, 10 Dec 2014 15:01:22 +0100 Subject: New command for importing a single domain from a file The command is used as follows: importDomainWithSettingsXML [overwrite] It reads the file given as first argument (path must be absolute) and imports the domain found in it. It does not check whether it overlaps with another domain (same elements in two domains). It does, however, check if there is an existing domain with the same name as the one being imported. If so and if the (optional) second argument is "overwrite", it will first delete the existing domain; if not it will refuse to import the new domain. Change-Id: I7aaa225f2f1a296f52dc8a97f55e1ff70c06d567 Signed-off-by: David Wagner --- parameter/ConfigurableDomain.cpp | 7 +++ parameter/ConfigurableDomain.h | 1 + parameter/ConfigurableDomains.cpp | 46 +++++++++++++++---- parameter/ConfigurableDomains.h | 32 +++++++++++++ parameter/ParameterMgr.cpp | 97 ++++++++++++++++++++++++++++++++++++--- parameter/ParameterMgr.h | 26 +++++++++++ 6 files changed, 193 insertions(+), 16 deletions(-) (limited to 'parameter') diff --git a/parameter/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index bdcddd4..35acb9c 100644 --- a/parameter/ConfigurableDomain.cpp +++ b/parameter/ConfigurableDomain.cpp @@ -40,6 +40,11 @@ using std::string; +CConfigurableDomain::CConfigurableDomain() : + _bSequenceAware(false), _pLastAppliedConfiguration(NULL) +{ +} + CConfigurableDomain::CConfigurableDomain(const string& strName) : base(strName), _bSequenceAware(false), _pLastAppliedConfiguration(NULL) { } @@ -215,6 +220,8 @@ bool CConfigurableDomain::fromXml(const CXmlElement& xmlElement, CXmlSerializing // Sequence awareness (optional) _bSequenceAware = xmlElement.hasAttribute("SequenceAware") && xmlElement.getAttributeBoolean("SequenceAware"); + setName(xmlElement.getAttributeString("Name")); + // Local parsing. Do not dig if (!parseDomainConfigurations(xmlElement, xmlDomainImportContext) || !parseConfigurableElements(xmlElement, xmlDomainImportContext) || diff --git a/parameter/ConfigurableDomain.h b/parameter/ConfigurableDomain.h index 084c187..a29c1ba 100644 --- a/parameter/ConfigurableDomain.h +++ b/parameter/ConfigurableDomain.h @@ -48,6 +48,7 @@ class CConfigurableDomain : public CBinarySerializableElement typedef std::list::const_iterator ConfigurableElementListIterator; typedef std::map::const_iterator ConfigurableElementToSyncerSetMapIterator; public: + CConfigurableDomain(); CConfigurableDomain(const std::string& strName); virtual ~CConfigurableDomain(); diff --git a/parameter/ConfigurableDomains.cpp b/parameter/ConfigurableDomains.cpp index 8dff45a..b77e2aa 100644 --- a/parameter/ConfigurableDomains.cpp +++ b/parameter/ConfigurableDomains.cpp @@ -127,26 +127,52 @@ bool CConfigurableDomains::createDomain(const string& strName, string& strError) return true; } -bool CConfigurableDomains::deleteDomain(const string& strName, string& strError) +bool CConfigurableDomains::addDomain(CConfigurableDomain& domain, bool bOverwrite, + string& strError) { - CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strName, strError); + string strErrorDrop; - if (!pConfigurableDomain) { + string strDomainName(domain.getName()); + CConfigurableDomain* pExistingDomain = findConfigurableDomain(strDomainName, strErrorDrop); - return false; - } + if (pExistingDomain) { + if (!bOverwrite) { + strError = "Can't add domain \"" + strDomainName + + "\" because it already exists and overwrite was not requested."; + return false; + } - log_info("Deleting configurable domain \"%s\"", strName.c_str()); + deleteDomain(*pExistingDomain); + } - // Hierarchy - removeChild(pConfigurableDomain); + log_info("Adding configurable domain \"" + strDomainName + "\""); - // Destroy - delete pConfigurableDomain; + addChild(&domain); return true; } +void CConfigurableDomains::deleteDomain(CConfigurableDomain& configurableDomain) +{ + log_info("Deleting configurable domain \"" + configurableDomain.getName() + "\""); + + removeChild(&configurableDomain); + + delete &configurableDomain; +} + +bool CConfigurableDomains::deleteDomain(const string& strName, string& strError) +{ + CConfigurableDomain* pConfigurableDomain = findConfigurableDomain(strName, strError); + + if (pConfigurableDomain) { + deleteDomain(*pConfigurableDomain); + return true; + } + + return false; +} + void CConfigurableDomains::deleteAllDomains() { log_info("Deleting all configurable domains"); diff --git a/parameter/ConfigurableDomains.h b/parameter/ConfigurableDomains.h index 8016cb9..3cc16df 100644 --- a/parameter/ConfigurableDomains.h +++ b/parameter/ConfigurableDomains.h @@ -49,6 +49,30 @@ public: // Configuration/Domains handling /// Domains bool createDomain(const std::string& strName, std::string& strError); + + /* + * Adds a domain object to configurable domains. The ConfigurableDomains + * object takes ownership of the ConfigurableDomain object. + * + * @param[in] pDomain the domain object. + * @param[in] bOverwrite if false, will refuse to overwrite an existing + * domain, otherwise, an existing domain with the same name will first be + * removed. + * @param[in,out] strError error message + * + * @returns true if the domain was successfully added + */ + bool addDomain(CConfigurableDomain& domain, bool bOverwrite, std::string& strError); + + /** + * Delete a domain by name + * + * @param[in] strName name of the domain to be deleted + * @param[in,out] strError error message + * + * @returns true of the domain was sucessfully deleted, false otherwise (i.e. + * the domain didn't exist). + */ bool deleteDomain(const std::string& strName, std::string& strError); void deleteAllDomains(); bool renameDomain(const std::string& strName, const std::string& strNewName, std::string& strError); @@ -105,6 +129,14 @@ public: // Class kind virtual std::string getKind() const; private: + /** Delete a domain + * + * @param(in] configurableDomain domain to be deleted + * @param[in,out] strError error message + * @returns true of the domain was sucessfully deleted, false otherwise (i.e. + * the domain didn't exist). + */ + void deleteDomain(CConfigurableDomain& configurableDomain); // Returns true if children dynamic creation is to be dealt with virtual bool childrenAreDynamic() const; // Gather owned configurable elements owned by any domain diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index 9b01c85..84a3fd4 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -89,6 +89,7 @@ #include "XmlMemoryDocSource.h" #include "Utility.h" #include +#include #define base CElement @@ -259,6 +260,11 @@ const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandPa { "importDomainsWithSettingsXML", &CParameterMgr::importConfigurableDomainsWithSettingsFromXMLCommmandProcess, 1, "", "Import domains including settings from XML file" }, + { "importDomainWithSettingsXML", + &CParameterMgr::importConfigurableDomainWithSettingsFromXMLCommmandProcess, 1, + " [overwrite]", "Import a single domain including settings from XML file." + " Does not overwrite an existing domain unless 'overwrite' is passed as second" + " argument" }, { "exportSettings", &CParameterMgr::exportSettingsCommmandProcess, 1, "", "Export settings to binary file" }, { "importSettings", &CParameterMgr::importSettingsCommmandProcess, 1, @@ -654,6 +660,38 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) return true; } +bool CParameterMgr::importDomainFromFile(const string& strXmlFilePath, bool bOverwrite, + string& strError) +{ + CXmlDomainImportContext xmlDomainImportContext(strError, true, *getSystemClass()); + + // Selection criteria definition for rule creation + xmlDomainImportContext.setSelectionCriteriaDefinition( + getConstSelectionCriteria()->getSelectionCriteriaDefinition()); + + // Auto validation of configurations + xmlDomainImportContext.setAutoValidationRequired(true); + + // We initialize the domain with an empty name but since we have set the isDomainStandalone + // context, the name will be retrieved during de-serialization + std::auto_ptr standaloneDomain(new CConfigurableDomain()); + bool bSuccess = xmlParse(xmlDomainImportContext, standaloneDomain.get(), + strXmlFilePath, "", EParameterConfigurationLibrary, ""); + + if (!bSuccess) { + return false; + } + + bSuccess = getConfigurableDomains()->addDomain(*standaloneDomain, bOverwrite, strError); + if (!bSuccess) { + return false; + } + + // ownership has been transfered to the ConfigurableDomains object + standaloneDomain.release(); + return true; +} + // XML parsing bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, const string& strXmlFilePath, const string& strXmlFolder, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttrituteName) { @@ -664,17 +702,25 @@ bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingCo // Get Schema file associated to root element string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd"; - CXmlFileDocSource fileDocSource(strXmlFilePath, strXmlSchemaFilePath, - pRootElement->getKind(), - pRootElement->getName(), strNameAttrituteName, - _bValidateSchemasOnStart); + std::auto_ptr fileDocSource(NULL); + + if (strNameAttrituteName.empty()) { + fileDocSource.reset(new CXmlFileDocSource(strXmlFilePath, strXmlSchemaFilePath, + pRootElement->getKind(), + _bValidateSchemasOnStart)); + } else { + fileDocSource.reset(new CXmlFileDocSource(strXmlFilePath, strXmlSchemaFilePath, + pRootElement->getKind(), + pRootElement->getName(), strNameAttrituteName, + _bValidateSchemasOnStart)); + } // Start clean pRootElement->clean(); CXmlMemoryDocSink memorySink(pRootElement); - if (!memorySink.process(fileDocSource, elementSerializingContext)) { + if (!memorySink.process(*fileDocSource, elementSerializingContext)) { //Cleanup pRootElement->clean(); @@ -1519,6 +1565,26 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableD return importDomainsXml(remoteCommand.getArgument(0), true, true, strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; } +CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::importConfigurableDomainWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) +{ + bool bOverwrite = false; + + // Look for optional arguments + if (remoteCommand.getArgumentCount() > 1) { + + if (remoteCommand.getArgument(1) == "overwrite") { + + bOverwrite = true; + } else { + // Show usage + return CCommandHandler::EShowUsage; + } + } + + return importSingleDomainXml(remoteCommand.getArgument(0), bOverwrite, strResult) ? + CCommandHandler::EDone : CCommandHandler::EFailed; +} + CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult) { return exportDomainsBinary(remoteCommand.getArgument(0), strResult) ? CCommandHandler::EDone : CCommandHandler::EFailed; @@ -2085,6 +2151,25 @@ bool CParameterMgr::importDomainsXml(const string& strXmlSource, bool bWithSetti return bProcessSuccess; } +bool CParameterMgr::importSingleDomainXml(const string& strXmlSource, bool bOverwrite, + string& strError) +{ + if (!checkTuningModeOn(strError)) { + + return false; + } + + // check path is absolute + if (strXmlSource[0] != '/') { + + strError = "Please provide absolute path"; + + return false; + } + + return importDomainFromFile(strXmlSource, bOverwrite, strError); +} + bool CParameterMgr::serializeElement(string& strXmlDest, CXmlSerializingContext& xmlSerializingContext, bool bToFile, const CElement& element, string& strError) const @@ -2269,7 +2354,7 @@ void CParameterMgr::feedElementLibraries() // Parameter Configuration Domains creation CElementLibrary* pParameterConfigurationLibrary = new CElementLibrary; - pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TNamedElementBuilderTemplate()); + pParameterConfigurationLibrary->addElementBuilder("ConfigurableDomain", new TElementBuilderTemplate()); pParameterConfigurationLibrary->addElementBuilder("Configuration", new TNamedElementBuilderTemplate()); pParameterConfigurationLibrary->addElementBuilder("CompoundRule", new TElementBuilderTemplate()); pParameterConfigurationLibrary->addElementBuilder("SelectionCriterionRule", new TElementBuilderTemplate()); diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index cd1c468..7962294 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -250,6 +250,31 @@ public: bool importDomainsXml(const std::string& strXmlSource, bool bWithSettings, bool bFromFile, std::string& strError); + /** + * Method that imports a single Configurable Domain from an Xml source. + * + * @param[in] strXmlSource 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] bFromFile a boolean that determines if the source is an xml description in + * strXmlSource or contained in a file. In that case strXmlSource is just the file path. + * @param[out] strError is used as the error output + * + * @return false if any error occurs + */ + bool importSingleDomainXml(const std::string& strXmlSource, bool bOverwrite, + std::string& strError); + + /** + * Method that imports a single Configurable Domain, with settings, from an Xml file. + * + * @param[in] strXmlFilePath absolute path to the xml file containing the domain + * @param[out] strError is used as the error output + * + * @return false if any error occurs + */ + bool importDomainFromFile(const std::string& strXmlFilePath, bool bOverwrite, std::string& strError); + /** * Export an element object to an Xml destination. @@ -398,6 +423,7 @@ private: CCommandHandler::CommandStatus importConfigurableDomainsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); CCommandHandler::CommandStatus exportConfigurableDomainsWithSettingsToXMLCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); CCommandHandler::CommandStatus importConfigurableDomainsWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); + CCommandHandler::CommandStatus importConfigurableDomainWithSettingsFromXMLCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); CCommandHandler::CommandStatus exportSettingsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); CCommandHandler::CommandStatus importSettingsCommmandProcess(const IRemoteCommand& remoteCommand, std::string& strResult); -- cgit v1.1