do {
std::shared_ptr<tizen_base::Parcel> parcel;
queue_.WaitAndPop(parcel);
- int len = parcel->GetRaw().size();
+ int len = parcel->GetDataSize();
if (len == 0) {
_W("Done");
break;
continue;
}
- ret = port_->Write(&*parcel->GetRaw().cbegin(), len);
+ ret = port_->Write(parcel->GetData(), len);
if (ret < 0) {
_E("Failed to write data");
SetConnectionStatus(false);
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) {
uint32_t size = 0;
parcel->ReadUInt32(&size);
if (size > 0) {
- auto buf = new (std::nothrow) uint8_t[size];
+ auto* buf = static_cast<uint8_t*>(malloc(size));
if (buf == nullptr) {
_E("Out of memory");
return;
}
- std::unique_ptr<uint8_t[]> ptr(buf);
parcel->Read(buf, size);
- parcel_reset(handle_, buf, size);
+ handle_ = std::move(tizen_base::Parcel(buf, size, false));
}
}
}
parcel_h Parcel::GetHandle() const {
- return handle_;
+ return static_cast<parcel_h>(const_cast<tizen_base::Parcel*>(&handle_));
}
} // namespace internal
#include <parcel.h>
+#include <parcel.hh>
+
#include <parcelable.hh>
#include "parcel-header-internal.hh"
private:
ParcelHeader header_;
- parcel_h handle_ = nullptr;
+ tizen_base::Parcel handle_;
};
} // namespace internal
int SendRequest(ClientSocket* client, const Request& request) {
tizen_base::Parcel parcel;
parcel.WriteParcelable(const_cast<Request&>(request));
- const std::vector<uint8_t>& raw = parcel.GetRaw();
- size_t size = raw.size();
+ size_t size = parcel.GetDataSize();
int ret = client->Send(reinterpret_cast<void*>(&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;
return -1;
}
- std::vector<uint8_t> buf(size);
- ret = client->Receive(buf.data(), size);
+ uint8_t* buf = static_cast<uint8_t*>(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");
if (len <= 0 || len > MAX_PARCEL_SIZE)
return RPC_PORT_ERROR_IO_ERROR;
- buf = new (std::nothrow) unsigned char[len];
+ buf = static_cast<unsigned char*>(malloc(len));
if (buf == nullptr) {
_E("Out of memory");
return RPC_PORT_ERROR_IO_ERROR;
ret = rpc_port_read(port, buf, len);
if (ret != 0) {
- delete[] buf;
+ free(buf);
return ret;
}
}
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<rpc_port_parcel_h>(parcel);
return RPC_PORT_ERROR_NONE;
}
auto* parcel = static_cast<internal::Parcel*>(h);
tizen_base::Parcel raw_parcel;
raw_parcel.WriteParcelable(*parcel);
- const std::vector<uint8_t>& raw_data = raw_parcel.GetRaw();
- void* raw = reinterpret_cast<void*>(const_cast<uint8_t*>(&raw_data[0]));
- uint32_t len = raw_data.size();
+ void* raw = reinterpret_cast<void*>(raw_parcel.GetData());
+ uint32_t len = raw_parcel.GetDataSize();
if (len <= 0)
return RPC_PORT_ERROR_INVALID_PARAMETER;
int SendResponse(ClientSocket* client, const Response& response) {
tizen_base::Parcel parcel;
parcel.WriteParcelable(const_cast<Response&>(response));
- const std::vector<uint8_t>& raw = parcel.GetRaw();
- size_t size = raw.size();
+ size_t size = parcel.GetDataSize();
int ret = client->Send(reinterpret_cast<void*>(&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;