11 static struct sync_flag a_reachable;
12 static struct sync_flag b_reachable;
14 static void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
21 if(!strcmp(node->name, "a")) {
22 set_sync_flag(&a_reachable, true);
23 } else if(!strcmp(node->name, "b")) {
24 set_sync_flag(&b_reachable, true);
29 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
31 init_sync_flag(&a_reachable);
32 init_sync_flag(&b_reachable);
34 meshlink_handle_t *mesh1, *mesh2;
35 open_meshlink_pair_ephemeral(&mesh1, &mesh2, "api_set_node_status_cb");
37 // Test case #1: check that setting a valid status callback will cause it to be called
38 // when the node itself is started or stopped
40 meshlink_set_node_status_cb(mesh1, status_cb);
41 assert(meshlink_start(mesh1));
42 assert(wait_sync_flag(&a_reachable, 5));
44 // Test case #2: check that the status callback will be called when another peer is started
46 assert(meshlink_start(mesh2));
47 assert(wait_sync_flag(&b_reachable, 5));
49 // Test case #3: check that passing a NULL pointer for the mesh returns an error
51 meshlink_errno = MESHLINK_OK;
52 meshlink_set_node_status_cb(NULL, status_cb);
53 assert(meshlink_errno == MESHLINK_EINVAL);
57 close_meshlink_pair(mesh1, mesh2);