Move component iterator creation to base component class
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 24 Nov 2016 18:58:34 +0000 (13:58 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:07 +0000 (14:09 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/plugin/component-internal.h
lib/plugin-system/component.c
lib/plugin-system/filter.c
lib/plugin-system/source.c

index 4239ac4dc80038bd954e11e1e31a94be12afae96..9cc39b3bbf2bd133310c32bcaf180f6752e95a74 100644 (file)
@@ -60,4 +60,8 @@ enum bt_component_status bt_component_init(struct bt_component *component,
 BT_HIDDEN
 enum bt_component_type bt_component_get_type(struct bt_component *component);
 
+BT_HIDDEN
+struct bt_notification_iterator *bt_component_create_iterator(
+               struct bt_component *component);
+
 #endif /* BABELTRACE_PLUGIN_COMPONENT_INTERNAL_H */
index 643e17ad21b3ad909862f556d35aae55e00fbff8..e722089ef58c7f5e0bc1792bec7c5efc67cc886b 100644 (file)
@@ -29,6 +29,8 @@
 #include <babeltrace/plugin/component.h>
 #include <babeltrace/plugin/component-internal.h>
 #include <babeltrace/plugin/source-internal.h>
+#include <babeltrace/plugin/filter-internal.h>
+#include <babeltrace/plugin/notification/iterator-internal.h>
 #include <babeltrace/plugin/sink-internal.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/compiler.h>
@@ -100,6 +102,75 @@ enum bt_component_type bt_component_get_type(struct bt_component *component)
        return component ? component->class->type : BT_COMPONENT_TYPE_UNKNOWN;
 }
 
+BT_HIDDEN
+struct bt_notification_iterator *bt_component_create_iterator(
+               struct bt_component *component)
+{
+       enum bt_notification_iterator_status ret_iterator;
+       enum bt_component_type component_type;
+       struct bt_notification_iterator *iterator = NULL;
+
+       if (!component) {
+               goto error;
+       }
+
+       component_type = bt_component_get_type(component);
+       if (component_type != BT_COMPONENT_TYPE_SOURCE &&
+                       component_type != BT_COMPONENT_TYPE_FILTER) {
+               /* Unsupported operation. */
+               goto error;
+       }
+
+       iterator = bt_notification_iterator_create(component);
+       if (!iterator) {
+               goto error;
+       }
+
+       switch (component_type) {
+       case BT_COMPONENT_TYPE_SOURCE:
+       {
+               struct bt_component_source *source;
+               enum bt_component_status ret_component;
+
+               source = container_of(component, struct bt_component_source, parent);
+               assert(source->init_iterator);
+               ret_component = source->init_iterator(component, iterator);
+               if (ret_component != BT_COMPONENT_STATUS_OK) {
+                       goto error;
+               }
+               break;
+
+               break;
+       }
+       case BT_COMPONENT_TYPE_FILTER:
+       {
+               struct bt_component_filter *filter;
+               enum bt_component_status ret_component;
+
+               filter = container_of(component, struct bt_component_filter, parent);
+               assert(filter->init_iterator);
+               ret_component = filter->init_iterator(component, iterator);
+               if (ret_component != BT_COMPONENT_STATUS_OK) {
+                       goto error;
+               }
+               break;
+       }
+       default:
+               /* Unreachable. */
+               assert(0);
+       }
+
+       ret_iterator = bt_notification_iterator_validate(iterator);
+       if (ret_iterator != BT_NOTIFICATION_ITERATOR_STATUS_OK) {
+               goto error;
+       }
+
+       return iterator;
+error:
+       BT_PUT(iterator);
+       return iterator;
+}
+
 struct bt_component *bt_component_create(
                struct bt_component_class *component_class, const char *name,
                struct bt_value *params)
index 5ba7405169deb8d36174277e87c9f65a55cc0566..cb60ca540ff44eb561ff18637f674cc5845befb2 100644 (file)
@@ -225,38 +225,5 @@ end:
 struct bt_notification_iterator *bt_component_filter_create_iterator(
                struct bt_component *component)
 {
-       enum bt_component_status ret_component;
-       enum bt_notification_iterator_status ret_iterator;
-       struct bt_component_filter *filter;
-       struct bt_notification_iterator *iterator = NULL;
-
-       if (!component) {
-               goto end;
-       }
-
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
-               goto end;
-       }
-
-       iterator = bt_notification_iterator_create(component);
-       if (!iterator) {
-               goto end;
-       }
-
-       filter = container_of(component, struct bt_component_filter, parent);
-       assert(filter->init_iterator);
-       ret_component = filter->init_iterator(component, iterator);
-       if (ret_component != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
-       ret_iterator = bt_notification_iterator_validate(iterator);
-       if (ret_iterator != BT_NOTIFICATION_ITERATOR_STATUS_OK) {
-               goto error;
-       }
-end:
-       return iterator;
-error:
-       BT_PUT(iterator);
-       return iterator;
+       return bt_component_create_iterator(component);
 }
index 51b32f83349ddd6eb78a5ad2ab40014c2193e1a3..7a19bc5500d0e5f840b783c5a8e731939014e246 100644 (file)
@@ -108,38 +108,5 @@ end:
 struct bt_notification_iterator *bt_component_source_create_iterator(
                struct bt_component *component)
 {
-       enum bt_component_status ret_component;
-       enum bt_notification_iterator_status ret_iterator;
-       struct bt_component_source *source;
-       struct bt_notification_iterator *iterator = NULL;
-
-       if (!component) {
-               goto end;
-       }
-
-       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) {
-               goto end;
-       }
-
-       iterator = bt_notification_iterator_create(component);
-       if (!iterator) {
-               goto end;
-       }
-
-       source = container_of(component, struct bt_component_source, parent);
-       assert(source->init_iterator);
-       ret_component = source->init_iterator(component, iterator);
-       if (ret_component != BT_COMPONENT_STATUS_OK) {
-               goto error;
-       }
-
-       ret_iterator = bt_notification_iterator_validate(iterator);
-       if (ret_iterator != BT_NOTIFICATION_ITERATOR_STATUS_OK) {
-               goto error;
-       }
-end:
-       return iterator;
-error:
-       BT_PUT(iterator);
-       return iterator;
+       return bt_component_create_iterator(component);
 }
This page took 0.029246 seconds and 4 git commands to generate.