* limitations under the License.
*/
-#include <parcel.h>
+#include <parcel.hh>
#include <stdint.h>
#include <string.h>
#include "include/rpc-port-parcel.h"
#include "log-private.hh"
+#include "parcel-internal.hh"
#include "port-internal.hh"
#define MAX_PARCEL_SIZE (1024 * 1024 * 10)
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_h parcel = nullptr;
- int ret = parcel_create(&parcel);
- if (ret != PARCEL_ERROR_NONE)
- return __convert_parcel_error(ret);
+ auto* parcel = new (std::nothrow) internal::Parcel();
+ if (parcel == nullptr)
+ return RPC_PORT_ERROR_OUT_OF_MEMORY;
*h = static_cast<rpc_port_parcel_h>(parcel);
return RPC_PORT_ERROR_NONE;
if (len <= 0 || len > MAX_PARCEL_SIZE)
return RPC_PORT_ERROR_IO_ERROR;
- buf = new unsigned char[len];
+ buf = new (std::nothrow) unsigned char[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;
}
}
- parcel_h parcel = nullptr;
- int ret = parcel_create(&parcel);
- if (ret != PARCEL_ERROR_NONE) {
+ auto* parcel = new (std::nothrow) internal::Parcel();
+ if (parcel == nullptr) {
+ _E("Out of memory");
delete[] buf;
return RPC_PORT_ERROR_IO_ERROR;
}
- parcel_burst_write(parcel, buf, len);
+ tizen_base::Parcel raw_parcel(buf, len);
+ raw_parcel.ReadParcelable(parcel);
delete[] buf;
*h = static_cast<rpc_port_parcel_h>(parcel);
return RPC_PORT_ERROR_NONE;
if (h == nullptr || port == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- void* raw = nullptr;
- uint32_t len = 0;
- parcel_get_raw(parcel, &raw, &len);
-
+ 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();
if (len <= 0)
return RPC_PORT_ERROR_INVALID_PARAMETER;
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- parcel_destroy(parcel);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ delete parcel;
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- parcel_write_byte(parcel, b);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ parcel_write_byte(parcel->GetHandle(), b);
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- parcel_write_int16(parcel, i);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ parcel_write_int16(parcel->GetHandle(), i);
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- parcel_write_int32(parcel, i);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ parcel_write_int32(parcel->GetHandle(), i);
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- parcel_write_int64(parcel, i);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ parcel_write_int64(parcel->GetHandle(), i);
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- parcel_write_float(parcel, f);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ parcel_write_float(parcel->GetHandle(), f);
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- parcel_write_double(parcel, d);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ parcel_write_double(parcel->GetHandle(), d);
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr || str == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- parcel_write_string(parcel, str);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ parcel_write_string(parcel->GetHandle(), str);
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- parcel_write_bool(parcel, b);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ parcel_write_bool(parcel->GetHandle(), b);
return RPC_PORT_ERROR_NONE;
}
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_string(parcel, reinterpret_cast<char*>(raw));
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ parcel_write_string(parcel->GetHandle(), reinterpret_cast<char*>(raw));
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- parcel_write_int32(parcel, count);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ parcel_write_int32(parcel->GetHandle(), count);
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr || b == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- int ret = parcel_read_byte(parcel, b);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ int ret = parcel_read_byte(parcel->GetHandle(), b);
if (ret != PARCEL_ERROR_NONE)
_E("parcel_read_byte() is failed. error(%d)", ret);
if (h == nullptr || i == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- int ret = parcel_read_int16(parcel, i);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ int ret = parcel_read_int16(parcel->GetHandle(), i);
if (ret != PARCEL_ERROR_NONE)
_E("parcel_read_int16() is failed. error(%d)", ret);
if (h == nullptr || i == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- int ret = parcel_read_int32(parcel, i);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ int ret = parcel_read_int32(parcel->GetHandle(), i);
if (ret != PARCEL_ERROR_NONE)
_E("parcel_read_int32() is failed. error(%d)", ret);
if (h == nullptr || i == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
+ auto* parcel = static_cast<internal::Parcel*>(h);
int64_t val = 0;
- int ret = parcel_read_int64(parcel, &val);
+ int ret = parcel_read_int64(parcel->GetHandle(), &val);
if (ret != PARCEL_ERROR_NONE)
_E("parcel_read_int64() is failed. error(%d)", ret);
if (h == nullptr || f == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- int ret = parcel_read_float(parcel, f);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ int ret = parcel_read_float(parcel->GetHandle(), f);
if (ret != PARCEL_ERROR_NONE)
_E("parcel_read_float() is failed. error(%d)", ret);
if (h == nullptr || d == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- int ret = parcel_read_double(parcel, d);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ int ret = parcel_read_double(parcel->GetHandle(), d);
if (ret != PARCEL_ERROR_NONE)
_E("parcel_read_double() is failed. error(%d)", ret);
if (h == nullptr || str == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- int ret = parcel_read_string(parcel, str);
+ 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);
*str = strdup("");
if (h == nullptr || b == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- int ret = parcel_read_bool(parcel, b);
- if (ret != PARCEL_ERROR_NONE)
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ int ret = parcel_read_bool(parcel->GetHandle(), b);
+ if (ret != 0)
_E("parcel_read_bool() is failed. error(%d)", ret);
return RPC_PORT_ERROR_NONE;
if (h == nullptr || b == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
+ auto* parcel = static_cast<internal::Parcel*>(h);
char* raw = nullptr;
- int ret = parcel_read_string(parcel, &raw);
- if (ret != PARCEL_ERROR_NONE) {
+ int ret = parcel_read_string(parcel->GetHandle(), &raw);
+ if (ret != 0) {
_E("parcel_read_string() is failed. error(%d)", ret);
*b = bundle_create();
} else {
if (h == nullptr || count == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- int ret = parcel_read_int32(parcel, count);
- if (ret != PARCEL_ERROR_NONE)
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ int ret = parcel_read_int32(parcel->GetHandle(), count);
+ if (ret != 0)
_E("parcel_read_int32() is failed. error(%d)", ret);
return RPC_PORT_ERROR_NONE;
return RPC_PORT_ERROR_INVALID_PARAMETER;
parcelable->from(h, data);
-
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr || buf == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
+ auto* parcel = static_cast<internal::Parcel*>(h);
uint32_t valid_size = size & UINT32_MAX;
- int ret = parcel_burst_read(parcel, static_cast<void*>(buf), valid_size);
+ int ret = parcel_burst_read(parcel->GetHandle(), static_cast<void*>(buf),
+ valid_size);
if (ret != PARCEL_ERROR_NONE)
- _E("parcel_burst_read() is failed. error(%d)", ret);
+ _E("parcel_read() is failed. error(%d)", ret);
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr || buf == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
+ auto* parcel = static_cast<internal::Parcel*>(h);
uint32_t valid_size = size & UINT32_MAX;
- parcel_burst_write(parcel, static_cast<const void*>(buf), valid_size);
+ parcel_burst_write(parcel->GetHandle(), static_cast<const void*>(buf),
+ valid_size);
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
- parcel_reset_reader(parcel);
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ parcel_reset_reader(parcel->GetHandle());
return RPC_PORT_ERROR_NONE;
}
if (h == nullptr || !array || !size)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
+ auto* parcel = static_cast<internal::Parcel*>(h);
void* raw = nullptr;
uint32_t raw_size = 0;
- parcel_get_raw(parcel, &raw, &raw_size);
+ parcel_get_raw(parcel->GetHandle(), &raw, &raw_size);
+ if (raw_size == 0) {
+ _E("raw_size is zero");
+ return RPC_PORT_ERROR_IO_ERROR;
+ }
void* array_ptr = malloc(raw_size);
if (array_ptr == nullptr)
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)
+ if (h == nullptr || array == nullptr || size == 0)
return RPC_PORT_ERROR_INVALID_PARAMETER;
- parcel_h parcel = static_cast<parcel_h>(h);
+ auto* parcel = static_cast<internal::Parcel*>(h);
uint32_t valid_size = size & UINT32_MAX;
- parcel_reset(parcel, array, valid_size);
+ parcel_reset(parcel->GetHandle(), array, valid_size);
+ return RPC_PORT_ERROR_NONE;
+}
+
+RPC_API int rpc_port_parcel_get_header(rpc_port_parcel_h h,
+ 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();
+ *header = reinterpret_cast<rpc_port_parcel_header_h>(
+ const_cast<internal::ParcelHeader*>(parcel_header));
+ 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;
+
+ auto* parcel_header = static_cast<internal::ParcelHeader*>(header);
+ parcel_header->SetSeqNum(seq_num);
+ return RPC_PORT_ERROR_NONE;
+}
+
+RPC_API int rpc_port_parcel_header_get_seq_num(rpc_port_parcel_header_h header,
+ int* seq_num) {
+ if (header == nullptr || seq_num == nullptr)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel_header = static_cast<internal::ParcelHeader*>(header);
+ *seq_num = parcel_header->GetSeqNum();
+ return RPC_PORT_ERROR_NONE;
+}
+
+RPC_API int rpc_port_parcel_header_get_timestamp(
+ rpc_port_parcel_header_h header, struct timespec* timestamp) {
+ if (header == nullptr || timestamp == nullptr)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel_header = static_cast<internal::ParcelHeader*>(header);
+ *timestamp = parcel_header->GetTimeStamp();
return RPC_PORT_ERROR_NONE;
}
ASSERT_EQ(buf[i], buf2[i]);
}
}
+
+/*
+ * @testcase rpc_port_parcel_get_header_P
+ * @description Gets the header handle from the rpc port parcel handle
+ * @apicovered rpc_port_parcel_get_header
+ */
+TEST_F(ParcelTest, rpc_port_parcel_get_header_P) {
+ rpc_port_parcel_header_h header = nullptr;
+ int ret = rpc_port_parcel_get_header(handle_, &header);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ASSERT_NE(header, nullptr);
+}
+
+/*
+ * @testcase rpc_port_parcel_get_header_N
+ * @description Gets the header handle from the rpc port parcel handle
+ * @apicovered rpc_port_parcel_get_header
+ */
+TEST_F(ParcelTest, rpc_port_parcel_get_header_N) {
+ int ret = rpc_port_parcel_get_header(nullptr, nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+}
+
+/*
+ * @testcase rpc_port_parcel_header_set_get_seq_num_P
+ * @description Sets and Gets the sequence number
+ * @apicovered rpc_port_parcel_header_set_seq_num, rpc_port_parcel_header_get_seq_num
+ */
+TEST_F(ParcelTest, rpc_port_parcel_header_set_get_seq_num_P) {
+ rpc_port_parcel_header_h header = nullptr;
+ int ret = rpc_port_parcel_get_header(handle_, &header);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ ret = rpc_port_parcel_header_set_seq_num(header, 100);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ int seq_num = 0;
+ ret = rpc_port_parcel_header_get_seq_num(header, &seq_num);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ASSERT_EQ(seq_num, 100);
+}
+
+/*
+ * @testcase rpc_port_parcel_header_set_get_seq_num_N
+ * @description Sets and Gets the sequence number
+ * @apicovered rpc_port_parcel_header_set_seq_num, rpc_port_parcel_header_get_seq_num
+ */
+TEST_F(ParcelTest, rpc_port_parcel_header_set_get_seq_num_N) {
+ int ret = rpc_port_parcel_header_set_seq_num(nullptr, -1);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+
+ ret = rpc_port_parcel_header_get_seq_num(nullptr, nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+}
+
+/*
+ * @testcase rpc_port_parcel_header_get_timestamp_P
+ * @description Gets the timestamp from the header handle of the rpc port parcel
+ * @apicovered rpc_port_parcel_header_get_timestamp
+ */
+TEST_F(ParcelTest, rpc_port_parcel_header_get_timestamp_P) {
+ rpc_port_parcel_header_h header = nullptr;
+ int ret = rpc_port_parcel_get_header(handle_, &header);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ struct timespec timestamp = { 0, };
+ ret = rpc_port_parcel_header_get_timestamp(header, ×tamp);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ ASSERT_NE(timestamp.tv_sec, 0);
+ ASSERT_NE(timestamp.tv_nsec, 0);
+}
+
+/*
+ * @testcase rpc_port_parcel_header_get_timestamp_N
+ * @description Gets the timestamp from the header handle of the rpc port parcel
+ * @apicovered rpc_port_parcel_header_get_timestamp
+ */
+TEST_F(ParcelTest, rpc_port_parcel_header_get_timestamp_N) {
+ int ret = rpc_port_parcel_header_get_timestamp(nullptr, nullptr);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
+}