From 2204c38125cf5079604ad250b1e0890c55ce758b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 20 Apr 2016 12:15:10 -0400 Subject: [PATCH] Add trace moficiation notification handler interface MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- formats/ctf/ir/trace.c | 26 ++++++++++++++++++ include/babeltrace/ctf-ir/trace-internal.h | 1 + include/babeltrace/ctf-ir/trace.h | 31 ++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/formats/ctf/ir/trace.c b/formats/ctf/ir/trace.c index 4d9e97f9..c4889b79 100644 --- a/formats/ctf/ir/trace.c +++ b/formats/ctf/ir/trace.c @@ -46,6 +46,11 @@ #define DEFAULT_IDENTIFIER_SIZE 128 #define DEFAULT_METADATA_STRING_SIZE 4096 +struct notification_handler { + bt_ctf_notification_cb func; + void *data; +}; + static void bt_ctf_trace_destroy(struct bt_object *obj); static @@ -1027,6 +1032,27 @@ end: return ret; } +int bt_ctf_trace_add_notification_handler_cb(struct bt_ctf_trace *trace, + bt_ctf_notification_cb handler, void *handler_data) +{ + int ret = 0; + struct notification_handler *handler_wrapper = + g_new0(struct notification_handler, 1); + + if (!trace || !handler || !handler_wrapper) { + ret = -1; + goto error; + } + + handler_wrapper->func = handler; + handler_wrapper->data = handler_data; + g_ptr_array_add(trace->notification_handlers, handler_wrapper); + return ret; +error: + g_free(handler_wrapper); + return ret; +} + BT_HIDDEN struct bt_ctf_field_type *get_field_type(enum field_type_alias alias) { diff --git a/include/babeltrace/ctf-ir/trace-internal.h b/include/babeltrace/ctf-ir/trace-internal.h index f9091425..c631b97d 100644 --- a/include/babeltrace/ctf-ir/trace-internal.h +++ b/include/babeltrace/ctf-ir/trace-internal.h @@ -65,6 +65,7 @@ struct bt_ctf_trace { * trace is _always_ frozen. */ int valid; + GPtrArray *notification_handlers; /* Array of notification_handler */ }; struct metadata_context { diff --git a/include/babeltrace/ctf-ir/trace.h b/include/babeltrace/ctf-ir/trace.h index ee740039..ccbfe9ef 100644 --- a/include/babeltrace/ctf-ir/trace.h +++ b/include/babeltrace/ctf-ir/trace.h @@ -43,6 +43,18 @@ struct bt_ctf_stream; struct bt_ctf_stream_class; struct bt_ctf_clock; +/** + * Notification handling function type. + * + * A reference must be taken on the notification if the handler has to + * keep ownership of the notification beyond the invocation of the callback. + * + * @param notification Notification to handle + * @param data Handler private data + */ +typedef void (*bt_ctf_notification_cb)( + struct bt_notification *notification, void *data); + /* * bt_ctf_trace_create: create a trace instance. * @@ -338,6 +350,25 @@ extern struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_type( extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace, struct bt_ctf_field_type *packet_header_type); +/* + * bt_ctf_trace_add_notification_handler_cb: set a notification callback + * which will be invoked whenever a trace's schema is modified. + * + * Register a notification handler to a trace. + * + * @param trace Trace instance. + * @param handler Notification handler to invoke on trace xmodification. + * @param handler_data Private data passed to the notification handler. + * + * Returns 0 on success, a negative value on error. + * + * Note: the notification handler will be used to serialize the trace's current + * state on registration. It will then be invoked on any change occuring within + * the trace's hierarchy. + */ +extern int bt_ctf_trace_add_notification_handler_cb(struct bt_ctf_trace *trace, + bt_ctf_notification_cb handler, void *handler_data); + #ifdef __cplusplus } #endif -- 2.34.1