API fix: Move callbacks to CTF plugin
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 17 Feb 2012 19:39:27 +0000 (14:39 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 17 Feb 2012 19:40:23 +0000 (14:40 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 files changed:
formats/ctf/Makefile.am
formats/ctf/callbacks.c [new file with mode: 0644]
formats/ctf/events.c
include/Makefile.am
include/babeltrace/babeltrace.h
include/babeltrace/callbacks-internal.h [deleted file]
include/babeltrace/ctf/callbacks-internal.h [new file with mode: 0644]
include/babeltrace/ctf/callbacks.h [new file with mode: 0644]
include/babeltrace/ctf/events-internal.h
include/babeltrace/iterator-internal.h
lib/Makefile.am
lib/callbacks.c [deleted file]
lib/iterator.c

index cf01be4baf65bee8448b027ce7cfbb2acec4a41a..f9468fcbfb0d21be9c1f61bd2912957f5513ce81 100644 (file)
@@ -6,7 +6,8 @@ lib_LTLIBRARIES = libctf.la
 
 libctf_la_SOURCES = \
        ctf.c \
-       events.c
+       events.c \
+       callbacks.c
 
 libctf_la_LIBADD = \
        types/libctf-types.la \
diff --git a/formats/ctf/callbacks.c b/formats/ctf/callbacks.c
new file mode 100644 (file)
index 0000000..f4e0a14
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+ * callbacks.c
+ *
+ * Babeltrace Library
+ *
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 <babeltrace/babeltrace.h>
+#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/context.h>
+#include <babeltrace/context-internal.h>
+#include <babeltrace/ctf-ir/metadata.h>
+#include <babeltrace/iterator-internal.h>
+#include <babeltrace/ctf/events.h>
+#include <babeltrace/ctf/events-internal.h>
+#include <babeltrace/ctf/callbacks-internal.h>
+#include <inttypes.h>
+
+static
+struct bt_dependencies *_babeltrace_dependencies_create(const char *first,
+                                                       va_list ap)
+{
+       const char *iter;
+       struct bt_dependencies *dep;
+
+       dep = g_new0(struct bt_dependencies, 1);
+       dep->refcount = 1;
+       dep->deps = g_array_new(FALSE, TRUE, sizeof(GQuark));
+       iter = first;
+       while (iter) {
+               GQuark q = g_quark_from_string(iter);
+               g_array_append_val(dep->deps, q);
+               iter = va_arg(ap, const char *);
+       }
+       return dep;
+}
+
+struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...)
+{
+       va_list ap;
+       struct bt_dependencies *deps;
+
+       va_start(ap, first);
+       deps = _babeltrace_dependencies_create(first, ap);
+       va_end(ap);
+       return deps;
+}
+
+/*
+ * bt_ctf_iter_add_callback: Add a callback to CTF iterator.
+ */
+int bt_ctf_iter_add_callback(struct bt_ctf_iter *iter,
+               bt_intern_str event, void *private_data, int flags,
+               enum bt_cb_ret (*callback)(struct bt_ctf_event *ctf_data,
+                                          void *private_data),
+               struct bt_dependencies *depends,
+               struct bt_dependencies *weak_depends,
+               struct bt_dependencies *provides)
+{
+       int i, stream_id;
+       gpointer *event_id_ptr;
+       unsigned long event_id;
+       struct trace_collection *tc = iter->parent.ctx->tc;
+
+       for (i = 0; i < tc->array->len; i++) {
+               struct ctf_trace *tin;
+               struct trace_descriptor *td_read;
+
+               td_read = g_ptr_array_index(tc->array, i);
+               tin = container_of(td_read, struct ctf_trace, parent);
+
+               for (stream_id = 0; stream_id < tin->streams->len; stream_id++) {
+                       struct ctf_stream_class *stream;
+                       struct bt_stream_callbacks *bt_stream_cb = NULL;
+                       struct bt_callback_chain *bt_chain = NULL;
+                       struct bt_callback new_callback;
+
+                       stream = g_ptr_array_index(tin->streams, stream_id);
+
+                       if (stream_id >= iter->callbacks->len) {
+                               g_array_set_size(iter->callbacks, stream->stream_id + 1);
+                       }
+                       bt_stream_cb = &g_array_index(iter->callbacks,
+                                       struct bt_stream_callbacks, stream->stream_id);
+                       if (!bt_stream_cb->per_id_callbacks) {
+                               bt_stream_cb->per_id_callbacks = g_array_new(FALSE, TRUE,
+                                               sizeof(struct bt_callback_chain));
+                       }
+
+                       if (event) {
+                               /* find the event id */
+                               event_id_ptr = g_hash_table_lookup(stream->event_quark_to_id,
+                                               (gconstpointer) (unsigned long) event);
+                               /* event not found in this stream class */
+                               if (!event_id_ptr) {
+                                       fprintf(stderr, "event not found\n");
+                                       continue;
+                               }
+                               event_id = (uint64_t)(unsigned long) *event_id_ptr;
+
+                               /* find or create the bt_callback_chain for this event */
+                               if (event_id >= bt_stream_cb->per_id_callbacks->len) {
+                                       g_array_set_size(bt_stream_cb->per_id_callbacks, event_id + 1);
+                               }
+                               bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks,
+                                               struct bt_callback_chain, event_id);
+                               if (!bt_chain->callback) {
+                                       bt_chain->callback = g_array_new(FALSE, TRUE,
+                                               sizeof(struct bt_callback));
+                               }
+                       } else {
+                               /* callback for all events */
+                               if (!iter->main_callbacks.callback) {
+                                       iter->main_callbacks.callback = g_array_new(FALSE, TRUE,
+                                                       sizeof(struct bt_callback));
+                               }
+                               bt_chain = &iter->main_callbacks;
+                       }
+
+                       new_callback.private_data = private_data;
+                       new_callback.flags = flags;
+                       new_callback.callback = callback;
+                       new_callback.depends = depends;
+                       new_callback.weak_depends = weak_depends;
+                       new_callback.provides = provides;
+
+                       /* TODO : take care of priority, for now just FIFO */
+                       g_array_append_val(bt_chain->callback, new_callback);
+               }
+       }
+
+       return 0;
+}
+
+static
+struct ctf_stream_event *extract_ctf_stream_event(struct ctf_stream *stream)
+{
+       struct ctf_stream_class *stream_class = stream->stream_class;
+       struct ctf_event *event_class;
+       struct ctf_stream_event *event;
+       uint64_t id = stream->event_id;
+
+       if (id >= stream_class->events_by_id->len) {
+               fprintf(stderr, "[error] Event id %" PRIu64 " is outside range.\n", id);
+               return NULL;
+       }
+       event = g_ptr_array_index(stream->events_by_id, id);
+       if (!event) {
+               fprintf(stderr, "[error] Event id %" PRIu64 " is unknown.\n", id);
+               return NULL;
+       }
+       event_class = g_ptr_array_index(stream_class->events_by_id, id);
+       if (!event_class) {
+               fprintf(stderr, "[error] Event id %" PRIu64 " is unknown.\n", id);
+               return NULL;
+       }
+
+       return event;
+}
+
+void process_callbacks(struct bt_ctf_iter *iter,
+                      struct ctf_stream *stream)
+{
+       struct bt_stream_callbacks *bt_stream_cb;
+       struct bt_callback_chain *bt_chain;
+       struct bt_callback *cb;
+       int i;
+       enum bt_cb_ret ret;
+       struct bt_ctf_event ctf_data;
+
+       ctf_data.event = extract_ctf_stream_event(stream);
+       ctf_data.stream = stream;
+
+       /* process all events callback first */
+       if (iter->main_callbacks.callback) {
+               for (i = 0; i < iter->main_callbacks.callback->len; i++) {
+                       cb = &g_array_index(iter->main_callbacks.callback, struct bt_callback, i);
+                       if (!cb)
+                               goto end;
+                       ret = cb->callback(&ctf_data, cb->private_data);
+                       switch (ret) {
+                       case BT_CB_OK_STOP:
+                       case BT_CB_ERROR_STOP:
+                               goto end;
+                       default:
+                               break;
+                       }
+               }
+       }
+
+       /* process per event callbacks */
+       bt_stream_cb = &g_array_index(iter->callbacks,
+                       struct bt_stream_callbacks, stream->stream_id);
+       if (!bt_stream_cb || !bt_stream_cb->per_id_callbacks)
+               goto end;
+
+       if (stream->event_id >= bt_stream_cb->per_id_callbacks->len)
+               goto end;
+       bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks,
+                       struct bt_callback_chain, stream->event_id);
+       if (!bt_chain || !bt_chain->callback)
+               goto end;
+
+       for (i = 0; i < bt_chain->callback->len; i++) {
+               cb = &g_array_index(bt_chain->callback, struct bt_callback, i);
+               if (!cb)
+                       goto end;
+               ret = cb->callback(&ctf_data, cb->private_data);
+               switch (ret) {
+               case BT_CB_OK_STOP:
+               case BT_CB_ERROR_STOP:
+                       goto end;
+               default:
+                       break;
+               }
+       }
+
+end:
+       return;
+}
index 27643fcbc61f513ce6d7cc0b021e7d6aea4bd053..8ecb7c487f74384847b6f02aced03035c7ce3ee1 100644 (file)
@@ -49,11 +49,39 @@ struct bt_ctf_iter *bt_ctf_iter_create(struct bt_context *ctx,
                g_free(iter);
                return NULL;
        }
