From: Hwankyu Jhun Date: Fri, 23 Sep 2022 11:06:39 +0000 (+0000) Subject: Use modified tizen_base::Parcel X-Git-Tag: accepted/tizen/unified/20220928.144443~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ce812b6c2ad864314c7911d0f421acca45b92e5c;p=platform%2Fcore%2Fappfw%2Frpc-port.git Use modified tizen_base::Parcel To improve the performance of the parcel creation, the implementation of the Parcel is changed. It uses malloc() instead of std::vector. Requires: - https://review.tizen.org/gerrit/#/c/platform/core/base/bundle/+/281779/ Change-Id: Iaf01e6e94e34e10a36b8ca17081c6aba3b3b51e1 Signed-off-by: Hwankyu Jhun --- diff --git a/src/debug-port-internal.cc b/src/debug-port-internal.cc index e5c1802..06e44dc 100644 --- a/src/debug-port-internal.cc +++ b/src/debug-port-internal.cc @@ -327,7 +327,7 @@ void DebugPortImpl::CreateThread() { do { std::shared_ptr parcel; queue_.WaitAndPop(parcel); - int len = parcel->GetRaw().size(); + int len = parcel->GetDataSize(); if (len == 0) { _W("Done"); break; @@ -343,7 +343,7 @@ void DebugPortImpl::CreateThread() { continue; } - ret = port_->Write(&*parcel->GetRaw().cbegin(), len); + ret = port_->Write(parcel->GetData(), len); if (ret < 0) { _E("Failed to write data"); SetConnectionStatus(false); diff --git a/src/parcel-internal.cc b/src/parcel-internal.cc index ba6ba66..75f5805 100644 --- a/src/parcel-internal.cc +++ b/src/parcel-internal.cc @@ -22,23 +22,15 @@ namespace rpc_port { namespace internal { -Parcel::Parcel() { - parcel_create(&handle_); -} +Parcel::Parcel() {} -Parcel::~Parcel() { - if (handle_) - parcel_destroy(handle_); -} +Parcel::~Parcel() {} void Parcel::WriteToParcel(tizen_base::Parcel* parcel) const { parcel->WriteParcelable(header_); - void* raw = nullptr; - uint32_t size = 0; - parcel_get_raw(handle_, &raw, &size); - parcel->WriteUInt32(size); - parcel->Write(raw, size); + parcel->WriteUInt32(handle_.GetDataSize()); + parcel->Write(handle_.GetData(), handle_.GetDataSize()); } void Parcel::ReadFromParcel(tizen_base::Parcel* parcel) { @@ -47,15 +39,14 @@ void Parcel::ReadFromParcel(tizen_base::Parcel* parcel) { uint32_t size = 0; parcel->ReadUInt32(&size); if (size > 0) { - auto buf = new (std::nothrow) uint8_t[size]; + auto* buf = static_cast(malloc(size)); if (buf == nullptr) { _E("Out of memory"); return; } - std::unique_ptr ptr(buf); parcel->Read(buf, size); - parcel_reset(handle_, buf, size); + handle_ = std::move(tizen_base::Parcel(buf, size, false)); } } @@ -64,7 +55,7 @@ const ParcelHeader* Parcel::GetParcelHeader() { } parcel_h Parcel::GetHandle() const { - return handle_; + return static_cast(const_cast(&handle_)); } } // namespace internal diff --git a/src/parcel-internal.hh b/src/parcel-internal.hh index 77507fb..6922003 100644 --- a/src/parcel-internal.hh +++ b/src/parcel-internal.hh @@ -19,6 +19,8 @@ #include +#include + #include #include "parcel-header-internal.hh" @@ -39,7 +41,7 @@ class Parcel : public tizen_base::Parcelable { private: ParcelHeader header_; - parcel_h handle_ = nullptr; + tizen_base::Parcel handle_; }; } // namespace internal diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 771a303..8ddb569 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -53,15 +53,14 @@ std::string GenInstance() { int SendRequest(ClientSocket* client, const Request& request) { tizen_base::Parcel parcel; parcel.WriteParcelable(const_cast(request)); - const std::vector& raw = parcel.GetRaw(); - size_t size = raw.size(); + size_t size = parcel.GetDataSize(); int ret = client->Send(reinterpret_cast(&size), sizeof(size)); if (ret != 0) { _E("Send() is failed. error(%d)", ret); return -1; } - ret = client->Send(raw.data(), raw.size()); + ret = client->Send(parcel.GetData(), size); if (ret != 0) { _E("Send() is failed. error(%d)", ret); return -1; @@ -78,14 +77,20 @@ int ReceiveResponse(ClientSocket* client, Response** response) { return -1; } - std::vector buf(size); - ret = client->Receive(buf.data(), size); + uint8_t* buf = static_cast(malloc(size)); + if (buf == nullptr) { + _E("Out of memory"); + return -1; + } + + ret = client->Receive(buf, size); if (ret != 0) { _E("Receive() is failed. error(%d)", ret); + free(buf); return -1; } - tizen_base::Parcel parcel(buf.data(), buf.size()); + tizen_base::Parcel parcel(buf, size, false); *response = new (std::nothrow) Response(); if (*response == nullptr) { _E("Out of memory"); diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index 35361db..86af7b3 100644 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -62,7 +62,7 @@ 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 (std::nothrow) unsigned char[len]; + buf = static_cast(malloc(len)); if (buf == nullptr) { _E("Out of memory"); return RPC_PORT_ERROR_IO_ERROR; @@ -70,7 +70,7 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, ret = rpc_port_read(port, buf, len); if (ret != 0) { - delete[] buf; + free(buf); return ret; } } @@ -78,13 +78,12 @@ RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h, auto* parcel = new (std::nothrow) internal::Parcel(); if (parcel == nullptr) { _E("Out of memory"); - delete[] buf; + free(buf); return RPC_PORT_ERROR_IO_ERROR; } - tizen_base::Parcel raw_parcel(buf, len); + tizen_base::Parcel raw_parcel(buf, len, false); raw_parcel.ReadParcelable(parcel); - delete[] buf; *h = static_cast(parcel); return RPC_PORT_ERROR_NONE; } @@ -96,9 +95,8 @@ RPC_API int rpc_port_parcel_send(rpc_port_parcel_h h, rpc_port_h port) { auto* parcel = static_cast(h); tizen_base::Parcel raw_parcel; raw_parcel.WriteParcelable(*parcel); - const std::vector& raw_data = raw_parcel.GetRaw(); - void* raw = reinterpret_cast(const_cast(&raw_data[0])); - uint32_t len = raw_data.size(); + void* raw = reinterpret_cast(raw_parcel.GetData()); + uint32_t len = raw_parcel.GetDataSize(); if (len <= 0) return RPC_PORT_ERROR_INVALID_PARAMETER; diff --git a/src/stub-internal.cc b/src/stub-internal.cc index 5a9d014..5508bc4 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -69,15 +69,14 @@ int ReceiveRequest(ClientSocket* client, Request** request) { int SendResponse(ClientSocket* client, const Response& response) { tizen_base::Parcel parcel; parcel.WriteParcelable(const_cast(response)); - const std::vector& raw = parcel.GetRaw(); - size_t size = raw.size(); + size_t size = parcel.GetDataSize(); int ret = client->Send(reinterpret_cast(&size), sizeof(size)); if (ret != 0) { _E("Send() is failed. error(%d)", ret); return -1; } - ret = client->Send(raw.data(), raw.size()); + ret = client->Send(parcel.GetData(), size); if (ret != 0) { _E("Send() is failed. error(%d)", ret); return -1;