From 353a917075df4b298a4b45b81422fc68f26c206a Mon Sep 17 00:00:00 2001
From: Piotr Czaja
Date: Fri, 8 Jan 2016 10:26:05 +0100
Subject: [PATCH] [MessagePort] Change to support array on MessagePortDataItem
[Verification] Web TCT result isn't changed
Change-Id: I187c522970c751bf0c1d1677ff81d67e283d1681
Signed-off-by: Piotr Czaja
---
src/messageport/messageport_instance.cc | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/messageport/messageport_instance.cc b/src/messageport/messageport_instance.cc
index 97882dee..81c6f9e1 100755
--- a/src/messageport/messageport_instance.cc
+++ b/src/messageport/messageport_instance.cc
@@ -99,7 +99,7 @@ static void BundleJsonIterator(const char *key, const int type, const bundle_key
}
o["key"] = picojson::value(key);
- o["value"] = picojson::value(picojson::value(tab).serialize());
+ o["value"] = picojson::value(picojson::value(tab));
break;
}
@@ -362,8 +362,29 @@ void MessageportInstance::RemoteMessagePortSendmessage
for (picojson::value::array::iterator it = data.begin();
it != data.end(); ++it) {
+ if ((*it).get("value").is()) {
+ LoggerD("value is string");
bundle_add(bundle, (*it).get("key").to_str().c_str(),
(*it).get("value").to_str().c_str());
+ }
+ else if ((*it).get("value").is()) {
+ LoggerD("value is array");
+ std::vector value_array = (*it).get("value").get();
+ const size_t size = value_array.size();
+ const char** arr = new const char*[size];
+ size_t i = 0;
+
+ for (auto iter = value_array.begin(); iter != value_array.end(); ++iter, ++i) {
+ arr[i] = iter->to_str().c_str();
+ }
+
+ bundle_add_str_array(bundle, (*it).get("key").to_str().c_str(), arr, size);
+ delete[] arr;
+ } else {
+ LogAndReportError(
+ TypeMismatchException("Type mismatch Error"), out,
+ ("data value should be string or string array"));
+ }
}
LoggerD("%s to %s", trusted ?
--
2.34.1