+       iter->callbacks = g_array_new(0, 1, sizeof(struct bt_stream_callbacks));
+       iter->recalculate_dep_graph = 0;
+       iter->main_callbacks.callback = NULL;
+       iter->dep_gc = g_ptr_array_new();
        return iter;
 }
 
 void bt_ctf_iter_destroy(struct bt_ctf_iter *iter)
 {
+       struct bt_stream_callbacks *bt_stream_cb;
+       struct bt_callback_chain *bt_chain;
+       int i, j;
+
+       /* free all events callbacks */
+       if (iter->main_callbacks.callback)
+               g_array_free(iter->main_callbacks.callback, TRUE);
+
+       /* free per-event callbacks */
+       for (i = 0; i < iter->callbacks->len; i++) {
+               bt_stream_cb = &g_array_index(iter->callbacks,
+                               struct bt_stream_callbacks, i);
+               if (!bt_stream_cb || !bt_stream_cb->per_id_callbacks)
+                       continue;
+               for (j = 0; j < bt_stream_cb->per_id_callbacks->len; j++) {
+                       bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks,
+                                       struct bt_callback_chain, j);
+                       if (bt_chain->callback) {
+                               g_array_free(bt_chain->callback, TRUE);
+                       }
+               }
+               g_array_free(bt_stream_cb->per_id_callbacks, TRUE);
+       }
+
        bt_iter_fini(&iter->parent);
        g_free(iter);
 }
@@ -77,10 +105,10 @@ struct bt_ctf_event *bt_ctf_iter_read_event(struct bt_ctf_iter *iter)
        ret->event = g_ptr_array_index(ret->stream->events_by_id,
                        ret->stream->event_id);
 
-       if (ret->stream->stream_id > iter->parent.callbacks->len)
+       if (ret->stream->stream_id > iter->callbacks->len)
                goto end;
 
-       process_callbacks(&iter->parent, ret->stream);
+       process_callbacks(iter, ret->stream);
 
 end:
        return ret;
index f4e410d53e33e31539a8f55435bed5b407b40549..e675f9e3724111cef25466ec8f7188b0e42b2275 100644 (file)
@@ -8,13 +8,13 @@ babeltraceinclude_HEADERS = \
        babeltrace/list.h
 
 babeltracectfinclude_HEADERS = \
-       babeltrace/ctf/events.h
+       babeltrace/ctf/events.h \
+       babeltrace/ctf/callbacks.h
 
 noinst_HEADERS = \
        babeltrace/align.h \
        babeltrace/babeltrace-internal.h \
        babeltrace/bitfield.h \
-       babeltrace/callbacks-internal.h \
        babeltrace/compiler.h \
        babeltrace/context-internal.h \
        babeltrace/iterator-internal.h \
@@ -25,4 +25,5 @@ noinst_HEADERS = \
        babeltrace/ctf/metadata.h \
        babeltrace/ctf-text/types.h \
        babeltrace/ctf/types.h \
+       babeltrace/ctf/callbacks-internal.h \
        babeltrace/trace-handle-internal.h
index e533397ca06be3da5c918a5200d5ca8a1effd4b1..83917c249408c8e8338cf9e1f763f27e1c485ba0 100644 (file)
 #include <babeltrace/trace-handle.h>
 #include <babeltrace/ctf/events.h>
 
-/* Forward declarations */
-struct bt_iter;
-struct bt_dependencies;
-
-enum bt_cb_ret {
-       BT_CB_OK                = 0,
-       BT_CB_OK_STOP           = 1,
-       BT_CB_ERROR_STOP        = 2,
-       BT_CB_ERROR_CONTINUE    = 3,
-};
-
-/*
- * Receives a variable number of strings as parameter, ended with NULL.
- */
-struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...);
-
-/*
- * struct bt_dependencies must be destroyed explicitly if not passed as
- * parameter to a bt_iter_add_callback().
- */
-void babeltrace_dependencies_destroy(struct bt_dependencies *dep);
-
-/*
- * bt_iter_add_callback: Add a callback to iterator.
- *
- * @iter: trace collection iterator (input)
- * @event: event to target. 0 for all events.
- * @private_data: private data pointer to pass to the callback
- * @flags: specific flags controlling the behavior of this callback
- *         (or'd).
- *            
- * @callback: function pointer to call
- * @depends: struct bt_dependency detailing the required computation results.
- *           Ends with 0.
- * @weak_depends: struct bt_dependency detailing the optional computation
- *                results that can be optionally consumed by this
- *                callback.
- * @provides: struct bt_dependency detailing the computation results
- *            provided by this callback.
- *            Ends with 0.
- *
- * "depends", "weak_depends" and "provides" memory is handled by the
- * babeltrace library after this call succeeds or fails. These objects
- * can still be used by the caller until the babeltrace iterator is
- * destroyed, but they belong to the babeltrace library.
- *
- * (note to implementor: we need to keep a gptrarray of struct
- * bt_dependencies to "garbage collect" in struct bt_iter, and
- * dependencies need to have a refcount to handle the case where they
- * would be passed to more than one iterator. Upon iterator detroy, we
- * iterate on all the gc ptrarray and decrement the refcounts, freeing
- * if we reach 0.)
- * (note to implementor: we calculate the dependency graph when
- * bt_iter_read_event() is executed after a
- * bt_iter_add_callback(). Beware that it is valid to create/add
- * callbacks/read/add more callbacks/read some more.)
- */
-int bt_iter_add_callback(struct bt_iter *iter,
-               bt_intern_str event, void *private_data, int flags,
-               enum bt_cb_ret (*callback)(struct bt_ctf_event *ctf_data,
-                                          void *caller_data),
-               struct bt_dependencies *depends,
-               struct bt_dependencies *weak_depends,
-               struct bt_dependencies *provides);
-
-/*
- * For flags parameter above.
- */
-enum {
-       BT_FLAGS_FREE_PRIVATE_DATA      = (1 << 0),
-};
-
 #endif /* _BABELTRACE_H */
