add a filter to loggers
events are accepted by the logger if the filter accepts them the filter is optional (no filter means to accept all events)
This commit is contained in:
@@ -8,18 +8,21 @@ LIBS=-lX11 -lm -lpng -lXft
|
|||||||
all: textlog enb vcd
|
all: textlog enb vcd
|
||||||
|
|
||||||
textlog: utils.o textlog.o database.o event.o handler.o config.o \
|
textlog: utils.o textlog.o database.o event.o handler.o config.o \
|
||||||
event_selector.o view/view.a gui/gui.a logger/logger.a
|
event_selector.o view/view.a gui/gui.a logger/logger.a \
|
||||||
|
filter/filter.a
|
||||||
$(CC) $(CFLAGS) -o textlog $^ $(LIBS)
|
$(CC) $(CFLAGS) -o textlog $^ $(LIBS)
|
||||||
|
|
||||||
enb: utils.o enb.o database.o event.o handler.o config.o \
|
enb: utils.o enb.o database.o event.o handler.o config.o \
|
||||||
event_selector.o view/view.a gui/gui.a logger/logger.a
|
event_selector.o view/view.a gui/gui.a logger/logger.a \
|
||||||
|
filter/filter.a
|
||||||
$(CC) $(CFLAGS) -o enb $^ $(LIBS)
|
$(CC) $(CFLAGS) -o enb $^ $(LIBS)
|
||||||
|
|
||||||
vcd: utils.o vcd.o database.o event.o handler.o config.o \
|
vcd: utils.o vcd.o database.o event.o handler.o config.o \
|
||||||
event_selector.o view/view.a gui/gui.a logger/logger.a
|
event_selector.o view/view.a gui/gui.a logger/logger.a \
|
||||||
|
filter/filter.a
|
||||||
$(CC) $(CFLAGS) -o vcd $^ $(LIBS)
|
$(CC) $(CFLAGS) -o vcd $^ $(LIBS)
|
||||||
|
|
||||||
.PHONY: all gui/gui.a view/view.a logger/logger.a
|
.PHONY: all gui/gui.a view/view.a logger/logger.a filter/filter.a
|
||||||
|
|
||||||
gui/gui.a:
|
gui/gui.a:
|
||||||
cd gui && make
|
cd gui && make
|
||||||
@@ -30,6 +33,9 @@ view/view.a:
|
|||||||
logger/logger.a:
|
logger/logger.a:
|
||||||
cd logger && make
|
cd logger && make
|
||||||
|
|
||||||
|
filter/filter.a:
|
||||||
|
cd filter && make
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
@@ -38,3 +44,4 @@ clean:
|
|||||||
cd gui && make clean
|
cd gui && make clean
|
||||||
cd view && make clean
|
cd view && make clean
|
||||||
cd logger && make clean
|
cd logger && make clean
|
||||||
|
cd filter && make clean
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
CC=gcc
|
||||||
|
CFLAGS=-Wall -g -pthread -I..
|
||||||
|
|
||||||
|
OBJS=filter.o
|
||||||
|
|
||||||
|
filter.a: $(OBJS)
|
||||||
|
ar cr filter.a $(OBJS)
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.a *.o
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
#include "filter.h"
|
||||||
|
#include "event.h"
|
||||||
|
#include "database.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
struct filter {
|
||||||
|
union {
|
||||||
|
struct { struct filter *a, *b; } eq;
|
||||||
|
int v;
|
||||||
|
struct { int event_type; int arg_index; } evarg;
|
||||||
|
} v;
|
||||||
|
|
||||||
|
int (*eval)(struct filter *this, event e);
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* evaluation functions */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
int eval_eq(struct filter *f, event e)
|
||||||
|
{
|
||||||
|
int a = f->v.eq.a->eval(f->v.eq.a, e);
|
||||||
|
int b = f->v.eq.b->eval(f->v.eq.b, e);
|
||||||
|
return a == b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int eval_int(struct filter *f, event e)
|
||||||
|
{
|
||||||
|
return f->v.v;
|
||||||
|
}
|
||||||
|
|
||||||
|
int eval_evarg(struct filter *f, event e)
|
||||||
|
{
|
||||||
|
if (e.type != f->v.evarg.event_type) {
|
||||||
|
printf("%s:%d:%s: bad event type\n", __FILE__, __LINE__, __FUNCTION__);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
if (e.e[f->v.evarg.arg_index].type != EVENT_INT) {
|
||||||
|
printf("%s:%d:%s: bad event argtype; has to be 'int'\n",
|
||||||
|
__FILE__, __LINE__, __FUNCTION__);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
return e.e[f->v.evarg.arg_index].i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* filter construction functions */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
filter *filter_eq(filter *a, filter *b)
|
||||||
|
{
|
||||||
|
struct filter *ret = calloc(1, sizeof(struct filter));
|
||||||
|
if (ret == NULL) abort();
|
||||||
|
ret->eval = eval_eq;
|
||||||
|
ret->v.eq.a = a;
|
||||||
|
ret->v.eq.b = b;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
filter *filter_int(int v)
|
||||||
|
{
|
||||||
|
struct filter *ret = calloc(1, sizeof(struct filter));
|
||||||
|
if (ret == NULL) abort();
|
||||||
|
ret->eval = eval_int;
|
||||||
|
ret->v.v = v;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
filter *filter_evarg(void *database, char *event_name, char *varname)
|
||||||
|
{
|
||||||
|
struct filter *ret;
|
||||||
|
int event_id;
|
||||||
|
database_event_format f;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
ret = calloc(1, sizeof(struct filter)); if (ret == NULL) abort();
|
||||||
|
|
||||||
|
event_id = event_id_from_name(database, event_name);
|
||||||
|
f = get_format(database, event_id);
|
||||||
|
|
||||||
|
ret->eval = eval_evarg;
|
||||||
|
ret->v.evarg.event_type = event_id;
|
||||||
|
ret->v.evarg.arg_index = -1;
|
||||||
|
|
||||||
|
for (i = 0; i < f.count; i++) {
|
||||||
|
if (strcmp(f.name[i], varname) != 0) continue;
|
||||||
|
ret->v.evarg.arg_index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ret->v.evarg.arg_index == -1) {
|
||||||
|
printf("%s:%d:%s: event '%s' has no argument '%s'\n",
|
||||||
|
__FILE__, __LINE__, __FUNCTION__, event_name, varname);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
/* eval function */
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
int filter_eval(filter *_f, event e)
|
||||||
|
{
|
||||||
|
struct filter *f = _f;
|
||||||
|
return f->eval(f, e);
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef _FILTER_H_
|
||||||
|
#define _FILTER_H_
|
||||||
|
|
||||||
|
#include "event.h"
|
||||||
|
|
||||||
|
typedef void filter;
|
||||||
|
|
||||||
|
filter *filter_eq(filter *a, filter *b);
|
||||||
|
filter *filter_int(int v);
|
||||||
|
filter *filter_evarg(void *database, char *event_name, char *varname);
|
||||||
|
|
||||||
|
int filter_eval(filter *f, event e);
|
||||||
|
|
||||||
|
#endif /* _FILTER_H_ */
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "logger_defs.h"
|
#include "logger_defs.h"
|
||||||
#include "handler.h"
|
#include "handler.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
#include "filter/filter.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -31,6 +32,9 @@ static void _event(void *p, event e)
|
|||||||
int bsize;
|
int bsize;
|
||||||
int nsamples;
|
int nsamples;
|
||||||
|
|
||||||
|
if (l->common.filter != NULL && filter_eval(l->common.filter, e) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
subframe = e.e[l->subframe_arg].i;
|
subframe = e.e[l->subframe_arg].i;
|
||||||
buffer = e.e[l->buffer_arg].b;
|
buffer = e.e[l->buffer_arg].b;
|
||||||
bsize = e.e[l->buffer_arg].bsize;
|
bsize = e.e[l->buffer_arg].bsize;
|
||||||
|
|||||||
@@ -9,3 +9,9 @@ void logger_add_view(logger *_l, view *v)
|
|||||||
l->v = realloc(l->v, l->vsize * sizeof(view *)); if (l->v == NULL) abort();
|
l->v = realloc(l->v, l->vsize * sizeof(view *)); if (l->v == NULL) abort();
|
||||||
l->v[l->vsize-1] = v;
|
l->v[l->vsize-1] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void logger_set_filter(logger *_l, void *filter)
|
||||||
|
{
|
||||||
|
struct logger *l = _l;
|
||||||
|
l->filter = filter;
|
||||||
|
}
|
||||||
|
|||||||
@@ -19,5 +19,6 @@ void framelog_set_skip(logger *_this, int skip_delay);
|
|||||||
#include "view/view.h"
|
#include "view/view.h"
|
||||||
|
|
||||||
void logger_add_view(logger *l, view *v);
|
void logger_add_view(logger *l, view *v);
|
||||||
|
void logger_set_filter(logger *l, void *filter);
|
||||||
|
|
||||||
#endif /* _LOGGER_H_ */
|
#endif /* _LOGGER_H_ */
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ struct logger {
|
|||||||
/* list of views */
|
/* list of views */
|
||||||
view **v;
|
view **v;
|
||||||
int vsize;
|
int vsize;
|
||||||
|
/* filter - NULL if no filter set */
|
||||||
|
void *filter;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _LOGGER_DEFS_H_ */
|
#endif /* _LOGGER_DEFS_H_ */
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "view/view.h"
|
#include "view/view.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "filter/filter.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -42,6 +43,9 @@ static void _event(void *p, event e)
|
|||||||
char tt[64];
|
char tt[64];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (l->common.filter != NULL && filter_eval(l->common.filter, e) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
l->o.osize = 0;
|
l->o.osize = 0;
|
||||||
|
|
||||||
#ifdef T_SEND_TIME
|
#ifdef T_SEND_TIME
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "handler.h"
|
#include "handler.h"
|
||||||
|
#include "filter/filter.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -21,6 +22,9 @@ static void _event(void *p, event e)
|
|||||||
int frame;
|
int frame;
|
||||||
int subframe;
|
int subframe;
|
||||||
|
|
||||||
|
if (l->common.filter != NULL && filter_eval(l->common.filter, e) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
frame = e.e[l->frame_arg].i;
|
frame = e.e[l->frame_arg].i;
|
||||||
subframe = e.e[l->subframe_arg].i;
|
subframe = e.e[l->subframe_arg].i;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "handler.h"
|
#include "handler.h"
|
||||||
|
#include "filter/filter.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -15,6 +16,9 @@ static void _event(void *p, event e)
|
|||||||
struct timelog *l = p;
|
struct timelog *l = p;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (l->common.filter != NULL && filter_eval(l->common.filter, e) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
for (i = 0; i < l->common.vsize; i++)
|
for (i = 0; i < l->common.vsize; i++)
|
||||||
l->common.v[i]->append(l->common.v[i], e.sending_time);
|
l->common.v[i]->append(l->common.v[i], e.sending_time);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "event.h"
|
#include "event.h"
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
#include "handler.h"
|
#include "handler.h"
|
||||||
|
#include "filter/filter.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -25,6 +26,9 @@ static void _event(void *p, event e)
|
|||||||
int subframe;
|
int subframe;
|
||||||
float value;
|
float value;
|
||||||
|
|
||||||
|
if (l->common.filter != NULL && filter_eval(l->common.filter, e) == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
frame = e.e[l->frame_arg].i;
|
frame = e.e[l->frame_arg].i;
|
||||||
subframe = e.e[l->subframe_arg].i;
|
subframe = e.e[l->subframe_arg].i;
|
||||||
switch (e.e[l->data_arg].type) {
|
switch (e.e[l->data_arg].type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user