Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: julien.desfossez@polymtl.ca (Julien Desfossez)
Subject: [ltt-dev] [BABELTRACE PATCH] Add parameters to callbacks
Date: Mon, 26 Sep 2011 11:53:56 -0400	[thread overview]
Message-ID: <1317052436-3687-1-git-send-email-julien.desfossez@polymtl.ca> (raw)

This patchs adds a new structure that is passed by the library as the
first parameter of each callback call. As of now it only provides a
pointer to the current event. Now we also pass the pointer to the
private data registered when the callback is added.

Signed-off-by: Julien Desfossez <julien.desfossez at polymtl.ca>
---
 converter/babeltrace-lib.c      |   55 +++++++++++++++++++++++++++++++--------
 include/babeltrace/babeltrace.h |    8 ++++-
 2 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/converter/babeltrace-lib.c b/converter/babeltrace-lib.c
index 80c373f..a1dd64b 100644
--- a/converter/babeltrace-lib.c
+++ b/converter/babeltrace-lib.c
@@ -56,7 +56,8 @@ struct bt_callback {
 	struct bt_dependencies *depends;
 	struct bt_dependencies *weak_depends;
 	struct bt_dependencies *provides;
-	enum bt_cb_ret (*callback)(void *private_data, void *caller_data);
+	enum bt_cb_ret (*callback)(struct bt_ctf_data *ctf_data,
+				   void *private_data);
 };
 
 struct bt_callback_chain {
@@ -138,7 +139,8 @@ struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...)
  */
 int babeltrace_iter_add_callback(struct babeltrace_iter *iter,
 		bt_event_name event, void *private_data, int flags,
-		enum bt_cb_ret (*callback)(void *private_data, void *caller_data),
+		enum bt_cb_ret (*callback)(struct bt_ctf_data *ctf_data,
+					   void *private_data),
 		struct bt_dependencies *depends,
 		struct bt_dependencies *weak_depends,
 		struct bt_dependencies *provides)
@@ -426,7 +428,9 @@ void babeltrace_iter_destroy(struct babeltrace_iter *iter)
 		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);
-			g_array_free(bt_chain->callback, TRUE);
+			if (bt_chain->callback) {
+				g_array_free(bt_chain->callback, TRUE);
+			}
 		}
 		g_array_free(bt_stream_cb->per_id_callbacks, TRUE);
 	}
@@ -464,14 +468,43 @@ end:
 }
 
 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(stdout, "[error] Event id %" PRIu64 " is outside range.\n", id);
+		return NULL;
+	}
+	event = g_ptr_array_index(stream->events_by_id, id);
+	if (!event) {
+		fprintf(stdout, "[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(stdout, "[error] Event id %" PRIu64 " is unknown.\n", id);
+		return NULL;
+	}
+
+	return event;
+}
+
+static
 void process_callbacks(struct babeltrace_iter *iter,
-		struct ctf_stream *stream)
+		       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_data ctf_data;
+
+	ctf_data.event = extract_ctf_stream_event(stream);
 
 	/* process all events callback first */
 	if (iter->main_callbacks.callback) {
@@ -479,13 +512,13 @@ void process_callbacks(struct babeltrace_iter *iter,
 			cb = &g_array_index(iter->main_callbacks.callback, struct bt_callback, i);
 			if (!cb)
 				goto end;
-			ret = cb->callback(NULL, NULL);
+			ret = cb->callback(&ctf_data, cb->private_data);
 			switch (ret) {
-				case BT_CB_OK_STOP:
-				case BT_CB_ERROR_STOP:
-					goto end;
-				default:
-					break;
+			case BT_CB_OK_STOP:
+			case BT_CB_ERROR_STOP:
+				goto end;
+			default:
+				break;
 			}
 		}
 	}
@@ -507,7 +540,7 @@ void process_callbacks(struct babeltrace_iter *iter,
 		cb = &g_array_index(bt_chain->callback, struct bt_callback, i);
 		if (!cb)
 			goto end;
-		ret = cb->callback(NULL, NULL);
+		ret = cb->callback(&ctf_data, cb->private_data);
 		switch (ret) {
 		case BT_CB_OK_STOP:
 		case BT_CB_ERROR_STOP:
diff --git a/include/babeltrace/babeltrace.h b/include/babeltrace/babeltrace.h
index eb15de0..fe5881a 100644
--- a/include/babeltrace/babeltrace.h
+++ b/include/babeltrace/babeltrace.h
@@ -50,6 +50,10 @@ struct trace_collection_pos {
 	} u;
 };
 
+struct bt_ctf_data {
+	struct ctf_stream_event *event;
+};
+
 /*
  * babeltrace_iter_create - Allocate a trace collection iterator.
  *
@@ -162,8 +166,8 @@ void babeltrace_dependencies_destroy(struct bt_dependencies *dep);
  */
 int babeltrace_iter_add_callback(struct babeltrace_iter *iter,
 		bt_event_name event, void *private_data, int flags,
-		enum bt_cb_ret (*callback)(void *private_data,
-					void *caller_data),
+		enum bt_cb_ret (*callback)(struct bt_ctf_data *ctf_data,
+					   void *caller_data),
 		struct bt_dependencies *depends,
 		struct bt_dependencies *weak_depends,
 		struct bt_dependencies *provides);
-- 
1.7.5.4




             reply	other threads:[~2011-09-26 15:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-26 15:53 Julien Desfossez [this message]
2011-09-27  0:55 ` Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1317052436-3687-1-git-send-email-julien.desfossez@polymtl.ca \
    --to=julien.desfossez@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox