[AITT] separate handle
authorJaeyun <jy1210.jung@samsung.com>
Fri, 2 Dec 2022 09:09:12 +0000 (18:09 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Tue, 6 Dec 2022 07:42:01 +0000 (16:42 +0900)
Separate AITT handle and update related code, to remove dependency to nns-edge handle.

Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
src/libnnstreamer-edge/nnstreamer-edge-aitt.c
src/libnnstreamer-edge/nnstreamer-edge-aitt.h
src/libnnstreamer-edge/nnstreamer-edge-internal.c
tests/unittest_nnstreamer-edge-aitt.cc

index ecb6697ee4df218ac9bc10a9e44f72f0730dee51..36ac30f6ad3a38bb7fd21bed21a535a0b1ac2d6b 100644 (file)
@@ -30,27 +30,52 @@ 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;
 } nns_edge_aitt_handle_s;
 
 /**
  * @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)
+nns_edge_aitt_connect (const char *id, const char *topic, const char *host,
+    const int port, nns_edge_aitt_h * handle)
 {
-  nns_edge_handle_s *eh;
   nns_edge_aitt_handle_s *ah;
   aitt_option_h option;
 
-  eh = (nns_edge_handle_s *) edge_h;
+  if (!STR_IS_VALID (id)) {
+    nns_edge_loge ("Invalid param, given id is invalid.");
+    return NNS_EDGE_ERROR_INVALID_PARAMETER;
+  }
 
-  if (!NNS_EDGE_MAGIC_IS_VALID (eh)) {
-    nns_edge_loge ("Invalid param, given edge handle is invalid.");
+  if (!STR_IS_VALID (topic)) {
+    nns_edge_loge ("Invalid param, given topic is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  nns_edge_logd ("Create AITT instance: My address: %s:%d", eh->host, eh->port);
+  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;
+  }
+
+  nns_edge_logd ("Create AITT instance: broker address: %s:%d", host, port);
 
   ah = (nns_edge_aitt_handle_s *) calloc (1, sizeof (nns_edge_aitt_handle_s));
   if (!ah) {
@@ -59,9 +84,9 @@ nns_edge_aitt_connect (nns_edge_h edge_h)
   }
 
   option = aitt_option_new ();
-  aitt_option_set (option, AITT_OPT_MY_IP, eh->host);
+  aitt_option_set (option, AITT_OPT_MY_IP, "localhost");
 
-  ah->aitt_handle = aitt_new (eh->id, option);
+  ah->aitt_handle = aitt_new (id, option);
   aitt_option_destroy (option);
 
   if (!ah->aitt_handle) {
@@ -70,45 +95,55 @@ nns_edge_aitt_connect (nns_edge_h edge_h)
     return NNS_EDGE_ERROR_UNKNOWN;
   }
 
-  if (AITT_ERROR_NONE != aitt_connect (ah->aitt_handle, eh->dest_host,
-          eh->dest_port)) {
-    nns_edge_loge ("Failed to connect to AITT. IP:port = %s:%d", eh->dest_host,
-        eh->dest_port);
+  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;
   }
-  eh->broker_h = ah;
 
+  ah->id = nns_edge_strdup (id);
+  ah->topic = nns_edge_strdup (topic);
+  ah->host = nns_edge_strdup (host);
+  ah->port = port;
+
+  *handle = ah;
   return NNS_EDGE_ERROR_NONE;
 }
 
 /**
  * @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)
+nns_edge_aitt_close (nns_edge_aitt_h handle)
 {
-  nns_edge_handle_s *eh;
   nns_edge_aitt_handle_s *ah;
 
-  eh = (nns_edge_handle_s *) edge_h;
-
-  if (!NNS_EDGE_MAGIC_IS_VALID (eh) || !eh->broker_h) {
-    nns_edge_loge ("Invalid param, given edge handle is invalid.");
+  if (!handle) {
+    nns_edge_loge ("Invalid param, given AITT handle is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  ah = (nns_edge_aitt_handle_s *) eh->broker_h;
-  if (AITT_ERROR_NONE != aitt_disconnect (ah->aitt_handle)) {
-    nns_edge_loge ("Failed to close AITT handle.");
-    return NNS_EDGE_ERROR_UNKNOWN;
+  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;
   }
-  aitt_destroy (ah->aitt_handle);
-  ah->aitt_handle = NULL;
-  SAFE_FREE (eh->broker_h);
-  eh->broker_h = NULL;
+
+  SAFE_FREE (ah->id);
+  SAFE_FREE (ah->topic);
+  SAFE_FREE (ah->host);
+  SAFE_FREE (ah);
 
   return NNS_EDGE_ERROR_NONE;
 }
@@ -117,20 +152,17 @@ 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)
+nns_edge_aitt_is_connected (nns_edge_aitt_h handle)
 {
-  nns_edge_handle_s *eh;
   nns_edge_aitt_handle_s *ah;
 
-  eh = (nns_edge_handle_s *) edge_h;
-
-  if (!NNS_EDGE_MAGIC_IS_VALID (eh)) {
-    nns_edge_loge ("Invalid param, given edge handle is invalid.");
+  if (!handle) {
+    nns_edge_loge ("Invalid param, given AITT handle is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  ah = (nns_edge_aitt_handle_s *) eh->broker_h;
-  if (!ah || !ah->aitt_handle) {
+  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;
   }
@@ -140,19 +172,16 @@ 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)
+nns_edge_aitt_publish (nns_edge_aitt_h handle, const void *data,
+    const int length)
 {
-  nns_edge_handle_s *eh;
   nns_edge_aitt_handle_s *ah;
   int ret;
 
-  eh = (nns_edge_handle_s *) edge_h;
-
-  if (!NNS_EDGE_MAGIC_IS_VALID (eh) || !eh->broker_h) {
-    nns_edge_loge ("Invalid param, given edge handle is invalid.");
+  if (!handle) {
+    nns_edge_loge ("Invalid param, given AITT handle is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
@@ -161,11 +190,11 @@ nns_edge_aitt_publish (nns_edge_h edge_h, const void *data, const int length)
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  ah = (nns_edge_aitt_handle_s *) eh->broker_h;
+  ah = (nns_edge_aitt_handle_s *) handle;
 
-  ret = aitt_publish (ah->aitt_handle, eh->topic, data, length);
+  ret = aitt_publish (ah->aitt_handle, ah->topic, data, length);
   if (AITT_ERROR_NONE != ret) {
-    nns_edge_loge ("Failed to publish the message. topic: %s", eh->topic);
+    nns_edge_loge ("Failed to publish the message. topic: %s", ah->topic);
     return NNS_EDGE_ERROR_IO;
   }
 
@@ -179,14 +208,14 @@ static void
 aitt_cb_message_arrived (aitt_msg_h msg_handle, const void *msg,
     int msg_len, void *user_data)
 {
-  nns_edge_handle_s *eh;
+  nns_edge_aitt_handle_s *ah;
   nns_edge_data_h data_h;
   int ret;
 
-  eh = (nns_edge_handle_s *) user_data;
+  ah = (nns_edge_aitt_handle_s *) user_data;
 
-  if (!NNS_EDGE_MAGIC_IS_VALID (eh)) {
-    nns_edge_loge ("Invalid param, given edge handle is invalid.");
+  if (!ah || !ah->event_cb) {
+    nns_edge_logw ("The event callback is null, cannot handle new message.");
     return;
   }
 
@@ -197,7 +226,7 @@ aitt_cb_message_arrived (aitt_msg_h msg_handle, const void *msg,
 
   nns_edge_data_deserialize (data_h, (void *) msg, (nns_size_t) msg_len);
 
-  ret = nns_edge_event_invoke_callback (eh->event_cb, eh->user_data,
+  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.");
@@ -207,33 +236,69 @@ aitt_cb_message_arrived (aitt_msg_h msg_handle, const void *msg,
 
 /**
  * @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)
+nns_edge_aitt_subscribe (nns_edge_aitt_h handle)
 {
-  nns_edge_handle_s *eh;
   nns_edge_aitt_handle_s *ah;
 
-  eh = (nns_edge_handle_s *) edge_h;
-
-  if (!NNS_EDGE_MAGIC_IS_VALID (eh) || !eh->broker_h) {
-    nns_edge_loge ("Invalid param, given edge handle is invalid.");
+  if (!handle) {
+    nns_edge_loge ("Invalid param, given AITT handle is invalid.");
     return NNS_EDGE_ERROR_INVALID_PARAMETER;
   }
 
-  if (!eh->topic) {
-    nns_edge_loge ("Invalid param, topic cannot be NULL for AITT connection. "
-        "Please set topic using nns_edge_set_info()");
-    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;
+}
 
-  ah = (nns_edge_aitt_handle_s *) eh->broker_h;
+/**
+ * @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 (AITT_ERROR_NONE != aitt_subscribe (ah->aitt_handle, eh->topic,
-          aitt_cb_message_arrived, eh, &ah->sub_handle)) {
-    nns_edge_loge ("Failed to subscribe the topic: %s", eh->topic);
-    return NNS_EDGE_ERROR_UNKNOWN;
+  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.");
+
+  nns_edge_free (data);
+  return ret;
+}
index 44da6e547f1beb3674c3e732fa8b7c9ddc1f0fe5..3b2a341f9d7b67054e71a4b682bfe7dd899ff6e5 100644 (file)
 extern "C" {
 #endif /* __cplusplus */
 
+typedef void *nns_edge_aitt_h;
+
 #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.
+ * @note This is internal function for AITT.
  */
-int nns_edge_aitt_connect (nns_edge_h edge_h);
+int nns_edge_aitt_connect (const char *id, const char *topic, const char *host, const int port, nns_edge_aitt_h *handle);
 
 /**
  * @brief Release the AITT handle.
- * @note This is internal function for AITT. You should call this with edge-handle lock.
+ * @note This is internal function for AITT.
  */
-int nns_edge_aitt_close (nns_edge_h edge_h);
+int nns_edge_aitt_close (nns_edge_aitt_h handle);
 
 /**
- * @brief Check whether aitt handle exists or not.
+ * @brief Publish raw data.
+ * @note This is internal function for AITT.
  */
-int nns_edge_aitt_is_connected (nns_edge_h edge_h);
+int nns_edge_aitt_publish (nns_edge_aitt_h handle, const void *data, const int length);
 
 /**
- * @brief Publish raw data.
- * @note This is internal function forAITT. You should call this with edge-handle lock.
+ * @brief Subscribe a topic.
+ * @note This is internal function for AITT.
  */
-int nns_edge_aitt_publish (nns_edge_h edge_h, const void *data, const int length);
+int nns_edge_aitt_subscribe (nns_edge_aitt_h handle);
 
 /**
- * @brief Subscribe a topic.
- * @note This is internal function for AITT. You should call this with edge-handle lock.
+ * @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_subscribe (nns_edge_h edge_h);
+int nns_edge_aitt_send_data (nns_edge_aitt_h handle, nns_edge_data_h data_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_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)
 #endif /* ENABLE_AITT */
 
 #ifdef __cplusplus
