X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fplugin-system%2Fcomponent.c;h=ec9390793b3407a1bc818905c7bda7f71dce5436;hb=09ac5ce7990677798a58638ab45ab1a62e615a9a;hp=9c4121ba699dcdc9bb18de053abdf1847d4bd218;hpb=30d619df191d89101727d0f6d5f4181d2df7653f;p=babeltrace.git diff --git a/lib/plugin-system/component.c b/lib/plugin-system/component.c index 9c4121ba..ec939079 100644 --- a/lib/plugin-system/component.c +++ b/lib/plugin-system/component.c @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,6 +41,7 @@ struct bt_component * (* const component_create_funcs[])( struct bt_component_class *, struct bt_value *) = { [BT_COMPONENT_TYPE_SOURCE] = bt_component_source_create, [BT_COMPONENT_TYPE_SINK] = bt_component_sink_create, + [BT_COMPONENT_TYPE_FILTER] = bt_component_filter_create, }; static @@ -46,6 +49,7 @@ enum bt_component_status (* const component_validation_funcs[])( struct bt_component *) = { [BT_COMPONENT_TYPE_SOURCE] = bt_component_source_validate, [BT_COMPONENT_TYPE_SINK] = bt_component_sink_validate, + [BT_COMPONENT_TYPE_FILTER] = bt_component_filter_validate, }; static @@ -59,8 +63,6 @@ void bt_component_destroy(struct bt_object *obj) } component = container_of(obj, struct bt_component, base); - - assert(component->destroy); component_class = component->class; /* @@ -68,10 +70,13 @@ void bt_component_destroy(struct bt_object *obj) * instance. */ if (component->user_destroy) { - component->user_destroy(component->user_data); + component->user_destroy(component); + } + + if (component->destroy) { + component->destroy(component); } - component->destroy(component); g_string_free(component->name, TRUE); bt_put(component_class); g_free(component); @@ -83,7 +88,7 @@ enum bt_component_status bt_component_init(struct bt_component *component, { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - if (!component || !destroy) { + if (!component) { ret = BT_COMPONENT_STATUS_INVALID; goto end; } @@ -99,6 +104,75 @@ enum bt_component_type bt_component_get_type(struct bt_component *component) return component ? component->class->type : BT_COMPONENT_TYPE_UNKNOWN; } +BT_HIDDEN +struct bt_notification_iterator *bt_component_create_iterator( + struct bt_component *component) +{ + enum bt_notification_iterator_status ret_iterator; + enum bt_component_type component_type; + struct bt_notification_iterator *iterator = NULL; + + if (!component) { + goto error; + } + + component_type = bt_component_get_type(component); + if (component_type != BT_COMPONENT_TYPE_SOURCE && + component_type != BT_COMPONENT_TYPE_FILTER) { + /* Unsupported operation. */ + goto error; + } + + iterator = bt_notification_iterator_create(component); + if (!iterator) { + goto error; + } + + switch (component_type) { + case BT_COMPONENT_TYPE_SOURCE: + { + struct bt_component_source *source; + enum bt_component_status ret_component; + + 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; + } + break; + + break; + } + case BT_COMPONENT_TYPE_FILTER: + { + struct bt_component_filter *filter; + enum bt_component_status ret_component; + + filter = container_of(component, struct bt_component_filter, parent); + assert(filter->init_iterator); + ret_component = filter->init_iterator(component, iterator); + if (ret_component != BT_COMPONENT_STATUS_OK) { + goto error; + } + break; + } + default: + /* Unreachable. */ + assert(0); + } + + ret_iterator = bt_notification_iterator_validate(iterator); + if (ret_iterator != BT_NOTIFICATION_ITERATOR_STATUS_OK) { + goto error; + } + + return iterator; +error: + BT_PUT(iterator); + return iterator; +} + struct bt_component *bt_component_create( struct bt_component_class *component_class, const char *name, struct bt_value *params) @@ -113,8 +187,7 @@ struct bt_component *bt_component_create( type = bt_component_class_get_type(component_class); if (type <= BT_COMPONENT_TYPE_UNKNOWN || - type >= BT_COMPONENT_TYPE_FILTER) { - /* Filter components are not supported yet. */ + type > BT_COMPONENT_TYPE_FILTER) { goto end; } @@ -124,16 +197,21 @@ struct bt_component *bt_component_create( } bt_object_init(component, bt_component_destroy); - component->class = bt_get(component_class); component->name = g_string_new(name); if (!component->name) { BT_PUT(component); goto end; } - component_class->init(component, params); + component->initializing = true; + ret = component_class->init(component, params); + component->initializing = false; + if (ret != BT_COMPONENT_STATUS_OK) { + BT_PUT(component); + goto end; + } ret = component_validation_funcs[type](component); - if (ret) { + if (ret != BT_COMPONENT_STATUS_OK) { BT_PUT(component); goto end; } @@ -186,7 +264,7 @@ bt_component_set_private_data(struct bt_component *component, { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - if (!component) { + if (!component || !component->initializing) { ret = BT_COMPONENT_STATUS_INVALID; goto end; } @@ -195,3 +273,18 @@ bt_component_set_private_data(struct bt_component *component, end: return ret; } + +enum bt_component_status bt_component_set_destroy_cb( + struct bt_component *component, bt_component_destroy_cb destroy) +{ + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + + if (!component || !component->initializing) { + ret = BT_COMPONENT_STATUS_INVALID; + goto end; + } + + component->user_destroy = destroy; +end: + return ret; +}