[Custom] Add disconnect function for custom connection accepted/tizen_unified accepted/tizen_unified_x accepted/tizen/unified/20250326.013035 accepted/tizen/unified/x/20250325.213602
authorGichan Jang <gichan2.jang@samsung.com>
Tue, 18 Feb 2025 08:53:34 +0000 (17:53 +0900)
committerSangjung Woo <again4you@gmail.com>
Thu, 20 Mar 2025 06:18:34 +0000 (15:18 +0900)
 - Add disconnection function for custom connection
 - Add unit test

Signed-off-by: Gichan Jang <gichan2.jang@samsung.com>
include/nnstreamer-edge-custom.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 95b55948f2e10b477d3f2a83f360047e6c9b6da1..0b5f8b452d96f7e5bebe26f205a4546d4d5e9783 100644 (file)
@@ -32,6 +32,7 @@ typedef struct
   int (*nns_edge_custom_start) (void *priv);
   int (*nns_edge_custom_stop) (void *priv);
   int (*nns_edge_custom_connect) (void *priv);
+  int (*nns_edge_custom_disconnect) (void *priv);
   int (*nns_edge_custom_subscribe) (void *priv);
   int (*nns_edge_custom_is_connected) (void *priv);
   int (*nns_edge_custom_start_discovery) (void *priv);
index 3d4dee1a586ae5888a055f08a92cb4db85814dfa..118334564c44b6ce07e8721ccb54683859848e8a 100644 (file)
@@ -289,6 +289,29 @@ nns_edge_custom_connect (nns_edge_custom_connection_h handle)
   return ret;
 }
 
+/**
+ * @brief Internal function to disconnect custom connection.
+ */
+int
+nns_edge_custom_disconnect (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_disconnect (custom->priv);
+  if (NNS_EDGE_ERROR_NONE != ret) {
+    nns_edge_loge ("Failed to disconnect custom connection.");
+  }
+
+  return ret;
+}
+
 /**
  * @brief Internal function to check custom connection.
  */
index 2a98992d8ade8511c3af411e6c49028e0a5c38ea..e5f4ca9305eb918d99410e01a190119c254375a6 100644 (file)
@@ -62,6 +62,11 @@ int nns_edge_custom_set_event_callback (nns_edge_custom_connection_h handle, nns
  */
 int nns_edge_custom_connect (nns_edge_custom_connection_h handle);
 
+/**
+ * @brief Internal function to disconnect custom connection.
+ */
+int nns_edge_custom_disconnect (nns_edge_custom_connection_h handle);
+
 /**
  * @brief Internal function to check custom connection.
  */
@@ -90,6 +95,7 @@ int nns_edge_custom_get_info (nns_edge_custom_connection_h handle, const char *k
 #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_disconnect(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
 #define nns_edge_custom_is_connected(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
 #define nns_edge_custom_send_data(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
 #define nns_edge_custom_set_info(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
index 762815daedb0d1c5c7b6fee3417dd07e9d4812ff..097fbaaf6b3088e708d3cd24d16ffa51e31ff570 100644 (file)
@@ -1836,6 +1836,7 @@ int
 nns_edge_disconnect (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) {
@@ -1849,10 +1850,14 @@ nns_edge_disconnect (nns_edge_h edge_h)
   }
 
   nns_edge_lock (eh);
-  _nns_edge_remove_all_connection (eh);
+  if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
+    ret = nns_edge_custom_disconnect (eh->custom_connection_h);
+  } else {
+    _nns_edge_remove_all_connection (eh);
+  }
   nns_edge_unlock (eh);
 
-  return NNS_EDGE_ERROR_NONE;
+  return ret;
 }
 
 /**
index b627d9a2d6e7fa5537cecb6261161dff78dbabf0..c16ac2f20fc2e847f2069783e68a30e445d628e4 100644 (file)
@@ -102,6 +102,20 @@ nns_edge_custom_connect (void *priv)
   return NNS_EDGE_ERROR_NONE;
 }
 
+static int
+nns_edge_custom_disconnect (void *priv)
+{
+  if (!priv) {
+    nns_edge_loge ("Invalid param, handle should not be null.");
+    return NNS_EDGE_ERROR_INVALID_PARAMETER;
+  }
+  nns_edge_custom_test_s *custom_h = (nns_edge_custom_test_s *) priv;
+  custom_h->is_connected = 0;
+
+  return NNS_EDGE_ERROR_NONE;
+}
+
+
 static int
 nns_edge_custom_subscribe (void *priv)
 {
@@ -223,6 +237,7 @@ nns_edge_custom_s edge_custom_h = {
   .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_disconnect = nns_edge_custom_disconnect,
   .nns_edge_custom_subscribe = nns_edge_custom_subscribe,
   .nns_edge_custom_is_connected = nns_edge_custom_is_connected,
   .nns_edge_custom_set_event_cb = nns_edge_custom_set_event_cb,
index 0f0c55ae516bb0844445dbb7d3c59c4e604a0d1b..17030d5915669281872265a207b12f833747ce3a 100644 (file)
@@ -134,6 +134,14 @@ TEST (edgeCustom, expectedReturn)
   ret = nns_edge_is_connected (edge_h);
   EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
 
+  ret = nns_edge_disconnect (edge_h);
+  EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+  ret = nns_edge_is_connected (edge_h);
+  EXPECT_EQ (NNS_EDGE_ERROR_CONNECTION_FAILURE, ret);
+
+  ret = nns_edge_connect (edge_h, "temp", 3000);
+  EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+
   ret = nns_edge_data_create (&data_h);
   EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
   ret = nns_edge_send (edge_h, data_h);
@@ -262,6 +270,17 @@ TEST (edgeCustom, connectInvalidParam01_n)
   EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
 }
 
+/**
+ * @brief Disconnect edge custom - invalid param.
+ */
+TEST (edgeCustom, disconnectInvalidParam01_n)
+{
+  int ret;
+
+  ret = nns_edge_custom_disconnect (NULL);
+  EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
 /**
  * @brief Check connection of edge custom - invalid param.
  */