Implement the filter base class validation and creation
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 11 Dec 2016 08:55:00 +0000 (03:55 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:08 +0000 (14:09 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
lib/plugin-system/filter.c

index cb60ca540ff44eb561ff18637f674cc5845befb2..2ba611d062d66b756fed766a2f37ab905ff88970 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <babeltrace/compiler.h>
 #include <babeltrace/values.h>
+#include <babeltrace/plugin/input.h>
 #include <babeltrace/plugin/filter-internal.h>
 #include <babeltrace/plugin/component-internal.h>
 #include <babeltrace/plugin/notification/notification.h>
@@ -227,3 +228,77 @@ struct bt_notification_iterator *bt_component_filter_create_iterator(
 {
        return bt_component_create_iterator(component);
 }
+
+static
+void bt_component_filter_destroy(struct bt_component *component)
+{
+       struct bt_component_filter *filter = container_of(component,
+                       struct bt_component_filter, parent);
+
+       component_input_fini(&filter->input);
+}
+
+BT_HIDDEN
+struct bt_component *bt_component_filter_create(
+               struct bt_component_class *class, struct bt_value *params)
+{
+       struct bt_component_filter *filter = NULL;
+       enum bt_component_status ret;
+
+       filter = g_new0(struct bt_component_filter, 1);
+       if (!filter) {
+               goto end;
+       }
+
+       filter->parent.class = bt_get(class);
+       ret = bt_component_init(&filter->parent, bt_component_filter_destroy);
+       if (ret != BT_COMPONENT_STATUS_OK) {
+               goto error;
+       }
+
+       if (component_input_init(&filter->input)) {
+               goto error;
+       }
+end:
+       return filter ? &filter->parent : NULL;
+error:
+       BT_PUT(filter);
+       goto end;
+}
+
+BT_HIDDEN
+enum bt_component_status bt_component_filter_validate(
+               struct bt_component *component)
+{
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       struct bt_component_filter *filter;
+
+       if (!component) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       if (!component->class) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       if (component->class->type != BT_COMPONENT_TYPE_FILTER) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       filter = container_of(component, struct bt_component_filter, parent);
+       if (!filter->init_iterator) {
+               printf_error("Invalid filter component; no iterator initialization callback defined.");
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       ret = component_input_validate(&filter->input);
+       if (ret) {
+               goto end;
+       }
+end:
+       return ret;
+}
This page took 0.025799 seconds and 4 git commands to generate.