diff --git a/.travis.yml b/.travis.yml index 3e96f39fc..d6c0c1956 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,6 +59,7 @@ after_success: --exclude "bindings/c/Test.cpp" --exclude "parameter/criterion/test/" --exclude "test/tokenizer" + --exclude "xmlserializer/test" --gcov /usr/bin/gcov-4.8 --gcov-options '\--long-file-names --preserve-paths' diff --git a/Schemas/SystemClass.xsd b/Schemas/SystemClass.xsd index 5aa32db27..7617a9653 100644 --- a/Schemas/SystemClass.xsd +++ b/Schemas/SystemClass.xsd @@ -7,7 +7,6 @@ - diff --git a/bindings/c/Test.cpp b/bindings/c/Test.cpp index db063ff4f..8b6e863f8 100644 --- a/bindings/c/Test.cpp +++ b/bindings/c/Test.cpp @@ -135,17 +135,15 @@ TEST_CASE_METHOD(Test, "Parameter-framework c api use") { // Create valid pfw config file const char *intParameterPath = "/test/system/integer"; const char *stringParameterPath = "/test/system/string"; - TmpFile system("\ - \ - \ - \ - \ - \ - \ - "); TmpFile libraries("\ \ - \ + \ + \ + \ + \ + \ + \ + \ "); TmpFile config("\ (getParent()); @@ -99,7 +99,7 @@ bool CBitParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingCo // Max if (xmlElement.hasAttribute("Max")) { - _uiMax = xmlElement.getAttributeInteger("Max"); + xmlElement.getAttribute("Max", _uiMax); if (_uiMax > getMaxEncodableValue()) { @@ -246,13 +246,13 @@ bool CBitParameterType::isEncodable(uint64_t uiData) const void CBitParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Position - xmlElement.setAttributeString("Pos", CUtility::toString(_uiBitPos)); + xmlElement.setAttribute("Pos", _uiBitPos); // Size - xmlElement.setAttributeString("Size", CUtility::toString(_uiBitSize)); + xmlElement.setAttribute("Size", _uiBitSize); // Maximum - xmlElement.setAttributeString("Max", CUtility::toString(_uiMax)); + xmlElement.setAttribute("Max", _uiMax); base::toXml(xmlElement, serializingContext); diff --git a/parameter/CMakeLists.txt b/parameter/CMakeLists.txt index d67bd4df8..b852485d5 100644 --- a/parameter/CMakeLists.txt +++ b/parameter/CMakeLists.txt @@ -59,7 +59,6 @@ add_library(parameter SHARED ErrorContext.cpp FixedPointParameterType.cpp FormattedSubsystemObject.cpp - FrameworkConfigurationLocation.cpp HardwareBackSynchronizer.cpp InstanceConfigurableElement.cpp InstanceDefinition.cpp @@ -73,14 +72,12 @@ add_library(parameter SHARED ParameterBlackboard.cpp ParameterBlockType.cpp Parameter.cpp - ParameterFrameworkConfiguration.cpp ParameterHandle.cpp ParameterMgr.cpp ParameterMgrFullConnector.cpp ParameterMgrPlatformConnector.cpp ParameterType.cpp PathNavigator.cpp - PluginLocation.cpp RuleParser.cpp SelectionCriterionRule.cpp SimulatedBackSynchronizer.cpp @@ -96,7 +93,6 @@ add_library(parameter SHARED VirtualSubsystem.cpp VirtualSyncer.cpp XmlElementSerializingContext.cpp - XmlFileIncluderElement.cpp XmlParameterSerializingContext.cpp command/src/Parser.cpp) @@ -105,6 +101,7 @@ include_directories( command/include "${PROJECT_SOURCE_DIR}/parameter" "${PROJECT_SOURCE_DIR}/xmlserializer" + "${PROJECT_SOURCE_DIR}/xmlserializer/include" "${PROJECT_SOURCE_DIR}/utility" "${PROJECT_SOURCE_DIR}/remote-processor" "${PROJECT_SOURCE_DIR}/parameter/log/include" @@ -131,7 +128,6 @@ install(FILES Element.h ElementBuilder.h ElementLibrary.h - FileIncluderElementBuilder.h FormattedSubsystemObject.h InstanceConfigurableElement.h Mapper.h diff --git a/parameter/ComponentInstance.cpp b/parameter/ComponentInstance.cpp index f26a383df..ecf4ba4d3 100644 --- a/parameter/ComponentInstance.cpp +++ b/parameter/ComponentInstance.cpp @@ -80,7 +80,8 @@ bool CComponentInstance::fromXml(const CXmlElement& xmlElement, CXmlSerializingC const CComponentLibrary* pComponentLibrary = parameterBuildContext.getComponentLibrary(); - std::string strComponentType = xmlElement.getAttributeString("Type"); + std::string strComponentType; + xmlElement.getAttribute("Type", strComponentType); _pComponentType = pComponentLibrary->getComponentType(strComponentType); diff --git a/parameter/ComponentType.cpp b/parameter/ComponentType.cpp index ee71596c4..5b077e3c5 100644 --- a/parameter/ComponentType.cpp +++ b/parameter/ComponentType.cpp @@ -89,7 +89,8 @@ bool CComponentType::fromXml(const CXmlElement& xmlElement, CXmlSerializingConte // Check for Extends attribute (extensions will be populated after and not before) if (xmlElement.hasAttribute("Extends")) { - std::string strExtendsType = xmlElement.getAttributeString("Extends"); + std::string strExtendsType; + xmlElement.getAttribute("Extends", strExtendsType); _pExtendsComponentType = pComponentLibrary->getComponentType(strExtendsType); diff --git a/parameter/CompoundRule.cpp b/parameter/CompoundRule.cpp index addb31ce9..0e66adb44 100644 --- a/parameter/CompoundRule.cpp +++ b/parameter/CompoundRule.cpp @@ -150,7 +150,7 @@ bool CCompoundRule::fromXml(const CXmlElement& xmlElement, CXmlSerializingContex void CCompoundRule::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Set type - xmlElement.setAttributeString("Type", _apcTypes[_bTypeAll]); + xmlElement.setAttribute("Type", _apcTypes[_bTypeAll]); // Base base::toXml(xmlElement, serializingContext); diff --git a/parameter/ConfigurableDomain.cpp b/parameter/ConfigurableDomain.cpp index 7f84cf5f8..e777fb3f0 100644 --- a/parameter/ConfigurableDomain.cpp +++ b/parameter/ConfigurableDomain.cpp @@ -120,7 +120,7 @@ void CConfigurableDomain::toXml(CXmlElement& xmlElement, CXmlSerializingContext& base::toXml(xmlElement, serializingContext); // Sequence awareness - xmlElement.setAttributeBoolean("SequenceAware", _bSequenceAware); + xmlElement.setAttribute("SequenceAware", _bSequenceAware); } void CConfigurableDomain::childrenToXml(CXmlElement& xmlElement, @@ -168,7 +168,7 @@ void CConfigurableDomain::composeConfigurableElements(CXmlElement& xmlElement) c xmlConfigurableElementsElement.createChild(xmlChildConfigurableElement, "ConfigurableElement"); // Set Path attribute - xmlChildConfigurableElement.setAttributeString("Path", pConfigurableElement->getPath()); + xmlChildConfigurableElement.setAttribute("Path", pConfigurableElement->getPath()); } } @@ -217,9 +217,11 @@ bool CConfigurableDomain::fromXml(const CXmlElement& xmlElement, CXmlSerializing static_cast(serializingContext); // Sequence awareness (optional) - _bSequenceAware = xmlElement.hasAttribute("SequenceAware") && xmlElement.getAttributeBoolean("SequenceAware"); + xmlElement.getAttribute("SequenceAware", _bSequenceAware); - setName(xmlElement.getAttributeString("Name")); + std::string name; + xmlElement.getAttribute("Name", name); + setName(name); // Local parsing. Do not dig if (!parseDomainConfigurations(xmlElement, xmlDomainImportContext) || @@ -273,7 +275,8 @@ bool CConfigurableDomain::parseConfigurableElements(const CXmlElement& xmlElemen while (it.next(xmlConfigurableElementElement)) { // Locate configurable element - string strConfigurableElementPath = xmlConfigurableElementElement.getAttributeString("Path"); + string strConfigurableElementPath; + xmlConfigurableElementElement.getAttribute("Path", strConfigurableElementPath); CPathNavigator pathNavigator(strConfigurableElementPath); string strError; diff --git a/parameter/ConfigurableDomains.cpp b/parameter/ConfigurableDomains.cpp index ee1a2d22d..441710aed 100644 --- a/parameter/ConfigurableDomains.cpp +++ b/parameter/ConfigurableDomains.cpp @@ -111,7 +111,7 @@ void CConfigurableDomains::apply(CParameterBlackboard* pParameterBlackboard, void CConfigurableDomains::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Set attribute - xmlElement.setAttributeString("SystemClassName", getName()); + xmlElement.setAttribute("SystemClassName", getName()); base::childrenToXml(xmlElement, serializingContext); } diff --git a/parameter/PluginLocation.h b/parameter/Configuration.h similarity index 63% rename from parameter/PluginLocation.h rename to parameter/Configuration.h index 3a8e13132..a10c2c116 100644 --- a/parameter/PluginLocation.h +++ b/parameter/Configuration.h @@ -28,27 +28,37 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once -#include "KindElement.h" -#include + #include +#include -class CPluginLocation : public CKindElement +namespace core { -public: - CPluginLocation(const std::string& strName, const std::string& strKind); - - // From IXmlSink - virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); - - // Folder - const std::string& getFolder() const; - - // Plugin list - const std::list& getPluginList() const; - -private: - std::string _strFolder; - std::list _pluginList; +/** Parameter-Framework Configuration holder */ +struct Configuration +{ + /** @param[in] file the file which contains the configuration */ + Configuration(const std::string &file) : configurationFile(file) {} + /** System class name */ + std::string systemClassName; + /** Indicate if the tuning is allowed */ + bool tuningAllowed = false; + /** Remote command server listening port */ + uint16_t serverPort = 0; + /** File which contains the configuration */ + std::string configurationFile; + /** Application XML schemas directory */ + std::string schemasLocation; + /** Application structure file */ + std::string structureFile; + /** Application settings file */ + std::string settingsFile; + /** Application binary settings file */ + std::string binarySettingsFile; + /** Application plugin path list */ + std::list plugins; }; + +} /** core namespace */ diff --git a/parameter/DomainConfiguration.cpp b/parameter/DomainConfiguration.cpp index dfc35c71e..30e33d8ff 100644 --- a/parameter/DomainConfiguration.cpp +++ b/parameter/DomainConfiguration.cpp @@ -86,7 +86,8 @@ bool CDomainConfiguration::parseSettings(CXmlElement& xmlConfigurationSettingsEl while (it.next(xmlConfigurableElementSettingsElement)) { // Retrieve area configuration - string strConfigurableElementPath = xmlConfigurableElementSettingsElement.getAttributeString("Path"); + string strConfigurableElementPath; + xmlConfigurableElementSettingsElement.getAttribute("Path", strConfigurableElementPath); CAreaConfiguration* pAreaConfiguration = findAreaConfiguration(strConfigurableElementPath); @@ -131,7 +132,7 @@ void CDomainConfiguration::composeSettings(CXmlElement& xmlConfigurationSettings xmlConfigurationSettingsElement.createChild(xmlConfigurableElementSettingsElement, "ConfigurableElement"); // Set Path attribute - xmlConfigurableElementSettingsElement.setAttributeString("Path", pConfigurableElement->getPath()); + xmlConfigurableElementSettingsElement.setAttribute("Path", pConfigurableElement->getPath()); // Delegate composing to area configuration ((CDomainConfiguration&)(*this)).serializeConfigurableElementSettings((CAreaConfiguration*)pAreaConfiguration, xmlConfigurableElementSettingsElement, serializingContext, true); diff --git a/parameter/Element.cpp b/parameter/Element.cpp index 6a4cf93c2..23a842e6b 100644 --- a/parameter/Element.cpp +++ b/parameter/Element.cpp @@ -129,7 +129,7 @@ void CElement::logValue(string& strValue, CErrorContext& errorContext) const // From IXmlSink bool CElement::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { - setDescription(getXmlDescriptionAttribute(xmlElement)); + xmlElement.getAttribute(gDescriptionPropertyName, _strDescription); // Propagate through children CXmlElement::CChildIterator childIterator(xmlElement); @@ -206,15 +206,10 @@ void CElement::setXmlDescriptionAttribute(CXmlElement& xmlElement) const { const string &description = getDescription(); if (!description.empty()) { - xmlElement.setAttributeString(gDescriptionPropertyName, description); + xmlElement.setAttribute(gDescriptionPropertyName, description); } } -string CElement::getXmlDescriptionAttribute(const CXmlElement& xmlElement) const -{ - return xmlElement.getAttributeString(gDescriptionPropertyName); -} - void CElement::setXmlNameAttribute(CXmlElement& xmlElement) const { // By default, set Name attribute if any diff --git a/parameter/Element.h b/parameter/Element.h index 3271df8af..bf1ea90db 100644 --- a/parameter/Element.h +++ b/parameter/Element.h @@ -137,15 +137,6 @@ class CElement : public IXmlSink, public IXmlSource */ void setXmlDescriptionAttribute(CXmlElement& xmlElement) const; - /** - * Extract the Description field from the Xml Element during XML decomposing. - * - * @param[in] xmlElement to extract the description from. - * - * @return description represented as a string, empty if not found - */ - std::string getXmlDescriptionAttribute(const CXmlElement &xmlElement) const; - /** * Appends if found human readable description property. * @@ -171,6 +162,8 @@ class CElement : public IXmlSink, public IXmlSource CElement* createChild(const CXmlElement& childElement, CXmlSerializingContext& elementSerializingContext); + static const std::string gDescriptionPropertyName; + private: // Returns Name or Kind if no Name std::string getPathName() const; @@ -194,6 +187,4 @@ class CElement : public IXmlSink, public IXmlSource std::vector _childArray; // Parent CElement* _pParent; - - static const std::string gDescriptionPropertyName; }; diff --git a/parameter/EnumParameterType.cpp b/parameter/EnumParameterType.cpp index 147ee95bf..ba9259cd6 100644 --- a/parameter/EnumParameterType.cpp +++ b/parameter/EnumParameterType.cpp @@ -82,7 +82,8 @@ void CEnumParameterType::showProperties(string& strResult) const bool CEnumParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Size in bits - uint32_t uiSizeInBits = xmlElement.getAttributeInteger("Size"); + uint32_t uiSizeInBits; + xmlElement.getAttribute("Size", uiSizeInBits); // Size setSize(uiSizeInBits / 8); @@ -345,7 +346,7 @@ bool CEnumParameterType::isValid(int iNumerical, CParameterAccessContext& parame void CEnumParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Size - xmlElement.setAttributeString("Size", CUtility::toString(getSize() * 8)); + xmlElement.setAttribute("Size", getSize() * 8); base::toXml(xmlElement, serializingContext); } diff --git a/parameter/EnumValuePair.cpp b/parameter/EnumValuePair.cpp index 35f4cd236..383babb53 100644 --- a/parameter/EnumValuePair.cpp +++ b/parameter/EnumValuePair.cpp @@ -59,10 +59,12 @@ string CEnumValuePair::getNumericalAsString() const bool CEnumValuePair::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Literal - setName(xmlElement.getAttributeString("Literal")); + std::string name; + xmlElement.getAttribute("Literal", name); + setName(name); // Numerical - _iNumerical = xmlElement.getAttributeSignedInteger("Numerical"); + xmlElement.getAttribute("Numerical", _iNumerical); // Base return base::fromXml(xmlElement, serializingContext); @@ -80,10 +82,10 @@ void CEnumValuePair::logValue(string& strValue, CErrorContext& errorContext) con void CEnumValuePair::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Literal - xmlElement.setAttributeString("Literal", this->getName()); + xmlElement.setAttribute("Literal", this->getName()); // Numerical - xmlElement.setAttributeString("Numerical", getNumericalAsString()); + xmlElement.setAttribute("Numerical", getNumericalAsString()); base::toXml(xmlElement, serializingContext); } diff --git a/parameter/FileIncluderElementBuilder.h b/parameter/FileIncluderElementBuilder.h deleted file mode 100644 index bccb227e4..000000000 --- a/parameter/FileIncluderElementBuilder.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 "ElementBuilder.h" -#include "XmlFileIncluderElement.h" - -/** This is the XmlFileIncluderElement builder class - * - * It is builds the XmlFileIncluderElement with - * a mandatory option specific to xml: - * whether it should be validated with schemas or not - */ -class CFileIncluderElementBuilder : public CElementBuilder -{ -public: - CFileIncluderElementBuilder(bool bValidateWithSchemas) : - CElementBuilder(), - _bValidateWithSchemas(bValidateWithSchemas) - {} - - virtual CElement *createElement(const CXmlElement &xmlElement) const - { - return new CXmlFileIncluderElement(xmlElement.getNameAttribute(), - xmlElement.getType(), _bValidateWithSchemas); - } - -private: - bool _bValidateWithSchemas; -}; diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp index 5189a0719..a1d438c99 100644 --- a/parameter/FixedPointParameterType.cpp +++ b/parameter/FixedPointParameterType.cpp @@ -85,7 +85,7 @@ void CFixedPointParameterType::handleValueSpaceAttribute(CXmlElement& xmlConfigu // Provide value space only if not the default one if (configurationAccessContext.valueSpaceIsRaw()) { - xmlConfigurableElementSettingsElement.setAttributeString("ValueSpace", "Raw"); + xmlConfigurableElementSettingsElement.setAttribute("ValueSpace", "Raw"); } } } @@ -93,16 +93,22 @@ void CFixedPointParameterType::handleValueSpaceAttribute(CXmlElement& xmlConfigu bool CFixedPointParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Size - uint32_t uiSizeInBits = xmlElement.getAttributeInteger("Size"); + uint32_t uiSizeInBits; + xmlElement.getAttribute("Size", uiSizeInBits); // Q notation - _uiIntegral = xmlElement.getAttributeInteger("Integral"); - _uiFractional = xmlElement.getAttributeInteger("Fractional"); + xmlElement.getAttribute("Integral", _uiIntegral); + xmlElement.getAttribute("Fractional", _uiFractional); // Size vs. Q notation integrity check if (uiSizeInBits < getUtilSizeInBits()) { - serializingContext.setError("Inconsistent Size vs. Q notation for " + getKind() + " " + xmlElement.getPath() + ": Summing (Integral + _uiFractional + 1) should not exceed given Size (" + xmlElement.getAttributeString("Size") + ")"); + std::string size; + xmlElement.getAttribute("Size", size); + serializingContext.setError( + "Inconsistent Size vs. Q notation for " + getKind() + " " + xmlElement.getPath() + + ": Summing (Integral + _uiFractional + 1) should not exceed given Size (" + + size + ")"); return false; } @@ -364,13 +370,13 @@ double CFixedPointParameterType::binaryQnmToDouble(int32_t iValue) const void CFixedPointParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Size - xmlElement.setAttributeString("Size", CUtility::toString(getSize() * 8)); + xmlElement.setAttribute("Size", getSize() * 8); // Integral - xmlElement.setAttributeString("Integral", CUtility::toString(_uiIntegral)); + xmlElement.setAttribute("Integral", _uiIntegral); // Fractional - xmlElement.setAttributeString("Fractional", CUtility::toString(_uiFractional)); + xmlElement.setAttribute("Fractional", _uiFractional); base::toXml(xmlElement, serializingContext); } diff --git a/parameter/FrameworkConfigurationLocation.cpp b/parameter/FrameworkConfigurationLocation.cpp deleted file mode 100644 index 6983f160a..000000000 --- a/parameter/FrameworkConfigurationLocation.cpp +++ /dev/null @@ -1,90 +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 "FrameworkConfigurationLocation.h" -#include - -#define base CKindElement - -CFrameworkConfigurationLocation::CFrameworkConfigurationLocation(const std::string& strName, const std::string& strKind) : base(strName, strKind) -{ -} - -// From IXmlSink -bool CFrameworkConfigurationLocation::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) -{ - _strPath = xmlElement.getAttributeString("Path"); - - if (_strPath.empty()) { - - serializingContext.setError("Empty Path attribute in element " + xmlElement.getPath()); - - return false; - } - return true; -} - -// File path -std::string CFrameworkConfigurationLocation::getFilePath(const std::string& strBaseFolder) const -{ - if (isPathRelative()) { - - return strBaseFolder + "/" + _strPath; - } - return _strPath; -} - -// Folder path -std::string CFrameworkConfigurationLocation::getFolderPath(const std::string& strBaseFolder) const -{ - uint32_t uiSlashPos = _strPath.rfind('/', -1); - - if (isPathRelative()) { - - if (uiSlashPos != (uint32_t)-1) { - - return strBaseFolder + "/" + _strPath.substr(0, uiSlashPos); - - } else { - - return strBaseFolder; - } - } else { - - assert(uiSlashPos != (uint32_t)-1); - - return _strPath.substr(0, uiSlashPos); - } -} - -// Detect relative path -bool CFrameworkConfigurationLocation::isPathRelative() const -{ - return _strPath[0] != '/'; -} diff --git a/parameter/FrameworkConfigurationLocation.h b/parameter/FrameworkConfigurationLocation.h deleted file mode 100644 index 56cc5f6e8..000000000 --- a/parameter/FrameworkConfigurationLocation.h +++ /dev/null @@ -1,55 +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. - */ -#pragma once - -#include "KindElement.h" - -#include - -class CFrameworkConfigurationLocation : public CKindElement -{ -public: - CFrameworkConfigurationLocation(const std::string& strName, const std::string& strKind); - - // File path - std::string getFilePath(const std::string& strBaseFolder) const; - - // Folder path - std::string getFolderPath(const std::string& strBaseFolder) const; - - // From IXmlSink - virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); -private: - // Detect relative path - bool isPathRelative() const; - - // Path - std::string _strPath; -}; diff --git a/parameter/IntegerParameterType.cpp b/parameter/IntegerParameterType.cpp index 2d48d53c2..2677c987b 100644 --- a/parameter/IntegerParameterType.cpp +++ b/parameter/IntegerParameterType.cpp @@ -93,15 +93,17 @@ void CIntegerParameterType::showProperties(string& strResult) const bool CIntegerParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // Sign - _bSigned = xmlElement.getAttributeBoolean("Signed"); + xmlElement.getAttribute("Signed", _bSigned); // Size in bits - uint32_t uiSizeInBits = xmlElement.getAttributeInteger("Size"); + uint32_t uiSizeInBits = 0; + xmlElement.getAttribute("Size", uiSizeInBits); // Size setSize(uiSizeInBits / 8); // Min / Max + // TODO: Make IntegerParameter template if (_bSigned) { // Signed means we have one less util bit @@ -109,7 +111,9 @@ bool CIntegerParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializi if (xmlElement.hasAttribute("Min")) { - _uiMin = (uint32_t)xmlElement.getAttributeSignedInteger("Min"); + int min = 0; + xmlElement.getAttribute("Min", min); + _uiMin = (uint32_t) min; } else { _uiMin = 1UL << uiSizeInBits; @@ -119,7 +123,9 @@ bool CIntegerParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializi if (xmlElement.hasAttribute("Max")) { - _uiMax = (uint32_t)xmlElement.getAttributeSignedInteger("Max"); + int max = 0; + xmlElement.getAttribute("Max", max); + _uiMax = (uint32_t) max; signExtend((int32_t&)_uiMax); } else { @@ -129,14 +135,14 @@ bool CIntegerParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializi } else { if (xmlElement.hasAttribute("Min")) { - _uiMin = xmlElement.getAttributeInteger("Min"); + xmlElement.getAttribute("Min", _uiMin); } else { _uiMin = 0; } if (xmlElement.hasAttribute("Max")) { - _uiMax = xmlElement.getAttributeInteger("Max"); + xmlElement.getAttribute("Max", _uiMax); } else { _uiMax = (uint32_t)-1L >> (8 * sizeof(uint32_t) - uiSizeInBits); @@ -435,27 +441,27 @@ const CParameterAdaptation* CIntegerParameterType::getParameterAdaptation() cons void CIntegerParameterType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { // Sign - xmlElement.setAttributeBoolean("Signed", _bSigned); + xmlElement.setAttribute("Signed", _bSigned); if (_bSigned) { // Mininmum - xmlElement.setAttributeString("Min", CUtility::toString((int32_t)_uiMin)); + xmlElement.setAttribute("Min", (int32_t)_uiMin); // Maximum - xmlElement.setAttributeString("Max", CUtility::toString((int32_t)_uiMax)); + xmlElement.setAttribute("Max", (int32_t)_uiMax); } else { // Minimum - xmlElement.setAttributeString("Min", CUtility::toString(_uiMin)); + xmlElement.setAttribute("Min", _uiMin); // Maximum - xmlElement.setAttributeString("Max", CUtility::toString(_uiMax)); + xmlElement.setAttribute("Max", _uiMax); } // Size - xmlElement.setAttributeString("Size", CUtility::toString(getSize() * 8)); + xmlElement.setAttribute("Size", getSize() * 8); base::toXml(xmlElement, serializingContext); diff --git a/parameter/KindElement.h b/parameter/KindElement.h deleted file mode 100644 index df826ffe3..000000000 --- a/parameter/KindElement.h +++ /dev/null @@ -1,50 +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. - */ -#pragma once - -#include "Element.h" - -#include - -class CKindElement : public CElement -{ -public: - CKindElement(const std::string& strName, const std::string& strKind) : CElement(strName), _strKind(strKind) - { - } - - virtual std::string getKind() const - { - return _strKind; - } -private: - - std::string _strKind; -}; diff --git a/parameter/KindElementBuilderTemplate.h b/parameter/KindElementBuilderTemplate.h deleted file mode 100644 index dc576dbe1..000000000 --- a/parameter/KindElementBuilderTemplate.h +++ /dev/null @@ -1,44 +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. - */ -#pragma once - -#include "ElementBuilder.h" - -template -class TKindElementBuilderTemplate : public CElementBuilder -{ -public: - TKindElementBuilderTemplate() : CElementBuilder() {} - - virtual CElement* createElement(const CXmlElement& xmlElement) const - { - return new ElementType(xmlElement.getNameAttribute(), xmlElement.getType()); - } -}; diff --git a/parameter/LinearParameterAdaptation.cpp b/parameter/LinearParameterAdaptation.cpp index ae925a74a..455947839 100644 --- a/parameter/LinearParameterAdaptation.cpp +++ b/parameter/LinearParameterAdaptation.cpp @@ -65,7 +65,7 @@ bool CLinearParameterAdaptation::fromXml(const CXmlElement& xmlElement, CXmlSeri // Get SlopeNumerator if (xmlElement.hasAttribute("SlopeNumerator")) { - _dSlopeNumerator = xmlElement.getAttributeDouble("SlopeNumerator"); + xmlElement.getAttribute("SlopeNumerator", _dSlopeNumerator); } else { // Default @@ -74,7 +74,7 @@ bool CLinearParameterAdaptation::fromXml(const CXmlElement& xmlElement, CXmlSeri // Get SlopeDenominator if (xmlElement.hasAttribute("SlopeDenominator")) { - _dSlopeDenominator = xmlElement.getAttributeDouble("SlopeDenominator"); + xmlElement.getAttribute("SlopeDenominator", _dSlopeDenominator); // Avoid by 0 division errors if (_dSlopeDenominator == 0) { diff --git a/parameter/LogarithmicParameterAdaptation.cpp b/parameter/LogarithmicParameterAdaptation.cpp index bca494834..0c1bd7eb5 100644 --- a/parameter/LogarithmicParameterAdaptation.cpp +++ b/parameter/LogarithmicParameterAdaptation.cpp @@ -59,7 +59,7 @@ bool CLogarithmicParameterAdaptation::fromXml(const CXmlElement& xmlElement, if (xmlElement.hasAttribute("LogarithmBase")) { - _dLogarithmBase = xmlElement.getAttributeDouble("LogarithmBase"); + xmlElement.getAttribute("LogarithmBase", _dLogarithmBase); // Avoid negative and 1 values if (_dLogarithmBase <= 0 || _dLogarithmBase == 1) { @@ -71,7 +71,7 @@ bool CLogarithmicParameterAdaptation::fromXml(const CXmlElement& xmlElement, } if (xmlElement.hasAttribute("FloorValue")) { - _dFloorValue = xmlElement.getAttributeDouble("FloorValue"); + xmlElement.getAttribute("FloorValue", _dFloorValue); } // Base return base::fromXml(xmlElement, serializingContext); diff --git a/parameter/ParameterAdaptation.cpp b/parameter/ParameterAdaptation.cpp index 99955f144..3a15bac62 100644 --- a/parameter/ParameterAdaptation.cpp +++ b/parameter/ParameterAdaptation.cpp @@ -69,7 +69,7 @@ bool CParameterAdaptation::fromXml(const CXmlElement& xmlElement, CXmlSerializin // Get offset if (xmlElement.hasAttribute("Offset")) { - _iOffset = xmlElement.getAttributeSignedInteger("Offset"); + xmlElement.getAttribute("Offset", _iOffset); } else { // Default diff --git a/parameter/ParameterFrameworkConfiguration.cpp b/parameter/ParameterFrameworkConfiguration.cpp deleted file mode 100644 index 3488454ea..000000000 --- a/parameter/ParameterFrameworkConfiguration.cpp +++ /dev/null @@ -1,81 +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 "ParameterFrameworkConfiguration.h" - -#define base CElement - -CParameterFrameworkConfiguration::CParameterFrameworkConfiguration() - : _bTuningAllowed(false), _uiServerPort(0) -{ -} - -std::string CParameterFrameworkConfiguration::getKind() const -{ - return "ParameterFrameworkConfiguration"; -} - -bool CParameterFrameworkConfiguration::childrenAreDynamic() const -{ - return true; -} - -// System class name -const std::string& CParameterFrameworkConfiguration::getSystemClassName() const -{ - return _strSystemClassName; -} - -// Tuning allowed -bool CParameterFrameworkConfiguration::isTuningAllowed() const -{ - return _bTuningAllowed; -} - -// Server port -uint16_t CParameterFrameworkConfiguration::getServerPort() const -{ - return _uiServerPort; -} - -// From IXmlSink -bool CParameterFrameworkConfiguration::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) -{ - // System class name - _strSystemClassName = xmlElement.getAttributeString("SystemClassName"); - - // Tuning allowed - _bTuningAllowed = xmlElement.getAttributeBoolean("TuningAllowed"); - - // Server port - _uiServerPort = (uint16_t)xmlElement.getAttributeInteger("ServerPort"); - - // Base - return base::fromXml(xmlElement, serializingContext); -} diff --git a/parameter/ParameterFrameworkConfiguration.h b/parameter/ParameterFrameworkConfiguration.h deleted file mode 100644 index a2617754b..000000000 --- a/parameter/ParameterFrameworkConfiguration.h +++ /dev/null @@ -1,62 +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. - */ -#pragma once - -#include "Element.h" - -#include - -class CParameterFrameworkConfiguration : public CElement -{ -public: - CParameterFrameworkConfiguration(); - - // System class name - const std::string& getSystemClassName() const; - - // Tuning allowed - bool isTuningAllowed() const; - - // Server port - uint16_t getServerPort() const; - - // From IXmlSink - virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); -private: - virtual std::string getKind() const; - virtual bool childrenAreDynamic() const; - - // System class name - std::string _strSystemClassName; - // Tuning allowed - bool _bTuningAllowed; - // Server port - uint16_t _uiServerPort; -}; diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp index eb3a53b3b..cf793bb22 100644 --- a/parameter/ParameterMgr.cpp +++ b/parameter/ParameterMgr.cpp @@ -33,10 +33,8 @@ #include "ElementLibrarySet.h" #include "SubsystemLibrary.h" #include "NamedElementBuilderTemplate.h" -#include "KindElementBuilderTemplate.h" #include "ElementBuilderTemplate.h" #include "SubsystemElementBuilder.h" -#include "FileIncluderElementBuilder.h" #include "ComponentType.h" #include "ComponentInstance.h" #include "ParameterBlockType.h" @@ -46,10 +44,6 @@ #include "ParameterBlackboard.h" #include "Parameter.h" #include "ParameterAccessContext.h" -#include "FrameworkConfigurationGroup.h" -#include "PluginLocation.h" -#include "SubsystemPlugins.h" -#include "FrameworkConfigurationLocation.h" #include "ConfigurableDomain.h" #include "DomainConfiguration.h" #include "XmlDomainSerializingContext.h" @@ -78,6 +72,8 @@ #include "XmlMemoryDocSink.h" #include "XmlDocSource.h" #include "XmlMemoryDocSource.h" +#include +#include "bindings/xml/ConfigurationBinder.h" #include "Utility.h" #include #include @@ -116,9 +112,6 @@ using namespace core::criterion::internal; // Used for remote processor server creation typedef IRemoteProcessorServerInterface* (*CreateRemoteProcessorServer)(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler); -// Global Schemas folder (fixed) -const char* gacSystemSchemasSubFolder = "Schemas"; - // Config File System looks normally like this: // --------------------------------------------- //|-- .xml @@ -141,8 +134,6 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge _bAutoSyncOn(true), _pMainParameterBlackboard(new CParameterBlackboard), _pElementLibrarySet(new CElementLibrarySet), - _strXmlConfigurationFilePath(strConfigurationFilePath), - _pSubsystemPlugins(NULL), _pvLibRemoteProcessorHandle(NULL), _uiStructureChecksum(0), _pRemoteProcessorServer(NULL), @@ -153,7 +144,7 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge _bFailOnMissingSubsystem(true), _bFailOnFailedSettingsLoad(true), _bValidateSchemasOnStart(false), - _pfwConfiguration(), + _pfwConfiguration(strConfigurationFilePath), _criteria(), _systemClass(_logger), _domains() @@ -162,18 +153,6 @@ CParameterMgr::CParameterMgr(const string& strConfigurationFilePath, log::ILogge // Tuning Mode Mutex bzero(&_blackboardMutex, sizeof(_blackboardMutex)); pthread_mutex_init(&_blackboardMutex, NULL); - - // Configuration file folder - std::string::size_type slashPos = _strXmlConfigurationFilePath.rfind('/', -1); - if(slashPos == std::string::npos) { - // Configuration folder is the current folder - _strXmlConfigurationFolderPath = '.'; - } else { - _strXmlConfigurationFolderPath = _strXmlConfigurationFilePath.substr(0, slashPos); - } - - // Schema absolute folder location - _strSchemaFolderLocation = _strXmlConfigurationFolderPath + "/" + gacSystemSchemasSubFolder; } CParameterMgr::~CParameterMgr() @@ -277,38 +256,20 @@ bool CParameterMgr::load(string& strError) bool CParameterMgr::loadFrameworkConfiguration(string& strError) { LOG_CONTEXT("Loading framework configuration"); - - // Parse Structure XML file - CXmlElementSerializingContext elementSerializingContext(strError); - - _xmlDoc *doc = CXmlDocSource::mkXmlDoc(_strXmlConfigurationFilePath, true, true, strError); - if (doc == NULL) { + try { + using namespace xml::serialization; + bindings::xml::ConfigurationBinder binder{_pfwConfiguration}; + Deserializer test{_pfwConfiguration.configurationFile, + binder.getBindings()}; + } catch (std::runtime_error &e) { + strError = e.what(); + warning() << "While parsing configuration: " << e.what(); return false; } + _systemClass.setName(_pfwConfiguration.systemClassName); + _domains.setName(_pfwConfiguration.systemClassName); - if (!xmlParse(elementSerializingContext, &_pfwConfiguration, doc, - _strXmlConfigurationFolderPath, EFrameworkConfigurationLibrary)) { - - return false; - } - // Set class name to system class and configurable domains - _systemClass.setName(_pfwConfiguration.getSystemClassName()); - _domains.setName(_pfwConfiguration.getSystemClassName()); - - // Get subsystem plugins elements - _pSubsystemPlugins = - static_cast(_pfwConfiguration.findChild("SubsystemPlugins")); - - if (!_pSubsystemPlugins) { - - strError = "Parameter Framework Configuration: couldn't find SubsystemPlugins element"; - - return false; - } - - // Log tuning availability - info() << "Tuning " << (_pfwConfiguration.isTuningAllowed() ? "allowed" : "prohibited"); - + info() << "Tuning " << (_pfwConfiguration.tuningAllowed ? "allowed" : "prohibited"); return true; } @@ -318,7 +279,7 @@ bool CParameterMgr::loadSubsystems(std::string& error) // Load subsystems bool isSuccess = _systemClass.loadSubsystems(error, - _pSubsystemPlugins, + _pfwConfiguration.plugins, !_bFailOnMissingSubsystem); if (isSuccess) { @@ -338,37 +299,18 @@ bool CParameterMgr::loadStructure(string& strError) { LOG_CONTEXT("Loading " + _systemClass.getName() + " system class structure"); - // Get structure description element - const CFrameworkConfigurationLocation* pStructureDescriptionFileLocation = - static_cast( - _pfwConfiguration.findChildOfKind("StructureDescriptionFileLocation")); - - if (!pStructureDescriptionFileLocation) { - - strError = "No StructureDescriptionFileLocation element found for SystemClass " + - _systemClass.getName(); - - return false; - } - - // Get Xml structure folder - string strXmlStructureFolder = pStructureDescriptionFileLocation->getFolderPath(_strXmlConfigurationFolderPath); - - // Get Xml structure file name - string strXmlStructureFilePath = pStructureDescriptionFileLocation->getFilePath(_strXmlConfigurationFolderPath); - // Parse Structure XML file CXmlParameterSerializingContext parameterBuildContext(strError); { - LOG_CONTEXT("Importing system structure from file " + strXmlStructureFilePath); + LOG_CONTEXT("Importing system structure from file " + _pfwConfiguration.structureFile); - _xmlDoc *doc = CXmlDocSource::mkXmlDoc(strXmlStructureFilePath, true, true, strError); + _xmlDoc *doc = CXmlDocSource::mkXmlDoc(_pfwConfiguration.structureFile, true, true, strError); if (doc == NULL) { return false; } - if (!xmlParse(parameterBuildContext, &_systemClass, doc, strXmlStructureFolder, EParameterCreationLibrary)) { + if (!xmlParse(parameterBuildContext, &_systemClass, doc, EParameterCreationLibrary)) { return false; } @@ -408,63 +350,31 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) { LOG_CONTEXT("Loading settings"); - // Get settings configuration element - const CFrameworkConfigurationGroup* pParameterConfigurationGroup = - static_cast( - _pfwConfiguration.findChildOfKind("SettingsConfiguration")); - - if (!pParameterConfigurationGroup) { - - // No settings to load - + if (_pfwConfiguration.settingsFile.empty()) { + // Not settings to load return true; } - // Get binary settings file location - const CFrameworkConfigurationLocation* pBinarySettingsFileLocation = static_cast(pParameterConfigurationGroup->findChildOfKind("BinarySettingsFileLocation")); - - string strXmlBinarySettingsFilePath; - - if (pBinarySettingsFileLocation) { - - // Get Xml binary settings file name - strXmlBinarySettingsFilePath = pBinarySettingsFileLocation->getFilePath(_strXmlConfigurationFolderPath); - } - - // Get configurable domains element - const CFrameworkConfigurationLocation* pConfigurableDomainsFileLocation = static_cast(pParameterConfigurationGroup->findChildOfKind("ConfigurableDomainsFileLocation")); - - if (!pConfigurableDomainsFileLocation) { - - strError = "No ConfigurableDomainsFileLocation element found for SystemClass " + - _systemClass.getName(); - - return false; - } - - // Get Xml configuration domains file name - string strXmlConfigurationDomainsFilePath = pConfigurableDomainsFileLocation->getFilePath(_strXmlConfigurationFolderPath); - - // Get Xml configuration domains folder - string strXmlConfigurationDomainsFolder = pConfigurableDomainsFileLocation->getFolderPath(_strXmlConfigurationFolderPath); + bool binarySettingsAvailable = !_pfwConfiguration.binarySettingsFile.empty(); // Parse configuration domains XML file (ask to read settings from XML file if they are not provided as binary) CXmlDomainImportContext xmlDomainImportContext(strError, - !pBinarySettingsFileLocation, + binarySettingsAvailable, _systemClass, _criteria); // Auto validation of configurations if no binary settings provided - xmlDomainImportContext.setAutoValidationRequired(!pBinarySettingsFileLocation); + xmlDomainImportContext.setAutoValidationRequired(binarySettingsAvailable); - info() << "Importing configurable domains from file " << strXmlConfigurationDomainsFilePath - << " " << ( pBinarySettingsFileLocation ? "without" : "with") << " settings"; + info() << "Importing configurable domains from file " << _pfwConfiguration.settingsFile + << " " << ( binarySettingsAvailable ? "without" : "with") << " settings"; - _xmlDoc *doc = CXmlDocSource::mkXmlDoc(strXmlConfigurationDomainsFilePath, true, true, strError); + _xmlDoc *doc = CXmlDocSource::mkXmlDoc(_pfwConfiguration.settingsFile, true, true, strError); if (doc == NULL) { return false; } - if (!xmlParse(xmlDomainImportContext, &_domains, doc, strXmlConfigurationDomainsFolder, EParameterConfigurationLibrary, "SystemClassName")) { + if (!xmlParse(xmlDomainImportContext, &_domains, doc, + EParameterConfigurationLibrary, "SystemClassName")) { return false; } @@ -473,8 +383,8 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) _domains.computeStructureChecksum(); // Load binary settings if any provided - if (pBinarySettingsFileLocation && !_domains.serializeSettings( - strXmlBinarySettingsFilePath, false, _uiStructureChecksum, strError)) { + if (binarySettingsAvailable && !_domains.serializeSettings( + _pfwConfiguration.binarySettingsFile, false, _uiStructureChecksum, strError)) { return false; } @@ -484,17 +394,16 @@ bool CParameterMgr::loadSettingsFromConfigFile(string& strError) // XML parsing bool CParameterMgr::xmlParse(CXmlElementSerializingContext& elementSerializingContext, - CElement* pRootElement, _xmlDoc* doc, - const string& strXmlFolder, + CElement* pRootElement, + _xmlDoc* doc, CParameterMgr::ElementLibrary eElementLibrary, const string& strNameAttributeName) { // Init serializing context - elementSerializingContext.set(_pElementLibrarySet->getElementLibrary( - eElementLibrary), strXmlFolder, _strSchemaFolderLocation); + elementSerializingContext.set(_pElementLibrarySet->getElementLibrary(eElementLibrary)); // Get Schema file associated to root element - string strXmlSchemaFilePath = _strSchemaFolderLocation + "/" + pRootElement->getKind() + ".xsd"; + string strXmlSchemaFilePath = _pfwConfiguration.schemasLocation + "/" + pRootElement->getKind() + ".xsd"; CXmlDocSource docSource(doc, _bValidateSchemasOnStart, strXmlSchemaFilePath, @@ -629,12 +538,12 @@ bool CParameterMgr::getFailureOnFailedSettingsLoad() const string& CParameterMgr::getSchemaFolderLocation() const { - return _strSchemaFolderLocation; + return _pfwConfiguration.schemasLocation; } void CParameterMgr::setSchemaFolderLocation(const string& strSchemaFolderLocation) { - _strSchemaFolderLocation = strSchemaFolderLocation; + _pfwConfiguration.schemasLocation = strSchemaFolderLocation; } void CParameterMgr::setValidateSchemasOnStart(bool bValidate) @@ -811,7 +720,7 @@ bool CParameterMgr::accessValue(CParameterAccessContext& parameterAccessContext, bool CParameterMgr::setTuningMode(bool bOn, string& strError) { // Tuning allowed? - if (bOn && !_pfwConfiguration.isTuningAllowed()) { + if (bOn && !_pfwConfiguration.tuningAllowed) { strError = "Tuning prohibited"; @@ -1285,7 +1194,8 @@ bool CParameterMgr::wrapLegacyXmlImport(const string& xmlSource, bool fromFile, return false; } - return xmlParse(xmlDomainImportContext, &element, doc, "", EParameterConfigurationLibrary, nameAttributeName); + return xmlParse(xmlDomainImportContext, &element, doc, + EParameterConfigurationLibrary, nameAttributeName); } bool CParameterMgr::serializeElement(std::ostream& output, @@ -1298,13 +1208,13 @@ bool CParameterMgr::serializeElement(std::ostream& output, } // Get Schema file associated to root element - string xmlSchemaFilePath = _strSchemaFolderLocation + "/" + + string strXmlSchemaFilePath = _pfwConfiguration.schemasLocation + "/" + element.getKind() + ".xsd"; // Use a doc source by loading data from instantiated Configurable Domains CXmlMemoryDocSource memorySource(&element, _bValidateSchemasOnStart, element.getKind(), - xmlSchemaFilePath, + strXmlSchemaFilePath, "parameter-framework", getVersion()); @@ -1436,19 +1346,6 @@ CParameterBlackboard* CParameterMgr::getParameterBlackboard() // Dynamic creation library feeding void CParameterMgr::feedElementLibraries() { - // Global Configuration handling - CElementLibrary* pFrameworkConfigurationLibrary = new CElementLibrary; - - pFrameworkConfigurationLibrary->addElementBuilder("ParameterFrameworkConfiguration", new TElementBuilderTemplate()); - pFrameworkConfigurationLibrary->addElementBuilder("SubsystemPlugins", new TKindElementBuilderTemplate()); - pFrameworkConfigurationLibrary->addElementBuilder("Location", new TKindElementBuilderTemplate()); - pFrameworkConfigurationLibrary->addElementBuilder("StructureDescriptionFileLocation", new TKindElementBuilderTemplate()); - pFrameworkConfigurationLibrary->addElementBuilder("SettingsConfiguration", new TKindElementBuilderTemplate()); - pFrameworkConfigurationLibrary->addElementBuilder("ConfigurableDomainsFileLocation", new TKindElementBuilderTemplate()); - pFrameworkConfigurationLibrary->addElementBuilder("BinarySettingsFileLocation", new TKindElementBuilderTemplate()); - - _pElementLibrarySet->addElementLibrary(pFrameworkConfigurationLibrary); - // Parameter creation CElementLibrary* pParameterCreationLibrary = new CElementLibrary; @@ -1467,7 +1364,6 @@ void CParameterMgr::feedElementLibraries() pParameterCreationLibrary->addElementBuilder("EnumParameter", new TNamedElementBuilderTemplate()); pParameterCreationLibrary->addElementBuilder("ValuePair", new TElementBuilderTemplate()); pParameterCreationLibrary->addElementBuilder("FixedPointParameter", new TNamedElementBuilderTemplate()); - pParameterCreationLibrary->addElementBuilder("SubsystemInclude", new CFileIncluderElementBuilder(_bValidateSchemasOnStart)); _pElementLibrarySet->addElementLibrary(pParameterCreationLibrary); @@ -1503,7 +1399,7 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) } // Start server if tuning allowed - if (_pfwConfiguration.isTuningAllowed()) { + if (_pfwConfiguration.tuningAllowed) { info() << "Loading remote processor library"; @@ -1538,17 +1434,17 @@ bool CParameterMgr::handleRemoteProcessingInterface(string& strError) _commandParser = ParserWrapper{ new command::Parser(*this) }; // Create server _pRemoteProcessorServer = - pfnCreateRemoteProcessorServer(_pfwConfiguration.getServerPort(), + pfnCreateRemoteProcessorServer(_pfwConfiguration.serverPort, _commandParser->getCommandHandler()); - info() << "Starting remote processor server on port " << _pfwConfiguration.getServerPort(); + info() << "Starting remote processor server on port " << _pfwConfiguration.serverPort; // Start if (!_pRemoteProcessorServer->start(strError)) { ostringstream oss; oss << "ParameterMgr: Unable to start remote processor server on port " - << _pfwConfiguration.getServerPort(); - strError = oss.str() + ": " + strError; + << _pfwConfiguration.serverPort; + strError = oss.str(); return false; } diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h index 5432415b8..1d7b48b9c 100644 --- a/parameter/ParameterMgr.h +++ b/parameter/ParameterMgr.h @@ -40,8 +40,8 @@ #include "XmlDocSource.h" #include "XmlDomainExportContext.h" #include "Results.h" -#include "ParameterFrameworkConfiguration.h" #include "criterion/Criteria.h" +#include "Configuration.h" #include "ConfigurableDomains.h" #include "SystemClass.h" #include @@ -58,14 +58,12 @@ class CSubsystemLibrary; class CParameterBlackboard; class IRemoteProcessorServerInterface; class CParameterHandle; -class CSubsystemPlugins; class CParameterAccessContext; class CConfigurableElement; class CParameterMgr { enum ElementLibrary { - EFrameworkConfigurationLibrary, EParameterCreationLibrary, EParameterConfigurationLibrary }; @@ -419,15 +417,14 @@ class CParameterMgr * @param[in] elementSerializingContext serializing context * @param[out] pRootElement the receiving element * @param[in] input the input XML stream - * @param[in] strXmlFolder the folder containing the XML input file (if applicable) or "" * @param[in] eElementLibrary which element library to be used * @param[in] strNameAttributeName the name of the element's XML "name" attribute * * @returns true if parsing succeeded, false otherwise */ bool xmlParse(CXmlElementSerializingContext& elementSerializingContext, CElement* pRootElement, - _xmlDoc* doc, const std::string& strXmlFolder, - ElementLibrary eElementLibrary, const std::string& strNameAttributeName = "Name"); + _xmlDoc* doc, ElementLibrary eElementLibrary, + const std::string& strNameAttributeName = "Name"); /** Wrapper for converting public APIs semantics to internal API * @@ -554,14 +551,6 @@ class CParameterMgr // Dynamic object creation CElementLibrarySet* _pElementLibrarySet; - // XML parsing, object creation handling - std::string _strXmlConfigurationFilePath; // Configuration file path - std::string _strXmlConfigurationFolderPath; // Root folder for configuration file - std::string _strSchemaFolderLocation; // Place where schemas stand - - // Subsystem plugin location - const CSubsystemPlugins* _pSubsystemPlugins; - /** * Remote processor library handle */ @@ -612,7 +601,7 @@ class CParameterMgr bool _bValidateSchemasOnStart; /** Parameter Configuration information */ - CParameterFrameworkConfiguration _pfwConfiguration; + core::Configuration _pfwConfiguration; /** Selection Criteria used in application rules */ core::criterion::internal::Criteria _criteria; diff --git a/parameter/ParameterType.cpp b/parameter/ParameterType.cpp index eb9fd3dfe..5e0489399 100644 --- a/parameter/ParameterType.cpp +++ b/parameter/ParameterType.cpp @@ -79,7 +79,7 @@ void CParameterType::setUnit(const std::string& strUnit) // From IXmlSink bool CParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { - setUnit(xmlElement.getAttributeString(gUnitPropertyName)); + xmlElement.getAttribute(gUnitPropertyName, _strUnit); return base::fromXml(xmlElement, serializingContext); } @@ -94,7 +94,7 @@ void CParameterType::setXmlUnitAttribute(CXmlElement& xmlElement) const { const string& unit = getUnit(); if (!unit.empty()) { - xmlElement.setAttributeString(gUnitPropertyName, unit); + xmlElement.setAttribute(gUnitPropertyName, unit); } } diff --git a/parameter/PluginLocation.cpp b/parameter/PluginLocation.cpp deleted file mode 100644 index 92f2ce974..000000000 --- a/parameter/PluginLocation.cpp +++ /dev/null @@ -1,69 +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 "PluginLocation.h" - -#define base CKindElement - -CPluginLocation::CPluginLocation(const std::string& strName, const std::string& strKind) : base(strName, strKind) -{ - -} - -const std::string& CPluginLocation::getFolder() const -{ - return _strFolder; -} - -const std::list& CPluginLocation::getPluginList() const -{ - return _pluginList; -} - -bool CPluginLocation::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) -{ - (void) serializingContext; - - // Retrieve folder - _strFolder = xmlElement.getAttributeString("Folder"); - - // Get Info from children - CXmlElement::CChildIterator childIterator(xmlElement); - - CXmlElement xmlPluginElement; - - while (childIterator.next(xmlPluginElement)) { - - // Fill Plugin List - _pluginList.push_back(xmlPluginElement.getAttributeString("Name")); - } - - // Don't dig - return true; -} diff --git a/parameter/SelectionCriterionRule.cpp b/parameter/SelectionCriterionRule.cpp index b0cf33108..fb89f6e30 100644 --- a/parameter/SelectionCriterionRule.cpp +++ b/parameter/SelectionCriterionRule.cpp @@ -133,7 +133,8 @@ bool CSelectionCriterionRule::fromXml(const CXmlElement& xmlElement, CXmlSeriali CXmlDomainImportContext& xmlDomainImportContext = static_cast(serializingContext); // Get selection criterion - string strSelectionCriterion = xmlElement.getAttributeString("SelectionCriterion"); + string strSelectionCriterion; + xmlElement.getAttribute("SelectionCriterion", strSelectionCriterion); _pSelectionCriterion = xmlDomainImportContext.getCriteria().getCriterion(strSelectionCriterion); @@ -147,7 +148,7 @@ bool CSelectionCriterionRule::fromXml(const CXmlElement& xmlElement, CXmlSeriali } // Get MatchesWhen - mMatchesWhenVerb = xmlElement.getAttributeString("MatchesWhen"); + xmlElement.getAttribute("MatchesWhen", mMatchesWhenVerb); string strError; if (!_pSelectionCriterion->isMatchMethodAvailable(mMatchesWhenVerb)) { @@ -160,7 +161,8 @@ bool CSelectionCriterionRule::fromXml(const CXmlElement& xmlElement, CXmlSeriali } // Get Value - string strValue = xmlElement.getAttributeString("Value"); + string strValue; + xmlElement.getAttribute("Value", strValue); if (!setMatchState(strValue)) { @@ -180,13 +182,13 @@ void CSelectionCriterionRule::toXml(CXmlElement& xmlElement, CXmlSerializingCont assert(_pSelectionCriterion); // Set selection criterion - xmlElement.setAttributeString("SelectionCriterion", _pSelectionCriterion->getName()); + xmlElement.setAttribute("SelectionCriterion", _pSelectionCriterion->getName()); // Set MatchesWhen - xmlElement.setAttributeString("MatchesWhen", mMatchesWhenVerb); + xmlElement.setAttribute("MatchesWhen", mMatchesWhenVerb); // Set Value - xmlElement.setAttributeString("Value", mMatchState.empty() ? gEmptyRule : *mMatchState.begin()); + xmlElement.setAttribute("Value", mMatchState.empty() ? gEmptyRule : *mMatchState.begin()); } bool CSelectionCriterionRule::setMatchState(const std::string &value) diff --git a/parameter/StringParameterType.cpp b/parameter/StringParameterType.cpp index 321dc9751..408b24e48 100644 --- a/parameter/StringParameterType.cpp +++ b/parameter/StringParameterType.cpp @@ -60,7 +60,7 @@ void CStringParameterType::showProperties(string& strResult) const bool CStringParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) { // MaxLength - _uiMaxLength = xmlElement.getAttributeInteger("MaxLength"); + xmlElement.getAttribute("MaxLength", _uiMaxLength); // Base return base::fromXml(xmlElement, serializingContext); @@ -81,7 +81,7 @@ uint32_t CStringParameterType::getMaxLength() const void CStringParameterType::toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const { // MaxLength - xmlElement.setAttributeInteger("MaxLength", _uiMaxLength); + xmlElement.setAttribute("MaxLength", _uiMaxLength); base::toXml(xmlElement, serializingContext); } diff --git a/parameter/Subsystem.cpp b/parameter/Subsystem.cpp index 9788a4664..5daa58e04 100644 --- a/parameter/Subsystem.cpp +++ b/parameter/Subsystem.cpp @@ -110,7 +110,9 @@ bool CSubsystem::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& { // Subsystem class does not rely on generic fromXml algorithm of Element class. // So, setting here the description if found as XML attribute. - setDescription(getXmlDescriptionAttribute(xmlElement)); + string description = ""; + xmlElement.getAttribute(gDescriptionPropertyName, description); + setDescription(description); // Context CXmlParameterSerializingContext& parameterBuildContext = static_cast(serializingContext); @@ -121,7 +123,8 @@ bool CSubsystem::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& CXmlElement childElement; // Manage mapping attribute - std::string rawMapping = xmlElement.getAttributeString("Mapping"); + string rawMapping; + xmlElement.getAttribute("Mapping", rawMapping); if (!rawMapping.empty()) { std::string error; diff --git a/parameter/SubsystemLibrary.h b/parameter/SubsystemLibrary.h index 2392b724a..eb35cd6a6 100644 --- a/parameter/SubsystemLibrary.h +++ b/parameter/SubsystemLibrary.h @@ -42,6 +42,8 @@ class CSubsystemLibrary : virtual std::string getBuilderType(const CXmlElement& xmlElement) const { // Xml element's name attribute - return xmlElement.getAttributeString("Type"); + std::string type; + xmlElement.getAttribute("Type", type); + return type; } }; diff --git a/parameter/SubsystemPlugins.h b/parameter/SubsystemPlugins.h deleted file mode 100644 index aa9e32cb1..000000000 --- a/parameter/SubsystemPlugins.h +++ /dev/null @@ -1,48 +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. - */ -#pragma once - -#include "KindElement.h" -#include - -class CSubsystemPlugins : public CKindElement -{ - -public: - CSubsystemPlugins(const std::string& strName, const std::string& strKind) : CKindElement(strName, strKind) - { - } - -private: - virtual bool childrenAreDynamic() const - { - return true; - } -}; diff --git a/parameter/SystemClass.cpp b/parameter/SystemClass.cpp index 51709b7f4..a97af5161 100644 --- a/parameter/SystemClass.cpp +++ b/parameter/SystemClass.cpp @@ -36,7 +36,6 @@ #include "VirtualSubsystem.h" #include "LoggingElementBuilderTemplate.h" #include -#include "PluginLocation.h" #include "Utility.h" #define base CConfigurableElement @@ -98,7 +97,7 @@ string CSystemClass::getKind() const } bool CSystemClass::loadSubsystems(string& strError, - const CSubsystemPlugins* pSubsystemPlugins, + const std::list &pluginsLocation, bool bVirtualSubsystemFallback) { // Start clean @@ -114,7 +113,7 @@ bool CSystemClass::loadSubsystems(string& strError, // Add subsystem defined in shared libraries core::Results errors; - bool bLoadPluginsSuccess = loadSubsystemsFromSharedLibraries(errors, pSubsystemPlugins); + bool bLoadPluginsSuccess = loadSubsystemsFromSharedLibraries(errors, pluginsLocation); // Fill strError for caller, he has to decide if there is a problem depending on // bVirtualSubsystemFallback value @@ -124,36 +123,10 @@ bool CSystemClass::loadSubsystems(string& strError, } bool CSystemClass::loadSubsystemsFromSharedLibraries(core::Results& errors, - const CSubsystemPlugins* pSubsystemPlugins) + std::list pluginsLocation) { - // Plugin list - list lstrPluginFiles; - - uint32_t uiPluginLocation; - - for (uiPluginLocation = 0; uiPluginLocation < pSubsystemPlugins->getNbChildren(); uiPluginLocation++) { - - // Get Folder for current Plugin Location - const CPluginLocation* pPluginLocation = static_cast(pSubsystemPlugins->getChild(uiPluginLocation)); - - string strFolder(pPluginLocation->getFolder()); - if (!strFolder.empty()) { - strFolder += "/"; - } - // Iterator on Plugin List: - list::const_iterator it; - - const list& pluginList = pPluginLocation->getPluginList(); - - for (it = pluginList.begin(); it != pluginList.end(); ++it) { - - // Fill Plugin files list - lstrPluginFiles.push_back(strFolder + *it); - } - } - // Actually load plugins - while (!lstrPluginFiles.empty()) { + while (!pluginsLocation.empty()) { // Because plugins might depend on one another, loading will be done // as an iteration process that finishes successfully when the remaining @@ -161,17 +134,17 @@ bool CSystemClass::loadSubsystemsFromSharedLibraries(core::Results& errors, // process failed to load at least one of them // Attempt to load the complete list - if (!loadPlugins(lstrPluginFiles, errors)) { + if (!loadPlugins(pluginsLocation, errors)) { // Unable to load at least one plugin break; } } - if (!lstrPluginFiles.empty()) { + if (!pluginsLocation.empty()) { // Unable to load at least one plugin string strPluginUnloaded; - CUtility::asString(lstrPluginFiles, strPluginUnloaded, ", "); + CUtility::asString(pluginsLocation, strPluginUnloaded, ", "); errors.push_back("Unable to load the following plugins: " + strPluginUnloaded + "."); return false; @@ -204,15 +177,15 @@ string CSystemClass::getPluginSymbol(const string& strPluginPath) } // Plugin loading -bool CSystemClass::loadPlugins(list& lstrPluginFiles, core::Results& errors) +bool CSystemClass::loadPlugins(std::list &pluginFiles, core::Results& errors) { - assert(lstrPluginFiles.size()); + assert(pluginFiles.size()); bool bAtLeastOneSubsystemPluginSuccessfullyLoaded = false; - list::iterator it = lstrPluginFiles.begin(); + list::iterator it = pluginFiles.begin(); - while (it != lstrPluginFiles.end()) { + while (it != pluginFiles.end()) { string strPluginFileName = *it; @@ -258,7 +231,7 @@ bool CSystemClass::loadPlugins(list& lstrPluginFiles, core::Results& err pfnGetSubsystemBuilder(_pSubsystemLibrary, _logger); // Remove successfully loaded plugin from list and select next - lstrPluginFiles.erase(it++); + pluginFiles.erase(it++); } return bAtLeastOneSubsystemPluginSuccessfullyLoaded; diff --git a/parameter/SystemClass.h b/parameter/SystemClass.h index dccb509a7..145a95dbd 100644 --- a/parameter/SystemClass.h +++ b/parameter/SystemClass.h @@ -30,7 +30,6 @@ #pragma once #include "ConfigurableElement.h" -#include "SubsystemPlugins.h" #include "Results.h" #include #include @@ -41,7 +40,6 @@ class CSubsystemLibrary; class CSystemClass : public CConfigurableElement { public: - /** * @param[in] logger the logger provided by the client * it need to be given to the subsystem library @@ -59,7 +57,7 @@ class CSystemClass : public CConfigurableElement * @return true if the plugins succesfully started or that a fallback is available, false otherwise. */ - bool loadSubsystems(std::string& strError, const CSubsystemPlugins* pSubsystemPlugins, + bool loadSubsystems(std::string& strError, const std::list &pluginsLocation, bool bVirtualSubsystemFallback = false); // Subsystem factory const CSubsystemLibrary* getSubsystemLibrary() const; @@ -98,27 +96,27 @@ class CSystemClass : public CConfigurableElement /** Load shared libraries subsystem plugins. * * @param[out] errors is the list of error that occured during loadings. - * @param[in] pSubsystemPlugins The plugins to load. + * @param[in] pluginsLocation The plugins to load. Plugin's names are intentionnaly copied * * @return true if all plugins have been succesfully loaded, false otherwises. */ bool loadSubsystemsFromSharedLibraries(core::Results& errors, - const CSubsystemPlugins* pSubsystemPlugins); + std::list pluginsLocation); // Plugin symbol computation static std::string getPluginSymbol(const std::string& strPluginPath); /** Load subsystem plugin shared libraries. * - * @param[in:out] lstrPluginFiles is the path list of the plugins shared libraries to load. + * @param[in:out] pluginFiles is the path list of the plugins shared libraries to load. * Successfully loaded plugins are removed from the list. * @param[out] errors is the list of error that occured during loadings. * * @return true if at least one plugin has been succesfully loaded, false otherwise. * When false is returned, some plugins MIHGT have been loaded - * but the lstrPluginFiles is accurate. + * but the pluginFiles is accurate. */ - bool loadPlugins(std::list& lstrPluginFiles, core::Results& errors); + bool loadPlugins(std::list& pluginFiles, core::Results& errors); // Subsystem factory CSubsystemLibrary* _pSubsystemLibrary; diff --git a/parameter/TypeElement.cpp b/parameter/TypeElement.cpp index 7081568e5..3d66b3881 100644 --- a/parameter/TypeElement.cpp +++ b/parameter/TypeElement.cpp @@ -105,12 +105,13 @@ bool CTypeElement::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext // Array Length attribute if (xmlElement.hasAttribute("ArrayLength")) { - _uiArrayLength = xmlElement.getAttributeInteger("ArrayLength"); + xmlElement.getAttribute("ArrayLength", _uiArrayLength); } else { _uiArrayLength = 0; // Scalar } // Manage mapping attribute - std::string rawMapping = xmlElement.getAttributeString("Mapping"); + std::string rawMapping; + xmlElement.getAttribute("Mapping", rawMapping); if (!rawMapping.empty()) { std::string error; @@ -157,7 +158,7 @@ void CTypeElement::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serial { if (!isScalar()) { - xmlElement.setAttributeInteger("ArrayLength", getArrayLength()); + xmlElement.setAttribute("ArrayLength", getArrayLength()); } base::toXml(xmlElement, serializingContext); diff --git a/parameter/XmlElementSerializingContext.cpp b/parameter/XmlElementSerializingContext.cpp index 9fe56f408..3b205d2db 100644 --- a/parameter/XmlElementSerializingContext.cpp +++ b/parameter/XmlElementSerializingContext.cpp @@ -38,11 +38,9 @@ CXmlElementSerializingContext::CXmlElementSerializingContext(string& strError) : } // Init -void CXmlElementSerializingContext::set(const CElementLibrary* pElementLibrary, const string& strXmlFolder, const string& strXmlSchemaFolder) +void CXmlElementSerializingContext::set(const CElementLibrary* pElementLibrary) { _pElementLibrary = pElementLibrary; - _strXmlFolder = strXmlFolder; - _strXmlSchemaFolder = strXmlSchemaFolder; } // ElementLibrary @@ -50,16 +48,3 @@ const CElementLibrary* CXmlElementSerializingContext::getElementLibrary() const { return _pElementLibrary; } - -// XML Folder Path -const string& CXmlElementSerializingContext::getXmlFolder() const -{ - return _strXmlFolder; -} - -// XML Schema Path -const string& CXmlElementSerializingContext::getXmlSchemaPathFolder() const -{ - return _strXmlSchemaFolder; -} - diff --git a/parameter/XmlElementSerializingContext.h b/parameter/XmlElementSerializingContext.h index dadb1dafd..7af084672 100644 --- a/parameter/XmlElementSerializingContext.h +++ b/parameter/XmlElementSerializingContext.h @@ -41,18 +41,10 @@ class CXmlElementSerializingContext : public CXmlSerializingContext CXmlElementSerializingContext(std::string& strError); // Init - void set(const CElementLibrary* pElementLibrary, const std::string& strXmlFolder, const std::string& strXmlSchemaFolder); + void set(const CElementLibrary* pElementLibrary); // ElementLibrary const CElementLibrary* getElementLibrary() const; - - // XML File Path - const std::string& getXmlFolder() const; - - // Schema Path - const std::string& getXmlSchemaPathFolder() const; private: const CElementLibrary* _pElementLibrary; - std::string _strXmlFolder; - std::string _strXmlSchemaFolder; }; diff --git a/parameter/XmlFileIncluderElement.cpp b/parameter/XmlFileIncluderElement.cpp deleted file mode 100644 index 3631f19f7..000000000 --- a/parameter/XmlFileIncluderElement.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2011-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 "XmlFileIncluderElement.h" -#include "XmlDocSource.h" -#include "XmlMemoryDocSink.h" -#include "XmlElementSerializingContext.h" -#include "ElementLibrary.h" -#include -#include - -#define base CKindElement -CXmlFileIncluderElement::CXmlFileIncluderElement(const std::string& strName, - const std::string& strKind, - bool bValidateWithSchemas) - : base(strName, strKind), _bValidateSchemasOnStart(bValidateWithSchemas) -{ -} - -// From IXmlSink -bool CXmlFileIncluderElement::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) -{ - // Context - CXmlElementSerializingContext& elementSerializingContext = static_cast(serializingContext); - - // Parse included document - std::string strPath = xmlElement.getAttributeString("Path"); - - // Relative path? - if (strPath[0] != '/') { - - strPath = elementSerializingContext.getXmlFolder() + "/" + strPath; - } - - // Instantiate parser - std::string strIncludedElementType = getIncludedElementType(); - { - // Use a doc source that load data from a file - std::string strPathToXsdFile = elementSerializingContext.getXmlSchemaPathFolder() + "/" + - strIncludedElementType + ".xsd"; - - std::string xmlErrorMsg; - _xmlDoc *doc = CXmlDocSource::mkXmlDoc(strPath, true, true, xmlErrorMsg); - if (doc == NULL) { - elementSerializingContext.setError(xmlErrorMsg); - return false; - } - - CXmlDocSource docSource(doc, _bValidateSchemasOnStart, - strPathToXsdFile, - strIncludedElementType); - - if (!docSource.isParsable()) { - - elementSerializingContext.setError("Could not parse document \"" + strPath + "\""); - - return false; - } - - // Get top level element - CXmlElement childElement; - - docSource.getRootElement(childElement); - - // Create child element - CElement* pChild = elementSerializingContext.getElementLibrary()->createElement(childElement); - - if (pChild) { - - // Store created child! - getParent()->addChild(pChild); - } else { - - elementSerializingContext.setError("Unable to create XML element " + childElement.getPath()); - - return false; - } - - // Use a doc sink that instantiate the structure from the doc source - CXmlMemoryDocSink memorySink(pChild); - - if (!memorySink.process(docSource, elementSerializingContext)) { - - return false; - } - } - // Detach from parent - getParent()->removeChild(this); - - // Self destroy - delete this; - - return true; -} - -// Element type -std::string CXmlFileIncluderElement::getIncludedElementType() const -{ - std::string strKind = getKind(); - - std::string::size_type pos = strKind.rfind("Include", std::string::npos); - - assert(pos != std::string::npos); - - return strKind.substr(0, pos); -} diff --git a/parameter/XmlFileIncluderElement.h b/parameter/XmlFileIncluderElement.h deleted file mode 100644 index 9163356ca..000000000 --- a/parameter/XmlFileIncluderElement.h +++ /dev/null @@ -1,49 +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. - */ -#pragma once - -#include "KindElement.h" - -#include - -// Class used to parse Include elements -class CXmlFileIncluderElement : public CKindElement -{ -public: - CXmlFileIncluderElement(const std::string& strName, - const std::string& strKind, - bool bValidateWithSchemas); - // From IXmlSink - virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext); -private: - // Element type - std::string getIncludedElementType() const; - bool _bValidateSchemasOnStart; -}; diff --git a/parameter/bindings/xml/ConfigurationBinder.h b/parameter/bindings/xml/ConfigurationBinder.h new file mode 100644 index 000000000..ae01e8511 --- /dev/null +++ b/parameter/bindings/xml/ConfigurationBinder.h @@ -0,0 +1,157 @@ +/* + * 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 + +#include +#include + +namespace core +{ +namespace bindings +{ +namespace xml +{ + +/** Bind an XML configuration file to a Configuration object */ +class ConfigurationBinder +{ +public: + /** @param[in] configuration the reference on the configuration to fill */ + ConfigurationBinder(Configuration &configuration) + : mConfiguration(configuration), mPluginFolder(""), mConfigurationFolder(".") + { + std::string::size_type lastSlashPos = mConfiguration.configurationFile.rfind('/', -1); + if(lastSlashPos != std::string::npos) { + // Configuration folder is not the current folder + mConfigurationFolder = mConfiguration.configurationFile.substr(0, lastSlashPos); + } + mConfiguration.schemasLocation = mConfigurationFolder + "/Schemas"; + } + + + /** Generate Xml bindings for a ParameterFrameworkConfiguration object + * + * return root Node of generated bindings + */ + core::xml::binding::Node getBindings() + { + using namespace core::xml::binding; + Node plugin { + "Plugin", + Body { + Attributes { + { "Name", + Type{}, + [] () { throw std::runtime_error("Unimplemented serialization behavior of" + " ParameterFrameworkConfiguration"); + return ""; }, + [this] (std::string name) { + mConfiguration.plugins.push_back( + mPluginFolder + (mPluginFolder.empty() ? "" : "/") + name); + } + } + }, + Nodes {} + } + }; + Node location { + "Location", + Body { + Attributes { { "Folder", makeBinder(mPluginFolder) } }, + Nodes { plugin } + } + }; + Node subsystemPlugins { "SubsystemPlugins", Body { Attributes {}, Nodes { location } } }; + Node structure { + "StructureDescriptionFileLocation", + Body { Attributes { makePathAttribute(mConfiguration.structureFile) }, Nodes {} } + }; + Node configurableDomains { + "ConfigurableDomainsFileLocation", + Body { Attributes { makePathAttribute(mConfiguration.settingsFile) }, Nodes {} } + }; + Node settingsBinary { + "BinarySettingsFileLocation", + Body { Attributes { makePathAttribute(mConfiguration.binarySettingsFile) }, Nodes {} } + }; + Node settings { + "SettingsConfiguration", + Body { Attributes {}, Nodes { configurableDomains, settingsBinary } } + }; + Node configuration { + "ParameterFrameworkConfiguration", + Body { + Attributes { + { "SystemClassName", makeBinder(mConfiguration.systemClassName) }, + { "ServerPort", makeBinder(mConfiguration.serverPort) }, + { "TuningAllowed", makeBinder(mConfiguration.tuningAllowed) } + }, + Nodes { subsystemPlugins, structure, settings } + } + }; + + return configuration; + } + +private: + /** Helper for Path attribute binding generation + * Prepare, in the setter, the path by adding the configuration folder to any + * relative path. + * + * @return an Attribute which can hold a path + */ + core::xml::binding::Attribute makePathAttribute(std::string &pathSink) + { + using namespace core::xml::binding; + return { "Path", Type{}, + [&pathSink] () { return pathSink; }, + [&pathSink, this] (std::string path) { + if (path[0] != '/') { + // Path is relative + pathSink = mConfigurationFolder + "/" + path; + } + } + }; + } + /** Reference on the Configuration object to fill */ + Configuration &mConfiguration; + + /** Plugin Folder temporary variable */ + std::string mPluginFolder; + + /** Configuration Folder temporary variable */ + std::string mConfigurationFolder; +}; + +} /** xml namespace */ +} /** bindings namespace */ +} /** core namespace */ diff --git a/parameter/criterion/src/Criterion.cpp b/parameter/criterion/src/Criterion.cpp index d269a1df4..579cff007 100644 --- a/parameter/criterion/src/Criterion.cpp +++ b/parameter/criterion/src/Criterion.cpp @@ -185,9 +185,9 @@ std::string Criterion::getFormattedDescription(bool withTypeInfo, bool humanRead void Criterion::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const { (void)serializingContext; - xmlElement.setAttributeString("Value", getFormattedState()); - xmlElement.setAttributeString("Name", mName); - xmlElement.setAttributeString("Kind", getKind()); + xmlElement.setAttribute("Value", getFormattedState()); + xmlElement.setAttribute("Name", mName); + xmlElement.setAttribute("Kind", getKind()); for (auto& value : mValues) { CXmlElement childValueElement; diff --git a/test/functional-tests/xml/configuration/Structure/Test/TestClass.xml b/test/functional-tests/xml/configuration/Structure/Test/TestClass.xml index 480aa057c..7d20d6046 100644 --- a/test/functional-tests/xml/configuration/Structure/Test/TestClass.xml +++ b/test/functional-tests/xml/configuration/Structure/Test/TestClass.xml @@ -1,4 +1,4 @@ - - + + diff --git a/test/test-fixed-point-parameter/TestClass.xml b/test/test-fixed-point-parameter/TestClass.xml index db1b0bc71..5bdaae671 100644 --- a/test/test-fixed-point-parameter/TestClass.xml +++ b/test/test-fixed-point-parameter/TestClass.xml @@ -1,4 +1,4 @@ - - + + diff --git a/utility/CMakeLists.txt b/utility/CMakeLists.txt index d248c6bd3..0d36ec4dd 100644 --- a/utility/CMakeLists.txt +++ b/utility/CMakeLists.txt @@ -37,4 +37,5 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") install(FILES Utility.h + convert.hpp DESTINATION "include/utility") diff --git a/xmlserializer/CMakeLists.txt b/xmlserializer/CMakeLists.txt index be068c91d..98507b77b 100644 --- a/xmlserializer/CMakeLists.txt +++ b/xmlserializer/CMakeLists.txt @@ -51,7 +51,10 @@ else(NOT LIBXML2_FOUND) endif(NOT XML2_XINCLUDE_SUPPORT) endif(NOT LIBXML2_FOUND) -include_directories(${LIBXML2_INCLUDE_DIR}) +include_directories( + ${LIBXML2_INCLUDE_DIR} + "${PROJECT_SOURCE_DIR}/utility") + target_link_libraries(xmlserializer ${LIBXML2_LIBRARIES}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBXML2_DEFINITIONS}") @@ -62,3 +65,22 @@ install(FILES XmlElement.h XmlSerializingContext.h DESTINATION "include/xmlserializer") + +if(BUILD_TESTING) + find_path(CATCH_HEADER catch.hpp) + include_directories( + ./ + include + ${CATCH_HEADER}) + + # Add unit test + add_executable(xmlBindingUnitTest test/XmlBindingUnitTest.cpp) + + target_link_libraries(xmlBindingUnitTest xmlserializer) + add_test(NAME xmlBindingUnitTest + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test + COMMAND xmlBindingUnitTest) + + # Custom function defined in the top-level CMakeLists + set_test_env(xmlBindingUnitTest) +endif() diff --git a/xmlserializer/XmlDocSource.cpp b/xmlserializer/XmlDocSource.cpp index 90a30acc8..332f810cc 100644 --- a/xmlserializer/XmlDocSource.cpp +++ b/xmlserializer/XmlDocSource.cpp @@ -42,11 +42,13 @@ using std::string; bool CXmlDocSource::_bLibXml2CleanupScheduled; CXmlDocSource::CXmlDocSource(_xmlDoc *pDoc, bool bValidateWithSchema, - _xmlNode *pRootNode) : + _xmlNode *pRootNode, + const std::string& strXmlSchemaFile, + const std::string& strRootElementType) : _pDoc(pDoc), _pRootNode(pRootNode), - _strXmlSchemaFile(""), - _strRootElementType(""), + _strXmlSchemaFile(strXmlSchemaFile), + _strRootElementType(strRootElementType), _strRootElementName(""), _strNameAttributeName(""), _bValidateWithSchema(bValidateWithSchema) @@ -93,7 +95,9 @@ string CXmlDocSource::getRootElementAttributeString(const string& strAttributeNa { CXmlElement topMostElement(_pRootNode); - return topMostElement.getAttributeString(strAttributeName); + string attribute; + topMostElement.getAttribute(strAttributeName, attribute); + return attribute; } _xmlDoc* CXmlDocSource::getDoc() const @@ -101,12 +105,6 @@ _xmlDoc* CXmlDocSource::getDoc() const return _pDoc; } -bool CXmlDocSource::isParsable() const -{ - // Check that the doc has been created - return _pDoc != NULL; -} - bool CXmlDocSource::populate(CXmlSerializingContext& serializingContext) { return validate(serializingContext); @@ -118,7 +116,8 @@ bool CXmlDocSource::validate(CXmlSerializingContext& serializingContext) // Check that the doc has been created if (!_pDoc) { - serializingContext.setError("Could not parse document "); + serializingContext.setError("Could not parse document with Root element: " + + _strRootElementType); return false; } diff --git a/xmlserializer/XmlDocSource.h b/xmlserializer/XmlDocSource.h index e41923e15..a84a22beb 100644 --- a/xmlserializer/XmlDocSource.h +++ b/xmlserializer/XmlDocSource.h @@ -53,8 +53,14 @@ class CXmlDocSource * @param[out] pDoc a pointer to the xml document that will be filled by the class * @param[in] pRootNode a pointer to the root element of the document. * @param[in] bValidateWithSchema a boolean that toggles schema validation + * @param[in] xmlSchemaFile a string containing the path to the schema file + * @param[in] rootElementType a string containing the root element type */ - CXmlDocSource(_xmlDoc* pDoc, bool bValidateWithSchema = false, _xmlNode* pRootNode = NULL); + CXmlDocSource(_xmlDoc* pDoc, + bool bValidateWithSchema = false, + _xmlNode* pRootNode = NULL, + const std::string& xmlSchemaFile = "", + const std::string& rootElementType = ""); /** * Constructor @@ -128,13 +134,6 @@ class CXmlDocSource */ virtual bool validate(CXmlSerializingContext& serializingContext); - /** - * Method that checks that the xml document has been correctly parsed. - * - * @return false if any error occurs during the parsing - */ - virtual bool isParsable() const; - /** * Helper method for creating an xml document from either a file or a * string. @@ -164,6 +163,11 @@ class CXmlDocSource */ static bool _bLibXml2CleanupScheduled; + /** + * Schema file + */ + std::string _strXmlSchemaFile; + private: /** @@ -184,11 +188,6 @@ class CXmlDocSource */ static void schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError); - /** - * Schema file - */ - std::string _strXmlSchemaFile; - /** * Element type info */ diff --git a/xmlserializer/XmlElement.cpp b/xmlserializer/XmlElement.cpp index 425e04104..96a0d0d69 100644 --- a/xmlserializer/XmlElement.cpp +++ b/xmlserializer/XmlElement.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2011-2014, Intel Corporation * All rights reserved. * @@ -30,10 +30,8 @@ #include "XmlElement.h" #include #include -#include using std::string; -using std::ostringstream; CXmlElement::CXmlElement(_xmlNode* pXmlElement) : _pXmlElement(pXmlElement) { @@ -74,7 +72,9 @@ string CXmlElement::getPath() const string CXmlElement::getNameAttribute() const { - return getAttributeString("Name"); + string attribute; + getAttribute("Name", attribute); + return attribute; } bool CXmlElement::hasAttribute(const string& strAttributeName) const @@ -82,55 +82,30 @@ bool CXmlElement::hasAttribute(const string& strAttributeName) const return xmlHasProp(_pXmlElement, (const xmlChar*)strAttributeName.c_str()) != NULL; } -string CXmlElement::getAttributeString(const string &strAttributeName) const +template <> +bool CXmlElement::getAttribute(const string &name, string &value) const { - if (!hasAttribute(strAttributeName)) { - - return ""; + if (!hasAttribute(name)) { + return false; } - xmlChar* pucXmlValue = xmlGetProp((xmlNode*)_pXmlElement, (const xmlChar*)strAttributeName.c_str()); + xmlChar* pucXmlValue = xmlGetProp((xmlNode*)_pXmlElement, (const xmlChar*)name.c_str()); + if (pucXmlValue == NULL) { - return ""; + return false; } - string strValue((const char*)pucXmlValue); + value = (const char*)pucXmlValue; xmlFree(pucXmlValue); - return strValue; + return true; } bool CXmlElement::getAttributeBoolean(const string& strAttributeName, const string& strTrueValue) const { - return getAttributeString(strAttributeName) == strTrueValue; -} - -bool CXmlElement::getAttributeBoolean(const string& strAttributeName) const -{ - string strAttributeValue(getAttributeString(strAttributeName)); - - return strAttributeValue == "true" || strAttributeValue == "1"; -} - -uint32_t CXmlElement::getAttributeInteger(const string &strAttributeName) const -{ - string strAttributeValue(getAttributeString(strAttributeName)); - - return strtoul(strAttributeValue.c_str(), NULL, 0); -} - -int32_t CXmlElement::getAttributeSignedInteger(const string &strAttributeName) const -{ - string strAttributeValue(getAttributeString(strAttributeName)); - - return strtol(strAttributeValue.c_str(), NULL, 0); -} - -double CXmlElement::getAttributeDouble(const string &strAttributeName) const -{ - string strAttributeValue(getAttributeString(strAttributeName)); - - return strtod(strAttributeValue.c_str(), NULL); + string value; + getAttribute(strAttributeName, value); + return value == strTrueValue; } string CXmlElement::getTextContent() const @@ -202,35 +177,21 @@ bool CXmlElement::getParentElement(CXmlElement& parentElement) const return false; } -// Setters -void CXmlElement::setAttributeBoolean(const string& strAttributeName, bool bValue) -{ - setAttributeString(strAttributeName, bValue ? "true" : "false"); -} - - -void CXmlElement::setAttributeString(const string& strAttributeName, const string& strValue) -{ - xmlNewProp(_pXmlElement, BAD_CAST strAttributeName.c_str(), BAD_CAST strValue.c_str()); -} - -void CXmlElement::setAttributeInteger(const string& strAttributeName, uint32_t uiValue) +template <> +void CXmlElement::setAttribute(const string& name, const bool &value) { - ostringstream strStream; - strStream << uiValue; - setAttributeString(strAttributeName, strStream.str()); + setAttribute(name, value ? "true" : "false"); } -void CXmlElement::setAttributeSignedInteger(const string& strAttributeName, int32_t iValue) +template <> +void CXmlElement::setAttribute(const string &name, const string &value) { - ostringstream strStream; - strStream << iValue; - setAttributeString(strAttributeName, strStream.str()); + xmlNewProp(_pXmlElement, BAD_CAST name.c_str(), BAD_CAST value.c_str()); } void CXmlElement::setNameAttribute(const string& strValue) { - setAttributeString("Name", strValue); + setAttribute("Name", strValue); } void CXmlElement::setTextContent(const string& strContent) diff --git a/xmlserializer/XmlElement.h b/xmlserializer/XmlElement.h index afa84386f..4ac6c7403 100644 --- a/xmlserializer/XmlElement.h +++ b/xmlserializer/XmlElement.h @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2011-2014, Intel Corporation * All rights reserved. * @@ -29,8 +29,10 @@ */ #pragma once +#include #include #include +#include struct _xmlNode; struct _xmlDoc; @@ -50,12 +52,25 @@ class CXmlElement std::string getPath() const; std::string getNameAttribute() const; bool hasAttribute(const std::string& strAttributeName) const; + + /** Get attribute + * + * @tparam T the type of the value to retrieve + * @param[in] name The attribute name + * @param[in] value The attribute value + * @return true if success, false otherwise + */ + template + bool getAttribute(const std::string &name, T &value) const + { + std::string rawValue; + if (!getAttribute(name, rawValue)) { + return false; + } + return convertTo(rawValue, value); + } + bool getAttributeBoolean(const std::string& strAttributeName, const std::string& strTrueValue) const; - bool getAttributeBoolean(const std::string& strAttributeName) const; - std::string getAttributeString(const std::string& strAttributeName) const; - uint32_t getAttributeInteger(const std::string& strAttributeName) const; - int32_t getAttributeSignedInteger(const std::string& strAttributeName) const; - double getAttributeDouble(const std::string& strAttributeName) const; std::string getTextContent() const; // Navigation @@ -64,20 +79,22 @@ class CXmlElement size_t getNbChildElements() const; bool getParentElement(CXmlElement& parentElement) const; - // Setters - void setAttributeBoolean(const std::string& strAttributeName, bool bValue); - void setAttributeString(const std::string& strAttributeName, const std::string& strValue); - void setNameAttribute(const std::string& strValue); - void setTextContent(const std::string& strContent); - void setAttributeInteger(const std::string& strAttributeName, uint32_t uiValue); - /** - * Set attribute with signed integer - * - * @param[in] strAttributeName The attribute name - * @param[in] iValue The attribute value + /** Set attribute * + * @tparam T the type of the value to retrieve + * @param[in] name The attribute name + * @param[in] value The attribute value */ - void setAttributeSignedInteger(const std::string& strAttributeName, int32_t iValue); + template + void setAttribute(const std::string& name, const T &value) + { + std::ostringstream stream; + stream << value; + setAttribute(name, stream.str()); + } + + void setNameAttribute(const std::string& strValue); + void setTextContent(const std::string& strContent); // Child creation void createChild(CXmlElement& childElement, const std::string& strType); @@ -98,3 +115,10 @@ class CXmlElement _xmlNode* _pXmlElement; }; + +template <> +bool CXmlElement::getAttribute(const std::string &name, std::string &value) const; +template <> +void CXmlElement::setAttribute(const std::string& name, const std::string &value); +template <> +void CXmlElement::setAttribute(const std::string& name, const bool &value); diff --git a/xmlserializer/XmlMemoryDocSource.cpp b/xmlserializer/XmlMemoryDocSource.cpp index 2929b7972..23725d7ca 100644 --- a/xmlserializer/XmlMemoryDocSource.cpp +++ b/xmlserializer/XmlMemoryDocSource.cpp @@ -40,9 +40,9 @@ CXmlMemoryDocSource::CXmlMemoryDocSource(const IXmlSource* pXmlSource, bool bVal const std::string& strProduct, const std::string& strVersion): base(xmlNewDoc(BAD_CAST "1.0"), bValidateWithSchema, - xmlNewNode(NULL, BAD_CAST strRootElementType.c_str())), + xmlNewNode(NULL, BAD_CAST strRootElementType.c_str()), + strXmlSchemaFile, strRootElementType), _pXmlSource(pXmlSource), - _strXmlSchemaFile(strXmlSchemaFile), _strProduct(strProduct), _strVersion(strVersion) { @@ -74,14 +74,14 @@ bool CXmlMemoryDocSource::populate(CXmlSerializingContext& serializingContext) if (!_strXmlSchemaFile.empty()) { // Schema namespace - docElement.setAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); + docElement.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); // Schema location - docElement.setAttributeString("xsi:noNamespaceSchemaLocation", _strXmlSchemaFile); + docElement.setAttribute("xsi:noNamespaceSchemaLocation", _strXmlSchemaFile); } // Compose the xml document _pXmlSource->toXml(docElement, serializingContext); - return true; + return base::validate(serializingContext); } diff --git a/xmlserializer/XmlMemoryDocSource.h b/xmlserializer/XmlMemoryDocSource.h index bc5fdb587..0a1c356a8 100644 --- a/xmlserializer/XmlMemoryDocSource.h +++ b/xmlserializer/XmlMemoryDocSource.h @@ -77,11 +77,6 @@ class CXmlMemoryDocSource : public CXmlDocSource */ const IXmlSource* _pXmlSource; - /** - * Schema file - */ - std::string _strXmlSchemaFile; - // Product and version info std::string _strProduct; std::string _strVersion; diff --git a/xmlserializer/include/xmlserializer/Attribute.h b/xmlserializer/include/xmlserializer/Attribute.h new file mode 100644 index 000000000..5a0412661 --- /dev/null +++ b/xmlserializer/include/xmlserializer/Attribute.h @@ -0,0 +1,273 @@ +/* + * 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 + +#include +#include +#include +#include +#include +#include + +namespace core +{ +namespace xml +{ +namespace binding +{ + +/** Data member setter to use during deserialization + * + * @tparam the type of the data to retrieve + */ +template using Setter = std::function; +template using Getter = std::function; +template using Binder = std::pair, Setter >; + +/** Helper for accessor/mutator pair creation + * + * @tparam T the type of the attribute to bind + * @param[in] attribute variable to bind + * @return a Binder variable which contains an accessor and a mutator to attribute parameter + */ +template +Binder makeBinder(T &attribute) +{ + return make_pair(Getter([&attribute](){return attribute;}), + Setter([&attribute](T value){attribute = value;})); +} + + +/** Type deduction helper structure + * + * @see Attribute + */ +template struct Type {}; + +// @{ +/** Available type List */ +template<> struct Type { using type = int; }; +template<> struct Type { using type = long; }; +template<> struct Type { using type = long long; }; +template<> struct Type { using type = unsigned; }; +template<> struct Type { using type = short unsigned; }; +template<> struct Type { using type = unsigned long; }; +template<> struct Type { using type = unsigned long long; }; +template<> struct Type { using type = float; }; +template<> struct Type { using type = double; }; +template<> struct Type { using type = long double; }; +template<> struct Type { using type = bool; }; +template<> struct Type { using type = std::string; }; +// @} + +namespace details +{ +/** Attribute Implementation forward declaration */ +template +class AttributeImpl; +} /** details namespace */ + +/** Xml Attribute representation. + * Allows to retrieve the data in an xml file and to set it in the right place + * This is a general facade which allows to store any type of attributes in the same container + * + * @tparam the type of the data to retrieve + */ +class Attribute +{ +public: + + /** Define a complete attribute. An attribute should contains methods to store and retrieves + * data of an Object. This is done using Getter and Setter object. + * + * @tparam[in] Type type of the binded attribute + * @tparam[in] GetterType signature of the getter used to get data from the binded attribute + * @tparam[in] SetterType signature of the setter used to set data in the binded attribute + * + * @param[in] name the name of the corresponding XML attribute + * @param[in] type help structure containing the type of the binded attribute + * C++ cannot deduce the type signature of a lambda, moreover there is no + * 'make_function' method. Using this variable allows to help the compiler + * to deduce the type of getter and setter parameter which will be wrapped + * in Getter and Setter object later. + * This is only syntactic sugar to avoid the type to create Getter and Setter + * object for each attribute. + * @param[in] getter the getter method of the binded data + * @param[in] setter the setter method of the binded data + */ + template + Attribute(const std::string &name, Type &&/**type*/, GetterType &&getter, SetterType &&setter) : + mAttributeImpl{new details::AttributeImpl(name, + Getter(getter), + Setter(setter))} + { + } + + /** Define a complete attribute. An attribute should contains methods to store and retrieves + * data of an Object. This is done using Binder object. + * + * @tparam[in] T type of the binded attribute + * + * @param[in] name the name of the corresponding XML attribute + * @param[in] binder Binder object containing mutator and accessor methods for binded attribute + * @see makeBinder + */ + template + Attribute(const std::string &name, Binder &&binder) : + Attribute(name, Type{}, Getter(binder.first), Setter(binder.second)) + { + } + + + virtual ~Attribute() = default; + + /** Retrieve the attribute name + * + * @return a string containing the name of the attribute + */ + virtual const std::string &getName() const + { + return mAttributeImpl->getName(); + } + + /** Retrieve the raw attribute value + * + * @return a string the raw attribute value + */ + virtual std::string get() const + { + return mAttributeImpl->get(); + } + + /** Set the raw attribute value + * + * @param[in] value the raw attribute value to set + */ + virtual void set(const std::string& value) + { + mAttributeImpl->set(value); + } + +protected: + + /** Default constructor needed by implementenation subclass */ + Attribute() = default; + +private: + + /** Implementation older + * + * shared_ptr is required because unique_ptr can't be copied. + * As Attribute are going to be in lists, there will be a copy + * when initializing through an initializer_list (which always copy) + */ + const std::shared_ptr mAttributeImpl = nullptr; +}; + +namespace details +{ + +/** Effective Attribute implementation class + * Provide a real handling of a particular type of Attribute + * + * @tparam the type of the data contained in the attribute + */ +template +class AttributeImpl : public Attribute +{ +public: + + /** @see Attribute */ + AttributeImpl(const std::string &name, Getter getter, Setter setter) : + mName(name), mGetter(getter), mSetter(setter) + { + } + + virtual const std::string &getName() const override final + { + return mName; + } + + virtual std::string get() const override final + { + return std::to_string(mGetter()); + } + + virtual void set(const std::string &rawValue) override final + { + T value; + if (!convertTo(rawValue, value)) + { + throw std::invalid_argument("Invalid type conversion during '" + + mName + "' attribute set"); + } + mSetter(value); + } + +private: + + /** XML attribute name */ + const std::string mName; + + /** Accessor of the binded variable attribute */ + const Getter mGetter; + + /** Mutator of the binded variable attribute */ + const Setter mSetter; +}; + +template <> +void AttributeImpl::set(const std::string &rawValue) +{ + mSetter(rawValue); +} + +template <> +std::string AttributeImpl::get() const +{ + return mGetter(); +} + +template <> +std::string AttributeImpl::get() const +{ + return mGetter() ? "true" : "false"; +} + +} /** details namespace */ + +/** Renaming commonly used list of attributes types */ +using Attributes = std::list; + +} /** binding namespace */ +} /** xml namespace */ +} /** core namespace */ diff --git a/xmlserializer/include/xmlserializer/Deserializer.h b/xmlserializer/include/xmlserializer/Deserializer.h new file mode 100644 index 000000000..8581fe173 --- /dev/null +++ b/xmlserializer/include/xmlserializer/Deserializer.h @@ -0,0 +1,164 @@ +/* + * 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 "xmlserializer/Node.h" + +#include "XmlSink.h" +#include "XmlDocSource.h" +#include "XmlMemoryDocSink.h" + +namespace core +{ +namespace xml +{ +namespace serialization +{ + +/** Indicates the source of the data + * + * File: the provided source will point to a file + * String: the provided source will point contains the data directly + */ +enum class ImportSource { File, String }; + +/** Allows to deserialize XML data + * + * @tparam sourceType the format used for the source of data + */ +template +class Deserializer : private IXmlSink +{ +public: + + /** Deserialize xml data using a dedicated binding + * + * @param[in] xmlSource holder of the data to deserialize + * if ImportSource is String, + * xmlSource should be a string containing the xml to deserialize + * XIncludes tags are not available, the file must contain all needed data + * if ImportSource is File, + * xmlSource should be a string containing the path to the xml file + * XIncludes tags are processed + * @param[in] rootNode the structure which is binding xml data to the structure in memory + * @param[in] schema XML schema file corresponding to xmlSource + * if empty, XML validity is not checked + */ + Deserializer(const std::string &xmlSource, + binding::Node rootNode, + const std::string &schema = "") + : mCurrentNode(rootNode) + { + std::string error; + CXmlSerializingContext context(error); + + // If a file is used, xincludes can be processed + auto doc = CXmlDocSource::mkXmlDoc(xmlSource, + sourceType == ImportSource::File, + sourceType == ImportSource::File, + error); + + // Validate through schema only if schema path is not empty + CXmlDocSource source(doc, !schema.empty(), schema, rootNode.first); + + CXmlMemoryDocSink sink(this); + if (!sink.process(source, context)) { + throw std::runtime_error(error); + } + } + +private: + + /** Private constructor used to create deserializer for subnodes + * + * @param[in] rootNode the structure which is binding xml data to the structure in memory + */ + Deserializer(binding::Node node) + : mCurrentNode(node) + { + } + + /** Parse an XML element to deserialize it into the desired structure + * + * @param[in] xmlElement current xml node + * @param[out] context error context used to communicate errors to upper layers + * @return true in case of success, false otherwiser + */ + virtual bool fromXml(const CXmlElement& xmlElement, + CXmlSerializingContext& context) override + { + for(auto &attribute : mCurrentNode.second.attributes) { + std::string rawAttribute; + if (xmlElement.hasAttribute(attribute.getName())) { + xmlElement.getAttribute(attribute.getName(), rawAttribute); + try { + attribute.set(rawAttribute); + } catch (std::invalid_argument &e) { + std::string error = "When parsing node '" + mCurrentNode.first + + "': Attribute error '" + attribute.getName() + + "': " + e.what(); + context.setError(error); + return false; + } + } + } + + if (xmlElement.getNbChildElements() != 0) { + CXmlElement::CChildIterator childIterator(xmlElement); + CXmlElement childNode; + while ( childIterator.next(childNode)) { + try + { + // retrieve node and propagate to dedicated deserializer + binding::Node childNodeStruct = + {childNode.getType(), mCurrentNode.second.childs.at(childNode.getType())}; + + Deserializer childSerializer(childNodeStruct); + if (!childSerializer.fromXml(childNode, context)) { + return false; + } + } catch (std::out_of_range &e) { + std::string error = "When parsing node '" + mCurrentNode.first + + "': child node '" + childNode.getType() + "' not found"; + context.setError(error); + return false; + } + } + } + return true; + } + + /** Node parsed by this deserializer */ + binding::Node mCurrentNode; +}; + +} /** serialization namespace */ +} /** xml namespace */ +} /** core namespace */ diff --git a/parameter/FrameworkConfigurationGroup.h b/xmlserializer/include/xmlserializer/Node.h similarity index 74% rename from parameter/FrameworkConfigurationGroup.h rename to xmlserializer/include/xmlserializer/Node.h index e4da5405f..9a95212ee 100644 --- a/parameter/FrameworkConfigurationGroup.h +++ b/xmlserializer/include/xmlserializer/Node.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014, Intel Corporation + * Copyright (c) 2015, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,22 +29,35 @@ */ #pragma once -#include "KindElement.h" +#include "xmlserializer/Attribute.h" +#include #include -class CFrameworkConfigurationGroup : public CKindElement +namespace core { -public: - CFrameworkConfigurationGroup(const std::string& strName, const std::string& strKind) : CKindElement(strName, strKind) - { - } +namespace xml +{ +namespace binding +{ + +/** An xml tag is represented through a simple string */ +using Tag = std::string; -private: - virtual bool childrenAreDynamic() const - { - return true; - } +struct Body; +/** Nodes should be retrieved easily thanks to their tag */ +using Nodes = std::map; +/** Xml Node representation */ +struct Body +{ + Attributes attributes; + Nodes childs; }; + +using Node = std::pair; + +} /** binding namespace */ +} /** xml namespace */ +} /** core namespace */ diff --git a/xmlserializer/include/xmlserializer/Serializer.h b/xmlserializer/include/xmlserializer/Serializer.h new file mode 100644 index 000000000..bf9960a85 --- /dev/null +++ b/xmlserializer/include/xmlserializer/Serializer.h @@ -0,0 +1,122 @@ +/* + * 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 "xmlserializer/Node.h" + +#include "XmlStreamDocSink.h" +#include "XmlMemoryDocSource.h" +#include "XmlSource.h" + +#include +#include +#include + +namespace core +{ +namespace xml +{ +namespace serialization +{ + +/** Allows to serialize XML data */ +class Serializer : private IXmlSource +{ +public: + + /** Serialize XML data using a dedicated binding + * + * @param[out] output destination stream of the generated serialized data + * @param[in] rootNode the structure which is binding XML data to the structure in memory + * @param[in] schema XML schema file corresponding to generated XML + * if empty, XML validity is not checked + */ + Serializer(std::ostream &output, + const binding::Node &rootNode, + const std::string &schemaFile = "") + : mCurrentNode(rootNode) + { + if (!output.good()) { + throw std::runtime_error("When serializing" + rootNode.first + + ": Provided output stream is not valid."); + } + + std::string error; + CXmlSerializingContext context(error); + CXmlMemoryDocSource source(this, !schemaFile.empty(), rootNode.first, + schemaFile, "parameter-framework", ""); + + CXmlStreamDocSink sink(output); + if (!sink.process(source, context)) { + throw std::runtime_error(error); + } + } + +private: + + /** Private constructor used to create serializer for subnodes + * + * @param[in] rootNode the structure which is binding xml data to the structure in memory + */ + Serializer(const binding::Node &node) + : mCurrentNode(node) + { + } + + /** Parse the Node member and modify the current XML node in consequence + * + * @param[in] xmlElement current xml node + * @param[out] context error context used to communicate errors to upper layers + */ + virtual void toXml(CXmlElement& xmlElement, + CXmlSerializingContext& context) const override + { + for(auto &attribute : mCurrentNode.second.attributes) { + xmlElement.setAttribute(attribute.getName(), attribute.get()); + } + + for(auto &child : mCurrentNode.second.childs) { + // Create corresponding child element + CXmlElement xmlChildElement; + xmlElement.createChild(xmlChildElement, child.first); + + // Continue serialization + Serializer childSerializer(child); + childSerializer.toXml(xmlChildElement, context); + } + } + + /** Node parsed by this serializer */ + binding::Node mCurrentNode; +}; + +} /** serialization namespace */ +} /** xml namespace */ +} /** core namespace */ diff --git a/xmlserializer/test/XmlBindingUnitTest.cpp b/xmlserializer/test/XmlBindingUnitTest.cpp new file mode 100644 index 000000000..c15289303 --- /dev/null +++ b/xmlserializer/test/XmlBindingUnitTest.cpp @@ -0,0 +1,498 @@ +/* + * 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. + */ + +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() +#include + +/** Ubuntu keeps using an old catch version where "Method" version of BDD Macros are + * not available. This macro adds this functionality in case that catch version is too old. + */ +#ifndef SCENARIO_METHOD +#define SCENARIO_METHOD(className, name, tags) \ + INTERNAL_CATCH_TEST_CASE_METHOD(className, "Scenario: " name, tags) +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace core::xml::binding; + +template +struct VariableHolder +{ + T get() { return value; } + void set(T newValue){ value = newValue; } + + T value; +}; + +template +class NumericalAttributesTest +{ +public: + void operator()() {} +}; + +template +class NumericalAttributesTest : NumericalAttributesTest +{ +public: + void operator()() + { + numericalAttributeTest(); + + // Base class call + NumericalAttributesTest::operator ()(); + } + +private: + + void getSetValueTest(T value, Attribute &attribute, VariableHolder &holder) + { + WHEN("[" + std::string(typeid(T).name()) + "] Setting a value") + { + attribute.set(std::to_string(value)); + THEN("[" + std::string(typeid(T).name()) + "] The holder should contains this value") + { + CHECK(holder.value == value); + } + WHEN("[" + std::string(typeid(T).name()) + "] Retrieving the value as string") + { + THEN("[" + std::string(typeid(T).name()) + + "] It should match the string which represents the value set") + { + CHECK(attribute.get() == std::to_string(holder.value)); + } + } + } + } + + void testLimits(Attribute &attribute, VariableHolder &holder) + { + WHEN("[" + std::string(typeid(T).name()) + "] Setting the maximum acceptable value") + { + getSetValueTest(std::numeric_limits::lowest(), attribute, holder); + } + WHEN("[" + std::string(typeid(T).name()) + "] Setting the minimum acceptable value") + { + getSetValueTest(std::numeric_limits::max(), attribute, holder); + } + } + + void numericalAttributeTest() + { + GIVEN("[" + std::string(typeid(T).name()) + + "] A Variable holder of a numeric type") + { + VariableHolder holder{0}; + + GIVEN("[" + std::string(typeid(T).name()) + + "] An attribute, created with the Helper, associated to that variable holder") + { + Attribute attribute{"TestedAttributeWithHelper", makeBinder(holder.value)}; + testLimits(attribute, holder); + } + GIVEN("[" + std::string(typeid(T).name()) + + "] An attribute associated to that variable holder") + { + Attribute attribute{"TestedAttribute", + Type{}, + [&holder] () { return holder.get(); }, + [&holder] (T value) { holder.set(value); } }; + testLimits(attribute, holder); + } + } + } +}; + +void booleanAttributeTest(bool booleanValue, Attribute &attribute, VariableHolder holder) +{ + THEN("The holder should contains this value") + { + CHECK(holder.value == booleanValue); + } + WHEN("Retrieving the value as string") + { + THEN("It should match the string which represents the value set") + { + // Implementation define that serialization generates lower case values + CHECK(attribute.get() == (booleanValue ? "true" : "false")); + } + } +} + +SCENARIO("Attribute", "[Xml Binding]") +{ + GIVEN("A list containing numerical type holder") + { + // Missing long long, unsigned long long, long double + NumericalAttributesTest{}(); + } + GIVEN("A string value holder") + { + VariableHolder holder{""}; + GIVEN("An attribute, created with the Helper, associated to that variable holder") + { + Attribute attribute{"StringAttribute", makeBinder(holder.value)}; + WHEN("Setting a string value") + { + const std::string value = "TestValue"; + attribute.set(value); + THEN("The holder should contains this value") + { + CHECK(holder.value == value); + } + WHEN("Retrieving the value as string") + { + THEN("It should match the string which represents the value set") + { + CHECK(attribute.get() == holder.value); + } + } + } + } + } + GIVEN("A boolean value") + { + VariableHolder holder{false}; + GIVEN("An attribute, created with the Helper, associated to that variable holder") + { + Attribute attribute{"BooleanAttribute", makeBinder(holder.value)}; + WHEN("Setting true value") + { + attribute.set("true"); + booleanAttributeTest(true, attribute, holder); + } + WHEN("Setting TRUE value") + { + attribute.set("TRUE"); + booleanAttributeTest(true, attribute, holder); + } + WHEN("Setting 1 (true) value") + { + attribute.set("1"); + booleanAttributeTest(true, attribute, holder); + } + WHEN("Setting false value") + { + attribute.set("false"); + booleanAttributeTest(false, attribute, holder); + } + WHEN("Setting FALSE value") + { + attribute.set("FALSE"); + booleanAttributeTest(false, attribute, holder); + } + WHEN("Setting 0 (false) value") + { + attribute.set("0"); + booleanAttributeTest(false, attribute, holder); + } + WHEN("Setting an invalid value") + { + REQUIRE_THROWS_AS(attribute.set("Et ouais Mec!"), std::invalid_argument); + } + } + } +} + +class SerializerTest +{ +public: + struct FillMe + { + FillMe() {} + FillMe(int integer, std::string string, bool boolean) : + mInteger(integer), mString(string), mBoolean(boolean) + { + } + + bool operator == (const FillMe &fillMe) + { + return mInteger == fillMe.mInteger && + mString == fillMe.mString && + mBoolean == fillMe.mBoolean; + } + + int mInteger = 0; + std::string mString = ""; + bool mBoolean = false; + }; + + struct FillMeBigger : FillMe + { + FillMeBigger() {} + FillMeBigger(int integer, std::string string, bool boolean, double doubleParam) : + FillMe(integer, string, boolean), mDouble(doubleParam) + { + } + FillMeBigger(const FillMe &fillMe, double doubleParam) : + FillMe(fillMe), mDouble(doubleParam) + { + } + + bool operator == (const FillMeBigger &fillMeBigger) + { + return FillMe::operator == (fillMeBigger) && mDouble == fillMeBigger.mDouble; + } + + double mDouble; + }; + + inline void removeWhitespaces(std::string& s) + { + s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end()); + } + + Node getTestBindings(FillMe &toFill) + { + using namespace core::xml::binding; + Node child { + "FillChild", + Body { + Attributes { + { "BooleanAttr", makeBinder(toFill.mBoolean) }, + { "StringAttr", makeBinder(toFill.mString) } + }, + Nodes {} /** empty child tag list */ + } + }; + return Node { + "FillMe", + Body { + Attributes { { "IntegerAttr", makeBinder(toFill.mInteger) } }, + Nodes { child } + } + }; + } + + Node getTestBindings(FillMeBigger &toFill) + { + auto bindings = getTestBindings(dynamic_cast(toFill)); + bindings.second.attributes.emplace_back(Attribute{"DoubleAttr", makeBinder(toFill.mDouble)}); + return bindings; + } + + template + void testDeserialization(const std::string &source, + const FillMe &structRef, + const std::string &schema = "") + { + using namespace core::xml::serialization; + GIVEN("An empty structure") + { + FillMe fillMe{}; + GIVEN("Corresponding bindings") + { + auto bindings = getTestBindings(fillMe); + WHEN("Deserializing the file into the empty structure") + { + THEN("Deserializing goes well, filled structure carry desired information") + { + REQUIRE_NOTHROW(Deserializer(source, bindings, schema)); + CHECK(fillMe == structRef); + } + } + } + } + } + + void testDeserializationError(const std::string &source, const std::string &schema = "") + { + using namespace core::xml::serialization; + GIVEN("An empty structure") + { + FillMe fillMe{}; + GIVEN("Corresponding bindings") + { + auto bindings = getTestBindings(fillMe); + WHEN("Deserializing the file into the empty structure") + { + THEN("Deserializing does not work") + { + REQUIRE_THROWS_AS( + Deserializer(source, bindings, schema), + std::runtime_error); + } + } + } + } + } +}; + +SCENARIO_METHOD(SerializerTest, "Serialization", "[Xml Binding]") +{ + using namespace core::xml::serialization; + GIVEN("A string containing a correct XML") + { + const std::string xmlRef = + R"( + + + )"; + + GIVEN("A reference structure filled with previous XML data") + { + const FillMe structRef{1984, "Et ouais Mec!", true}; + testDeserialization(xmlRef, structRef); + + GIVEN("Corresponding bindings") + { + FillMe structRefCpy{structRef}; + auto bindings = getTestBindings(structRefCpy); + WHEN("Serializing the structure into a valid stream") + { + std::ostringstream output; + THEN("Serialization goes well and stream contains the reference xml file") + { + REQUIRE_NOTHROW(Serializer(output, bindings)); + std::string result{output.str()}; + std::string xmlRefCpy{xmlRef}; + + removeWhitespaces(result); + removeWhitespaces(xmlRefCpy); + + CHECK(xmlRefCpy == result); + CHECK(structRefCpy == structRef); + } + } + WHEN("Serializing the structure into an invalid stream") + { + std::ostream nullStream(0); + THEN("Serialization does not work") + { + REQUIRE_THROWS_AS(Serializer(nullStream, bindings), std::runtime_error); + } + } + } + GIVEN("Invalid bindings in an XML Schema point of view") + { + FillMeBigger structRefCpy{structRef, 13.46}; + auto bindings = getTestBindings(structRefCpy); + WHEN("Serializing the structure into a valid stream") + { + std::ostringstream output; + THEN("Serialization goes well and stream contains the reference xml file") + { + REQUIRE_NOTHROW(Serializer(output, bindings)); + } + } + GIVEN("The XML schema of the XML string") + { + const std::string &xmlSchemaFile = "bindingTest.xsd"; + WHEN("Serializing the structure into a valid stream") + { + std::ostringstream output; + THEN("Serialization does not work") + { + REQUIRE_THROWS_AS(Serializer(output, bindings, xmlSchemaFile), + std::runtime_error); + } + } + } + } + } + } + GIVEN("A string containing an XML with a bad root node") + { + const std::string xmlInvalidNode = + R"( + + + )"; + testDeserializationError(xmlInvalidNode); + } + GIVEN("A string containing an XML with a node not listed in bindings") + { + const std::string xmlInvalidNode = + R"( + + + )"; + testDeserializationError(xmlInvalidNode); + } + GIVEN("A string containing an XML with an invalid attribute value") + { + const std::string xmlInvalidAttribute = + R"( + + + )"; + testDeserializationError(xmlInvalidAttribute); + } + GIVEN("A string containing an invalid XML in the point of view of a schema") + { + const std::string xmlInvalidAttribute = + R"( + + + )"; + GIVEN("A reference structure filled with previous XML data") + { + const FillMe structRef{1984, "Et ouais Mec!", true}; + testDeserialization(xmlInvalidAttribute, structRef); + } + GIVEN("The corresponding XML schema") + { + const std::string &xmlSchemaFile = "bindingTest.xsd"; + testDeserializationError(xmlInvalidAttribute, xmlSchemaFile); + } + } + GIVEN("A file containing a valid xml") + { + const std::string &xmlFile = "valid.xml"; + GIVEN("A reference structure filled with data from the XML file") + { + const FillMe structRef{666666, "Premature optimization is the root of all evil", false}; + testDeserialization(xmlFile, structRef); + } + + GIVEN("The corresponding XML schema") + { + const std::string &xmlSchemaFile = "bindingTest.xsd"; + GIVEN("A reference structure filled with data from the XML file") + { + const FillMe structRef { + 666666, "Premature optimization is the root of all evil", false + }; + testDeserialization(xmlFile, structRef, xmlSchemaFile); + } + } + } +} diff --git a/xmlserializer/test/bindingTest.xsd b/xmlserializer/test/bindingTest.xsd new file mode 100644 index 000000000..d5bea7d4c --- /dev/null +++ b/xmlserializer/test/bindingTest.xsd @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/xmlserializer/test/valid.xml b/xmlserializer/test/valid.xml new file mode 100644 index 000000000..5bb7d7d52 --- /dev/null +++ b/xmlserializer/test/valid.xml @@ -0,0 +1,4 @@ + + + +