From: Timo Kokkonen Date: Mon, 19 Nov 2012 20:12:09 +0000 (+0200) Subject: onewire_parser: Convert to a plugin X-Git-Url: http://git.itanic.dy.fi/?p=rrdd;a=commitdiff_plain;h=5e0df02c60a4ae7cc1606fcf3f4098b0e410de66 onewire_parser: Convert to a plugin Onewire parser is the only piece of code here that depends on libownet and requires linking against it. This is cumbersome whenever we wish to build rrdd and we are not interested in having support for onewire at all. Converting the parser to a plugin solves the issue: We can now build main rrdd without libownet dependency. Even if we have built the onewire parser, we don't need to load it unless we are actually using it. Signed-off-by: Timo Kokkonen --- diff --git a/Makefile b/Makefile index 677e88e..0f3d347 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,11 @@ LD=ld CFLAGS=-Wall -O2 -g -fPIC RRDD_OBJS= main.o process.o rrdtool.o parser.o built_in_parsers.o string.o \ - debug.o config.o onewire_parser.o plugin_manager.o + debug.o config.o plugin_manager.o -ALL_OBJS = $(RRDD_OBJS) +ONEWIRE_PARSER_OBJS = onewire_parser.o + +ALL_OBJS = $(RRDD_OBJS) $(ONEWIRE_PLUGIN_OBJS) ALL_DEBS = $(patsubst %.o,.%.o.d,$(ALL_OBJS)) ifeq ($(V),1) @@ -21,7 +23,10 @@ endif all: rrdd rrdd: $(RRDD_OBJS) - $(QUIET_LINK)$(CC) -o rrdd $(RRDD_OBJS) -lconfig -lownet -ldl -rdynamic + $(QUIET_LINK)$(CC) -o rrdd $(RRDD_OBJS) -lconfig -ldl -rdynamic + +onewire_parser.so: $(ONEWIRE_PARSER_OBJS) + $(QUIET_LINK)$(CC) $(CFLAGS) -lownet -shared -fPIC $< -o $@ clean: rm -vf rrdd *~ *.o .*.d *.so diff --git a/built_in_parsers.c b/built_in_parsers.c index f3a8c79..5ee045b 100644 --- a/built_in_parsers.c +++ b/built_in_parsers.c @@ -306,10 +306,6 @@ static struct parser_info built_in_parsers[] = { .name = "netstats", .parse = netstats_parser, }, - { - .name = "onewire", - .parse = onewire_parser, - }, }; int register_built_in_parsers(void) diff --git a/built_in_parsers.h b/built_in_parsers.h index 76b3a98..1702289 100644 --- a/built_in_parsers.h +++ b/built_in_parsers.h @@ -3,6 +3,4 @@ int register_built_in_parsers(void); -int onewire_parser(char *rrd_data, const char **parser_data); - #endif diff --git a/onewire_parser.c b/onewire_parser.c index f878b09..287fec1 100644 --- a/onewire_parser.c +++ b/onewire_parser.c @@ -5,8 +5,9 @@ #include "debug.h" #include "string.h" #include "utils.h" +#include "plugin.h" -int parse_opts(const char *str, char *ow_path, size_t pathlen, double *offset) +static int parse_opts(const char *str, char *ow_path, size_t pathlen, double *offset) { char *endptr; const char *start_str = str; @@ -44,7 +45,7 @@ int parse_opts(const char *str, char *ow_path, size_t pathlen, double *offset) return 0; } -int onewire_parser(char *rrd_data, const char **parser_data) +static int onewire_parser(char *rrd_data, const char **parser_data) { OWNET_HANDLE h; const char *server_addr; @@ -125,3 +126,18 @@ next: OWNET_finish(); return 0; } + +static struct parser_info onewire_parser_info = { + .name = "onewire", + .parse = onewire_parser, +}; + +static int init_onewire_parser(void) +{ + return register_parser(&onewire_parser_info); +} + +struct plugin_info plugin_info = { + .name = "onewire_parser", + .init = init_onewire_parser, +};