Fix rpc-port-parcel implementation related to bundle 67/254967/2
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 11 Mar 2021 05:07:28 +0000 (14:07 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 11 Mar 2021 05:23:52 +0000 (14:23 +0900)
Parcel APIs related to Bundle API will be removed.
rpc_port_parcel_write_bundle() modifies to use use parcel_write_string()
instead of parcel_write_bundle(). rpc_port_parcel_read_bundle() modifies
to use parcel_read_string() instead of parcel_read_bundle().

Change-Id: Iad0b6e347bb72197ebeffd1a630862a5eb8ffbbc
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/rpc-port-parcel.cc

index e934efb..2276a77 100644 (file)
@@ -18,6 +18,8 @@
 #include <stdint.h>
 #include <string.h>
 
+#include <memory>
+
 #include "log-private.hh"
 #include "port-internal.hh"
 #include "rpc-port-parcel.h"
@@ -203,8 +205,13 @@ RPC_API int rpc_port_parcel_write_bundle(rpc_port_parcel_h h, bundle* b) {
   if (h == nullptr || b == nullptr)
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
+  bundle_raw* raw = nullptr;
+  int len = 0;
+  bundle_encode(b, &raw, &len);
+  auto ptr = std::unique_ptr<bundle_raw, decltype(std::free)*>(raw, std::free);
+
   parcel_h parcel = static_cast<parcel_h>(h);
-  parcel_write_bundle(parcel, b);
+  parcel_write_string(parcel, reinterpret_cast<char*>(raw));
   return RPC_PORT_ERROR_NONE;
 }
 
@@ -334,10 +341,14 @@ RPC_API int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle** b) {
     return RPC_PORT_ERROR_INVALID_PARAMETER;
 
   parcel_h parcel = static_cast<parcel_h>(h);
-  int ret = parcel_read_bundle(parcel, b);
+  char* raw = nullptr;
+  int ret = parcel_read_string(parcel, &raw);
   if (ret != PARCEL_ERROR_NONE) {
-    _E("parcel_read_bundle() is failed. error(%d)", ret);
+    _E("parcel_read_string() is failed. error(%d)", ret);
     *b = bundle_create();
+  } else {
+    *b = bundle_decode(reinterpret_cast<bundle_raw*>(raw), strlen(raw));
+    std::free(raw);
   }
 
   return RPC_PORT_ERROR_NONE;