diff --git a/server/include/file.h b/server/include/file.h index 4b9beaf7d..349181164 100644 --- a/server/include/file.h +++ b/server/include/file.h @@ -14,17 +14,20 @@ #include "node.h" +#define FILE_MAX_PATHLEN 128 + struct file { FILE *in; FILE *out; const char *path_in; - const char *path_out; + char *path_out; const char *mode; /**< The mode for fopen() which is used for the out file. */ double rate; /**< The sending rate. */ int tfd; /**< Timer file descriptor. Blocks until 1/rate seconds are elapsed. */ + int timestamp; /**< Bolean flag, prepend timestamp in front of message */ }; /** @see node_vtable::init */ diff --git a/server/src/file.c b/server/src/file.c index 333f2b2e8..e072d4e8b 100644 --- a/server/src/file.c +++ b/server/src/file.c @@ -53,6 +53,9 @@ int file_parse(config_setting_t *cfg, struct node *n) if (!config_setting_lookup_float(cfg, "rate", &f->rate)) f->rate = 1; + if (!config_setting_lookup_bool(cfg, "timestamp", &f->timestamp)) + f->timestamp = 0; + n->file = f; return 0; @@ -100,6 +103,8 @@ int file_close(struct node *n) if (f->out) fclose(f->out); + free(f->path_out); + return 0; } @@ -133,6 +138,12 @@ int file_write(struct node *n, struct msg *pool, int poolsize, int first, int cn for (i = 0; i < cnt; i++) { struct msg *m = &pool[(first+i) % poolsize]; + if (f->timestamp) { + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + fprintf(f->out, "%lu.%06lu\t", ts.tv_sec, (long) (ts.tv_nsec / 1e3)); + } + msg_fprint(f->out, m); } }