From 4703c596b24090b6bfb2acbdd48f742e1298940f Mon Sep 17 00:00:00 2001 From: gichan Date: Fri, 14 Oct 2022 11:11:22 +0900 Subject: [PATCH] [MQTT] Separate MQTT implementation Separate implementation for MQTT into paho-mqtt-c and mosquitto. Let's use mosquitto lib in environments where the paho lib is not supported, such as tizenRT. Signed-off-by: gichan --- CMakeLists.txt | 7 +- src/CMakeLists.txt | 12 ++- .../nnstreamer-edge-mqtt-mosquitto.c | 94 +++++++++++++++++++ ...dge-mqtt.c => nnstreamer-edge-mqtt-paho.c} | 2 +- 4 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 src/libnnstreamer-edge/nnstreamer-edge-mqtt-mosquitto.c rename src/libnnstreamer-edge/{nnstreamer-edge-mqtt.c => nnstreamer-edge-mqtt-paho.c} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 668422d..679fd27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,12 @@ IF(MQTT_SUPPORT) FIND_LIBRARY(PAHO_MQTT_LIB NAMES paho-mqtt3a paho-mqtt3c paho-mqtt3as paho-mqtt3cs) IF(NOT PAHO_MQTT_LIB) - MESSAGE(FATAL_ERROR "Cannot find Paho MQTT library.") + FIND_LIBRARY(MOSQUITTO_LIB NAMES mosquitto) + IF(NOT MOSQUITTO_LIB) + MESSAGE("FATAL_ERROR Cannot find paho-mqtt-c and mosquitto library.") + ELSE() + MESSAGE("FOUND MOSQUITTO LIB.") + ENDIF() ELSE() MESSAGE("Found Paho MQTT library.") ENDIF() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8920f47..e1354ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,7 +10,11 @@ SET(NNS_EDGE_SRCS ) IF(MQTT_SUPPORT) - SET(NNS_EDGE_SRCS ${NNS_EDGE_SRCS} ${NNS_EDGE_SRC_DIR}/nnstreamer-edge-mqtt.c) + IF(PAHO_MQTT_LIB) + SET(NNS_EDGE_SRCS ${NNS_EDGE_SRCS} ${NNS_EDGE_SRC_DIR}/nnstreamer-edge-mqtt-paho.c) + ELSE() + SET(NNS_EDGE_SRCS ${NNS_EDGE_SRCS} ${NNS_EDGE_SRC_DIR}/nnstreamer-edge-mqtt-mosquitto.c) + ENDIF() ENDIF() IF(AITT_SUPPORT) @@ -23,7 +27,11 @@ TARGET_INCLUDE_DIRECTORIES(${NNS_EDGE_LIB_NAME} PRIVATE ${INCLUDE_DIR} ${EDGE_RE TARGET_LINK_LIBRARIES(${NNS_EDGE_LIB_NAME} ${EDGE_REQUIRE_PKGS_LDFLAGS}) IF(MQTT_SUPPORT) - TARGET_LINK_LIBRARIES(${NNS_EDGE_LIB_NAME} ${PAHO_MQTT_LIB}) + IF(PAHO_MQTT_LIB) + TARGET_LINK_LIBRARIES(${NNS_EDGE_LIB_NAME} ${PAHO_MQTT_LIB}) + ELSE() + TARGET_LINK_LIBRARIES(${NNS_EDGE_LIB_NAME} ${MOSQUITTO_LIB}) + ENDIF() ENDIF() IF(AITT_SUPPORT) diff --git a/src/libnnstreamer-edge/nnstreamer-edge-mqtt-mosquitto.c b/src/libnnstreamer-edge/nnstreamer-edge-mqtt-mosquitto.c new file mode 100644 index 0000000..291a13e --- /dev/null +++ b/src/libnnstreamer-edge/nnstreamer-edge-mqtt-mosquitto.c @@ -0,0 +1,94 @@ +/* SPDX-License-Identifier: Apache-2.0 */ +/** + * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. + * + * @file nnstreamer-edge-mqtt-mosquitto.c + * @date 14 Oct 2022 + * @brief Internal functions to support MQTT protocol (mosquitto Library). + * @see https://github.com/nnstreamer/nnstreamer-edge + * @author Gichan Jang + * @bug No known bugs except for NYI items + */ + +#include "nnstreamer-edge-internal.h" +#include "nnstreamer-edge-log.h" +#include "nnstreamer-edge-util.h" +#include "nnstreamer-edge-queue.h" + +/** + * @brief Data structure for mqtt broker handle. + */ +typedef struct +{ + void *mqtt_h; + nns_edge_queue_h server_list; + char *topic; +} nns_edge_broker_s; + +/** + * @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) +{ + UNUSED (edge_h); + UNUSED (topic); + return NNS_EDGE_ERROR_NOT_SUPPORTED; +} + +/** + * @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) +{ + UNUSED (edge_h); + return NNS_EDGE_ERROR_NOT_SUPPORTED; +} + +/** + * @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) +{ + UNUSED (edge_h); + UNUSED (data); + UNUSED (length); + return NNS_EDGE_ERROR_NOT_SUPPORTED; +} + +/** + * @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) +{ + UNUSED (edge_h); + return NNS_EDGE_ERROR_NOT_SUPPORTED; +} + +/** + * @brief Check mqtt connection + */ +bool +nns_edge_mqtt_is_connected (nns_edge_h edge_h) +{ + UNUSED (edge_h); + return false; +} + +/** + * @brief Get message from mqtt broker. + */ +int +nns_edge_mqtt_get_message (nns_edge_h edge_h, char **msg) +{ + UNUSED (edge_h); + UNUSED (msg); + return NNS_EDGE_ERROR_NOT_SUPPORTED; +} diff --git a/src/libnnstreamer-edge/nnstreamer-edge-mqtt.c b/src/libnnstreamer-edge/nnstreamer-edge-mqtt-paho.c similarity index 99% rename from src/libnnstreamer-edge/nnstreamer-edge-mqtt.c rename to src/libnnstreamer-edge/nnstreamer-edge-mqtt-paho.c index db743c7..49c23ff 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-mqtt.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-mqtt-paho.c @@ -2,7 +2,7 @@ /** * Copyright (C) 2022 Samsung Electronics Co., Ltd. All Rights Reserved. * - * @file nnstreamer-edge-mqtt.c + * @file nnstreamer-edge-mqtt-paho.c * @date 11 May 2022 * @brief Internal functions to support MQTT protocol (Paho Asynchronous MQTT C Client Library). * @see https://github.com/nnstreamer/nnstreamer -- 2.34.1