summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Schemas/Parameter.xsd1
-rw-r--r--parameter/BitParameterType.cpp40
-rw-r--r--parameter/BitParameterType.h6
-rw-r--r--parameter/ParameterMgr.cpp6
4 files changed, 41 insertions, 12 deletions
diff --git a/Schemas/Parameter.xsd b/Schemas/Parameter.xsd
index 10d506a..098ee26 100644
--- a/Schemas/Parameter.xsd
+++ b/Schemas/Parameter.xsd
@@ -116,6 +116,7 @@
</xs:restriction>
</xs:simpleType>
</xs:attribute>
+ <xs:attribute name="Max" type="xs:integer" use="optional"/>
</xs:complexType>
<xs:element name="BitParameterBlock">
<xs:complexType>
diff --git a/parameter/BitParameterType.cpp b/parameter/BitParameterType.cpp
index 30b0173..9a09a59 100644
--- a/parameter/BitParameterType.cpp
+++ b/parameter/BitParameterType.cpp
@@ -37,7 +37,7 @@
#define base CTypeElement
-CBitParameterType::CBitParameterType(const string& strName) : base(strName), _uiBitPos(0), _uiBitSize(0)
+CBitParameterType::CBitParameterType(const string& strName) : base(strName), _uiBitPos(0), _uiBitSize(0), _uiMax(uint32_t(-1))
{
}
@@ -61,6 +61,11 @@ void CBitParameterType::showProperties(string& strResult) const
strResult += "Bit size: ";
strResult += toString(_uiBitSize);
strResult += "\n";
+
+ // Max
+ strResult += "Max: ";
+ strResult += toString(_uiMax);
+ strResult += "\n";
}
// From IXmlSink
@@ -89,6 +94,27 @@ bool CBitParameterType::fromXml(const CXmlElement& xmlElement, CXmlSerializingCo
return false;
}
+ // Max
+ if (xmlElement.hasAttribute("Max")) {
+
+ _uiMax = xmlElement.getAttributeInteger("Max");
+
+ if (_uiMax > getMaxEncodableValue()) {
+
+ // Max value exceeded
+ ostringstream strStream;
+
+ strStream << "Max attribute inconsistent with maximum encodable size (" << getMaxEncodableValue() << ") for " + getKind();
+
+ serializingContext.setError(strStream.str());
+
+ return false;
+ }
+ } else {
+
+ _uiMax = getMaxEncodableValue();
+ }
+
// Base
return base::fromXml(xmlElement, serializingContext);
}
@@ -102,7 +128,7 @@ bool CBitParameterType::toBlackboard(const string& strValue, uint32_t& uiValue,
// Get value
uint32_t uiConvertedValue = strtoul(strValue.c_str(), NULL, 0);
- if (uiConvertedValue > getMaxValue()) {
+ if (uiConvertedValue > _uiMax) {
// Range exceeded
ostringstream strStream;
@@ -116,7 +142,7 @@ bool CBitParameterType::toBlackboard(const string& strValue, uint32_t& uiValue,
strStream << "0, ";
}
- strStream << getMaxValue() << "] for " + getKind();
+ strStream << _uiMax << "] for " + getKind();
parameterAccessContext.setError(strStream.str());
@@ -151,7 +177,7 @@ void CBitParameterType::fromBlackboard(string& strValue, const uint32_t& uiValue
// Integer
bool CBitParameterType::toBlackboard(uint32_t uiUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
{
- if (uiUserValue > getMaxValue()) {
+ if (uiUserValue > _uiMax) {
parameterAccessContext.setError("Value out of range");
@@ -183,15 +209,15 @@ CInstanceConfigurableElement* CBitParameterType::doInstantiate() const
}
// Max value
-uint32_t CBitParameterType::getMaxValue() const
+uint32_t CBitParameterType::getMaxEncodableValue() const
{
- return (1 << _uiBitSize) - 1;
+ return (uint32_t)-1L >> (8 * sizeof(uint32_t) - _uiBitSize);
}
// Biwise mask
uint32_t CBitParameterType::getMask() const
{
- return getMaxValue() << _uiBitPos;
+ return getMaxEncodableValue() << _uiBitPos;
}
// Check data has no bit set outside available range
diff --git a/parameter/BitParameterType.h b/parameter/BitParameterType.h
index 6cd86c4..ebfec7e 100644
--- a/parameter/BitParameterType.h
+++ b/parameter/BitParameterType.h
@@ -63,8 +63,8 @@ public:
private:
// Instantiation
virtual CInstanceConfigurableElement* doInstantiate() const;
- // Max value
- uint32_t getMaxValue() const;
+ // Max encodable value
+ uint32_t getMaxEncodableValue() const;
// Biwise mask
uint32_t getMask() const;
// Check data has no bit set outside available range
@@ -74,4 +74,6 @@ private:
uint32_t _uiBitPos;
// Size in bits
uint32_t _uiBitSize;
+ // Max value
+ uint32_t _uiMax;
};
diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp
index f1dd9eb..66c8d9e 100644
--- a/parameter/ParameterMgr.cpp
+++ b/parameter/ParameterMgr.cpp
@@ -620,7 +620,7 @@ CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, st
// Nagivate through system class
if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
- return false;
+ return NULL;
}
// Find element
@@ -630,7 +630,7 @@ CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, st
strError = "Path not found";
- return false;
+ return NULL;
}
// Check found element is a parameter
@@ -641,7 +641,7 @@ CParameterHandle* CParameterMgr::createParameterHandle(const string& strPath, st
// Element is not parameter
strError = "Not a parameter";
- return false;
+ return NULL;
}
// Convert as parameter and return new handle