From 526fc31a226717a4335176fc49917fa4c56501f0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sun, 11 Dec 2016 03:55:00 -0500 Subject: [PATCH] Implement the filter base class validation and creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- lib/plugin-system/filter.c | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/lib/plugin-system/filter.c b/lib/plugin-system/filter.c index cb60ca540..2ba611d06 100644 --- a/lib/plugin-system/filter.c +++ b/lib/plugin-system/filter.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -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; +} -- 2.34.1