diff --git a/include/babeltrace/callbacks-internal.h b/include/babeltrace/callbacks-internal.h
deleted file mode 100644 (file)
index c125706..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-#ifndef _BABELTRACE_CALLBACKS_INTERNAL_H
-#define _BABELTRACE_CALLBACKS_INTERNAL_H
-
-/*
- * BabelTrace
- *
- * Internal callbacks header
- *
- * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
- *
- * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * 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 <glib.h>
-#include <babeltrace/ctf/events.h>
-
-struct bt_callback {
-       int prio;               /* Callback order priority. Lower first. Dynamically assigned from dependency graph. */
-       void *private_data;
-       int flags;
-       struct bt_dependencies *depends;
-       struct bt_dependencies *weak_depends;
-       struct bt_dependencies *provides;
-       enum bt_cb_ret (*callback)(struct bt_ctf_event *ctf_data,
-                                  void *private_data);
-};
-
-struct bt_callback_chain {
-       GArray *callback;       /* Array of struct bt_callback, ordered by priority */
-};
-
-/*
- * per id callbacks need to be per stream class because event ID vs
- * event name mapping can vary from stream to stream.
- */
-struct bt_stream_callbacks {
-       GArray *per_id_callbacks;       /* Array of struct bt_callback_chain */
-};
-
-struct bt_dependencies {
-       GArray *deps;                   /* Array of GQuarks */
-       int refcount;                   /* free when decremented to 0 */
-};
-
-void process_callbacks(struct bt_iter *iter,
-       struct ctf_stream *stream);
-
-#endif /* _BABELTRACE_CALLBACKS_INTERNAL_H */
diff --git a/include/babeltrace/ctf/callbacks-internal.h b/include/babeltrace/ctf/callbacks-internal.h
new file mode 100644 (file)
index 0000000..611851a
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef _BABELTRACE_CALLBACKS_INTERNAL_H
+#define _BABELTRACE_CALLBACKS_INTERNAL_H
+
+/*
+ * BabelTrace
+ *
+ * Internal callbacks header
+ *
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 <glib.h>
+#include <babeltrace/ctf/events.h>
+
+struct bt_callback {
+       int prio;               /* Callback order priority. Lower first. Dynamically assigned from dependency graph. */
+       void *private_data;
+       int flags;
+       struct bt_dependencies *depends;
+       struct bt_dependencies *weak_depends;
+       struct bt_dependencies *provides;
+       enum bt_cb_ret (*callback)(struct bt_ctf_event *ctf_data,
+                                  void *private_data);
+};
+
+struct bt_callback_chain {
+       GArray *callback;       /* Array of struct bt_callback, ordered by priority */
+};
+
+/*
+ * per id callbacks need to be per stream class because event ID vs
+ * event name mapping can vary from stream to stream.
+ */
+struct bt_stream_callbacks {
+       GArray *per_id_callbacks;       /* Array of struct bt_callback_chain */
+};
+
+struct bt_dependencies {
+       GArray *deps;                   /* Array of GQuarks */
+       int refcount;                   /* free when decremented to 0 */
+};
+
+void process_callbacks(struct bt_ctf_iter *iter, struct ctf_stream *stream);
+
+#endif /* _BABELTRACE_CALLBACKS_INTERNAL_H */
diff --git a/include/babeltrace/ctf/callbacks.h b/include/babeltrace/ctf/callbacks.h
new file mode 100644 (file)
index 0000000..c0986f9
--- /dev/null
@@ -0,0 +1,100 @@
+#ifndef _BABELTRACE_CTF_CALLBACKS_H
+#define _BABELTRACE_CTF_CALLBACKS_H
+
+/*
+ * BabelTrace
+ *
+ * CTF events API
+ *
+ * Copyright 2011-2012 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *         Julien Desfossez <julien.desfossez@efficios.com>
+ *
+ * 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 <babeltrace/format.h>
+
+/* Forward declarations */
+struct bt_ctf_iter;
+struct bt_dependencies;
+
+enum bt_cb_ret {
+       BT_CB_OK                = 0,
+       BT_CB_OK_STOP           = 1,
+       BT_CB_ERROR_STOP        = 2,
+       BT_CB_ERROR_CONTINUE    = 3,
+};
+
+/*
+ * Receives a variable number of strings as parameter, ended with NULL.
+ */
+struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...);
+
+/*
+ * struct bt_dependencies must be destroyed explicitly if not passed as
+ * parameter to a bt_iter_add_callback().
+ */
+void babeltrace_dependencies_destroy(struct bt_dependencies *dep);
+
+/*
+ * bt_iter_add_callback: Add a callback to iterator.
+ *
+ * @iter: trace collection iterator (input)
+ * @event: event to target. 0 for all events.
+ * @private_data: private data pointer to pass to the callback
+ * @flags: specific flags controlling the behavior of this callback
+ *         (or'd).
+ *            
+ * @callback: function pointer to call
+ * @depends: struct bt_dependency detailing the required computation results.
+ *           Ends with 0.
+ * @weak_depends: struct bt_dependency detailing the optional computation
+ *                results that can be optionally consumed by this
+ *                callback.
+ * @provides: struct bt_dependency detailing the computation results
+ *            provided by this callback.
+ *            Ends with 0.
+ *
+ * "depends", "weak_depends" and "provides" memory is handled by the
+ * babeltrace library after this call succeeds or fails. These objects
+ * can still be used by the caller until the babeltrace iterator is
+ * destroyed, but they belong to the babeltrace library.
+ *
+ * (note to implementor: we need to keep a gptrarray of struct
+ * bt_dependencies to "garbage collect" in struct bt_iter, and
+ * dependencies need to have a refcount to handle the case where they
+ * would be passed to more than one iterator. Upon iterator detroy, we
+ * iterate on all the gc ptrarray and decrement the refcounts, freeing
+ * if we reach 0.)
+ * (note to implementor: we calculate the dependency graph when
+ * bt_iter_read_event() is executed after a
+ * bt_iter_add_callback(). Beware that it is valid to create/add
+ * callbacks/read/add more callbacks/read some more.)
+ */
+int bt_ctf_iter_add_callback(struct bt_ctf_iter *iter,
+               bt_intern_str event, void *private_data, int flags,
+               enum bt_cb_ret (*callback)(struct bt_ctf_event *ctf_data,
+                                          void *caller_data),
+               struct bt_dependencies *depends,
+               struct bt_dependencies *weak_depends,
+               struct bt_dependencies *provides);
+
+/*
+ * For flags parameter above.
+ */
+enum {
+       BT_FLAGS_FREE_PRIVATE_DATA      = (1 << 0),
+};
+
+#endif /*_BABELTRACE_CTF_CALLBACKS_H */
index deff10585a5d4cc6e79426682316b1884426491e..c78470ecab9fce91e4071984bc5470595c7f9200 100644 (file)
  */
 
 #include <babeltrace/iterator-internal.h>
