From 0469c78a12ef3e952c54e0d231b46df880888bf9 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 24 Dec 2020 08:05:03 +0900 Subject: [PATCH] Use tizen base parcel API The parcel implmentation is removed. Bacause, Parcel APi is added on Bundle repository. We use tizen_base::Parcel API instread. Requires: - https://review.tizen.org/gerrit/#/c/platform/core/base/bundle/+/249500/ Change-Id: I996f43ca0cac9c68315aee45287e8a4316c36167 Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 2 +- packaging/rpc-port.spec | 1 + src/debug-port-internal.cc | 10 +- src/debug-port-internal.hh | 4 +- src/parcel-internal.cc | 194 ------------------------------------ src/parcel-internal.hh | 75 -------------- src/rpc-port-parcel.cc | 242 +++++++++++++++++++++++---------------------- 7 files changed, 133 insertions(+), 395 deletions(-) delete mode 100644 src/parcel-internal.cc delete mode 100644 src/parcel-internal.hh diff --git a/CMakeLists.txt b/CMakeLists.txt index 82d5c9e..7f93a11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ INCLUDE_DIRECTORIES ( ${CMAKE_SOURCE_DIR}/src ) -SET(${this_target}_requires "dlog bundle glib-2.0 gio-2.0 aul capi-base-common pkgmgr-info gio-unix-2.0 cynara-client cynara-creds-gdbus uuid") +SET(${this_target}_requires "dlog bundle glib-2.0 gio-2.0 aul capi-base-common pkgmgr-info gio-unix-2.0 cynara-client cynara-creds-gdbus uuid parcel") INCLUDE(FindPkgConfig) pkg_check_modules(${this_target} REQUIRED ${${this_target}_requires}) diff --git a/packaging/rpc-port.spec b/packaging/rpc-port.spec index 435953a..4bd6586 100644 --- a/packaging/rpc-port.spec +++ b/packaging/rpc-port.spec @@ -17,6 +17,7 @@ BuildRequires: pkgconfig(gmock) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-creds-gdbus) BuildRequires: pkgconfig(uuid) +BuildRequires: pkgconfig(parcel) %if 0%{?gcov:1} BuildRequires: lcov diff --git a/src/debug-port-internal.cc b/src/debug-port-internal.cc index 4723a87..debd51e 100644 --- a/src/debug-port-internal.cc +++ b/src/debug-port-internal.cc @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include @@ -21,7 +22,6 @@ #include "debug-port-internal.hh" #include "log-private.hh" -#include "parcel-internal.hh" namespace rpc_port { namespace internal { @@ -95,7 +95,7 @@ int DebugPort::Send(int port, bool is_read, uint32_t seq, } // time + port_name + destination + is_delegate + port + is_read + seq + size + data - Parcel parcel; + tizen_base::Parcel parcel; parcel.WriteInt64(time(nullptr)); parcel.WriteString(session->GetPortName().c_str()); parcel.WriteString(session->GetDestination().c_str()); @@ -106,7 +106,7 @@ int DebugPort::Send(int port, bool is_read, uint32_t seq, parcel.WriteInt32(size); parcel.Write(static_cast(buf), size); - queue_.Push(std::make_shared(parcel)); + queue_.Push(std::make_shared(parcel)); return 0; } @@ -313,7 +313,7 @@ void DebugPort::CreateThread() { thread_ = std::thread([&]() { _W("START"); do { - std::shared_ptr parcel; + std::shared_ptr parcel; queue_.WaitAndPop(parcel); int len = parcel->GetRaw().size(); if (len == 0) { @@ -345,7 +345,7 @@ void DebugPort::CreateThread() { void DebugPort::JoinThread() { if (is_running_) - queue_.Push(std::shared_ptr(new Parcel())); + queue_.Push(std::shared_ptr(new tizen_base::Parcel())); if (thread_.joinable()) { _W("Join thread"); diff --git a/src/debug-port-internal.hh b/src/debug-port-internal.hh index 8904bba..caff4ac 100644 --- a/src/debug-port-internal.hh +++ b/src/debug-port-internal.hh @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -27,7 +28,6 @@ #include #include -#include "parcel-internal.hh" #include "port-internal.hh" #include "shared-queue-internal.hh" @@ -133,7 +133,7 @@ class DebugPort { std::list> sessions_; std::thread thread_; std::atomic is_running_; - SharedQueue> queue_; + SharedQueue> queue_; mutable std::recursive_mutex mutex_; }; diff --git a/src/parcel-internal.cc b/src/parcel-internal.cc deleted file mode 100644 index 0667929..0000000 --- a/src/parcel-internal.cc +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include - -#include "parcel-internal.hh" - -namespace rpc_port { - -Parcel::Parcel(const unsigned char* buf, unsigned int size) - : data_(buf, buf + size) {} - -void Parcel::WriteByte(char b) { - Write(b); -} - -void Parcel::WriteInt16(short i) { - Write(i); -} - -void Parcel::WriteInt32(int i) { - Write(i); -} - -void Parcel::WriteInt64(long long i) { - Write(i); -} - -void Parcel::WriteFloat(float f) { - Write(f); -} - -void Parcel::WriteDouble(double d) { - Write(d); -} - -void Parcel::WriteString(const char* str) { - int l = std::strlen(str) + 1; - - Write(l); - std::copy(str, str + l, std::back_inserter(data_)); -} - -void Parcel::WriteBool(bool b) { - Write(b); -} - -void Parcel::WriteBundle(bundle* b) { - bundle_raw *r; - int len; - bundle_encode(b, &r, &len); - unsigned char* c = reinterpret_cast(r); - - Write(len + 1); - std::copy(c, c + len + 1, std::back_inserter(data_)); - free(r); -} - -void Parcel::WriteArrayCount(int count) { - Write(count); -} - -char Parcel::ReadByte() { - return Read(); -} - -short Parcel::ReadInt16() { - return Read(); -} - -int Parcel::ReadInt32() { - return Read(); -} - -long long Parcel::ReadInt64() { - return Read(); -} - -float Parcel::ReadFloat() { - return Read(); -} - -double Parcel::ReadDouble() { - return Read(); -} - -const char* Parcel::ReadString() { - int l = Read(); - - if (l <= 0) - return nullptr; - if (reader_ + l > data_.size()) - return nullptr; - if (data_[reader_ + l - 1] != 0) - return nullptr; - const char* str = reinterpret_cast(&data_[reader_]); - reader_ += l; - - return str; -} - -bool Parcel::ReadBool() { - return Read(); -} - -bundle* Parcel::ReadBundle() { - int l = Read(); - - if (l <= 0) - return nullptr; - if (reader_ + l > data_.size()) - return nullptr; - if (data_[reader_ + l - 1] != 0) - return nullptr; - const bundle_raw* str = reinterpret_cast(&data_[reader_]); - reader_ += l; - - bundle* b = bundle_decode(str, l - 1); - - return b; -} - -int Parcel::ReadArrayCount() { - return Read(); -} - -const std::vector& Parcel::GetRaw() { - return data_; -} - -void Parcel::Write(const unsigned char* buf, unsigned int size) { - std::copy(buf, buf + size, std::back_inserter(data_)); -} - -void Parcel::Read(unsigned char* buf, unsigned int size) { - if (reader_ + size > data_.size()) - return; - std::copy(&data_[reader_], &data_[reader_] + size, buf); - reader_ += size; -} - -// LCOV_EXCL_START -void Parcel::ResetReader() { - reader_ = 0; -} -// LCOV_EXCL_STOP - -// LCOV_EXCL_START -void Parcel::Clear() { - data_.clear(); - reader_ = 0; -} -// LCOV_EXCL_STOP - -// LCOV_EXCL_START -void Parcel::Reset(const unsigned char* buf, unsigned int size) { - Clear(); - Write(buf, size); -} -// LCOV_EXCL_STOP - -template -void Parcel::Write(T d) { - unsigned char* p = reinterpret_cast(&d); - - std::copy(p, p + sizeof(T), std::back_inserter(data_)); -} - -template -T Parcel::Read() { - T d = 0; - unsigned char* p = reinterpret_cast(&d); - - if (reader_ + sizeof(T) > data_.size()) - return d; - std::copy(&data_[reader_], &data_[reader_] + sizeof(T), p); - reader_ += sizeof(T); - return d; -} - - -} // namespace rpc_port diff --git a/src/parcel-internal.hh b/src/parcel-internal.hh deleted file mode 100644 index acf9b6f..0000000 --- a/src/parcel-internal.hh +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PARCEL_INTERNAL_H_ -#define PARCEL_INTERNAL_H_ - -#include - -#include -#include -#include -#include - -namespace rpc_port { - -class Parcel { - public: - Parcel() = default; - Parcel(const unsigned char* buf, unsigned int size); - - void Write(const unsigned char* buf, unsigned int size); - void Read(unsigned char* buf, unsigned int size); - void WriteByte(char b); - void WriteInt16(short i); - void WriteInt32(int i); - void WriteInt64(long long i); - void WriteFloat(float f); - void WriteDouble(double d); - void WriteString(const char* str); - void WriteBool(bool b); - void WriteBundle(bundle* b); - void WriteArrayCount(int count); - char ReadByte(); - short ReadInt16(); - int ReadInt32(); - long long ReadInt64(); - float ReadFloat(); - double ReadDouble(); - const char* ReadString(); - bool ReadBool(); - bundle* ReadBundle(); - int ReadArrayCount(); - const std::vector& GetRaw(); - void ResetReader(); - void Clear(); - void Reset(const unsigned char* buf, unsigned int size); - - private: - template - void Write(T d); - - template - T Read(); - - private: - std::vector data_; - unsigned int reader_ = 0; -}; - -} // namespace rpc_port - -#endif // PARCEL_INTERNAL_H_ diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index c4fa7fb..c5802f2 100644 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2018 - 2020 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -14,12 +14,13 @@ * limitations under the License. */ +#include +#include #include -#include "rpc-port-parcel.h" - -#include "parcel-internal.hh" +#include "log-private.hh" #include "port-internal.hh" +#include "rpc-port-parcel.h" #define MAX_PARCEL_SIZE (1024 * 1024 * 10) @@ -28,14 +29,28 @@ using namespace rpc_port; +static int __convert_parcel_error(int error) { + switch (error) { + case PARCEL_ERROR_ILLEGAL_BYTE_SEQ: + case PARCEL_ERROR_NO_DATA: + return RPC_PORT_ERROR_IO_ERROR; + case PARCEL_ERROR_OUT_OF_MEMORY: + return RPC_PORT_ERROR_OUT_OF_MEMORY; + default: + return RPC_PORT_ERROR_INVALID_PARAMETER; + } +} + RPC_API int rpc_port_parcel_create(rpc_port_parcel_h* h) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = new Parcel(); - - *h = p; + parcel_h parcel = nullptr; + int ret = parcel_create(&parcel); + if (ret != PARCEL_ERROR_NONE) + return __convert_parcel_error(ret); + *h = static_cast(parcel); return RPC_PORT_ERROR_NONE; } @@ -56,19 +71,23 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, if (len <= 0 || len > MAX_PARCEL_SIZE) return RPC_PORT_ERROR_IO_ERROR; + buf = new unsigned char[len]; ret = rpc_port_read(port, buf, len); if (ret != 0) { - delete[] buf; // LCOV_EXCL_LINE - return ret; // LCOV_EXCL_LINE + delete[] buf; + return ret; } } - Parcel* p = new Parcel(buf, len); + parcel_h parcel = nullptr; + int ret = parcel_create(&parcel); + if (ret != PARCEL_ERROR_NONE) + return RPC_PORT_ERROR_IO_ERROR; + parcel_burst_write(parcel, buf, len); delete[] buf; - *h = p; - + *h = static_cast(parcel); return RPC_PORT_ERROR_NONE; } @@ -76,8 +95,10 @@ RPC_API int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port) { if (h == nullptr || port == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - int len = p->GetRaw().size(); + parcel_h parcel = static_cast(h); + void* raw = nullptr; + uint32_t len = 0; + parcel_get_raw(parcel, &raw, &len); if (len <= 0) return RPC_PORT_ERROR_INVALID_PARAMETER; @@ -85,11 +106,11 @@ RPC_API int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port) { internal::Port* pt = static_cast(port); { std::lock_guard lock(pt->GetMutex()); - int ret = rpc_port_write(port, &len, 4); + int ret = rpc_port_write(port, &len, sizeof(len)); if (ret != 0) return ret; - ret = rpc_port_write(port, &*(p->GetRaw().cbegin()), len); + ret = rpc_port_write(port, raw, len); if (ret != 0) return ret; } @@ -101,8 +122,8 @@ RPC_API int rpc_port_parcel_destroy(rpc_port_parcel_h h) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - delete static_cast(h); - + parcel_h parcel = static_cast(h); + parcel_destroy(parcel); return RPC_PORT_ERROR_NONE; } @@ -110,10 +131,8 @@ RPC_API int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->WriteByte(b); - + parcel_h parcel = static_cast(h); + parcel_write_byte(parcel, b); return RPC_PORT_ERROR_NONE; } @@ -121,10 +140,8 @@ RPC_API int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->WriteInt16(i); - + parcel_h parcel = static_cast(h); + parcel_write_int16(parcel, i); return RPC_PORT_ERROR_NONE; } @@ -132,10 +149,8 @@ RPC_API int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->WriteInt32(i); - + parcel_h parcel = static_cast(h); + parcel_write_int32(parcel, i); return RPC_PORT_ERROR_NONE; } @@ -143,10 +158,8 @@ RPC_API int rpc_port_parcel_write_int64(rpc_port_parcel_h h, long long i) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->WriteInt64(i); - + parcel_h parcel = static_cast(h); + parcel_write_int64(parcel, i); return RPC_PORT_ERROR_NONE; } @@ -154,10 +167,8 @@ RPC_API int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->WriteFloat(f); - + parcel_h parcel = static_cast(h); + parcel_write_float(parcel, f); return RPC_PORT_ERROR_NONE; } @@ -165,10 +176,8 @@ RPC_API int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->WriteDouble(d); - + parcel_h parcel = static_cast(h); + parcel_write_double(parcel, d); return RPC_PORT_ERROR_NONE; } @@ -176,10 +185,8 @@ RPC_API int rpc_port_parcel_write_string(rpc_port_parcel_h h, const char* str) { if (h == nullptr || str == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->WriteString(str); - + parcel_h parcel = static_cast(h); + parcel_write_string(parcel, str); return RPC_PORT_ERROR_NONE; } @@ -187,10 +194,8 @@ RPC_API int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->WriteBool(b); - + parcel_h parcel = static_cast(h); + parcel_write_bool(parcel, b); return RPC_PORT_ERROR_NONE; } @@ -198,10 +203,8 @@ 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; - Parcel* p = static_cast(h); - - p->WriteBundle(b); - + parcel_h parcel = static_cast(h); + parcel_write_bundle(parcel, b); return RPC_PORT_ERROR_NONE; } @@ -209,10 +212,8 @@ RPC_API int rpc_port_parcel_write_array_count(rpc_port_parcel_h h, int count) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->WriteArrayCount(count); - + parcel_h parcel = static_cast(h); + parcel_write_int32(parcel, count); return RPC_PORT_ERROR_NONE; } @@ -225,7 +226,6 @@ RPC_API int rpc_port_parcel_write(rpc_port_parcel_h h, return RPC_PORT_ERROR_INVALID_PARAMETER; parcelable->to(h, data); - return RPC_PORT_ERROR_NONE; } @@ -233,9 +233,10 @@ RPC_API int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char* b) { if (h == nullptr || b == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - *b = p->ReadByte(); + parcel_h parcel = static_cast(h); + int ret = parcel_read_byte(parcel, b); + if (ret != PARCEL_ERROR_NONE) + _E("parcel_read_byte() is failed. error(%d)", ret); return RPC_PORT_ERROR_NONE; } @@ -244,9 +245,10 @@ RPC_API int rpc_port_parcel_read_int16(rpc_port_parcel_h h, short* i) { if (h == nullptr || i == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - *i = p->ReadInt16(); + parcel_h parcel = static_cast(h); + int ret = parcel_read_int16(parcel, i); + if (ret != PARCEL_ERROR_NONE) + _E("parcel_read_int16() is failed. error(%d)", ret); return RPC_PORT_ERROR_NONE; } @@ -255,9 +257,10 @@ RPC_API int rpc_port_parcel_read_int32(rpc_port_parcel_h h, int* i) { if (h == nullptr || i == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - *i = p->ReadInt32(); + parcel_h parcel = static_cast(h); + int ret = parcel_read_int32(parcel, i); + if (ret != PARCEL_ERROR_NONE) + _E("parcel_read_int32() is failed. error(%d)", ret); return RPC_PORT_ERROR_NONE; } @@ -266,9 +269,10 @@ RPC_API int rpc_port_parcel_read_int64(rpc_port_parcel_h h, long long* i) { if (h == nullptr || i == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - *i = p->ReadInt64(); + parcel_h parcel = static_cast(h); + int ret = parcel_read_int64(parcel, i); + if (ret != PARCEL_ERROR_NONE) + _E("parcel_read_int64() is failed. error(%d)", ret); return RPC_PORT_ERROR_NONE; } @@ -277,9 +281,10 @@ RPC_API int rpc_port_parcel_read_float(rpc_port_parcel_h h, float* f) { if (h == nullptr || f == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - *f = p->ReadFloat(); + parcel_h parcel = static_cast(h); + int ret = parcel_read_float(parcel, f); + if (ret != PARCEL_ERROR_NONE) + _E("parcel_read_float() is failed. error(%d)", ret); return RPC_PORT_ERROR_NONE; } @@ -288,9 +293,10 @@ RPC_API int rpc_port_parcel_read_double(rpc_port_parcel_h h, double* d) { if (h == nullptr || d == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - *d = p->ReadDouble(); + parcel_h parcel = static_cast(h); + int ret = parcel_read_double(parcel, d); + if (ret != PARCEL_ERROR_NONE) + _E("parcel_read_double() is failed. error(%d)", ret); return RPC_PORT_ERROR_NONE; } @@ -299,9 +305,12 @@ RPC_API int rpc_port_parcel_read_string(rpc_port_parcel_h h, char** str) { if (h == nullptr || str == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - const char* read = p->ReadString(); - *str = read == nullptr ? strdup("") : strdup(read); + parcel_h parcel = static_cast(h); + int ret = parcel_read_string(parcel, str); + if (ret != PARCEL_ERROR_NONE) { + _E("parcel_read_string() is failed. error(%d)", ret); + *str = strdup(""); + } return RPC_PORT_ERROR_NONE; } @@ -310,9 +319,10 @@ RPC_API int rpc_port_parcel_read_bool(rpc_port_parcel_h h, bool* b) { if (h == nullptr || b == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - *b = p->ReadBool(); + parcel_h parcel = static_cast(h); + int ret = parcel_read_bool(parcel, b); + if (ret != PARCEL_ERROR_NONE) + _E("parcel_read_bool() is failed. error(%d)", ret); return RPC_PORT_ERROR_NONE; } @@ -321,10 +331,12 @@ RPC_API int rpc_port_parcel_read_bundle(rpc_port_parcel_h h, bundle** b) { if (h == nullptr || b == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - bundle* read = p->ReadBundle(); - - *b = read == nullptr ? bundle_create() : read; + parcel_h parcel = static_cast(h); + int ret = parcel_read_bundle(parcel, b); + if (ret != PARCEL_ERROR_NONE) { + _E("parcel_read_bundle() is failed. error(%d)", ret); + *b = bundle_create(); + } return RPC_PORT_ERROR_NONE; } @@ -333,9 +345,10 @@ RPC_API int rpc_port_parcel_read_array_count(rpc_port_parcel_h h, int* count) { if (h == nullptr || count == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - *count = p->ReadArrayCount(); + parcel_h parcel = static_cast(h); + int ret = parcel_read_int32(parcel, count); + if (ret != PARCEL_ERROR_NONE) + _E("parcel_read_int32() is failed. error(%d)", ret); return RPC_PORT_ERROR_NONE; } @@ -358,9 +371,11 @@ RPC_API int rpc_port_parcel_burst_read(rpc_port_parcel_h h, unsigned char *buf, if (h == nullptr || buf == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->Read(buf, size); + parcel_h parcel = static_cast(h); + uint32_t valid_size = size & UINT32_MAX; + int ret = parcel_burst_read(parcel, static_cast(buf), valid_size); + if (ret != PARCEL_ERROR_NONE) + _E("parcel_burst_read() is failed. error(%d)", ret); return RPC_PORT_ERROR_NONE; } @@ -370,57 +385,48 @@ RPC_API int rpc_port_parcel_burst_write(rpc_port_parcel_h h, if (h == nullptr || buf == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->Write(buf, size); - + parcel_h parcel = static_cast(h); + uint32_t valid_size = size & UINT32_MAX; + parcel_burst_write(parcel, static_cast(buf), valid_size); return RPC_PORT_ERROR_NONE; } -// LCOV_EXCL_START RPC_API int rpc_port_parcel_reset_reader(rpc_port_parcel_h h) { if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->ResetReader(); - + parcel_h parcel = static_cast(h); + parcel_reset_reader(parcel); return RPC_PORT_ERROR_NONE; } -// LCOV_EXCL_STOP -// LCOV_EXCL_START RPC_API int rpc_port_parcel_to_array(rpc_port_parcel_h h, void** array, unsigned int* size) { if (h == nullptr || !array || !size) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); + parcel_h parcel = static_cast(h); + void* raw = nullptr; + uint32_t raw_size = 0; + parcel_get_raw(parcel, &raw, &raw_size); - const auto& ptr = p->GetRaw(); - void* array_ptr = malloc(ptr.size()); - if (!array_ptr) + void* array_ptr = malloc(raw_size); + if (array_ptr == nullptr) return RPC_PORT_ERROR_OUT_OF_MEMORY; - memcpy(array_ptr, ptr.data(), ptr.size()); + memcpy(array_ptr, raw, raw_size); *array = array_ptr; - *size = ptr.size(); - + *size = static_cast(raw_size); return RPC_PORT_ERROR_NONE; } -// LCOV_EXCL_STOP -// LCOV_EXCL_START RPC_API int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void* array, unsigned int size) { if (h == nullptr || !array || size == 0) return RPC_PORT_ERROR_INVALID_PARAMETER; - Parcel* p = static_cast(h); - - p->Reset(reinterpret_cast(array), size); - + parcel_h parcel = static_cast(h); + uint32_t valid_size = size & UINT32_MAX; + parcel_reset(parcel, array, valid_size); return RPC_PORT_ERROR_NONE; } -// LCOV_EXCL_STOP -- 2.7.4