From: Niklas Hofmann Date: Wed, 13 Aug 2014 17:50:29 +0000 (+0200) Subject: json export of node and edge structure X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain;h=31ab43d8a0691e773db6992fa3b52ca24f7f8db4 json export of node and edge structure --- diff --git a/examples/manynodes.c b/examples/manynodes.c index 2e26739c..3b617e4e 100644 --- a/examples/manynodes.c +++ b/examples/manynodes.c @@ -7,6 +7,11 @@ #include #include "../src/meshlink.h" +#include "../src/devtools.h" + +#include +#include +#include static int n = 10; static meshlink_handle_t **mesh; @@ -62,6 +67,40 @@ static void linkmesh() { } } +static bool exportmeshgraph(const char* path) +{ + struct stat ps; + int psr = stat(path, &ps); + + if(psr == 0 || errno != ENOENT) + { + if(psr == -1) + { perror("stat"); } + else + { fprintf(stderr, "%s exists already\n", path); } + + return false; + } + + FILE* stream = fopen(path, "w"); + + if(!stream) + { + perror("stream"); + return false; + } + + if(!devtool_export_json_all_edges_state(mesh[0], stream)) + { + fclose(stream); + fprintf(stderr, "could not export graph\n"); + return false; + } + + fclose(stream); + return true; +} + static void parse_command(char *buf) { char *arg = strchr(buf, ' '); if(arg) @@ -131,6 +170,8 @@ static void parse_command(char *buf) { } } else if(!strcasecmp(buf, "link")) { linkmesh(); + } else if(!strcasecmp(buf, "eg")) { + exportmeshgraph(arg); } else if(!strcasecmp(buf, "test")) { testmesh(); } else if(!strcasecmp(buf, "quit")) { @@ -145,6 +186,7 @@ static void parse_command(char *buf) { "/kick Blacklist the given node.\n" "/who [] List all nodes or show information about the given node.\n" "/link Link all nodes together.\n" + "/eg Export graph as json file.\n" "/test Test functionality sending some data to all nodes\n" "/quit Exit this program.\n" ); diff --git a/src/Makefile.am b/src/Makefile.am index 0c681acb..cae2ab95 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -56,7 +56,7 @@ sptps_speed_SOURCES = \ lib_LTLIBRARIES = libmeshlink.la -libmeshlink_la_LDFLAGS = -export-symbols-regex '^meshlink_' +libmeshlink_la_LDFLAGS = -export-symbols-regex '^(meshlink_|devtool_)' libmeshlink_la_SOURCES = \ meshlink.c meshlink.h \ @@ -99,6 +99,7 @@ libmeshlink_la_SOURCES = \ system.h \ utils.c utils.h \ xalloc.h \ + devtools.c devtools.h \ $(ed25519_SOURCES) \ $(chacha_poly1305_SOURCES) diff --git a/src/meshlink.h b/src/meshlink.h index 16603f47..3d929073 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -96,6 +96,8 @@ struct meshlink_handle { struct meshlink_node { char *name; ///< Textual name of this node. It is stored in a nul-terminated C string, which is allocated by MeshLink. + uint32_t options; + dev_class_t devclass; void *priv; ///< Private pointer which may be set freely by the application, and is never used or modified by MeshLink. }; diff --git a/src/node.h b/src/node.h index b669b5da..c86c3cee 100644 --- a/src/node.h +++ b/src/node.h @@ -40,10 +40,9 @@ typedef struct node_status_t { typedef struct node_t { char *name; /* name of this node */ - void *priv; - uint32_t options; /* options turned on for this node */ dev_class_t devclass; + void *priv; struct meshlink_handle *mesh; /* The mesh this node belongs to */