#include <babeltrace/compiler.h>
#include <babeltrace/values.h>
-#include <babeltrace/component/input.h>
#include <babeltrace/component/component-filter-internal.h>
#include <babeltrace/component/component-internal.h>
#include <babeltrace/component/component-class-internal.h>
#include <babeltrace/component/notification/notification.h>
#include <babeltrace/component/notification/iterator-internal.h>
-enum bt_component_status bt_component_filter_set_minimum_input_count(
- struct bt_component *component,
- unsigned int minimum)
+BT_HIDDEN
+void bt_component_filter_destroy(struct bt_component *component)
{
- 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_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) {
- ret = BT_COMPONENT_STATUS_UNSUPPORTED;
- goto end;
- }
+BT_HIDDEN
+struct bt_component *bt_component_filter_create(
+ struct bt_component_class *class, struct bt_value *params)
+{
+ struct bt_component_filter *filter = NULL;
- if (!component->initializing) {
- ret = BT_COMPONENT_STATUS_INVALID;
+ filter = g_new0(struct bt_component_filter, 1);
+ if (!filter) {
goto end;
}
- filter = container_of(component, struct bt_component_filter, parent);
- filter->input.min_count = minimum;
end:
- return ret;
+ return filter ? &filter->parent : NULL;
}
-enum bt_component_status bt_component_filter_set_maximum_input_count(
- struct bt_component *component,
- unsigned int maximum)
+BT_HIDDEN
+enum bt_component_status bt_component_filter_validate(
+ struct bt_component *component)
{
- struct bt_component_filter *filter;
enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
if (!component) {
goto end;
}
- if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) {
- ret = BT_COMPONENT_STATUS_UNSUPPORTED;
+ if (!component->class) {
+ ret = BT_COMPONENT_STATUS_INVALID;
goto end;
}
- if (!component->initializing) {
+ if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
ret = BT_COMPONENT_STATUS_INVALID;
goto end;
}
- filter = container_of(component, struct bt_component_filter, parent);
- filter->input.max_count = maximum;
+ /* Enforce iterator limits. */
end:
return ret;
}
-enum bt_component_status
-bt_component_filter_get_input_count(struct bt_component *component,
- unsigned int *count)
+enum bt_component_status bt_component_filter_get_input_port_count(
+ struct bt_component *component, uint64_t *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;
- }
+ enum bt_component_status status = BT_COMPONENT_STATUS_OK;
- if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) {
- ret = BT_COMPONENT_STATUS_UNSUPPORTED;
+ if (!component || !count ||
+ component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
+ status = BT_COMPONENT_STATUS_INVALID;
goto end;
}
- filter = container_of(component, struct bt_component_filter, parent);
- *count = (unsigned int) filter->input.iterators->len;
+ *count = bt_component_get_input_port_count(component);
end:
- return ret;
+ return status;
}
-enum bt_component_status
-bt_component_filter_get_input_iterator(struct bt_component *component,
- unsigned int input, struct bt_notification_iterator **iterator)
+struct bt_port *bt_component_filter_get_input_port(
+ struct bt_component *component, const char *name)
{
- struct bt_component_filter *filter;
- enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+ struct bt_port *port = NULL;
- if (!component || !iterator) {
- ret = BT_COMPONENT_STATUS_INVALID;
+ if (!component || !name ||
+ component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
goto end;
}
- if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) {
- ret = BT_COMPONENT_STATUS_UNSUPPORTED;
- goto end;
- }
+ port = bt_component_get_input_port(component, name);
+end:
+ return port;
+}
- filter = container_of(component, struct bt_component_filter, parent);
- if (input >= (unsigned int) filter->input.iterators->len) {
- ret = BT_COMPONENT_STATUS_INVALID;
+struct bt_port *bt_component_filter_get_input_port_at_index(
+ struct bt_component *component, int index)
+{
+ struct bt_port *port = NULL;
+
+ if (!component ||
+ component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
goto end;
}
- *iterator = bt_get(g_ptr_array_index(filter->input.iterators, input));
+ port = bt_component_get_input_port_at_index(component, index);
end:
- return ret;
+ return port;
}
-enum bt_component_status bt_component_filter_add_iterator(
- struct bt_component *component,
- struct bt_notification_iterator *iterator)
+struct bt_port *bt_component_filter_get_default_input_port(
+ struct bt_component *component)
{
- struct bt_component_filter *filter;
- enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
- struct bt_component_class_filter *filter_class;
+ return bt_component_filter_get_input_port(component,
+ DEFAULT_INPUT_PORT_NAME);
+}
- if (!component || !iterator) {
- ret = BT_COMPONENT_STATUS_INVALID;
- goto end;
- }
+enum bt_component_status bt_component_filter_get_output_port_count(
+ struct bt_component *component, uint64_t *count)
+{
+ enum bt_component_status status = BT_COMPONENT_STATUS_OK;
- if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) {
- ret = BT_COMPONENT_STATUS_UNSUPPORTED;
+ if (!component || !count ||
+ component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
+ status = BT_COMPONENT_STATUS_INVALID;
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;
+ *count = bt_component_get_output_port_count(component);
+end:
+ return status;
+}
+
+struct bt_port *bt_component_filter_get_output_port(
+ struct bt_component *component, const char *name)
+{
+ struct bt_port *port = NULL;
+
+ if (!component || !name ||
+ component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
goto end;
}
- filter_class = container_of(component->class, struct bt_component_class_filter, parent);
+ port = bt_component_get_output_port(component, name);
+end:
+ return port;
+}
+
+struct bt_port *bt_component_filter_get_output_port_at_index(
+ struct bt_component *component, int index)
+{
+ struct bt_port *port = NULL;
- if (filter_class->methods.add_iterator) {
- ret = filter_class->methods.add_iterator(component, iterator);
- if (ret != BT_COMPONENT_STATUS_OK) {
- goto end;
- }
+ if (!component ||
+ component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
+ goto end;
}
- g_ptr_array_add(filter->input.iterators, bt_get(iterator));
+ port = bt_component_get_output_port_at_index(component, index);
end:
- return ret;
+ return port;
}
-struct bt_notification_iterator *bt_component_filter_create_iterator(
+struct bt_port *bt_component_filter_get_default_output_port(
struct bt_component *component)
{
- return bt_component_create_iterator(component);
+ return bt_component_filter_get_output_port(component,
+ DEFAULT_OUTPUT_PORT_NAME);
}
-static
-void bt_component_filter_destroy(struct bt_component *component)
+struct bt_private_port *
+bt_private_component_filter_get_input_private_port_at_index(
+ struct bt_private_component *private_component, int index)
{
- struct bt_component_filter *filter = container_of(component,
- struct bt_component_filter, parent);
+ return bt_private_port_from_port(
+ bt_component_filter_get_input_port_at_index(
+ bt_component_from_private(private_component), index));
+}
- component_input_fini(&filter->input);
+struct bt_private_port *
+bt_private_component_filter_get_default_private_input_port(
+ struct bt_private_component *private_component)
+{
+ return bt_private_port_from_port(
+ bt_component_filter_get_default_input_port(
+ bt_component_from_private(private_component)));
}
-BT_HIDDEN
-struct bt_component *bt_component_filter_create(
- struct bt_component_class *class, struct bt_value *params)
+struct bt_private_port *bt_private_component_filter_add_input_private_port(
+ struct bt_private_component *private_component,
+ const char *name)
{
- struct bt_component_filter *filter = NULL;
- enum bt_component_status ret;
+ struct bt_port *port = NULL;
+ struct bt_component *component =
+ bt_component_from_private(private_component);
- filter = g_new0(struct bt_component_filter, 1);
- if (!filter) {
+ if (!component ||
+ component->class->type != BT_COMPONENT_CLASS_TYPE_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;
- }
+ port = bt_component_add_input_port(component, name);
end:
- return filter ? &filter->parent : NULL;
-error:
- BT_PUT(filter);
- goto end;
+ return bt_private_port_from_port(port);
}
-BT_HIDDEN
-enum bt_component_status bt_component_filter_validate(
- struct bt_component *component)
+struct bt_private_port *
+bt_private_component_filter_get_output_private_port_at_index(
+ struct bt_private_component *private_component, int index)
{
- enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
- struct bt_component_filter *filter;
+ return bt_private_port_from_port(
+ bt_component_filter_get_output_port_at_index(
+ bt_component_from_private(private_component), index));
+}
- if (!component) {
- ret = BT_COMPONENT_STATUS_INVALID;
- goto end;
- }
+struct bt_private_port *
+bt_private_component_filter_get_default_private_output_port(
+ struct bt_private_component *private_component)
+{
+ return bt_private_port_from_port(
+ bt_component_filter_get_default_output_port(
+ bt_component_from_private(private_component)));
+}
- if (!component->class) {
- ret = BT_COMPONENT_STATUS_INVALID;
- goto end;
- }
+struct bt_private_port *bt_private_component_filter_add_output_private_port(
+ struct bt_private_component *private_component,
+ const char *name)
+{
+ struct bt_port *port = NULL;
+ struct bt_component *component =
+ bt_component_from_private(private_component);
- if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
- ret = BT_COMPONENT_STATUS_INVALID;
+ if (!component ||
+ component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
goto end;
}
- filter = container_of(component, struct bt_component_filter, parent);
- ret = component_input_validate(&filter->input);
- if (ret) {
- goto end;
- }
+ port = bt_component_add_output_port(component, name);
end:
- return ret;
+ return bt_private_port_from_port(port);
}