8 volatile bool bar_reachable = false;
10 void status_cb(meshlink_handle_t *mesh, meshlink_node_t *node, bool reachable) {
11 if(!strcmp(node->name, "bar"))
12 bar_reachable = reachable;
15 int main(int argc, char *argv[]) {
16 // Open two new meshlink instance.
18 meshlink_handle_t *mesh1 = meshlink_open("import_export_conf.1", "foo");
20 fprintf(stderr, "Could not initialize configuration for foo\n");
24 meshlink_handle_t *mesh2 = meshlink_open("import_export_conf.2", "bar");
26 fprintf(stderr, "Could not initialize configuration for bar\n");
30 // Import and export both side's data
32 meshlink_add_address(mesh1, "localhost");
33 meshlink_add_address(mesh2, "localhost");
35 char *data = meshlink_export(mesh1);
37 fprintf(stderr, "Foo could not export its configuration\n");
41 if(!meshlink_import(mesh2, data)) {
42 fprintf(stderr, "Bar could not import foo's configuration\n");
48 data = meshlink_export(mesh2);
50 fprintf(stderr, "Bar could not export its configuration\n");
55 if(!meshlink_import(mesh1, data)) {
56 fprintf(stderr, "Foo could not import bar's configuration\n");
62 // Start both instances
64 meshlink_set_node_status_cb(mesh1, status_cb);
66 if(!meshlink_start(mesh1)) {
67 fprintf(stderr, "Foo could not start\n");
71 if(!meshlink_start(mesh2)) {
72 fprintf(stderr, "Bar could not start\n");
76 // Wait for the two to connect.
78 for(int i = 0; i < 20; i++) {
85 fprintf(stderr, "Bar not reachable for foo after 20 seconds\n");
93 meshlink_close(mesh2);
94 meshlink_close(mesh1);