Add bt_component_sink_register_notification_type
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 25 Feb 2016 01:37:39 +0000 (20:37 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 16:57:26 +0000 (12:57 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/plugin/component.h
include/babeltrace/plugin/notification/notification.h
include/babeltrace/plugin/plugin-system.h
include/babeltrace/plugin/sink-internal.h
lib/plugin-system/component-class.c
lib/plugin-system/component.c
lib/plugin-system/sink.c

index 3a59d627358edba1ec2b117e3cad452fe6114a05..5462b7b18d55dc5ff5ee201e2b157d0cbde387ab 100644 (file)
@@ -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,
index 7b661b78a6938a76cebc7d92ee9371c86621e721..21a7328d9544d95e2a9936c32f9d398ad22e5081 100644 (file)
@@ -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,
 };
 
 /**
index 28bed36c37e6021e2cfacecbcbac3f646d9e879a..d3fe33290b2dc8c069aca3a57521247358db1e77 100644 (file)
@@ -30,6 +30,8 @@
  * SOFTWARE.
  */
 
+#include <babeltrace/plugin/notification/notification.h>
+
 #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.
index ec6f9c2f1a42620f4d115f8c266f6e1d4ad2d1f8..047d6d1cc9d4a28137bf02079afb2d7e3254e15c 100644 (file)
@@ -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;
 };
 
 /**
index 9f5ccb0634fdf6fdf9c3a116fbe3b5b0bb033e56..70dd638965dc4576b7622846635266685fa76ac9 100644 (file)
@@ -102,4 +102,3 @@ const char *bt_component_class_get_description(
 {
        return component_class ? component_class->description->str : NULL;
 }
-
index 483788acd6be9381f7fa3cb156d09ddd105f118f..9c4121ba699dcdc9bb18de053abdf1847d4bd218 100644 (file)
@@ -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;
        }
 
index 81f6cba61cd8a19135a6fd49ce7ba1edf396c805..e37105b1b60713ae942e1ca8fb2ed3699da3c30e 100644 (file)
@@ -29,6 +29,7 @@
 #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)
@@ -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;
+}
This page took 0.029707 seconds and 4 git commands to generate.