seperated source and header files
This commit is contained in:
parent
d339266ac2
commit
d11ac57848
20 changed files with 360 additions and 176 deletions
|
@ -1,15 +1,15 @@
|
|||
AM_CFLAGS = -Wall -D_REENTRANT -std=gnu99 $(DEPS_VZ_CFLAGS)
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include -Iinclude
|
||||
|
||||
bin_PROGRAMS = vzlogger
|
||||
vzlogger_SOURCES = vzlogger.c channel.c api.c options.c list.c buffer.c
|
||||
vzlogger_LDADD = ../../src/libmeter.la ../../src/libobis.la
|
||||
vzlogger_SOURCES = src/vzlogger.c src/channel.c src/api.c src/options.c src/list.c src/buffer.c
|
||||
vzlogger_LDADD = $(top_srcdir)/src/libmeter.la $(top_srcdir)/src/libobis.la
|
||||
vzlogger_LDFLAGS = -lpthread -lm $(DEPS_VZ_LIBS)
|
||||
|
||||
# local interface support
|
||||
####################################################################
|
||||
if LOCAL_SUPPORT
|
||||
vzlogger_SOURCES += local.c
|
||||
vzlogger_SOURCES += src/local.c
|
||||
vzlogger_LDADD += $(DEPS_LOCAL_LIBS)
|
||||
AM_CFLAGS += $(DEPS_LOCAL_CFLAGS)
|
||||
endif
|
|
@ -38,7 +38,7 @@ bin_PROGRAMS = vzlogger$(EXEEXT)
|
|||
|
||||
# local interface support
|
||||
####################################################################
|
||||
@LOCAL_SUPPORT_TRUE@am__append_1 = local.c
|
||||
@LOCAL_SUPPORT_TRUE@am__append_1 = src/local.c
|
||||
@LOCAL_SUPPORT_TRUE@am__append_2 = $(DEPS_LOCAL_LIBS)
|
||||
@LOCAL_SUPPORT_TRUE@am__append_3 = $(DEPS_LOCAL_CFLAGS)
|
||||
|
||||
|
@ -46,7 +46,7 @@ bin_PROGRAMS = vzlogger$(EXEEXT)
|
|||
####################################################################
|
||||
@SML_SUPPORT_TRUE@am__append_4 = $(DEPS_SML_LIBS)
|
||||
@SML_SUPPORT_TRUE@am__append_5 = $(DEPS_SML_CFLAGS)
|
||||
subdir = bin/vzlogger
|
||||
subdir = bin/logger
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
|
||||
|
@ -58,8 +58,8 @@ CONFIG_CLEAN_FILES =
|
|||
CONFIG_CLEAN_VPATH_FILES =
|
||||
am__installdirs = "$(DESTDIR)$(bindir)"
|
||||
PROGRAMS = $(bin_PROGRAMS)
|
||||
am__vzlogger_SOURCES_DIST = vzlogger.c channel.c api.c options.c \
|
||||
list.c buffer.c local.c
|
||||
am__vzlogger_SOURCES_DIST = src/vzlogger.c src/channel.c src/api.c \
|
||||
src/options.c src/list.c src/buffer.c src/local.c
|
||||
@LOCAL_SUPPORT_TRUE@am__objects_1 = local.$(OBJEXT)
|
||||
am_vzlogger_OBJECTS = vzlogger.$(OBJEXT) channel.$(OBJEXT) \
|
||||
api.$(OBJEXT) options.$(OBJEXT) list.$(OBJEXT) \
|
||||
|
@ -68,8 +68,9 @@ vzlogger_OBJECTS = $(am_vzlogger_OBJECTS)
|
|||
am__DEPENDENCIES_1 =
|
||||
@LOCAL_SUPPORT_TRUE@am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1)
|
||||
@SML_SUPPORT_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1)
|
||||
vzlogger_DEPENDENCIES = ../../src/libmeter.la ../../src/libobis.la \
|
||||
$(am__DEPENDENCIES_2) $(am__DEPENDENCIES_3)
|
||||
vzlogger_DEPENDENCIES = $(top_srcdir)/src/libmeter.la \
|
||||
$(top_srcdir)/src/libobis.la $(am__DEPENDENCIES_2) \
|
||||
$(am__DEPENDENCIES_3)
|
||||
vzlogger_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(vzlogger_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
|
@ -215,11 +216,11 @@ top_builddir = @top_builddir@
|
|||
top_srcdir = @top_srcdir@
|
||||
AM_CFLAGS = -Wall -D_REENTRANT -std=gnu99 $(DEPS_VZ_CFLAGS) \
|
||||
$(am__append_3) $(am__append_5)
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include
|
||||
vzlogger_SOURCES = vzlogger.c channel.c api.c options.c list.c \
|
||||
buffer.c $(am__append_1)
|
||||
vzlogger_LDADD = ../../src/libmeter.la ../../src/libobis.la \
|
||||
$(am__append_2) $(am__append_4)
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include -Iinclude
|
||||
vzlogger_SOURCES = src/vzlogger.c src/channel.c src/api.c \
|
||||
src/options.c src/list.c src/buffer.c $(am__append_1)
|
||||
vzlogger_LDADD = $(top_srcdir)/src/libmeter.la \
|
||||
$(top_srcdir)/src/libobis.la $(am__append_2) $(am__append_4)
|
||||
vzlogger_LDFLAGS = -lpthread -lm $(DEPS_VZ_LIBS)
|
||||
all: all-am
|
||||
|
||||
|
@ -234,9 +235,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
|||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu bin/vzlogger/Makefile'; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu bin/logger/Makefile'; \
|
||||
$(am__cd) $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu bin/vzlogger/Makefile
|
||||
$(AUTOMAKE) --gnu bin/logger/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
|
@ -337,6 +338,104 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
vzlogger.o: src/vzlogger.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT vzlogger.o -MD -MP -MF $(DEPDIR)/vzlogger.Tpo -c -o vzlogger.o `test -f 'src/vzlogger.c' || echo '$(srcdir)/'`src/vzlogger.c
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/vzlogger.Tpo $(DEPDIR)/vzlogger.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/vzlogger.c' object='vzlogger.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o vzlogger.o `test -f 'src/vzlogger.c' || echo '$(srcdir)/'`src/vzlogger.c
|
||||
|
||||
vzlogger.obj: src/vzlogger.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT vzlogger.obj -MD -MP -MF $(DEPDIR)/vzlogger.Tpo -c -o vzlogger.obj `if test -f 'src/vzlogger.c'; then $(CYGPATH_W) 'src/vzlogger.c'; else $(CYGPATH_W) '$(srcdir)/src/vzlogger.c'; fi`
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/vzlogger.Tpo $(DEPDIR)/vzlogger.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/vzlogger.c' object='vzlogger.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o vzlogger.obj `if test -f 'src/vzlogger.c'; then $(CYGPATH_W) 'src/vzlogger.c'; else $(CYGPATH_W) '$(srcdir)/src/vzlogger.c'; fi`
|
||||
|
||||
channel.o: src/channel.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT channel.o -MD -MP -MF $(DEPDIR)/channel.Tpo -c -o channel.o `test -f 'src/channel.c' || echo '$(srcdir)/'`src/channel.c
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/channel.Tpo $(DEPDIR)/channel.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/channel.c' object='channel.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o channel.o `test -f 'src/channel.c' || echo '$(srcdir)/'`src/channel.c
|
||||
|
||||
channel.obj: src/channel.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT channel.obj -MD -MP -MF $(DEPDIR)/channel.Tpo -c -o channel.obj `if test -f 'src/channel.c'; then $(CYGPATH_W) 'src/channel.c'; else $(CYGPATH_W) '$(srcdir)/src/channel.c'; fi`
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/channel.Tpo $(DEPDIR)/channel.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/channel.c' object='channel.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o channel.obj `if test -f 'src/channel.c'; then $(CYGPATH_W) 'src/channel.c'; else $(CYGPATH_W) '$(srcdir)/src/channel.c'; fi`
|
||||
|
||||
api.o: src/api.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT api.o -MD -MP -MF $(DEPDIR)/api.Tpo -c -o api.o `test -f 'src/api.c' || echo '$(srcdir)/'`src/api.c
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/api.Tpo $(DEPDIR)/api.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/api.c' object='api.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o api.o `test -f 'src/api.c' || echo '$(srcdir)/'`src/api.c
|
||||
|
||||
api.obj: src/api.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT api.obj -MD -MP -MF $(DEPDIR)/api.Tpo -c -o api.obj `if test -f 'src/api.c'; then $(CYGPATH_W) 'src/api.c'; else $(CYGPATH_W) '$(srcdir)/src/api.c'; fi`
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/api.Tpo $(DEPDIR)/api.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/api.c' object='api.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o api.obj `if test -f 'src/api.c'; then $(CYGPATH_W) 'src/api.c'; else $(CYGPATH_W) '$(srcdir)/src/api.c'; fi`
|
||||
|
||||
options.o: src/options.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.o -MD -MP -MF $(DEPDIR)/options.Tpo -c -o options.o `test -f 'src/options.c' || echo '$(srcdir)/'`src/options.c
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/options.Tpo $(DEPDIR)/options.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/options.c' object='options.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.o `test -f 'src/options.c' || echo '$(srcdir)/'`src/options.c
|
||||
|
||||
options.obj: src/options.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT options.obj -MD -MP -MF $(DEPDIR)/options.Tpo -c -o options.obj `if test -f 'src/options.c'; then $(CYGPATH_W) 'src/options.c'; else $(CYGPATH_W) '$(srcdir)/src/options.c'; fi`
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/options.Tpo $(DEPDIR)/options.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/options.c' object='options.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o options.obj `if test -f 'src/options.c'; then $(CYGPATH_W) 'src/options.c'; else $(CYGPATH_W) '$(srcdir)/src/options.c'; fi`
|
||||
|
||||
list.o: src/list.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT list.o -MD -MP -MF $(DEPDIR)/list.Tpo -c -o list.o `test -f 'src/list.c' || echo '$(srcdir)/'`src/list.c
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/list.Tpo $(DEPDIR)/list.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/list.c' object='list.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o list.o `test -f 'src/list.c' || echo '$(srcdir)/'`src/list.c
|
||||
|
||||
list.obj: src/list.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT list.obj -MD -MP -MF $(DEPDIR)/list.Tpo -c -o list.obj `if test -f 'src/list.c'; then $(CYGPATH_W) 'src/list.c'; else $(CYGPATH_W) '$(srcdir)/src/list.c'; fi`
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/list.Tpo $(DEPDIR)/list.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/list.c' object='list.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o list.obj `if test -f 'src/list.c'; then $(CYGPATH_W) 'src/list.c'; else $(CYGPATH_W) '$(srcdir)/src/list.c'; fi`
|
||||
|
||||
buffer.o: src/buffer.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT buffer.o -MD -MP -MF $(DEPDIR)/buffer.Tpo -c -o buffer.o `test -f 'src/buffer.c' || echo '$(srcdir)/'`src/buffer.c
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/buffer.Tpo $(DEPDIR)/buffer.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/buffer.c' object='buffer.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o buffer.o `test -f 'src/buffer.c' || echo '$(srcdir)/'`src/buffer.c
|
||||
|
||||
buffer.obj: src/buffer.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT buffer.obj -MD -MP -MF $(DEPDIR)/buffer.Tpo -c -o buffer.obj `if test -f 'src/buffer.c'; then $(CYGPATH_W) 'src/buffer.c'; else $(CYGPATH_W) '$(srcdir)/src/buffer.c'; fi`
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/buffer.Tpo $(DEPDIR)/buffer.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/buffer.c' object='buffer.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o buffer.obj `if test -f 'src/buffer.c'; then $(CYGPATH_W) 'src/buffer.c'; else $(CYGPATH_W) '$(srcdir)/src/buffer.c'; fi`
|
||||
|
||||
local.o: src/local.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT local.o -MD -MP -MF $(DEPDIR)/local.Tpo -c -o local.o `test -f 'src/local.c' || echo '$(srcdir)/'`src/local.c
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/local.Tpo $(DEPDIR)/local.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/local.c' object='local.o' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o local.o `test -f 'src/local.c' || echo '$(srcdir)/'`src/local.c
|
||||
|
||||
local.obj: src/local.c
|
||||
@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT local.obj -MD -MP -MF $(DEPDIR)/local.Tpo -c -o local.obj `if test -f 'src/local.c'; then $(CYGPATH_W) 'src/local.c'; else $(CYGPATH_W) '$(srcdir)/src/local.c'; fi`
|
||||
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/local.Tpo $(DEPDIR)/local.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/local.c' object='local.obj' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o local.obj `if test -f 'src/local.c'; then $(CYGPATH_W) 'src/local.c'; else $(CYGPATH_W) '$(srcdir)/src/local.c'; fi`
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
|
@ -42,8 +42,8 @@ typedef struct {
|
|||
int curl_custom_debug_callback(CURL *curl, curl_infotype type, char *data, size_t size, void *custom);
|
||||
size_t curl_custom_write_callback(void *ptr, size_t size, size_t nmemb, void *data);
|
||||
|
||||
json_object * api_json_tuples(buffer_t *buf, meter_reading_t *start);
|
||||
void * api_thread(void *arg);
|
||||
json_object * api_json_tuples(buffer_t *buf, meter_reading_t *first, meter_reading_t *last);
|
||||
void * logging_thread(void *arg);
|
||||
double api_tvtof(struct timeval tv);
|
||||
|
||||
#endif /* _API_H_ */
|
|
@ -34,19 +34,19 @@
|
|||
#include <reading.h>
|
||||
|
||||
typedef struct {
|
||||
meter_reading_t *last;
|
||||
meter_reading_t *last; /* the oldest reading NOT sent */
|
||||
meter_reading_t *start;
|
||||
meter_reading_t *sent;
|
||||
|
||||
int size; /* number of readings currently in the buffer */
|
||||
int memory; /* number of readings to keep in mind for local interface */
|
||||
int keep; /* number of readings to cache for local interface */
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
} buffer_t;
|
||||
|
||||
/* Prototypes */
|
||||
void buffer_init(buffer_t *buf, int mem);
|
||||
int buffer_push(buffer_t *buf, meter_reading_t rd);
|
||||
void buffer_init(buffer_t *buf, int keep);
|
||||
meter_reading_t * buffer_push(buffer_t *buf, meter_reading_t rd);
|
||||
void buffer_free(buffer_t *buf);
|
||||
void buffer_clean(buffer_t *buf);
|
||||
void buffer_clear(buffer_t *buf);
|
|
@ -55,6 +55,6 @@ typedef struct channel {
|
|||
void channel_init(channel_t *ch, char *uuid, char *middleware, unsigned long interval, char *options, meter_type_t *type);
|
||||
void channel_free(channel_t *ch);
|
||||
|
||||
void reading_thread(void *arg);
|
||||
void * reading_thread(void *arg);
|
||||
|
||||
#endif /* _CHANNEL_H_ */
|
|
@ -35,8 +35,8 @@
|
|||
/* some hard coded configuration */
|
||||
#define RETRY_PAUSE 10 //600 /* seconds to wait after failed request */
|
||||
#define BUFFER_DURATION 60 /* in seconds */
|
||||
#define BUFFER_LENGTH 256 /* in readings */
|
||||
#define COMET_TIMEOUT 30 /* seconds */
|
||||
#define BUFFER_LENGTH 10 // 256 /* in readings */
|
||||
#define COMET_TIMEOUT 6 //30 /* in seconds */
|
||||
|
||||
/* Prototypes */
|
||||
void print(int level, char *format, channel_t *ch, ... );
|
|
@ -96,17 +96,19 @@ double api_tvtof(struct timeval tv) {
|
|||
* Create JSON object of tuples
|
||||
*
|
||||
* @param buf the buffer our readings are stored in (required for mutex)
|
||||
* @param start the first tuple of our linked list which should be encoded
|
||||
* @param first the first tuple of our linked list which should be encoded
|
||||
* @param last the last tuple of our linked list which should be encoded
|
||||
*/
|
||||
json_object * api_json_tuples(buffer_t *buf, meter_reading_t *start) {
|
||||
json_object * api_json_tuples(buffer_t *buf, meter_reading_t *first, meter_reading_t *last) {
|
||||
json_object *json_tuples = json_object_new_array();
|
||||
meter_reading_t *it;
|
||||
|
||||
for (meter_reading_t *rd = start; rd != NULL; rd = rd->next) {
|
||||
for (it = first; it != last->next; it = it->next) {
|
||||
struct json_object *json_tuple = json_object_new_array();
|
||||
|
||||
pthread_mutex_lock(&buf->mutex);
|
||||
double timestamp = api_tvtof(rd->tv); // TODO use long int of new json-c version
|
||||
double value = rd->value;
|
||||
double timestamp = api_tvtof(it->tv); // TODO use long int of new json-c version
|
||||
double value = it->value;
|
||||
pthread_mutex_unlock(&buf->mutex);
|
||||
|
||||
json_object_array_add(json_tuple, json_object_new_double(timestamp));
|
||||
|
@ -179,15 +181,27 @@ void api_parse_exception(CURLresponse response, char *err) {
|
|||
*
|
||||
* Logs buffered readings against middleware
|
||||
*/
|
||||
void * api_thread(void *arg) {
|
||||
void logging_thread_cleanup(void *arg) {
|
||||
curl_easy_cleanup((CURL *) arg); /* always cleanup */
|
||||
}
|
||||
|
||||
void * logging_thread(void *arg) {
|
||||
CURL *curl;
|
||||
channel_t *ch = (channel_t *) arg; /* casting argument */
|
||||
|
||||
/* we don't to log in local only mode */
|
||||
if (opts.local && !opts.daemon) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
curl = api_curl_init(ch);
|
||||
pthread_cleanup_push(&logging_thread_cleanup, curl);
|
||||
|
||||
while (TRUE) { /* start thread mainloop */
|
||||
do { /* start thread mainloop */
|
||||
CURLresponse response;
|
||||
json_object *json_obj;
|
||||
meter_reading_t *last;
|
||||
|
||||
const char *json_str;
|
||||
long int http_code, curl_code;
|
||||
|
||||
|
@ -201,7 +215,8 @@ void * api_thread(void *arg) {
|
|||
}
|
||||
pthread_mutex_unlock(&ch->buffer.mutex);
|
||||
|
||||
json_obj = api_json_tuples(&ch->buffer, ch->buffer.sent);
|
||||
last = ch->buffer.last;
|
||||
json_obj = api_json_tuples(&ch->buffer, ch->buffer.sent, last);
|
||||
json_str = json_object_to_json_string(json_obj);
|
||||
|
||||
print(10, "JSON request body: %s", ch, json_str);
|
||||
|
@ -216,7 +231,7 @@ void * api_thread(void *arg) {
|
|||
/* check response */
|
||||
if (curl_code == CURLE_OK && http_code == 200) { /* everything is ok */
|
||||
print(4, "Request succeeded with code: %i", ch, http_code);
|
||||
ch->buffer.sent = NULL;
|
||||
ch->buffer.sent = last->next;
|
||||
}
|
||||
else { /* error */
|
||||
if (curl_code != CURLE_OK) {
|
||||
|
@ -233,16 +248,13 @@ void * api_thread(void *arg) {
|
|||
free(response.data);
|
||||
json_object_put(json_obj);
|
||||
|
||||
if (!opts.daemon) {
|
||||
break;
|
||||
}
|
||||
else if (curl_code != CURLE_OK || http_code != 200) {
|
||||
if (opts.daemon && (curl_code != CURLE_OK || http_code != 200)) {
|
||||
print(2, "Sleeping %i seconds due to previous failure", ch, RETRY_PAUSE);
|
||||
sleep(RETRY_PAUSE);
|
||||
}
|
||||
}
|
||||
|
||||
curl_easy_cleanup(curl); /* always cleanup */
|
||||
} while (opts.daemon);
|
||||
|
||||
pthread_cleanup_pop(1);
|
||||
|
||||
return NULL;
|
||||
}
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include "buffer.h"
|
||||
|
||||
void buffer_init(buffer_t *buf, int mem) {
|
||||
void buffer_init(buffer_t *buf, int keep) {
|
||||
pthread_mutex_init(&buf->mutex, NULL);
|
||||
|
||||
pthread_mutex_lock(&buf->mutex);
|
||||
|
@ -39,44 +39,54 @@ void buffer_init(buffer_t *buf, int mem) {
|
|||
buf->start = NULL;
|
||||
buf->sent = NULL;
|
||||
buf->size = 0;
|
||||
buf->memory = mem;
|
||||
buf->keep = keep;
|
||||
pthread_mutex_unlock(&buf->mutex);
|
||||
}
|
||||
|
||||
int buffer_push(buffer_t *buf, meter_reading_t rd) {
|
||||
meter_reading_t *new = malloc(sizeof(meter_reading_t));
|
||||
meter_reading_t * buffer_push(buffer_t *buf, meter_reading_t rd) {
|
||||
meter_reading_t *new;
|
||||
|
||||
/* allocate memory for new reading */
|
||||
new = malloc(sizeof(meter_reading_t));
|
||||
|
||||
if (!new) {
|
||||
return 0; /* cannot allocate memory */
|
||||
/* cannot allocate memory */
|
||||
if (new == NULL) {
|
||||
/* => delete old readings (ring buffer) */
|
||||
if (buf->size > 0) {
|
||||
pthread_mutex_lock(&buf->mutex);
|
||||
new = buf->start;
|
||||
buf->start = new->next;
|
||||
buf->size--;
|
||||
pthread_mutex_unlock(&buf->mutex);
|
||||
}
|
||||
else { /* giving up :-( */
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(new, &rd, sizeof(meter_reading_t));
|
||||
|
||||
pthread_mutex_lock(&buf->mutex);
|
||||
if (buf->last == NULL) { /* empty buffer */
|
||||
if (buf->size == 0) { /* empty buffer */
|
||||
buf->start = new;
|
||||
}
|
||||
else {
|
||||
buf->last->next = new;
|
||||
}
|
||||
|
||||
if (buf->sent == NULL) { /* add reading to send queue */
|
||||
buf->sent = new;
|
||||
}
|
||||
|
||||
new->next = NULL;
|
||||
|
||||
buf->last = new;
|
||||
buf->size++;
|
||||
|
||||
pthread_mutex_unlock(&buf->mutex);
|
||||
|
||||
buffer_clean(buf);
|
||||
|
||||
return buf->size;
|
||||
return new;
|
||||
}
|
||||
|
||||
void buffer_clean(buffer_t *buf) {
|
||||
pthread_mutex_lock(&buf->mutex);
|
||||
while(buf->size > buf->memory && buf->start != buf->sent) {
|
||||
while(buf->size > buf->keep && buf->start != buf->sent) {
|
||||
meter_reading_t *pop = buf->start;
|
||||
|
||||
buf->start = buf->start->next;
|
|
@ -34,14 +34,29 @@
|
|||
|
||||
extern options_t opts;
|
||||
|
||||
void reading_thread(void *arg) {
|
||||
void * reading_thread(void *arg) {
|
||||
channel_t *ch = (channel_t *) arg;
|
||||
|
||||
while (1) {
|
||||
meter_reading_t rd = meter_read(&ch->meter);
|
||||
do { /* start thread main loop */
|
||||
meter_reading_t rd, *added;
|
||||
|
||||
rd = meter_read(&ch->meter);
|
||||
print(1, "Value read: %.2f at %.0f", ch, rd.value, api_tvtof(rd.tv));
|
||||
|
||||
buffer_push(&ch->buffer, rd);
|
||||
/* add reading to buffer */
|
||||
added = buffer_push(&ch->buffer, rd);
|
||||
|
||||
if ( /* queue reading into sending queue if... */
|
||||
added /* we got it in the buffer */
|
||||
&& ch->buffer.sent == NULL /* there are no other readings pending in queue */
|
||||
&& (opts.daemon || !opts.local) /* we aren't in local only mode */
|
||||
) {
|
||||
ch->buffer.sent = added;
|
||||
}
|
||||
|
||||
/* shrink buffer */
|
||||
buffer_clean(&ch->buffer);
|
||||
|
||||
pthread_mutex_lock(&ch->buffer.mutex);
|
||||
pthread_cond_broadcast(&ch->condition); /* notify webserver and logging thread */
|
||||
pthread_mutex_unlock(&ch->buffer.mutex);
|
||||
|
@ -50,20 +65,33 @@ void reading_thread(void *arg) {
|
|||
if (opts.verbose >= 10) {
|
||||
char dump[1024];
|
||||
buffer_dump(&ch->buffer, dump, 1024);
|
||||
print(10, "Buffer dump: %s (size=%i, memory=%i)", ch, dump, ch->buffer.size, ch->buffer.memory);
|
||||
print(10, "Buffer dump: %s (size=%i, memory=%i)", ch, dump, ch->buffer.size, ch->buffer.keep);
|
||||
}
|
||||
|
||||
if (ch->meter.type->periodical) {
|
||||
if ((opts.daemon || opts.local) && ch->meter.type->periodical) {
|
||||
print(8, "Next reading in %i seconds", ch, ch->interval);
|
||||
sleep(ch->interval);
|
||||
}
|
||||
}
|
||||
} while (opts.daemon || opts.local);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void channel_init(channel_t *ch, char *uuid, char *middleware, unsigned long interval, char *options, meter_type_t *type) {
|
||||
static int instances; /* static to generate channel ids */
|
||||
|
||||
int buffer_size = (type->periodical) ? (BUFFER_DURATION / interval) + 1 : BUFFER_LENGTH;
|
||||
int keep; /* number of readings to cache for local interface */
|
||||
if (opts.local) {
|
||||
if (type->periodical) {
|
||||
keep = (BUFFER_DURATION / interval) + 1; /* determine cache length by interval */
|
||||
}
|
||||
else {
|
||||
keep = BUFFER_LENGTH; /* fixed cache length for meters */
|
||||
}
|
||||
}
|
||||
else {
|
||||
keep = 0; /* don't cache if we have no HTTPd started */
|
||||
}
|
||||
|
||||
ch->id = instances++;
|
||||
ch->interval = interval;
|
||||
|
@ -72,7 +100,7 @@ void channel_init(channel_t *ch, char *uuid, char *middleware, unsigned long int
|
|||
ch->options = strdup(options);
|
||||
|
||||
meter_init(&ch->meter, type, options);
|
||||
buffer_init(&ch->buffer, buffer_size); /* initialize buffer */
|
||||
buffer_init(&ch->buffer, keep); /* initialize buffer */
|
||||
|
||||
pthread_cond_init(&ch->condition, NULL); /* initialize thread syncronization helpers */
|
||||
}
|
110
bin/logger/src/local.c
Normal file
110
bin/logger/src/local.c
Normal file
|
@ -0,0 +1,110 @@
|
|||
/**
|
||||
* Implementation of local interface via libmicrohttpd
|
||||
*
|
||||
* @package vzlogger
|
||||
* @copyright Copyright (c) 2011, The volkszaehler.org project
|
||||
* @license http://www.gnu.org/licenses/gpl.txt GNU Public License
|
||||
* @author Steffen Vogel <info@steffenvogel.de>
|
||||
*/
|
||||
/*
|
||||
* This file is part of volkzaehler.org
|
||||
*
|
||||
* volkzaehler.org is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* volkzaehler.org is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <json/json.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "vzlogger.h"
|
||||
#include "local.h"
|
||||
#include "options.h"
|
||||
#include "api.h"
|
||||
|
||||
extern list_t chans;
|
||||
extern options_t opts;
|
||||
|
||||
int handle_request(void *cls, struct MHD_Connection *connection, const char *url, const char *method,
|
||||
const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) {
|
||||
|
||||
const char *mode;
|
||||
int ret, http_status = MHD_HTTP_NOT_FOUND;
|
||||
struct MHD_Response *response;
|
||||
|
||||
print(2, "Local request received: %s %s %s", NULL, version, method, url);
|
||||
|
||||
mode = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "mode");
|
||||
|
||||
if (strcmp(method, "GET") == 0) {
|
||||
struct timespec ts;
|
||||
struct timeval tp;
|
||||
|
||||
struct json_object *json_obj = json_object_new_object();
|
||||
struct json_object *json_data = json_object_new_object();
|
||||
|
||||
const char *uuid = url+1;
|
||||
const char *json_str;
|
||||
|
||||
for (channel_t *ch = chans.start; ch != NULL; ch = ch->next) {
|
||||
if (strcmp(url, "/") == 0 || strcmp(ch->uuid, uuid) == 0) {
|
||||
http_status = MHD_HTTP_OK;
|
||||
|
||||
/* convert from timeval to timespec */
|
||||
gettimeofday(&tp, NULL);
|
||||
ts.tv_sec = tp.tv_sec;
|
||||
ts.tv_nsec = tp.tv_usec * 1000;
|
||||
|
||||
ts.tv_sec += (ch->meter.type->periodical) ? ch->interval : COMET_TIMEOUT;
|
||||
|
||||
if (strcmp(url, "/") != 0 && mode && strcmp(mode, "comet") == 0) {
|
||||
/* blocking until new data arrives (comet-like blocking of HTTP response) */
|
||||
pthread_mutex_lock(&ch->buffer.mutex);
|
||||
pthread_cond_timedwait(&ch->condition, &ch->buffer.mutex, &ts);
|
||||
pthread_mutex_unlock(&ch->buffer.mutex);
|
||||
}
|
||||
|
||||
json_object_object_add(json_data, "uuid", json_object_new_string(ch->uuid));
|
||||
json_object_object_add(json_data, "interval", json_object_new_int(ch->interval));
|
||||
|
||||
struct json_object *json_tuples = api_json_tuples(&ch->buffer, ch->buffer.start, ch->buffer.last);
|
||||
json_object_object_add(json_data, "tuples", json_tuples);
|
||||
}
|
||||
}
|
||||
|
||||
json_object_object_add(json_obj, "version", json_object_new_string(VERSION));
|
||||
json_object_object_add(json_obj, "generator", json_object_new_string(PACKAGE));
|
||||
json_object_object_add(json_obj, "data", json_data);
|
||||
|
||||
json_str = json_object_to_json_string(json_obj);
|
||||
response = MHD_create_response_from_data(strlen(json_str), (void *) json_str, FALSE, TRUE);
|
||||
json_object_put(json_obj);
|
||||
|
||||
MHD_add_response_header(response, "Content-type", "application/json");
|
||||
}
|
||||
else {
|
||||
char *response_str = strdup("not implemented\n");
|
||||
response = MHD_create_response_from_data(strlen(response_str), (void *) response_str, TRUE, FALSE);
|
||||
|
||||
http_status = MHD_HTTP_METHOD_NOT_ALLOWED;
|
||||
MHD_add_response_header(response, "Content-type", "text/text");
|
||||
}
|
||||
|
||||
|
||||
ret = MHD_queue_response(connection, http_status, response);
|
||||
|
||||
MHD_destroy_response(response);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
extern meter_type_t meter_types[];
|
||||
|
||||
options_t opts = { /* setting default options */
|
||||
const options_t opts = { /* setting default options */
|
||||
"/etc/vzlogger.conf", /* config file */
|
||||
8080, /* port for local interface */
|
||||
0, /* verbosity level */
|
||||
|
@ -51,7 +51,7 @@ options_t opts = { /* setting default options */
|
|||
/**
|
||||
* Command line options
|
||||
*/
|
||||
struct option long_options[] = {
|
||||
const struct option long_options[] = {
|
||||
{"config", required_argument, 0, 'c'},
|
||||
{"daemon", required_argument, 0, 'd'},
|
||||
#ifdef LOCAL_SUPPORT
|
||||
|
@ -168,7 +168,9 @@ void parse_channels(char *filename, list_t *chans) {
|
|||
char *middleware, *options, *uuid;
|
||||
unsigned long interval;
|
||||
channel_t ch;
|
||||
|
||||
meter_type_t *type;
|
||||
meter_conn_t connection;
|
||||
|
||||
/* parse tokens (required) */
|
||||
memset(tokens, 0, 5);
|
||||
|
@ -182,6 +184,7 @@ void parse_channels(char *filename, list_t *chans) {
|
|||
for (type = meter_types; type->name != NULL; type++) { /* linear search */
|
||||
if (strcmp(type->name, tokens[0]) == 0) break;
|
||||
}
|
||||
|
||||
|
||||
if (type->name == NULL) { /* reached end */
|
||||
print(-1, "Invalid protocol: %s in %s:%i", NULL, tokens[0], filename, lineno);
|
||||
|
@ -214,6 +217,8 @@ void parse_channels(char *filename, list_t *chans) {
|
|||
interval = 0;
|
||||
}
|
||||
|
||||
/* connection */
|
||||
|
||||
/* options (optional) */
|
||||
options = tokens[type->periodical ? 4 : 3];
|
||||
|
|
@ -46,10 +46,10 @@
|
|||
|
||||
/* global variables */
|
||||
list_t chans;
|
||||
extern options_t opts;
|
||||
extern char *long_options_descs[];
|
||||
extern struct option long_options[];
|
||||
extern meter_type_t meter_types[];
|
||||
extern const options_t opts;
|
||||
extern const char *long_options_descs[];
|
||||
extern const struct option long_options[];
|
||||
extern const meter_type_t meter_types[];
|
||||
|
||||
/**
|
||||
* Print available options and some other usefull information
|
||||
|
@ -147,13 +147,14 @@ int main(int argc, char *argv[]) {
|
|||
meter_open(&ch->meter);
|
||||
|
||||
print(5, "Starting threads", ch);
|
||||
pthread_create(&ch->logging_thread, NULL, &api_thread, (void *) ch);
|
||||
pthread_create(&ch->logging_thread, NULL, &logging_thread, (void *) ch);
|
||||
pthread_create(&ch->reading_thread, NULL, &reading_thread, (void *) ch);
|
||||
}
|
||||
|
||||
#ifdef LOCAL_SUPPORT
|
||||
/* start webserver for local interface */
|
||||
struct MHD_Daemon *httpd_handle = NULL;
|
||||
if (opts.local) { /* start webserver for local interface */
|
||||
if (opts.local) {
|
||||
print(5, "Starting local interface HTTPd on port %i", NULL, opts.port);
|
||||
httpd_handle = MHD_start_daemon(
|
||||
MHD_USE_THREAD_PER_CONNECTION,
|
|
@ -30,6 +30,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
@ -41,8 +42,8 @@
|
|||
#include <sml/sml_file.h>
|
||||
#include <sml/sml_transport.h>
|
||||
|
||||
#include "obis.h"
|
||||
#include "unit.h"
|
||||
#include <obis.h>
|
||||
#include <unit.h>
|
||||
|
||||
obis_id_t filter;
|
||||
|
||||
|
@ -57,15 +58,23 @@ void transport_receiver(unsigned char *buffer, size_t buffer_len) {
|
|||
sml_list *entry;
|
||||
sml_get_list_response *body;
|
||||
|
||||
struct timeval time;
|
||||
int time_mode = 0;
|
||||
|
||||
body = (sml_get_list_response *) message->message_body->data;
|
||||
|
||||
printf("new message from: %*s\n", body->server_id->len, body->server_id->str);
|
||||
//printf("new message from: %*s\n", body->server_id->len, body->server_id->str);
|
||||
|
||||
if (body->act_sensor_time) {
|
||||
time.tv_sec = *body->act_sensor_time->data.timestamp;
|
||||
time.tv_usec = 0;
|
||||
time_mode = 1;
|
||||
}
|
||||
|
||||
for (entry = body->val_list; entry != NULL; entry = entry->next) { /* linked list */
|
||||
obis_id_t id = obis_init(entry->obj_name->str);
|
||||
|
||||
if (memcmp(&id, &filter, sizeof(obis_id_t)) == 0) {
|
||||
struct timeval time;
|
||||
int unit = (entry->unit) ? *entry->unit : 0;
|
||||
int scaler = (entry->scaler) ? *entry->scaler : 1;
|
||||
double value;
|
||||
|
@ -81,24 +90,25 @@ void transport_receiver(unsigned char *buffer, size_t buffer_len) {
|
|||
case 0x68: value = *entry->value->data.uint64; break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Unknown value type: %x", type);
|
||||
fprintf(stderr, "Unknown value type: %x", entry->value->type);
|
||||
value = 0;
|
||||
}
|
||||
|
||||
/* apply scaler */
|
||||
value *= pow(10, scaler);
|
||||
|
||||
|
||||
/* get time */
|
||||
if (entry->val_time) { // TODO handle SML_TIME_SEC_INDEX
|
||||
time.tv_sec = *entry->val_time->data.timestamp;
|
||||
time.tv_usec = 0;
|
||||
time_mode = 2;
|
||||
}
|
||||
else {
|
||||
else if (time_mode == 0) {
|
||||
gettimeofday(&time, NULL);
|
||||
time_mode = 3;
|
||||
}
|
||||
|
||||
printf("%lu.%lu\t%.2f %s\n", time.tv_sec, time.tv_usec, value, dlms_get_unit(unit));
|
||||
printf("%lu.%lu (%i)\t%.2f %s\n", time.tv_sec, time.tv_usec, time_mode, value, dlms_get_unit(unit));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/**
|
||||
* Implementation of local interface via libmicrohttpd
|
||||
*
|
||||
* @package vzlogger
|
||||
* @copyright Copyright (c) 2011, The volkszaehler.org project
|
||||
* @license http://www.gnu.org/licenses/gpl.txt GNU Public License
|
||||
* @author Steffen Vogel <info@steffenvogel.de>
|
||||
*/
|
||||
/*
|
||||
* This file is part of volkzaehler.org
|
||||
*
|
||||
* volkzaehler.org is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* volkzaehler.org is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <json/json.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "vzlogger.h"
|
||||
#include "local.h"
|
||||
#include "options.h"
|
||||
#include "api.h"
|
||||
|
||||
extern list_t chans;
|
||||
extern options_t opts;
|
||||
|
||||
int handle_request(void *cls, struct MHD_Connection *connection, const char *url, const char *method,
|
||||
const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) {
|
||||
|
||||
int ret;
|
||||
const char *json_str;
|
||||
const char *uuid = url+1;
|
||||
|
||||
struct timespec ts;
|
||||
struct timeval tp;
|
||||
|
||||
struct MHD_Response *response;
|
||||
|
||||
struct json_object *json_obj = json_object_new_object();
|
||||
struct json_object *json_data = json_object_new_object();
|
||||
|
||||
print(2, "Local request received: %s %s %s", NULL, version, method, url);
|
||||
|
||||
for (channel_t *ch = chans.start; ch != NULL; ch = ch->next) {
|
||||
if (strcmp(url, "/") == 0 || strcmp(ch->uuid, uuid) == 0) {
|
||||
/* convert from timeval to timespec */
|
||||
gettimeofday(&tp, NULL);
|
||||
ts.tv_sec = tp.tv_sec;
|
||||
ts.tv_nsec = tp.tv_usec * 1000;
|
||||
ts.tv_sec += COMET_TIMEOUT;
|
||||
|
||||
/* blocking until new data arrives (comet-like blocking of HTTP response) */
|
||||
pthread_mutex_lock(&ch->buffer.mutex);
|
||||
pthread_cond_timedwait(&ch->condition, &ch->buffer.mutex, &ts);
|
||||
pthread_mutex_unlock(&ch->buffer.mutex);
|
||||
|
||||
json_object_object_add(json_data, "uuid", json_object_new_string(ch->uuid));
|
||||
json_object_object_add(json_data, "interval", json_object_new_int(ch->interval));
|
||||
|
||||
struct json_object *json_tuples = api_json_tuples(&ch->buffer, ch->buffer.start);
|
||||
json_object_object_add(json_data, "tuples", json_tuples);
|
||||
}
|
||||
}
|
||||
|
||||
json_object_object_add(json_obj, "version", json_object_new_string(VERSION));
|
||||
json_object_object_add(json_obj, "generator", json_object_new_string(PACKAGE));
|
||||
json_object_object_add(json_obj, "data", json_data);
|
||||
json_str = json_object_to_json_string(json_obj);
|
||||
|
||||
response = MHD_create_response_from_data(strlen(json_str), (void *) json_str, FALSE, TRUE);
|
||||
|
||||
MHD_add_response_header(response, "Content-type", "application/json");
|
||||
|
||||
ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
|
||||
|
||||
MHD_destroy_response (response);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -32,7 +32,7 @@ typedef struct meter_reading {
|
|||
float value;
|
||||
struct timeval tv;
|
||||
|
||||
struct meter_reading *next, *prev; /* pointers for linked list */
|
||||
struct meter_reading *next; /* pointer for linked list */
|
||||
} meter_reading_t;
|
||||
|
||||
#endif /* _READING_H_ */
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "../include/meter.h"
|
||||
|
||||
/* List of available meter types */
|
||||
meter_type_t meter_types[] = {
|
||||
const meter_type_t meter_types[] = {
|
||||
{ONEWIRE, "onewire", "Dallas 1-Wire sensors (via OWFS)", 1},
|
||||
{RANDOM, "random", "Random walk", 1},
|
||||
{S0, "S0", "S0 on RS232", 0},
|
||||
|
@ -39,7 +39,7 @@ meter_type_t meter_types[] = {
|
|||
#endif /* SML_SUPPORT */
|
||||
{} /* stop condition for iterator */
|
||||
};
|
||||
|
||||
|
||||
void meter_init(meter_t *meter, meter_type_t *type, char *options) {
|
||||
meter->type = type;
|
||||
meter->options = strdup(options);
|
||||
|
|
Loading…
Add table
Reference in a new issue