From 2d41b99e628ef719c83f11d55d4a88aa9126a35e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 20 Feb 2017 20:29:00 -0500 Subject: [PATCH] Replace add_iterator methods by a single new_connection method MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- .../component/component-class-filter.h | 7 -- .../component/component-class-internal.h | 3 +- .../component/component-class-sink.h | 7 -- .../babeltrace/component/component-class.h | 11 +++ .../babeltrace/component/component-internal.h | 5 ++ include/babeltrace/plugin/plugin-dev.h | 80 +++++++++++-------- lib/component/component-class.c | 63 +++++---------- lib/plugin/plugin-so.c | 44 ++++------ 8 files changed, 97 insertions(+), 123 deletions(-) diff --git a/include/babeltrace/component/component-class-filter.h b/include/babeltrace/component/component-class-filter.h index 78d3df8d..b0024dc2 100644 --- a/include/babeltrace/component/component-class-filter.h +++ b/include/babeltrace/component/component-class-filter.h @@ -33,18 +33,11 @@ extern "C" { struct bt_component_class; -typedef enum bt_component_status (*bt_component_class_filter_add_iterator_method)( - struct bt_component *, struct bt_notification_iterator *); - extern struct bt_component_class *bt_component_class_filter_create(const char *name, bt_component_class_notification_iterator_get_method notification_iterator_get_method, bt_component_class_notification_iterator_next_method notification_iterator_next_method); -extern int bt_component_class_filter_set_add_iterator_method( - struct bt_component_class *component_class, - bt_component_class_filter_add_iterator_method add_iterator_method); - extern int bt_component_class_filter_set_notification_iterator_init_method( struct bt_component_class *component_class, diff --git a/include/babeltrace/component/component-class-internal.h b/include/babeltrace/component/component-class-internal.h index d03ded15..3994edbd 100644 --- a/include/babeltrace/component/component-class-internal.h +++ b/include/babeltrace/component/component-class-internal.h @@ -58,6 +58,7 @@ struct bt_component_class { bt_component_class_init_method init; bt_component_class_destroy_method destroy; bt_component_class_query_method query; + bt_component_class_new_connection_method new_connection_method; } methods; /* Array of struct bt_component_class_destroy_listener */ GArray *destroy_listeners; @@ -83,7 +84,6 @@ struct bt_component_class_sink { struct bt_component_class parent; struct { bt_component_class_sink_consume_method consume; - bt_component_class_sink_add_iterator_method add_iterator; } methods; }; @@ -91,7 +91,6 @@ struct bt_component_class_filter { struct bt_component_class parent; struct { struct bt_component_class_iterator_methods iterator; - bt_component_class_filter_add_iterator_method add_iterator; } methods; }; diff --git a/include/babeltrace/component/component-class-sink.h b/include/babeltrace/component/component-class-sink.h index 5f89bc81..8b3ed62d 100644 --- a/include/babeltrace/component/component-class-sink.h +++ b/include/babeltrace/component/component-class-sink.h @@ -36,17 +36,10 @@ struct bt_component_class; typedef enum bt_component_status (*bt_component_class_sink_consume_method)( struct bt_component *); -typedef enum bt_component_status (*bt_component_class_sink_add_iterator_method)( - struct bt_component *, struct bt_notification_iterator *); - extern struct bt_component_class *bt_component_class_sink_create(const char *name, bt_component_class_sink_consume_method consume_method); -extern int bt_component_class_sink_set_add_iterator_method( - struct bt_component_class *component_class, - bt_component_class_sink_add_iterator_method add_iterator_method); - #ifdef __cplusplus } #endif diff --git a/include/babeltrace/component/component-class.h b/include/babeltrace/component/component-class.h index 6135343e..9ca1f046 100644 --- a/include/babeltrace/component/component-class.h +++ b/include/babeltrace/component/component-class.h @@ -77,6 +77,9 @@ typedef struct bt_value *(*bt_component_class_query_method)( struct bt_component_class *component_class, const char *object, struct bt_value *params); +typedef enum bt_component_status (*bt_component_class_new_connection_method)( + struct bt_port *own_port, struct bt_connection *connection); + extern int bt_component_class_set_init_method( struct bt_component_class *component_class, bt_component_class_init_method init_method); @@ -85,6 +88,10 @@ extern int bt_component_class_set_destroy_method( struct bt_component_class *component_class, bt_component_class_destroy_method destroy_method); +extern int bt_component_class_set_new_connection_method( + struct bt_component_class *component_class, + bt_component_class_new_connection_method new_connection_method); + extern int bt_component_class_set_description( struct bt_component_class *component_class, const char *description); @@ -124,6 +131,10 @@ extern int bt_component_class_set_query_method( struct bt_component_class *component_class, bt_component_class_query_method query_method); +extern int bt_component_class_set_new_connection_method( + struct bt_component_class *component_class, + bt_component_class_new_connection_method new_connection_method); + extern struct bt_value *bt_component_class_query( struct bt_component_class *component_class, const char *object, struct bt_value *params); diff --git a/include/babeltrace/component/component-internal.h b/include/babeltrace/component/component-internal.h index 3915cd83..b6dfc880 100644 --- a/include/babeltrace/component/component-internal.h +++ b/include/babeltrace/component/component-internal.h @@ -67,6 +67,11 @@ BT_HIDDEN struct bt_notification_iterator *bt_component_create_iterator( struct bt_component *component, void *init_method_data); +BT_HIDDEN +enum bt_component_status bt_component_new_connection( + struct bt_component *component, struct bt_port *own_port, + struct bt_connection *connection); + BT_HIDDEN void bt_component_set_graph(struct bt_component *component, struct bt_graph *graph); diff --git a/include/babeltrace/plugin/plugin-dev.h b/include/babeltrace/plugin/plugin-dev.h index bf04da73..145c9018 100644 --- a/include/babeltrace/plugin/plugin-dev.h +++ b/include/babeltrace/plugin/plugin-dev.h @@ -169,11 +169,10 @@ enum __bt_plugin_component_class_descriptor_attribute_type { BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD = 2, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD = 3, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD = 4, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD = 5, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD = 6, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD = 7, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_DESTROY_METHOD = 8, - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_SEEK_TIME_METHOD = 9, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NEW_CONNECTION_METHOD = 5, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD = 6, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_DESTROY_METHOD = 7, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_SEEK_TIME_METHOD = 8, }; /* Component class attribute (internal use) */ @@ -207,11 +206,8 @@ struct __bt_plugin_component_class_descriptor_attribute { /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD */ bt_component_class_query_method query_method; - /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD */ - bt_component_class_filter_add_iterator_method filter_add_iterator_method; - - /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD */ - bt_component_class_sink_add_iterator_method sink_add_iterator_method; + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NEW_CONNECTION_METHOD */ + bt_component_class_new_connection_method new_connection_method; /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD */ bt_component_class_notification_iterator_init_method notif_iter_init_method; @@ -624,28 +620,40 @@ struct __bt_plugin_component_class_descriptor_attribute { __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(query_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD, _id, _comp_class_id, sink, _x) /* - * Defines an add iterator method attribute attached to a specific + * Defines a new connection method attribute attached to a specific + * source component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: New connection method + * (bt_component_class_new_connection_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NEW_CONNECTION_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(new_connection_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NEW_CONNECTION_METHOD, _id, _comp_class_id, source, _x) + +/* + * Defines a new connection method attribute attached to a specific * filter component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Add iterator method - * (bt_component_class_filter_add_iterator_method). + * _x: New connection method + * (bt_component_class_new_connection_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_add_iterator_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD, _id, _comp_class_id, filter, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_NEW_CONNECTION_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(new_connection_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NEW_CONNECTION_METHOD, _id, _comp_class_id, filter, _x) /* - * Defines an add iterator method attribute attached to a specific + * Defines a new connection method attribute attached to a specific * sink component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Add iterator method - * (bt_component_class_sink_add_iterator_method). + * _x: New connection method + * (bt_component_class_new_connection_method). */ -#define BT_PLUGIN_SINK_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(sink_add_iterator_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD, _id, _comp_class_id, sink, _x) +#define BT_PLUGIN_SINK_COMPONENT_CLASS_NEW_CONNECTION_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(new_connection_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NEW_CONNECTION_METHOD, _id, _comp_class_id, sink, _x) /* * Defines an iterator initialization method attribute attached to a @@ -976,26 +984,34 @@ struct __bt_plugin_component_class_descriptor_attribute { BT_PLUGIN_SINK_COMPONENT_CLASS_QUERY_METHOD_WITH_ID(auto, _name, _x) /* - * Defines an add iterator method attribute attached to a filter - * component class descriptor which is attached to the automatic plugin - * descriptor. + * Defines a new connection method attribute attached to a source component + * class descriptor which is attached to the automatic plugin descriptor. * * _name: Component class name (C identifier). - * _x: Add iterator method (bt_component_class_filter_add_iterator_method). + * _x: New connections method (bt_component_class_new_connection_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ADD_ITERATOR_METHOD(_name, _x) \ - BT_PLUGIN_FILTER_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NEW_CONNECTION_METHOD(_name, _x) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_NEW_CONNECTION_METHOD_WITH_ID(auto, _name, _x) /* - * Defines an add iterator method attribute attached to a sink - * component class descriptor which is attached to the automatic plugin - * descriptor. + * Defines a new connection method attribute attached to a filter component + * class descriptor which is attached to the automatic plugin descriptor. + * + * _name: Component class name (C identifier). + * _x: New connections method (bt_component_class_new_connection_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_NEW_CONNECTION_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_NEW_CONNECTION_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines a new connection method attribute attached to a sink component + * class descriptor which is attached to the automatic plugin descriptor. * * _name: Component class name (C identifier). - * _x: Add iterator method (bt_component_class_sink_add_iterator_method). + * _x: New connections method (bt_component_class_new_connection_method). */ -#define BT_PLUGIN_SINK_COMPONENT_CLASS_ADD_ITERATOR_METHOD(_name, _x) \ - BT_PLUGIN_SINK_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_SINK_COMPONENT_CLASS_NEW_CONNECTION_METHOD(_name, _x) \ + BT_PLUGIN_SINK_COMPONENT_CLASS_NEW_CONNECTION_METHOD_WITH_ID(auto, _name, _x) /* * Defines an iterator initialization method attribute attached to a diff --git a/lib/component/component-class.c b/lib/component/component-class.c index fa71bc94..0843e0c2 100644 --- a/lib/component/component-class.c +++ b/lib/component/component-class.c @@ -245,6 +245,24 @@ end: return ret; } +int bt_component_class_set_new_connection_method( + struct bt_component_class *component_class, + bt_component_class_new_connection_method new_connection_method) +{ + int ret = 0; + + if (!component_class || component_class->frozen || + !new_connection_method) { + ret = -1; + goto end; + } + + component_class->methods.new_connection_method = new_connection_method; + +end: + return ret; +} + int bt_component_class_set_destroy_method( struct bt_component_class *component_class, bt_component_class_destroy_method destroy_method) @@ -481,51 +499,6 @@ end: return ret; } -extern int bt_component_class_sink_set_add_iterator_method( - struct bt_component_class *component_class, - bt_component_class_sink_add_iterator_method add_iterator_method) -{ - struct bt_component_class_sink *sink_class; - int ret = 0; - - if (!component_class || component_class->frozen || - !add_iterator_method || - component_class->type != BT_COMPONENT_CLASS_TYPE_SINK) { - ret = -1; - goto end; - } - - sink_class = container_of(component_class, - struct bt_component_class_sink, parent); - sink_class->methods.add_iterator = add_iterator_method; - -end: - return ret; -} - -extern int bt_component_class_filter_set_add_iterator_method( - struct bt_component_class *component_class, - bt_component_class_filter_add_iterator_method add_iterator_method) -{ - struct bt_component_class_filter *filter_class; - int ret = 0; - - if (!component_class || component_class->frozen || - !add_iterator_method || - component_class->type != - BT_COMPONENT_CLASS_TYPE_FILTER) { - ret = -1; - goto end; - } - - filter_class = container_of(component_class, - struct bt_component_class_filter, parent); - filter_class->methods.add_iterator = add_iterator_method; - -end: - return ret; -} - int bt_component_class_freeze( struct bt_component_class *component_class) { diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index 83c5e10e..24478f1f 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -253,8 +253,7 @@ enum bt_plugin_status bt_plugin_so_init( bt_component_class_init_method init_method; bt_component_class_destroy_method destroy_method; bt_component_class_query_method query_method; - bt_component_class_filter_add_iterator_method filter_add_iterator_method; - bt_component_class_sink_add_iterator_method sink_add_iterator_method; + bt_component_class_new_connection_method new_connection_method; struct bt_component_class_iterator_methods iterator_methods; }; @@ -383,13 +382,9 @@ enum bt_plugin_status bt_plugin_so_init( cc_full_descr->query_method = cur_cc_descr_attr->value.query_method; break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD: - cc_full_descr->filter_add_iterator_method = - cur_cc_descr_attr->value.filter_add_iterator_method; - break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD: - cc_full_descr->sink_add_iterator_method = - cur_cc_descr_attr->value.sink_add_iterator_method; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NEW_CONNECTION_METHOD: + cc_full_descr->new_connection_method = + cur_cc_descr_attr->value.new_connection_method; break; case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD: cc_full_descr->iterator_methods.init = @@ -516,6 +511,16 @@ enum bt_plugin_status bt_plugin_so_init( } } + if (cc_full_descr->new_connection_method) { + ret = bt_component_class_set_new_connection_method( + comp_class, cc_full_descr->new_connection_method); + if (ret) { + status = BT_PLUGIN_STATUS_ERROR; + BT_PUT(comp_class); + goto end; + } + } + switch (cc_full_descr->descriptor->type) { case BT_COMPONENT_CLASS_TYPE_SOURCE: if (cc_full_descr->iterator_methods.init) { @@ -552,17 +557,6 @@ enum bt_plugin_status bt_plugin_so_init( } break; case BT_COMPONENT_CLASS_TYPE_FILTER: - if (cc_full_descr->filter_add_iterator_method) { - ret = bt_component_class_filter_set_add_iterator_method( - comp_class, - cc_full_descr->filter_add_iterator_method); - if (ret) { - status = BT_PLUGIN_STATUS_ERROR; - BT_PUT(comp_class); - goto end; - } - } - if (cc_full_descr->iterator_methods.init) { ret = bt_component_class_filter_set_notification_iterator_init_method( comp_class, @@ -597,16 +591,6 @@ enum bt_plugin_status bt_plugin_so_init( } break; case BT_COMPONENT_CLASS_TYPE_SINK: - if (cc_full_descr->sink_add_iterator_method) { - ret = bt_component_class_sink_set_add_iterator_method( - comp_class, - cc_full_descr->sink_add_iterator_method); - if (ret) { - status = BT_PLUGIN_STATUS_ERROR; - BT_PUT(comp_class); - goto end; - } - } break; default: assert(false); -- 2.34.1