index 0f4552aca8e5322cfb595d0768d795c1b6575d0e..c7b2536f130c75a573bdf377cab43ad167ce435d 100644 (file)
@@ -329,37 +329,6 @@ _nns_edge_cmd_send (nns_edge_conn_s * conn, nns_edge_cmd_s * cmd)
   return NNS_EDGE_ERROR_NONE;
 }
 
-/**
- * @brief Send edge command to connected device using AITT.
- */
-static int
-_nns_edge_cmd_send_aitt (nns_edge_handle_s * eh, nns_edge_data_h data_h)
-{
-  int ret;
-  void *data = NULL;
-  nns_size_t size;
-
-  if (!eh) {
-    nns_edge_loge ("Failed to send command, edge handle is null.");
-    return NNS_EDGE_ERROR_INVALID_PARAMETER;
-  }
-
-  ret = nns_edge_data_serialize (data_h, &data, &size);
-  if (NNS_EDGE_ERROR_NONE != ret) {
-    nns_edge_loge ("Failed to serialize the edge data.");
-    goto done;
-  }
-
-  ret = nns_edge_aitt_publish (eh, data, size);
-  if (NNS_EDGE_ERROR_NONE != ret) {
-    nns_edge_loge ("Failed to send data to destination.");
-  }
-
-done:
-  nns_edge_free (data);
-  return ret;
-}
-
 /**
  * @brief Receive edge command from connected device.
  * @note Before calling this function, you should initialize edge-cmd by using _nns_edge_cmd_init().
@@ -839,7 +808,9 @@ _nns_edge_send_thread (void *thread_data)
         }
         break;
       case NNS_EDGE_CONNECT_TYPE_AITT:
-        _nns_edge_cmd_send_aitt (eh, data_h);
+        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;
       default:
         break;
@@ -1290,11 +1261,19 @@ 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);
+      ret = nns_edge_aitt_connect (eh->id, eh->topic, eh->dest_host,
+          eh->dest_port, &eh->broker_h);
       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;
+      }
     }
   }
 
@@ -1342,10 +1321,9 @@ nns_edge_release_handle (nns_edge_h edge_h)
       if (NNS_EDGE_ERROR_NONE != nns_edge_mqtt_close (eh->broker_h)) {
         nns_edge_logw ("Failed to close mqtt connection.");
       }
-      eh->broker_h = NULL;
       break;
     case NNS_EDGE_CONNECT_TYPE_AITT:
-      if (NNS_EDGE_ERROR_NONE != nns_edge_aitt_close (eh)) {
+      if (NNS_EDGE_ERROR_NONE != nns_edge_aitt_close (eh->broker_h)) {
         nns_edge_logw ("Failed to close AITT connection.");
       }
       break;
@@ -1353,9 +1331,11 @@ nns_edge_release_handle (nns_edge_h edge_h)
       break;
   }
 
+  /* Clear event callback and handles */
   eh->magic = NNS_EDGE_MAGIC_DEAD;
   eh->event_cb = NULL;
   eh->user_data = NULL;
