8 void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) {
9 static struct timeval tv0;
13 gettimeofday(&tv0, NULL);
16 gettimeofday(&tv, NULL);
17 fprintf(stderr, "%u.%.03u ", (unsigned int)(tv.tv_sec - tv0.tv_sec), (unsigned int)tv.tv_usec / 1000);
20 fprintf(stderr, "(%s) ", mesh->name);
23 fprintf(stderr, "[%d] %s\n", level, text);
27 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
29 // Open a new meshlink instance.
31 meshlink_handle_t *mesh = meshlink_open("basic_conf", "foo", "basic", DEV_CLASS_BACKBONE);
34 fprintf(stderr, "Could not initialize configuration for foo\n");
38 meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb);
40 // Check that our own node exists.
42 meshlink_node_t *self = meshlink_get_self(mesh);
45 fprintf(stderr, "Foo does not know about itself\n");
49 if(strcmp(self->name, "foo")) {
50 fprintf(stderr, "Foo thinks its name is %s\n", self->name);
54 // Start and stop the mesh.
56 if(!meshlink_start(mesh)) {
57 fprintf(stderr, "Foo could not start\n");
63 // Make sure we can start and stop the mesh again.
65 if(!meshlink_start(mesh)) {
66 fprintf(stderr, "Foo could not start twice\n");
72 // Close the mesh and open it again, now with a different name parameter.
76 // Check that the name is ignored now, and that we still are "foo".
78 mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
81 fprintf(stderr, "Could not open configuration for foo a second time\n");
85 meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb);
87 if(meshlink_get_node(mesh, "bar")) {
88 fprintf(stderr, "Foo knows about bar, it shouldn't\n");
92 self = meshlink_get_self(mesh);
95 fprintf(stderr, "Foo doesn't know about itself the second time\n");
99 if(strcmp(self->name, "foo")) {
100 fprintf(stderr, "Foo thinks its name is %s the second time\n", self->name);
104 // Start and stop the mesh.
106 if(!meshlink_start(mesh)) {
107 fprintf(stderr, "Foo could not start a third time\n");
115 meshlink_close(mesh);
119 if(!meshlink_destroy("basic_conf")) {
120 fprintf(stderr, "Could not destroy configuration\n");
124 if(!access("basic_conf", F_OK) || errno != ENOENT) {
125 fprintf(stderr, "Configuration not fully destroyed\n");