From: Hwankyu Jhun Date: Thu, 11 Mar 2021 05:06:47 +0000 (+0900) Subject: Remove Bundle dependency from Parcel X-Git-Tag: submit/tizen/20210311.081932~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0326569840e73a99bf612ed8069c1662f95f44b9;p=platform%2Fcore%2Fbase%2Fbundle.git Remove Bundle dependency from Parcel Requires: - https://review.tizen.org/gerrit/#/c/platform/core/appfw/rpc-port/+/254967/ Change-Id: I8ecfc3b8eb1753485ca85d72f473e682dd862c61 Signed-off-by: Hwankyu Jhun --- diff --git a/parcel/api/parcel.h b/parcel/api/parcel.h index 886aa1a..6338030 100644 --- a/parcel/api/parcel.h +++ b/parcel/api/parcel.h @@ -19,7 +19,6 @@ #include #include -#include #include /** @@ -272,19 +271,6 @@ int parcel_write_double(parcel_h parcel, double val); 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 @@ -451,22 +437,6 @@ int parcel_read_double(parcel_h parcel, double *val); 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 diff --git a/parcel/parcel.cc b/parcel/parcel.cc index 9171895..c2cb30b 100644 --- a/parcel/parcel.cc +++ b/parcel/parcel.cc @@ -206,24 +206,6 @@ void Parcel::WriteCString(const char* str) { 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(raw, std::free); - - auto* p = reinterpret_cast(raw); - impl_->WriteSize(len + 1); - impl_->Write(p, len + 1); -} - -void Parcel::WriteBundle(const Bundle& b) { - auto raw = const_cast(b).ToRaw(); - auto* p = reinterpret_cast(raw.first.get()); - impl_->WriteSize(raw.second + 1); - impl_->Write(p, raw.second + 1); -} - int Parcel::ReadBool(bool* val) { return impl_->Read(val); } @@ -309,57 +291,6 @@ int Parcel::ReadCString(char** str) { 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(raw); - ret = impl_->Read(raw, len); - if (ret != TIZEN_ERROR_NONE) - return ret; - - *b = bundle_decode(reinterpret_cast(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(raw); - ret = impl_->Read(raw, len); - if (ret != TIZEN_ERROR_NONE) { - set_last_result(ret); - return {}; - } - - bundle* b = bundle_decode(reinterpret_cast(raw), len); - if (b == nullptr) - return {}; - - set_last_result(TIZEN_ERROR_NONE); - return Bundle(b, false, true); -} - const std::vector& Parcel::GetRaw() { return impl_->GetRaw(); } diff --git a/parcel/parcel.hh b/parcel/parcel.hh index 1b5f731..d924c93 100644 --- a/parcel/parcel.hh +++ b/parcel/parcel.hh @@ -22,7 +22,6 @@ * @{ */ -#include #include #include @@ -210,20 +209,6 @@ class EXPORT Parcel final { 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 @@ -342,25 +327,6 @@ class EXPORT Parcel final { 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 diff --git a/parcel/parcel.pc.in b/parcel/parcel.pc.in index d7908b0..0238b17 100644 --- a/parcel/parcel.pc.in +++ b/parcel/parcel.pc.in @@ -8,7 +8,7 @@ includedir=${prefix}/include 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 diff --git a/parcel/stub.cc b/parcel/stub.cc index 24ec529..da80f8c 100644 --- a/parcel/stub.cc +++ b/parcel/stub.cc @@ -211,17 +211,6 @@ extern "C" EXPORT int parcel_write_string(parcel_h parcel, const char* str) { 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); - 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"); @@ -332,16 +321,6 @@ extern "C" EXPORT int parcel_read_string(parcel_h parcel, char** str) { 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); - return h->ReadCBundle(b); -} - extern "C" EXPORT int parcel_reset_reader(parcel_h parcel) { if (parcel == nullptr) { _E("Invalid parameter"); diff --git a/tests/parcel_unittests/test_parcel.cc b/tests/parcel_unittests/test_parcel.cc index 3fef107..a8aaa97 100644 --- a/tests/parcel_unittests/test_parcel.cc +++ b/tests/parcel_unittests/test_parcel.cc @@ -271,28 +271,6 @@ TEST_F(ParcelTest, parcel_write_string_N) { 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::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); @@ -449,28 +427,6 @@ TEST_F(ParcelTest, parcel_read_string_N) { 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::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); diff --git a/tests/parcel_unittests/test_parcel_cpp.cc b/tests/parcel_unittests/test_parcel_cpp.cc index 2c2f910..d3e5af0 100644 --- a/tests/parcel_unittests/test_parcel_cpp.cc +++ b/tests/parcel_unittests/test_parcel_cpp.cc @@ -183,31 +183,6 @@ TEST_F(ParcelCppTest, WriteCString_AND_ReadCString) { 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(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();