#include "include/rpc-port-parcel.h"
-#include <parcel.hh>
+#include <bundle_internal.h>
#include <stdint.h>
#include <string.h>
#include <memory>
+#include <parcel.hh>
#include "log-private.hh"
#include "parcel-internal.hh"
#include "port-internal.hh"
-#define MAX_PARCEL_SIZE (1024 * 1024 * 10)
+#define MAX_PARCEL_SIZE (1024 * 1024 * 10)
#undef RPC_API
#define RPC_API extern "C" __attribute__((visibility("default")))
using namespace rpc_port;
RPC_API int rpc_port_parcel_create(rpc_port_parcel_h* h) {
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = new (std::nothrow) internal::Parcel();
- if (parcel == nullptr)
- return RPC_PORT_ERROR_OUT_OF_MEMORY;
+ if (parcel == nullptr) return RPC_PORT_ERROR_OUT_OF_MEMORY;
*h = static_cast<rpc_port_parcel_h>(parcel);
return RPC_PORT_ERROR_NONE;
}
RPC_API int rpc_port_parcel_create_from_port(rpc_port_parcel_h* h,
- rpc_port_h port) {
+ rpc_port_h port) {
int len;
unsigned char* buf;
- if (h == nullptr || port == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr || port == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
internal::Port* pt = static_cast<internal::Port*>(port);
{
std::lock_guard<std::recursive_mutex> lock(pt->GetReadMutex());
int ret = rpc_port_read(port, &len, 4);
- if (ret != 0)
- return ret;
+ if (ret != 0) return ret;
- if (len <= 0 || len > MAX_PARCEL_SIZE)
- return RPC_PORT_ERROR_IO_ERROR;
+ if (len <= 0 || len > MAX_PARCEL_SIZE) return RPC_PORT_ERROR_IO_ERROR;
buf = static_cast<unsigned char*>(malloc(len));
if (buf == nullptr) {
- _E("Out of memory"); // LCOV_EXCL_LINE
+ _E("Out of memory"); // LCOV_EXCL_LINE
return RPC_PORT_ERROR_IO_ERROR; // LCOV_EXCL_LINE
}
ret = rpc_port_read(port, buf, len);
if (ret != 0) {
- free(buf); // LCOV_EXCL_LINE
+ free(buf); // LCOV_EXCL_LINE
return ret; // LCOV_EXCL_LINE
}
}
}
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;
+ if (h == nullptr || port == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
tizen_base::Parcel raw_parcel;
raw_parcel.WriteParcelable(*parcel);
void* raw = reinterpret_cast<void*>(raw_parcel.GetData());
uint32_t len = static_cast<uint32_t>(raw_parcel.GetDataSize());
- if (len <= 0)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (len <= 0) return RPC_PORT_ERROR_INVALID_PARAMETER;
internal::Port* pt = static_cast<internal::Port*>(port);
{
std::lock_guard<std::recursive_mutex> lock(pt->GetWriteMutex());
int ret = rpc_port_write(port, &len, sizeof(len));
- if (ret != 0)
- return ret;
+ if (ret != 0) return ret;
ret = rpc_port_write(port, raw, len);
- if (ret != 0)
- return ret;
+ if (ret != 0) return ret;
}
return RPC_PORT_ERROR_NONE;
}
RPC_API int rpc_port_parcel_destroy(rpc_port_parcel_h h) {
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
delete parcel;
}
RPC_API int rpc_port_parcel_write_byte(rpc_port_parcel_h h, char b) {
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
parcel_write_byte(parcel->GetHandle(), b);
}
RPC_API int rpc_port_parcel_write_int16(rpc_port_parcel_h h, short i) {
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
parcel_write_int16(parcel->GetHandle(), i);
}
RPC_API int rpc_port_parcel_write_int32(rpc_port_parcel_h h, int i) {
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
parcel_write_int32(parcel->GetHandle(), i);
}
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;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
parcel_write_int64(parcel->GetHandle(), i);
}
RPC_API int rpc_port_parcel_write_float(rpc_port_parcel_h h, float f) {
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
parcel_write_float(parcel->GetHandle(), f);
}
RPC_API int rpc_port_parcel_write_double(rpc_port_parcel_h h, double d) {
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
parcel_write_double(parcel->GetHandle(), d);
}
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;
+ if (h == nullptr || str == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
parcel_write_string(parcel->GetHandle(), str);
}
RPC_API int rpc_port_parcel_write_bool(rpc_port_parcel_h h, bool b) {
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
parcel_write_bool(parcel->GetHandle(), b);
}
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;
+ 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);
+ bundle_encode_raw(b, &raw, &len);
+ auto ptr =
+ std::unique_ptr<bundle_raw*, decltype(bundle_free_encoded_rawdata)*>(
+ &raw, bundle_free_encoded_rawdata);
auto* parcel = static_cast<internal::Parcel*>(h);
- parcel_write_string(parcel->GetHandle(), reinterpret_cast<char*>(raw));
+ parcel_write_int32(parcel->GetHandle(), len);
+ parcel_burst_write(parcel->GetHandle(), raw, len);
return RPC_PORT_ERROR_NONE;
}
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;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
parcel_write_int32(parcel->GetHandle(), count);
}
RPC_API int rpc_port_parcel_write(rpc_port_parcel_h h,
- rpc_port_parcelable_t* parcelable, void* data) {
+ rpc_port_parcelable_t* parcelable,
+ void* data) {
if (parcelable == nullptr || parcelable->to == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
parcelable->to(h, data);
return RPC_PORT_ERROR_NONE;
}
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;
+ if (h == nullptr || b == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_byte(parcel->GetHandle(), b);
}
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;
+ if (h == nullptr || i == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_int16(parcel->GetHandle(), i);
}
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;
+ if (h == nullptr || i == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_int32(parcel->GetHandle(), i);
}
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;
+ if (h == nullptr || i == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
int64_t val = 0;
}
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;
+ if (h == nullptr || f == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_float(parcel->GetHandle(), f);
}
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;
+ if (h == nullptr || d == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_double(parcel->GetHandle(), d);
}
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;
+ if (h == nullptr || str == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_string(parcel->GetHandle(), str);
if (ret != PARCEL_ERROR_NONE) {
_E("parcel_read_string() is failed. error(%d)", ret); // LCOV_EXCL_LINE
- *str = strdup(""); // LCOV_EXCL_LINE
+ *str = strdup(""); // LCOV_EXCL_LINE
}
return RPC_PORT_ERROR_NONE;
}
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;
+ if (h == nullptr || b == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_bool(parcel->GetHandle(), b);
}
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;
+ if (h == nullptr || b == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
- char* raw = nullptr;
- int ret = parcel_read_string(parcel->GetHandle(), &raw);
+ int len = 0;
+ int ret = parcel_read_int32(parcel->GetHandle(), &len);
if (ret != 0) {
- _E("parcel_read_string() is failed. error(%d)", ret); // LCOV_EXCL_LINE
- *b = bundle_create(); // LCOV_EXCL_LINE
+ _E("parcel_read_int32() failed. error(%d)", ret); // LCOV_EXCL_LINE
+ *b = bundle_create(); // LCOV_EXCL_LINE
+ return RPC_PORT_ERROR_NONE;
+ }
+
+ void* raw = nullptr;
+ ret = parcel_read_ptr(parcel->GetHandle(), &raw, len);
+ if (ret != 0 || raw == nullptr) {
+ _E("parcel_read_ptr() failed."); // LCOV_EXCL_LINE
+ *b = bundle_create(); // LCOV_EXCL_LINE
} else {
- *b = bundle_decode(reinterpret_cast<bundle_raw*>(raw), strlen(raw));
- std::free(raw);
+ *b = bundle_decode_raw(static_cast<bundle_raw*>(raw), len);
}
return RPC_PORT_ERROR_NONE;
}
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;
+ if (h == nullptr || count == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
int ret = parcel_read_int32(parcel->GetHandle(), count);
}
RPC_API int rpc_port_parcel_read(rpc_port_parcel_h h,
- rpc_port_parcelable_t* parcelable, void* data) {
+ rpc_port_parcelable_t* parcelable,
+ void* data) {
if (parcelable == nullptr || parcelable->from == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
parcelable->from(h, data);
return RPC_PORT_ERROR_NONE;
}
-RPC_API int rpc_port_parcel_burst_read(rpc_port_parcel_h h, unsigned char *buf,
- unsigned int size) {
- if (h == nullptr || buf == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+RPC_API int rpc_port_parcel_burst_read(rpc_port_parcel_h h, unsigned char* buf,
+ unsigned int size) {
+ if (h == nullptr || buf == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
uint32_t valid_size = size & UINT32_MAX;
int ret = parcel_burst_read(parcel->GetHandle(), static_cast<void*>(buf),
- valid_size);
+ valid_size);
if (ret != PARCEL_ERROR_NONE)
_E("parcel_read() is failed. error(%d)", ret); // LCOV_EXCL_LINE
}
RPC_API int rpc_port_parcel_burst_write(rpc_port_parcel_h h,
- const unsigned char *buf, unsigned int size) {
- if (h == nullptr || buf == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ const unsigned char* buf,
+ unsigned int size) {
+ if (h == nullptr || buf == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
uint32_t valid_size = size & UINT32_MAX;
parcel_burst_write(parcel->GetHandle(), static_cast<const void*>(buf),
- valid_size);
+ valid_size);
return RPC_PORT_ERROR_NONE;
}
RPC_API int rpc_port_parcel_reset_reader(rpc_port_parcel_h h) {
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
parcel_reset_reader(parcel->GetHandle());
}
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;
+ unsigned int* size) {
+ if (h == nullptr || !array || !size) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
tizen_base::Parcel raw_parcel;
}
void* array_ptr = malloc(raw_size);
- if (array_ptr == nullptr)
- return RPC_PORT_ERROR_OUT_OF_MEMORY;
+ if (array_ptr == nullptr) return RPC_PORT_ERROR_OUT_OF_MEMORY;
memcpy(array_ptr, raw, raw_size);
*array = array_ptr;
}
RPC_API int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void* array,
- unsigned int size) {
+ unsigned int size) {
if (h == nullptr || array == nullptr || size == 0)
return RPC_PORT_ERROR_INVALID_PARAMETER;
}
RPC_API int rpc_port_parcel_get_header(rpc_port_parcel_h h,
- rpc_port_parcel_header_h* header) {
+ rpc_port_parcel_header_h* header) {
if (h == nullptr || header == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = static_cast<internal::Parcel*>(h);
auto* parcel_header = parcel->GetParcelHeader();
- if (parcel_header == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (parcel_header == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
*header = reinterpret_cast<rpc_port_parcel_header_h>(
const_cast<internal::ParcelHeader*>(parcel_header));
}
RPC_API int rpc_port_parcel_header_set_tag(rpc_port_parcel_header_h header,
- const char* tag) {
+ const char* tag) {
if (header == nullptr || tag == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
}
RPC_API int rpc_port_parcel_header_get_tag(rpc_port_parcel_header_h header,
- char** tag) {
+ char** tag) {
if (header == nullptr || tag == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
const std::string& raw_tag = parcel_header->GetTag();
*tag = strdup(raw_tag.c_str());
- if (*tag == nullptr)
- return RPC_PORT_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
+ if (*tag == nullptr) return RPC_PORT_ERROR_OUT_OF_MEMORY; // LCOV_EXCL_LINE
return RPC_PORT_ERROR_NONE;
}
RPC_API int rpc_port_parcel_header_set_seq_num(rpc_port_parcel_header_h header,
- int seq_num) {
- if (header == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ int seq_num) {
+ if (header == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel_header = static_cast<internal::ParcelHeader*>(header);
parcel_header->SetSeqNum(seq_num);
}
RPC_API int rpc_port_parcel_header_get_seq_num(rpc_port_parcel_header_h header,
- int* seq_num) {
+ int* seq_num) {
if (header == nullptr || seq_num == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
}
RPC_API int rpc_port_parcel_get_raw(rpc_port_parcel_h h, void** raw,
- unsigned int* size) {
+ unsigned int* size) {
if (h == nullptr || raw == nullptr || size == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
}
RPC_API int rpc_port_parcel_create_from_raw(rpc_port_parcel_h* h,
- const void* raw, unsigned int size) {
+ const void* raw,
+ unsigned int size) {
if (h == nullptr || raw == nullptr || size == 0)
return RPC_PORT_ERROR_INVALID_PARAMETER;
rpc_port_parcel_h parcel;
int ret = rpc_port_parcel_create(&parcel);
- if (ret != RPC_PORT_ERROR_NONE)
- return ret;
+ if (ret != RPC_PORT_ERROR_NONE) return ret;
ret = rpc_port_parcel_from_array(parcel, raw, size);
if (ret != RPC_PORT_ERROR_NONE) {
rpc_port_parcel_destroy(parcel); // LCOV_EXCL_LINE
- return ret; // LCOV_EXCL_LINE
+ return ret; // LCOV_EXCL_LINE
}
*h = parcel;
}
RPC_API int rpc_port_parcel_create_without_header(rpc_port_parcel_h* h) {
- if (h == nullptr)
- return RPC_PORT_ERROR_INVALID_PARAMETER;
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
auto* parcel = new (std::nothrow) internal::Parcel(true);
- if (parcel == nullptr)
- return RPC_PORT_ERROR_OUT_OF_MEMORY;
+ if (parcel == nullptr) return RPC_PORT_ERROR_OUT_OF_MEMORY;
*h = static_cast<rpc_port_parcel_h>(parcel);
return RPC_PORT_ERROR_NONE;