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,
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,
};
/**
* SOFTWARE.
*/
+#include <babeltrace/plugin/notification/notification.h>
+
#ifdef __cplusplus
extern "C" {
#endif
* 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
*/
/**
* 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.
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;
};
/**
{
return component_class ? component_class->description->str : NULL;
}
-
enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
if (!component || !destroy) {
- ret = BT_COMPONENT_STATUS_INVAL;
+ ret = BT_COMPONENT_STATUS_INVALID;
goto end;
}
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;
}
enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
if (!component) {
- ret = BT_COMPONENT_STATUS_INVAL;
+ ret = BT_COMPONENT_STATUS_INVALID;
goto end;
}
#include <babeltrace/compiler.h>
#include <babeltrace/plugin/sink-internal.h>
#include <babeltrace/plugin/component-internal.h>
+#include <babeltrace/plugin/notification/notification.h>
static
void bt_component_sink_destroy(struct bt_component *component)
struct bt_component_sink *sink = NULL;
if (!component || !notification) {
- ret = BT_COMPONENT_STATUS_INVAL;
+ ret = BT_COMPONENT_STATUS_INVALID;
goto end;
}
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;
+}