summaryrefslogtreecommitdiffstats
path: root/parameter/ParameterMgr.cpp
diff options
context:
space:
mode:
authorPatrick Benavoli <patrick.benavoli@intel.com>2014-07-08 14:09:09 +0200
committerPhilippe Afonso <philippex.afonso@intel.com>2015-02-18 11:13:26 +0100
commit0548523ab6bbca766dcce4be97a0c50efd529d90 (patch)
tree4df756d6875dc1a0afc7835c3a16fb69b451c1da /parameter/ParameterMgr.cpp
parent79694d5d0a632ed4ca04ea42f19fb09c3fba0cdb (diff)
downloadexternal_parameter-framework-0548523ab6bbca766dcce4be97a0c50efd529d90.zip
external_parameter-framework-0548523ab6bbca766dcce4be97a0c50efd529d90.tar.gz
external_parameter-framework-0548523ab6bbca766dcce4be97a0c50efd529d90.tar.bz2
Adding XML format to Criteria export tuning I/F
BZ: 209937 The "listCriteria" command returns the list of criteria in a human readable way. However, external tools that require to know this list of criteria have trouble parsing this output. An XML output would solve the issue. Changed "listCriteria" command to accept "XML" as first and only argument. In the end, listCriteria command accepts the 3 following forms: - listCriteria => will list the criteria states and type content in a human readable format - listCriteria csv|CSV => will list the criteria states and type content in a CSV format - listCriteria xml|XML => will list the criteria states and type content in an XML format Removed python binding accordingly. Change-Id: Ib060ec0a5d1ff87ba6c25caf4e0d5839a7927715 Signed-off-by: Patrick Benavoli <patrick.benavoli@intel.com> Signed-off-by: Sebastien Gonzalve <sebastien.gonzalve@intel.com>
Diffstat (limited to 'parameter/ParameterMgr.cpp')
-rw-r--r--parameter/ParameterMgr.cpp70
1 files changed, 49 insertions, 21 deletions
diff --git a/parameter/ParameterMgr.cpp b/parameter/ParameterMgr.cpp
index 47abd0d..a1f2087 100644
--- a/parameter/ParameterMgr.cpp
+++ b/parameter/ParameterMgr.cpp
@@ -87,8 +87,11 @@
#include "XmlStringDocSource.h"
#include "XmlMemoryDocSink.h"
#include "XmlMemoryDocSource.h"
+#include "SelectionCriteriaDefinition.h"
#include "Utility.h"
#include <sstream>
+#include <algorithm>
+#include <ctype.h>
#include <memory>
#define base CElement
@@ -160,7 +163,7 @@ const CParameterMgr::SRemoteCommandParserItem CParameterMgr::gastRemoteCommandPa
/// Criteria
{ "listCriteria", &CParameterMgr::listCriteriaCommmandProcess, 0,
- "[csv]", "List selection criteria" },
+ "[CSV|XML]", "List selection criteria" },
/// Domains
{ "listDomains", &CParameterMgr::listDomainsCommmandProcess, 0,
@@ -1083,28 +1086,52 @@ CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::syncCommmandProcess
/// Criteria
CParameterMgr::CCommandHandler::CommandStatus CParameterMgr::listCriteriaCommmandProcess(const IRemoteCommand& remoteCommand, string& strResult)
{
- (void)remoteCommand;
+ if (remoteCommand.getArgumentCount() > 1) {
- bool humanReadable = true;
+ return CCommandHandler::EShowUsage;
+ }
+
+ string strOutputFormat;
// Look for optional arguments
- if (remoteCommand.getArgumentCount() >= 1) {
+ if (remoteCommand.getArgumentCount() == 1) {
+
+ // Get requested format
+ strOutputFormat = remoteCommand.getArgument(0);
+
+ // Capitalize
+ std::transform(strOutputFormat.begin(), strOutputFormat.end(), strOutputFormat.begin(), ::toupper);
+
+ if (strOutputFormat != "XML" && strOutputFormat != "CSV") {
- // If csv is provided, format the criterion list in Commas Separated Value pairs
- if (remoteCommand.getArgument(0) == "csv") {
- humanReadable = false;
- } else {
return CCommandHandler::EShowUsage;
}
}
- list<string> lstrResult;
- getSelectionCriteria()->listSelectionCriteria(lstrResult, true, humanReadable);
+ if (strOutputFormat == "XML") {
+ // Get Root element where to export from
+ const CSelectionCriteriaDefinition* pSelectionCriteriaDefinition = getConstSelectionCriteria()->getSelectionCriteriaDefinition();
- // Concatenate the criterion list as the command result
- CUtility::asString(lstrResult, strResult);
+ if (!exportElementToXMLString(pSelectionCriteriaDefinition, "SelectionCriteria", false, strResult)) {
- return CCommandHandler::ESucceeded;
+ return CCommandHandler::EFailed;
+ }
+
+ // Succeeded
+ return CCommandHandler::ESucceeded;
+ } else {
+
+ // Requested format will be either CSV or human readable based on strOutputFormat content
+ bool bHumanReadable = strOutputFormat.empty();
+
+ list<string> lstrResult;
+ getSelectionCriteria()->listSelectionCriteria(lstrResult, true, bHumanReadable);
+
+ // Concatenate the criterion list as the command result
+ CUtility::asString(lstrResult, strResult);
+
+ return CCommandHandler::ESucceeded;
+ }
}
/// Domains
@@ -1646,7 +1673,10 @@ CParameterMgr::CCommandHandler::CommandStatus
{
(void)remoteCommand;
- if (!getSystemClassXMLString(strResult)) {
+ // Get Root element where to export from
+ const CSystemClass* pSystemClass = getSystemClass();
+
+ if (!exportElementToXMLString(pSystemClass, pSystemClass->getKind(), false, strResult)) {
return CCommandHandler::EFailed;
}
@@ -2581,28 +2611,26 @@ void CParameterMgr::doApplyConfigurations(bool bForce)
getSelectionCriteria()->resetModifiedStatus();
}
-bool CParameterMgr::getSystemClassXMLString(string& strResult)
+// Export to XML string
+bool CParameterMgr::exportElementToXMLString(const IXmlSource *pXmlSource, const string& strRootElementType, bool bValidateWithSchema, string& strResult) const
{
- // Root element
- const CSystemClass* pSystemClass = getSystemClass();
-
string strError;
CXmlSerializingContext xmlSerializingContext(strError);
// Use a doc source by loading data from instantiated Configurable Domains
- CXmlMemoryDocSource memorySource(pSystemClass, pSystemClass->getKind(),
- _bValidateSchemasOnStart);
+ CXmlMemoryDocSource memorySource(pXmlSource, strRootElementType,
+ bValidateWithSchema);
// Use a doc sink that write the doc data in a string
CXmlStringDocSink stringSink(strResult);
+ // Do the export
bool bProcessSuccess = stringSink.process(memorySource, xmlSerializingContext);
if (!bProcessSuccess) {
strResult = strError;
-
}
return bProcessSuccess;