From 70bd0a12b09ce7f233189cf07e090fda593ebc48 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Fri, 12 Aug 2011 20:15:28 -0400 Subject: [PATCH] Export the babeltrace API in babeltrace.h Rename the previous babeltrace.h as babeltrace-internal.h [ Edit by Mathieu Desnoyers: API cleanup. ] Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- configure.ac | 3 + converter/babeltrace-api.h | 93 ------------------ converter/babeltrace-lib.c | 25 ++++- converter/babeltrace-log.c | 2 +- converter/babeltrace.c | 2 +- formats/bt-dummy/bt-dummy.c | 2 +- formats/ctf-text/ctf-text.c | 2 +- formats/ctf/ctf.c | 2 +- formats/ctf/metadata/ctf-lexer.l | 2 +- formats/ctf/metadata/ctf-parser-test.c | 2 +- formats/ctf/metadata/ctf-parser.y | 2 +- .../metadata/ctf-visitor-generate-io-struct.c | 2 +- .../ctf/metadata/ctf-visitor-parent-links.c | 2 +- .../metadata/ctf-visitor-semantic-validator.c | 2 +- formats/ctf/metadata/ctf-visitor-xml.c | 2 +- formats/ctf/types/string.c | 2 +- include/Makefile.am | 4 +- include/babeltrace/babeltrace-internal.h | 31 ++++++ include/babeltrace/babeltrace.h | 98 +++++++++++++++---- include/babeltrace/ctf-text/types.h | 2 +- include/babeltrace/ctf/types.h | 2 +- types/types.c | 2 +- 22 files changed, 153 insertions(+), 133 deletions(-) delete mode 100644 converter/babeltrace-api.h create mode 100644 include/babeltrace/babeltrace-internal.h diff --git a/configure.ac b/configure.ac index 7764b150..1ed70d71 100644 --- a/configure.ac +++ b/configure.ac @@ -48,6 +48,9 @@ LIBS="$LIBS $GMODULE_LIBS" PACKAGE_CFLAGS="$GMODULE_CFLAGS -Wall -Wformat" AC_SUBST(PACKAGE_CFLAGS) +babeltraceincludedir="${includedir}" +AC_SUBST(babeltraceincludedir) + AC_CONFIG_FILES([ Makefile types/Makefile diff --git a/converter/babeltrace-api.h b/converter/babeltrace-api.h deleted file mode 100644 index d16352ab..00000000 --- a/converter/babeltrace-api.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef _BABELTRACE_LIB_H -#define _BABELTRACE_LIB_H - -/* - * BabelTrace API - * - * 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 - -/* - * struct babeltrace_iter: data structure representing an iterator on a trace - * collection. - */ -struct babeltrace_iter { - struct ptr_heap *stream_heap; - struct trace_collection *tc; -}; - -struct babeltrace_iter_pos { - GPtrArray *pos; /* struct babeltrace_iter_stream_pos */ -}; - -struct babeltrace_iter_stream_pos { - struct stream_pos parent; - ssize_t offset; - size_t cur_index; -}; - -/* - * Initialization/teardown. - */ -struct babeltrace_iter *babeltrace_iter_create(struct trace_collection *tc); -void babeltrace_iter_destroy(struct babeltrace_iter *iter); - -/* - * Move within the trace. - */ -/* - * babeltrace_iter_next: Move stream position to the next event. - * - * Returns 0 on success, a negative value on error - */ -int babeltrace_iter_next(struct babeltrace_iter *iter); - -/* Get the current position for each stream of the trace */ -struct babeltrace_iter_pos * -babeltrace_iter_get_pos(struct babeltrace_iter *iter); - -/* The position needs to be freed after use */ -void babeltrace_iter_free_pos(struct babeltrace_iter_pos *pos); - -/* Seek the trace to the position */ -int babeltrace_iter_seek_pos(struct babeltrace_iter *iter, - struct babeltrace_iter_pos *pos); - -/* - * babeltrace_iter_seek_time: Seek the trace to the given timestamp. - * - * Return EOF if timestamp is after the last event of the trace. - * Return other negative value for other errors. - * Return 0 for success. - */ -int babeltrace_iter_seek_time(struct babeltrace_iter *iter, - uint64_t timestamp); - -/* - * babeltrace_iter_read_event: Read the current event data. - * - * @iter: trace iterator (input) - * @stream: stream containing event at current position (output) - * @event: current event (output) - * Return 0 on success, negative error value on error. - */ -int babeltrace_iter_read_event(struct babeltrace_iter *iter, - struct ctf_stream **stream, - struct ctf_stream_event **event); - -#endif /* _BABELTRACE_LIB_H */ diff --git a/converter/babeltrace-lib.c b/converter/babeltrace-lib.c index 656bae86..ee34d283 100644 --- a/converter/babeltrace-lib.c +++ b/converter/babeltrace-lib.c @@ -22,14 +22,35 @@ #include #include #include -#include +#include #include #include #include #include #include +#include +#include +#include +#include -#include "babeltrace-api.h" +/* + * struct babeltrace_iter: data structure representing an iterator on a trace + * collection. + */ +struct babeltrace_iter { + struct ptr_heap *stream_heap; + struct trace_collection *tc; +}; + +struct babeltrace_iter_pos { + GPtrArray *pos; /* struct babeltrace_iter_stream_pos */ +}; + +struct babeltrace_iter_stream_pos { + struct stream_pos parent; + ssize_t offset; + size_t cur_index; +}; static int stream_read_event(struct ctf_file_stream *sin) { diff --git a/converter/babeltrace-log.c b/converter/babeltrace-log.c index 16f9a179..9ca2b479 100644 --- a/converter/babeltrace-log.c +++ b/converter/babeltrace-log.c @@ -35,7 +35,7 @@ #include #include -#include +#include #include #define USEC_PER_SEC 1000000UL diff --git a/converter/babeltrace.c b/converter/babeltrace.c index ded493ce..5c372425 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -20,7 +20,7 @@ #define _XOPEN_SOURCE 700 #include -#include +#include #include #include #include diff --git a/formats/bt-dummy/bt-dummy.c b/formats/bt-dummy/bt-dummy.c index 221b51ff..41cfb741 100644 --- a/formats/bt-dummy/bt-dummy.c +++ b/formats/bt-dummy/bt-dummy.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c index ac35cfb7..f1ddbaf5 100644 --- a/formats/ctf-text/ctf-text.c +++ b/formats/ctf-text/ctf-text.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index b39b8690..95a581fa 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/formats/ctf/metadata/ctf-lexer.l b/formats/ctf/metadata/ctf-lexer.l index 7e81add5..7a0e73fe 100644 --- a/formats/ctf/metadata/ctf-lexer.l +++ b/formats/ctf/metadata/ctf-lexer.l @@ -18,7 +18,7 @@ */ #include -#include +#include #include "ctf-scanner.h" #include "ctf-parser.h" #include "ctf-ast.h" diff --git a/formats/ctf/metadata/ctf-parser-test.c b/formats/ctf/metadata/ctf-parser-test.c index 9d102515..e84dc128 100644 --- a/formats/ctf/metadata/ctf-parser-test.c +++ b/formats/ctf/metadata/ctf-parser-test.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include "ctf-scanner.h" #include "ctf-parser.h" diff --git a/formats/ctf/metadata/ctf-parser.y b/formats/ctf/metadata/ctf-parser.y index 1d40d04f..d216cd0e 100644 --- a/formats/ctf/metadata/ctf-parser.y +++ b/formats/ctf/metadata/ctf-parser.y @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include "ctf-scanner.h" #include "ctf-parser.h" #include "ctf-ast.h" diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index 6fbc7c02..725235d1 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/formats/ctf/metadata/ctf-visitor-parent-links.c b/formats/ctf/metadata/ctf-visitor-parent-links.c index 0258fd63..3dea11a0 100644 --- a/formats/ctf/metadata/ctf-visitor-parent-links.c +++ b/formats/ctf/metadata/ctf-visitor-parent-links.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include "ctf-scanner.h" #include "ctf-parser.h" diff --git a/formats/ctf/metadata/ctf-visitor-semantic-validator.c b/formats/ctf/metadata/ctf-visitor-semantic-validator.c index b89f7bd7..eab4391b 100644 --- a/formats/ctf/metadata/ctf-visitor-semantic-validator.c +++ b/formats/ctf/metadata/ctf-visitor-semantic-validator.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include "ctf-scanner.h" #include "ctf-parser.h" diff --git a/formats/ctf/metadata/ctf-visitor-xml.c b/formats/ctf/metadata/ctf-visitor-xml.c index c47bd27d..56974c38 100644 --- a/formats/ctf/metadata/ctf-visitor-xml.c +++ b/formats/ctf/metadata/ctf-visitor-xml.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include "ctf-scanner.h" #include "ctf-parser.h" diff --git a/formats/ctf/types/string.c b/formats/ctf/types/string.c index 682bd76d..3b54a2df 100644 --- a/formats/ctf/types/string.c +++ b/formats/ctf/types/string.c @@ -18,7 +18,7 @@ * all copies or substantial portions of the Software. */ -#include +#include #include #include /* C99 limits */ #include diff --git a/include/Makefile.am b/include/Makefile.am index 7239596c..a5f54542 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,6 +1,8 @@ +babeltraceinclude_HEADERS = babeltrace/babeltrace.h + noinst_HEADERS = \ babeltrace/align.h \ - babeltrace/babeltrace.h \ + babeltrace/babeltrace-internal.h \ babeltrace/bitfield.h \ babeltrace/compiler.h \ babeltrace/format.h \ diff --git a/include/babeltrace/babeltrace-internal.h b/include/babeltrace/babeltrace-internal.h new file mode 100644 index 00000000..7c02948a --- /dev/null +++ b/include/babeltrace/babeltrace-internal.h @@ -0,0 +1,31 @@ +#ifndef _BABELTRACE_INTERNAL_H +#define _BABELTRACE_INTERNAL_H + +#include +#include + +extern int babeltrace_verbose, babeltrace_debug; + +#define printf_verbose(fmt, args...) \ + do { \ + if (babeltrace_verbose) \ + printf("[verbose] " fmt, ## args); \ + } while (0) + +#define printf_debug(fmt, args...) \ + do { \ + if (babeltrace_debug) \ + printf("[debug] " fmt, ## args); \ + } while (0) + +struct trace_descriptor; +struct trace_collection { + GPtrArray *array; +}; + +int convert_trace(struct trace_descriptor *td_write, + struct trace_collection *trace_collection_read); + +extern int opt_field_names; + +#endif diff --git a/include/babeltrace/babeltrace.h b/include/babeltrace/babeltrace.h index 8091ac44..c8b0581a 100644 --- a/include/babeltrace/babeltrace.h +++ b/include/babeltrace/babeltrace.h @@ -1,31 +1,87 @@ #ifndef _BABELTRACE_H #define _BABELTRACE_H -#include -#include +/* + * BabelTrace API + * + * 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. + */ -extern int babeltrace_verbose, babeltrace_debug; +/* Forward declarations */ +struct babeltrace_iter; +struct babeltrace_iter_pos; +struct babeltrace_iter_stream_pos; +struct trace_collection; +struct ctf_stream_event; +struct ctf_stream; -#define printf_verbose(fmt, args...) \ - do { \ - if (babeltrace_verbose) \ - printf("[verbose] " fmt, ## args); \ - } while (0) +/* + * babeltrace_iter_create - Allocate a trace collection iterator. + */ +struct babeltrace_iter *babeltrace_iter_create(struct trace_collection *tc); -#define printf_debug(fmt, args...) \ - do { \ - if (babeltrace_debug) \ - printf("[debug] " fmt, ## args); \ - } while (0) +/* + * babeltrace_iter_destroy - Free a trace collection iterator. + */ +void babeltrace_iter_destroy(struct babeltrace_iter *iter); -struct trace_descriptor; -struct trace_collection { - GPtrArray *array; -}; +/* + * babeltrace_iter_next: Move trace collection position to the next event. + * + * Returns 0 on success, a negative value on error + */ +int babeltrace_iter_next(struct babeltrace_iter *iter); -int convert_trace(struct trace_descriptor *td_write, - struct trace_collection *trace_collection_read); +/* + * babeltrace_iter_get_pos - Get the current trace collection position. + * + * The position returned by this function needs to be freed by + * babeltrace_iter_free_pos after use. + */ +struct babeltrace_iter_pos * + babeltrace_iter_get_pos(struct babeltrace_iter *iter); -extern int opt_field_names; +/* + * babeltrace_iter_free_pos - Free the position. + */ +void babeltrace_iter_free_pos(struct babeltrace_iter_pos *pos); -#endif +/* + * babeltrace_iter_seek_pos - Seek the trace collection to the position. + */ +int babeltrace_iter_seek_pos(struct babeltrace_iter *iter, + struct babeltrace_iter_pos *pos); + +/* + * babeltrace_iter_seek_time: Seek the trace collection to the given timestamp. + * + * Return EOF if timestamp is after the last event of the trace collection. + * Return other negative value for other errors. + * Return 0 for success. + */ +int babeltrace_iter_seek_time(struct babeltrace_iter *iter, + uint64_t timestamp); + +/* + * babeltrace_iter_read_event: Read the iterator's current event data. + * + * @iter: trace collection iterator (input) + * @stream: stream containing event at current position (output) + * @event: current event (output) + * Return 0 on success, negative error value on error. + */ +int babeltrace_iter_read_event(struct babeltrace_iter *iter, + struct ctf_stream **stream, + struct ctf_stream_event **event); + +#endif /* _BABELTRACE_H */ diff --git a/include/babeltrace/ctf-text/types.h b/include/babeltrace/ctf-text/types.h index 1b05523e..400e62c6 100644 --- a/include/babeltrace/ctf-text/types.h +++ b/include/babeltrace/ctf-text/types.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/babeltrace/ctf/types.h b/include/babeltrace/ctf/types.h index 8d57ec74..58352ef7 100644 --- a/include/babeltrace/ctf/types.h +++ b/include/babeltrace/ctf/types.h @@ -20,7 +20,7 @@ */ #include -#include +#include #include #include #include diff --git a/types/types.c b/types/types.c index 11e91b02..4e96f443 100644 --- a/types/types.c +++ b/types/types.c @@ -21,7 +21,7 @@ */ #include -#include +#include #include #include #include -- 2.34.1