Implement custom discovery function and add related unit tests.
Signed-off-by: Gichan Jang <gichan2.jang@samsung.com>
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_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 Discovery connectable devices within the network.
+ * @brief Discover connectable devices within the network.
* @param[in] edge_h The edge handle.
- * @param[in] user_data The user's custom data passed to discovery callback.
* @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_discovery (nns_edge_h edge_h, void *user_data);
+int nns_edge_discover (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().
return ret;
}
+/**
+ * @brief Internal function to discover devices of custom connection.
+ */
+int
+nns_edge_custom_discover (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_discover (custom->priv);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to discover devices of custom connection.");
+ }
+
+ return ret;
+}
+
/**
* @brief Internal function to connect custom connection.
*/
*/
int nns_edge_custom_stop (nns_edge_custom_connection_h handle);
+/**
+ * @brief Internal function to discover devices of custom connection.
+ */
+int nns_edge_custom_discover (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_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)
return ret;
}
+
+/**
+ * @brief Discover connectable devices within the network.
+ */
+int nns_edge_discover (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 (!eh->event_cb) {
+ nns_edge_loge ("NNStreamer-edge event callback is not registered.");
+ nns_edge_unlock (eh);
+ return NNS_EDGE_ERROR_CONNECTION_FAILURE;
+ }
+
+ if (NNS_EDGE_CONNECT_TYPE_CUSTOM == eh->connect_type) {
+ ret = nns_edge_custom_discover (eh->custom_connection_h);
+ }
+
+ nns_edge_unlock (eh);
+
+ return ret;
+}
+
return NNS_EDGE_ERROR_NOT_SUPPORTED;
}
+
+static int
+nns_edge_custom_discover (void *priv)
+{
+ int ret = NNS_EDGE_ERROR_NONE;
+
+ 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;
+ ret = nns_edge_event_invoke_callback (custom_h->event_cb, custom_h->user_data,
+ NNS_EDGE_EVENT_DEVICE_FOUND, NULL, 0, NULL);
+
+ return ret;
+}
+
static int
nns_edge_custom_is_connected (void *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->event_cb = cb;
+ custom_h->user_data = user_data;
return NNS_EDGE_ERROR_NONE;
}
.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_stop = nns_edge_custom_stop,
.nns_edge_custom_connect = nns_edge_custom_connect,
.nns_edge_custom_subscribe = nns_edge_custom_subscribe,
static int
_test_edge_event_cb (nns_edge_event_h event_h, void *user_data)
{
+ nns_edge_event_e event = NNS_EDGE_EVENT_UNKNOWN;
+ int ret;
+ int *device_found = (int *) user_data;
+
+ ret = nns_edge_event_get_type (event_h, &event);
+ EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
+
+ switch (event) {
+ case NNS_EDGE_EVENT_DEVICE_FOUND:
+ (*device_found)++;
+ break;
+ default:
+ break;
+ }
+
return NNS_EDGE_ERROR_NONE;
}
nns_edge_h edge_h = NULL;
nns_edge_data_h data_h = NULL;
char *ret_str = NULL;
+ int device_found = 0;
ret = nns_edge_custom_create_handle ("temp_id", "libnnstreamer-edge-custom-test.so",
NNS_EDGE_NODE_TYPE_QUERY_SERVER, &edge_h);
ASSERT_EQ (NNS_EDGE_ERROR_NONE, ret);
- ret = nns_edge_set_event_callback (edge_h, _test_edge_event_cb, NULL);
+ ret = nns_edge_set_event_callback (edge_h, _test_edge_event_cb, &device_found);
EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
ret = nns_edge_set_info (edge_h, "PEER_ADDRESS", "TE:MP:AD:DR:ES:SS");
EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
ret = nns_edge_start (edge_h);
EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+ ret = nns_edge_discover (edge_h);
+ EXPECT_EQ (NNS_EDGE_ERROR_NONE, ret);
+ EXPECT_EQ (1, device_found);
+
ret = nns_edge_is_connected (edge_h);
EXPECT_EQ (NNS_EDGE_ERROR_CONNECTION_FAILURE, ret);
EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
}
+/**
+ * @brief Set event callback of edge custom - invalid param.
+ */
+TEST (edgeCustom, discoverInvalidParam01_n)
+{
+ int ret;
+
+ ret = nns_edge_custom_discover (NULL);
+ EXPECT_NE (NNS_EDGE_ERROR_NONE, ret);
+}
+
/**
* @brief Set event callback of edge custom - invalid param.
*/