+#include <babeltrace/ctf/callbacks.h>
+#include <babeltrace/ctf/callbacks-internal.h>
+#include <glib.h>
 
 struct bt_ctf_iter {
        struct bt_iter parent;
        struct bt_ctf_event current_ctf_event;  /* last read event */
+       GArray *callbacks;                              /* Array of struct bt_stream_callbacks */
+       struct bt_callback_chain main_callbacks;        /* For all events */
+       /*
+        * Flag indicating if dependency graph needs to be recalculated.
+        * Set by bt_iter_add_callback(), and checked (and
+        * cleared) by upon entry into bt_iter_read_event().
+        * bt_iter_read_event() is responsible for calling dep
+        * graph calculation if it sees this flag set.
+        */
+       int recalculate_dep_graph;
+       /*
+        * Array of pointers to struct bt_dependencies, for garbage
+        * collection. We're not using a linked list here because each
+        * struct bt_dependencies can belong to more than one
+        * bt_iter.
+        */
+       GPtrArray *dep_gc;
 };
 
 #endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */
index c9b5d60716f43d7eee77b580a58147f35f994b8d..626a7a0009b16377406bc4e51d99425e6eda4e7e 100644 (file)
@@ -21,7 +21,6 @@
  * all copies or substantial portions of the Software.
  */
 
