From 741342b1c9c12c273fbe838005c132baab6a6e0e Mon Sep 17 00:00:00 2001 From: gichan2-jang Date: Thu, 22 Aug 2024 13:33:12 +0900 Subject: [PATCH] Export edge data and event functions. Export edge data and event functions for custom connections. Signed-off-by: gichan2-jang --- debian/nnstreamer-edge-dev.install | 2 + include/nnstreamer-edge-data.h | 237 ++++++++++++++++++ include/nnstreamer-edge-event.h | 131 ++++++++++ include/nnstreamer-edge.h | 190 +------------- packaging/nnstreamer-edge.spec | 2 + src/CMakeLists.txt | 2 + src/libnnstreamer-edge/nnstreamer-edge-data.c | 1 + src/libnnstreamer-edge/nnstreamer-edge-data.h | 68 ----- .../nnstreamer-edge-event.h | 49 ---- .../nnstreamer-edge-internal.c | 1 + .../nnstreamer-edge-metadata.h | 2 +- 11 files changed, 379 insertions(+), 306 deletions(-) create mode 100644 include/nnstreamer-edge-data.h create mode 100644 include/nnstreamer-edge-event.h delete mode 100644 src/libnnstreamer-edge/nnstreamer-edge-data.h delete mode 100644 src/libnnstreamer-edge/nnstreamer-edge-event.h diff --git a/debian/nnstreamer-edge-dev.install b/debian/nnstreamer-edge-dev.install index ea4991d..51e3b54 100644 --- a/debian/nnstreamer-edge-dev.install +++ b/debian/nnstreamer-edge-dev.install @@ -1,4 +1,6 @@ /usr/include/nnstreamer/nnstreamer-edge.h /usr/include/nnstreamer/nnstreamer-edge-custom.h +/usr/include/nnstreamer/nnstreamer-edge-data.h +/usr/include/nnstreamer/nnstreamer-edge-event.h /usr/lib/*/pkgconfig/nnstreamer-edge.pc /usr/lib/*/libnnstreamer-edge.so diff --git a/include/nnstreamer-edge-data.h b/include/nnstreamer-edge-data.h new file mode 100644 index 0000000..da0de33 --- /dev/null +++ b/include/nnstreamer-edge-data.h @@ -0,0 +1,237 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. + * + * @file nnstreamer-edge-data.h + * @date 7 Sep 2022 + * @brief Util functions for edge data. + * @see https://github.com/nnstreamer/nnstreamer + * @author Gichan Jang + * @bug No known bugs except for NYI items + */ + +#ifndef __NNSTREAMER_EDGE_DATA_H__ +#define __NNSTREAMER_EDGE_DATA_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef void *nns_edge_data_h; +typedef uint64_t nns_size_t; +typedef int64_t nns_ssize_t; + +/** + * @brief The maximum number of data instances that nnstreamer-edge data may have. + */ +#define NNS_EDGE_DATA_LIMIT (256) +/** + * @brief Callback called when nnstreamer-edge data is released. + */ +typedef void (*nns_edge_data_destroy_cb) (void *data); + + +/** + * @brief Create a handle used for data transmission. + * @note Caller should release returned edge data using nns_edge_data_destroy(). + * @param[out] data_h Handle of edge data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_OUT_OF_MEMORY Failed to allocate required memory. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_create (nns_edge_data_h *data_h); + +/** + * @brief Destroy nnstreamer edge data handle. + * @param[in] data_h Handle of edge data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_destroy (nns_edge_data_h data_h); + +/** + * @brief Copy edge data and return new handle. + * @note Caller should release returned new edge data using nns_edge_data_destroy(). + * @param[in] data_h The edge data to be copied. + * @param[out] new_data_h A destination handle of edge data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_OUT_OF_MEMORY Failed to allocate required memory. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_copy (nns_edge_data_h data_h, nns_edge_data_h *new_data_h); + +/** + * @brief Add raw data into nnstreamer edge data. + * @note See NNS_EDGE_DATA_LIMIT, the maximum number of raw data in handle. + * @param[in] data_h The edge data handle. + * @param[in] data The raw data. + * @param[in] data_len The byte size of the data. + * @param[in] destroy_cb The callback for destroying the added data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_add (nns_edge_data_h data_h, void *data, nns_size_t data_len, nns_edge_data_destroy_cb destroy_cb); + +/** + * @brief Remove raw data in edge data. + * @param[in] data_h The edge data handle. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_clear (nns_edge_data_h data_h); + +/** + * @brief Get the n'th edge data. + * @note DO NOT release returned data. You should copy the data to another buffer if the returned data is necessary. + * @param[in] data_h The edge data handle. + * @param[in] index The index of the data to get. + * @param[out] data The data in the data handle. + * @param[out] data_len The byte size of the data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_get (nns_edge_data_h data_h, unsigned int index, void **data, nns_size_t *data_len); + +/** + * @brief Get the number of edge data in handle. + * @param[in] data_h The edge data handle. + * @param[out] count The number of the data in the data handle. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_get_count (nns_edge_data_h data_h, unsigned int *count); + +/** + * @brief Set the information of edge data. + * @note The param key is case-insensitive. If same key string already exists, it will replace old value. + * @param[in] data_h The edge data handle. + * @param[in] key A key of the information. + * @param[in] value The information to be set. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_set_info (nns_edge_data_h data_h, const char *key, const char *value); + +/** + * @brief Get the information of edge data. + * @note The param key is case-insensitive. Caller should release the returned value using free(). + * @param[in] data_h The edge data handle. + * @param[in] key A key of the information. + * @param[in] value The information to get. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_get_info (nns_edge_data_h data_h, const char *key, char **value); + +/** + * @brief Clear information of edge data. + * @param[in] data_h The edge data handle. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_clear_info (nns_edge_data_h data_h); + +/** + * @brief Release the edge data handle. This function releases the memory allocated for the edge data handle. + * @param[in] data The pointer to the edge data handle to be released. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +void nns_edge_data_release_handle (void *data); + +/** + * @brief Validate edge data handle. + * @param[in] data_h The edge data handle. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_is_valid (nns_edge_data_h data_h); + +/** + * @brief Serialize metadata in edge data. + * @param[in] data_h The handle to the edge data. + * @param[out] data A pointer to store the serialized meta data. + * @param[out] data_len A pointer to store the length of the serialized meta data. + * @return 0 on success, otherwise an error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + * @retval #NNS_EDGE_ERROR_OUT_OF_MEMORY Failed to allocate required memory. + */ +int nns_edge_data_serialize_meta (nns_edge_data_h data_h, void **data, nns_size_t *data_len); + +/** + * @brief Deserialize metadata in edge data. + * @param[in] data_h The handle to the edge data. + * @param[out] data A pointer to deserialized meta data. + * @param[out] data_len Length of the deserialized meta data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_deserialize_meta (nns_edge_data_h data_h, const void *data, const nns_size_t data_len); + +/** + * @brief Serialize entire edge data (meta data + raw data). + * @param[in] data_h The handle to the edge data. + * @param[out] data A pointer to store the serialized edge data. + * @param[out] data_len A pointer to store the length of the serialized edge data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + * @retval #NNS_EDGE_ERROR_OUT_OF_MEMORY Failed to allocate required memory. + */ +int nns_edge_data_serialize (nns_edge_data_h data_h, void **data, nns_size_t *data_len); + +/** + * @brief Deserialize entire edge data (meta data + raw data). + * @param[in] data_h The handle to the edge data. + * @param[out] data A pointer to deserialized edge data. + * @param[out] data_len Length of the deserialized edge data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_data_deserialize (nns_edge_data_h data_h, const void *data, const nns_size_t data_len); + +/** + * @brief Check given data is serialized buffer. + * @param[in] data A serialized edge data to check. + * @param[in] data_len Length of the serialized edge data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. */ +int nns_edge_data_is_serialized (const void *data, const nns_size_t data_len); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* __NNSTREAMER_EDGE_DATA_H__ */ diff --git a/include/nnstreamer-edge-event.h b/include/nnstreamer-edge-event.h new file mode 100644 index 0000000..5c719d6 --- /dev/null +++ b/include/nnstreamer-edge-event.h @@ -0,0 +1,131 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. + * + * @file nnstreamer-edge-event.h + * @date 7 Sep 2022 + * @brief Util functions for nnstreamer edge event. + * @see https://github.com/nnstreamer/nnstreamer + * @author Gichan Jang + * @bug No known bugs except for NYI items + */ + +#ifndef __NNSTREAMER_EDGE_EVENT_H__ +#define __NNSTREAMER_EDGE_EVENT_H__ + +#include "nnstreamer-edge-data.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef void *nns_edge_event_h; + +typedef enum { + NNS_EDGE_EVENT_UNKNOWN = 0, + NNS_EDGE_EVENT_CAPABILITY, + NNS_EDGE_EVENT_NEW_DATA_RECEIVED, + NNS_EDGE_EVENT_CALLBACK_RELEASED, + NNS_EDGE_EVENT_CONNECTION_CLOSED, + + NNS_EDGE_EVENT_CUSTOM = 0x01000000 +} nns_edge_event_e; + +/** + * @brief Callback for the nnstreamer edge event. + * @param[in] event_h The edge event handle. + * @param[in] user_data The user's custom data given to callbacks. + * @note This callback will suspend data stream. Do not spend too much time in the callback. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. */ +typedef int (*nns_edge_event_cb) (nns_edge_event_h event_h, void *user_data); + +/** + * @brief Get the nnstreamer edge event type. + * @param[in] event_h The edge event handle. + * @param[out] event The event type, value of @a nns_edge_event_e. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + */ +int nns_edge_event_get_type (nns_edge_event_h event_h, nns_edge_event_e *event); + +/** + * @brief Parse edge event (NNS_EDGE_EVENT_NEW_DATA_RECEIVED) and get received data. + * @note Caller should release returned edge data using nns_edge_data_destroy(). + * @param[in] event_h The edge event handle. + * @param[out] data_h Handle of received data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid + */ +int nns_edge_event_parse_new_data (nns_edge_event_h event_h, nns_edge_data_h *data_h); + +/** + * @brief Parse edge event (NNS_EDGE_EVENT_CAPABILITY) and get capability string. + * @note Caller should release returned string using free(). + * @param[in] event_h The edge event handle. + * @param[out] capability Capability string. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid + */ +int nns_edge_event_parse_capability (nns_edge_event_h event_h, char **capability); + +/** + * @brief Util function to invoke event callback. + * @param[in] event_cb Callback for the nnstreamer edge event. + * @param[in] user_data The user's custom data given to callbacks. + * @param[in] data A pointer to event data. + * @param[in] data_len Length of the event data. + * @param[in] destroy_cb A callback function to free the event data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + * @retval #NNS_EDGE_ERROR_OUT_OF_MEMORY Failed to allocate required memory. + */ +int nns_edge_event_invoke_callback (nns_edge_event_cb event_cb, void *user_data, nns_edge_event_e event, void *data, nns_size_t data_len, nns_edge_data_destroy_cb destroy_cb); + +/** + * @brief Create nnstreamer edge event. + * @param[in] event Edge event type. + * @param[out] event_h The handle of the created edge event. It should be released using nns_edge_event_destroy(). + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. + * @retval #NNS_EDGE_ERROR_OUT_OF_MEMORY Failed to allocate required memory. + */ +int nns_edge_event_create (nns_edge_event_e event, nns_edge_event_h *event_h); + +/** + * @brief Destroy nnstreamer edge event. + * @param[in] event_h The handle of the event to be destroyed. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. */ +int nns_edge_event_destroy (nns_edge_event_h event_h); + +/** + * @brief Set event data. + * @param[in] event_h The handle of edge event. + * @param[in] data A pointer to event data. + * @param[in] data_len Length of the event data. + * @param[in] destroy_cb A callback function to destroy the event data. + * @return 0 on success. Otherwise a negative error value. + * @retval #NNS_EDGE_ERROR_NONE Successful. + * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. + * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. */ +int nns_edge_event_set_data (nns_edge_event_h event_h, void *data, nns_size_t data_len, nns_edge_data_destroy_cb destroy_cb); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* __NNSTREAMER_EDGE_EVENT_H__ */ diff --git a/include/nnstreamer-edge.h b/include/nnstreamer-edge.h index 3325713..3983ce6 100644 --- a/include/nnstreamer-edge.h +++ b/include/nnstreamer-edge.h @@ -13,25 +13,17 @@ #ifndef __NNSTREAMER_EDGE_H__ #define __NNSTREAMER_EDGE_H__ -#include #include #include #include +#include "nnstreamer-edge-data.h" +#include "nnstreamer-edge-event.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ typedef void *nns_edge_h; -typedef void *nns_edge_event_h; -typedef void *nns_edge_data_h; -typedef uint64_t nns_size_t; -typedef int64_t nns_ssize_t; - -/** - * @brief The maximum number of data instances that nnstreamer-edge data may have. - */ -#define NNS_EDGE_DATA_LIMIT (256) /** * @brief Enumeration for the error codes of nnstreamer-edge (linux standard error, sync with tizen error code). @@ -46,16 +38,6 @@ typedef enum { NNS_EDGE_ERROR_NOT_SUPPORTED = (NNS_EDGE_ERROR_UNKNOWN + 2), } nns_edge_error_e; -typedef enum { - NNS_EDGE_EVENT_UNKNOWN = 0, - NNS_EDGE_EVENT_CAPABILITY, - NNS_EDGE_EVENT_NEW_DATA_RECEIVED, - NNS_EDGE_EVENT_CALLBACK_RELEASED, - NNS_EDGE_EVENT_CONNECTION_CLOSED, - - NNS_EDGE_EVENT_CUSTOM = 0x01000000 -} nns_edge_event_e; - typedef enum { NNS_EDGE_CONNECT_TYPE_TCP = 0, NNS_EDGE_CONNECT_TYPE_MQTT, @@ -75,18 +57,6 @@ typedef enum { NNS_EDGE_NODE_TYPE_UNKNOWN, } nns_edge_node_type_e; -/** - * @brief Callback for the nnstreamer edge event. - * @note This callback will suspend data stream. Do not spend too much time in the callback. - * @return User should return NNS_EDGE_ERROR_NONE if an event is successfully handled. - */ -typedef int (*nns_edge_event_cb) (nns_edge_event_h event_h, void *user_data); - -/** - * @brief Callback called when nnstreamer-edge data is released. - */ -typedef void (*nns_edge_data_destroy_cb) (void *data); - /** * @brief Create a handle representing an instance of edge-AI connection between a server and client (query) or a data publisher and scriber. * @param[in] id Unique id in local network @@ -344,162 +314,6 @@ int nns_edge_set_info (nns_edge_h edge_h, const char *key, const char *value); */ int nns_edge_get_info (nns_edge_h edge_h, const char *key, char **value); -/** - * @brief Get the nnstreamer edge event type. - * @param[in] event_h The edge event handle. - * @param[out] event The event type, value of @a nns_edge_event_e. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. - */ -int nns_edge_event_get_type (nns_edge_event_h event_h, nns_edge_event_e *event); - -/** - * @brief Parse edge event (NNS_EDGE_EVENT_NEW_DATA_RECEIVED) and get received data. - * @note Caller should release returned edge data using nns_edge_data_destroy(). - * @param[in] event_h The edge event handle. - * @param[out] data_h Handle of received data. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid - */ -int nns_edge_event_parse_new_data (nns_edge_event_h event_h, nns_edge_data_h *data_h); - -/** - * @brief Parse edge event (NNS_EDGE_EVENT_CAPABILITY) and get capability string. - * @note Caller should release returned string using free(). - * @param[in] event_h The edge event handle. - * @param[out] capability Capability string. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid - */ -int nns_edge_event_parse_capability (nns_edge_event_h event_h, char **capability); - -/** - * @brief Create a handle used for data transmission. - * @note Caller should release returned edge data using nns_edge_data_destroy(). - * @param[out] data_h Handle of edge data. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_OUT_OF_MEMORY Failed to allocate required memory. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. - */ -int nns_edge_data_create (nns_edge_data_h *data_h); - -/** - * @brief Destroy nnstreamer edge data handle. - * @param[in] data_h Handle of edge data. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. - */ -int nns_edge_data_destroy (nns_edge_data_h data_h); - -/** - * @brief Copy edge data and return new handle. - * @note Caller should release returned new edge data using nns_edge_data_destroy(). - * @param[in] data_h The edge data to be copied. - * @param[out] new_data_h A destination handle of edge data. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_OUT_OF_MEMORY Failed to allocate required memory. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. - */ -int nns_edge_data_copy (nns_edge_data_h data_h, nns_edge_data_h *new_data_h); - -/** - * @brief Add raw data into nnstreamer edge data. - * @note See NNS_EDGE_DATA_LIMIT, the maximum number of raw data in handle. - * @param[in] data_h The edge data handle. - * @param[in] data The raw data. - * @param[in] data_len The byte size of the data. - * @param[in] destroy_cb The callback for destroying the added data. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. - */ -int nns_edge_data_add (nns_edge_data_h data_h, void *data, nns_size_t data_len, nns_edge_data_destroy_cb destroy_cb); - -/** - * @brief Remove raw data in edge data. - * @param[in] data_h The edge data handle. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. - */ -int nns_edge_data_clear (nns_edge_data_h data_h); - -/** - * @brief Get the n'th edge data. - * @note DO NOT release returned data. You should copy the data to another buffer if the returned data is necessary. - * @param[in] data_h The edge data handle. - * @param[in] index The index of the data to get. - * @param[out] data The data in the data handle. - * @param[out] data_len The byte size of the data. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. - */ -int nns_edge_data_get (nns_edge_data_h data_h, unsigned int index, void **data, nns_size_t *data_len); - -/** - * @brief Get the number of edge data in handle. - * @param[in] data_h The edge data handle. - * @param[out] count The number of the data in the data handle. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. - */ -int nns_edge_data_get_count (nns_edge_data_h data_h, unsigned int *count); - -/** - * @brief Set the information of edge data. - * @note The param key is case-insensitive. If same key string already exists, it will replace old value. - * @param[in] data_h The edge data handle. - * @param[in] key A key of the information. - * @param[in] value The information to be set. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_OUT_OF_MEMORY Failed to allocate required memory. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. - */ -int nns_edge_data_set_info (nns_edge_data_h data_h, const char *key, const char *value); - -/** - * @brief Get the information of edge data. - * @note The param key is case-insensitive. Caller should release the returned value using free(). - * @param[in] data_h The edge data handle. - * @param[in] key A key of the information. - * @param[in] value The information to get. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. - */ -int nns_edge_data_get_info (nns_edge_data_h data_h, const char *key, char **value); - -/** - * @brief Clear information of edge data. - * @param[in] data_h The edge data handle. - * @return 0 on success. Otherwise a negative error value. - * @retval #NNS_EDGE_ERROR_NONE Successful. - * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. - * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid. - */ -int nns_edge_data_clear_info (nns_edge_data_h data_h); - /** * @brief Get the version of nnstreamer-edge. * @param[out] major MAJOR.minor.micro, won't set if it's null. diff --git a/packaging/nnstreamer-edge.spec b/packaging/nnstreamer-edge.spec index 58e00fd..3a1b1d4 100644 --- a/packaging/nnstreamer-edge.spec +++ b/packaging/nnstreamer-edge.spec @@ -175,6 +175,8 @@ rm -rf %{buildroot} %files devel %{_includedir}/nnstreamer/nnstreamer-edge.h %{_includedir}/nnstreamer/nnstreamer-edge-custom.h +%{_includedir}/nnstreamer/nnstreamer-edge-data.h +%{_includedir}/nnstreamer/nnstreamer-edge-event.h %{_libdir}/pkgconfig/nnstreamer-edge.pc %if 0%{?unit_test} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0ae6eae..0afd473 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,3 +45,5 @@ ENDIF() INSTALL (TARGETS ${NNS_EDGE_LIB_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) INSTALL (FILES ${INCLUDE_DIR}/nnstreamer-edge.h DESTINATION ${INCLUDE_INSTALL_DIR}) INSTALL (FILES ${INCLUDE_DIR}/nnstreamer-edge-custom.h DESTINATION ${INCLUDE_INSTALL_DIR}) +INSTALL (FILES ${INCLUDE_DIR}/nnstreamer-edge-data.h DESTINATION ${INCLUDE_INSTALL_DIR}) +INSTALL (FILES ${INCLUDE_DIR}/nnstreamer-edge-event.h DESTINATION ${INCLUDE_INSTALL_DIR}) diff --git a/src/libnnstreamer-edge/nnstreamer-edge-data.c b/src/libnnstreamer-edge/nnstreamer-edge-data.c index bebfa20..22c22c5 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-data.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-data.c @@ -13,6 +13,7 @@ #include "nnstreamer-edge-data.h" #include "nnstreamer-edge-log.h" #include "nnstreamer-edge-util.h" +#include "nnstreamer-edge-metadata.h" #define NNS_EDGE_DATA_KEY (0xeddaedda) diff --git a/src/libnnstreamer-edge/nnstreamer-edge-data.h b/src/libnnstreamer-edge/nnstreamer-edge-data.h deleted file mode 100644 index 523c90b..0000000 --- a/src/libnnstreamer-edge/nnstreamer-edge-data.h +++ /dev/null @@ -1,68 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ -/** - * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. - * - * @file nnstreamer-edge-data.h - * @date 7 Sep 2022 - * @brief Util functions for edge data. - * @see https://github.com/nnstreamer/nnstreamer - * @author Gichan Jang - * @bug No known bugs except for NYI items - * @note This file is internal header for nnstreamer edge utils. DO NOT export this file. - */ - -#ifndef __NNSTREAMER_EDGE_DATA_H__ -#define __NNSTREAMER_EDGE_DATA_H__ - -#include "nnstreamer-edge.h" -#include "nnstreamer-edge-metadata.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * @brief Internal wrapper function of the nns_edge_data_destroy() to avoid build warning of the incompatibe type casting. (See nns_edge_data_destroy_cb()) - */ -void nns_edge_data_release_handle (void *data); - -/** - * @brief Validate edge data handle. - * @note This is internal function, DO NOT export this. - */ -int nns_edge_data_is_valid (nns_edge_data_h data_h); - -/** - * @brief Serialize metadata in edge data. - * @note This is internal function, DO NOT export this. Caller should release the returned value using free(). - */ -int nns_edge_data_serialize_meta (nns_edge_data_h data_h, void **data, nns_size_t *data_len); - -/** - * @brief Deserialize metadata in edge data. - * @note This is internal function, DO NOT export this. - */ -int nns_edge_data_deserialize_meta (nns_edge_data_h data_h, const void *data, const nns_size_t data_len); - -/** - * @brief Serialize entire edge data (meta data + raw data). - * @note This is internal function, DO NOT export this. Caller should release the returned value using free(). - */ -int nns_edge_data_serialize (nns_edge_data_h data_h, void **data, nns_size_t *data_len); - -/** - * @brief Deserialize entire edge data (meta data + raw data). - * @note This is internal function, DO NOT export this. - */ -int nns_edge_data_deserialize (nns_edge_data_h data_h, const void *data, const nns_size_t data_len); - -/** - * @brief Check given data is serialized buffer. - * @note This is internal function, DO NOT export this. - */ -int nns_edge_data_is_serialized (const void *data, const nns_size_t data_len); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* __NNSTREAMER_EDGE_DATA_H__ */ diff --git a/src/libnnstreamer-edge/nnstreamer-edge-event.h b/src/libnnstreamer-edge/nnstreamer-edge-event.h deleted file mode 100644 index dd317c2..0000000 --- a/src/libnnstreamer-edge/nnstreamer-edge-event.h +++ /dev/null @@ -1,49 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ -/** - * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. - * - * @file nnstreamer-edge-event.h - * @date 7 Sep 2022 - * @brief Util functions for nnstreamer edge event. - * @see https://github.com/nnstreamer/nnstreamer - * @author Gichan Jang - * @bug No known bugs except for NYI items - * @note This file is internal header for nnstreamer edge utils. DO NOT export this file. - */ - -#ifndef __NNSTREAMER_EDGE_EVENT_H__ -#define __NNSTREAMER_EDGE_EVENT_H__ - -#include "nnstreamer-edge.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** - * @brief Internal util function to invoke event callback. - */ -int nns_edge_event_invoke_callback (nns_edge_event_cb event_cb, void *user_data, nns_edge_event_e event, void *data, nns_size_t data_len, nns_edge_data_destroy_cb destroy_cb); - -/** - * @brief Create nnstreamer edge event. - * @note This is internal function for edge event. - */ -int nns_edge_event_create (nns_edge_event_e event, nns_edge_event_h *event_h); - -/** - * @brief Destroy nnstreamer edge event. - * @note This is internal function for edge event. - */ -int nns_edge_event_destroy (nns_edge_event_h event_h); - -/** - * @brief Set event data. - * @note This is internal function for edge event. - */ -int nns_edge_event_set_data (nns_edge_event_h event_h, void *data, nns_size_t data_len, nns_edge_data_destroy_cb destroy_cb); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* __NNSTREAMER_EDGE_EVENT_H__ */ diff --git a/src/libnnstreamer-edge/nnstreamer-edge-internal.c b/src/libnnstreamer-edge/nnstreamer-edge-internal.c index 1d9c43b..d1ca771 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-internal.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-internal.c @@ -21,6 +21,7 @@ #include "nnstreamer-edge-util.h" #include "nnstreamer-edge-queue.h" #include "nnstreamer-edge-aitt.h" +#include "nnstreamer-edge-metadata.h" #include "nnstreamer-edge-mqtt.h" #include "nnstreamer-edge-custom-impl.h" diff --git a/src/libnnstreamer-edge/nnstreamer-edge-metadata.h b/src/libnnstreamer-edge/nnstreamer-edge-metadata.h index 5d9e3c3..4b4c520 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-metadata.h +++ b/src/libnnstreamer-edge/nnstreamer-edge-metadata.h @@ -14,7 +14,7 @@ #ifndef __NNSTREAMER_EDGE_METADATA_H__ #define __NNSTREAMER_EDGE_METADATA_H__ -#include "nnstreamer-edge.h" +#include "nnstreamer-edge-data.h" #ifdef __cplusplus extern "C" { -- 2.34.1