9 void log_cb(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *text) {
10 static struct timeval tv0;
14 gettimeofday(&tv0, NULL);
17 gettimeofday(&tv, NULL);
18 fprintf(stderr, "%u.%.03u ", (unsigned int)(tv.tv_sec - tv0.tv_sec), (unsigned int)tv.tv_usec / 1000);
21 fprintf(stderr, "(%s) ", mesh->name);
24 fprintf(stderr, "[%d] %s\n", level, text);
28 meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
30 // Open a new meshlink instance.
32 meshlink_handle_t *mesh = meshlink_open("basic_conf", "foo", "basic", DEV_CLASS_BACKBONE);
35 fprintf(stderr, "Could not initialize configuration for foo\n");
39 meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb);
41 // Check that our own node exists.
43 meshlink_node_t *self = meshlink_get_self(mesh);
46 fprintf(stderr, "Foo does not know about itself\n");
50 if(strcmp(self->name, "foo")) {
51 fprintf(stderr, "Foo thinks its name is %s\n", self->name);
55 // Start and stop the mesh.
57 if(!meshlink_start(mesh)) {
58 fprintf(stderr, "Foo could not start\n");
64 // Make sure we can start and stop the mesh again.
66 if(!meshlink_start(mesh)) {
67 fprintf(stderr, "Foo could not start twice\n");
73 // Close the mesh and open it again, now with a different name parameter.
77 // Check that the name is ignored now, and that we still are "foo".
79 mesh = meshlink_open("basic_conf", "bar", "basic", DEV_CLASS_BACKBONE);
82 fprintf(stderr, "Could not open configuration for foo a second time\n");
86 meshlink_set_log_cb(mesh, MESHLINK_DEBUG, log_cb);
88 if(meshlink_get_node(mesh, "bar")) {
89 fprintf(stderr, "Foo knows about bar, it shouldn't\n");
93 self = meshlink_get_self(mesh);
96 fprintf(stderr, "Foo doesn't know about itself the second time\n");
100 if(strcmp(self->name, "foo")) {
101 fprintf(stderr, "Foo thinks its name is %s the second time\n", self->name);
105 // Start and stop the mesh.
107 if(!meshlink_start(mesh)) {
108 fprintf(stderr, "Foo could not start a third time\n");
116 meshlink_close(mesh);
120 if(!meshlink_destroy("basic_conf")) {
121 fprintf(stderr, "Could not destroy configuration\n");
125 if(!access("basic_conf", F_OK) || errno != ENOENT) {
126 fprintf(stderr, "Configuration not fully destroyed\n");