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);
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().
}
/**
- * @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;
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;
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.
#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)
}
/**
- * @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;
}
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);
static int
-nns_edge_custom_discover (void *priv)
+nns_edge_custom_start_discovery (void *priv)
{
int ret = NNS_EDGE_ERROR_NONE;
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)
{
.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,
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);
/**
* @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);
}