timelog.c 912 Bytes
Newer Older
Cedric Roux's avatar
Cedric Roux committed
1 2 3 4 5
#include "logger.h"
#include "logger_defs.h"
#include "event.h"
#include "database.h"
#include "handler.h"
Cedric Roux's avatar
Cedric Roux committed
6
#include "filter/filter.h"
Cedric Roux's avatar
Cedric Roux committed
7 8 9 10 11 12 13 14 15 16 17 18
#include <stdlib.h>
#include <string.h>

struct timelog {
  struct logger common;
};

static void _event(void *p, event e)
{
  struct timelog *l = p;
  int i;

Cedric Roux's avatar
Cedric Roux committed
19 20 21
  if (l->common.filter != NULL && filter_eval(l->common.filter, e) == 0)
    return;

Cedric Roux's avatar
Cedric Roux committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
  for (i = 0; i < l->common.vsize; i++)
    l->common.v[i]->append(l->common.v[i], e.sending_time);
}

logger *new_timelog(event_handler *h, void *database, char *event_name)
{
  struct timelog *ret;
  int event_id;

  ret = calloc(1, sizeof(struct timelog)); if (ret == NULL) abort();

  ret->common.event_name = strdup(event_name);
  if (ret->common.event_name == NULL) abort();

  event_id = event_id_from_name(database, event_name);

  ret->common.handler_id = register_handler_function(h,event_id,_event,ret);

  return ret;
}