From 642ec66de5bdf7e5e8edfca5d3aacf809955e33e Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 6 May 2011 20:24:40 -0400 Subject: [PATCH] Add missing ctf-text.c to repo Signed-off-by: Mathieu Desnoyers --- formats/ctf-text/ctf-text.c | 104 ++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 formats/ctf-text/ctf-text.c diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c new file mode 100644 index 00000000..2e9509e7 --- /dev/null +++ b/formats/ctf-text/ctf-text.c @@ -0,0 +1,104 @@ +/* + * BabelTrace - Common Trace Format (CTF) + * + * CTF Text Format registration. + * + * Copyright 2010, 2011 - Mathieu Desnoyers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct trace_descriptor *ctf_text_open_trace(const char *path, int flags); +void ctf_text_close_trace(struct trace_descriptor *descriptor); + +static +rw_dispatch read_dispatch_table[] = { + /* All unimplemented */ +}; + +static +rw_dispatch write_dispatch_table[] = { + [ CTF_TYPE_INTEGER ] = ctf_text_integer_write, + [ CTF_TYPE_FLOAT ] = ctf_text_float_write, + [ CTF_TYPE_ENUM ] = ctf_text_enum_write, + [ CTF_TYPE_STRING ] = ctf_text_string_write, + [ CTF_TYPE_STRUCT ] = ctf_text_struct_write, + [ CTF_TYPE_VARIANT ] = ctf_text_variant_write, + [ CTF_TYPE_ARRAY ] = ctf_text_array_write, + [ CTF_TYPE_SEQUENCE ] = ctf_text_sequence_write, +}; + +static +struct format ctf_text_format = { + .open_trace = ctf_text_open_trace, + .close_trace = ctf_text_close_trace, +}; + +struct trace_descriptor *ctf_text_open_trace(const char *path, int flags) +{ + struct ctf_text_stream_pos *pos; + FILE *fp; + + pos = g_new0(struct ctf_text_stream_pos, 1); + + switch (flags & O_ACCMODE) { + case O_WRONLY: + fp = fopen(path, "w"); + if (!fp) + goto error; + pos->fp = fp; + pos->parent.rw_table = write_dispatch_table; + break; + case O_RDONLY: + default: + fprintf(stdout, "[error] Incorrect open flags.\n"); + goto error; + } + + return &pos->trace_descriptor; +error: + g_free(pos); + return NULL; +} + +void ctf_text_close_trace(struct trace_descriptor *td) +{ + struct ctf_text_stream_pos *pos = + container_of(td, struct ctf_text_stream_pos, trace_descriptor); + fclose(pos->fp); + g_free(pos); +} + +void __attribute__((constructor)) ctf_text_init(void) +{ + int ret; + + ctf_text_format.name = g_quark_from_static_string("text"); + ret = bt_register_format(&ctf_text_format); + assert(!ret); +} + +/* TODO: finalize */ -- 2.34.1