[MessagePort] Change to support array on MessagePortDataItem
authorPiotr Czaja <p.czaja@samsung.com>
Fri, 8 Jan 2016 09:26:05 +0000 (10:26 +0100)
committerPiotr Czaja <p.czaja@samsung.com>
Wed, 13 Jan 2016 10:00:41 +0000 (11:00 +0100)
[Verification] Web TCT result isn't changed

Change-Id: I187c522970c751bf0c1d1677ff81d67e283d1681
Signed-off-by: Piotr Czaja <p.czaja@samsung.com>
src/messageport/messageport_instance.cc

index 97882dee8b275058aead8ae57172974b26aa32f9..81c6f9e1414ed0d59fe090b9d14f81e457c1a6c8 100755 (executable)
@@ -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<std::string>()) {
+      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<picojson::array>()) {
+      LoggerD("value is array");
+      std::vector<picojson::value> value_array = (*it).get("value").get<picojson::array>();
+      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 ?