From: Jérémie Galarneau Date: Thu, 25 Feb 2016 01:37:39 +0000 (-0500) Subject: Add bt_component_sink_register_notification_type X-Git-Tag: v2.0.0-pre1~823 X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=30d619df191d89101727d0f6d5f4181d2df7653f;p=babeltrace.git Add bt_component_sink_register_notification_type Signed-off-by: Jérémie Galarneau --- diff --git a/include/babeltrace/plugin/component.h b/include/babeltrace/plugin/component.h index 3a59d627..5462b7b1 100644 --- a/include/babeltrace/plugin/component.h +++ b/include/babeltrace/plugin/component.h @@ -43,7 +43,7 @@ enum bt_component_status { BT_COMPONENT_STATUS_NOMEM = -4, /** Invalid arguments. */ - BT_COMPONENT_STATUS_INVAL = -3, + BT_COMPONENT_STATUS_INVALID = -3, /** Unsupported component feature. */ BT_COMPONENT_STATUS_UNSUPPORTED = -2, diff --git a/include/babeltrace/plugin/notification/notification.h b/include/babeltrace/plugin/notification/notification.h index 7b661b78..21a7328d 100644 --- a/include/babeltrace/plugin/notification/notification.h +++ b/include/babeltrace/plugin/notification/notification.h @@ -39,17 +39,25 @@ struct bt_notification; enum bt_notification_type { BT_NOTIFICATION_TYPE_UNKNOWN = -1, + /** + * All types of notifications (used to register to notification + * delivery). + */ + BT_NOTIFICATION_TYPE_ALL = 0, + /** Event delivery notification, see event.h */ - BT_NOTIFICATION_TYPE_EVENT = 0, + BT_NOTIFICATION_TYPE_EVENT = 1, /** New stream packet notification, see packet.h */ - BT_NOTIFICATION_TYPE_NEW_PACKET = 1, + BT_NOTIFICATION_TYPE_NEW_PACKET = 2, /** End of stream packet notification, see packet.h */ - BT_NOTIFICATION_TYPE_END_PACKET = 1, + BT_NOTIFICATION_TYPE_END_PACKET = 3, /** End of trace notification, see eot.h */ - BT_NOTIFICATION_TYPE_END_OF_TRACE = 2, + BT_NOTIFICATION_TYPE_END_OF_TRACE = 4, + + BT_NOTIFICATION_TYPE_NR, }; /** diff --git a/include/babeltrace/plugin/plugin-system.h b/include/babeltrace/plugin/plugin-system.h index 28bed36c..d3fe3329 100644 --- a/include/babeltrace/plugin/plugin-system.h +++ b/include/babeltrace/plugin/plugin-system.h @@ -30,6 +30,8 @@ * SOFTWARE. */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -101,28 +103,27 @@ extern enum bt_component_status bt_component_set_destroy_cb( * A notification iterator's private data, deinitialization, next, and get * callbacks must be set by this function. * - * @param component Component instance + * @param source Source component instance * @param iterator Notification iterator instance */ typedef enum bt_component_status (*bt_component_source_init_iterator_cb)( - struct bt_component *component, - struct bt_notification_iterator *iterator); + struct bt_component *, struct bt_notification_iterator *); /** * Set a source component's iterator initialization function. * - * @param component Component instance + * @param source Source component instance * @param init_iterator Notification iterator initialization callback */ extern enum bt_component_status -bt_component_source_set_iterator_init_cb(struct bt_component *component, +bt_component_source_set_iterator_init_cb(struct bt_component *source, bt_component_source_init_iterator_cb init_iterator); /** bt_component_sink */ /** * Notification handling function type. * - * @param component Component instance + * @param sink Sink component instance * @param notificattion Notification to handle * @returns One of #bt_component_status values */ @@ -132,14 +133,29 @@ typedef enum bt_component_status (*bt_component_sink_handle_notification_cb)( /** * Set a sink component's notification handling callback. * - * @param component Component instance + * @param sink Sink component instance * @param handle_notification Notification handling callback * @returns One of #bt_component_status values */ extern enum bt_component_status -bt_component_sink_set_handle_notification_cb(struct bt_component *component, +bt_component_sink_set_handle_notification_cb(struct bt_component *sink, bt_component_sink_handle_notification_cb handle_notification); +/** + * Register a sink to a given notification type. + * + * A sink is always registered to notifications of type + * BT_NOTIFICATION_TYPE_EVENT. However, it may opt to receive any (or all) + * other notification type(s). + * + * @param sink Sink component instance. + * @param type One of #bt_notification_type + * @returns One of #bt_component_status + */ +extern enum bt_component_status +bt_component_sink_register_notification_type(struct bt_component *sink, + enum bt_notification_type type); + /** bt_component_notification_iterator */ /** * Function returning an iterator's current notification. diff --git a/include/babeltrace/plugin/sink-internal.h b/include/babeltrace/plugin/sink-internal.h index ec6f9c2f..047d6d1c 100644 --- a/include/babeltrace/plugin/sink-internal.h +++ b/include/babeltrace/plugin/sink-internal.h @@ -38,11 +38,13 @@ struct bt_component_sink_class { struct bt_component_class parent; }; +typedef uint32_t notification_mask_t; struct bt_component_sink { struct bt_component parent; /* Component implementation callbacks */ bt_component_sink_handle_notification_cb handle_notification; + notification_mask_t registered_notifications_mask; }; /** diff --git a/lib/plugin-system/component-class.c b/lib/plugin-system/component-class.c index 9f5ccb06..70dd6389 100644 --- a/lib/plugin-system/component-class.c +++ b/lib/plugin-system/component-class.c @@ -102,4 +102,3 @@ const char *bt_component_class_get_description( { return component_class ? component_class->description->str : NULL; } - diff --git a/lib/plugin-system/component.c b/lib/plugin-system/component.c index 483788ac..9c4121ba 100644 --- a/lib/plugin-system/component.c +++ b/lib/plugin-system/component.c @@ -84,7 +84,7 @@ enum bt_component_status bt_component_init(struct bt_component *component, enum bt_component_status ret = BT_COMPONENT_STATUS_OK; if (!component || !destroy) { - ret = BT_COMPONENT_STATUS_INVAL; + ret = BT_COMPONENT_STATUS_INVALID; goto end; } @@ -160,7 +160,7 @@ enum bt_component_status bt_component_set_name(struct bt_component *component, enum bt_component_status ret = BT_COMPONENT_STATUS_OK; if (!component || !name || name[0] == '\0') { - ret = BT_COMPONENT_STATUS_INVAL; + ret = BT_COMPONENT_STATUS_INVALID; goto end; } @@ -187,7 +187,7 @@ bt_component_set_private_data(struct bt_component *component, enum bt_component_status ret = BT_COMPONENT_STATUS_OK; if (!component) { - ret = BT_COMPONENT_STATUS_INVAL; + ret = BT_COMPONENT_STATUS_INVALID; goto end; } diff --git a/lib/plugin-system/sink.c b/lib/plugin-system/sink.c index 81f6cba6..e37105b1 100644 --- a/lib/plugin-system/sink.c +++ b/lib/plugin-system/sink.c @@ -29,6 +29,7 @@ #include #include #include +#include static void bt_component_sink_destroy(struct bt_component *component) @@ -72,7 +73,7 @@ enum bt_component_status bt_component_sink_handle_notification( struct bt_component_sink *sink = NULL; if (!component || !notification) { - ret = BT_COMPONENT_STATUS_INVAL; + ret = BT_COMPONENT_STATUS_INVALID; goto end; } @@ -87,3 +88,35 @@ enum bt_component_status bt_component_sink_handle_notification( end: return ret; } + +enum bt_component_status bt_component_sink_register_notification_type( + struct bt_component *component, enum bt_notification_type type) +{ + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + struct bt_component_sink *sink = NULL; + + if (!component) { + ret = BT_COMPONENT_STATUS_INVALID; + goto end; + } + + if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { + ret = BT_COMPONENT_STATUS_UNSUPPORTED; + goto end; + } + + if (type <= BT_NOTIFICATION_TYPE_UNKNOWN || + type >= BT_NOTIFICATION_TYPE_NR) { + ret = BT_COMPONENT_STATUS_INVALID; + goto end; + } + sink = container_of(component, struct bt_component_sink, parent); + if (type == BT_NOTIFICATION_TYPE_ALL) { + sink->registered_notifications_mask = ~(notification_mask_t) 0; + } else { + sink->registered_notifications_mask |= + (notification_mask_t) 1 << type; + } +end: + return ret; +}