Commit 724b6622 authored by Cedric Roux's avatar Cedric Roux
Browse files

TTI logger

parent b04a448b
CC=gcc CC=gcc
CFLAGS=-Wall -g -pthread -I.. CFLAGS=-Wall -g -pthread -I..
OBJS=textlog.o framelog.o OBJS=textlog.o framelog.o ttilog.o
logger.a: $(OBJS) logger.a: $(OBJS)
ar cr logger.a $(OBJS) ar cr logger.a $(OBJS)
#include "ttilog.h"
#include "event.h"
#include "database.h"
#include "handler.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct ttilog {
char *event_name;
void *database;
unsigned long handler_id;
int frame_arg;
int subframe_arg;
int data_arg;
/* list of views */
view **v;
int vsize;
static void _event(void *p, event e)
struct ttilog *l = p;
int i;
int frame;
int subframe;
float value;
frame = e.e[l->frame_arg].i;
subframe = e.e[l->subframe_arg].i;
switch (e.e[l->data_arg].type) {
case EVENT_INT: value = e.e[l->data_arg].i;
default: printf("%s:%d: unsupported type\n", __FILE__, __LINE__); abort();
for (i = 0; i < l->vsize; i++)
l->v[i]->append(l->v[i], frame, subframe, value);
ttilog *new_ttilog(event_handler *h, void *database,
char *event_name, char *frame_varname, char *subframe_varname,
char *data_varname)
struct ttilog *ret;
int event_id;
database_event_format f;
int i;
ret = calloc(1, sizeof(struct ttilog)); if (ret == NULL) abort();
ret->event_name = strdup(event_name); if (ret->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);
f = get_format(database, event_id);
/* look for frame, subframe and data args */
ret->frame_arg = -1;
ret->subframe_arg = -1;
ret->data_arg = -1;
for (i = 0; i < f.count; i++) {
if (!strcmp([i], frame_varname)) ret->frame_arg = i;
if (!strcmp([i], subframe_varname)) ret->subframe_arg = i;
if (!strcmp([i], data_varname)) ret->data_arg = i;
if (ret->frame_arg == -1) {
printf("%s:%d: frame argument '%s' not found in event '%s'\n",
__FILE__, __LINE__, frame_varname, event_name);
if (ret->subframe_arg == -1) {
printf("%s:%d: subframe argument '%s' not found in event '%s'\n",
__FILE__, __LINE__, subframe_varname, event_name);
if (ret->data_arg == -1) {
printf("%s:%d: data argument '%s' not found in event '%s'\n",
__FILE__, __LINE__, data_varname, event_name);
if (strcmp(f.type[ret->frame_arg], "int") != 0) {
printf("%s:%d: argument '%s' has wrong type (should be 'int')\n",
__FILE__, __LINE__, frame_varname);
if (strcmp(f.type[ret->subframe_arg], "int") != 0) {
printf("%s:%d: argument '%s' has wrong type (should be 'int')\n",
__FILE__, __LINE__, subframe_varname);
if (strcmp(f.type[ret->data_arg], "int") != 0 &&
strcmp(f.type[ret->data_arg], "float") != 0) {
printf("%s:%d: argument '%s' has wrong type"
" (should be 'int' or 'float')\n",
__FILE__, __LINE__, data_varname);
return ret;
void ttilog_add_view(ttilog *_l, view *v)
struct ttilog *l = _l;
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);
#include "view/view.h"
void ttilog_add_view(ttilog *l, view *v);
#endif /* _TTILOG_H_ */
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