From: Jaeyun Date: Thu, 28 Jul 2022 10:53:23 +0000 (+0900) Subject: [Interface] update edge interface X-Git-Tag: submit/tizen/20220810.074948~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04ba13cb64164dbda7de0c7561dfee0c8aed4d17;p=platform%2Fupstream%2Fnnstreamer-edge.git [Interface] update edge interface Update edge interfaces. - request/respond functions are unnecessary as it can send a data by using publish. - subscribe does not require data handle. - define connect-type and flags for future work. Signed-off-by: Jaeyun --- diff --git a/include/nnstreamer-edge.h b/include/nnstreamer-edge.h index bb018ff..51fe0b7 100644 --- a/include/nnstreamer-edge.h +++ b/include/nnstreamer-edge.h @@ -65,14 +65,22 @@ typedef enum { } nns_edge_event_e; typedef enum { - NNS_EDGE_PROTOCOL_TCP = 0, - NNS_EDGE_PROTOCOL_UDP, - NNS_EDGE_PROTOCOL_MQTT, - NNS_EDGE_PROTOCOL_AITT, - NNS_EDGE_PROTOCOL_AITT_TCP, + NNS_EDGE_CONNECT_TYPE_TCP = 0, + NNS_EDGE_CONNECT_TYPE_UDP, + NNS_EDGE_CONNECT_TYPE_MQTT, + NNS_EDGE_CONNECT_TYPE_HYBRID, - NNS_EDGE_PROTOCOL_MAX -} nns_edge_protocol_e; + NNS_EDGE_CONNECT_TYPE_UNKNOWN +} nns_edge_connect_type_e; + +typedef enum { + NNS_EDGE_FLAG_NONE = 0, + NNS_EDGE_FLAG_RECV = (1 << 0), + NNS_EDGE_FLAG_SEND = (1 << 1), + NNS_EDGE_FLAG_SERVER = (1 << 2), + + NNS_EDGE_FLAG_ALL = (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND | NNS_EDGE_FLAG_SERVER) +} nns_edge_flag_e; /** * @brief Callback for the nnstreamer edge event. @@ -87,14 +95,14 @@ typedef int (*nns_edge_event_cb) (nns_edge_event_h event_h, void *user_data); typedef void (*nns_edge_data_destroy_cb) (void *data); /** - * @brief Get registered handle. If not registered, create new handle and register it. + * @brief Create edge handle. */ -int nns_edge_create_handle (const char *id, const char *topic, nns_edge_h *edge_h); +int nns_edge_create_handle (const char *id, nns_edge_connect_type_e connect_type, int flags, nns_edge_h *edge_h); /** * @brief Start the nnstreamer edge. */ -int nns_edge_start (nns_edge_h edge_h, bool is_server); +int nns_edge_start (nns_edge_h edge_h); /** * @brief Release the given handle. @@ -109,7 +117,7 @@ int nns_edge_set_event_callback (nns_edge_h edge_h, nns_edge_event_cb cb, void * /** * @brief Connect to the destination node. */ -int nns_edge_connect (nns_edge_h edge_h, nns_edge_protocol_e protocol, const char *ip, int port); +int nns_edge_connect (nns_edge_h edge_h, const char *dest_ip, int dest_port); /** * @brief Disconnect from the destination node. @@ -117,35 +125,20 @@ int nns_edge_connect (nns_edge_h edge_h, nns_edge_protocol_e protocol, const cha int nns_edge_disconnect (nns_edge_h edge_h); /** - * @brief Publish a message to a given topic. + * @brief Publish a message to desination (broker or connected node). */ int nns_edge_publish (nns_edge_h edge_h, nns_edge_data_h data_h); /** - * @brief Request result to the server. - */ -int nns_edge_request (nns_edge_h edge_h, nns_edge_data_h data_h); - -/** - * @brief Respond to a request. + * @brief Subscribe a message from broker. */ -int nns_edge_respond (nns_edge_h edge_h, nns_edge_data_h data_h); +int nns_edge_subscribe (nns_edge_h edge_h); /** - * @brief Subscribe a message to a given topic. - */ -int nns_edge_subscribe (nns_edge_h edge_h, nns_edge_data_h data_h); - -/** - * @brief Unsubscribe a message to a given topic. + * @brief Unsubscribe a message. */ int nns_edge_unsubscribe (nns_edge_h edge_h); -/** - * @brief Get the topic of edge handle. Caller should release returned string using free(). - */ -int nns_edge_get_topic (nns_edge_h edge_h, char **topic); - /** * @brief Set nnstreamer edge info. * @note The param key is case-insensitive. If same key string already exists, it will replace the old value. diff --git a/src/libnnstreamer-edge/nnstreamer-edge-aitt.c b/src/libnnstreamer-edge/nnstreamer-edge-aitt.c index 1a1b024..3012406 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-aitt.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-aitt.c @@ -23,7 +23,7 @@ typedef void *nns_edge_aitt_sub_h; */ typedef struct { - nns_edge_protocol_e protocol; + nns_edge_connect_type_e connect_type; struct { nns_edge_aitt_h aitt_h; diff --git a/src/libnnstreamer-edge/nnstreamer-edge-internal.c b/src/libnnstreamer-edge/nnstreamer-edge-internal.c index cd6877c..0f4b70f 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-internal.c +++ b/src/libnnstreamer-edge/nnstreamer-edge-internal.c @@ -15,7 +15,6 @@ #define N_BACKLOG 10 #define DEFAULT_TIMEOUT_SEC 10 -#define _STR_NULL(str) ((str) ? (str) : "(NULL)") /** * @brief enum for nnstreamer edge query commands. @@ -342,6 +341,28 @@ _nns_edge_cmd_receive (nns_edge_conn_s * conn, nns_edge_cmd_s * cmd) return ret; } +/** + * @brief Internal function to send edge data. + */ +static int +_nns_edge_transfer_data (nns_edge_conn_s * conn, nns_edge_data_h data_h, + int64_t client_id) +{ + nns_edge_cmd_s cmd; + unsigned int i; + int ret; + + _nns_edge_cmd_init (&cmd, _NNS_EDGE_CMD_TRANSFER_DATA, client_id); + + nns_edge_data_get_count (data_h, &cmd.info.num); + for (i = 0; i < cmd.info.num; i++) + nns_edge_data_get (data_h, i, &cmd.mem[i], &cmd.info.mem_size[i]); + + ret = _nns_edge_cmd_send (conn, &cmd); + + return ret; +} + /** * @brief Internal function to invoke event callback. * @note This function should be called with handle lock. @@ -604,7 +625,7 @@ _nns_edge_connect_to (nns_edge_handle_s * eh, int64_t client_id, goto error; } - if (!eh->is_server) { + if (!(eh->flags & NNS_EDGE_FLAG_SERVER)) { /* Receive capability and client ID from server. */ _nns_edge_cmd_init (&cmd, _NNS_EDGE_CMD_ERROR, client_id); ret = _nns_edge_cmd_receive (conn, &cmd); @@ -730,15 +751,14 @@ _nns_edge_message_handler (void *thread_data) continue; } + for (i = 0; i < cmd.info.num; i++) + nns_edge_data_add (data_h, cmd.mem[i], cmd.info.mem_size[i], NULL); + /* Set client ID in edge data */ val = nns_edge_strdup_printf ("%ld", (long int) client_id); nns_edge_data_set_info (data_h, "client_id", val); SAFE_FREE (val); - for (i = 0; i < cmd.info.num; i++) { - nns_edge_data_add (data_h, cmd.mem[i], cmd.info.mem_size[i], NULL); - } - ret = _nns_edge_invoke_event_cb (eh, NNS_EDGE_EVENT_NEW_DATA_RECEIVED, data_h, sizeof (nns_edge_data_h), NULL); if (ret != NNS_EDGE_ERROR_NONE) { @@ -851,10 +871,13 @@ _nns_edge_accept_socket_async_cb (GObject * source, GAsyncResult * result, goto error; } - client_id = eh->is_server ? g_get_monotonic_time () : eh->client_id; + if (eh->flags & NNS_EDGE_FLAG_SERVER) + client_id = g_get_monotonic_time (); + else + client_id = eh->client_id; /* Send capability and info to check compatibility. */ - if (eh->is_server) { + if (eh->flags & NNS_EDGE_FLAG_SERVER) { if (!STR_IS_VALID (eh->caps_str)) { nns_edge_loge ("Cannot accept socket, invalid capability."); goto error; @@ -923,10 +946,11 @@ error: } /** - * @brief Get registered handle. If not registered, create new handle and register it. + * @brief Create edge handle. */ int -nns_edge_create_handle (const char *id, const char *topic, nns_edge_h * edge_h) +nns_edge_create_handle (const char *id, nns_edge_connect_type_e connect_type, + int flags, nns_edge_h * edge_h) { nns_edge_handle_s *eh; @@ -935,8 +959,17 @@ nns_edge_create_handle (const char *id, const char *topic, nns_edge_h * edge_h) return NNS_EDGE_ERROR_INVALID_PARAMETER; } - if (!STR_IS_VALID (topic)) { - nns_edge_loge ("Invalid param, given topic is invalid."); + if (connect_type < 0 || connect_type >= NNS_EDGE_CONNECT_TYPE_UNKNOWN) { + nns_edge_loge ("Invalid param, set valid connect type."); + return NNS_EDGE_ERROR_INVALID_PARAMETER; + } + + /** + * @todo handle flag (receive | send) + * e.g., send only case: listener is unnecessary. + */ + if (flags <= 0 || !(flags & NNS_EDGE_FLAG_ALL)) { + nns_edge_loge ("Invalid param, set exact edge flags."); return NNS_EDGE_ERROR_INVALID_PARAMETER; } @@ -945,11 +978,6 @@ nns_edge_create_handle (const char *id, const char *topic, nns_edge_h * edge_h) return NNS_EDGE_ERROR_INVALID_PARAMETER; } - /** - * @todo manage edge handles - * 1. consider adding hash table or list to manage edge handles. - * 2. compare topic and return error if existing topic in handle is different. - */ eh = (nns_edge_handle_s *) malloc (sizeof (nns_edge_handle_s)); if (!eh) { nns_edge_loge ("Failed to allocate memory for edge handle."); @@ -960,12 +988,10 @@ nns_edge_create_handle (const char *id, const char *topic, nns_edge_h * edge_h) nns_edge_lock_init (eh); eh->magic = NNS_EDGE_MAGIC; eh->id = nns_edge_strdup (id); - eh->topic = nns_edge_strdup (topic); - eh->protocol = NNS_EDGE_PROTOCOL_TCP; - eh->is_server = false; + eh->connect_type = connect_type; eh->ip = nns_edge_strdup ("localhost"); eh->port = 0; - eh->caps_str = NULL; + eh->flags = flags; /* Connection data for each client ID. */ eh->conn_table = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, @@ -979,7 +1005,7 @@ nns_edge_create_handle (const char *id, const char *topic, nns_edge_h * edge_h) * @brief Start the nnstreamer edge. */ int -nns_edge_start (nns_edge_h edge_h, bool is_server) +nns_edge_start (nns_edge_h edge_h) { GSocketAddress *saddr = NULL; GError *err = NULL; @@ -1000,8 +1026,7 @@ nns_edge_start (nns_edge_h edge_h, bool is_server) return NNS_EDGE_ERROR_INVALID_PARAMETER; } - eh->is_server = is_server; - if (!is_server && 0 == eh->port) { + if (eh->port <= 0) { eh->port = nns_edge_get_available_port (); if (eh->port <= 0) { nns_edge_loge ("Failed to start edge. Cannot get available port."); @@ -1073,6 +1098,7 @@ nns_edge_release_handle (nns_edge_h edge_h) SAFE_FREE (eh->id); SAFE_FREE (eh->topic); SAFE_FREE (eh->ip); + SAFE_FREE (eh->dest_ip); SAFE_FREE (eh->caps_str); nns_edge_unlock (eh); @@ -1125,8 +1151,7 @@ nns_edge_set_event_callback (nns_edge_h edge_h, nns_edge_event_cb cb, * @brief Connect to the destination node. */ int -nns_edge_connect (nns_edge_h edge_h, nns_edge_protocol_e protocol, - const char *ip, int port) +nns_edge_connect (nns_edge_h edge_h, const char *dest_ip, int dest_port) { nns_edge_handle_s *eh; int ret; @@ -1137,7 +1162,7 @@ nns_edge_connect (nns_edge_h edge_h, nns_edge_protocol_e protocol, return NNS_EDGE_ERROR_INVALID_PARAMETER; } - if (!STR_IS_VALID (ip)) { + if (!STR_IS_VALID (dest_ip)) { nns_edge_loge ("Invalid param, given IP is invalid."); return NNS_EDGE_ERROR_INVALID_PARAMETER; } @@ -1156,12 +1181,14 @@ nns_edge_connect (nns_edge_h edge_h, nns_edge_protocol_e protocol, return NNS_EDGE_ERROR_CONNECTION_FAILURE; } - eh->protocol = protocol; - - /** Connect to info channel. */ - ret = _nns_edge_connect_to (eh, eh->client_id, ip, port); + /* Connect to info channel. */ + ret = _nns_edge_connect_to (eh, eh->client_id, dest_ip, dest_port); if (ret != NNS_EDGE_ERROR_NONE) { - nns_edge_loge ("Failed to connect to %s:%d", ip, port); + nns_edge_loge ("Failed to connect to %s:%d", dest_ip, dest_port); + } else { + SAFE_FREE (eh->dest_ip); + eh->dest_ip = nns_edge_strdup (dest_ip); + eh->dest_port = dest_port; } nns_edge_unlock (eh); @@ -1197,12 +1224,16 @@ nns_edge_disconnect (nns_edge_h edge_h) } /** - * @brief Publish a message to a given topic. + * @brief Publish a message to desination (broker or connected node). */ int nns_edge_publish (nns_edge_h edge_h, nns_edge_data_h data_h) { nns_edge_handle_s *eh; + nns_edge_conn_data_s *conn_data; + int64_t client_id; + char *val; + int ret = NNS_EDGE_ERROR_NONE; eh = (nns_edge_handle_s *) edge_h; if (!eh) { @@ -1215,42 +1246,14 @@ nns_edge_publish (nns_edge_h edge_h, nns_edge_data_h data_h) return NNS_EDGE_ERROR_INVALID_PARAMETER; } - nns_edge_lock (eh); - - if (!NNS_EDGE_MAGIC_IS_VALID (eh)) { - nns_edge_loge ("Invalid param, given edge handle is invalid."); - nns_edge_unlock (eh); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - /** @todo update code (publish data) */ - - nns_edge_unlock (eh); - return NNS_EDGE_ERROR_NONE; -} - -/** - * @brief Request result to the server. - */ -int -nns_edge_request (nns_edge_h edge_h, nns_edge_data_h data_h) -{ - nns_edge_handle_s *eh; - nns_edge_conn_data_s *conn_data; - nns_edge_cmd_s cmd; - int ret; - unsigned int i; - - eh = (nns_edge_handle_s *) edge_h; - if (!eh) { - nns_edge_loge ("Invalid param, given edge handle is null."); + ret = nns_edge_data_get_info (data_h, "client_id", &val); + if (ret != NNS_EDGE_ERROR_NONE) { + nns_edge_loge ("Cannot find client ID in edge data."); return NNS_EDGE_ERROR_INVALID_PARAMETER; } - if (nns_edge_data_is_valid (data_h) != NNS_EDGE_ERROR_NONE) { - nns_edge_loge ("Invalid param, given edge data is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } + client_id = strtoll (val, NULL, 10); + SAFE_FREE (val); nns_edge_lock (eh); @@ -1260,35 +1263,38 @@ nns_edge_request (nns_edge_h edge_h, nns_edge_data_h data_h) return NNS_EDGE_ERROR_INVALID_PARAMETER; } - conn_data = _nns_edge_get_connection (eh, eh->client_id); - if (!conn_data || !_nns_edge_check_connection (conn_data->sink_conn)) { - nns_edge_loge ("Failed to request, connection failure."); - nns_edge_unlock (eh); - return NNS_EDGE_ERROR_CONNECTION_FAILURE; - } - - _nns_edge_cmd_init (&cmd, _NNS_EDGE_CMD_TRANSFER_DATA, eh->client_id); + /** @todo update code for each connect type */ + switch (eh->connect_type) { + case NNS_EDGE_CONNECT_TYPE_TCP: + case NNS_EDGE_CONNECT_TYPE_HYBRID: + conn_data = _nns_edge_get_connection (eh, client_id); + if (!conn_data) { + nns_edge_loge + ("Cannot find connection, invalid client ID or connection closed."); + ret = NNS_EDGE_ERROR_INVALID_PARAMETER; + break; + } - nns_edge_data_get_count (data_h, &cmd.info.num); - for (i = 0; i < cmd.info.num; i++) { - nns_edge_data_get (data_h, i, &cmd.mem[i], &cmd.info.mem_size[i]); + ret = _nns_edge_transfer_data (conn_data->sink_conn, data_h, client_id); + if (ret != NNS_EDGE_ERROR_NONE) + nns_edge_loge ("Failed to send edge data."); + break; + default: + break; } - ret = _nns_edge_cmd_send (conn_data->sink_conn, &cmd); - if (ret != NNS_EDGE_ERROR_NONE) - nns_edge_loge ("Failed to request, cannot send edge data."); - nns_edge_unlock (eh); return ret; } /** - * @brief Subscribe a message to a given topic. + * @brief Subscribe a message from broker. */ int -nns_edge_subscribe (nns_edge_h edge_h, nns_edge_data_h data_h) +nns_edge_subscribe (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) { @@ -1296,32 +1302,41 @@ nns_edge_subscribe (nns_edge_h edge_h, nns_edge_data_h data_h) return NNS_EDGE_ERROR_INVALID_PARAMETER; } - if (nns_edge_data_is_valid (data_h) != NNS_EDGE_ERROR_NONE) { - nns_edge_loge ("Invalid param, given edge data is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - nns_edge_lock (eh); if (!NNS_EDGE_MAGIC_IS_VALID (eh)) { nns_edge_loge ("Invalid param, given edge handle is invalid."); - nns_edge_unlock (eh); - return NNS_EDGE_ERROR_INVALID_PARAMETER; + ret = NNS_EDGE_ERROR_INVALID_PARAMETER; + goto done; + } + + if (eh->connect_type != NNS_EDGE_CONNECT_TYPE_MQTT) { + nns_edge_loge ("Invalid connect type, cannot subscribe a message."); + ret = NNS_EDGE_ERROR_INVALID_PARAMETER; + goto done; + } + + if (!STR_IS_VALID (eh->topic)) { + nns_edge_loge ("Invalid topic, cannot subscribe a message."); + ret = NNS_EDGE_ERROR_INVALID_PARAMETER; + goto done; } /** @todo update code (subscribe) */ +done: nns_edge_unlock (eh); - return NNS_EDGE_ERROR_NONE; + return ret; } /** - * @brief Unsubscribe a message to a given topic. + * @brief Unsubscribe a message. */ int nns_edge_unsubscribe (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) { @@ -1333,48 +1348,27 @@ nns_edge_unsubscribe (nns_edge_h edge_h) if (!NNS_EDGE_MAGIC_IS_VALID (eh)) { nns_edge_loge ("Invalid param, given edge handle is invalid."); - nns_edge_unlock (eh); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - /** @todo update code (unsubscribe) */ - - nns_edge_unlock (eh); - return NNS_EDGE_ERROR_NONE; -} - -/** - * @brief Get the topic of edge handle. Caller should release returned string using free(). - * @todo is this necessary? - */ -int -nns_edge_get_topic (nns_edge_h edge_h, char **topic) -{ - nns_edge_handle_s *eh; - - 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; + ret = NNS_EDGE_ERROR_INVALID_PARAMETER; + goto done; } - if (!topic) { - nns_edge_loge ("Invalid param, topic should not be null."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; + if (eh->connect_type != NNS_EDGE_CONNECT_TYPE_MQTT) { + nns_edge_loge ("Invalid connect type, cannot subscribe a message."); + ret = NNS_EDGE_ERROR_INVALID_PARAMETER; + goto done; } - nns_edge_lock (eh); - - if (!NNS_EDGE_MAGIC_IS_VALID (eh)) { - nns_edge_loge ("Invalid param, given edge handle is invalid."); - nns_edge_unlock (eh); - return NNS_EDGE_ERROR_INVALID_PARAMETER; + if (!STR_IS_VALID (eh->topic)) { + nns_edge_loge ("Invalid topic, cannot subscribe a message."); + ret = NNS_EDGE_ERROR_INVALID_PARAMETER; + goto done; } - *topic = nns_edge_strdup (eh->topic); + /** @todo update code (unsubscribe) */ +done: nns_edge_unlock (eh); - return NNS_EDGE_ERROR_NONE; + return ret; } /** @@ -1384,6 +1378,7 @@ int nns_edge_set_info (nns_edge_h edge_h, const char *key, const char *value) { nns_edge_handle_s *eh; + int ret = NNS_EDGE_ERROR_NONE; eh = (nns_edge_handle_s *) edge_h; if (!eh) { @@ -1420,16 +1415,21 @@ nns_edge_set_info (nns_edge_h edge_h, const char *key, const char *value) SAFE_FREE (eh->ip); eh->ip = nns_edge_strdup (value); } else if (0 == strcasecmp (key, "PORT")) { - eh->port = g_ascii_strtoll (value, NULL, 10); + eh->port = (int) strtoll (value, NULL, 10); } else if (0 == strcasecmp (key, "TOPIC")) { SAFE_FREE (eh->topic); eh->topic = nns_edge_strdup (value); + } else if (0 == strcasecmp (key, "ID") || 0 == strcasecmp (key, "CLIENT_ID")) { + /* Not allowed key */ + nns_edge_loge ("Cannot update %s.", key); + ret = NNS_EDGE_ERROR_INVALID_PARAMETER; } else { nns_edge_logw ("Failed to set edge info. Unknown key: %s", key); + ret = NNS_EDGE_ERROR_INVALID_PARAMETER; } nns_edge_unlock (eh); - return NNS_EDGE_ERROR_NONE; + return ret; } /** @@ -1439,6 +1439,7 @@ int nns_edge_get_info (nns_edge_h edge_h, const char *key, char **value) { nns_edge_handle_s *eh; + int ret = NNS_EDGE_ERROR_NONE; eh = (nns_edge_handle_s *) edge_h; if (!eh) { @@ -1476,76 +1477,20 @@ nns_edge_get_info (nns_edge_h edge_h, const char *key, char **value) *value = nns_edge_strdup_printf ("%d", eh->port); } else if (0 == strcasecmp (key, "TOPIC")) { *value = nns_edge_strdup (eh->topic); + } else if (0 == strcasecmp (key, "ID")) { + *value = nns_edge_strdup (eh->id); + } else if (0 == strcasecmp (key, "CLIENT_ID")) { + if (eh->flags & NNS_EDGE_FLAG_SERVER) { + nns_edge_loge ("Cannot get the client ID, it was started as a server."); + ret = NNS_EDGE_ERROR_INVALID_PARAMETER; + } else { + *value = nns_edge_strdup_printf ("%ld", (long int) eh->client_id); + } } else { nns_edge_logw ("Failed to get edge info. Unknown key: %s", key); + ret = NNS_EDGE_ERROR_INVALID_PARAMETER; } - nns_edge_unlock (eh); - return NNS_EDGE_ERROR_NONE; -} - -/** - * @brief Respond to a request. - */ -int -nns_edge_respond (nns_edge_h edge_h, nns_edge_data_h data_h) -{ - nns_edge_handle_s *eh; - nns_edge_conn_data_s *conn_data; - nns_edge_cmd_s cmd; - int64_t client_id; - char *val; - int ret; - unsigned int i; - - 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_data_is_valid (data_h) != NNS_EDGE_ERROR_NONE) { - nns_edge_loge ("Invalid param, given edge data is invalid."); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - nns_edge_lock (eh); - - if (!NNS_EDGE_MAGIC_IS_VALID (eh)) { - nns_edge_loge ("Invalid param, given edge handle is invalid."); - nns_edge_unlock (eh); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - ret = nns_edge_data_get_info (data_h, "client_id", &val); - if (ret != NNS_EDGE_ERROR_NONE) { - nns_edge_loge ("Cannot find client ID in edge data."); - nns_edge_unlock (eh); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - client_id = strtoll (val, NULL, 10); - SAFE_FREE (val); - - conn_data = _nns_edge_get_connection (eh, client_id); - if (!conn_data) { - nns_edge_loge - ("Cannot find connection, invalid client ID or connection closed."); - nns_edge_unlock (eh); - return NNS_EDGE_ERROR_INVALID_PARAMETER; - } - - _nns_edge_cmd_init (&cmd, _NNS_EDGE_CMD_TRANSFER_DATA, client_id); - - nns_edge_data_get_count (data_h, &cmd.info.num); - for (i = 0; i < cmd.info.num; i++) { - nns_edge_data_get (data_h, i, &cmd.mem[i], &cmd.info.mem_size[i]); - } - - ret = _nns_edge_cmd_send (conn_data->sink_conn, &cmd); - if (ret != NNS_EDGE_ERROR_NONE) - nns_edge_loge ("Failed to respond, cannot send edge data."); - nns_edge_unlock (eh); return ret; } diff --git a/src/libnnstreamer-edge/nnstreamer-edge-internal.h b/src/libnnstreamer-edge/nnstreamer-edge-internal.h index 55a3fd6..a58cae3 100644 --- a/src/libnnstreamer-edge/nnstreamer-edge-internal.h +++ b/src/libnnstreamer-edge/nnstreamer-edge-internal.h @@ -30,15 +30,17 @@ typedef struct { pthread_mutex_t lock; char *id; char *topic; - nns_edge_protocol_e protocol; + nns_edge_connect_type_e connect_type; char *ip; /**< host IP */ int port; /**< host port */ + char *dest_ip; /**< destination IP (broker or target device) */ + int dest_port; /**< destination port (broker or target device) */ + int flags; /* Edge event callback and user data */ nns_edge_event_cb event_cb; void *user_data; - bool is_server; int64_t client_id; char *caps_str; diff --git a/tests/unittest_nnstreamer-edge.cc b/tests/unittest_nnstreamer-edge.cc index b3af41b..390f0b0 100644 --- a/tests/unittest_nnstreamer-edge.cc +++ b/tests/unittest_nnstreamer-edge.cc @@ -99,7 +99,7 @@ _test_edge_event_cb (nns_edge_event_h event_h, void *user_data) * @note This is test code, responding to client. * Recommend not to call edge API in event callback. */ - ret = nns_edge_respond (_td->handle, data_h); + ret = nns_edge_publish (_td->handle, data_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); } else { /* Compare received data */ @@ -132,7 +132,7 @@ _test_edge_thread (void *data) ne_test_data_s *_td = (ne_test_data_s *) data; int ret; - ret = nns_edge_start (_td->handle, _td->is_server); + ret = nns_edge_start (_td->handle); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); _td->running = true; @@ -156,7 +156,7 @@ TEST(edge, connectLocal) void *data; unsigned int i, retry; int ret, port; - char *val; + char *val, *client1_id, *client2_id; _td_server = _get_test_data (true); _td_client1 = _get_test_data (false); @@ -165,7 +165,8 @@ TEST(edge, connectLocal) /* Prepare server (127.0.0.1:port) */ val = nns_edge_strdup_printf ("%d", port); - nns_edge_create_handle ("temp-server", "temp-topic", &server_h); + nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND | NNS_EDGE_FLAG_SERVER), &server_h); nns_edge_set_event_callback (server_h, _test_edge_event_cb, _td_server); nns_edge_set_info (server_h, "IP", "127.0.0.1"); nns_edge_set_info (server_h, "PORT", val); @@ -174,12 +175,14 @@ TEST(edge, connectLocal) nns_edge_free (val); /* Prepare client */ - nns_edge_create_handle ("temp-client1", "temp-topic", &client1_h); + nns_edge_create_handle ("temp-client1", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &client1_h); nns_edge_set_event_callback (client1_h, _test_edge_event_cb, _td_client1); nns_edge_set_info (client1_h, "CAPS", "test client1"); _td_client1->handle = client1_h; - nns_edge_create_handle ("temp-client2", "temp-topic", &client2_h); + nns_edge_create_handle ("temp-client2", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &client2_h); nns_edge_set_event_callback (client2_h, _test_edge_event_cb, _td_client2); nns_edge_set_info (client2_h, "CAPS", "test client2"); _td_client2->handle = client2_h; @@ -205,10 +208,10 @@ TEST(edge, connectLocal) usleep (20000); } while (!g_main_loop_is_running (_td_client2->loop)); - ret = nns_edge_connect (client1_h, NNS_EDGE_PROTOCOL_TCP, "127.0.0.1", port); + ret = nns_edge_connect (client1_h, "127.0.0.1", port); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); usleep (10000); - ret = nns_edge_connect (client2_h, NNS_EDGE_PROTOCOL_TCP, "127.0.0.1", port); + ret = nns_edge_connect (client2_h, "127.0.0.1", port); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); sleep (2); @@ -218,6 +221,12 @@ TEST(edge, connectLocal) data = malloc (data_len); ASSERT_TRUE (data != NULL); + client1_id = client2_id = NULL; + ret = nns_edge_get_info (client1_h, "client_id", &client1_id); + EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); + ret = nns_edge_get_info (client2_h, "client_id", &client2_id); + EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); + for (i = 0; i < 10U; i++) ((unsigned int *) data)[i] = i; @@ -228,10 +237,14 @@ TEST(edge, connectLocal) EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); for (i = 0; i < 5U; i++) { - ret = nns_edge_request (client1_h, data_h); + ret = nns_edge_data_set_info (data_h, "client_id", client1_id); + EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); + ret = nns_edge_publish (client1_h, data_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); usleep (10000); - ret = nns_edge_request (client2_h, data_h); + ret = nns_edge_data_set_info (data_h, "client_id", client2_id); + EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); + ret = nns_edge_publish (client2_h, data_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); usleep (100000); @@ -263,6 +276,9 @@ TEST(edge, connectLocal) EXPECT_TRUE (_td_client1->received > 0); EXPECT_TRUE (_td_client2->received > 0); + nns_edge_free (client1_id); + nns_edge_free (client2_id); + _free_test_data (_td_server); _free_test_data (_td_client1); _free_test_data (_td_client2); @@ -276,7 +292,8 @@ TEST(edge, createHandleInvalidParam01_n) nns_edge_h edge_h; int ret; - ret = nns_edge_create_handle (NULL, "temp-topic", &edge_h); + ret = nns_edge_create_handle (NULL, NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); } @@ -288,7 +305,8 @@ TEST(edge, createHandleInvalidParam02_n) nns_edge_h edge_h; int ret; - ret = nns_edge_create_handle ("temp-id", NULL, &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_UNKNOWN, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); } @@ -299,7 +317,8 @@ TEST(edge, createHandleInvalidParam03_n) { int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", NULL); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), NULL); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); } @@ -311,7 +330,8 @@ TEST(edge, createHandleInvalidParam04_n) nns_edge_h edge_h; int ret; - ret = nns_edge_create_handle ("", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("", NNS_EDGE_CONNECT_TYPE_MQTT, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); } @@ -323,7 +343,8 @@ TEST(edge, createHandleInvalidParam05_n) nns_edge_h edge_h; int ret; - ret = nns_edge_create_handle ("temp-id", "", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_HYBRID, + NNS_EDGE_FLAG_NONE, &edge_h); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); } @@ -334,7 +355,7 @@ TEST(edge, startInvalidParam01_n) { int ret; - ret = nns_edge_start (NULL, false); + ret = nns_edge_start (NULL); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); } @@ -347,13 +368,14 @@ TEST(edge, startInvalidParam02_n) nns_edge_handle_s *eh; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); eh = (nns_edge_handle_s *) edge_h; eh->magic = NNS_EDGE_MAGIC_DEAD; - ret = nns_edge_start (edge_h, false); + ret = nns_edge_start (edge_h); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); eh->magic = NNS_EDGE_MAGIC; @@ -382,7 +404,8 @@ TEST(edge, releaseHandleInvalidParam02_n) nns_edge_handle_s *eh; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); eh = (nns_edge_handle_s *) edge_h; @@ -408,7 +431,8 @@ TEST(edge, setEventCbSetNullCallback) _td = _get_test_data (false); - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_set_event_callback (edge_h, _test_edge_event_cb, _td); @@ -449,7 +473,8 @@ TEST(edge, setEventCbInvalidParam02_n) _td = _get_test_data (false); - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); eh = (nns_edge_handle_s *) edge_h; @@ -473,7 +498,7 @@ TEST(edge, connectInvalidParam01_n) { int ret; - ret = nns_edge_connect (NULL, NNS_EDGE_PROTOCOL_TCP, "127.0.0.1", 80); + ret = nns_edge_connect (NULL, "127.0.0.1", 80); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); } @@ -486,7 +511,8 @@ TEST(edge, connectInvalidParam02_n) nns_edge_handle_s *eh; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_set_event_callback (edge_h, _test_edge_event_cb, NULL); @@ -495,7 +521,7 @@ TEST(edge, connectInvalidParam02_n) eh = (nns_edge_handle_s *) edge_h; eh->magic = NNS_EDGE_MAGIC_DEAD; - ret = nns_edge_connect (edge_h, NNS_EDGE_PROTOCOL_TCP, "127.0.0.1", 80); + ret = nns_edge_connect (edge_h, "127.0.0.1", 80); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); eh->magic = NNS_EDGE_MAGIC; @@ -512,13 +538,14 @@ TEST(edge, connectInvalidParam03_n) nns_edge_h edge_h; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_set_event_callback (edge_h, _test_edge_event_cb, NULL); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - ret = nns_edge_connect (edge_h, NNS_EDGE_PROTOCOL_TCP, NULL, 80); + ret = nns_edge_connect (edge_h, NULL, 80); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_release_handle (edge_h); @@ -533,13 +560,14 @@ TEST(edge, connectInvalidParam04_n) nns_edge_h edge_h; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_set_event_callback (edge_h, _test_edge_event_cb, NULL); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - ret = nns_edge_connect (edge_h, NNS_EDGE_PROTOCOL_TCP, "", 80); + ret = nns_edge_connect (edge_h, "", 80); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_release_handle (edge_h); @@ -566,7 +594,8 @@ TEST(edge, disconnectInvalidParam02_n) nns_edge_handle_s *eh; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); eh = (nns_edge_handle_s *) edge_h; @@ -592,6 +621,9 @@ TEST(edge, publishInvalidParam01_n) ret = nns_edge_data_create (&data_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); + ret = nns_edge_data_set_info (data_h, "client_id", "10"); + EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); + ret = nns_edge_publish (NULL, data_h); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); @@ -609,12 +641,16 @@ TEST(edge, publishInvalidParam02_n) nns_edge_handle_s *eh; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_data_create (&data_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); + ret = nns_edge_data_set_info (data_h, "client_id", "10"); + EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); + eh = (nns_edge_handle_s *) edge_h; eh->magic = NNS_EDGE_MAGIC_DEAD; @@ -638,7 +674,8 @@ TEST(edge, publishInvalidParam03_n) nns_edge_h edge_h; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_publish (edge_h, NULL); @@ -649,162 +686,23 @@ TEST(edge, publishInvalidParam03_n) } /** - * @brief Request - invalid param. - */ -TEST(edge, requestInvalidParam01_n) -{ - nns_edge_data_h data_h; - int ret; - - ret = nns_edge_data_create (&data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_request (NULL, data_h); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_destroy (data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Request - invalid param. - */ -TEST(edge, requestInvalidParam02_n) -{ - nns_edge_h edge_h; - nns_edge_data_h data_h; - nns_edge_handle_s *eh; - int ret; - - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_create (&data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - eh = (nns_edge_handle_s *) edge_h; - eh->magic = NNS_EDGE_MAGIC_DEAD; - - ret = nns_edge_request (edge_h, data_h); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - eh->magic = NNS_EDGE_MAGIC; - - ret = nns_edge_release_handle (edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_destroy (data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Request - invalid param. - */ -TEST(edge, requestInvalidParam03_n) -{ - nns_edge_h edge_h; - int ret; - - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_request (edge_h, NULL); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_release_handle (edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Respond - invalid param. - */ -TEST(edge, respondInvalidParam01_n) -{ - nns_edge_data_h data_h; - int ret; - - ret = nns_edge_data_create (&data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_set_info (data_h, "client_id", "10"); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_respond (NULL, data_h); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_destroy (data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Respond - invalid param. - */ -TEST(edge, respondInvalidParam02_n) -{ - nns_edge_h edge_h; - nns_edge_data_h data_h; - nns_edge_handle_s *eh; - int ret; - - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_create (&data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_set_info (data_h, "client_id", "10"); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - eh = (nns_edge_handle_s *) edge_h; - eh->magic = NNS_EDGE_MAGIC_DEAD; - - ret = nns_edge_respond (edge_h, data_h); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - eh->magic = NNS_EDGE_MAGIC; - - ret = nns_edge_release_handle (edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_destroy (data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Respond - invalid param. - */ -TEST(edge, respondInvalidParam03_n) -{ - nns_edge_h edge_h; - int ret; - - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_respond (edge_h, NULL); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_release_handle (edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Respond - invalid param. + * @brief Publish - invalid param. */ -TEST(edge, respondInvalidParam04_n) +TEST(edge, publishInvalidParam04_n) { nns_edge_h edge_h; nns_edge_data_h data_h; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_data_create (&data_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); /* No client ID */ - ret = nns_edge_respond (edge_h, data_h); + ret = nns_edge_publish (edge_h, data_h); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_release_handle (edge_h); @@ -819,17 +717,10 @@ TEST(edge, respondInvalidParam04_n) */ TEST(edge, subscribeInvalidParam01_n) { - nns_edge_data_h data_h; int ret; - ret = nns_edge_data_create (&data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_subscribe (NULL, data_h); + ret = nns_edge_subscribe (NULL); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_destroy (data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); } /** @@ -838,47 +729,23 @@ TEST(edge, subscribeInvalidParam01_n) TEST(edge, subscribeInvalidParam02_n) { nns_edge_h edge_h; - nns_edge_data_h data_h; nns_edge_handle_s *eh; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_create (&data_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); eh = (nns_edge_handle_s *) edge_h; eh->magic = NNS_EDGE_MAGIC_DEAD; - ret = nns_edge_subscribe (edge_h, data_h); + ret = nns_edge_subscribe (edge_h); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); eh->magic = NNS_EDGE_MAGIC; ret = nns_edge_release_handle (edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_data_destroy (data_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Subscribe - invalid param. - */ -TEST(edge, subscribeInvalidParam03_n) -{ - nns_edge_h edge_h; - int ret; - - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_subscribe (edge_h, NULL); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_release_handle (edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); } /** @@ -901,7 +768,8 @@ TEST(edge, unsubscribeInvalidParam02_n) nns_edge_handle_s *eh; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); eh = (nns_edge_handle_s *) edge_h; @@ -917,55 +785,33 @@ TEST(edge, unsubscribeInvalidParam02_n) } /** - * @brief Get topic. - */ -TEST(edge, getTopic) -{ - nns_edge_h edge_h; - char *topic = NULL; - int ret; - - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_get_topic (edge_h, &topic); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - EXPECT_STREQ (topic, "temp-topic"); - free (topic); - - ret = nns_edge_release_handle (edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Get topic - invalid param. + * @brief Set info - invalid param. */ -TEST(edge, getTopicInvalidParam01_n) +TEST(edge, setInfoInvalidParam01_n) { - char *topic = NULL; int ret; - ret = nns_edge_get_topic (NULL, &topic); + ret = nns_edge_set_info (NULL, "caps", "temp-caps"); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); } /** - * @brief Get topic - invalid param. + * @brief Set info - invalid param. */ -TEST(edge, getTopicInvalidParam02_n) +TEST(edge, setInfoInvalidParam02_n) { nns_edge_h edge_h; nns_edge_handle_s *eh; - char *topic = NULL; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); eh = (nns_edge_handle_s *) edge_h; eh->magic = NNS_EDGE_MAGIC_DEAD; - ret = nns_edge_get_topic (edge_h, &topic); + ret = nns_edge_set_info (edge_h, "caps", "temp-caps"); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); eh->magic = NNS_EDGE_MAGIC; @@ -974,55 +820,21 @@ TEST(edge, getTopicInvalidParam02_n) EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); } -/** - * @brief Get topic - invalid param. - */ -TEST(edge, getTopicInvalidParam03_n) -{ - nns_edge_h edge_h; - int ret; - - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_get_topic (edge_h, NULL); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - - ret = nns_edge_release_handle (edge_h); - EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); -} - -/** - * @brief Set info - invalid param. - */ -TEST(edge, setInfoInvalidParam01_n) -{ - int ret; - - ret = nns_edge_set_info (NULL, "topic", "temp-topic"); - EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); -} - /** * @brief Set info - invalid param. */ -TEST(edge, setInfoInvalidParam02_n) +TEST(edge, setInfoInvalidParam03_n) { nns_edge_h edge_h; - nns_edge_handle_s *eh; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - eh = (nns_edge_handle_s *) edge_h; - eh->magic = NNS_EDGE_MAGIC_DEAD; - - ret = nns_edge_set_info (edge_h, "topic", "temp-topic"); + ret = nns_edge_set_info (edge_h, NULL, "temp-caps"); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); - eh->magic = NNS_EDGE_MAGIC; - ret = nns_edge_release_handle (edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); } @@ -1030,15 +842,16 @@ TEST(edge, setInfoInvalidParam02_n) /** * @brief Set info - invalid param. */ -TEST(edge, setInfoInvalidParam03_n) +TEST(edge, setInfoInvalidParam04_n) { nns_edge_h edge_h; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - ret = nns_edge_set_info (edge_h, NULL, "temp-topic"); + ret = nns_edge_set_info (edge_h, "", "temp-caps"); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_release_handle (edge_h); @@ -1048,15 +861,16 @@ TEST(edge, setInfoInvalidParam03_n) /** * @brief Set info - invalid param. */ -TEST(edge, setInfoInvalidParam04_n) +TEST(edge, setInfoInvalidParam05_n) { nns_edge_h edge_h; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - ret = nns_edge_set_info (edge_h, "", "temp-topic"); + ret = nns_edge_set_info (edge_h, "caps", NULL); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_release_handle (edge_h); @@ -1066,15 +880,16 @@ TEST(edge, setInfoInvalidParam04_n) /** * @brief Set info - invalid param. */ -TEST(edge, setInfoInvalidParam05_n) +TEST(edge, setInfoInvalidParam06_n) { nns_edge_h edge_h; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - ret = nns_edge_set_info (edge_h, "topic", NULL); + ret = nns_edge_set_info (edge_h, "caps", ""); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_release_handle (edge_h); @@ -1084,15 +899,19 @@ TEST(edge, setInfoInvalidParam05_n) /** * @brief Set info - invalid param. */ -TEST(edge, setInfoInvalidParam06_n) +TEST(edge, setInfoInvalidParam07_n) { nns_edge_h edge_h; int ret; - ret = nns_edge_create_handle ("temp-id", "temp-topic", &edge_h); + ret = nns_edge_create_handle ("temp-id", NNS_EDGE_CONNECT_TYPE_TCP, + (NNS_EDGE_FLAG_RECV | NNS_EDGE_FLAG_SEND), &edge_h); EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE); - ret = nns_edge_set_info (edge_h, "topic", ""); + /* Not allowed key */ + ret = nns_edge_set_info (edge_h, "id", "temp-id2"); + EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); + ret = nns_edge_set_info (edge_h, "client_id", "temp-cid"); EXPECT_NE (ret, NNS_EDGE_ERROR_NONE); ret = nns_edge_release_handle (edge_h);