From 005b8bd5f0f661d195428318e29ebab9d0d0dc43 Mon Sep 17 00:00:00 2001 From: Christof Schulze Date: Tue, 12 Nov 2019 21:22:24 +0100 Subject: [PATCH] gluon-mesh-babel: move code from handle_neighbour.c into neighbours-babel After refactoring the respondd module to work with a separate thread, handle_neighbour() is different in those two programs. A common implemenation thus is impossible and the structure is removed. --- package/gluon-mesh-babel/src/Makefile | 2 +- .../gluon-mesh-babel/src/handle_neighbour.c | 28 ------------------- .../gluon-mesh-babel/src/neighbours-babel.c | 24 +++++++++++++++- 3 files changed, 24 insertions(+), 30 deletions(-) delete mode 100644 package/gluon-mesh-babel/src/handle_neighbour.c diff --git a/package/gluon-mesh-babel/src/Makefile b/package/gluon-mesh-babel/src/Makefile index 28e6eca7..b458459a 100644 --- a/package/gluon-mesh-babel/src/Makefile +++ b/package/gluon-mesh-babel/src/Makefile @@ -27,5 +27,5 @@ LDFLAGS_JSONC = $(shell pkg-config --libs json-c) respondd.so: respondd.c $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -shared $(LDFLAGS_JSONC) -o $@ $^ -lgluonutil -lblobmsg_json -lubox -lubus -luci -neighbours-babel: neighbours-babel.c handle_neighbour.c +neighbours-babel: neighbours-babel.c $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_JSONC) $(LDFLAGS) $(LDLIBS) $(LDFLAGS_JSONC) -o $@ $^ diff --git a/package/gluon-mesh-babel/src/handle_neighbour.c b/package/gluon-mesh-babel/src/handle_neighbour.c deleted file mode 100644 index 950bfe45..00000000 --- a/package/gluon-mesh-babel/src/handle_neighbour.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include -#include "handle_neighbour.h" -#include - -bool handle_neighbour(char **data, void *arg) { - struct json_object *obj = (struct json_object*)arg; - - if (data[NEIGHBOUR]) { - struct json_object *neigh = json_object_new_object(); - - if (data[RXCOST]) - json_object_object_add(neigh, "rxcost", json_object_new_int(atoi(data[RXCOST]))); - if (data[TXCOST]) - json_object_object_add(neigh, "txcost", json_object_new_int(atoi(data[TXCOST]))); - if (data[COST]) - json_object_object_add(neigh, "cost", json_object_new_int(atoi(data[COST]))); - if (data[REACH]) - json_object_object_add(neigh, "reachability", json_object_new_double(strtod(data[REACH], NULL))); - if (data[IF]) - json_object_object_add(neigh, "ifname", json_object_new_string(data[IF])); - if (data[ADDRESS]) - json_object_object_add(obj, data[ADDRESS] , neigh); - } - return true; -} diff --git a/package/gluon-mesh-babel/src/neighbours-babel.c b/package/gluon-mesh-babel/src/neighbours-babel.c index 31f9c606..ea888586 100644 --- a/package/gluon-mesh-babel/src/neighbours-babel.c +++ b/package/gluon-mesh-babel/src/neighbours-babel.c @@ -2,8 +2,30 @@ #include #include #include +#include #include -#include "handle_neighbour.h" + +bool handle_neighbour(char **data, void *arg) { + struct json_object *obj = (struct json_object*)arg; + + if (data[NEIGHBOUR]) { + struct json_object *neigh = json_object_new_object(); + + if (data[RXCOST]) + json_object_object_add(neigh, "rxcost", json_object_new_int(atoi(data[RXCOST]))); + if (data[TXCOST]) + json_object_object_add(neigh, "txcost", json_object_new_int(atoi(data[TXCOST]))); + if (data[COST]) + json_object_object_add(neigh, "cost", json_object_new_int(atoi(data[COST]))); + if (data[REACH]) + json_object_object_add(neigh, "reachability", json_object_new_double(strtod(data[REACH], NULL))); + if (data[IF]) + json_object_object_add(neigh, "ifname", json_object_new_string(data[IF])); + if (data[ADDRESS]) + json_object_object_add(obj, data[ADDRESS] , neigh); + } + return true; +} int main(void) { struct json_object *neighbours;