Separate AITT handle and update related code, to remove dependency to nns-edge handle.
Signed-off-by: Jaeyun <jy1210.jung@samsung.com>
{
aitt_h aitt_handle;
aitt_sub_h sub_handle;
+ char *id;
+ char *topic;
+ char *host;
+ int port;
+
+ /* event callback for new message */
+ nns_edge_event_cb event_cb;
+ void *user_data;
} nns_edge_aitt_handle_s;
/**
* @brief Create AITT handle and connect to AITT.
- * @note This is internal function for AITT. You should call this with edge-handle lock.
*/
int
-nns_edge_aitt_connect (nns_edge_h edge_h)
+nns_edge_aitt_connect (const char *id, const char *topic, const char *host,
+ const int port, nns_edge_aitt_h * handle)
{
- nns_edge_handle_s *eh;
nns_edge_aitt_handle_s *ah;
aitt_option_h option;
- eh = (nns_edge_handle_s *) edge_h;
+ if (!STR_IS_VALID (id)) {
+ nns_edge_loge ("Invalid param, given id is invalid.");
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+ }
- if (!NNS_EDGE_MAGIC_IS_VALID (eh)) {
- nns_edge_loge ("Invalid param, given edge handle is invalid.");
+ if (!STR_IS_VALID (topic)) {
+ nns_edge_loge ("Invalid param, given topic is invalid.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
- nns_edge_logd ("Create AITT instance: My address: %s:%d", eh->host, eh->port);
+ if (!STR_IS_VALID (host)) {
+ nns_edge_loge ("Invalid param, given host is invalid.");
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!PORT_IS_VALID (port)) {
+ nns_edge_loge ("Invalid param, given port is invalid.");
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+ }
+
+ if (!handle) {
+ nns_edge_loge ("Invalid param, handle should not be null.");
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
+ }
+
+ nns_edge_logd ("Create AITT instance: broker address: %s:%d", host, port);
ah = (nns_edge_aitt_handle_s *) calloc (1, sizeof (nns_edge_aitt_handle_s));
if (!ah) {
}
option = aitt_option_new ();
- aitt_option_set (option, AITT_OPT_MY_IP, eh->host);
+ aitt_option_set (option, AITT_OPT_MY_IP, "localhost");
- ah->aitt_handle = aitt_new (eh->id, option);
+ ah->aitt_handle = aitt_new (id, option);
aitt_option_destroy (option);
if (!ah->aitt_handle) {
return NNS_EDGE_ERROR_UNKNOWN;
}
- if (AITT_ERROR_NONE != aitt_connect (ah->aitt_handle, eh->dest_host,
- eh->dest_port)) {
- nns_edge_loge ("Failed to connect to AITT. IP:port = %s:%d", eh->dest_host,
- eh->dest_port);
+ if (AITT_ERROR_NONE != aitt_connect (ah->aitt_handle, host, port)) {
+ nns_edge_loge ("Failed to connect to AITT. IP:port = %s:%d", host, port);
aitt_destroy (ah->aitt_handle);
SAFE_FREE (ah);
return NNS_EDGE_ERROR_UNKNOWN;
}
- eh->broker_h = ah;
+ ah->id = nns_edge_strdup (id);
+ ah->topic = nns_edge_strdup (topic);
+ ah->host = nns_edge_strdup (host);
+ ah->port = port;
+
+ *handle = ah;
return NNS_EDGE_ERROR_NONE;
}
/**
* @brief Release the AITT handle.
- * @note This is internal function for AITT. You should call this with edge-handle lock.
*/
int
-nns_edge_aitt_close (nns_edge_h edge_h)
+nns_edge_aitt_close (nns_edge_aitt_h handle)
{
- nns_edge_handle_s *eh;
nns_edge_aitt_handle_s *ah;
- eh = (nns_edge_handle_s *) edge_h;
-
- if (!NNS_EDGE_MAGIC_IS_VALID (eh) || !eh->broker_h) {
- nns_edge_loge ("Invalid param, given edge handle is invalid.");
+ if (!handle) {
+ nns_edge_loge ("Invalid param, given AITT handle is invalid.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
- ah = (nns_edge_aitt_handle_s *) eh->broker_h;
- if (AITT_ERROR_NONE != aitt_disconnect (ah->aitt_handle)) {
- nns_edge_loge ("Failed to close AITT handle.");
- return NNS_EDGE_ERROR_UNKNOWN;
+ ah = (nns_edge_aitt_handle_s *) handle;
+
+ /* clear event callback */
+ ah->event_cb = NULL;
+ ah->user_data = NULL;
+
+ if (ah->aitt_handle) {
+ if (AITT_ERROR_NONE != aitt_disconnect (ah->aitt_handle)) {
+ nns_edge_loge ("Failed to close AITT handle.");
+ return NNS_EDGE_ERROR_UNKNOWN;
+ }
+
+ aitt_destroy (ah->aitt_handle);
+ ah->aitt_handle = NULL;
}
- aitt_destroy (ah->aitt_handle);
- ah->aitt_handle = NULL;
- SAFE_FREE (eh->broker_h);
- eh->broker_h = NULL;
+
+ SAFE_FREE (ah->id);
+ SAFE_FREE (ah->topic);
+ SAFE_FREE (ah->host);
+ SAFE_FREE (ah);
return NNS_EDGE_ERROR_NONE;
}
* @brief Check whether aitt handle exists or not.
*/
int
-nns_edge_aitt_is_connected (nns_edge_h edge_h)
+nns_edge_aitt_is_connected (nns_edge_aitt_h handle)
{
- nns_edge_handle_s *eh;
nns_edge_aitt_handle_s *ah;
- eh = (nns_edge_handle_s *) edge_h;
-
- if (!NNS_EDGE_MAGIC_IS_VALID (eh)) {
- nns_edge_loge ("Invalid param, given edge handle is invalid.");
+ if (!handle) {
+ nns_edge_loge ("Invalid param, given AITT handle is invalid.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
- ah = (nns_edge_aitt_handle_s *) eh->broker_h;
- if (!ah || !ah->aitt_handle) {
+ ah = (nns_edge_aitt_handle_s *) handle;
+ if (!ah->aitt_handle) {
nns_edge_loge ("AITT handle is not yet connected.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
/**
* @brief Publish raw data.
- * @note This is internal function forAITT. You should call this with edge-handle lock.
*/
int
-nns_edge_aitt_publish (nns_edge_h edge_h, const void *data, const int length)
+nns_edge_aitt_publish (nns_edge_aitt_h handle, const void *data,
+ const int length)
{
- nns_edge_handle_s *eh;
nns_edge_aitt_handle_s *ah;
int ret;
- eh = (nns_edge_handle_s *) edge_h;
-
- if (!NNS_EDGE_MAGIC_IS_VALID (eh) || !eh->broker_h) {
- nns_edge_loge ("Invalid param, given edge handle is invalid.");
+ if (!handle) {
+ nns_edge_loge ("Invalid param, given AITT handle is invalid.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
- ah = (nns_edge_aitt_handle_s *) eh->broker_h;
+ ah = (nns_edge_aitt_handle_s *) handle;
- ret = aitt_publish (ah->aitt_handle, eh->topic, data, length);
+ ret = aitt_publish (ah->aitt_handle, ah->topic, data, length);
if (AITT_ERROR_NONE != ret) {
- nns_edge_loge ("Failed to publish the message. topic: %s", eh->topic);
+ nns_edge_loge ("Failed to publish the message. topic: %s", ah->topic);
return NNS_EDGE_ERROR_IO;
}
aitt_cb_message_arrived (aitt_msg_h msg_handle, const void *msg,
int msg_len, void *user_data)
{
- nns_edge_handle_s *eh;
+ nns_edge_aitt_handle_s *ah;
nns_edge_data_h data_h;
int ret;
- eh = (nns_edge_handle_s *) user_data;
+ ah = (nns_edge_aitt_handle_s *) user_data;
- if (!NNS_EDGE_MAGIC_IS_VALID (eh)) {
- nns_edge_loge ("Invalid param, given edge handle is invalid.");
+ if (!ah || !ah->event_cb) {
+ nns_edge_logw ("The event callback is null, cannot handle new message.");
return;
}
nns_edge_data_deserialize (data_h, (void *) msg, (nns_size_t) msg_len);
- ret = nns_edge_event_invoke_callback (eh->event_cb, eh->user_data,
+ ret = nns_edge_event_invoke_callback (ah->event_cb, ah->user_data,
NNS_EDGE_EVENT_NEW_DATA_RECEIVED, data_h, sizeof (nns_edge_data_h), NULL);
if (ret != NNS_EDGE_ERROR_NONE)
nns_edge_loge ("Failed to send an event for received message.");
/**
* @brief Subscribe a topic.
- * @note This is internal function for AITT. You should call this with edge-handle lock.
*/
int
-nns_edge_aitt_subscribe (nns_edge_h edge_h)
+nns_edge_aitt_subscribe (nns_edge_aitt_h handle)
{
- nns_edge_handle_s *eh;
nns_edge_aitt_handle_s *ah;
- eh = (nns_edge_handle_s *) edge_h;
-
- if (!NNS_EDGE_MAGIC_IS_VALID (eh) || !eh->broker_h) {
- nns_edge_loge ("Invalid param, given edge handle is invalid.");
+ if (!handle) {
+ nns_edge_loge ("Invalid param, given AITT handle is invalid.");
return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
- if (!eh->topic) {
- nns_edge_loge ("Invalid param, topic cannot be NULL for AITT connection. "
- "Please set topic using nns_edge_set_info()");
- return NNS_EDGE_ERROR_INVALID_PARAMETER;
+ ah = (nns_edge_aitt_handle_s *) handle;
+
+ if (AITT_ERROR_NONE != aitt_subscribe (ah->aitt_handle, ah->topic,
+ aitt_cb_message_arrived, ah, &ah->sub_handle)) {
+ nns_edge_loge ("Failed to subscribe the topic: %s", ah->topic);
+ return NNS_EDGE_ERROR_UNKNOWN;
}
+ return NNS_EDGE_ERROR_NONE;
+}
- ah = (nns_edge_aitt_handle_s *) eh->broker_h;
+/**
+ * @brief Set event callback for new message.
+ */
+int
+nns_edge_aitt_set_event_callback (nns_edge_aitt_h handle, nns_edge_event_cb cb,
+ void *user_data)
+{
+ nns_edge_aitt_handle_s *ah;
- if (AITT_ERROR_NONE != aitt_subscribe (ah->aitt_handle, eh->topic,
- aitt_cb_message_arrived, eh, &ah->sub_handle)) {
- nns_edge_loge ("Failed to subscribe the topic: %s", eh->topic);
- return NNS_EDGE_ERROR_UNKNOWN;
+ if (!handle) {
+ nns_edge_loge ("Invalid param, given AITT handle is invalid.");
+ return NNS_EDGE_ERROR_INVALID_PARAMETER;
}
+
+ ah = (nns_edge_aitt_handle_s *) handle;
+
+ ah->event_cb = cb;
+ ah->user_data = user_data;
+
return NNS_EDGE_ERROR_NONE;
}
+
+/**
+ * @brief Internal util function to send edge-data.
+ */
+int
+nns_edge_aitt_send_data (nns_edge_aitt_h handle, nns_edge_data_h data_h)
+{
+ int ret;
+ void *data = NULL;
+ nns_size_t size;
+
+ ret = nns_edge_data_serialize (data_h, &data, &size);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to serialize the edge data.");
+ return ret;
+ }
+
+ ret = nns_edge_aitt_publish (handle, data, size);
+ if (NNS_EDGE_ERROR_NONE != ret)
+ nns_edge_loge ("Failed to send data to destination.");
+
+ nns_edge_free (data);
+ return ret;
+}
extern "C" {
#endif /* __cplusplus */
+typedef void *nns_edge_aitt_h;
+
#if defined(ENABLE_AITT)
/**
* @brief Create AITT handle and connect to AITT.
- * @note This is internal function for AITT. You should call this with edge-handle lock.
+ * @note This is internal function for AITT.
*/
-int nns_edge_aitt_connect (nns_edge_h edge_h);
+int nns_edge_aitt_connect (const char *id, const char *topic, const char *host, const int port, nns_edge_aitt_h *handle);
/**
* @brief Release the AITT handle.
- * @note This is internal function for AITT. You should call this with edge-handle lock.
+ * @note This is internal function for AITT.
*/
-int nns_edge_aitt_close (nns_edge_h edge_h);
+int nns_edge_aitt_close (nns_edge_aitt_h handle);
/**
- * @brief Check whether aitt handle exists or not.
+ * @brief Publish raw data.
+ * @note This is internal function for AITT.
*/
-int nns_edge_aitt_is_connected (nns_edge_h edge_h);
+int nns_edge_aitt_publish (nns_edge_aitt_h handle, const void *data, const int length);
/**
- * @brief Publish raw data.
- * @note This is internal function forAITT. You should call this with edge-handle lock.
+ * @brief Subscribe a topic.
+ * @note This is internal function for AITT.
*/
-int nns_edge_aitt_publish (nns_edge_h edge_h, const void *data, const int length);
+int nns_edge_aitt_subscribe (nns_edge_aitt_h handle);
/**
- * @brief Subscribe a topic.
- * @note This is internal function for AITT. You should call this with edge-handle lock.
+ * @brief Set event callback for new message.
+ */
+int nns_edge_aitt_set_event_callback (nns_edge_aitt_h handle, nns_edge_event_cb cb, void *user_data);
+
+/**
+ * @brief Check whether aitt handle exists or not.
+ */
+int nns_edge_aitt_is_connected (nns_edge_aitt_h handle);
+
+/**
+ * @brief Internal util function to send edge-data.
*/
-int nns_edge_aitt_subscribe (nns_edge_h edge_h);
+int nns_edge_aitt_send_data (nns_edge_aitt_h handle, nns_edge_data_h data_h);
#else
#define nns_edge_aitt_connect(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
#define nns_edge_aitt_close(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
#define nns_edge_aitt_publish(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
#define nns_edge_aitt_subscribe(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
+#define nns_edge_aitt_set_event_callback(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
#define nns_edge_aitt_is_connected(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
+#define nns_edge_aitt_send_data(...) (NNS_EDGE_ERROR_NOT_SUPPORTED)
#endif /* ENABLE_AITT */
#ifdef __cplusplus
return NNS_EDGE_ERROR_NONE;
}
-/**
- * @brief Send edge command to connected device using AITT.
- */
-static int
-_nns_edge_cmd_send_aitt (nns_edge_handle_s * eh, nns_edge_data_h data_h)
-{
- int ret;
- void *data = NULL;
- nns_size_t size;
-
- if (!eh) {
- nns_edge_loge ("Failed to send command, edge handle is null.");
- return NNS_EDGE_ERROR_INVALID_PARAMETER;
- }
-
- ret = nns_edge_data_serialize (data_h, &data, &size);
- if (NNS_EDGE_ERROR_NONE != ret) {
- nns_edge_loge ("Failed to serialize the edge data.");
- goto done;
- }
-
- ret = nns_edge_aitt_publish (eh, data, size);
- if (NNS_EDGE_ERROR_NONE != ret) {
- nns_edge_loge ("Failed to send data to destination.");
- }
-
-done:
- nns_edge_free (data);
- return ret;
-}
-
/**
* @brief Receive edge command from connected device.
* @note Before calling this function, you should initialize edge-cmd by using _nns_edge_cmd_init().
}
break;
case NNS_EDGE_CONNECT_TYPE_AITT:
- _nns_edge_cmd_send_aitt (eh, data_h);
+ ret = nns_edge_aitt_send_data (eh->broker_h, data_h);
+ if (NNS_EDGE_ERROR_NONE != ret)
+ nns_edge_loge ("Failed to send data via AITT connection.");
break;
default:
break;
goto done;
}
} else if (NNS_EDGE_CONNECT_TYPE_AITT == eh->connect_type) {
- ret = nns_edge_aitt_connect (eh);
+ ret = nns_edge_aitt_connect (eh->id, eh->topic, eh->dest_host,
+ eh->dest_port, &eh->broker_h);
if (NNS_EDGE_ERROR_NONE != ret) {
nns_edge_loge ("Failed to connect to AITT broker.");
goto done;
}
+
+ ret = nns_edge_aitt_set_event_callback (eh->broker_h, eh->event_cb,
+ eh->user_data);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to set event callback to AITT broker.");
+ goto done;
+ }
}
}
if (NNS_EDGE_ERROR_NONE != nns_edge_mqtt_close (eh->broker_h)) {
nns_edge_logw ("Failed to close mqtt connection.");
}
- eh->broker_h = NULL;
break;
case NNS_EDGE_CONNECT_TYPE_AITT:
- if (NNS_EDGE_ERROR_NONE != nns_edge_aitt_close (eh)) {
+ if (NNS_EDGE_ERROR_NONE != nns_edge_aitt_close (eh->broker_h)) {
nns_edge_logw ("Failed to close AITT connection.");
}
break;
break;
}
+ /* Clear event callback and handles */
eh->magic = NNS_EDGE_MAGIC_DEAD;
eh->event_cb = NULL;
eh->user_data = NULL;
+ eh->broker_h = NULL;
nns_edge_queue_destroy (eh->send_queue);
eh->send_queue = NULL;
}
} while (TRUE);
} else if (NNS_EDGE_CONNECT_TYPE_AITT == eh->connect_type) {
- ret = nns_edge_aitt_connect (eh);
+ ret = nns_edge_aitt_connect (eh->id, eh->topic, dest_host, dest_port,
+ &eh->broker_h);
if (ret != NNS_EDGE_ERROR_NONE) {
- nns_edge_loge ("Failed to connect to aitt broker. %s:%d", dest_host,
+ nns_edge_loge ("Failed to connect to AITT broker. %s:%d", dest_host,
dest_port);
goto done;
}
- ret = nns_edge_aitt_subscribe (eh);
+
+ ret = nns_edge_aitt_set_event_callback (eh->broker_h, eh->event_cb,
+ eh->user_data);
+ if (NNS_EDGE_ERROR_NONE != ret) {
+ nns_edge_loge ("Failed to set event callback to AITT broker.");
+ goto done;
+ }
+
+ ret = nns_edge_aitt_subscribe (eh->broker_h);
if (NNS_EDGE_ERROR_NONE != ret) {
nns_edge_loge ("Failed to subscribe the topic using AITT: %s", eh->topic);
- SAFE_FREE (eh->broker_h);
- eh->broker_h = NULL;
goto done;
}
} else {
nns_edge_conn_s *conn;
if (NNS_EDGE_CONNECT_TYPE_AITT == eh->connect_type &&
- NNS_EDGE_ERROR_NONE == nns_edge_aitt_is_connected (eh))
+ NNS_EDGE_ERROR_NONE == nns_edge_aitt_is_connected (eh->broker_h))
return true;
conn_data = (nns_edge_conn_data_s *) eh->connections;
TEST(edgeAitt, connectInvalidParam1_n)
{
int ret = -1;
+ nns_edge_aitt_h handle;
if (!_check_mqtt_broker ())
return;
- ret = nns_edge_aitt_connect (NULL);
+ ret = nns_edge_aitt_connect (NULL, "temp-aitt-topic", "127.0.0.1", 1883, &handle);
+ EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
+
+ ret = nns_edge_aitt_connect ("", "temp-aitt-topic", "127.0.0.1", 1883, &handle);
EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
}
TEST(edgeAitt, connectInvalidParam2_n)
{
int ret = -1;
- nns_edge_h edge_h;
+ nns_edge_aitt_h handle;
if (!_check_mqtt_broker ())
return;
- ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
- NNS_EDGE_NODE_TYPE_PUB, &edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
- nns_edge_set_info (edge_h, "DEST_IP", "f.a.i.l");
- nns_edge_set_info (edge_h, "DEST_PORT", "1883");
- nns_edge_set_info (edge_h, "TOPIC", "AITT_TEST_TOPIC");
-
- ret = nns_edge_aitt_connect (edge_h);
+ ret = nns_edge_aitt_connect ("temp-aitt-id", NULL, "127.0.0.1", 1883, &handle);
EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
- ret = nns_edge_release_handle (edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
+ ret = nns_edge_aitt_connect ("temp-aitt-id", "", "127.0.0.1", 1883, &handle);
+ EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
}
/**
TEST(edgeAitt, connectInvalidParam3_n)
{
int ret = -1;
- nns_edge_h edge_h;
+ nns_edge_aitt_h handle;
if (!_check_mqtt_broker ())
return;
- ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
- NNS_EDGE_NODE_TYPE_PUB, &edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
- nns_edge_set_info (edge_h, "DEST_IP", "127.0.0.1");
- nns_edge_set_info (edge_h, "DEST_PORT", "0");
- nns_edge_set_info (edge_h, "TOPIC", "AITT_TEST_TOPIC");
-
- /** TOPIC is not set */
- ret = nns_edge_aitt_connect (edge_h);
+ ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", NULL, 1883, &handle);
EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
- ret = nns_edge_release_handle (edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
+ ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", "", 1883, &handle);
+ EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
}
/**
- * @brief Close the mqtt handle with invalid param.
+ * @brief Connect to the mqtt broker with invalid param.
*/
-TEST(edgeAitt, closeInvalidParam_n)
+TEST(edgeAitt, connectInvalidParam4_n)
{
int ret = -1;
+ nns_edge_aitt_h handle;
if (!_check_mqtt_broker ())
return;
- ret = nns_edge_aitt_close (NULL);
+ ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 0, &handle);
EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
}
/**
- * @brief Close the mqtt handle before the connection.
+ * @brief Connect to the mqtt broker with invalid param.
*/
-TEST(edgeAitt, closeInvalidParam2_n)
+TEST(edgeAitt, connectInvalidParam5_n)
{
int ret = -1;
- nns_edge_h edge_h;
if (!_check_mqtt_broker ())
return;
- ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
- NNS_EDGE_NODE_TYPE_PUB, &edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-
- ret = nns_edge_aitt_close (edge_h);
+ ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 1883, NULL);
EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
-
- ret = nns_edge_release_handle (edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
}
/**
- * @brief Publish with invalid param.
+ * @brief Close the mqtt handle with invalid param.
*/
-TEST(edgeAitt, publishInvalidParam_n)
+TEST(edgeAitt, closeInvalidParam_n)
{
int ret = -1;
- const char *msg = "TEMP_MESSAGE";
if (!_check_mqtt_broker ())
return;
- ret = nns_edge_aitt_publish (NULL, msg, strlen (msg) + 1);
+ ret = nns_edge_aitt_close (NULL);
EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
}
/**
* @brief Publish with invalid param.
*/
-TEST(edgeAitt, publishInvalidParam2_n)
+TEST(edgeAitt, publishInvalidParam_n)
{
int ret = -1;
- nns_edge_h edge_h;
const char *msg = "TEMP_MESSAGE";
if (!_check_mqtt_broker ())
return;
- ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
- NNS_EDGE_NODE_TYPE_PUB, &edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
- nns_edge_set_info (edge_h, "DEST_HOST", "127.0.0.1");
- nns_edge_set_info (edge_h, "DEST_PORT", "1883");
- nns_edge_set_info (edge_h, "TOPIC", "AITT_TEST_TOPIC");
-
- ret = nns_edge_start (edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-
- /* data is null */
- ret = nns_edge_aitt_publish (edge_h, NULL, strlen (msg) + 1);
+ ret = nns_edge_aitt_publish (NULL, msg, strlen (msg) + 1);
EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
-
- ret = nns_edge_release_handle (edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
}
/**
* @brief Publish with invalid param.
*/
-TEST(edgeAitt, publishInvalidParam3_n)
+TEST(edgeAitt, publishInvalidParam2_n)
{
int ret = -1;
- nns_edge_h edge_h;
+ nns_edge_aitt_h handle;
const char *msg = "TEMP_MESSAGE";
if (!_check_mqtt_broker ())
return;
- ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
- NNS_EDGE_NODE_TYPE_PUB, &edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
- nns_edge_set_info (edge_h, "DEST_HOST", "127.0.0.1");
- nns_edge_set_info (edge_h, "DEST_PORT", "1883");
- nns_edge_set_info (edge_h, "TOPIC", "AITT_TEST_TOPIC");
-
- ret = nns_edge_start (edge_h);
+ ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 1883, &handle);
EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
- /* data length is 0 */
- ret = nns_edge_aitt_publish (edge_h, msg, 0);
+ /* data is null */
+ ret = nns_edge_aitt_publish (handle, NULL, strlen (msg) + 1);
EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
- ret = nns_edge_release_handle (edge_h);
+ ret = nns_edge_aitt_close (handle);
EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
}
/**
- * @brief Publish the message without the connection.
+ * @brief Publish with invalid param.
*/
-TEST(edgeAitt, publishInvalidParam4_n)
+TEST(edgeAitt, publishInvalidParam3_n)
{
int ret = -1;
- nns_edge_h edge_h;
+ nns_edge_aitt_h handle;
const char *msg = "TEMP_MESSAGE";
if (!_check_mqtt_broker ())
return;
- ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
- NNS_EDGE_NODE_TYPE_PUB, &edge_h);
+ ret = nns_edge_aitt_connect ("temp-aitt-id", "temp-aitt-topic", "127.0.0.1", 1883, &handle);
EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
- nns_edge_set_info (edge_h, "DEST_HOST", "127.0.0.1");
- nns_edge_set_info (edge_h, "DEST_PORT", "1883");
- ret = nns_edge_aitt_publish (edge_h, msg, strlen (msg) + 1);
+ /* data length is 0 */
+ ret = nns_edge_aitt_publish (handle, msg, 0);
EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
- ret = nns_edge_release_handle (edge_h);
+ ret = nns_edge_aitt_close (handle);
EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
}
}
/**
- * @brief Subscribe the topic before the connection.
+ * @brief Check connection with invalid param.
*/
-TEST(edgeAitt, subscribeInvalidParam2_n)
+TEST(edgeAitt, checkConnectionInvalidParam_n)
{
int ret = -1;
- nns_edge_h edge_h;
if (!_check_mqtt_broker ())
return;
- ret = nns_edge_create_handle ("temp-server", NNS_EDGE_CONNECT_TYPE_AITT,
- NNS_EDGE_NODE_TYPE_SUB, &edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-
- nns_edge_set_info (edge_h, "DEST_HOST", "127.0.0.1");
- nns_edge_set_info (edge_h, "DEST_PORT", "1883");
- nns_edge_set_info (edge_h, "TOPIC", "AITT_TEST_TOPIC");
-
- ret = nns_edge_start (edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
-
- ret = nns_edge_aitt_subscribe (edge_h);
+ ret = nns_edge_aitt_is_connected (NULL);
EXPECT_NE (ret, NNS_EDGE_ERROR_NONE);
-
- ret = nns_edge_release_handle (edge_h);
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);
}
/**