#include <babeltrace/plugin/notification/iterator.h>
#include <babeltrace/plugin/notification/iterator-internal.h>
-static
-void bt_component_source_destroy(struct bt_component *component)
-{
- return;
-}
-
BT_HIDDEN
enum bt_component_status bt_component_source_validate(
struct bt_component *component)
{
- return BT_COMPONENT_STATUS_OK;
+ enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+ struct bt_component_source *source;
+
+ 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_SOURCE) {
+ ret = BT_COMPONENT_STATUS_INVALID;
+ goto end;
+ }
+
+ source = container_of(component, struct bt_component_source, parent);
+ if (!source->init_iterator) {
+ ret = BT_COMPONENT_STATUS_INVALID;
+ goto end;
+ }
+end:
+ return ret;
}
BT_HIDDEN
goto end;
}
- ret = bt_component_init(&source->parent, bt_component_source_destroy);
+ source->parent.class = bt_get(class);
+ ret = bt_component_init(&source->parent, NULL);
if (ret != BT_COMPONENT_STATUS_OK) {
BT_PUT(source);
goto end;
return source ? &source->parent : NULL;
}
-struct bt_notification_iterator *bt_component_source_create_iterator(
- struct bt_component *component)
+enum bt_component_status
+bt_component_source_set_iterator_init_cb(struct bt_component *component,
+ bt_component_source_init_iterator_cb init_iterator)
{
- enum bt_component_status ret_component;
- enum bt_notification_iterator_status ret_iterator;
struct bt_component_source *source;
- struct bt_notification_iterator *iterator = NULL;
-
- if (!component) {
- goto end;
- }
-
- if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) {
- goto end;
- }
+ enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
- iterator = bt_notification_iterator_create(component);
- if (!iterator) {
+ if (component->class->type != BT_COMPONENT_TYPE_SOURCE ||
+ !component->initializing) {
+ ret = BT_COMPONENT_STATUS_INVALID;
goto end;
}
source = container_of(component, struct bt_component_source, parent);
- assert(source->init_iterator);
- ret_component = source->init_iterator(component, iterator);
- if (ret_component != BT_COMPONENT_STATUS_OK) {
- goto error;
- }
-
- ret_iterator = bt_notification_iterator_validate(iterator);
- if (ret_iterator != BT_NOTIFICATION_ITERATOR_STATUS_OK) {
- goto error;
- }
+ source->init_iterator = init_iterator;
end:
- return iterator;
-error:
- BT_PUT(iterator);
- return iterator;
+ return ret;
+}
+
+struct bt_notification_iterator *bt_component_source_create_iterator(
+ struct bt_component *component)
+{
+ return bt_component_create_iterator(component);
}