diff options
-rw-r--r-- | newproject.txt | 0 | ||||
-rw-r--r-- | parameter/InstanceConfigurableElement.cpp | 33 | ||||
-rw-r--r-- | parameter/Subsystem.cpp | 84 | ||||
-rw-r--r-- | parameter/Subsystem.h | 34 |
4 files changed, 99 insertions, 52 deletions
diff --git a/newproject.txt b/newproject.txt deleted file mode 100644 index e69de29..0000000 --- a/newproject.txt +++ /dev/null diff --git a/parameter/InstanceConfigurableElement.cpp b/parameter/InstanceConfigurableElement.cpp index 6795f8b..4a6cacc 100644 --- a/parameter/InstanceConfigurableElement.cpp +++ b/parameter/InstanceConfigurableElement.cpp @@ -58,34 +58,29 @@ bool CInstanceConfigurableElement::getMappingData(const string& strKey, const st bool CInstanceConfigurableElement::map(IMapper& mapper, string& strError) { bool bHasMappingData = getTypeElement()->hasMappingData(); + bool bKeepDiving = true; // Begin - if (bHasMappingData) { - - bool bKeepDiving; - - if (!mapper.mapBegin(this, bKeepDiving, strError)) { - - return false; - } - // Go on through children? - if (!bKeepDiving) { + if (bHasMappingData && !mapper.mapBegin(this, bKeepDiving, strError)) { - return true; - } + return false; } - // Map children - uint32_t uiNbChildren = getNbChildren(); - uint32_t uiChild; + // Go on through children? + if (bKeepDiving) { + + // Map children + uint32_t uiNbChildren = getNbChildren(); + uint32_t uiChild; - for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { + for (uiChild = 0; uiChild < uiNbChildren; uiChild++) { - CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild)); + CInstanceConfigurableElement* pInstanceConfigurableChildElement = static_cast<CInstanceConfigurableElement*>(getChild(uiChild)); - if (!pInstanceConfigurableChildElement->map(mapper, strError)) { + if (!pInstanceConfigurableChildElement->map(mapper, strError)) { - return false; + return false; + } } } diff --git a/parameter/Subsystem.cpp b/parameter/Subsystem.cpp index a9115c8..f49ba64 100644 --- a/parameter/Subsystem.cpp +++ b/parameter/Subsystem.cpp @@ -233,10 +233,13 @@ bool CSubsystem::handleMappingContext(const CInstanceConfigurableElement* pInsta return true; } -// Creation handling -bool CSubsystem::handleSubsystemObjectCreation(CInstanceConfigurableElement* pInstanceConfigurableElement, CMappingContext& context, string& strError) +// Subsystem object creation handling +bool CSubsystem::handleSubsystemObjectCreation( + CInstanceConfigurableElement* pInstanceConfigurableElement, + CMappingContext& context, bool& bHasCreatedSubsystemObject, string& strError) { uint32_t uiItem; + bHasCreatedSubsystemObject = false; for (uiItem = 0; uiItem < _subsystemObjectCreatorArray.size(); uiItem++) { @@ -281,13 +284,16 @@ bool CSubsystem::handleSubsystemObjectCreation(CInstanceConfigurableElement* pIn // Do create object and keep its track _subsystemObjectList.push_back(pSubsystemObjectCreator->objectCreate(*pStrValue, pInstanceConfigurableElement, context)); - // Done - return true; + // Indicate subsytem creation to caller + bHasCreatedSubsystemObject = true; + + // The subsystem Object has been instantiated, no need to continue looking for an + // instantiation mapping + break; } } - getMappingError(strError, "Mapping key", "Not found", pInstanceConfigurableElement); - return false; + return true; } // Generic error handling from derived subsystem classes @@ -297,46 +303,64 @@ void CSubsystem::getMappingError(string& strError, const string& strKey, const s } // From IMapper -bool CSubsystem::mapBegin(CInstanceConfigurableElement* pInstanceConfigurableElement, bool& bKeepDiving, string& strError) +// Handle a configurable element mapping +bool CSubsystem::mapBegin(CInstanceConfigurableElement* pInstanceConfigurableElement, + bool& bKeepDiving, string& strError) { // Get current context CMappingContext context = _contextStack.top(); - switch(pInstanceConfigurableElement->getType()) { + // Add mapping in context + if (!handleMappingContext(pInstanceConfigurableElement, context, strError)) { - case CInstanceConfigurableElement::EComponent: + return false; + } - if (!handleMappingContext(pInstanceConfigurableElement, context, strError)) { + // Push context + _contextStack.push(context); - return false; - } + // Assume diving by default + bKeepDiving = true; - // Push context - _contextStack.push(context); + // Deal with ambiguous usage of parameter blocks + bool bShouldCreateSubsystemObject = true; - // Keep diving - bKeepDiving = true; + switch(pInstanceConfigurableElement->getType()) { - return true; + case CInstanceConfigurableElement::EComponent: + return true; - case CInstanceConfigurableElement::EParameterBlock: - case CInstanceConfigurableElement::EBitParameterBlock: - case CInstanceConfigurableElement::EParameter: - case CInstanceConfigurableElement::EStringParameter: + case CInstanceConfigurableElement::EParameterBlock: + // Subsystem object creation is optional in parameter blocks + bShouldCreateSubsystemObject = false; + // No break + case CInstanceConfigurableElement::EBitParameterBlock: + case CInstanceConfigurableElement::EParameter: + case CInstanceConfigurableElement::EStringParameter: - if (!handleSubsystemObjectCreation(pInstanceConfigurableElement, context, strError)) { + bool bHasCreatedSubsystemObject; - return false; - } + if (!handleSubsystemObjectCreation(pInstanceConfigurableElement, context, + bHasCreatedSubsystemObject, strError)) { + + return false; + } + // Check for creation error + if (bShouldCreateSubsystemObject && !bHasCreatedSubsystemObject) { - // Done - bKeepDiving = false; + getMappingError(strError, "Not found", + "Subsystem object mapping key is missing", + pInstanceConfigurableElement); + return false; + } + // Not created and no error, keep diving + bKeepDiving = !bHasCreatedSubsystemObject; - return true; + return true; - default: - assert(0); - return false; + default: + assert(0); + return false; } } diff --git a/parameter/Subsystem.h b/parameter/Subsystem.h index 0b808ad..5a0f844 100644 --- a/parameter/Subsystem.h +++ b/parameter/Subsystem.h @@ -85,14 +85,42 @@ private: // Generic subsystem mapping error handling void getMappingError(string& strError, const string& strKey, const string& strMessage, const CInstanceConfigurableElement* pInstanceConfigurableElement); - // From IMapper + /** + * Handle a configurable element mapping. + * + * Add context mappings to the context and instantiate a subsystem object if needed. + * + * @param[in:out] pInstanceConfigurableElement The configurable element + * @param[out] bKeepDiving Keep diving for mapping keys + Is set to true if a subsystem object (tree leave) has been instantiated. + Undetermined on error + * @param[out] strError String filled with an human readable error on error, + left unmodified otherwise + * + * @return true on success, false on failure + */ virtual bool mapBegin(CInstanceConfigurableElement* pInstanceConfigurableElement, bool& bKeepDiving, string& strError); virtual void mapEnd(); // Mapping generic context handling bool handleMappingContext(const CInstanceConfigurableElement* pInstanceConfigurableElement, CMappingContext& context, string& strError); - // Subsystem object creation handling - bool handleSubsystemObjectCreation(CInstanceConfigurableElement* pInstanceConfigurableElement, CMappingContext& context, string& strError); + + /** + * Looks if a subsystem object needs to be instantiated for the given configurable + * element, then instantiate it if needed. + * + * @param[in:out] pInstanceConfigurableElement The configurable element to check + * for instanciation + * @param[in] context The mapping values container + * @param[out] bHasCreatedSubsystemObject If a subsystem object has been instantiated. + Undetermined on error + * @param[out] strError String filled with an human readable error on error, + left unmodified otherwise + * + * @return true on success, false on failure + */ + bool handleSubsystemObjectCreation(CInstanceConfigurableElement* pInstanceConfigurableElement, + CMappingContext& context, bool& bHasCreatedSubsystemObject, string& strError); // Subsystem context mapping keys vector<string> _contextMappingKeyArray; |