summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2019-07-31 18:14:41 +0900
committerHwanKyu Jhun <h.jhun@samsung.com>2019-08-09 00:58:07 +0000
commita09e06e4d491de7a986f69e15a2b942d69e4b7b5 (patch)
tree05bf2a459b5f386ccc55e6254e899abdbb6a2e57
parenta4629cfccf5f9cb40fc266afbfaeef5177aee0a5 (diff)
downloadbundle-a09e06e4d491de7a986f69e15a2b942d69e4b7b5.tar.gz
bundle-a09e06e4d491de7a986f69e15a2b942d69e4b7b5.tar.bz2
bundle-a09e06e4d491de7a986f69e15a2b942d69e4b7b5.zip
Support setter/getter methods for byte array type
The following functions are moved from internal header: - bundle_add_byte_array() - bundle_set_byte_array_element() - bundle_get_byte_array() Change-Id: I3a2c07df65ae3db46c984674a0d2c4cc3d253544 Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rwxr-xr-xinclude/bundle.h86
-rwxr-xr-xinclude/bundle_internal.h100
-rw-r--r--src/bundle.c20
3 files changed, 86 insertions, 120 deletions
diff --git a/include/bundle.h b/include/bundle.h
index ce1e1ff..9ace22d 100755
--- a/include/bundle.h
+++ b/include/bundle.h
@@ -48,7 +48,8 @@ typedef enum {
BUNDLE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
BUNDLE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
BUNDLE_ERROR_KEY_NOT_AVAILABLE = TIZEN_ERROR_KEY_NOT_AVAILABLE, /**< Required key not available */
- BUNDLE_ERROR_KEY_EXISTS = TIZEN_ERROR_BUNDLE | 0x01 /**< Key exists */
+ BUNDLE_ERROR_KEY_EXISTS = TIZEN_ERROR_BUNDLE | 0x01, /**< Key exists */
+ BUNDLE_ERROR_ARRAY_INDEX_OUT_OF_BOUNDS = TIZEN_ERROR_BUNDLE | 0x02 /**< The index is out of bounds of the array */
} bundle_error_e;
@@ -499,12 +500,13 @@ API int bundle_add_str(bundle *b, const char *key, const char *str);
/**
- * @brief Adds a byte type key-value pair into a bundle.
+ * @brief Adds a byte sequence type key-value pair into a bundle.
+ * @details The bundle will contain a copy of the added byte sequence.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
* @param[in] b The bundle object
* @param[in] key The key
- * @param[in] byte The string type value
- * @param[in] size The size of @a byte
+ * @param[in] bytes The byte sequence
+ * @param[in] size The byte sequence size in bytes
* @return The operation result
* @retval BUNDLE_ERROR_NONE Success
* @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
@@ -524,7 +526,7 @@ API int bundle_add_str(bundle *b, const char *key, const char *str);
bundle_free(b);
* @endcode
*/
-API int bundle_add_byte(bundle *b, const char *key, const void *byte, const size_t size);
+API int bundle_add_byte(bundle *b, const char *key, const void *bytes, const size_t size);
/**
@@ -557,13 +559,13 @@ API int bundle_get_str(bundle *b, const char *key, char **str);
/**
- * @brief Gets the byte value with the given key.
+ * @brief Gets the byte sequence with the given key.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
* @remarks You must not free @a byte.
* @param[in] b The bundle object
* @param[in] key The key
- * @param[out] byte The returned value
- * @param[out] size The size of the byte
+ * @param[out] bytes The byte sequence
+ * @param[out] size The byte sequence size in bytes
* @return The operation result
* @retval BUNDLE_ERROR_NONE Success
* @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
@@ -588,7 +590,73 @@ API int bundle_get_str(bundle *b, const char *key, char **str);
bundle_free(b); // After freeing b, v and n become a dangling pointer
* @endcode
*/
-API int bundle_get_byte(bundle *b, const char *key, void **byte, size_t *size);
+API int bundle_get_byte(bundle *b, const char *key, void **bytes, size_t *size);
+
+/**
+ * @brief Adds an 'array of byte sequences' type key-value pair into a bundle.
+ * @since_tizen 5.5
+ * @remarks To set the value of the byte array element, you should use bundle_set_byte_array_element().
+ * This function is only for creating a buffer of the byte array.
+ *
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[in] len The length of the array to be created
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #BUNDLE_ERROR_NONE Successful
+ * @retval #BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BUNDLE_ERROR_KEY_EXISTS Key already exists
+ * @retval #BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
+ *
+ * @see bundle_get_byte_array()
+ * @see bundle_set_byte_array_element()
+ */
+API int bundle_add_byte_array(bundle *b, const char *key, const unsigned int len);
+
+/**
+ * @brief Sets an element of an array of byte sequences.
+ * @since_tizen 5.5
+ * @details The array will contain its own copy of the added value.
+ *
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[in] idx The index of the array element to be changed
+ * @param[in] bytes The byte sequence
+ * @param[in] size The byte sequence size in bytes
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #BUNDLE_ERROR_NONE Successful
+ * @retval #BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
+ * @retval #BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #BUNDLE_ERROR_ARRAY_INDEX_OUT_OF_BOUNDS The index is out of bounds of the array
+ *
+ * @see bundle_add_byte_array()
+ * @see bundle_get_byte_array()
+ */
+API int bundle_set_byte_array_element(bundle *b, const char *key, const unsigned int idx, const void *bytes, const size_t size);
+
+/**
+ * @brief Gets the array of byte sequences with the given key.
+ * @since_tizen 5.5
+ * @remarks You should not release @a byte_array, @a len and @a array_element_size.
+ * @a byte_array, @a len and @a array_element_size will be released when the bundle containing them is released with bundle_free().
+ *
+ * @param[in] b The bundle object
+ * @param[in] key The key
+ * @param[out] byte_array The array pointer of the byte value
+ * @param[out] len The array length
+ * @param[out] array_element_size An array of sizes of each @a byte_array element
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #BUNDLE_ERROR_NONE Successful
+ * @retval #BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
+ *
+ * @see bundle_add_byte_array()
+ * @see bundle_set_byte_array_element()
+*/
+API int bundle_get_byte_array(bundle *b, const char *key, void ***byte_array, unsigned int *len, unsigned int **array_element_size);
#ifdef __cplusplus
}
diff --git a/include/bundle_internal.h b/include/bundle_internal.h
index 59499b2..a64d7d9 100755
--- a/include/bundle_internal.h
+++ b/include/bundle_internal.h
@@ -341,106 +341,6 @@ API bundle *bundle_import_from_argv(int argc, char **argv);
API int bundle_set_str_array_element(bundle *b, const char *key, const unsigned int idx, const char *val);
/**
- * @brief Adds a byte array type key-value pair into a bundle.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] b The bundle object
- * @param[in] key The key
- * @param[in] byte_array Not used
- * @param[in] len The length of the array to be created
- * @return The operation result
- * @retval BUNDLE_ERROR_NONE Success
- * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval BUNDLE_ERROR_KEY_EXISTS Key already exists
- * @retval BUNDLE_ERROR_OUT_OF_MEMORY Out of memory
- * @pre @a b must be a valid bundle object.
- * @see bundle_get_byte_array()
- * @see bundle_set_byte_array_element()
- @code
- #include <bundle_internal.h>
- bundle *b = bundle_create();
- bundle_add_byte_array(b, "foo", NULL, 3); // add a byte-array with length 3
-
- bundle_set_byte_array_element(b, "foo", 0, "aaa\0", 4); array[0] = "aaa\0"
- bundle_set_byte_array_element(b, "foo", 1, "bbb\0", 4); array[1] = "bbb\0"
- bundle_set_byte_array_element(b, "foo", 2, "ccc\0", 4); array[2] = "ccc\0"
-
- bundle_free(b);
- @endcode
- */
-API int bundle_add_byte_array(bundle *b, const char *key, void **byte_array, const unsigned int len);
-
-/**
- * @brief Sets the value of the byte array element.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @param[in] b The bundle object
- * @param[in] key The key
- * @param[in] idx The index of the array element to be changed
- * @param[in] val The string type value; if @c NULL, an empty array is created; you can change an item with
- * @param[in] size The size of the value in bytes
- * @return Operation result
- * @retval BUNDLE_ERROR_NONE Success
- * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
- * @pre @a b must be a valid bundle object.
- * @see bundle_add_byte_array()
- * @see bundle_get_byte_array()
- @code
- #include <bundle_internal.h>
- bundle *b = bundle_create();
- bundle_add_byte_array(b, "foo", NULL, 3); // add a key-val pair
-
- bundle_set_byte_array_element(b, "foo", 0, "aaa\0", 4);
- bundle_set_byte_array_element(b, "foo", 1, "bbb\0", 4);
- bundle_set_byte_array_element(b, "foo", 2, "ccc\0", 4);
-
- unsigned char **byte_array = NULL;
- int len_byte_array = 0;
-
- bundle_get_byte_array(b, "foo", &byte_array, &len_byte_array, &size_byte_array);
- // byte_array = { "aaa\0", "bbb\0", "ccc\0" }, and len_byte_array = 3
-
- bundle_free(b);
- @endcode
- */
-API int bundle_set_byte_array_element(bundle *b, const char *key, const unsigned int idx, const void *val, const size_t size);
-
-/**
- * @brief Gets the byte array value with the given key.
- * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
- * @remarks You must not free str!
- * @param[in] b The bundle object
- * @param[in] key The key
- * @param[out] byte_array The returned value
- * @param[out] len The array length
- * @param[out] array_element_size an array of sizes of each @a byte_array element
- * @return The operation result
- * @retval BUNDLE_ERROR_NONE Success
- * @retval BUNDLE_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval BUNDLE_ERROR_KEY_NOT_AVAILABLE Key not available
- * @pre @a b must be a valid bundle object.
- * @see bundle_add_byte_array()
- * @see bundle_set_byte_array_element()
- @code
- #include <bundle_internal.h>
- bundle *b = bundle_create();
- bundle_add_byte_array(b, "foo", NULL, 3);
- bundle_set_byte_array_element(b, "foo", 0, "aaa\0", 4);
- bundle_set_byte_array_element(b, "foo", 1, "bbb\0", 4);
- bundle_set_byte_array_element(b, "foo", 2, "ccc\0", 4);
-
- char **byte_array = NULL;
- int len_byte_array = 0;
- size_t *size_byte_array = NULL;
-
- bundle_get_byte_array(b, "foo", &byte_array, &len_byte_array, &size_byte_array);
- // byte_array = { "aaa\0", "bbb\0", "ccc\0" }, len_byte_array = 3, and size_byte_array = { 4, 4, 4 }
-
- bundle_free(b);
- @endcode
- */
-API int bundle_get_byte_array(bundle *b, const char *key, void ***byte_array, unsigned int *len, unsigned int **array_element_size);
-
-/**
* @brief Creates a json data from bundle.
* @since_tizen 3.0
* @remarks This API only supports the string type and the string array type.
diff --git a/src/bundle.c b/src/bundle.c
index 4513486..333536a 100644
--- a/src/bundle.c
+++ b/src/bundle.c
@@ -989,7 +989,7 @@ static int bundle_set_array_val(bundle *b, const char *key, const int type,
kva = (keyval_array_t *)kv;
if (!keyval_array_is_idx_valid(kva, idx))
- return BUNDLE_ERROR_INVALID_PARAMETER;
+ return BUNDLE_ERROR_ARRAY_INDEX_OUT_OF_BOUNDS;
/* NULL value test (TODO: is this needed?) */
if (!kva->array_val)
@@ -1058,23 +1058,21 @@ int bundle_set_str_array_element(bundle *b, const char *key,
idx, val, strlen(val) + 1);
}
-int bundle_add_byte(bundle *b, const char *key, const void *byte,
+int bundle_add_byte(bundle *b, const char *key, const void *bytes,
const size_t size)
{
- return _bundle_add_kv(b, key, byte, size, BUNDLE_TYPE_BYTE, 1);
+ return _bundle_add_kv(b, key, bytes, size, BUNDLE_TYPE_BYTE, 1);
}
-int bundle_get_byte(bundle *b, const char *key, void **byte, size_t *size)
+int bundle_get_byte(bundle *b, const char *key, void **bytes, size_t *size)
{
- return _bundle_get_val(b, key, BUNDLE_TYPE_BYTE, (void **)byte,
+ return _bundle_get_val(b, key, BUNDLE_TYPE_BYTE, (void **)bytes,
size, NULL, NULL);
}
-int bundle_add_byte_array(bundle *b, const char *key, void **byte_array,
- const unsigned int len)
+int bundle_add_byte_array(bundle *b, const char *key, const unsigned int len)
{
- return _bundle_add_kv(b, key, byte_array, 0,
- BUNDLE_TYPE_BYTE_ARRAY, len);
+ return bundle_init_byte_array(b, key, len);
}
int bundle_init_byte_array(bundle *b, const char *key, const unsigned int len)
@@ -1090,8 +1088,8 @@ int bundle_get_byte_array(bundle *b, const char *key, void ***byte_array,
}
int bundle_set_byte_array_element(bundle *b, const char *key,
- const unsigned int idx, const void *val, const size_t size)
+ const unsigned int idx, const void *bytes, const size_t size)
{
return bundle_set_array_val(b, key, BUNDLE_TYPE_BYTE_ARRAY,
- idx, val, size);
+ idx, bytes, size);
}