return bt_component_create_iterator(component, init_method_data);
}
-static
+BT_HIDDEN
void bt_component_filter_destroy(struct bt_component *component)
{
- struct bt_component_filter *filter = container_of(component,
- struct bt_component_filter, parent);
-
- if (filter->input_ports) {
- g_ptr_array_free(filter->input_ports, TRUE);
- }
-
- if (filter->output_ports) {
- g_ptr_array_free(filter->output_ports, TRUE);
- }
}
BT_HIDDEN
struct bt_component *bt_component_filter_create(
struct bt_component_class *class, struct bt_value *params)
{
- int ret;
struct bt_component_filter *filter = NULL;
- enum bt_component_status status;
filter = g_new0(struct bt_component_filter, 1);
if (!filter) {
goto end;
}
- filter->parent.class = bt_get(class);
- status = bt_component_init(&filter->parent, bt_component_filter_destroy);
- if (status != BT_COMPONENT_STATUS_OK) {
- goto error;
- }
-
- ret = bt_component_init_input_ports(&filter->parent,
- &filter->input_ports);
- if (ret) {
- goto error;
- }
-
- ret = bt_component_init_output_ports(&filter->parent,
- &filter->output_ports);
- if (ret) {
- goto error;
- }
-
end:
return filter ? &filter->parent : NULL;
-error:
- BT_PUT(filter);
- goto end;
}
BT_HIDDEN
struct bt_component *component, uint64_t *count)
{
enum bt_component_status status = BT_COMPONENT_STATUS_OK;
- struct bt_component_filter *filter;
- if (!component || !count) {
+ if (!component || !count ||
+ component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
status = BT_COMPONENT_STATUS_INVALID;
goto end;
}
- if (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 = (uint64_t) filter->input_ports->len;
+ *count = bt_component_get_input_port_count(component);
end:
return status;
}
struct bt_port *bt_component_filter_get_input_port(
struct bt_component *component, const char *name)
{
- struct bt_component_filter *filter;
- struct bt_port *ret_port = NULL;
+ struct bt_port *port = NULL;
if (!component || !name ||
component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
goto end;
}
- filter = container_of(component, struct bt_component_filter, parent);
- ret_port = bt_component_get_port(filter->input_ports, name);
+ port = bt_component_get_input_port(component, name);
end:
- return ret_port;
+ return port;
}
struct bt_port *bt_component_filter_get_input_port_at_index(
struct bt_component *component, int index)
{
struct bt_port *port = NULL;
- struct bt_component_filter *filter;
if (!component ||
component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
goto end;
}
- filter = container_of(component, struct bt_component_filter, parent);
- port = bt_component_get_port_at_index(filter->input_ports, index);
+ port = bt_component_get_input_port_at_index(component, index);
end:
return port;
}
struct bt_port *bt_component_filter_add_input_port(
struct bt_component *component, const char *name)
{
- struct bt_port *port;
- struct bt_component_filter *filter;
+ struct bt_port *port = NULL;
if (!component ||
component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
- port = NULL;
goto end;
}
- filter = container_of(component, struct bt_component_filter, parent);
- port = bt_component_add_port(component, filter->input_ports,
- BT_PORT_TYPE_INPUT, name);
+ port = bt_component_add_input_port(component, name);
end:
return port;
}
-enum bt_component_status bt_component_filter_remove_input_port(
- struct bt_component *component, const char *name)
-{
- enum bt_component_status status;
- struct bt_component_filter *filter;
-
- if (!component ||
- component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
- status = BT_COMPONENT_STATUS_INVALID;
- goto end;
- }
-
- filter = container_of(component, struct bt_component_filter, parent);
- status = bt_component_remove_port(component, filter->input_ports,
- name);
-end:
- return status;
-}
-
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;
- struct bt_component_filter *filter;
- if (!component || !count) {
+ if (!component || !count ||
+ component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
status = BT_COMPONENT_STATUS_INVALID;
goto end;
}
- if (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 = (uint64_t) filter->output_ports->len;
+ *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_component_filter *filter;
- struct bt_port *ret_port = NULL;
+ struct bt_port *port = NULL;
if (!component || !name ||
component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
goto end;
}
- filter = container_of(component, struct bt_component_filter, parent);
- ret_port = bt_component_get_port(filter->output_ports, name);
+ port = bt_component_get_output_port(component, name);
end:
- return ret_port;
+ return port;
}
struct bt_port *bt_component_filter_get_output_port_at_index(
struct bt_component *component, int index)
{
struct bt_port *port = NULL;
- struct bt_component_filter *filter;
if (!component ||
component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
goto end;
}
- filter = container_of(component, struct bt_component_filter, parent);
- port = bt_component_get_port_at_index(filter->output_ports, index);
+ port = bt_component_get_output_port_at_index(component, index);
end:
return port;
}
struct bt_port *bt_component_filter_add_output_port(
struct bt_component *component, const char *name)
{
- struct bt_port *port;
- struct bt_component_filter *filter;
+ struct bt_port *port = NULL;
if (!component ||
component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
- port = NULL;
goto end;
}
- filter = container_of(component, struct bt_component_filter, parent);
- port = bt_component_add_port(component, filter->output_ports,
- BT_PORT_TYPE_OUTPUT, name);
+ port = bt_component_add_output_port(component, name);
end:
return port;
}
-
-enum bt_component_status bt_component_filter_remove_output_port(
- struct bt_component *component, const char *name)
-{
- enum bt_component_status status;
- struct bt_component_filter *filter;
-
- if (!component ||
- component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
- status = BT_COMPONENT_STATUS_INVALID;
- goto end;
- }
-
- filter = container_of(component, struct bt_component_filter, parent);
- status = bt_component_remove_port(component, filter->output_ports,
- name);
-end:
- return status;
-}