summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Denneulin <guillaume.denneulin@intel.com>2014-01-10 14:58:42 +0100
committerDavid Wagner <david.wagner@intel.com>2014-02-12 17:04:19 +0100
commita6b01d2049a137932f303cdee554d8d2703d7af7 (patch)
tree1babc313169e1299f8e98d741df88046a12567dd
parent28119d8ec7d49b5fab310f08e6fc40c910e3bc8a (diff)
downloadexternal_parameter-framework-a6b01d2049a137932f303cdee554d8d2703d7af7.zip
external_parameter-framework-a6b01d2049a137932f303cdee554d8d2703d7af7.tar.gz
external_parameter-framework-a6b01d2049a137932f303cdee554d8d2703d7af7.tar.bz2
Add integer conversion that can take care of sign extension
BZ: 163707 When using signed integers of size 8 or 16, the bit of sign needs to be propagated if the API called by the plugin wait for "int" type Add the virtual toInteger function in CTypeElement for each parameter type to take care of conversion to "int". Specialize this function in the class CIntegerParameterType to take care of sign extension. Change-Id: I41183dccbcc21212299d1dde86b3ad4ba8432ce4 Signed-off-by: Guillaume Denneulin <guillaume.denneulin@intel.com>
-rwxr-xr-x[-rw-r--r--]parameter/IntegerParameterType.cpp10
-rwxr-xr-x[-rw-r--r--]parameter/IntegerParameterType.h4
-rwxr-xr-x[-rw-r--r--]parameter/ParameterType.cpp2
-rwxr-xr-x[-rw-r--r--]parameter/ParameterType.h19
-rwxr-xr-xparameter/SubsystemObject.cpp18
-rwxr-xr-x[-rw-r--r--]parameter/SubsystemObject.h11
-rwxr-xr-x[-rw-r--r--]parameter/TypeElement.cpp5
-rwxr-xr-x[-rw-r--r--]parameter/TypeElement.h9
8 files changed, 73 insertions, 5 deletions
diff --git a/parameter/IntegerParameterType.cpp b/parameter/IntegerParameterType.cpp
index 3c3a626..b07194b 100644..100755
--- a/parameter/IntegerParameterType.cpp
+++ b/parameter/IntegerParameterType.cpp
@@ -343,6 +343,16 @@ uint32_t CIntegerParameterType::getDefaultValue() const
return _uiMin;
}
+int CIntegerParameterType::toPlainInteger(int iSizeOptimizedData) const
+{
+ if (_bSigned) {
+
+ signExtend(iSizeOptimizedData);
+ }
+
+ return base::toPlainInteger(iSizeOptimizedData);
+}
+
// Convert value provided by the user as a string into an int64
bool CIntegerParameterType::convertValueFromString(const string& strValue, int64_t& iData, CParameterAccessContext& parameterAccessContext) const {
diff --git a/parameter/IntegerParameterType.h b/parameter/IntegerParameterType.h
index 9fb0dfd..29d28b7 100644..100755
--- a/parameter/IntegerParameterType.h
+++ b/parameter/IntegerParameterType.h
@@ -59,8 +59,12 @@ public:
// Element properties
virtual void showProperties(string& strResult) const;
+ // Integer conversion
+ virtual int toPlainInteger(int iSizeOptimizedData) const;
+
// CElement
virtual string getKind() const;
+
private:
// Returns true if children dynamic creation is to be dealt with
virtual bool childrenAreDynamic() const;
diff --git a/parameter/ParameterType.cpp b/parameter/ParameterType.cpp
index f7dda74..27df1dc 100644..100755
--- a/parameter/ParameterType.cpp
+++ b/parameter/ParameterType.cpp
@@ -112,13 +112,11 @@ CInstanceConfigurableElement* CParameterType::doInstantiate() const
}
}
-// Sign extension (32 bits)
void CParameterType::signExtend(int32_t& iData) const
{
doSignExtend(iData);
}
-// Sign extension (64 bits)
void CParameterType::signExtend(int64_t& iData) const
{
doSignExtend(iData);
diff --git a/parameter/ParameterType.h b/parameter/ParameterType.h
index ed30ac3..2fcd9e5 100644..100755
--- a/parameter/ParameterType.h
+++ b/parameter/ParameterType.h
@@ -73,14 +73,27 @@ public:
// Default value handling (simulation only)
virtual uint32_t getDefaultValue() const;
+
+ /**
+ * Sign extension (32 bits)
+ *
+ * @param[in:out] iData the data which will be sign extended
+ */
+ void signExtend(int32_t& iData) const;
+
+ /**
+ * Sign extension (64 bits)
+ *
+ * @param[in:out] iData the data which will be sign extended
+ */
+ void signExtend(int64_t& iData) const;
+
protected:
// Object creation
virtual void populate(CElement* pElement) const;
// Size
void setSize(uint32_t uiSize);
- // Sign extension
- void signExtend(int32_t& iData) const;
- void signExtend(int64_t& iData) const;
+
// Check data has no bit set outside available range (based on byte size) and
// check data is consistent with available range, with respect to its sign
bool isEncodable(uint32_t uiData, bool bIsSigned) const;
diff --git a/parameter/SubsystemObject.cpp b/parameter/SubsystemObject.cpp
index eaf87aa..c8d4c1b 100755
--- a/parameter/SubsystemObject.cpp
+++ b/parameter/SubsystemObject.cpp
@@ -28,6 +28,7 @@
#include "ParameterBlackboard.h"
#include "ParameterAccessContext.h"
#include "MappingContext.h"
+#include "ParameterType.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
@@ -82,6 +83,23 @@ string CSubsystemObject::asString(uint32_t uiValue)
return ostr.str();
}
+int CSubsystemObject::toPlainInteger(
+ const CInstanceConfigurableElement *instanceConfigurableElement,
+ int sizeOptimizedData)
+{
+ if (instanceConfigurableElement) {
+
+ // Get actual element type
+ const CTypeElement *typeElement =
+ static_cast<const CParameterType *>(instanceConfigurableElement->getTypeElement());
+
+ // Do the extension
+ return typeElement->toPlainInteger(sizeOptimizedData);
+ }
+
+ return sizeOptimizedData;
+}
+
// Default back synchronization
void CSubsystemObject::setDefaultValues(CParameterBlackboard& parameterBlackboard) const
{
diff --git a/parameter/SubsystemObject.h b/parameter/SubsystemObject.h
index ca52df8..1c6690d 100644..100755
--- a/parameter/SubsystemObject.h
+++ b/parameter/SubsystemObject.h
@@ -56,6 +56,17 @@ protected:
static uint32_t asInteger(const string& strValue);
static string asString(uint32_t uiValue);
+ /**
+ * Conversion of int8, int16, int32 to int (taking care of sign extension)
+ *
+ * @param[in] instanceConfigurableElement pointer to configurable element instance
+ * @param[in] sizeOptimizedData data to convert
+ *
+ * @return the data converted to int
+ */
+ int toPlainInteger(const CInstanceConfigurableElement *instanceConfigurableElement,
+ int sizeOptimizedData);
+
// Sync to/from HW
virtual bool sendToHW(string& strError);
virtual bool receiveFromHW(string& strError);
diff --git a/parameter/TypeElement.cpp b/parameter/TypeElement.cpp
index 5bfc2d7..59d4412 100644..100755
--- a/parameter/TypeElement.cpp
+++ b/parameter/TypeElement.cpp
@@ -49,6 +49,11 @@ uint32_t CTypeElement::getArrayLength() const
return _uiArrayLength;
}
+int CTypeElement::toPlainInteger(int iSizeOptimizedData) const
+{
+ return iSizeOptimizedData;
+}
+
bool CTypeElement::getMappingData(const string& strKey, const string*& pStrValue) const
{
if (_pMappingData) {
diff --git a/parameter/TypeElement.h b/parameter/TypeElement.h
index 353b0a5..6d801aa 100644..100755
--- a/parameter/TypeElement.h
+++ b/parameter/TypeElement.h
@@ -64,6 +64,15 @@ public:
// Array Length
uint32_t getArrayLength() const;
+ /**
+ * Converts size optimized integer input data (int8, int16, int32) to plain int
+ *
+ * @param[in] iSizeOptimizedData the data to convert
+ *
+ * @return the data with int type
+ */
+ virtual int toPlainInteger(int iSizeOptimizedData) const;
+
protected:
// Object creation
virtual void populate(CElement* pElement) const;