*/\r
typedef struct\r
{\r
- GMainLoop *loop;\r
nns_edge_h handle;\r
bool running;\r
bool is_server;\r
_td = (ne_test_data_s *) calloc (1, sizeof (ne_test_data_s));\r
\r
if (_td) {\r
- _td->loop = g_main_loop_new (NULL, FALSE);\r
_td->is_server = is_server;\r
}\r
\r
if (!_td)\r
return;\r
\r
- if (_td->loop) {\r
- if (g_main_loop_is_running (_td->loop))\r
- g_main_loop_quit (_td->loop);\r
-\r
- g_main_loop_unref (_td->loop);\r
- _td->loop = NULL;\r
- }\r
-\r
free (_td);\r
}\r
\r
return NNS_EDGE_ERROR_NONE;\r
}\r
\r
-/**\r
- * @brief Edge thread for test.\r
- */\r
-static void *\r
-_test_edge_thread (void *data)\r
-{\r
- ne_test_data_s *_td = (ne_test_data_s *) data;\r
- int ret;\r
-\r
- ret = nns_edge_start (_td->handle);\r
- EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);\r
-\r
- _td->running = true;\r
- g_main_loop_run (_td->loop);\r
- _td->running = false;\r
-\r
- return NULL;\r
-}\r
-\r
/**\r
* @brief Connect to local host, multiple clients.\r
*/\r
nns_edge_h server_h, client1_h, client2_h;\r
ne_test_data_s *_td_server, *_td_client1, *_td_client2;\r
nns_edge_data_h data_h;\r
- pthread_t server_thread, client1_thread, client2_thread;\r
- pthread_attr_t attr;\r
size_t data_len;\r
void *data;\r
unsigned int i, retry;\r
nns_edge_set_info (client2_h, "CAPS", "test client2");\r
_td_client2->handle = client2_h;\r
\r
- /* Start server/client thread */\r
- pthread_attr_init (&attr);\r
- pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);\r
- pthread_create (&server_thread, &attr, _test_edge_thread, _td_server);\r
- pthread_create (&client1_thread, &attr, _test_edge_thread, _td_client1);\r
- pthread_create (&client2_thread, &attr, _test_edge_thread, _td_client2);\r
- pthread_attr_destroy (&attr);\r
-\r
- /* Wait for server/client thread */\r
- do {\r
- usleep (20000);\r
- } while (!g_main_loop_is_running (_td_server->loop));\r
+ ret = nns_edge_start (server_h);\r
+ EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);\r
+ ret = nns_edge_start (client1_h);\r
+ EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);\r
+ ret = nns_edge_start (client2_h);\r
+ EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);\r
\r
- do {\r
- usleep (20000);\r
- } while (!g_main_loop_is_running (_td_client1->loop));\r
-\r
- do {\r
- usleep (20000);\r
- } while (!g_main_loop_is_running (_td_client2->loop));\r
+ usleep (200000);\r
\r
ret = nns_edge_connect (client1_h, "127.0.0.1", port);\r
EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);\r
break;\r
} while (retry++ < 200U);\r
\r
- g_main_loop_quit (_td_server->loop);\r
- g_main_loop_quit (_td_client1->loop);\r
- g_main_loop_quit (_td_client2->loop);\r
-\r
ret = nns_edge_disconnect (server_h);\r
EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);\r
\r
nns_edge_h server_h, client_h;\r
ne_test_data_s *_td_server, *_td_client;\r
nns_edge_data_h data_h;\r
- pthread_t server_thread, client_thread;\r
- pthread_attr_t attr;\r
size_t data_len;\r
void *data;\r
unsigned int i, retry;\r
nns_edge_set_info (client_h, "TOPIC", "temp-mqtt-topic");\r
_td_client->handle = client_h;\r
\r
- /* Start server/client thread */\r
- pthread_attr_init (&attr);\r
- pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);\r
- pthread_create (&server_thread, &attr, _test_edge_thread, _td_server);\r
- pthread_create (&client_thread, &attr, _test_edge_thread, _td_client);\r
- pthread_attr_destroy (&attr);\r
-\r
- /* Wait for server/client thread */\r
- do {\r
- usleep (20000);\r
- } while (!g_main_loop_is_running (_td_server->loop));\r
+ ret = nns_edge_start (server_h);\r
+ EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);\r
+ ret = nns_edge_start (client_h);\r
+ EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);\r
\r
- do {\r
- usleep (20000);\r
- } while (!g_main_loop_is_running (_td_client->loop));\r
+ usleep (200000);\r
\r
ret = nns_edge_connect (client_h, "tcp://localhost", 1883);\r
EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);\r
break;\r
} while (retry++ < 200U);\r
\r
- g_main_loop_quit (_td_server->loop);\r
- g_main_loop_quit (_td_client->loop);\r
-\r
ret = nns_edge_release_handle (server_h);\r
EXPECT_EQ (ret, NNS_EDGE_ERROR_NONE);\r
ret = nns_edge_release_handle (client_h);\r