From: Mathieu Desnoyers Date: Mon, 12 Mar 2012 15:12:12 +0000 (-0400) Subject: Fix API: add const qualifiers, privatize struct bt_ctf_event X-Git-Tag: v1.0.0-pre4~5 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=04ae3991741c634481fc3fa069664ae28bbdbaa6 Fix API: add const qualifiers, privatize struct bt_ctf_event Signed-off-by: Mathieu Desnoyers --- diff --git a/converter/babeltrace.c b/converter/babeltrace.c index 54efdfe0..de9b4960 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -25,6 +25,8 @@ #include #include #include +/* TODO: fix object model for format-agnostic callbacks */ +#include #include #include #include diff --git a/formats/ctf/events.c b/formats/ctf/events.c index 0e32d21e..ebc4f1b0 100644 --- a/formats/ctf/events.c +++ b/formats/ctf/events.c @@ -38,7 +38,7 @@ */ __thread int bt_ctf_last_field_error = 0; -struct definition *bt_ctf_get_top_level_scope(struct bt_ctf_event *event, +const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event, enum bt_ctf_scope scope) { struct definition *tmp = NULL; @@ -87,8 +87,8 @@ error: return NULL; } -struct definition *bt_ctf_get_field(struct bt_ctf_event *event, - struct definition *scope, +const struct definition *bt_ctf_get_field(const struct bt_ctf_event *event, + const struct definition *scope, const char *field) { struct definition *def; @@ -118,8 +118,8 @@ struct definition *bt_ctf_get_field(struct bt_ctf_event *event, return NULL; } -struct definition *bt_ctf_get_index(struct bt_ctf_event *event, - struct definition *field, +const struct definition *bt_ctf_get_index(const struct bt_ctf_event *event, + const struct definition *field, unsigned int index) { struct definition *ret = NULL; @@ -138,7 +138,7 @@ struct definition *bt_ctf_get_index(struct bt_ctf_event *event, return ret; } -const char *bt_ctf_event_name(struct bt_ctf_event *event) +const char *bt_ctf_event_name(const struct bt_ctf_event *event) { struct ctf_event *event_class; struct ctf_stream_class *stream_class; @@ -165,8 +165,8 @@ enum ctf_type_id bt_ctf_field_type(const struct definition *def) return CTF_TYPE_UNKNOWN; } -int bt_ctf_get_field_list(struct bt_ctf_event *event, - struct definition *scope, +int bt_ctf_get_field_list(const struct bt_ctf_event *event, + const struct definition *scope, struct definition const * const **list, unsigned int *count) { @@ -178,9 +178,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, goto error; case CTF_TYPE_STRUCT: { - struct definition_struct *def_struct; + const struct definition_struct *def_struct; - def_struct = container_of(scope, struct definition_struct, p); + def_struct = container_of(scope, const struct definition_struct, p); if (!def_struct) goto error; if (def_struct->fields->pdata) { @@ -195,9 +195,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, goto error; case CTF_TYPE_VARIANT: { - struct definition_variant *def_variant; + const struct definition_variant *def_variant; - def_variant = container_of(scope, struct definition_variant, p); + def_variant = container_of(scope, const struct definition_variant, p); if (!def_variant) goto error; if (def_variant->fields->pdata) { @@ -210,9 +210,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, } case CTF_TYPE_ARRAY: { - struct definition_array *def_array; + const struct definition_array *def_array; - def_array = container_of(scope, struct definition_array, p); + def_array = container_of(scope, const struct definition_array, p); if (!def_array) goto error; if (def_array->elems->pdata) { @@ -225,9 +225,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, } case CTF_TYPE_SEQUENCE: { - struct definition_sequence *def_sequence; + const struct definition_sequence *def_sequence; - def_sequence = container_of(scope, struct definition_sequence, p); + def_sequence = container_of(scope, const struct definition_sequence, p); if (!def_sequence) goto error; if (def_sequence->elems->pdata) { @@ -251,7 +251,7 @@ error: return -1; } -uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event *event) +uint64_t bt_ctf_get_timestamp_raw(const struct bt_ctf_event *event) { if (event && event->stream->has_timestamp) return ctf_get_timestamp_raw(event->stream, @@ -260,7 +260,7 @@ uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event *event) return -1ULL; } -uint64_t bt_ctf_get_timestamp(struct bt_ctf_event *event) +uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *event) { if (event && event->stream->has_timestamp) return ctf_get_timestamp(event->stream, diff --git a/formats/ctf/iterator.c b/formats/ctf/iterator.c index 3413dbb0..3597010a 100644 --- a/formats/ctf/iterator.c +++ b/formats/ctf/iterator.c @@ -32,8 +32,8 @@ #include "events-private.h" struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx, - struct bt_iter_pos *begin_pos, - struct bt_iter_pos *end_pos) + const struct bt_iter_pos *begin_pos, + const struct bt_iter_pos *end_pos) { struct bt_ctf_iter *iter; int ret; diff --git a/include/babeltrace/ctf/events-internal.h b/include/babeltrace/ctf/events-internal.h index c78470ec..9f579a06 100644 --- a/include/babeltrace/ctf/events-internal.h +++ b/include/babeltrace/ctf/events-internal.h @@ -28,6 +28,16 @@ #include #include +struct ctf_stream; +struct ctf_stream_event; +/* + * the structure to manipulate events + */ +struct bt_ctf_event { + struct ctf_stream *stream; + struct ctf_stream_event *event; +}; + struct bt_ctf_iter { struct bt_iter parent; struct bt_ctf_event current_ctf_event; /* last read event */ diff --git a/include/babeltrace/ctf/events.h b/include/babeltrace/ctf/events.h index d0ec3e10..80fbdcf2 100644 --- a/include/babeltrace/ctf/events.h +++ b/include/babeltrace/ctf/events.h @@ -25,9 +25,8 @@ #include -struct ctf_stream; -struct ctf_stream_event; struct definition; +struct bt_ctf_event; /* * the top-level scopes in CTF @@ -68,14 +67,6 @@ enum ctf_string_encoding { CTF_STRING_UNKNOWN, }; -/* - * the structure to manipulate events - */ -struct bt_ctf_event { - struct ctf_stream *stream; - struct ctf_stream_event *event; -}; - /* * bt_ctf_get_top_level_scope: return a definition of the top-level scope * @@ -86,49 +77,49 @@ struct bt_ctf_event { * between the enum and the actual definition of top-level scopes. * On error return NULL. */ -struct definition *bt_ctf_get_top_level_scope(struct bt_ctf_event *event, +const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event, enum bt_ctf_scope scope); /* * bt_ctf_event_get_name: returns the name of the event or NULL on error */ -const char *bt_ctf_event_name(struct bt_ctf_event *event); +const char *bt_ctf_event_name(const struct bt_ctf_event *event); /* * bt_ctf_get_timestamp_raw: returns the timestamp of the event as written in * the packet or -1ULL on error */ -uint64_t bt_ctf_get_timestamp_raw(struct bt_ctf_event *event); +uint64_t bt_ctf_get_timestamp_raw(const struct bt_ctf_event *event); /* * bt_ctf_get_timestamp: returns the timestamp of the event offsetted with the * system clock source or -1ULL on error */ -uint64_t bt_ctf_get_timestamp(struct bt_ctf_event *event); +uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *event); /* * bt_ctf_get_field_list: set list pointer to an array of definition * pointers and set count to the number of elements in the array. * Return 0 on success and a negative value on error. */ -int bt_ctf_get_field_list(struct bt_ctf_event *event, - struct definition *scope, +int bt_ctf_get_field_list(const struct bt_ctf_event *event, + const struct definition *scope, struct definition const * const **list, unsigned int *count); /* * bt_ctf_get_field: returns the definition of a specific field */ -struct definition *bt_ctf_get_field(struct bt_ctf_event *event, - struct definition *scope, +const struct definition *bt_ctf_get_field(const struct bt_ctf_event *event, + const struct definition *scope, const char *field); /* * bt_ctf_get_index: if the field is an array or a sequence, return the element * at position index, otherwise return NULL; */ -struct definition *bt_ctf_get_index(struct bt_ctf_event *event, - struct definition *field, +const struct definition *bt_ctf_get_index(const struct bt_ctf_event *event, + const struct definition *field, unsigned int index); /* diff --git a/include/babeltrace/ctf/iterator.h b/include/babeltrace/ctf/iterator.h index 8f9af0e1..71f935a0 100644 --- a/include/babeltrace/ctf/iterator.h +++ b/include/babeltrace/ctf/iterator.h @@ -41,8 +41,8 @@ struct bt_ctf_event; * trace) is the EOF criterion. */ struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx, - struct bt_iter_pos *begin_pos, - struct bt_iter_pos *end_pos); + const struct bt_iter_pos *begin_pos, + const struct bt_iter_pos *end_pos); /* * bt_ctf_get_iter - get iterator from ctf iterator. diff --git a/include/babeltrace/iterator-internal.h b/include/babeltrace/iterator-internal.h index ea47745a..8000875e 100644 --- a/include/babeltrace/iterator-internal.h +++ b/include/babeltrace/iterator-internal.h @@ -30,7 +30,7 @@ struct bt_iter { struct ptr_heap *stream_heap; struct bt_context *ctx; - struct bt_iter_pos *end_pos; + const struct bt_iter_pos *end_pos; }; /* @@ -46,8 +46,8 @@ struct bt_iter { * trace) is the EOF criterion. */ struct bt_iter *bt_iter_create(struct bt_context *ctx, - struct bt_iter_pos *begin_pos, - struct bt_iter_pos *end_pos); + const struct bt_iter_pos *begin_pos, + const struct bt_iter_pos *end_pos); /* * bt_iter_destroy - Free a trace collection iterator. @@ -56,8 +56,8 @@ void bt_iter_destroy(struct bt_iter *iter); int bt_iter_init(struct bt_iter *iter, struct bt_context *ctx, - struct bt_iter_pos *begin_pos, - struct bt_iter_pos *end_pos); + const struct bt_iter_pos *begin_pos, + const struct bt_iter_pos *end_pos); void bt_iter_fini(struct bt_iter *iter); #endif /* _BABELTRACE_ITERATOR_INTERNAL_H */ diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h index dd116f10..9addebb2 100644 --- a/include/babeltrace/types.h +++ b/include/babeltrace/types.h @@ -507,15 +507,15 @@ void append_scope_path(const char *path, GArray *q); /* * Lookup helpers. */ -struct definition *lookup_definition(struct definition *definition, +struct definition *lookup_definition(const struct definition *definition, const char *field_name); -struct definition_integer *lookup_integer(struct definition *definition, +struct definition_integer *lookup_integer(const struct definition *definition, const char *field_name, int signedness); -struct definition_enum *lookup_enum(struct definition *definition, +struct definition_enum *lookup_enum(const struct definition *definition, const char *field_name, int signedness); -struct definition *lookup_variant(struct definition *definition, +struct definition *lookup_variant(const struct definition *definition, const char *field_name); static inline diff --git a/lib/iterator.c b/lib/iterator.c index 0af15140..e50846f4 100644 --- a/lib/iterator.c +++ b/lib/iterator.c @@ -430,8 +430,8 @@ end: int bt_iter_init(struct bt_iter *iter, struct bt_context *ctx, - struct bt_iter_pos *begin_pos, - struct bt_iter_pos *end_pos) + const struct bt_iter_pos *begin_pos, + const struct bt_iter_pos *end_pos) { int i, stream_id; int ret = 0; @@ -496,8 +496,8 @@ error_heap_init: } struct bt_iter *bt_iter_create(struct bt_context *ctx, - struct bt_iter_pos *begin_pos, - struct bt_iter_pos *end_pos) + const struct bt_iter_pos *begin_pos, + const struct bt_iter_pos *end_pos) { struct bt_iter *iter; int ret; diff --git a/types/types.c b/types/types.c index d3c204ae..450c93ba 100644 --- a/types/types.c +++ b/types/types.c @@ -147,7 +147,7 @@ end: } static struct definition_scope * - get_definition_scope(struct definition *definition) + get_definition_scope(const struct definition *definition) { return definition->scope; } @@ -600,7 +600,7 @@ void free_definition_scope(struct definition_scope *scope) g_free(scope); } -struct definition *lookup_definition(struct definition *definition, +struct definition *lookup_definition(const struct definition *definition, const char *field_name) { struct definition_scope *scope = get_definition_scope(definition); @@ -612,7 +612,7 @@ struct definition *lookup_definition(struct definition *definition, scope); } -struct definition_integer *lookup_integer(struct definition *definition, +struct definition_integer *lookup_integer(const struct definition *definition, const char *field_name, int signedness) { @@ -630,7 +630,7 @@ struct definition_integer *lookup_integer(struct definition *definition, return lookup_integer; } -struct definition_enum *lookup_enum(struct definition *definition, +struct definition_enum *lookup_enum(const struct definition *definition, const char *field_name, int signedness) { @@ -648,7 +648,7 @@ struct definition_enum *lookup_enum(struct definition *definition, return lookup_enum; } -struct definition *lookup_variant(struct definition *definition, +struct definition *lookup_variant(const struct definition *definition, const char *field_name) { struct definition *lookup;