+  eh->broker_h = NULL;
 
   nns_edge_queue_destroy (eh->send_queue);
   eh->send_queue = NULL;
@@ -1521,17 +1501,24 @@ nns_edge_connect (nns_edge_h edge_h, const char *dest_host, int dest_port)
       }
     } while (TRUE);
   } else if (NNS_EDGE_CONNECT_TYPE_AITT == eh->connect_type) {
-    ret = nns_edge_aitt_connect (eh);
+    ret = nns_edge_aitt_connect (eh->id, eh->topic, dest_host, dest_port,
+        &eh->broker_h);
     if (ret != NNS_EDGE_ERROR_NONE) {
-      nns_edge_loge ("Failed to connect to aitt broker. %s:%d", dest_host,
+      nns_edge_loge ("Failed to connect to AITT broker. %s:%d", dest_host,
           dest_port);
       goto done;
     }
-    ret = nns_edge_aitt_subscribe (eh);
+
+    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);
-      SAFE_FREE (eh->broker_h);
-      eh->broker_h = NULL;
       goto done;
     }
   } else {
@@ -1585,7 +1572,7 @@ _nns_edge_is_connected (nns_edge_h edge_h)
   nns_edge_conn_s *conn;
 
   if (NNS_EDGE_CONNECT_TYPE_AITT == eh->connect_type &&
-      NNS_EDGE_ERROR_NONE == nns_edge_aitt_is_connected (eh))
+      NNS_EDGE_ERROR_NONE == nns_edge_aitt_is_connected (eh->broker_h))
     return true;
 
   conn_data = (nns_edge_conn_data_s *) eh->connections;
index dcaf16cbf23e87e0d198b3b956abb33d9bd17050..bbc0a177d8577b7cc7846510c3f1f5f11099325a 100644 (file)
@@ -257,11 +257,15 @@ TEST(edgeAitt, connectLocal)
 TEST(edgeAitt, connectInvalidParam1_n)
 {
   int ret = -1;
+  nns_edge_aitt_h handle;
 
   if (!_check_mqtt_broker ())
     return;
 
-  ret = nns_edge_aitt_connect (NULL);
+  ret = nns_edge_aitt_connect (NULL, "temp-aitt-topic", "127.0.0.1", 1883, &handle);
+  EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
+
+  ret = nns_edge_aitt_connect ("", "temp-aitt-topic", "127.0.0.1", 1883, &handle);
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
 }
 
@@ -271,23 +275,16 @@ TEST(edgeAitt, connectInvalidParam1_n)
 TEST(edgeAitt, connectInvalidParam2_n)
 {
   int ret = -1;
-  nns_edge_h edge_h;
+  nns_edge_aitt_h handle;
 
   if (!_check_mqtt_broker ())
     return;
 
-  ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
-      NNS_EDGE_NODE_TYPE_PUB, &edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-  nns_edge_set_info (edge_h, "DEST_IP", "f.a.i.l");
-  nns_edge_set_info (edge_h, "DEST_PORT", "1883");
-  nns_edge_set_info (edge_h, "TOPIC", "AITT_TEST_TOPIC");
-
-  ret = nns_edge_aitt_connect (edge_h);
+  ret = nns_edge_aitt_connect ("temp-aitt-id", NULL, "127.0.0.1", 1883, &handle);
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
 
-  ret = nns_edge_release_handle (edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
+  ret = nns_edge_aitt_connect ("temp-aitt-id", "", "127.0.0.1", 1883, &handle);
+  EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
 }
 
 /**
@@ -296,159 +293,119 @@ TEST(edgeAitt, connectInvalidParam2_n)
 TEST(edgeAitt, connectInvalidParam3_n)
 {
   int ret = -1;
-  nns_edge_h edge_h;
+  nns_edge_aitt_h handle;
 
   if (!_check_mqtt_broker ())
     return;
 
-  ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
-      NNS_EDGE_NODE_TYPE_PUB, &edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-  nns_edge_set_info (edge_h, "DEST_IP", "127.0.0.1");
-  nns_edge_set_info (edge_h, "DEST_PORT", "0");
-  nns_edge_set_info (edge_h, "TOPIC", "AITT_TEST_TOPIC");
-
-  /** TOPIC is not set */
-  ret = nns_edge_aitt_connect (edge_h);
+  ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", NULL, 1883, &handle);
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
 
-  ret = nns_edge_release_handle (edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
+  ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", "", 1883, &handle);
+  EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
 }
 
 /**
- * @brief Close the mqtt handle with invalid param.
+ * @brief Connect to the mqtt broker with invalid param.
  */
-TEST(edgeAitt, closeInvalidParam_n)
+TEST(edgeAitt, connectInvalidParam4_n)
 {
   int ret = -1;
+  nns_edge_aitt_h handle;
 
   if (!_check_mqtt_broker ())
     return;
 
-  ret = nns_edge_aitt_close (NULL);
+  ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 0, &handle);
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
 }
 
 /**
- * @brief Close the mqtt handle before the connection.
+ * @brief Connect to the mqtt broker with invalid param.
  */
-TEST(edgeAitt, closeInvalidParam2_n)
+TEST(edgeAitt, connectInvalidParam5_n)
 {
   int ret = -1;
-  nns_edge_h edge_h;
 
   if (!_check_mqtt_broker ())
     return;
 
-  ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
-      NNS_EDGE_NODE_TYPE_PUB, &edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-
-  ret = nns_edge_aitt_close (edge_h);
+  ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 1883, NULL);
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
-
-  ret = nns_edge_release_handle (edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
 }
 
 /**
- * @brief Publish with invalid param.
+ * @brief Close the mqtt handle with invalid param.
  */
-TEST(edgeAitt, publishInvalidParam_n)
+TEST(edgeAitt, closeInvalidParam_n)
 {
   int ret = -1;
-  const char *msg = "TEMP_MESSAGE";
 
   if (!_check_mqtt_broker ())
     return;
 
-  ret = nns_edge_aitt_publish (NULL, msg, strlen (msg) + 1);
+  ret = nns_edge_aitt_close (NULL);
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
 }
 
 /**
  * @brief Publish with invalid param.
  */
-TEST(edgeAitt, publishInvalidParam2_n)
+TEST(edgeAitt, publishInvalidParam_n)
 {
   int ret = -1;
-  nns_edge_h edge_h;
   const char *msg = "TEMP_MESSAGE";
 
   if (!_check_mqtt_broker ())
     return;
 
-  ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
-      NNS_EDGE_NODE_TYPE_PUB, &edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-  nns_edge_set_info (edge_h, "DEST_HOST", "127.0.0.1");
-  nns_edge_set_info (edge_h, "DEST_PORT", "1883");
-  nns_edge_set_info (edge_h, "TOPIC", "AITT_TEST_TOPIC");
-
-  ret = nns_edge_start (edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-
-  /* data is null */
-  ret = nns_edge_aitt_publish (edge_h, NULL, strlen (msg) + 1);
+  ret = nns_edge_aitt_publish (NULL, msg, strlen (msg) + 1);
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
-
-  ret = nns_edge_release_handle (edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
 }
 
 /**
  * @brief Publish with invalid param.
  */
-TEST(edgeAitt, publishInvalidParam3_n)
+TEST(edgeAitt, publishInvalidParam2_n)
 {
   int ret = -1;
-  nns_edge_h edge_h;
+  nns_edge_aitt_h handle;
   const char *msg = "TEMP_MESSAGE";
 
   if (!_check_mqtt_broker ())
     return;
 
-  ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
-      NNS_EDGE_NODE_TYPE_PUB, &edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-  nns_edge_set_info (edge_h, "DEST_HOST", "127.0.0.1");
-  nns_edge_set_info (edge_h, "DEST_PORT", "1883");
-  nns_edge_set_info (edge_h, "TOPIC", "AITT_TEST_TOPIC");
-
-  ret = nns_edge_start (edge_h);
+  ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 1883, &handle);
   EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
 
-  /* data length is 0 */
-  ret = nns_edge_aitt_publish (edge_h, msg, 0);
+  /* data is null */
+  ret = nns_edge_aitt_publish (handle, NULL, strlen (msg) + 1);
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
 
-  ret = nns_edge_release_handle (edge_h);
+  ret = nns_edge_aitt_close (handle);
   EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
 }
 
 /**
- * @brief Publish the message without the connection.
+ * @brief Publish with invalid param.
  */
-TEST(edgeAitt, publishInvalidParam4_n)
+TEST(edgeAitt, publishInvalidParam3_n)
 {
   int ret = -1;
-  nns_edge_h edge_h;
+  nns_edge_aitt_h handle;
   const char *msg = "TEMP_MESSAGE";
 
   if (!_check_mqtt_broker ())
     return;
 
-  ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
-      NNS_EDGE_NODE_TYPE_PUB, &edge_h);
+  ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 1883, &handle);
   EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-  nns_edge_set_info (edge_h, "DEST_HOST", "127.0.0.1");
-  nns_edge_set_info (edge_h, "DEST_PORT", "1883");
 
-  ret = nns_edge_aitt_publish (edge_h, msg, strlen (msg) + 1);
+  /* data length is 0 */
+  ret = nns_edge_aitt_publish (handle, msg, 0);
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
 
-  ret = nns_edge_release_handle (edge_h);
+  ret = nns_edge_aitt_close (handle);
   EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
 }
 
@@ -467,32 +424,17 @@ TEST(edgeAitt, subscribeInvalidParam_n)
 }
 
 /**
- * @brief Subscribe the topic before the connection.
+ * @brief Check connection with invalid param.
  */
-TEST(edgeAitt, subscribeInvalidParam2_n)
+TEST(edgeAitt, checkConnectionInvalidParam_n)
 {
   int ret = -1;
-  nns_edge_h edge_h;
 
   if (!_check_mqtt_broker ())
     return;
 
-  ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
-      NNS_EDGE_NODE_TYPE_SUB, &edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-
-  nns_edge_set_info (edge_h, "DEST_HOST", "127.0.0.1");
-  nns_edge_set_info (edge_h, "DEST_PORT", "1883");
-  nns_edge_set_info (edge_h, "TOPIC", "AITT_TEST_TOPIC");
-
-  ret = nns_edge_start (edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-
-  ret = nns_edge_aitt_subscribe (edge_h);
+  ret = nns_edge_aitt_is_connected (NULL);
   EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
-
-  ret = nns_edge_release_handle (edge_h);
-  EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
 }
 
 /**