From: Jaeyun Date: Thu, 15 Sep 2022 04:53:32 +0000 (+0900) Subject: [CodeClean] new header for mqtt and aitt X-Git-Tag: accepted/tizen/unified/20220919.012623^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=20b93269b8b555afa832a895dbc31c4b1852df7d;p=platform%2Fupstream%2Fnnstreamer-edge.git [CodeClean] new header for mqtt and aitt Prepare connection handle, separate header files for mqtt and aitt. Signed-off-by: Jaeyun --- diff --git a/src/libnnstreamer-edge/nnstreamer-edge-aitt.h b/src/libnnstreamer-edge/nnstreamer-edge-aitt.h new file mode 100644 index 0000000..44da6e5 --- /dev/null +++ b/src/libnnstreamer-edge/nnstreamer-edge-aitt.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. + * + * @file nnstreamer-edge-aitt.h + * @date 28 Mar 2022 + * @brief Common library to support communication among devices using aitt. + * @see https://github.com/nnstreamer/nnstreamer + * @author Sangjung Woo + * @bug No known bugs except for NYI items + */ + +#ifndef __NNSTREAMER_EDGE_AITT_H__ +#define __NNSTREAMER_EDGE_AITT_H__ + +#include "nnstreamer-edge.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#if defined(ENABLE_AITT) +/** + * @brief Create AITT handle and connect to AITT. + * @note This is internal function for AITT. You should call this with edge-handle lock. + */ +int nns_edge_aitt_connect (nns_edge_h edge_h); + +/** + * @brief Release the AITT handle. + * @note This is internal function for AITT. You should call this with edge-handle lock. + */ +int nns_edge_aitt_close (nns_edge_h edge_h); + +/** + * @brief Check whether aitt handle exists or not. + */ +int nns_edge_aitt_is_connected (nns_edge_h edge_h); + +/** + * @brief Publish raw data. + * @note This is internal function forAITT. You should call this with edge-handle lock. + */ +int nns_edge_aitt_publish (nns_edge_h edge_h, const void *data, const int length); + +/** + * @brief Subscribe a topic. + * @note This is internal function for AITT. You should call this with edge-handle lock. + */ +int nns_edge_aitt_subscribe (nns_edge_h edge_h); +#else +#define nns_edge_aitt_connect(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) +#define nns_edge_aitt_close(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) +#define nns_edge_aitt_publish(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) +#define nns_edge_aitt_subscribe(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) +#define nns_edge_aitt_is_connected(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) +#endif /* ENABLE_AITT */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* __NNSTREAMER_EDGE_AITT_H__ */ diff --git a/src/libnnstreamer-edge/nnstreamer-edge-internal.h b/src/libnnstreamer-edge/nnstreamer-edge-internal.h index 9e0b01b..201994d 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-internal.h +++ b/src/libnnstreamer-edge/nnstreamer-edge-internal.h @@ -20,10 +20,10 @@ extern "C" { #include "nnstreamer-edge.h" #include "nnstreamer-edge-metadata.h" +#include "nnstreamer-edge-aitt.h" +#include "nnstreamer-edge-mqtt.h" #include "nnstreamer-edge-queue.h" -typedef void *nns_edge_broker_h; - /** * @brief Internal data structure for raw data. */ @@ -77,101 +77,10 @@ typedef struct { nns_edge_queue_h send_queue; pthread_t send_thread; - /* MQTT */ - nns_edge_broker_h broker_h; + /* MQTT or AITT handle */ + void *broker_h; } nns_edge_handle_s; -#if defined(ENABLE_MQTT) -/** - * @brief Connect to MQTT. - * @note This is internal function for MQTT broker. You should call this with edge-handle lock. - */ -int nns_edge_mqtt_connect (nns_edge_h edge_h, const char *topic); - -/** - * @brief Close the connection to MQTT. - * @note This is internal function for MQTT broker. You should call this with edge-handle lock. - */ -int nns_edge_mqtt_close (nns_edge_h edge_h); - -/** - * @brief Publish raw data. - * @note This is internal function for MQTT broker. You should call this with edge-handle lock. - */ -int nns_edge_mqtt_publish (nns_edge_h edge_h, const void *data, const int length); - -/** - * @brief Subscribe a topic. - * @note This is internal function for MQTT broker. You should call this with edge-handle lock. - */ -int nns_edge_mqtt_subscribe (nns_edge_h edge_h); - -/** - * @brief Check mqtt connection - */ -bool nns_edge_mqtt_is_connected (nns_edge_h edge_h); - -/** - * @brief Get message from mqtt broker. - */ -int nns_edge_mqtt_get_message (nns_edge_h edge_h, char **msg); - -#else -/** - * @todo consider to change code style later. - * If MQTT is disabled, nnstreamer does not include nnstreamer_edge_mqtt.c, and changing code style will make error as it is not used function now. - * - * static int nns_edge_mqtt_publish (nns_edge_h edge_h, const void *data, const int length) - * { - * return NNS_EDGE_ERROR_NOT_SUPPORTED; - * } - */ -#define nns_edge_mqtt_connect(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_mqtt_close(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_mqtt_publish(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_mqtt_subscribe(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_mqtt_is_connected(...) (false) -#define nns_edge_mqtt_get_message(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#endif - -#if defined(ENABLE_AITT) -/** - * @brief Create AITT handle and connect to AITT. - * @note This is internal function for AITT. You should call this with edge-handle lock. - */ -int nns_edge_aitt_connect (nns_edge_h edge_h); - -/** - * @brief Release the AITT handle. - * @note This is internal function for AITT. You should call this with edge-handle lock. - */ -int nns_edge_aitt_close (nns_edge_h edge_h); - -/** - * @brief Check whether aitt handle exists or not. - */ -int -nns_edge_aitt_is_connected (nns_edge_h edge_h); - -/** - * @brief Publish raw data. - * @note This is internal function forAITT. You should call this with edge-handle lock. - */ -int nns_edge_aitt_publish (nns_edge_h edge_h, const void *data, const int length); - -/** - * @brief Subscribe a topic. - * @note This is internal function for AITT. You should call this with edge-handle lock. - */ -int nns_edge_aitt_subscribe (nns_edge_h edge_h); -#else -#define nns_edge_aitt_connect(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_aitt_close(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_aitt_publish(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_aitt_subscribe(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_aitt_is_connected(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#endif - #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/libnnstreamer-edge/nnstreamer-edge-mqtt.h b/src/libnnstreamer-edge/nnstreamer-edge-mqtt.h new file mode 100644 index 0000000..1253d1e --- /dev/null +++ b/src/libnnstreamer-edge/nnstreamer-edge-mqtt.h @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. + * + * @file nnstreamer-edge-mqtt.h + * @date 11 May 2022 + * @brief Internal functions to support MQTT protocol (Paho Asynchronous MQTT C Client Library). + * @see https://github.com/nnstreamer/nnstreamer + * @author Sangjung Woo + * @bug No known bugs except for NYI items + */ + +#ifndef __NNSTREAMER_EDGE_MQTT_H__ +#define __NNSTREAMER_EDGE_MQTT_H__ + +#include +#include "nnstreamer-edge.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef void *nns_edge_mqtt_h; + +#if defined(ENABLE_MQTT) +/** + * @brief Connect to MQTT. + * @note This is internal function for MQTT broker. You should call this with edge-handle lock. + */ +int nns_edge_mqtt_connect (nns_edge_h edge_h, const char *topic); + +/** + * @brief Close the connection to MQTT. + * @note This is internal function for MQTT broker. You should call this with edge-handle lock. + */ +int nns_edge_mqtt_close (nns_edge_h edge_h); + +/** + * @brief Publish raw data. + * @note This is internal function for MQTT broker. You should call this with edge-handle lock. + */ +int nns_edge_mqtt_publish (nns_edge_h edge_h, const void *data, const int length); + +/** + * @brief Subscribe a topic. + * @note This is internal function for MQTT broker. You should call this with edge-handle lock. + */ +int nns_edge_mqtt_subscribe (nns_edge_h edge_h); + +/** + * @brief Check mqtt connection + */ +bool nns_edge_mqtt_is_connected (nns_edge_h edge_h); + +/** + * @brief Get message from mqtt broker. + */ +int nns_edge_mqtt_get_message (nns_edge_h edge_h, char **msg); + +#else +/** + * @todo consider to change code style later. + * If MQTT is disabled, nnstreamer does not include nnstreamer_edge_mqtt.c, and changing code style will make error as it is not used function now. + * + * static int nns_edge_mqtt_publish (nns_edge_h edge_h, const void *data, const int length) + * { + * return NNS_EDGE_ERROR_NOT_SUPPORTED; + * } + */ +#define nns_edge_mqtt_connect(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) +#define nns_edge_mqtt_close(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) +#define nns_edge_mqtt_publish(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) +#define nns_edge_mqtt_subscribe(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) +#define nns_edge_mqtt_is_connected(...) (false) +#define nns_edge_mqtt_get_message(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) +#endif /* ENABLE_MQTT */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* __NNSTREAMER_EDGE_MQTT_H__ */