Add connection check API
authorgichan2-jang <gichan2.jang@samsung.com>
Fri, 14 Jul 2023 00:47:58 +0000 (09:47 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Mon, 17 Jul 2023 02:28:05 +0000 (11:28 +0900)
Adds API that checks the connection of given edge handle.

Signed-off-by: gichan2-jang <gichan2.jang@samsung.com>
include/nnstreamer-edge.h
src/libnnstreamer-edge/nnstreamer-edge-internal.c

index 56f484e636342776c94e077361b1f6b5852852bb..fc03f11d3d40d7519e0dbc411f98c337ecc77aea 100644 (file)
@@ -285,6 +285,17 @@ int nns_edge_disconnect (nns_edge_h edge_h);
  */
 int nns_edge_send (nns_edge_h edge_h, nns_edge_data_h data_h);
 
+/**
+ * @brief Check whether edge is connected or not.
+ * @param[in] edge_h The edge handle.
+ * @return 0 on success. Otherwise a negative error value.
+ * @retval #NNS_EDGE_ERROR_NONE Successful.
+ * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid.
+ * @retval #NNS_EDGE_ERROR_IO No available connection.
+ */
+int
+nns_edge_is_connected (nns_edge_h edge_h);
+
 /**
  * @brief Set nnstreamer edge info.
  * @note The param key is case-insensitive. If same key string already exists, it will replace the old value.
index 3857249e5c7bf6aca224825e113f8e058fdc922c..91f027440252fcf3f6278aaf435dc02d9348c61e 100644 (file)
@@ -1667,31 +1667,41 @@ nns_edge_disconnect (nns_edge_h edge_h)
 /**
  * @brief Check whether edge is connected or not.
  */
-static bool
-_nns_edge_is_connected (nns_edge_h edge_h)
+int
+nns_edge_is_connected (nns_edge_h edge_h)
 {
   nns_edge_handle_s *eh = (nns_edge_handle_s *) edge_h;
   nns_edge_conn_data_s *conn_data;
   nns_edge_conn_s *conn;
 
+  if (!eh) {
+    nns_edge_loge ("Invalid param, given edge handle is null.");
+    return NNS_EDGE_ERROR_INVALID_PARAMETER;
+  }
+
+  if (!nns_edge_handle_is_valid (eh)) {
+    nns_edge_loge ("Invalid param, given edge handle is invalid.");
+    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 true;
+    return NNS_EDGE_ERROR_NONE;
 
   if (NNS_EDGE_CONNECT_TYPE_MQTT == eh->connect_type &&
       nns_edge_mqtt_is_connected (eh->broker_h))
-    return true;
+    return NNS_EDGE_ERROR_NONE;
 
   conn_data = (nns_edge_conn_data_s *) eh->connections;
   while (conn_data) {
     conn = conn_data->sink_conn;
     if (_nns_edge_check_connection (conn)) {
-      return true;
+      return NNS_EDGE_ERROR_NONE;
     }
     conn_data = conn_data->next;
   }
 
-  return false;
+  return NNS_EDGE_ERROR_CONNECTION_FAILURE;
 }
 
 /**
@@ -1721,7 +1731,7 @@ nns_edge_send (nns_edge_h edge_h, nns_edge_data_h data_h)
 
   nns_edge_lock (eh);
 
-  if (!_nns_edge_is_connected (eh)) {
+  if (NNS_EDGE_ERROR_NONE != nns_edge_is_connected (eh)) {
     nns_edge_loge ("There is no available connection.");
     nns_edge_unlock (eh);
     return NNS_EDGE_ERROR_IO;