X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fctf.c;h=f5ad955e0e417ccfdb12d928eeee880bc03ad08d;hp=eec36148573eef6a3283808aff916ba22d08ef58;hb=61e9d0cef413869e6ac39ba85b7b4258d8f7fdbc;hpb=7fe001942cc8ece60d945cbfbd1d135ff548dc7d diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index eec36148..f5ad955e 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -3,29 +3,37 @@ * * Format registration. * - * Copyright (c) 2010 Mathieu Desnoyers + * Copyright 2010, 2011 - Mathieu Desnoyers * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * 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: * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 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 + +struct trace_descriptor { + struct ctf_trace ctf_trace; +}; -void __attribute__((constructor)) ctf_init(void); +struct trace_descriptor *ctf_open_trace(const char *path, int flags); +void ctf_close_trace(struct trace_descriptor *descriptor); -static const struct format ctf_format = { +static struct format ctf_format = { .uint_read = ctf_uint_read, .int_read = ctf_int_read, .uint_write = ctf_uint_write, @@ -39,13 +47,107 @@ static const struct format ctf_format = { .string_free_temp = ctf_string_free_temp, .enum_read = ctf_enum_read, .enum_write = ctf_enum_write, + .struct_begin = ctf_struct_begin, + .struct_end = ctf_struct_end, + .variant_begin = ctf_variant_begin, + .variant_end = ctf_variant_end, + .array_begin = ctf_array_begin, + .array_end = ctf_array_end, + .sequence_begin = ctf_sequence_begin, + .sequence_end = ctf_sequence_end, + .open_trace = ctf_open_trace, + .close_trace = ctf_close_trace, }; -void ctf_init(void) +static +int ctf_open_trace_read(struct trace_descriptor *td, const char *path, int flags) +{ + int ret; + + td->ctf_trace.flags = flags; + + /* Open trace directory */ + td->ctf_trace.dir = opendir(path); + if (!td->ctf_trace.dir) { + fprintf(stdout, "Unable to open trace directory.\n"); + ret = -ENOENT; + goto error; + } + + + + /* + * Open each stream: for each file, try to open, check magic + * number, and get the stream ID to add to the right location in + * the stream array. + * + * Keep the metadata file separate. + */ + + + + /* + * Use the metadata file to populate the trace metadata. + */ + + + return 0; +error: + return ret; +} + +static +int ctf_open_trace_write(struct trace_descriptor *td, const char *path, int flags) +{ + int ret; + + ret = mkdir(path, S_IRWXU|S_IRWXG); + if (ret) + return ret; + + return 0; +} + +struct trace_descriptor *ctf_open_trace(const char *path, int flags) +{ + struct trace_descriptor *td; + int ret; + + td = g_new(struct trace_descriptor, 1); + + switch (flags) { + case O_RDONLY: + ret = ctf_open_trace_read(td, path, flags); + if (ret) + goto error; + break; + case O_WRONLY: + ret = ctf_open_trace_write(td, path, flags); + if (ret) + goto error; + break; + default: + fprintf(stdout, "Incorrect open flags.\n"); + goto error; + } + + return td; +error: + g_free(td); + return NULL; +} + +void ctf_close_trace(struct trace_descriptor *td) +{ + closedir(td->ctf_trace.dir); + g_free(td); +} + +void __attribute__((constructor)) ctf_init(void) { int ret; - ctf_format->name = g_quark_from_static_string("ctf"); + ctf_format.name = g_quark_from_static_string("ctf"); ret = bt_register_format(&ctf_format); assert(!ret); }