-#include <babeltrace/callbacks-internal.h>
 #include <babeltrace/ctf/events.h>
 
 /*
@@ -32,23 +31,6 @@ struct bt_iter {
        struct ptr_heap *stream_heap;
        struct bt_context *ctx;
        struct bt_iter_pos *end_pos;
-       GArray *callbacks;                              /* Array of struct bt_stream_callbacks */
-       struct bt_callback_chain main_callbacks;        /* For all events */
-       /*
-        * Flag indicating if dependency graph needs to be recalculated.
-        * Set by bt_iter_add_callback(), and checked (and
-        * cleared) by upon entry into bt_iter_read_event().
-        * bt_iter_read_event() is responsible for calling dep
-        * graph calculation if it sees this flag set.
-        */
-       int recalculate_dep_graph;
-       /*
-        * Array of pointers to struct bt_dependencies, for garbage
-        * collection. We're not using a linked list here because each
-        * struct bt_dependencies can belong to more than one
-        * bt_iter.
-        */
-       GPtrArray *dep_gc;
 };
 
 int bt_iter_init(struct bt_iter *iter,
index 5d069a96d9dd702a76eb685767e4afa7ab995cdb..db6db39830c66d480d96faa16f5a2934833d0202 100644 (file)
@@ -5,7 +5,6 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
 lib_LTLIBRARIES = libbabeltrace.la
 
 libbabeltrace_la_SOURCES = babeltrace.c \
-                          callbacks.c \
                           iterator.c \
                           context.c \
                           trace-handle.c \
diff --git a/lib/callbacks.c b/lib/callbacks.c
deleted file mode 100644 (file)
index fa212c9..0000000
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * callbacks.c
- *
- * Babeltrace Library
- *
- * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
- *
- * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * 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 <babeltrace/babeltrace.h>
-#include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/callbacks-internal.h>
-#include <babeltrace/context.h>
-#include <babeltrace/context-internal.h>
-#include <babeltrace/ctf-ir/metadata.h>
-#include <babeltrace/iterator-internal.h>
-#include <babeltrace/ctf/events.h>
-#include <inttypes.h>
-
-static
-struct bt_dependencies *_babeltrace_dependencies_create(const char *first,
-                                                       va_list ap)
-{
-       const char *iter;
-       struct bt_dependencies *dep;
-
-       dep = g_new0(struct bt_dependencies, 1);
-       dep->refcount = 1;
-       dep->deps = g_array_new(FALSE, TRUE, sizeof(GQuark));
-       iter = first;
-       while (iter) {
-               GQuark q = g_quark_from_string(iter);
-               g_array_append_val(dep->deps, q);
-               iter = va_arg(ap, const char *);
-       }
-       return dep;
-}
-
-struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...)
-{
-       va_list ap;
-       struct bt_dependencies *deps;
-
-       va_start(ap, first);
-       deps = _babeltrace_dependencies_create(first, ap);
-       va_end(ap);
-       return deps;
-}
-
-/*
- * bt_iter_add_callback: Add a callback to iterator.
- */
-int bt_iter_add_callback(struct bt_iter *iter,
-               bt_intern_str event, void *private_data, int flags,
-               enum bt_cb_ret (*callback)(struct bt_ctf_event *ctf_data,
-                                          void *private_data),
-               struct bt_dependencies *depends,
-               struct bt_dependencies *weak_depends,
-               struct bt_dependencies *provides)
-{
-       int i, stream_id;
-       gpointer *event_id_ptr;
-       unsigned long event_id;
-       struct trace_collection *tc = iter->ctx->tc;
-
-       for (i = 0; i < tc->array->len; i++) {
-               struct ctf_trace *tin;
-               struct trace_descriptor *td_read;
-
-               td_read = g_ptr_array_index(tc->array, i);
-               tin = container_of(td_read, struct ctf_trace, parent);
-
-               for (stream_id = 0; stream_id < tin->streams->len; stream_id++) {
-                       struct ctf_stream_class *stream;
-                       struct bt_stream_callbacks *bt_stream_cb = NULL;
-                       struct bt_callback_chain *bt_chain = NULL;
-                       struct bt_callback new_callback;
-
-                       stream = g_ptr_array_index(tin->streams, stream_id);
-
-                       if (stream_id >= iter->callbacks->len) {
-                               g_array_set_size(iter->callbacks, stream->stream_id + 1);
-                       }
-                       bt_stream_cb = &g_array_index(iter->callbacks,
-                                       struct bt_stream_callbacks, stream->stream_id);
-                       if (!bt_stream_cb->per_id_callbacks) {
-                               bt_stream_cb->per_id_callbacks = g_array_new(FALSE, TRUE,
-                                               sizeof(struct bt_callback_chain));
-                       }
-
-                       if (event) {
-                               /* find the event id */
-                               event_id_ptr = g_hash_table_lookup(stream->event_quark_to_id,
-                                               (gconstpointer) (unsigned long) event);
-                               /* event not found in this stream class */
-                               if (!event_id_ptr) {
-                                       fprintf(stderr, "event not found\n");
-                                       continue;
-                               }
-                               event_id = (uint64_t)(unsigned long) *event_id_ptr;
-
-                               /* find or create the bt_callback_chain for this event */
-                               if (event_id >= bt_stream_cb->per_id_callbacks->len) {
-                                       g_array_set_size(bt_stream_cb->per_id_callbacks, event_id + 1);
-                               }
-                               bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks,
-                                               struct bt_callback_chain, event_id);
-                               if (!bt_chain->callback) {
-                                       bt_chain->callback = g_array_new(FALSE, TRUE,
-                                               sizeof(struct bt_callback));
-                               }
-                       } else {
-                               /* callback for all events */
-                               if (!iter->main_callbacks.callback) {
-                                       iter->main_callbacks.callback = g_array_new(FALSE, TRUE,
-                                                       sizeof(struct bt_callback));
-                               }
-                               bt_chain = &iter->main_callbacks;
-                       }
-
-                       new_callback.private_data = private_data;
-                       new_callback.flags = flags;
-                       new_callback.callback = callback;
-                       new_callback.depends = depends;
-                       new_callback.weak_depends = weak_depends;
-                       new_callback.provides = provides;
-
-                       /* TODO : take care of priority, for now just FIFO */
-                       g_array_append_val(bt_chain->callback, new_callback);
-               }
-       }
-
-       return 0;
-}
-
-static
-struct ctf_stream_event *extract_ctf_stream_event(struct ctf_stream *stream)
-{
-       struct ctf_stream_class *stream_class = stream->stream_class;
-       struct ctf_event *event_class;
-       struct ctf_stream_event *event;
-       uint64_t id = stream->event_id;
-
-       if (id >= stream_class->events_by_id->len) {
-               fprintf(stderr, "[error] Event id %" PRIu64 " is outside range.\n", id);
-               return NULL;
-       }
-       event = g_ptr_array_index(stream->events_by_id, id);
-       if (!event) {
-               fprintf(stderr, "[error] Event id %" PRIu64 " is unknown.\n", id);
-               return NULL;
-       }
-       event_class = g_ptr_array_index(stream_class->events_by_id, id);
-       if (!event_class) {
-               fprintf(stderr, "[error] Event id %" PRIu64 " is unknown.\n", id);
-               return NULL;
-       }
-
-       return event;
-}
-
-void process_callbacks(struct bt_iter *iter,
-                      struct ctf_stream *stream)
-{
-       struct bt_stream_callbacks *bt_stream_cb;
-       struct bt_callback_chain *bt_chain;
-       struct bt_callback *cb;
-       int i;
-       enum bt_cb_ret ret;
-       struct bt_ctf_event ctf_data;
-
-       ctf_data.event = extract_ctf_stream_event(stream);
-       ctf_data.stream = stream;
-
-       /* process all events callback first */
-       if (iter->main_callbacks.callback) {
-               for (i = 0; i < iter->main_callbacks.callback->len; i++) {
-                       cb = &g_array_index(iter->main_callbacks.callback, struct bt_callback, i);
-                       if (!cb)
-                               goto end;
-                       ret = cb->callback(&ctf_data, cb->private_data);
-                       switch (ret) {
-                       case BT_CB_OK_STOP:
-                       case BT_CB_ERROR_STOP:
-                               goto end;
-                       default:
-                               break;
-                       }
-               }
-       }
-
-       /* process per event callbacks */
-       bt_stream_cb = &g_array_index(iter->callbacks,
-                       struct bt_stream_callbacks, stream->stream_id);
-       if (!bt_stream_cb || !bt_stream_cb->per_id_callbacks)
-               goto end;
-
-       if (stream->event_id >= bt_stream_cb->per_id_callbacks->len)
-               goto end;
-       bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks,
-                       struct bt_callback_chain, stream->event_id);
-       if (!bt_chain || !bt_chain->callback)
-               goto end;
-
-       for (i = 0; i < bt_chain->callback->len; i++) {
-               cb = &g_array_index(bt_chain->callback, struct bt_callback, i);
-               if (!cb)
-                       goto end;
-               ret = cb->callback(&ctf_data, cb->private_data);
-               switch (ret) {
-               case BT_CB_OK_STOP:
-               case BT_CB_ERROR_STOP:
-                       goto end;
-               default:
-                       break;
-               }
-       }
-
-end:
-       return;
-}
index bf87193a3b64f8bdf491fc5ba309f4ca4ae80e82..3dbe878846ab3699af938d2e3a98c202eca8d7b3 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <stdlib.h>
 #include <babeltrace/babeltrace.h>
