X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Fsource.c;h=6e76206afb6e00c26627e044d44df098aba08eaf;hb=38b48196e2b127cceb022056bb22a15086644e10;hp=d32fa2a7071df83e2a24990c71ae32a1f8678c8b;hpb=0d884c50d1a934e65bf6893b0232b0e7fdecf70a;p=babeltrace.git diff --git a/plugins/source.c b/plugins/source.c index d32fa2a7..6e76206a 100644 --- a/plugins/source.c +++ b/plugins/source.c @@ -26,9 +26,12 @@ * SOFTWARE. */ +#include #include #include #include +#include +#include static void bt_component_source_destroy(struct bt_component *component) @@ -43,32 +46,63 @@ void bt_component_source_destroy(struct bt_component *component) g_free(source); } -struct bt_component *bt_component_source_create(const char *name, - void *private_data, bt_component_destroy_cb destroy_func, - bt_component_source_iterator_create_cb iterator_create_cb) +BT_HIDDEN +struct bt_component *bt_component_source_create( + struct bt_component_class *class, const char *name) { struct bt_component_source *source = NULL; enum bt_component_status ret; - if (!iterator_create_cb) { - goto end; - } - source = g_new0(struct bt_component_source, 1); if (!source) { goto end; } - ret = bt_component_init(&source->parent, name, private_data, - destroy_func, BT_COMPONENT_TYPE_SOURCE, + ret = bt_component_init(&source->parent, class, name, bt_component_source_destroy); if (ret != BT_COMPONENT_STATUS_OK) { - g_free(source); - source = NULL; + BT_PUT(source); goto end; } - - source->create_iterator = iterator_create_cb; end: return source ? &source->parent : NULL; } + +struct bt_notification_iterator *bt_component_source_create_iterator( + struct bt_component *component) +{ + 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; + } + + iterator = bt_notification_iterator_create(component); + if (!iterator) { + 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; + } +end: + return iterator; +error: + BT_PUT(iterator); + return iterator; +}