PFW: parameter access code reuse
BZ: 13283
Path navigator embeds a navigate and validate functionality
that spares parameter manager from replicating code between
get and set parameter contexts.
Change-Id: Ic7c950660cd8c22b233ce02238fa1a66649a501b
Signed-off-by: Patrick Benavoli <patrickx.benavoli@intel.com>
Reviewed-on: http://android.intel.com:8080/25403
Reviewed-by: Barthes, FabienX <fabienx.barthes@intel.com>
Tested-by: Barthes, FabienX <fabienx.barthes@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
diff --git a/parameter/ParameterAccessContext.h b/parameter/ParameterAccessContext.h
index af6f1b7..11c0fdc 100644
--- a/parameter/ParameterAccessContext.h
+++ b/parameter/ParameterAccessContext.h
@@ -37,7 +37,7 @@
class CParameterAccessContext : public CErrorContext
{
public:
- CParameterAccessContext(string& strError, CParameterBlackboard* pParameterBlackboard, bool bValueSpaceIsRaw, bool bOutputRawFormatIsHex);
+ CParameterAccessContext(string& strError, CParameterBlackboard* pParameterBlackboard, bool bValueSpaceIsRaw, bool bOutputRawFormatIsHex = false);
CParameterAccessContext(string& strError);
// ParameterBlackboard
diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp
index 83867d5..61e204a 100644
--- a/parameter/ParameterMgr.cpp
+++ b/parameter/ParameterMgr.cpp
@@ -1652,31 +1652,14 @@
{
CPathNavigator pathNavigator(strPath);
- if (!pathNavigator.isPathValid()) {
-
- strError = "Path not well formed";
-
- return false;
- }
-
- string* pStrChildName = pathNavigator.next();
-
- if (!pStrChildName) {
-
- strError = "Non settable element";
-
- return false;
- }
-
- if (*pStrChildName != getSystemClass()->getName()) {
-
- strError = "Path not found";
+ // Nagivate through system class
+ if (!pathNavigator.navigateThrough(getSystemClass()->getName(), strError)) {
return false;
}
// Define context
- CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, bRawValueSpace, false);
+ CParameterAccessContext parameterAccessContext(strError, _pMainParameterBlackboard, bRawValueSpace);
// Set auto sync
parameterAccessContext.setAutoSync(_bAutoSyncOn);
@@ -1692,25 +1675,8 @@
{
CPathNavigator pathNavigator(strPath);
- if (!pathNavigator.isPathValid()) {
-
- strError = "Path not well formed";
-
- return false;
- }
-
- string* pStrChildName = pathNavigator.next();
-
- if (!pStrChildName) {
-
- strError = "Non settable element";
-
- return false;
- }
-
- if (*pStrChildName != getConstSystemClass()->getName()) {
-
- strError = "Path not found";
+ // Nagivate through system class
+ if (!pathNavigator.navigateThrough(getConstSystemClass()->getName(), strError)) {
return false;
}
diff --git a/parameter/PathNavigator.cpp b/parameter/PathNavigator.cpp
index 1911002..cb6bec3 100644
--- a/parameter/PathNavigator.cpp
+++ b/parameter/PathNavigator.cpp
@@ -50,6 +50,35 @@
return _bValid;
}
+// Navigate through
+bool CPathNavigator::navigateThrough(const string& strItemName, string& strError)
+{
+ if (!_bValid) {
+
+ strError = "Path not well formed";
+
+ return false;
+ }
+
+ string* pStrChildName = next();
+
+ if (!pStrChildName) {
+
+ strError = "Path not complete";
+
+ return false;
+ }
+
+ if (*pStrChildName != strItemName) {
+
+ strError = "Path not found";
+
+ return false;
+ }
+
+ return true;
+}
+
string* CPathNavigator::next()
{
if (_uiCurrentIndex < _astrItems.size()) {
diff --git a/parameter/PathNavigator.h b/parameter/PathNavigator.h
index ae3a901..c7f637a 100644
--- a/parameter/PathNavigator.h
+++ b/parameter/PathNavigator.h
@@ -41,10 +41,16 @@
public:
CPathNavigator(const string& strPath);
+ // Path validity
bool isPathValid() const;
+ // Navigate through
+ bool navigateThrough(const string& strItemName, string& strError);
+
+ // Nagivate
string* next();
+ // Current path
string getCurrentPath() const;
private: