Add stop discovery function accepted/tizen/unified/20250313.054818 accepted/tizen/unified/x/20250311.211311
authorGichan Jang <gichan2.jang@samsung.com>
Thu, 23 Jan 2025 01:03:07 +0000 (10:03 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 23 Jan 2025 04:45:29 +0000 (13:45 +0900)
 - Add stop discovery function
 - Rename discover to start_discovery

Signed-off-by: Gichan Jang <gichan2.jang@samsung.com>
include/nnstreamer-edge-custom.h
include/nnstreamer-edge.h
src/libnnstreamer-edge/nnstreamer-edge-custom-impl.c
src/libnnstreamer-edge/nnstreamer-edge-custom-impl.h
src/libnnstreamer-edge/nnstreamer-edge-internal.c
tests/nnstreamer-edge-custom-test.c
tests/unittest_nnstreamer-edge-custom.cc

index de339289238da9a17c48896ef71c76d2542b60f3..95b55948f2e10b477d3f2a83f360047e6c9b6da1 100644 (file)
@@ -34,7 +34,8 @@ typedef struct
   int (*nns_edge_custom_connect) (void *priv);
   int (*nns_edge_custom_subscribe) (void *priv);
   int (*nns_edge_custom_is_connected) (void *priv);
-  int (*nns_edge_custom_discover) (void *priv);
+  int (*nns_edge_custom_start_discovery) (void *priv);
+  int (*nns_edge_custom_stop_discovery) (void *priv);
   int (*nns_edge_custom_set_event_cb) (void *priv, nns_edge_event_cb cb, void *user_data);
   int (*nns_edge_custom_send_data) (void *priv, nns_edge_data_h data_h);
   int (*nns_edge_custom_set_info) (void *priv, const char *key, const char *value);
index e47109e6b47853174e37278c8d99f6b882817b34..a5d82d16a41b8de36fb22cfa40d962dc6252c226 100644 (file)
@@ -214,14 +214,24 @@ 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 Discover connectable devices within the network.
+ * @brief Start discovery connectable devices within the network.
  * @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_NOT_SUPPORTED Not supported.
  * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid.
  */
-int nns_edge_discover (nns_edge_h edge_h);
+int nns_edge_start_discovery (nns_edge_h edge_h);
+
+/**
+ * @brief Stop discovery connectable devices within the network.
+ * @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_NOT_SUPPORTED Not supported.
+ * @retval #NNS_EDGE_ERROR_INVALID_PARAMETER Given parameter is invalid.
+ */
+int nns_edge_stop_discovery (nns_edge_h edge_h);
 
 /**
  * @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().
index 93c5bc46bc3c0a259e07b40d7a68417280c3ed0f..3d4dee1a586ae5888a055f08a92cb4db85814dfa 100644 (file)
@@ -221,10 +221,10 @@ nns_edge_custom_set_event_callback (nns_edge_custom_connection_h handle,
 }
 
 /**
- * @brief Internal function to discover devices of custom connection.
+ * @brief Internal function to start discovery devices of custom connection.
  */
 int
-nns_edge_custom_discover (nns_edge_custom_connection_h handle)
+nns_edge_custom_start_discovery (nns_edge_custom_connection_h handle)
 {
   custom_connection_s *custom = (custom_connection_s *) handle;
   nns_edge_custom_s *custom_h;
@@ -235,9 +235,32 @@ nns_edge_custom_discover (nns_edge_custom_connection_h handle)
 
   custom_h = custom->instance;
 
-  ret = custom_h->nns_edge_custom_discover (custom->priv);
+  ret = custom_h->nns_edge_custom_start_discovery (custom->priv);
   if (NNS_EDGE_ERROR_NONE != ret) {
-    nns_edge_loge ("Failed to discover devices of custom connection.");
+    nns_edge_loge ("Failed to start discovery devices of custom connection.");
+  }
+
+  return ret;
+}
+
+/**
+ * @brief Internal function to stop discovery devices of custom connection.
+ */
+int
+nns_edge_custom_stop_discovery (nns_edge_custom_connection_h handle)
+{
+  custom_connection_s *custom = (custom_connection_s *) handle;
+  nns_edge_custom_s *custom_h;
+  int ret;
+
+  if (!custom || !custom->instance)
+    return NNS_EDGE_ERROR_INVALID_PARAMETER;
+
+  custom_h = custom->instance;
+
+  ret = custom_h->nns_edge_custom_stop_discovery (custom->priv);
+  if (NNS_EDGE_ERROR_NONE != ret) {
+    nns_edge_loge ("Failed to stop discovery devices of custom connection.");
   }
 
   return ret;
index 2fbe1f016d46f414ec4b4d7462cc6f261bb383e8..2a98992d8ade8511c3af411e6c49028e0a5c38ea 100644 (file)
@@ -43,9 +43,14 @@ int nns_edge_custom_start (nns_edge_custom_connection_h handle);
 int nns_edge_custom_stop (nns_edge_custom_connection_h handle);
 
 /**
- * @brief Internal function to discover devices of custom connection.
+ * @brief Internal function to start discovery devices of custom connection.
  */
-int nns_edge_custom_discover (nns_edge_custom_connection_h handle);
+int nns_edge_custom_start_discovery (nns_edge_custom_connection_h handle);
+
+/**
+ * @brief Internal function to stop discovery devices of custom connection.
+ */
+int nns_edge_custom_stop_discovery (nns_edge_custom_connection_h handle);
 
 /**
  * @brief Internal function to set the event callback of custom connection.
@@ -81,7 +86,8 @@ int nns_edge_custom_get_info (nns_edge_custom_connection_h handle, const char *k
 #define nns_edge_custom_release(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
 #define nns_edge_custom_start(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
 #define nns_edge_custom_stop(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
-#define nns_edge_custom_discover(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
+#define nns_edge_custom_start_discovery(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
+#define nns_edge_custom_stop_discovery(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
 #define nns_edge_custom_set_event_callback(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
 #define nns_edge_custom_connect(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
 #define nns_edge_custom_is_connected(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
index a6a74bf64925c995266c6d9573b77bd39f71f565..762815daedb0d1c5c7b6fee3417dd07e9d4812ff 100644 (file)
@@ -2145,9 +2145,9 @@ nns_edge_get_info (nns_edge_h edge_h, const char *key, char **value)
 }
 
 /**
- * @brief Discover connectable devices within the network.
+ * @brief Start discovery connectable devices within the network.
  */
-int nns_edge_discover (nns_edge_h edge_h)
+int nns_edge_start_discovery (nns_edge_h edge_h)
 {
   nns_edge_handle_s *eh;
   int ret = NNS_EDGE_ERROR_NONE;
@@ -2171,7 +2171,37 @@ int nns_edge_discover (nns_edge_h edge_h)
   }
 
   if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
-    ret = nns_edge_custom_discover (eh->custom_connection_h);
+    ret = nns_edge_custom_start_discovery (eh->custom_connection_h);
+  }
+
+  nns_edge_unlock (eh);
+
+  return ret;
+}
+
+/**
+ * @brief Stop discovery connectable devices within the network.
+ */
+int nns_edge_stop_discovery (nns_edge_h edge_h)
+{
+  nns_edge_handle_s *eh;
+  int ret = NNS_EDGE_ERROR_NONE;
+
+  eh = (nns_edge_handle_s *) edge_h;
+  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;
+  }
+
+  nns_edge_lock (eh);
+
+  if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
+    ret = nns_edge_custom_stop_discovery (eh->custom_connection_h);
   }
 
   nns_edge_unlock (eh);
index 7c00b03f7fff93d6a8c4aa31a17ffbd30f181b35..b627d9a2d6e7fa5537cecb6261161dff78dbabf0 100644 (file)
@@ -110,7 +110,7 @@ nns_edge_custom_subscribe (void *priv)
 
 
 static int
-nns_edge_custom_discover (void *priv)
+nns_edge_custom_start_discovery (void *priv)
 {
   int ret = NNS_EDGE_ERROR_NONE;
 
@@ -125,6 +125,17 @@ nns_edge_custom_discover (void *priv)
   return ret;
 }
 
+static int
+nns_edge_custom_stop_discovery (void *priv)
+{
+  if (!priv) {
+    nns_edge_loge ("Invalid param, handle should not be null.");
+    return NNS_EDGE_ERROR_INVALID_PARAMETER;
+  }
+
+  return NNS_EDGE_ERROR_NONE;
+}
+
 static int
 nns_edge_custom_is_connected (void *priv)
 {
@@ -208,7 +219,8 @@ nns_edge_custom_s edge_custom_h = {
   .nns_edge_custom_create = nns_edge_custom_create,
   .nns_edge_custom_close = nns_edge_custom_close,
   .nns_edge_custom_start = nns_edge_custom_start,
-  .nns_edge_custom_discover = nns_edge_custom_discover,
+  .nns_edge_custom_start_discovery = nns_edge_custom_start_discovery,
+  .nns_edge_custom_stop_discovery = nns_edge_custom_stop_discovery,
   .nns_edge_custom_stop = nns_edge_custom_stop,
   .nns_edge_custom_connect = nns_edge_custom_connect,
   .nns_edge_custom_subscribe = nns_edge_custom_subscribe,
index 0b565b589842a4300745850488ef8fd0f7010b7f..0f0c55ae516bb0844445dbb7d3c59c4e604a0d1b 100644 (file)
@@ -119,10 +119,13 @@ TEST (edgeCustom, expectedReturn)
   ret = nns_edge_start (edge_h);
   EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
 
-  ret = nns_edge_discover (edge_h);
+  ret = nns_edge_start_discovery (edge_h);
   EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
   EXPECT_EQ (1, device_found);
 
+  ret = nns_edge_stop_discovery (edge_h);
+  EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+
   ret = nns_edge_is_connected (edge_h);
   EXPECT_EQ (NNS_EDGE_ERROR_CONNECTION_FAILURE, ret);
 
@@ -218,11 +221,22 @@ TEST (edgeCustom, stopInvalidParam01_n)
 /**
  * @brief Set event callback of edge custom - invalid param.
  */
-TEST (edgeCustom, discoverInvalidParam01_n)
+TEST (edgeCustom, startDiscoveryInvalidParam01_n)
+{
+  int ret;
+
+  ret = nns_edge_custom_start_discovery (NULL);
+  EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
+/**
+ * @brief Set event callback of edge custom - invalid param.
+ */
+TEST (edgeCustom, stopDiscoveryInvalidParam01_n)
 {
   int ret;
 
-  ret = nns_edge_custom_discover (NULL);
+  ret = nns_edge_custom_stop_discovery (NULL);
   EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
 }