Commit e5689a5b authored by Cedric Roux's avatar Cedric Roux

introducing a generic logger "class"

parent d8ec913b
CC=gcc
CFLAGS=-Wall -g -pthread -I..
OBJS=textlog.o framelog.o ttilog.o
OBJS=logger.o textlog.o framelog.o ttilog.o
logger.a: $(OBJS)
ar cr logger.a $(OBJS)
......
#include "framelog.h"
#include "logger.h"
#include "logger_defs.h"
#include "handler.h"
#include "database.h"
#include <stdlib.h>
......@@ -7,14 +8,10 @@
#include <math.h>
struct framelog {
char *event_name;
struct logger common;
void *database;
unsigned long handler_id;
int subframe_arg;
int buffer_arg;
/* list of views */
view **v;
int vsize;
float *x;
float *buffer;
int blength;
......@@ -47,8 +44,8 @@ static void _event(void *p, event e)
for (i = 0; i < l->blength; i++)
l->x[i] = i;
/* update 'length' of views */
for (i = 0; i < l->vsize; i++)
l->v[i]->set(l->v[i], "length", l->blength);
for (i = 0; i < l->common.vsize; i++)
l->common.v[i]->set(l->common.v[i], "length", l->blength);
}
/* TODO: compute the LOGs in the plotter (too much useless computations) */
......@@ -59,11 +56,11 @@ static void _event(void *p, event e)
}
if (subframe == 9)
for (i = 0; i < l->vsize; i++)
l->v[i]->append(l->v[i], l->x, l->buffer, l->blength);
for (i = 0; i < l->common.vsize; i++)
l->common.v[i]->append(l->common.v[i], l->x, l->buffer, l->blength);
}
framelog *new_framelog(event_handler *h, void *database,
logger *new_framelog(event_handler *h, void *database,
char *event_name, char *subframe_varname, char *buffer_varname)
{
struct framelog *ret;
......@@ -73,12 +70,13 @@ framelog *new_framelog(event_handler *h, void *database,
ret = calloc(1, sizeof(struct framelog)); if (ret == NULL) abort();
ret->event_name = strdup(event_name); if (ret->event_name == NULL) abort();
ret->common.event_name = strdup(event_name);
if (ret->common.event_name == NULL) abort();
ret->database = database;
event_id = event_id_from_name(database, event_name);
ret->handler_id = register_handler_function(h, event_id, _event, ret);
ret->common.handler_id = register_handler_function(h,event_id,_event,ret);
f = get_format(database, event_id);
......@@ -112,11 +110,3 @@ framelog *new_framelog(event_handler *h, void *database,
return ret;
}
void framelog_add_view(framelog *_l, view *v)
{
struct framelog *l = _l;
l->vsize++;
l->v = realloc(l->v, l->vsize * sizeof(view *)); if (l->v == NULL) abort();
l->v[l->vsize-1] = v;
}
#ifndef _FRAMELOG_H_
#define _FRAMELOG_H_
typedef void framelog;
framelog *new_framelog(void *event_handler, void *database,
char *event_name, char *subframe_varname, char *buffer_varname);
#include "view/view.h"
void framelog_add_view(framelog *l, view *v);
#endif /* _FRAMELOG_H_ */
#include "logger.h"
#include "logger_defs.h"
#include <stdlib.h>
void logger_add_view(logger *_l, view *v)
{
struct logger *l = _l;
l->vsize++;
l->v = realloc(l->v, l->vsize * sizeof(view *)); if (l->v == NULL) abort();
l->v[l->vsize-1] = v;
}
#ifndef _LOGGER_H_
#define _LOGGER_H_
typedef void logger;
logger *new_framelog(void *event_handler, void *database,
char *event_name, char *subframe_varname, char *buffer_varname);
logger *new_textlog(void *event_handler, void *database,
char *event_name, char *format);
logger *new_ttilog(void *event_handler, void *database,
char *event_name, char *frame_varname, char *subframe_varname,
char *data_varname, int convert_to_dB);
#include "view/view.h"
void logger_add_view(logger *l, view *v);
#endif /* _LOGGER_H_ */
#ifndef _LOGGER_DEFS_H_
#define _LOGGER_DEFS_H_
#include "view/view.h"
struct logger {
char *event_name;
unsigned long handler_id;
/* list of views */
view **v;
int vsize;
};
#endif /* _LOGGER_DEFS_H_ */
#include "textlog.h"
#include "logger.h"
#include "logger_defs.h"
#include "handler.h"
#include "database.h"
#include "view/view.h"
......@@ -22,16 +23,12 @@ struct format_item {
};
struct textlog {
char *event_name;
struct logger common;
char *format;
void *database;
unsigned long handler_id;
/* parsed format string */
struct format_item *f;
int fsize;
/* list of views */
view **v;
int vsize;
/* local output buffer */
OBUF o;
};
......@@ -56,7 +53,8 @@ static void _event(void *p, event e)
}
PUTC(&l->o, 0);
for (i = 0; i < l->vsize; i++) l->v[i]->append(l->v[i], l->o.obuf);
for (i = 0; i < l->common.vsize; i++)
l->common.v[i]->append(l->common.v[i], l->o.obuf);
}
enum chunk_type { C_ERROR, C_STRING, C_ARG_NAME, C_EVENT_NAME };
......@@ -127,7 +125,7 @@ error:
return (struct chunk){type:C_ERROR};
}
textlog *new_textlog(event_handler *h, void *database,
logger *new_textlog(event_handler *h, void *database,
char *event_name, char *format)
{
struct textlog *ret;
......@@ -137,13 +135,14 @@ textlog *new_textlog(event_handler *h, void *database,
ret = calloc(1, sizeof(struct textlog)); if (ret == NULL) abort();
ret->event_name = strdup(event_name); if (ret->event_name == NULL) abort();
ret->common.event_name = strdup(event_name);
if (ret->common.event_name == NULL) abort();
ret->format = strdup(format); if (ret->format == NULL) abort();
ret->database = database;
event_id = event_id_from_name(database, event_name);
ret->handler_id = register_handler_function(h, event_id, _event, ret);
ret->common.handler_id = register_handler_function(h,event_id,_event,ret);
f = get_format(database, event_id);
......@@ -167,7 +166,7 @@ textlog *new_textlog(event_handler *h, void *database,
break;
case C_EVENT_NAME:
ret->f[ret->fsize].type = INSTRING;
ret->f[ret->fsize].s = ret->event_name;
ret->f[ret->fsize].s = ret->common.event_name;
break;
}
ret->fsize++;
......@@ -179,11 +178,3 @@ error:
printf("%s:%d: bad format '%s'\n", __FILE__, __LINE__, format);
abort();
}
void textlog_add_view(textlog *_l, view *v)
{
struct textlog *l = _l;
l->vsize++;
l->v = realloc(l->v, l->vsize * sizeof(view *)); if (l->v == NULL) abort();
l->v[l->vsize-1] = v;
}
#ifndef _TEXTLOG_H_
#define _TEXTLOG_H_
typedef void textlog;
textlog *new_textlog(void *event_handler, void *database,
char *event_name, char *format);
#include "view/view.h"
void textlog_add_view(textlog *l, view *v);
#endif /* _TEXTLOG_H_ */
#include "ttilog.h"
#include "logger.h"
#include "logger_defs.h"
#include "event.h"
#include "database.h"
#include "handler.h"
......@@ -8,15 +9,11 @@
#include <math.h>
struct ttilog {
char *event_name;
struct logger common;
void *database;
unsigned long handler_id;
int frame_arg;
int subframe_arg;
int data_arg;
/* list of views */
view **v;
int vsize;
int convert_to_dB;
};
......@@ -37,11 +34,11 @@ static void _event(void *p, event e)
if (l->convert_to_dB) value = 10 * log10(value);
for (i = 0; i < l->vsize; i++)
l->v[i]->append(l->v[i], frame, subframe, value);
for (i = 0; i < l->common.vsize; i++)
l->common.v[i]->append(l->common.v[i], frame, subframe, value);
}
ttilog *new_ttilog(event_handler *h, void *database,
logger *new_ttilog(event_handler *h, void *database,
char *event_name, char *frame_varname, char *subframe_varname,
char *data_varname, int convert_to_dB)
{
......@@ -52,13 +49,14 @@ ttilog *new_ttilog(event_handler *h, void *database,
ret = calloc(1, sizeof(struct ttilog)); if (ret == NULL) abort();
ret->event_name = strdup(event_name); if (ret->event_name == NULL) abort();
ret->common.event_name = strdup(event_name);
if (ret->common.event_name == NULL) abort();
ret->database = database;
ret->convert_to_dB = convert_to_dB;
event_id = event_id_from_name(database, event_name);
ret->handler_id = register_handler_function(h, event_id, _event, ret);
ret->common.handler_id = register_handler_function(h,event_id,_event,ret);
f = get_format(database, event_id);
......@@ -106,11 +104,3 @@ ttilog *new_ttilog(event_handler *h, void *database,
return ret;
}
void ttilog_add_view(ttilog *_l, view *v)
{
struct ttilog *l = _l;
l->vsize++;
l->v = realloc(l->v, l->vsize * sizeof(view *)); if (l->v == NULL) abort();
l->v[l->vsize-1] = v;
}
#ifndef _TTILOG_H_
#define _TTILOG_H_
typedef void ttilog;
ttilog *new_ttilog(void *event_handler, void *database,
char *event_name, char *frame_varname, char *subframe_varname,
char *data_varname, int convert_to_dB);
#include "view/view.h"
void ttilog_add_view(ttilog *l, view *v);
#endif /* _TTILOG_H_ */
......@@ -7,7 +7,7 @@
#include "database.h"
#include "event.h"
#include "handler.h"
#include "logger/textlog.h"
#include "logger/logger.h"
#include "view/view.h"
#include "gui/gui.h"
#include "utils.h"
......@@ -125,7 +125,7 @@ int main(int n, char **v)
char t;
int l;
event_handler *h;
textlog *textlog;
logger *textlog;
gui *g;
int gui_mode = 0;
view *out;
......@@ -192,7 +192,7 @@ int main(int n, char **v)
textlog = new_textlog(h, database, name, desc);
// "ENB_UL_CHANNEL_ESTIMATE",
// "ev: {} eNB_id [eNB_ID] frame [frame] subframe [subframe]");
textlog_add_view(textlog, out);
logger_add_view(textlog, out);
free(name);
free(desc);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment