ref.h: doc: fix typo
[babeltrace.git] / lib / plugin-system / filter.c
index 33cceaefc10a94b92202d4e0b7d53d426822908b..2ba611d062d66b756fed766a2f37ab905ff88970 100644 (file)
 
 #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>
+#include <babeltrace/plugin/notification/iterator-internal.h>
 
+enum bt_component_status bt_component_filter_set_iterator_init_cb(
+               struct bt_component *component,
+               bt_component_filter_init_iterator_cb init_iterator)
+{
+       struct bt_component_filter *filter;
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
 
+       if (component->class->type != BT_COMPONENT_TYPE_FILTER ||
+                       !component->initializing) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       filter = container_of(component, struct bt_component_filter, parent);
+       filter->init_iterator = init_iterator;
+end:
+       return ret;
+}
+
+enum bt_component_status bt_component_filter_set_add_iterator_cb(
+               struct bt_component *component,
+               bt_component_filter_add_iterator_cb add_iterator)
+{
+       struct bt_component_filter *filter;
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+
+       if (!component) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
+               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
+               goto end;
+       }
+
+       if (!component->initializing) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       filter = container_of(component, struct bt_component_filter, parent);
+       filter->add_iterator = add_iterator;
+end:
+       return ret;
+}
+
+enum bt_component_status bt_component_filter_set_minimum_input_count(
+               struct bt_component *component,
+               unsigned int minimum)
+{
+       struct bt_component_filter *filter;
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+
+       if (!component) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
+               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
+               goto end;
+       }
+
+       if (!component->initializing) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       filter = container_of(component, struct bt_component_filter, parent);
+       filter->input.min_count = minimum;
+end:
+       return ret;
+}
+
+enum bt_component_status bt_component_filter_set_maximum_input_count(
+               struct bt_component *component,
+               unsigned int maximum)
+{
+       struct bt_component_filter *filter;
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+
+       if (!component) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
+               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
+               goto end;
+       }
+
+       if (!component->initializing) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       filter = container_of(component, struct bt_component_filter, parent);
+       filter->input.max_count = maximum;
+end:
+       return ret;
+}
+
+enum bt_component_status
+bt_component_filter_get_input_count(struct bt_component *component,
+               unsigned int *count)
+{
+       struct bt_component_filter *filter;
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+
+       if (!component || !count) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
+               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
+               goto end;
+       }
+
+       filter = container_of(component, struct bt_component_filter, parent);
+       *count = (unsigned int) filter->input.iterators->len;
+end:
+       return ret;
+}
+
+enum bt_component_status
+bt_component_filter_get_input_iterator(struct bt_component *component,
+               unsigned int input, struct bt_notification_iterator **iterator)
+{
+       struct bt_component_filter *filter;
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+
+       if (!component || !iterator) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
+               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
+               goto end;
+       }
+
+       filter = container_of(component, struct bt_component_filter, parent);
+       if (input >= (unsigned int) filter->input.iterators->len) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       *iterator = bt_get(g_ptr_array_index(filter->input.iterators, input));
+end:
+       return ret;
+}
+
+enum bt_component_status bt_component_filter_add_iterator(
+               struct bt_component *component,
+               struct bt_notification_iterator *iterator)
+{
+       struct bt_component_filter *filter;
+       enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+
+       if (!component || !iterator) {
+               ret = BT_COMPONENT_STATUS_INVALID;
+               goto end;
+       }
+
+       if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) {
+               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
+               goto end;
+       }
+
+       filter = container_of(component, struct bt_component_filter, parent);
+       if (filter->input.iterators->len == filter->input.max_count) {
+               ret = BT_COMPONENT_STATUS_UNSUPPORTED;
+               goto end;
+       }
+
+       if (filter->add_iterator) {
+               ret = filter->add_iterator(component, iterator);
+               if (ret != BT_COMPONENT_STATUS_OK) {
+                       goto end;
+               }
+       }
+
+       g_ptr_array_add(filter->input.iterators, bt_get(iterator));
+end:
+       return ret;
+}
+
+struct bt_notification_iterator *bt_component_filter_create_iterator(
+               struct bt_component *component)
+{
+       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.027197 seconds and 4 git commands to generate.