diff options
author | David Wagner <david.wagner@intel.com> | 2014-03-05 10:55:15 +0100 |
---|---|---|
committer | Mattijs Korpershoek <mattijsx.korpershoek@intel.com> | 2014-06-24 11:51:18 +0200 |
commit | 01c7495e66caea59165316bc025a69cce1383311 (patch) | |
tree | f7a7b1732f69dfd118f4dc0dc0021eb2b0d13bff /parameter | |
parent | c4dd2ae2f070333da2917a93e30b3557caa38760 (diff) | |
download | external_parameter-framework-01c7495e66caea59165316bc025a69cce1383311.zip external_parameter-framework-01c7495e66caea59165316bc025a69cce1383311.tar.gz external_parameter-framework-01c7495e66caea59165316bc025a69cce1383311.tar.bz2 |
Support context mapping at Subsystem level
BZ: 176942
Add a class (ConfigurableMappingElement) handling the mapping; to be derived by
all classes that can contain mapping. ConfigurableMappingElement derives from
ConfigurableElement. Until now, the only child of ConfigurableElement that
could have mapping was InstanceConfigurableElement (through TypeElement, that
contains all information related to its type).
Now, both InstanceConfigurableElement and Subsystem derive from
ConfigurableMappingElement. That way, Subsystem XML elements can now have a
"Mapping" attribute, propagated to all Elements in the tree. The Subsystem.xsd
schema is updated in that regard.
Only context mapping is relevant at the Subsystem-level (as opposed to
instantiation mapping). If an instantiation mapping is set in the Subsystem,
it is silently ignored.
Change-Id: I3c09959bc5e3d18c5a4d354e498d69cc5489a247
Signed-off-by: David Wagner <david.wagner@intel.com>
Signed-off-by: Mattijs Korpershoek <mattijsx.korpershoek@intel.com>
Diffstat (limited to 'parameter')
-rw-r--r-- | parameter/ConfigurableElementWithMapping.h | 55 | ||||
-rw-r--r-- | parameter/InstanceConfigurableElement.cpp | 2 | ||||
-rw-r--r-- | parameter/InstanceConfigurableElement.h | 6 | ||||
-rw-r--r-- | parameter/Subsystem.cpp | 48 | ||||
-rw-r--r-- | parameter/Subsystem.h | 27 |
5 files changed, 114 insertions, 24 deletions
diff --git a/parameter/ConfigurableElementWithMapping.h b/parameter/ConfigurableElementWithMapping.h new file mode 100644 index 0000000..d241cea --- /dev/null +++ b/parameter/ConfigurableElementWithMapping.h @@ -0,0 +1,55 @@ +/* + * 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 "ConfigurableElement.h" +#include <string> + +/** + * Base class for all Configurable Elements that can have a Mapping attribute. + * + * This class acts as an interface: it doesn't implement anything but only + * declares getMappingData as pure virtual fonction. + */ +class CConfigurableElementWithMapping : public CConfigurableElement { +public: + CConfigurableElementWithMapping(const string& strName) : CConfigurableElement(strName) {} + virtual ~CConfigurableElementWithMapping() {} + + /** + * Get the value associated to a mapping key in the object's mapping + * + * @param[in] strKey the mapping key + * @param[out] pStrValue the associated value + * + * @return true if @p strKey is found in the object's mapping, false if not + */ + virtual bool getMappingData(const std::string& strKey, const std::string*& pStrValue) const = 0; +}; diff --git a/parameter/InstanceConfigurableElement.cpp b/parameter/InstanceConfigurableElement.cpp index 098fe8f..d0e1971 100644 --- a/parameter/InstanceConfigurableElement.cpp +++ b/parameter/InstanceConfigurableElement.cpp @@ -35,7 +35,7 @@ #include "ParameterAccessContext.h" #include <assert.h> -#define base CConfigurableElement +#define base CConfigurableElementWithMapping CInstanceConfigurableElement::CInstanceConfigurableElement(const string& strName, const CTypeElement* pTypeElement) : base(strName), _pTypeElement(pTypeElement), _pSyncer(NULL) { diff --git a/parameter/InstanceConfigurableElement.h b/parameter/InstanceConfigurableElement.h index 7d9298e..78b348c 100644 --- a/parameter/InstanceConfigurableElement.h +++ b/parameter/InstanceConfigurableElement.h @@ -29,14 +29,14 @@ */ #pragma once -#include "ConfigurableElement.h" +#include "ConfigurableElementWithMapping.h" #include "TypeElement.h" class IMapper; class CParameterBlackboard; class CParameterAccessContext; -class CInstanceConfigurableElement : public CConfigurableElement +class CInstanceConfigurableElement : public CConfigurableElementWithMapping { public: enum Type { @@ -53,7 +53,7 @@ public: // Instantiated type const CTypeElement* getTypeElement() const; - bool getMappingData(const string& strKey, const string*& pStrValue) const; + virtual bool getMappingData(const string& strKey, const string*& pStrValue) const; /** * Returns the mapping data associated to the type element of the current diff --git a/parameter/Subsystem.cpp b/parameter/Subsystem.cpp index d4bc7c8..9a550d5 100644 --- a/parameter/Subsystem.cpp +++ b/parameter/Subsystem.cpp @@ -38,9 +38,9 @@ #include <assert.h> #include <sstream> -#define base CConfigurableElement +#define base CConfigurableElementWithMapping -CSubsystem::CSubsystem(const string& strName) : base(strName), _pComponentLibrary(new CComponentLibrary), _pInstanceDefinition(new CInstanceDefinition), _bBigEndian(false) +CSubsystem::CSubsystem(const string& strName) : base(strName), _pComponentLibrary(new CComponentLibrary), _pInstanceDefinition(new CInstanceDefinition), _bBigEndian(false), _pMappingData(NULL) { // Note: A subsystem contains instance components // InstanceDefintion and ComponentLibrary objects are then not chosen to be children @@ -68,6 +68,8 @@ CSubsystem::~CSubsystem() // Order matters! delete _pInstanceDefinition; delete _pComponentLibrary; + + delete _pMappingData; } string CSubsystem::getKind() const @@ -106,6 +108,16 @@ bool CSubsystem::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& CXmlElement childElement; + // Manage mapping attribute + if (xmlElement.hasAttribute("Mapping")) { + + _pMappingData = new CMappingData; + if (!_pMappingData->fromXml(xmlElement, serializingContext)) { + + return false; + } + } + // XML populate ComponentLibrary xmlElement.getChildElement("ComponentLibrary", childElement); @@ -152,7 +164,11 @@ bool CSubsystem::serializeXmlSettings(CXmlElement& xmlConfigurationSettingsEleme bool CSubsystem::mapSubsystemElements(string& strError) { // Default mapping context - _contextStack.push(CMappingContext(_contextMappingKeyArray.size())); + CMappingContext context(_contextMappingKeyArray.size()); + // Add Subsystem-level mapping data, which will be propagated to all children + handleMappingContext(this, context, strError); + + _contextStack.push(context); // Map all instantiated subelements in subsystem uint32_t uiNbChildren = getNbChildren(); @@ -326,20 +342,30 @@ void CSubsystem::addSubsystemObjectFactory(CSubsystemObjectCreator* pSubsystemOb } // Generic error handling from derived subsystem classes -string CSubsystem::getMappingError(const string& strKey, - const string& strMessage, - const CInstanceConfigurableElement* pInstanceConfigurableElement) -const +string CSubsystem::getMappingError( + const string& strKey, + const string& strMessage, + const CConfigurableElementWithMapping* pConfigurableElementWithMapping) const { return getName() + " " + getKind() + " " + "mapping:\n" + strKey + " " + "error: \"" + strMessage + "\" " + - "for element " + pInstanceConfigurableElement->getPath(); + "for element " + pConfigurableElementWithMapping->getPath(); +} + + +bool CSubsystem::getMappingData(const std::string& strKey, const std::string*& pStrValue) const +{ + if (_pMappingData) { + + return _pMappingData->getValue(strKey, pStrValue); + } + return false; } // Mapping generic context handling bool CSubsystem::handleMappingContext( - const CInstanceConfigurableElement* pInstanceConfigurableElement, + const CConfigurableElementWithMapping* pConfigurableElementWithMapping, CMappingContext& context, string& strError) const { @@ -351,11 +377,11 @@ bool CSubsystem::handleMappingContext( const string& strKey = _contextMappingKeyArray[uiItem]; const string* pStrValue; - if (pInstanceConfigurableElement->getMappingData(strKey, pStrValue)) { + if (pConfigurableElementWithMapping->getMappingData(strKey, pStrValue)) { // Assign item to context if (!context.setItem(uiItem, &strKey, pStrValue)) { - strError = getMappingError(strKey, "Already set", pInstanceConfigurableElement); + strError = getMappingError(strKey, "Already set", pConfigurableElementWithMapping); return false; } diff --git a/parameter/Subsystem.h b/parameter/Subsystem.h index 6b15181..a03a2ef 100644 --- a/parameter/Subsystem.h +++ b/parameter/Subsystem.h @@ -30,6 +30,7 @@ #pragma once #include "ConfigurableElement.h" +#include "ConfigurableElementWithMapping.h" #include "Mapper.h" #include "MappingContext.h" #include <stack> @@ -40,8 +41,9 @@ class CComponentLibrary; class CSubsystemObject; class CSubsystemObjectCreator; class CInstanceConfigurableElement; +class CMappingData; -class CSubsystem : public CConfigurableElement, private IMapper +class CSubsystem : public CConfigurableElementWithMapping, private IMapper { // Subsystem objects iterator typedef list<CSubsystemObject*>::const_iterator SubsystemObjectListIterator; @@ -67,6 +69,8 @@ public: // from CElement virtual string getKind() const; + virtual bool getMappingData(const std::string& strKey, const std::string*& pStrValue) const; + /** * Fetch mapping data of an element. * @@ -130,13 +134,14 @@ private: * * @param[in] strKey The key on which the error refers * @param[in] strMessage The error message - * @param[in] pInstanceConfigurableElement The element on wich the error refers + * @param[in] pConfigurableElementWithMapping The element on which the error refers * * returns The formated error string */ - string getMappingError(const string& strKey, - const string& strMessage, - const CInstanceConfigurableElement* pInstanceConfigurableElement) const; + string getMappingError( + const string& strKey, + const string& strMessage, + const CConfigurableElementWithMapping* pConfigurableElementWithMapping) const; /** * Format the mapping data of the ConfigurableElements that have been gathered through recursive @@ -193,15 +198,16 @@ private: * * Feed context with mapping data of the current element * - * @param[in] pInstanceConfigurableElement The element containing mapping data + * @param[in] pConfigurableElementWithMapping The element containing mapping data * @param[out] context The context mapping to update with the current element mapping values * @param[out] strError The formated error string * * @return true on success */ - bool handleMappingContext(const CInstanceConfigurableElement* pInstanceConfigurableElement, - CMappingContext& context, - string& strError) const; + bool handleMappingContext( + const CConfigurableElementWithMapping* pConfigurableElementWithMapping, + CMappingContext& context, + string& strError) const; /** * Looks if a subsystem object needs to be instantiated for the given configurable @@ -239,4 +245,7 @@ private: // Endianness bool _bBigEndian; + + //! Contains the mapping info at Subsystem level + CMappingData* _pMappingData; }; |