-#include <babeltrace/callbacks-internal.h>
 #include <babeltrace/context.h>
 #include <babeltrace/context-internal.h>
 #include <babeltrace/iterator-internal.h>
@@ -445,10 +444,6 @@ int bt_iter_init(struct bt_iter *iter,
 
        iter->stream_heap = g_new(struct ptr_heap, 1);
        iter->end_pos = end_pos;
-       iter->callbacks = g_array_new(0, 1, sizeof(struct bt_stream_callbacks));
-       iter->recalculate_dep_graph = 0;
-       iter->main_callbacks.callback = NULL;
-       iter->dep_gc = g_ptr_array_new();
        bt_context_get(ctx);
        iter->ctx = ctx;
 
@@ -524,35 +519,10 @@ struct bt_iter *bt_iter_create(struct bt_context *ctx,
 
 void bt_iter_fini(struct bt_iter *iter)
 {
-       struct bt_stream_callbacks *bt_stream_cb;
-       struct bt_callback_chain *bt_chain;
-       int i, j;
-
        if (iter->stream_heap) {
                heap_free(iter->stream_heap);
                g_free(iter->stream_heap);
        }
-
-       /* free all events callbacks */
-       if (iter->main_callbacks.callback)
-               g_array_free(iter->main_callbacks.callback, TRUE);
-
-       /* free per-event callbacks */
-       for (i = 0; i < iter->callbacks->len; i++) {
-               bt_stream_cb = &g_array_index(iter->callbacks,
-                               struct bt_stream_callbacks, i);
-               if (!bt_stream_cb || !bt_stream_cb->per_id_callbacks)
-                       continue;
-               for (j = 0; j < bt_stream_cb->per_id_callbacks->len; j++) {
-                       bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks,
-                                       struct bt_callback_chain, j);
-                       if (bt_chain->callback) {
-                               g_array_free(bt_chain->callback, TRUE);
-                       }
-               }
-               g_array_free(bt_stream_cb->per_id_callbacks, TRUE);
-       }
-
        bt_context_put(iter->ctx);
 }
 
This page took 0.057557 seconds and 4 git commands to generate.