summaryrefslogtreecommitdiffstats
path: root/parameter
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
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')
-rw-r--r--parameter/ParameterMgr.cpp70
-rw-r--r--parameter/ParameterMgr.h14
-rw-r--r--parameter/ParameterMgrFullConnector.cpp5
-rw-r--r--parameter/SelectionCriterion.cpp13
-rw-r--r--parameter/SelectionCriterion.h9
-rw-r--r--parameter/SelectionCriterionType.cpp23
-rw-r--r--parameter/SelectionCriterionType.h9
-rw-r--r--parameter/include/ParameterMgrFullConnector.h10
8 files changed, 111 insertions, 42 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;
diff --git a/parameter/ParameterMgr.h b/parameter/ParameterMgr.h
index 7edace1..03a1e92 100644
--- a/parameter/ParameterMgr.h
+++ b/parameter/ParameterMgr.h
@@ -88,7 +88,7 @@ class CParameterMgr : private CElement
};
// Version
static const uint32_t guiEditionMajor = 0x2;
- static const uint32_t guiEditionMinor = 0x3;
+ static const uint32_t guiEditionMinor = 0x4;
static const uint32_t guiRevision = 0x0;
// Parameter handle friendship
@@ -340,14 +340,16 @@ public:
bool exportDomainsBinary(const std::string& strFileName, std::string& strError);
/**
- * Method that creates an Xml description of the instanciated parameter structure contained
- * in SystemClass.
+ * Method that exports an Xml description of the passed element into a string
*
- * @param[out] strResult contains the xml description of SystemClass or the errors if any
+ * @param[in] pXmlSource The source element to export
+ * @param[in] strRootElementType The XML root element name of the exported instance document
+ * @param[in] bValidateWithSchema true if source XML document requires validation against schema
+ * @param[out] strResult contains the xml description or the error description in case false is returned
*
- * @return false if any error occures during the creation of the xml description
+ * @return true for success, false if any error occurs during the creation of the xml description (validation or encoding)
*/
- bool getSystemClassXMLString(std::string& strResult);
+ bool exportElementToXMLString(const IXmlSource* pXmlSource, const std::string& strRootElementType, bool bValidateWithSchema, std::string& strResult) const;
// CElement
virtual std::string getKind() const;
diff --git a/parameter/ParameterMgrFullConnector.cpp b/parameter/ParameterMgrFullConnector.cpp
index b03facc..30f31e9 100644
--- a/parameter/ParameterMgrFullConnector.cpp
+++ b/parameter/ParameterMgrFullConnector.cpp
@@ -363,8 +363,3 @@ bool CParameterMgrFullConnector::exportSingleDomainXml(string& strXmlDest,
return _pParameterMgr->exportSingleDomainXml(strXmlDest, strDomainName, bWithSettings, bToFile,
strError);
}
-
-bool CParameterMgrFullConnector::getSystemClassXMLString(string& strResult)
-{
- return _pParameterMgr->getSystemClassXMLString(strResult);
-}
diff --git a/parameter/SelectionCriterion.cpp b/parameter/SelectionCriterion.cpp
index f49137b..7818924 100644
--- a/parameter/SelectionCriterion.cpp
+++ b/parameter/SelectionCriterion.cpp
@@ -27,6 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+
#include "SelectionCriterion.h"
#include "AutoLog.h"
@@ -168,3 +169,15 @@ std::string CSelectionCriterion::getFormattedDescription(bool bWithTypeInfo, boo
}
return strFormattedDescription;
}
+
+// XML export
+void CSelectionCriterion::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
+{
+ // Current Value
+ xmlElement.setAttributeString("Value", _pType->getFormattedState(_iState));
+
+ // Serialize Type node
+ _pType->toXml(xmlElement, serializingContext);
+
+ base::toXml(xmlElement, serializingContext);
+}
diff --git a/parameter/SelectionCriterion.h b/parameter/SelectionCriterion.h
index c61d7d0..cf99035 100644
--- a/parameter/SelectionCriterion.h
+++ b/parameter/SelectionCriterion.h
@@ -63,6 +63,15 @@ public:
/// From CElement
virtual std::string getKind() const;
+
+ /**
+ * Export to XML
+ *
+ * @param[in] xmlElement The XML element to export to
+ * @param[in] serializingContext The serializing context
+ *
+ */
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
private:
// Current state
int _iState;
diff --git a/parameter/SelectionCriterionType.cpp b/parameter/SelectionCriterionType.cpp
index 3e9cc80..95e8e46 100644
--- a/parameter/SelectionCriterionType.cpp
+++ b/parameter/SelectionCriterionType.cpp
@@ -203,3 +203,26 @@ std::string CSelectionCriterionType::getFormattedState(int iValue) const
return strFormattedState;
}
+
+// From IXmlSource
+void CSelectionCriterionType::toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const
+{
+ // Type Kind
+ xmlElement.setAttributeString("Kind", isTypeInclusive() ? "Inclusive" : "Exclusive");
+
+ // Value pairs as children
+ NumToLitMapConstIt it;
+
+ for (it = _numToLitMap.begin(); it != _numToLitMap.end(); ++it) {
+
+ CXmlElement childValuePairElement;
+
+ xmlElement.createChild(childValuePairElement, "ValuePair");
+ // Literal
+ childValuePairElement.setAttributeString("Literal", it->first);
+ // Numerical
+ childValuePairElement.setAttributeSignedInteger("Numerical", it->second);
+ }
+
+ base::toXml(xmlElement, serializingContext);
+}
diff --git a/parameter/SelectionCriterionType.h b/parameter/SelectionCriterionType.h
index bfef21e..ef4176a 100644
--- a/parameter/SelectionCriterionType.h
+++ b/parameter/SelectionCriterionType.h
@@ -63,6 +63,15 @@ public:
// Formatted state
virtual std::string getFormattedState(int iValue) const;
+ /**
+ * Export to XML
+ *
+ * @param[in] xmlElement The XML element to export to
+ * @param[in] serializingContext The serializing context
+ *
+ */
+ virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
+
// From CElement
virtual std::string getKind() const;
private:
diff --git a/parameter/include/ParameterMgrFullConnector.h b/parameter/include/ParameterMgrFullConnector.h
index 8ef7bb7..31022a6 100644
--- a/parameter/include/ParameterMgrFullConnector.h
+++ b/parameter/include/ParameterMgrFullConnector.h
@@ -259,16 +259,6 @@ public:
bool exportSingleDomainXml(std::string& strXmlDest, const std::string& strDomainName, bool bWithSettings,
bool bToFile, std::string& strError) const;
- /**
- * Method that creates an Xml description of the instanciated parameter structure contained
- * in SystemClass.
- *
- * @param[out] strResult contains the xml description of SystemClass or the errors if any
- *
- * @return false if any error occures during the creation of the xml description
- */
- bool getSystemClassXMLString(std::string& strResult);
-
private:
// disallow copying because this class manages raw pointers' lifecycle
CParameterMgrFullConnector(const CParameterMgrFullConnector&);