Add new internal API for parcel 31/319431/5
authorpjh9216 <jh9216.park@samsung.com>
Wed, 23 Oct 2024 04:46:49 +0000 (13:46 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Wed, 30 Oct 2024 04:02:53 +0000 (04:02 +0000)
Change-Id: I61797a337dd9bcb50908db92379cf40f3576c07f
Signed-off-by: pjh9216 <jh9216.park@samsung.com>
src/parcel/api/parcel.h
src/parcel/parcel.cc
src/parcel/parcel.hh
src/parcel/parcel_implementation.hh
src/parcel/stub.cc
tests/parcel_unittests/test_parcel.cc

index d16909c91f55306acb144faa9dc4f29a10d2a1c9..87642b811d4cc7a6c769f684c5d26cd0fd341e99 100644 (file)
@@ -460,6 +460,18 @@ int parcel_read_string(parcel_h parcel, char **str);
  */
 int parcel_reset_reader(parcel_h parcel);
 
+/**
+ * @brief Sets the reader pointer of the handle to the given position.
+ * @since_tizen 10.0
+ * @param[in] parcel The parcel handle
+ * @param[in] pos The position to set
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #PARCEL_ERROR_NONE Successful
+ * @retval #PARCEL_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int parcel_set_reader(parcel_h parcel, uint32_t pos);
+
 /**
  * @brief Clears the data of the parcel handle.
  * @since_tizen 6.5
index 343ae9db5c0e3f20499b2168df09e006bd1c2b7c..fc1e873515b5c80ca4d3f8b0ecaa8b760b684e7a 100644 (file)
@@ -77,6 +77,13 @@ void Parcel::Impl::ResetReader() {
   reader_ = 0;
 }
 
+bool Parcel::Impl::SetReader(uint32_t pos) {
+  if (pos > data_size_)
+    return false;
+  reader_ = pos;
+  return true;
+}
+
 void Parcel::Impl::Clear() {
   data_size_ = 0;
   reader_ = 0;
@@ -507,6 +514,10 @@ void Parcel::ResetReader() {
   impl_->ResetReader();
 }
 
+bool Parcel::SetReader(uint32_t pos) {
+  return impl_->SetReader(pos);
+}
+
 void Parcel::Clear() {
   impl_->Clear();
 }
index 965a2082fcae1e0f77b028d412fb06eae205559c..e934f3fe4545ef70b5364f4f761acd390a55a650 100644 (file)
@@ -343,6 +343,15 @@ class EXPORT Parcel final {
    */
   void ResetReader();
 
+  /**
+   * @brief Sets the reader pointer of the handle to the given position.
+   * @since_tizen 10.0
+   * @param[in] pos The position to set
+   * @return @c true on success,
+   *         otherwise false
+   */
+  bool SetReader(uint32_t pos);
+
   /**
    * @brief Clears the data of the parcel.
    * @since_tizen 6.5
index d6951f109304c9298ab22f809072944c3300a1f8..dbf076a366e2167036b2fc25edcfc32c05889414 100644 (file)
@@ -32,6 +32,7 @@ class Parcel::Impl {
   void Write(const void* buf, uint32_t size);
   int Read(void* buf, uint32_t size);
   void ResetReader();
+  bool SetReader(uint32_t pos);
   void Clear();
   void Reset(const void* buf, uint32_t size);
   bool IsEmpty();
index bf2a78c64bccd808e88d6cf107c82267ba67cf40..da4ca6eb71d7e5e657756c81ec0b3cb52a22e0fb 100644 (file)
@@ -346,6 +346,18 @@ extern "C" EXPORT int parcel_reset_reader(parcel_h parcel) {
   return PARCEL_ERROR_NONE;
 }
 
+extern "C" EXPORT int parcel_set_reader(parcel_h parcel, uint32_t pos) {
+  if (parcel == nullptr) {
+    _E("Invalid parameter");
+    return PARCEL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* h = static_cast<Parcel*>(parcel);
+  if (h->SetReader(pos))
+    return PARCEL_ERROR_NONE;
+  return PARCEL_ERROR_INVALID_PARAMETER;
+}
+
 extern "C" EXPORT int parcel_clear(parcel_h parcel) {
   if (parcel == nullptr) {
     _E("Invalid parameter");
index 28c049d14b8ddf4f0e80eda4d8276ae287b2cb35..ef08bb3e687466ee25b4267055d1f87b3c72c5d3 100644 (file)
@@ -437,6 +437,27 @@ TEST_F(ParcelTest, parcel_reset_reader_N) {
   ASSERT_EQ(ret, PARCEL_ERROR_INVALID_PARAMETER);
 }
 
+TEST_F(ParcelTest, parcel_set_reader_P) {
+  parcel_write_uint32(GetHandle(), 1);
+  parcel_write_uint32(GetHandle(), 2);
+  parcel_write_uint32(GetHandle(), 3);
+  int ret = parcel_set_reader(GetHandle(), 4);
+  int32_t val = 0;
+  parcel_read_int32(GetHandle(), &val);
+  ASSERT_EQ(ret, PARCEL_ERROR_NONE);
+  ASSERT_EQ(val, 2);
+}
+
+TEST_F(ParcelTest, parcel_set_reader_N1) {
+  int ret = parcel_set_reader(nullptr, 0);
+  ASSERT_EQ(ret, PARCEL_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(ParcelTest, parcel_set_reader_N2) {
+  int ret = parcel_set_reader(GetHandle(), 100);
+  ASSERT_EQ(ret, PARCEL_ERROR_INVALID_PARAMETER);
+}
+
 TEST_F(ParcelTest, parcel_clear_P) {
   int ret = parcel_clear(GetHandle());
   ASSERT_EQ(ret, PARCEL_ERROR_NONE);