#include <stdint.h>
#include <stddef.h>
-#include <bundle.h>
#include <tizen.h>
/**
int parcel_write_string(parcel_h parcel, const char *str);
/**
- * @brief Writes a bundle data into the parcel handle.
- * @since_tizen 6.5
- * @param[in] parcel The parcel handle
- * @param[in] b The bundle data
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #PARCEL_ERROR_NONE Successful
- * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
- * @see parcel_read_bundle()
- */
-int parcel_write_bundle(parcel_h parcel, bundle* b);
-
-/**
* @brief Reads a boolean value from the parcel handle.
* @since_tizen 6.5
* @param[in] parcel The parcel handle
int parcel_read_string(parcel_h parcel, char **str);
/**
- * @brief Reads a bundle data from the parcel handle.
- * @since_tizen 6.5
- * @param[in] parcel The parcel handle
- * @param[out] val The bundle data
- * @return @c 0 on success,
- * otherwise a negative error value
- * @retval #PARCEL_ERROR_NONE Successful
- * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #PARCEL_ERROR_NO_DATA No data available
- * @retval #PARCEL_ERROR_ILLEGAL_BYTE_SEQ Illegal byte sequence
- * @retval #PARCEL_ERROR_OUT_OF_MEMORY Out of memory
- * @see parcel_write_uint8()
- */
-int parcel_read_bundle(parcel_h parcel, bundle **b);
-
-/**
* @brief Resets the reader pointer of the parcel handle to the start.
* @since_tizen 6.5
* @param[in] parcel The parcel handle
impl_->Write(str, strlen(str) + 1);
}
-void Parcel::WriteCBundle(bundle* b) {
- 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);
-
- auto* p = reinterpret_cast<void*>(raw);
- impl_->WriteSize(len + 1);
- impl_->Write(p, len + 1);
-}
-
-void Parcel::WriteBundle(const Bundle& b) {
- auto raw = const_cast<Bundle&>(b).ToRaw();
- auto* p = reinterpret_cast<void*>(raw.first.get());
- impl_->WriteSize(raw.second + 1);
- impl_->Write(p, raw.second + 1);
-}
-
int Parcel::ReadBool(bool* val) {
return impl_->Read<bool>(val);
}
return TIZEN_ERROR_NONE;
}
-int Parcel::ReadCBundle(bundle** b) {
- uint32_t len = 0;
- int ret = impl_->ReadSize(&len);
- if (ret != TIZEN_ERROR_NONE)
- return ret;
-
- uint8_t* raw = new (std::nothrow) uint8_t [len];
- if (raw == nullptr)
- return TIZEN_ERROR_OUT_OF_MEMORY;
-
- auto ptr = std::unique_ptr<uint8_t[]>(raw);
- ret = impl_->Read(raw, len);
- if (ret != TIZEN_ERROR_NONE)
- return ret;
-
- *b = bundle_decode(reinterpret_cast<bundle_raw*>(raw), len);
- if (*b == nullptr)
- return get_last_result();
-
- return TIZEN_ERROR_NONE;
-}
-
-Bundle Parcel::ReadBundle() {
- uint32_t len = 0;
- int ret = impl_->ReadSize(&len);
- if (ret != TIZEN_ERROR_NONE) {
- set_last_result(ret);
- return {};
- }
-
- uint8_t* raw = new (std::nothrow) uint8_t [len];
- if (raw == nullptr) {
- set_last_result(TIZEN_ERROR_OUT_OF_MEMORY);
- return {};
- }
-
- auto ptr = std::unique_ptr<uint8_t[]>(raw);
- ret = impl_->Read(raw, len);
- if (ret != TIZEN_ERROR_NONE) {
- set_last_result(ret);
- return {};
- }
-
- bundle* b = bundle_decode(reinterpret_cast<bundle_raw*>(raw), len);
- if (b == nullptr)
- return {};
-
- set_last_result(TIZEN_ERROR_NONE);
- return Bundle(b, false, true);
-}
-
const std::vector<uint8_t>& Parcel::GetRaw() {
return impl_->GetRaw();
}
* @{
*/
-#include <bundle_cpp.h>
#include <tizen.h>
#include <memory>
void WriteCString(const char* str);
/**
- * @brief Writes a bundle data into the parcel.
- * @since_tizen 6.5
- * @param[in] b The bundle data
- */
- void WriteCBundle(bundle* b);
-
- /**
- * @brief Writes a bundle data into the parcel.
- * @since_tizen 6.5
- * @param[in] b The bundle data
- */
- void WriteBundle(const Bundle& b);
-
- /**
* @brief Reads a boolean value from the parcel.
* @since_tizen 6.5
* @param[out] val The boolean value
int ReadCString(char** str);
/**
- * @brief Reads a bundle data from the parcel.
- * @since_tizen 6.5
- * @remarks You should release @a b using bundle_free().
- * @param[out] b The bundle data
- * @return @c 0 on success,
- * otherwise a negative error value
- */
- int ReadCBundle(bundle** b);
-
- /**
- * @brief Reads a bundle data from the parcel.
- * @since_tizen 6.5
- * @return The bundle data
- * @remarks Before using the returned value, you should check the result using get_last_result().
- * @see get_last_result();
- */
- Bundle ReadBundle();
-
- /**
* @brief Gets the raw data of the parcel.
* @since_tizen 6.5
* @return The raw data
Name: parcel
Description: Parcel library
Version: @VERSION@
-Requires: capi-base-common bundle
-Libs: -L${libdir} -lparcel -lbundle
+Requires: capi-base-common
+Libs: -L${libdir} -lparcel
Cflags: -I${includedir} -I${includedir}/parcel
cppflags: -I${includedir} -I${includedir}/parcel
return PARCEL_ERROR_NONE;
}
-extern "C" EXPORT int parcel_write_bundle(parcel_h parcel, bundle* b) {
- if (parcel == nullptr || b == nullptr) {
- _E("Invalid parameter");
- return PARCEL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<Parcel*>(parcel);
- h->WriteCBundle(b);
- return PARCEL_ERROR_NONE;
-}
-
extern "C" EXPORT int parcel_read_bool(parcel_h parcel, bool* val) {
if (parcel == nullptr || val == nullptr) {
_E("Invalid parameter");
return h->ReadCString(str);
}
-extern "C" EXPORT int parcel_read_bundle(parcel_h parcel, bundle** b) {
- if (parcel == nullptr || b == nullptr) {
- _E("Invalid parameter");
- return PARCEL_ERROR_INVALID_PARAMETER;
- }
-
- auto* h = static_cast<Parcel*>(parcel);
- return h->ReadCBundle(b);
-}
-
extern "C" EXPORT int parcel_reset_reader(parcel_h parcel) {
if (parcel == nullptr) {
_E("Invalid parameter");
ASSERT_EQ(ret, PARCEL_ERROR_INVALID_PARAMETER);
}
-TEST_F(ParcelTest, parcel_write_bundle_P) {
- bundle* b = bundle_create();
- bundle_add_str(b, "Key", "Value");
- int ret = parcel_write_bundle(GetHandle(), b);
- bundle_free(b);
- ASSERT_EQ(ret, PARCEL_ERROR_NONE);
- b = nullptr;
- ret = parcel_read_bundle(GetHandle(), &b);
- ASSERT_NE(b, nullptr);
- auto ptr = std::unique_ptr<std::remove_pointer<bundle>::type,
- decltype(bundle_free)*>(b, bundle_free);
- ASSERT_EQ(ret, PARCEL_ERROR_NONE);
- char* str = nullptr;
- bundle_get_str(b, "Key", &str);
- ASSERT_EQ(std::string(str), "Value");
-}
-
-TEST_F(ParcelTest, parcel_write_bundle_N) {
- int ret = parcel_write_bundle(nullptr, nullptr);
- ASSERT_EQ(ret, PARCEL_ERROR_INVALID_PARAMETER);
-}
-
TEST_F(ParcelTest, parcel_read_bool_P) {
int ret = parcel_write_bool(GetHandle(), false);
ASSERT_EQ(ret, PARCEL_ERROR_NONE);
ASSERT_EQ(ret, PARCEL_ERROR_INVALID_PARAMETER);
}
-TEST_F(ParcelTest, parcel_read_bundle_P) {
- bundle* b = bundle_create();
- bundle_add_str(b, "Key", "Value");
- int ret = parcel_write_bundle(GetHandle(), b);
- bundle_free(b);
- ASSERT_EQ(ret, PARCEL_ERROR_NONE);
- b = nullptr;
- ret = parcel_read_bundle(GetHandle(), &b);
- ASSERT_NE(b, nullptr);
- auto ptr = std::unique_ptr<std::remove_pointer<bundle>::type,
- decltype(bundle_free)*>(b, bundle_free);
- ASSERT_EQ(ret, PARCEL_ERROR_NONE);
- char* str = nullptr;
- bundle_get_str(b, "Key", &str);
- ASSERT_EQ(std::string(str), "Value");
-}
-
-TEST_F(ParcelTest, parcel_read_bundle_N) {
- int ret = parcel_read_bundle(nullptr, nullptr);
- ASSERT_EQ(ret, PARCEL_ERROR_INVALID_PARAMETER);
-}
-
TEST_F(ParcelTest, parcel_reset_reader_P) {
int ret = parcel_reset_reader(GetHandle());
ASSERT_EQ(ret, PARCEL_ERROR_NONE);
ASSERT_EQ(std::string(str), "TestCString");
}
-TEST_F(ParcelCppTest, WriteCBundle_AND_ReadCBundle) {
- bundle* b = bundle_create();
- bundle_add_str(b, "Key", "Value");
- GetHandle().WriteCBundle(b);
- bundle_free(b);
- bundle* val = nullptr;
- int ret = GetHandle().ReadCBundle(&val);
- auto ptr = std::unique_ptr<bundle, decltype(bundle_free)*>(val, bundle_free);
- ASSERT_EQ(ret, Parcel::Error::None);
- ASSERT_NE(val, nullptr);
- char* str = nullptr;
- bundle_get_str(val, "Key", &str);
- ASSERT_EQ(std::string(str), "Value");
-}
-
-TEST_F(ParcelCppTest, WriteBundle_AND_ReadBundle) {
- Bundle b;
- b.Add("Key", "Value");
- GetHandle().WriteBundle(b);
- auto val = GetHandle().ReadBundle();
- ASSERT_EQ(get_last_result(), Parcel::Error::None);
- auto str = val.GetString("Key");
- ASSERT_EQ(str, "Value");
-}
-
TEST_F(ParcelCppTest, GetRaw) {
GetHandle().WriteInt32(0);
auto& raw = GetHandle().GetRaw();