From 8226b8c6734120715bc8764f95b792aabd1e43bd Mon Sep 17 00:00:00 2001 From: gichan2-jang Date: Fri, 6 Sep 2024 09:56:16 +0900 Subject: [PATCH] [AITT] Remove AITT connection Remove AITT connection since AITT has been deprecated. Signed-off-by: gichan2-jang --- CMakeLists.txt | 7 - include/nnstreamer-edge.h | 19 +- jni/nnstreamer-edge.mk | 2 - src/CMakeLists.txt | 9 - src/libnnstreamer-edge/nnstreamer-edge-aitt.c | 466 ------------ src/libnnstreamer-edge/nnstreamer-edge-aitt.h | 104 --- .../nnstreamer-edge-internal.c | 76 +- tests/CMakeLists.txt | 8 - tests/unittest_nnstreamer-edge-aitt.cc | 666 ------------------ 9 files changed, 10 insertions(+), 1347 deletions(-) delete mode 100644 src/libnnstreamer-edge/nnstreamer-edge-aitt.c delete mode 100644 src/libnnstreamer-edge/nnstreamer-edge-aitt.h delete mode 100644 tests/unittest_nnstreamer-edge-aitt.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 11395a4..03ad053 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,6 @@ OPTION(ENABLE_TIZEN "Enable Tizen build" OFF) # Default features. You may change the features according to your needs. OPTION(MQTT_SUPPORT "Enable MQTT" OFF) -OPTION(AITT_SUPPORT "Enable AITT" OFF) IF (NOT DEFINED VERSION) SET(VERSION 0.2.6) @@ -58,12 +57,6 @@ IF(ENABLE_TIZEN) SET(REQUIRE_PKGS "${REQUIRE_PKGS} dlog") ENDIF() -# AITT Library -IF(AITT_SUPPORT) - SET(REQUIRE_PKGS "${REQUIRE_PKGS} aitt") - SET(NNS_EDGE_FLAGS "${NNS_EDGE_FLAGS} -DENABLE_AITT=1") -ENDIF() - IF(NOT ${REQUIRE_PKGS} STREQUAL "") PKG_CHECK_MODULES(EDGE_REQUIRE_PKGS REQUIRED ${REQUIRE_PKGS}) ADD_DEFINITIONS(${EDGE_REQUIRE_PKGS_CFLAGS}) diff --git a/include/nnstreamer-edge.h b/include/nnstreamer-edge.h index 21d11a8..347d548 100644 --- a/include/nnstreamer-edge.h +++ b/include/nnstreamer-edge.h @@ -46,7 +46,6 @@ typedef enum { NNS_EDGE_CONNECT_TYPE_TCP = 0, NNS_EDGE_CONNECT_TYPE_MQTT, NNS_EDGE_CONNECT_TYPE_HYBRID, - NNS_EDGE_CONNECT_TYPE_AITT, NNS_EDGE_CONNECT_TYPE_CUSTOM, NNS_EDGE_CONNECT_TYPE_UNKNOWN @@ -124,18 +123,18 @@ typedef enum { * // Information that needs to be set according to the node and connection type. * // 1. Query-server-src: * // - All connection type: HOST, PORT, CAPS - * // - Hybrid and AITT: DEST_HOST, DEST_PORT, TOPIC + * // - Hybrid and MQTT: DEST_HOST, DEST_PORT, TOPIC * // 2. Query-server-sink: * // - All connection type: CAPS * // 3. Query-client * // - All connection type: HOST, PORT, CAPS - * // - Hybrid and AITT: TOPIC + * // - Hybrid and MQTT: TOPIC * // 4. Stream-sink * // - All connection type: HOST, PORT - * // - Hybrid and AITT: DEST_HOST, DEST_PORT, TOPIC + * // - Hybrid and MQTT: DEST_HOST, DEST_PORT, TOPIC * // 5. Stream-src * // - All connection type: HOST, PORT - * // - Hybrid and AITT: DEST_HOST, DEST_PORT, TOPIC + * // - Hybrid and MQTT: DEST_HOST, DEST_PORT, TOPIC * * // Set information for query-client of TCP connection. * ret = nns_edge_set_info (edge_h, "HOST", "127.0.0.1"); @@ -215,10 +214,10 @@ int nns_edge_release_handle (nns_edge_h edge_h); int nns_edge_set_event_callback (nns_edge_h edge_h, nns_edge_event_cb cb, void *user_data); /** - * @brief Connect to the destination node. In the case of Hybrid and AITT, the TOPIC, DEST_HOST and DEST_PORT must be set before connection using nns_edge_set_info(). + * @brief Connect to the destination node. In the case of Hybrid and MQTT, the TOPIC, DEST_HOST and DEST_PORT must be set before connection using nns_edge_set_info(). * @param[in] edge_h The edge handle. - * @param[in] dest_host IP address to connect. In case of TCP connection, it is the IP address of the destination node, and in the case of Hybrid or AITT connection, it is the IP of the broker. - * @param[in] dest_port The network port to connect. In case of TCP connection, it is the port of the destination node, and in the case of Hybrid or AITT connection, it is the port of the broker. + * @param[in] dest_host IP address to connect. In case of TCP connection, it is the IP address of the destination node, and in the case of Hybrid or MQTT connection, it is the IP of the broker. + * @param[in] dest_port The network port to connect. In case of TCP connection, it is the port of the destination node, and in the case of Hybrid or MQTT connection, it is the port of the broker. * @return 0 on success. Otherwise a negative error value. * @retval #NNS_EDGE_ERROR_NONE Successful. * @retval #NNS_EDGE_ERROR_NOT_SUPPORTED Not supported. @@ -302,8 +301,8 @@ int nns_edge_is_connected (nns_edge_h edge_h); * CAPS or CAPABILITY | capability strings. * IP or HOST | IP address of the node to accept connection from other node. * PORT | Port of the node to accept connection from other node. The value should be 0 or higher, if the port is set to 0 then the available port is allocated. - * DEST_IP or DEST_HOST | IP address of the destination node. In case of TCP connection, it is the IP address of the destination node, and in the case of Hybrid or AITT connection, it is the IP address of the broker. - * DEST_PORT | Port of the destination node. In case of TCP connection, it is the port number of the destination node, and in the case of Hybrid or AITT connection, it is the port number of the broker. The value should be 0 or higher. + * DEST_IP or DEST_HOST | IP address of the destination node. In case of TCP connection, it is the IP address of the destination node, and in the case of Hybrid or MQTT connection, it is the IP address of the broker. + * DEST_PORT | Port of the destination node. In case of TCP connection, it is the port number of the destination node, and in the case of Hybrid or MQTT connection, it is the port number of the broker. The value should be 0 or higher. * TOPIC | Topic used to publish/subscribe to/from the broker. * QUEUE_SIZE | Max number of data in the queue, when sending edge data to other node. Default 0 means unlimited. N: where leaky 'OLD' drops old buffer (default NEW). (e.g., QUEUE_SIZE=5:OLD drops old buffer and pushes new data when queue size reaches 5.) * ID or CLIENT_ID | Unique identifier of the edge handle or client ID. (Read-only) diff --git a/jni/nnstreamer-edge.mk b/jni/nnstreamer-edge.mk index 6cd740a..c5439a1 100644 --- a/jni/nnstreamer-edge.mk +++ b/jni/nnstreamer-edge.mk @@ -18,5 +18,3 @@ NNSTREAMER_EDGE_SRCS := \ $(NNSTREAMER_EDGE_ROOT)/src/libnnstreamer-edge/nnstreamer-edge-queue.c \ $(NNSTREAMER_EDGE_ROOT)/src/libnnstreamer-edge/nnstreamer-edge-util.c -# TODO: Add mqtt and aitt - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0afd473..3b61e1a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,10 +20,6 @@ IF(MQTT_SUPPORT) ENDIF() ENDIF() -IF(AITT_SUPPORT) - SET(NNS_EDGE_SRCS ${NNS_EDGE_SRCS} ${NNS_EDGE_SRC_DIR}/nnstreamer-edge-aitt.c) -ENDIF() - ADD_LIBRARY(${NNS_EDGE_LIB_NAME} SHARED ${NNS_EDGE_SRCS}) SET_TARGET_PROPERTIES(${NNS_EDGE_LIB_NAME} PROPERTIES VERSION ${SO_VERSION}) TARGET_INCLUDE_DIRECTORIES(${NNS_EDGE_LIB_NAME} PRIVATE ${INCLUDE_DIR} ${EDGE_REQUIRE_PKGS_INCLUDE_DIRS}) @@ -37,11 +33,6 @@ IF(MQTT_SUPPORT) ENDIF() ENDIF() -IF(AITT_SUPPORT) - TARGET_LINK_LIBRARIES(${NNS_EDGE_LIB_NAME} ${AITT_LIB}) - TARGET_INCLUDE_DIRECTORIES(${NNS_EDGE_LIB_NAME} PUBLIC ${AITT_INCLUDE_DIR}) -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}) diff --git a/src/libnnstreamer-edge/nnstreamer-edge-aitt.c b/src/libnnstreamer-edge/nnstreamer-edge-aitt.c deleted file mode 100644 index 4e788c2..0000000 --- a/src/libnnstreamer-edge/nnstreamer-edge-aitt.c +++ /dev/null @@ -1,466 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 */ -/** - * Copyright (C) 2022 Gichan Jang - * - * @file nnstreamer-edge-aitt.c - * @date 28 Mar 2022 - * @brief Common library to support communication among devices using aitt. - * @see https://github.com/nnstreamer/nnstreamer - * @author Gichan Jang - * @bug No known bugs except for NYI items - */ - -#if !defined(ENABLE_AITT) -#error "This file can be built with AITT library." -#endif - -#include - -#include "nnstreamer-edge-aitt.h" -#include "nnstreamer-edge-data.h" -#include "nnstreamer-edge-event.h" -#include "nnstreamer-edge-util.h" -#include "nnstreamer-edge-log.h" - -/** - * @brief Data structure for aitt handle. - */ -typedef struct -{ - aitt_h aitt_handle; - aitt_sub_h sub_handle; - char *id; - char *topic; - char *host; - int port; - - /* event callback for new message */ - nns_edge_event_cb event_cb; - void *user_data; - aitt_option_h option; - aitt_protocol_e protocol; -} nns_edge_aitt_handle_s; - -/** - * @brief Create AITT handle and connect to AITT. - */ -int -nns_edge_aitt_connect (nns_edge_aitt_h handle, const char *id, - const char *topic, const char *host, const int port) -{ - nns_edge_aitt_handle_s *ah; - - if (!STR_IS_VALID (id)) { - nns_edge_loge ("Invalid param, given id is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - if (!STR_IS_VALID (topic)) { - nns_edge_loge ("Invalid param, given topic is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - if (!STR_IS_VALID (host)) { - nns_edge_loge ("Invalid param, given host is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - if (!PORT_IS_VALID (port)) { - nns_edge_loge ("Invalid param, given port is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - if (!handle) { - nns_edge_loge ("Invalid param, handle should not be null."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - ah = (nns_edge_aitt_handle_s *) handle; - - nns_edge_logd ("Create AITT instance: broker address: %s:%d", host, port); - - ah->aitt_handle = aitt_new (id, ah->option); - - if (!ah->aitt_handle) { - nns_edge_loge ("Failed to create AITT handle. AITT internal error."); - SAFE_FREE (ah); - return NNS_EDGE_ERROR_UNKNOWN; - } - - if (AITT_ERROR_NONE != aitt_connect (ah->aitt_handle, host, port)) { - nns_edge_loge ("Failed to connect to AITT. IP:port = %s:%d", host, port); - aitt_destroy (ah->aitt_handle); - SAFE_FREE (ah); - return NNS_EDGE_ERROR_UNKNOWN; - } - - ah->id = nns_edge_strdup (id); - ah->topic = nns_edge_strdup (topic); - ah->host = nns_edge_strdup (host); - ah->port = port; - - return NNS_EDGE_ERROR_NONE; -} - -/** - * @brief Release the AITT handle. - */ -int -nns_edge_aitt_close (nns_edge_aitt_h handle) -{ - nns_edge_aitt_handle_s *ah; - - if (!handle) { - nns_edge_loge ("Invalid param, given AITT handle is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - ah = (nns_edge_aitt_handle_s *) handle; - - /* clear event callback */ - ah->event_cb = NULL; - ah->user_data = NULL; - - if (ah->aitt_handle) { - if (AITT_ERROR_NONE != aitt_disconnect (ah->aitt_handle)) { - nns_edge_loge ("Failed to close AITT handle."); - return NNS_EDGE_ERROR_UNKNOWN; - } - - aitt_destroy (ah->aitt_handle); - ah->aitt_handle = NULL; - } - - if (ah->option) - aitt_option_destroy (ah->option); - SAFE_FREE (ah->id); - SAFE_FREE (ah->topic); - SAFE_FREE (ah->host); - SAFE_FREE (ah); - - return NNS_EDGE_ERROR_NONE; -} - -/** - * @brief Check whether aitt handle exists or not. - */ -int -nns_edge_aitt_is_connected (nns_edge_aitt_h handle) -{ - nns_edge_aitt_handle_s *ah; - - if (!handle) { - nns_edge_loge ("Invalid param, given AITT handle is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - ah = (nns_edge_aitt_handle_s *) handle; - if (!ah->aitt_handle) { - nns_edge_loge ("AITT handle is not yet connected."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - return NNS_EDGE_ERROR_NONE; -} - -/** - * @brief Publish raw data. - */ -int -nns_edge_aitt_publish (nns_edge_aitt_h handle, const void *data, - const int length) -{ - nns_edge_aitt_handle_s *ah; - - if (!handle) { - nns_edge_loge ("Invalid param, given AITT handle is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - ah = (nns_edge_aitt_handle_s *) handle; - - return nns_edge_aitt_publish_full (handle, data, length, ah->protocol, - AITT_QOS_AT_MOST_ONCE); -} - -/** - * @brief Publish raw data with protocol and QoS. - */ -int -nns_edge_aitt_publish_full (nns_edge_aitt_h handle, const void *data, - const int length, aitt_protocol_e protocol, aitt_qos_e qos) -{ - nns_edge_aitt_handle_s *ah; - int ret; - - if (!handle) { - nns_edge_loge ("Invalid param, given AITT handle is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - if (!data || length <= 0) { - nns_edge_loge ("Invalid param, given data is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - ah = (nns_edge_aitt_handle_s *) handle; - - ret = aitt_publish_full (ah->aitt_handle, ah->topic, - data, length, protocol, qos); - if (AITT_ERROR_NONE != ret) { - nns_edge_loge ("Failed to publish the message. topic: %s", ah->topic); - return NNS_EDGE_ERROR_IO; - } - - return NNS_EDGE_ERROR_NONE; -} - -/** - * @brief Callback function to be called when a message is arrived. - */ -static void -aitt_cb_message_arrived (aitt_msg_h msg_handle, const void *msg, - int msg_len, void *user_data) -{ - nns_edge_aitt_handle_s *ah; - nns_edge_data_h data_h; - int ret; - - ah = (nns_edge_aitt_handle_s *) user_data; - - if (!ah || !ah->event_cb) { - nns_edge_logw ("The event callback is null, cannot handle new message."); - return; - } - - if (nns_edge_data_create (&data_h) != NNS_EDGE_ERROR_NONE) { - nns_edge_loge ("Failed to create data handle in msg thread."); - return; - } - - nns_edge_data_deserialize (data_h, (void *) msg, (nns_size_t) msg_len); - - ret = nns_edge_event_invoke_callback (ah->event_cb, ah->user_data, - NNS_EDGE_EVENT_NEW_DATA_RECEIVED, data_h, sizeof (nns_edge_data_h), NULL); - if (ret != NNS_EDGE_ERROR_NONE) - nns_edge_loge ("Failed to send an event for received message."); - - nns_edge_data_destroy (data_h); -} - -/** - * @brief Subscribe a topic. - */ -int -nns_edge_aitt_subscribe (nns_edge_aitt_h handle) -{ - nns_edge_aitt_handle_s *ah; - - if (!handle) { - nns_edge_loge ("Invalid param, given AITT handle is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - ah = (nns_edge_aitt_handle_s *) handle; - - if (AITT_ERROR_NONE != aitt_subscribe (ah->aitt_handle, ah->topic, - aitt_cb_message_arrived, ah, &ah->sub_handle)) { - nns_edge_loge ("Failed to subscribe the topic: %s", ah->topic); - return NNS_EDGE_ERROR_UNKNOWN; - } - return NNS_EDGE_ERROR_NONE; -} - -/** - * @brief Set event callback for new message. - */ -int -nns_edge_aitt_set_event_callback (nns_edge_aitt_h handle, nns_edge_event_cb cb, - void *user_data) -{ - nns_edge_aitt_handle_s *ah; - - if (!handle) { - nns_edge_loge ("Invalid param, given AITT handle is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - ah = (nns_edge_aitt_handle_s *) handle; - - ah->event_cb = cb; - ah->user_data = user_data; - - return NNS_EDGE_ERROR_NONE; -} - -/** - * @brief Internal util function to send edge-data. - */ -int -nns_edge_aitt_send_data (nns_edge_aitt_h handle, nns_edge_data_h data_h) -{ - int ret; - void *data = NULL; - nns_size_t size; - - ret = nns_edge_data_serialize (data_h, &data, &size); - if (NNS_EDGE_ERROR_NONE != ret) { - nns_edge_loge ("Failed to serialize the edge data."); - return ret; - } - - ret = nns_edge_aitt_publish (handle, data, size); - if (NNS_EDGE_ERROR_NONE != ret) - nns_edge_loge ("Failed to send data to destination."); - - SAFE_FREE (data); - return ret; -} - -/** - * @brief Parse aitt option from the key. - */ -static aitt_option_e -_nns_edge_parse_aitt_option (const char *key) -{ - aitt_option_e aitt_opt; - - if (0 == strcasecmp (key, "my-ip")) - aitt_opt = AITT_OPT_UNKNOWN; - else if (0 == strcasecmp (key, "clean-session")) - aitt_opt = AITT_OPT_CLEAN_SESSION; - else if (0 == strcasecmp (key, "custom-broker")) - aitt_opt = AITT_OPT_CUSTOM_BROKER; - else if (0 == strcasecmp (key, "service-id")) - aitt_opt = AITT_OPT_SERVICE_ID; - else if (0 == strcasecmp (key, "location-id")) - aitt_opt = AITT_OPT_LOCATION_ID; - else if (0 == strcasecmp (key, "root-ca")) - aitt_opt = AITT_OPT_ROOT_CA; - else if (0 == strcasecmp (key, "custom-rw-file")) - aitt_opt = AITT_OPT_CUSTOM_RW_FILE; - else - aitt_opt = AITT_OPT_UNKNOWN; - - return aitt_opt; -} - -/** - * @brief Internal util function to set AITT option. - */ -int -nns_edge_aitt_set_option (nns_edge_aitt_h handle, const char *key, - const char *value) -{ - nns_edge_aitt_handle_s *ah; - aitt_option_e aitt_opt; - - if (!handle) { - nns_edge_loge ("Invalid param, given AITT handle is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - if (!STR_IS_VALID (key)) { - nns_edge_loge - ("The parameter, 'key' is NULL. It should be a valid const char*"); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - if (!STR_IS_VALID (value)) { - nns_edge_loge - ("The parameter, 'value' is NULL. It should be a valid const char*"); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - ah = (nns_edge_aitt_handle_s *) handle; - - if (0 == strcasecmp (key, "protocol")) { - if (0 == strcasecmp (value, "TCP")) { - ah->protocol = AITT_TYPE_TCP; - } else if (0 == strcasecmp (value, "MQTT")) { - ah->protocol = AITT_TYPE_MQTT; - } else if (0 == strcasecmp (value, "TCP_SECURE") || - 0 == strcasecmp (value, "TCP-SECURE")) { - ah->protocol = AITT_TYPE_TCP_SECURE; - } else { - nns_edge_logw ("Invalid AITT protocol. Please check the value: %s", - value); - } - } else { - aitt_opt = _nns_edge_parse_aitt_option (key); - if (AITT_OPT_UNKNOWN == aitt_opt) { - nns_edge_loge ("Invalid AITT option key: %s, please check the key", key); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - if (AITT_ERROR_NONE != aitt_option_set (ah->option, aitt_opt, value)) { - nns_edge_loge ("Failed to set AITT option, key:value= %s:%s", key, value); - return NNS_EDGE_ERROR_UNKNOWN; - } - } - - return NNS_EDGE_ERROR_NONE; -} - -/** - * @brief Internal util function to get AITT option. - */ -const char * -nns_edge_aitt_get_option (nns_edge_aitt_h handle, const char *key) -{ - nns_edge_aitt_handle_s *ah; - aitt_option_e aitt_opt; - - if (!handle) { - nns_edge_loge ("Invalid param, given AITT handle is invalid."); - return NULL; - } - - if (!STR_IS_VALID (key)) { - nns_edge_loge - ("The parameter, 'key' is NULL. It should be a valid const char*"); - return NULL; - } - - ah = (nns_edge_aitt_handle_s *) handle; - - aitt_opt = _nns_edge_parse_aitt_option (key); - if (AITT_OPT_UNKNOWN == aitt_opt) { - nns_edge_loge ("Invalid AITT option key: %s, please check the key", key); - return NULL; - } - - return aitt_option_get (ah->option, aitt_opt); -} - -/** - * @brief Create AITT handle. - */ -int -nns_edge_aitt_create (nns_edge_aitt_h * handle) -{ - nns_edge_aitt_handle_s *ah; - aitt_option_h option; - - if (!handle) { - nns_edge_loge ("Invalid param, handle should not be null."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - ah = (nns_edge_aitt_handle_s *) calloc (1, sizeof (nns_edge_aitt_handle_s)); - if (!ah) { - nns_edge_loge ("Failed to allocate memory for AITT handle."); - return NNS_EDGE_ERROR_OUT_OF_MEMORY; - } - - option = aitt_option_new (); - if (!option) { - nns_edge_loge ("Failed to allocate memory for AITT handle."); - nns_edge_free (ah); - return NNS_EDGE_ERROR_UNKNOWN; - } - ah->option = option; - ah->protocol = AITT_TYPE_TCP; - - *handle = ah; - - return NNS_EDGE_ERROR_NONE; -} diff --git a/src/libnnstreamer-edge/nnstreamer-edge-aitt.h b/src/libnnstreamer-edge/nnstreamer-edge-aitt.h deleted file mode 100644 index 2e0b84d..0000000 --- a/src/libnnstreamer-edge/nnstreamer-edge-aitt.h +++ /dev/null @@ -1,104 +0,0 @@ -/* 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 */ - -typedef void *nns_edge_aitt_h; - -#if defined(ENABLE_AITT) -#include - -/** - * @brief Connect to AITT. - * @note This is internal function for AITT. - */ -int nns_edge_aitt_connect (nns_edge_aitt_h handle, const char *id, const char *topic, const char *host, const int port); - -/** - * @brief Release the AITT handle. - * @note This is internal function for AITT. - */ -int nns_edge_aitt_close (nns_edge_aitt_h handle); - -/** - * @brief Publish raw data. - * @note This is internal function for AITT. - */ -int nns_edge_aitt_publish (nns_edge_aitt_h handle, const void *data, const int length); - -/** - * @brief Publish raw data with protocol and QoS. - * @note This is internal function for AITT. - */ -int nns_edge_aitt_publish_full (nns_edge_aitt_h handle, const void *data, const int length, aitt_protocol_e protocol, aitt_qos_e qos); - -/** - * @brief Subscribe a topic. - * @note This is internal function for AITT. - */ -int nns_edge_aitt_subscribe (nns_edge_aitt_h handle); - -/** - * @brief Set event callback for new message. - */ -int nns_edge_aitt_set_event_callback (nns_edge_aitt_h handle, nns_edge_event_cb cb, void *user_data); - -/** - * @brief Check whether aitt handle exists or not. - */ -int nns_edge_aitt_is_connected (nns_edge_aitt_h handle); - -/** - * @brief Internal util function to send edge-data. - */ -int nns_edge_aitt_send_data (nns_edge_aitt_h handle, nns_edge_data_h data_h); - -/** - * @brief Internal util function to set AITT option. - */ -int nns_edge_aitt_set_option (nns_edge_aitt_h handle, const char *key, const char *value); - -/** - * @brief Internal util function to get AITT option. - */ -const char *nns_edge_aitt_get_option (nns_edge_aitt_h handle, const char *key); - -/** - * @brief Create AITT handle. - */ -int nns_edge_aitt_create (nns_edge_aitt_h *handle); - -#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_publish_full(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_aitt_subscribe(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_aitt_set_event_callback(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_aitt_is_connected(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_aitt_send_data(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_aitt_set_option(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_aitt_get_option(...) (NNS_EDGE_ERROR_NOT_SUPPORTED) -#define nns_edge_aitt_create(...) (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.c b/src/libnnstreamer-edge/nnstreamer-edge-internal.c index b79aa5a..ac7c9db 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-internal.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-internal.c @@ -20,7 +20,6 @@ #include "nnstreamer-edge-log.h" #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" @@ -73,7 +72,7 @@ typedef struct nns_edge_queue_h send_queue; pthread_t send_thread; - /* MQTT or AITT handle */ + /* MQTT handle */ void *broker_h; /* Data for custom connection */ @@ -915,11 +914,6 @@ _nns_edge_send_thread (void *thread_data) } } break; - case NNS_EDGE_CONNECT_TYPE_AITT: - ret = nns_edge_aitt_send_data (eh->broker_h, data_h); - if (NNS_EDGE_ERROR_NONE != ret) - nns_edge_loge ("Failed to send data via AITT connection."); - break; case NNS_EDGE_CONNECT_TYPE_MQTT: ret = nns_edge_mqtt_publish_data (eh->broker_h, data_h); if (NNS_EDGE_ERROR_NONE != ret) @@ -1402,19 +1396,7 @@ nns_edge_create_handle (const char *id, nns_edge_connect_type_e connect_type, eh = (nns_edge_handle_s *) (*edge_h); eh->connect_type = connect_type; - if (NNS_EDGE_CONNECT_TYPE_AITT == connect_type) { - ret = nns_edge_aitt_create (&eh->broker_h); - if (NNS_EDGE_ERROR_NONE != ret) { - nns_edge_loge ("Failed to create AITT handle."); - goto error; - } - } - return NNS_EDGE_ERROR_NONE; - -error: - nns_edge_release_handle (eh); - return ret; } /** @@ -1500,20 +1482,6 @@ nns_edge_start (nns_edge_h edge_h) goto done; } } - } else if (NNS_EDGE_CONNECT_TYPE_AITT == eh->connect_type) { - ret = nns_edge_aitt_connect (eh->broker_h, eh->id, eh->topic, - eh->dest_host, eh->dest_port); - if (NNS_EDGE_ERROR_NONE != ret) { - nns_edge_loge ("Failed to connect to AITT broker."); - goto done; - } - - ret = nns_edge_aitt_set_event_callback (eh->broker_h, eh->event_cb, - eh->user_data); - if (NNS_EDGE_ERROR_NONE != ret) { - nns_edge_loge ("Failed to set event callback to AITT broker."); - goto done; - } } } @@ -1604,11 +1572,6 @@ nns_edge_release_handle (nns_edge_h edge_h) nns_edge_logw ("Failed to close mqtt connection."); } break; - case NNS_EDGE_CONNECT_TYPE_AITT: - if (NNS_EDGE_ERROR_NONE != nns_edge_aitt_close (eh->broker_h)) { - nns_edge_logw ("Failed to close AITT connection."); - } - break; case NNS_EDGE_CONNECT_TYPE_CUSTOM: nns_edge_custom_release (&eh->custom); break; @@ -1839,27 +1802,6 @@ nns_edge_connect (nns_edge_h edge_h, const char *dest_host, int dest_port) goto done; } } - } else if (NNS_EDGE_CONNECT_TYPE_AITT == eh->connect_type) { - ret = nns_edge_aitt_connect (eh->broker_h, eh->id, eh->topic, dest_host, - dest_port); - if (ret != NNS_EDGE_ERROR_NONE) { - nns_edge_loge ("Failed to connect to AITT broker. %s:%d", dest_host, - dest_port); - goto done; - } - - ret = nns_edge_aitt_set_event_callback (eh->broker_h, eh->event_cb, - eh->user_data); - if (NNS_EDGE_ERROR_NONE != ret) { - nns_edge_loge ("Failed to set event callback to AITT broker."); - goto done; - } - - ret = nns_edge_aitt_subscribe (eh->broker_h); - if (NNS_EDGE_ERROR_NONE != ret) { - nns_edge_loge ("Failed to subscribe the topic using AITT: %s", eh->topic); - goto done; - } } else if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) { ret = nns_edge_custom_connect (&eh->custom); if (ret != NNS_EDGE_ERROR_NONE) { @@ -1923,10 +1865,6 @@ nns_edge_is_connected (nns_edge_h edge_h) return NNS_EDGE_ERROR_INVALID_PARAMETER; } - if (NNS_EDGE_CONNECT_TYPE_AITT == eh->connect_type && - NNS_EDGE_ERROR_NONE == nns_edge_aitt_is_connected (eh->broker_h)) - return NNS_EDGE_ERROR_NONE; - if (NNS_EDGE_CONNECT_TYPE_MQTT == eh->connect_type && nns_edge_mqtt_is_connected (eh->broker_h)) return NNS_EDGE_ERROR_NONE; @@ -2090,18 +2028,6 @@ nns_edge_set_info (nns_edge_h edge_h, const char *key, const char *value) if (ret == NNS_EDGE_ERROR_NONE) nns_edge_queue_set_limit (eh->send_queue, limit, leaky); - } else if (0 == strcasecmp (key, "my-ip") || - 0 == strcasecmp (key, "clean-session") || - 0 == strcasecmp (key, "custom-broker") || - 0 == strcasecmp (key, "service-id") || - 0 == strcasecmp (key, "location-id") || - 0 == strcasecmp (key, "root-ca") || - 0 == strcasecmp (key, "custom-rw-file")) { - if (NNS_EDGE_CONNECT_TYPE_AITT == eh->connect_type) { - ret = nns_edge_aitt_set_option (eh->broker_h, key, value); - } else { - nns_edge_metadata_set (eh->metadata, key, value); - } } else { ret = nns_edge_metadata_set (eh->metadata, key, value); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5a919be..218e8e6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,14 +17,6 @@ TARGET_INCLUDE_DIRECTORIES(unittest_nnstreamer-edge-custom PRIVATE ${EDGE_REQUIR TARGET_LINK_LIBRARIES(unittest_nnstreamer-edge-custom ${TEST_REQUIRE_PKGS_LDFLAGS} ${NNS_EDGE_LIB_NAME} ${NNS_EDGE_CUSTOM_TEST_LIB_NAME}) INSTALL (TARGETS unittest_nnstreamer-edge-custom DESTINATION ${BIN_INSTALL_DIR}) -# AITT test -IF(AITT_SUPPORT) -ADD_EXECUTABLE(unittest_nnstreamer-edge-aitt unittest_nnstreamer-edge-aitt.cc) -TARGET_INCLUDE_DIRECTORIES(unittest_nnstreamer-edge-aitt PRIVATE ${EDGE_REQUIRE_PKGS_INCLUDE_DIRS} ${INCLUDE_DIR} ${NNS_EDGE_SRC_DIR}) -TARGET_LINK_LIBRARIES(unittest_nnstreamer-edge-aitt ${TEST_REQUIRE_PKGS_LDFLAGS} ${NNS_EDGE_LIB_NAME}) -INSTALL (TARGETS unittest_nnstreamer-edge-aitt DESTINATION ${BIN_INSTALL_DIR}) -ENDIF() - # MQTT test IF(MQTT_SUPPORT) ADD_EXECUTABLE(unittest_nnstreamer-edge-mqtt unittest_nnstreamer-edge-mqtt.cc) diff --git a/tests/unittest_nnstreamer-edge-aitt.cc b/tests/unittest_nnstreamer-edge-aitt.cc deleted file mode 100644 index 877e6d2..0000000 --- a/tests/unittest_nnstreamer-edge-aitt.cc +++ /dev/null @@ -1,666 +0,0 @@ -/** - * @file unittest_nnstreamer-edge-aitt.cc - * @date 26 Aug 2022 - * @brief Unittest for nnstreamer-edge AITT support. - * @see https://github.com/nnstreamer/nnstreamer-edge - * @author Jaeyun Jung - * @bug No known bugs - */ - -#include -#include "nnstreamer-edge.h" -#include "nnstreamer-edge-aitt.h" -#include "nnstreamer-edge-log.h" -#include "nnstreamer-edge-util.h" - -/** - * @brief Data struct for unittest. - */ -typedef struct -{ - nns_edge_h handle; - bool running; - bool is_server; - bool event_cb_released; - unsigned int received; -} ne_test_data_s; - -/** - * @brief Allocate and initialize test data. - */ -static ne_test_data_s * -_get_test_data (bool is_server) -{ - ne_test_data_s *_td; - - _td = (ne_test_data_s *) calloc (1, sizeof (ne_test_data_s)); - - if (_td) { - _td->is_server = is_server; - } - - return _td; -} - -/** - * @brief Release test data. - */ -static void -_free_test_data (ne_test_data_s *_td) -{ - if (!_td) - return; - - SAFE_FREE (_td); -} - -/** - * @brief Edge event callback for test. - */ -static int -_test_edge_event_cb (nns_edge_event_h event_h, void *user_data) -{ - ne_test_data_s *_td = (ne_test_data_s *) user_data; - nns_edge_event_e event = NNS_EDGE_EVENT_UNKNOWN; - nns_edge_data_h data_h; - void *data; - nns_size_t data_len; - unsigned int i, count; - int ret; - - if (!_td) { - /* Cannot update event status. */ - return NNS_EDGE_ERROR_NONE; - } - - ret = nns_edge_event_get_type (event_h, &event); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - switch (event) { - case NNS_EDGE_EVENT_CALLBACK_RELEASED: - _td->event_cb_released = true; - break; - case NNS_EDGE_EVENT_NEW_DATA_RECEIVED: - _td->received++; - ret = nns_edge_event_parse_new_data (event_h, &data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - /* Compare received data */ - ret = nns_edge_data_get_count (data_h, &count); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - EXPECT_EQ (count, 2U); - - ret = nns_edge_data_get (data_h, 0, &data, &data_len); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - for (i = 0; i < 10U; i++) - EXPECT_EQ (((unsigned int *) data)[i], i); - - ret = nns_edge_data_get (data_h, 1, &data, &data_len); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - for (i = 0; i < 20U; i++) - EXPECT_EQ (((unsigned int *) data)[i], 20 - i); - - ret = nns_edge_data_destroy (data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - break; - default: - break; - } - - return NNS_EDGE_ERROR_NONE; -} - -/** - * @brief Check whether MQTT broker is running or not. - */ -static bool -_check_mqtt_broker () -{ - int ret = 0; - - ret = system ("ps aux | grep mosquitto | grep -v grep"); - if (0 != ret) { - nns_edge_logw ("MQTT broker is not running. Skip query hybrid test."); - return false; - } - - return true; -} - -/** - * @brief Connect to local host, multiple clients. - */ -TEST(edgeAitt, connectLocal) -{ - nns_edge_h server_h, client1_h, client2_h; - ne_test_data_s *_td_server, *_td_client1, *_td_client2; - nns_edge_data_h data_h; - nns_size_t data_len; - void *data1, *data2; - unsigned int i, retry; - int ret, port; - char *val; - - if (!_check_mqtt_broker ()) - return; - - _td_server = _get_test_data (true); - _td_client1 = _get_test_data (false); - _td_client2 = _get_test_data (false); - ASSERT_TRUE (_td_server != NULL && _td_client1 != NULL && _td_client2 != NULL); - port = nns_edge_get_available_port (); - - /* Prepare server (127.0.0.1:port) */ - val = nns_edge_strdup_printf ("%d", port); - nns_edge_create_handle ("temp-sender", NNS_EDGE_CONNECT_TYPE_AITT, - NNS_EDGE_NODE_TYPE_PUB, &server_h); - nns_edge_set_info (server_h, "IP", "127.0.0.1"); - nns_edge_set_info (server_h, "PORT", val); - nns_edge_set_info (server_h, "DEST_IP", "127.0.0.1"); - nns_edge_set_info (server_h, "DEST_PORT", "1883"); - nns_edge_set_info (server_h, "TOPIC", "AITT_TEST_TOPIC"); - _td_server->handle = server_h; - SAFE_FREE (val); - - /* Prepare client */ - nns_edge_create_handle ("temp-receiver", NNS_EDGE_CONNECT_TYPE_AITT, - NNS_EDGE_NODE_TYPE_SUB, &client1_h); - nns_edge_set_event_callback (client1_h, _test_edge_event_cb, _td_client1); - nns_edge_set_info (client1_h, "TOPIC", "AITT_TEST_TOPIC"); - _td_client1->handle = client1_h; - - nns_edge_create_handle ("temp-client2", NNS_EDGE_CONNECT_TYPE_AITT, - NNS_EDGE_NODE_TYPE_SUB, &client2_h); - nns_edge_set_event_callback (client2_h, _test_edge_event_cb, _td_client2); - nns_edge_set_info (client2_h, "TOPIC", "AITT_TEST_TOPIC"); - _td_client2->handle = client2_h; - - - ret = nns_edge_start (server_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - ret = nns_edge_start (client1_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - ret = nns_edge_start (client2_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - usleep (200000); - - ret = nns_edge_connect (client1_h, "127.0.0.1", 1883); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - usleep (10000); - ret = nns_edge_connect (client2_h, "127.0.0.1", 1883); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - sleep (2); - - /* Send request to server */ - data_len = 10U * sizeof (unsigned int); - data1 = malloc (data_len); - ASSERT_TRUE (data1 != NULL); - - data2 = malloc (data_len * 2); - ASSERT_TRUE (data2 != NULL); - - for (i = 0; i < 10U; i++) - ((unsigned int *) data1)[i] = i; - - for (i = 0; i < 20U; i++) - ((unsigned int *) data2)[i] = 20 - i; - - ret = nns_edge_data_create (&data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_add (data_h, data1, data_len, nns_edge_free); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_add (data_h, data2, data_len * 2, nns_edge_free); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - for (i = 0; i < 5U; i++) { - ret = nns_edge_send (server_h, data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - usleep (10000); - } - - ret = nns_edge_data_destroy (data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - /* Wait for responding data (20 seconds) */ - retry = 0U; - do { - usleep (100000); - if (_td_client1->received > 0 && _td_client2->received > 0) - break; - } while (retry++ < 200U); - - ret = nns_edge_disconnect (server_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_release_handle (server_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - ret = nns_edge_release_handle (client1_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - ret = nns_edge_release_handle (client2_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - EXPECT_TRUE (_td_client1->received > 0); - EXPECT_TRUE (_td_client2->received > 0); - - _free_test_data (_td_server); - _free_test_data (_td_client1); - _free_test_data (_td_client2); -} - -/** - * @brief Connect to the mqtt broker with invalid param. - */ -TEST(edgeAitt, connectInvalidParam1_n) -{ - int ret = -1; - nns_edge_aitt_h handle; - - if (!_check_mqtt_broker ()) - return; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_connect (handle, NULL, "temp-aitt-topic", "127.0.0.1", 1883); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_connect (handle, "", "temp-aitt-topic", "127.0.0.1", 1883); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Connect to the mqtt broker with invalid param. - */ -TEST(edgeAitt, connectInvalidParam2_n) -{ - int ret = -1; - nns_edge_aitt_h handle; - - if (!_check_mqtt_broker ()) - return; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_connect (handle, "temp-aitt-id", NULL, "127.0.0.1", 1883); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_connect (handle, "temp-aitt-id", "", "127.0.0.1", 1883); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Connect to the mqtt broker with invalid param. - */ -TEST(edgeAitt, connectInvalidParam3_n) -{ - int ret = -1; - nns_edge_aitt_h handle; - - if (!_check_mqtt_broker ()) - return; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_connect (handle, "temp-aitt-id", "temp-aitt-topic", NULL, 1883); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_connect (handle, "temp-aitt-id", "temp-aitt-topic", "", 1883); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Connect to the mqtt broker with invalid param. - */ -TEST(edgeAitt, connectInvalidParam4_n) -{ - int ret = -1; - nns_edge_aitt_h handle; - - if (!_check_mqtt_broker ()) - return; - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_connect (handle, "temp-aitt-id", "temp-aitt-topic", "127.0.0.1", -1); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Connect to the mqtt broker with invalid param. - */ -TEST(edgeAitt, connectInvalidParam5_n) -{ - int ret = -1; - nns_edge_aitt_h handle; - - if (!_check_mqtt_broker ()) - return; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_connect (NULL, "temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 1883); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Close the mqtt handle with invalid param. - */ -TEST(edgeAitt, closeInvalidParam_n) -{ - int ret = -1; - - if (!_check_mqtt_broker ()) - return; - - ret = nns_edge_aitt_close (NULL); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Publish with invalid param. - */ -TEST(edgeAitt, publishInvalidParam_n) -{ - int ret = -1; - const char *msg = "TEMP_MESSAGE"; - - if (!_check_mqtt_broker ()) - return; - - ret = nns_edge_aitt_publish (NULL, msg, strlen (msg) + 1); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Publish with invalid param. - */ -TEST(edgeAitt, publishInvalidParam2_n) -{ - int ret = -1; - nns_edge_aitt_h handle; - const char *msg = "TEMP_MESSAGE"; - - if (!_check_mqtt_broker ()) - return; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_connect (handle, "temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 1883); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - /* data is null */ - ret = nns_edge_aitt_publish (handle, NULL, strlen (msg) + 1); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Publish with invalid param. - */ -TEST(edgeAitt, publishInvalidParam3_n) -{ - int ret = -1; - nns_edge_aitt_h handle; - const char *msg = "TEMP_MESSAGE"; - - if (!_check_mqtt_broker ()) - return; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_connect (handle, "temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 1883); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - /* data length is 0 */ - ret = nns_edge_aitt_publish (handle, msg, 0); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Subscribe the topic with invalid param. - */ -TEST(edgeAitt, subscribeInvalidParam_n) -{ - int ret = -1; - - if (!_check_mqtt_broker ()) - return; - - ret = nns_edge_aitt_subscribe (NULL); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Check connection with invalid param. - */ -TEST(edgeAitt, checkConnectionInvalidParam_n) -{ - int ret = -1; - - if (!_check_mqtt_broker ()) - return; - - ret = nns_edge_aitt_is_connected (NULL); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Set and get AITT option. - */ -TEST(edgeAitt, setGetOption_p) -{ - int ret = -1; - nns_edge_aitt_h handle; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_set_option (handle, "custom-broker", "true"); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - EXPECT_STREQ ("true", nns_edge_aitt_get_option (handle, "custom-broker")); - - ret = nns_edge_aitt_set_option (handle, "clean-session", "true"); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - EXPECT_STREQ ("true", nns_edge_aitt_get_option (handle, "clean-session")); - - ret = nns_edge_aitt_set_option (handle, "service-id", "test_service_id"); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - EXPECT_STREQ ("test_service_id", nns_edge_aitt_get_option (handle, "service-id")); - - ret = nns_edge_aitt_set_option (handle, "location-id", "test_location_id"); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - EXPECT_STREQ ("test_location_id", nns_edge_aitt_get_option (handle, "location-id")); - - ret = nns_edge_aitt_set_option (handle, "root-ca", "root_ca_path"); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - EXPECT_STREQ ("root_ca_path", nns_edge_aitt_get_option (handle, "root-ca")); - - ret = nns_edge_aitt_set_option (handle, "custom-rw-file", "custom_rw_file_path"); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - EXPECT_STREQ ("custom_rw_file_path", nns_edge_aitt_get_option (handle, "custom-rw-file")); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief create AITT handle with invalid param. - */ -TEST(edgeAitt, createInvalidParam_n) -{ - int ret = -1; - - ret = nns_edge_aitt_create (NULL); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief set AITT option with invalid param. - */ -TEST(edgeAitt, setOptionInvalidParam_n) -{ - int ret = -1; - nns_edge_aitt_h handle; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_set_option (NULL, "custom-broker", "true"); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_set_option (handle, NULL, "true"); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_set_option (handle, "custom-broker", NULL); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_set_option (handle, "custom-broker", "not_boolean_str"); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Set custom option even it's not a custom broker. - */ -TEST(edgeAitt, setOptionNoCustomBroker_n) -{ - int ret = -1; - nns_edge_aitt_h handle; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_set_option (handle, "custom-broker", "false"); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_set_option (handle, "service-id", "test_service_id"); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_set_option (handle, "location-id", "test_location_id"); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_set_option (handle, "root-ca", "root_ca_path"); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_set_option (handle, "custom-rw-file", "custom_rw_file_path"); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief set AITT option with invalid key. - */ -TEST(edgeAitt, setOptionInvalidkey_n) -{ - int ret = -1; - nns_edge_aitt_h handle; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_set_option (handle, "invalid_key", "true"); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief get AITT option with invalid param. - */ -TEST(edgeAitt, getOptionInvalidParam_n) -{ - int ret = -1; - const char *ret_str = NULL; - nns_edge_aitt_h handle; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret_str = nns_edge_aitt_get_option (handle, "custom-broker"); - EXPECT_STREQ (ret_str, "false"); - - ret_str = nns_edge_aitt_get_option (NULL, "custom-broker"); - EXPECT_STREQ (ret_str, NULL); - - ret_str = nns_edge_aitt_get_option (handle, NULL); - EXPECT_STREQ (ret_str, NULL); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief get AITT option with invalid key. - */ -TEST(edgeAitt, getOptionInvalidkey_n) -{ - int ret = -1; - const char *ret_str = NULL; - nns_edge_aitt_h handle; - - ret = nns_edge_aitt_create (&handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret_str = nns_edge_aitt_get_option (handle, "invalid_key"); - EXPECT_STREQ (ret_str, NULL); - - ret = nns_edge_aitt_close (handle); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Main gtest - */ -int -main (int argc, char **argv) -{ - int result = -1; - - try { - testing::InitGoogleTest (&argc, argv); - } catch (...) { - nns_edge_loge ("Catch exception, failed to init google test."); - } - - try { - result = RUN_ALL_TESTS (); - } catch (...) { - nns_edge_loge ("Catch exception, failed to run the unittest."); - } - - return result; -}