From 2e1b56154a3032b52687751ed2e5c1a8a5134f7c Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 26 Sep 2019 14:26:29 -0400 Subject: [PATCH] lib: make it mandatory to have seek_X if can_seek_X is defined It's currently possible for a component class to provide can_seek_X (can_seek_beginning or can_seek_ns_from_origin) without the corresponding seek_X. This doesn't make much sense, as if can_seek_X returns true, Babeltrace assumes that seek_X can be called (which is inconvenient if it's not provided). That only leaves room for the case where can_seek_X always returns false, which is not useful. This patch makes it only possible to provide a can_seek_X if the corresponding seek_X is provided, for both C and Python user component classes. It's still possible, however, to provide seek_X without can_seek_X, in which case Babeltrace assumes that it's always possible to call seek_X. In the C API, component class method setters for seek_X and can_seek_X are merged in a single function that sets both. Since we assert that seek_X is not NULL, this ensures that can_seek_X can only provided along with a seek_X. In the Python API, this verification is done dynamically when a user message iterator class is assigned to a source or filter component class. Change-Id: If596d35dc3327bfd6e3f1e59f74c43dce3a722e1 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2100 Tested-by: jenkins Reviewed-by: Philippe Proulx Reviewed-by: Francis Deslauriers --- .../graph/component-class-filter.h | 20 +- .../graph/component-class-source.h | 20 +- include/babeltrace2/plugin/plugin-dev.h | 245 ++++++------------ src/bindings/python/bt2/bt2/component.py | 18 ++ .../bt2/bt2/native_bt_component_class.i.h | 30 +-- src/lib/graph/component-class.c | 102 ++------ src/lib/graph/iterator.c | 4 +- src/lib/graph/message/iterator.h | 6 +- src/lib/plugin/plugin-so.c | 76 +----- src/plugins/ctf/plugin.c | 4 +- src/plugins/lttng-utils/plugin.c | 8 +- src/plugins/text/plugin.c | 6 +- src/plugins/utils/plugin.c | 6 +- .../python/bt2/test_message_iterator.py | 127 +++++---- 14 files changed, 263 insertions(+), 409 deletions(-) diff --git a/include/babeltrace2/graph/component-class-filter.h b/include/babeltrace2/graph/component-class-filter.h index da06f29c..a6a69bea 100644 --- a/include/babeltrace2/graph/component-class-filter.h +++ b/include/babeltrace2/graph/component-class-filter.h @@ -160,24 +160,16 @@ bt_component_class_filter_set_message_iterator_finalize_method( bt_component_class_filter_message_iterator_finalize_method method); extern bt_component_class_set_method_status -bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method( +bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods( bt_component_class_filter *comp_class, - bt_component_class_filter_message_iterator_seek_ns_from_origin_method method); + bt_component_class_filter_message_iterator_seek_ns_from_origin_method seek_method, + bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method can_seek_method); extern bt_component_class_set_method_status -bt_component_class_filter_set_message_iterator_seek_beginning_method( +bt_component_class_filter_set_message_iterator_seek_beginning_methods( bt_component_class_filter *comp_class, - bt_component_class_filter_message_iterator_seek_beginning_method method); - -extern bt_component_class_set_method_status -bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method( - bt_component_class_filter *comp_class, - bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method method); - -extern bt_component_class_set_method_status -bt_component_class_filter_set_message_iterator_can_seek_beginning_method( - bt_component_class_filter *comp_class, - bt_component_class_filter_message_iterator_can_seek_beginning_method method); + bt_component_class_filter_message_iterator_seek_beginning_method seek_method, + bt_component_class_filter_message_iterator_can_seek_beginning_method can_seek_method); #ifdef __cplusplus } diff --git a/include/babeltrace2/graph/component-class-source.h b/include/babeltrace2/graph/component-class-source.h index d4872b1c..bdc85180 100644 --- a/include/babeltrace2/graph/component-class-source.h +++ b/include/babeltrace2/graph/component-class-source.h @@ -149,24 +149,16 @@ bt_component_class_source_set_message_iterator_finalize_method( bt_component_class_source_message_iterator_finalize_method method); extern bt_component_class_set_method_status -bt_component_class_source_set_message_iterator_seek_ns_from_origin_method( +bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods( bt_component_class_source *comp_class, - bt_component_class_source_message_iterator_seek_ns_from_origin_method method); + bt_component_class_source_message_iterator_seek_ns_from_origin_method seek_method, + bt_component_class_source_message_iterator_can_seek_ns_from_origin_method can_seek_method); extern bt_component_class_set_method_status -bt_component_class_source_set_message_iterator_seek_beginning_method( +bt_component_class_source_set_message_iterator_seek_beginning_methods( bt_component_class_source *comp_class, - bt_component_class_source_message_iterator_seek_beginning_method method); - -extern bt_component_class_set_method_status -bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method( - bt_component_class_source *comp_class, - bt_component_class_source_message_iterator_can_seek_ns_from_origin_method method); - -extern bt_component_class_set_method_status -bt_component_class_source_set_message_iterator_can_seek_beginning_method( - bt_component_class_source *comp_class, - bt_component_class_source_message_iterator_can_seek_beginning_method method); + bt_component_class_source_message_iterator_seek_beginning_method seek_method, + bt_component_class_source_message_iterator_can_seek_beginning_method can_seek_method); #ifdef __cplusplus } diff --git a/include/babeltrace2/plugin/plugin-dev.h b/include/babeltrace2/plugin/plugin-dev.h index 0dbe7738..85c3ef7f 100644 --- a/include/babeltrace2/plugin/plugin-dev.h +++ b/include/babeltrace2/plugin/plugin-dev.h @@ -877,52 +877,35 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_msg_iter_finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_FINALIZE_METHOD, _id, _comp_class_id, source, _x) /* - * Defines an iterator "seek nanoseconds from origin" 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: Iterator "seek nanoseconds from origin" method - * (bt_component_class_source_message_iterator_seek_ns_from_origin_method). - */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_msg_iter_seek_ns_from_origin_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_NS_FROM_ORIGIN_METHOD, _id, _comp_class_id, source, _x) - -/* - * Defines an iterator "seek beginning" method attribute attached to a - * specific source component class descriptor. + * Defines an iterator "seek nanoseconds from origin" and "can seek nanoseconds + * from origin" method attributes attached to a specific source component class + * descriptor. * - * _id: Plugin descriptor ID (C identifier). - * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Iterator "seek beginning" method - * (bt_component_class_source_message_iterator_seek_beginning_method). + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _seek_method: Iterator "seek nanoseconds from origin" method + * (bt_component_class_source_message_iterator_seek_ns_from_origin_method). + * _can_seek_method: Iterator "can seek nanoseconds from origin" method + * (bt_component_class_source_message_iterator_can_seek_ns_from_origin_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_msg_iter_seek_beginning_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_BEGINNING_METHOD, _id, _comp_class_id, source, _x) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHODS_WITH_ID(_id, _comp_class_id, _seek_method, _can_seek_method) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_msg_iter_seek_ns_from_origin_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_NS_FROM_ORIGIN_METHOD, _id, _comp_class_id, source, _seek_method); \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_msg_iter_can_seek_ns_from_origin_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_NS_FROM_ORIGIN_METHOD, _id, _comp_class_id, source, _can_seek_method) /* - * Defines an iterator "can seek nanoseconds from origin" method - * attribute attached to a specific source component class descriptor. + * Defines an iterator "seek beginning" and "can seek beginning" method + * attributes attached to a specific source component class descriptor. * - * _id: Plugin descriptor ID (C identifier). - * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Iterator "can seek nanoseconds from origin" method - * (bt_component_class_source_message_iterator_can_seek_ns_from_origin_method). + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _seek_method: Iterator "seek beginning" method + * (bt_component_class_source_message_iterator_seek_beginning_method). + * _can_seek_method: Iterator "can seek beginning" method + * (bt_component_class_source_message_iterator_can_seek_beginning_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_msg_iter_can_seek_ns_from_origin_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_NS_FROM_ORIGIN_METHOD, _id, _comp_class_id, source, _x) - -/* - * Defines an iterator "can seek beginning" 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: Iterator "can seek beginning" method - * (bt_component_class_source_message_iterator_can_seek_beginning_method). - */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_msg_iter_can_seek_beginning_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_BEGINNING_METHOD, _id, _comp_class_id, source, _x) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHODS_WITH_ID(_id, _comp_class_id, _seek_method, _can_seek_method) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_msg_iter_seek_beginning_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_BEGINNING_METHOD, _id, _comp_class_id, source, _seek_method); \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(source_msg_iter_can_seek_beginning_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_BEGINNING_METHOD, _id, _comp_class_id, source, _can_seek_method) /* * Defines an iterator initialization method attribute attached to a @@ -949,52 +932,34 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_msg_iter_finalize_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_FINALIZE_METHOD, _id, _comp_class_id, filter, _x) /* - * Defines an iterator "seek nanoseconds from origin" 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: Iterator "seek nanoseconds from origin" method - * (bt_component_class_filter_message_iterator_seek_ns_from_origin_method). - */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_msg_iter_seek_ns_from_origin_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_NS_FROM_ORIGIN_METHOD, _id, _comp_class_id, filter, _x) - -/* - * Defines an iterator "seek beginning" 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: Iterator "seek beginning" method - * (bt_component_class_filter_message_iterator_seek_beginning_method). - */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_msg_iter_seek_beginning_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_BEGINNING_METHOD, _id, _comp_class_id, filter, _x) - -/* - * Defines an iterator "can seek nanoseconds from origin" method - * attribute attached to a specific filter component class descriptor. + * Defines an iterator "seek nanoseconds" and "can seek nanoseconds from origin" + * method attributes attached to a specific filter component class descriptor. * - * _id: Plugin descriptor ID (C identifier). - * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Iterator "can seek nanoseconds from origin" method - * (bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method). + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _seek_method: Iterator "seek nanoseconds from origin" method + * (bt_component_class_filter_message_iterator_seek_ns_from_origin_method). + * _can_seek_method: Iterator "can seek nanoseconds from origin" method + * (bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_msg_iter_can_seek_ns_from_origin_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_NS_FROM_ORIGIN_METHOD, _id, _comp_class_id, filter, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHODS_WITH_ID(_id, _comp_class_id, _seek_method, _can_seek_method) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_msg_iter_seek_ns_from_origin_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_NS_FROM_ORIGIN_METHOD, _id, _comp_class_id, filter, _seek_method); \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_msg_iter_can_seek_ns_from_origin_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_NS_FROM_ORIGIN_METHOD, _id, _comp_class_id, filter, _can_seek_method) /* - * Defines an iterator "can seek beginning" method attribute attached to a - * specific filter component class descriptor. + * Defines an iterator "seek beginning" and "can seek beginning" method + * attributes attached to a specific filter component class descriptor. * - * _id: Plugin descriptor ID (C identifier). - * _comp_class_id: Component class descriptor ID (C identifier). - * _x: Iterator "can seek beginning" method - * (bt_component_class_filter_message_iterator_can_seek_beginning_method). + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _seek_method: Iterator "seek beginning" method + * (bt_component_class_filter_message_iterator_seek_beginning_method). + * _can_seek_method: Iterator "can seek beginning" method + * (bt_component_class_filter_message_iterator_can_seek_beginning_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD_WITH_ID(_id, _comp_class_id, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_msg_iter_can_seek_beginning_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_BEGINNING_METHOD, _id, _comp_class_id, filter, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHODS_WITH_ID(_id, _comp_class_id, _seek_method, _can_seek_method) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_msg_iter_seek_beginning_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_BEGINNING_METHOD, _id, _comp_class_id, filter, _seek_method); \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_msg_iter_can_seek_beginning_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_BEGINNING_METHOD, _id, _comp_class_id, filter, _can_seek_method); /* * Defines a plugin descriptor with an automatic ID. @@ -1362,52 +1327,32 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_FINALIZE_METHOD_WITH_ID(auto, _name, _x) /* - * Defines an iterator "seek nanoseconds from origin" method attribute - * attached to a source component class descriptor which is attached to - * the automatic plugin descriptor. - * - * _name: Component class name (C identifier). - * _x: Iterator "seek nanoseconds from origin" method - * (bt_component_class_source_message_iterator_seek_ns_from_origin_method). - */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHOD(_name, _x) \ - BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHOD_WITH_ID(auto, _name, _x) - -/* - * Defines an iterator "seek beginning" method attribute - * attached to a source component class descriptor which is attached to - * the automatic plugin descriptor. - * - * _name: Component class name (C identifier). - * _x: Iterator "seek beginning" method - * (bt_component_class_source_message_iterator_seek_beginning_method). - */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD(_name, _x) \ - BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_WITH_ID(auto, _name, _x) - -/* - * Defines an iterator "can seek nanoseconds from origin" method - * attribute attached to a source component class descriptor which is - * attached to the automatic plugin descriptor. + * Defines an iterator "seek nanoseconds from origin" and "can seek nanoseconds + * from origin" method attributes attached to a source component class + * descriptor which is attached to the automatic plugin descriptor. * - * _name: Component class name (C identifier). - * _x: Iterator "can seek nanoseconds from origin" method - * (bt_component_class_source_message_iterator_can_seek_ns_from_origin_method). + * _name: Component class name (C identifier). + * _seek_method: Iterator "seek nanoseconds from origin" method + * (bt_component_class_source_message_iterator_seek_ns_from_origin_method). + * _can_seek_method: Iterator "can seek nanoseconds from origin" method + * (bt_component_class_source_message_iterator_can_seek_ns_from_origin_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD(_name, _x) \ - BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHODS(_name, _seek_method, _can_seek_method) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHODS_WITH_ID(auto, _name, _seek_method, _can_seek_method) /* - * Defines an iterator "can seek beginning" method attribute - * attached to a source component class descriptor which is attached to - * the automatic plugin descriptor. + * Defines an iterator "seek beginning" and "can seek beginning" method + * attributes attached to a source component class descriptor which is attached + * to the automatic plugin descriptor. * - * _name: Component class name (C identifier). - * _x: Iterator "can seek beginning" method - * (bt_component_class_source_message_iterator_can_seek_beginning_method). + * _name: Component class name (C identifier). + * _seek_method: Iterator "can seek beginning" method + * (bt_component_class_source_message_iterator_can_seek_beginning_method). + * _can_seek_method: Iterator "can seek beginning" method + * (bt_component_class_source_message_iterator_seek_beginning_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD(_name, _x) \ - BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHODS(_name, _seek_method, _can_seek_method) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHODS_WITH_ID(auto, _name, _seek_method, _can_seek_method) /* * Defines an iterator initialization method attribute attached to a @@ -1434,52 +1379,32 @@ struct __bt_plugin_component_class_descriptor_attribute const * const *__bt_get_ BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_FINALIZE_METHOD_WITH_ID(auto, _name, _x) /* - * Defines an iterator "seek nanoseconds from origin" method attribute - * attached to a filter component class descriptor which is attached to - * the automatic plugin descriptor. + * Defines an iterator "seek nanosecconds from origin" and "can seek + * nanoseconds from origin" method attributes attached to a filter component + * class descriptor which is attached to the automatic plugin descriptor. * - * _name: Component class name (C identifier). - * _x: Iterator "seek nanoseconds from origin" method - * (bt_component_class_filter_message_iterator_seek_ns_from_origin_method). + * _name: Component class name (C identifier). + * _seek_method: Iterator "seek nanoseconds from origin" method + * (bt_component_class_filter_message_iterator_seek_ns_from_origin_method). + * _can_seek_method: Iterator "can seek nanoseconds from origin" method + * (bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHOD(_name, _x) \ - BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHODS(_name, _seek_method, _can_seek_method) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_NS_FROM_ORIGIN_METHODS_WITH_ID(auto, _name, _seek_method, _can_seek_method) /* - * Defines an iterator "seek beginning" method attribute - * attached to a filter component class descriptor which is attached to - * the automatic plugin descriptor. + * Defines an iterator "seek beginning" and "can seek beginning" method + * attributes attached to a filter component class descriptor which is attached + * to the automatic plugin descriptor. * - * _name: Component class name (C identifier). - * _x: Iterator "seek beginning" method - * (bt_component_class_filter_message_iterator_seek_beginning_method). - */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD(_name, _x) \ - BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_WITH_ID(auto, _name, _x) - -/* - * Defines an iterator "can seek nanoseconds from origin" method - * attribute attached to a filter component class descriptor which is - * attached to the automatic plugin descriptor. - * - * _name: Component class name (C identifier). - * _x: Iterator "can seek nanoseconds from origin" method - * (bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method). - */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD(_name, _x) \ - BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_NS_FROM_ORIGIN_METHOD_WITH_ID(auto, _name, _x) - -/* - * Defines an iterator "can seek beginning" method attribute - * attached to a filter component class descriptor which is attached to - * the automatic plugin descriptor. - * - * _name: Component class name (C identifier). - * _x: Iterator "can seek beginning" method - * (bt_component_class_filter_message_iterator_can_seek_beginning_method). + * _name: Component class name (C identifier). + * _seek_method: Iterator "seek beginning" method + * (bt_component_class_filter_message_iterator_seek_beginning_method). + * _can_seek_method: Iterator "can seek beginning" method + * (bt_component_class_filter_message_iterator_can_seek_beginning_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD(_name, _x) \ - BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD_WITH_ID(auto, _name, _x) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHODS(_name, _seek_method, _can_seek_method) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHODS_WITH_ID(auto, _name, _seek_method, _can_seek_method) #define BT_PLUGIN_MODULE() \ static struct __bt_plugin_descriptor const * const __bt_plugin_descriptor_dummy __BT_PLUGIN_DESCRIPTOR_ATTRS = NULL; \ diff --git a/src/bindings/python/bt2/bt2/component.py b/src/bindings/python/bt2/bt2/component.py index c4be7368..9d27e6e0 100644 --- a/src/bindings/python/bt2/bt2/component.py +++ b/src/bindings/python/bt2/bt2/component.py @@ -553,6 +553,24 @@ class _UserComponentType(type): ) ) + if hasattr(iter_cls, '_user_can_seek_ns_from_origin') and not hasattr( + iter_cls, '_user_seek_ns_from_origin' + ): + raise bt2._IncompleteUserClass( + "cannot create component class '{}': message iterator class implements _user_can_seek_ns_from_origin but not _user_seek_ns_from_origin".format( + cls.__name__ + ) + ) + + if hasattr(iter_cls, '_user_can_seek_beginning') and not hasattr( + iter_cls, '_user_seek_beginning' + ): + raise bt2._IncompleteUserClass( + "cannot create component class '{}': message iterator class implements _user_can_seek_beginning but not _user_seek_beginning".format( + cls.__name__ + ) + ) + cls._iter_cls = iter_cls @property diff --git a/src/bindings/python/bt2/bt2/native_bt_component_class.i.h b/src/bindings/python/bt2/bt2/native_bt_component_class.i.h index 4a0fdbcd..b29f3fa9 100644 --- a/src/bindings/python/bt2/bt2/native_bt_component_class.i.h +++ b/src/bindings/python/bt2/bt2/native_bt_component_class.i.h @@ -1267,16 +1267,11 @@ bt_component_class_source *bt_bt2_component_class_source_create( BT_ASSERT(ret == 0); ret = bt_component_class_source_set_finalize_method(component_class_source, component_class_source_finalize); BT_ASSERT(ret == 0); - ret = bt_component_class_source_set_message_iterator_can_seek_beginning_method(component_class_source, - component_class_can_seek_beginning); - BT_ASSERT(ret == 0); - ret = bt_component_class_source_set_message_iterator_seek_beginning_method(component_class_source, - component_class_seek_beginning); - ret = bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method( - component_class_source, component_class_can_seek_ns_from_origin); - BT_ASSERT(ret == 0); - ret = bt_component_class_source_set_message_iterator_seek_ns_from_origin_method( - component_class_source, component_class_seek_ns_from_origin); + ret = bt_component_class_source_set_message_iterator_seek_beginning_methods(component_class_source, + component_class_seek_beginning, component_class_can_seek_beginning); + ret = bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods( + component_class_source, component_class_seek_ns_from_origin, + component_class_can_seek_ns_from_origin); BT_ASSERT(ret == 0); ret = bt_component_class_source_set_output_port_connected_method(component_class_source, component_class_source_output_port_connected); @@ -1324,17 +1319,12 @@ bt_component_class_filter *bt_bt2_component_class_filter_create( BT_ASSERT(ret == 0); ret = bt_component_class_filter_set_finalize_method (component_class_filter, component_class_filter_finalize); BT_ASSERT(ret == 0); - ret = bt_component_class_filter_set_message_iterator_can_seek_beginning_method(component_class_filter, - component_class_can_seek_beginning); - BT_ASSERT(ret == 0); - ret = bt_component_class_filter_set_message_iterator_seek_beginning_method(component_class_filter, - component_class_seek_beginning); - BT_ASSERT(ret == 0); - ret = bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method( - component_class_filter, component_class_can_seek_ns_from_origin); + ret = bt_component_class_filter_set_message_iterator_seek_beginning_methods(component_class_filter, + component_class_seek_beginning, component_class_can_seek_beginning); BT_ASSERT(ret == 0); - ret = bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method( - component_class_filter, component_class_seek_ns_from_origin); + ret = bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods( + component_class_filter, component_class_seek_ns_from_origin, + component_class_can_seek_ns_from_origin); ret = bt_component_class_filter_set_input_port_connected_method(component_class_filter, component_class_filter_input_port_connected); BT_ASSERT(ret == 0); diff --git a/src/lib/graph/component-class.c b/src/lib/graph/component-class.c index be4bbe7a..9bbf4172 100644 --- a/src/lib/graph/component-class.c +++ b/src/lib/graph/component-class.c @@ -556,113 +556,65 @@ bt_component_class_filter_set_message_iterator_finalize_method( } enum bt_component_class_set_method_status -bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method( +bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods( struct bt_component_class_filter *comp_cls, - bt_component_class_filter_message_iterator_seek_ns_from_origin_method method) + bt_component_class_filter_message_iterator_seek_ns_from_origin_method seek_method, + bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method can_seek_method) { BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method"); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); - comp_cls->methods.msg_iter_seek_ns_from_origin = method; + comp_cls->methods.msg_iter_seek_ns_from_origin = seek_method; + comp_cls->methods.msg_iter_can_seek_ns_from_origin = can_seek_method; BT_LIB_LOGD("Set filter component class's message iterator \"seek nanoseconds from origin\" method" ": %!+C", comp_cls); return BT_FUNC_STATUS_OK; } enum bt_component_class_set_method_status -bt_component_class_source_set_message_iterator_seek_ns_from_origin_method( - struct bt_component_class_source *comp_cls, - bt_component_class_source_message_iterator_seek_ns_from_origin_method method) -{ - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); - BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); - comp_cls->methods.msg_iter_seek_ns_from_origin = method; - BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" method" - ": %!+C", comp_cls); - return BT_FUNC_STATUS_OK; -} - -enum bt_component_class_set_method_status -bt_component_class_filter_set_message_iterator_seek_beginning_method( - struct bt_component_class_filter *comp_cls, - bt_component_class_filter_message_iterator_seek_beginning_method method) -{ - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); - BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); - comp_cls->methods.msg_iter_seek_beginning = method; - BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" method" - ": %!+C", comp_cls); - return BT_FUNC_STATUS_OK; -} - -enum bt_component_class_set_method_status -bt_component_class_source_set_message_iterator_seek_beginning_method( - struct bt_component_class_source *comp_cls, - bt_component_class_source_message_iterator_seek_beginning_method method) -{ - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); - BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); - comp_cls->methods.msg_iter_seek_beginning = method; - BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" method" - ": %!+C", comp_cls); - return BT_FUNC_STATUS_OK; -} - -enum bt_component_class_set_method_status -bt_component_class_filter_set_message_iterator_can_seek_beginning_method( - struct bt_component_class_filter *comp_cls, - bt_component_class_filter_message_iterator_can_seek_beginning_method method) -{ - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); - BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); - comp_cls->methods.msg_iter_can_seek_beginning = method; - BT_LIB_LOGD("Set filter component class's message iterator \"can seek beginning\" method" - ": %!+C", comp_cls); - return BT_FUNC_STATUS_OK; -} - -enum bt_component_class_set_method_status -bt_component_class_source_set_message_iterator_can_seek_beginning_method( +bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods( struct bt_component_class_source *comp_cls, - bt_component_class_source_message_iterator_can_seek_beginning_method method) + bt_component_class_source_message_iterator_seek_ns_from_origin_method seek_method, + bt_component_class_source_message_iterator_can_seek_ns_from_origin_method can_seek_method) { BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method"); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); - comp_cls->methods.msg_iter_can_seek_beginning = method; - BT_LIB_LOGD("Set source component class's message iterator \"can seek beginning\" method" + comp_cls->methods.msg_iter_seek_ns_from_origin = seek_method; + comp_cls->methods.msg_iter_can_seek_ns_from_origin = can_seek_method; + BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" methods" ": %!+C", comp_cls); return BT_FUNC_STATUS_OK; } enum bt_component_class_set_method_status -bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method( +bt_component_class_filter_set_message_iterator_seek_beginning_methods( struct bt_component_class_filter *comp_cls, - bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method method) + bt_component_class_filter_message_iterator_seek_beginning_method seek_method, + bt_component_class_filter_message_iterator_can_seek_beginning_method can_seek_method) { BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method"); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); - comp_cls->methods.msg_iter_can_seek_ns_from_origin = method; - BT_LIB_LOGD("Set filter component class's message iterator \"can seek nanoseconds from origin\" method" + comp_cls->methods.msg_iter_seek_beginning = seek_method; + comp_cls->methods.msg_iter_can_seek_beginning = can_seek_method; + BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" methods" ": %!+C", comp_cls); return BT_FUNC_STATUS_OK; } enum bt_component_class_set_method_status -bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method( +bt_component_class_source_set_message_iterator_seek_beginning_methods( struct bt_component_class_source *comp_cls, - bt_component_class_source_message_iterator_can_seek_ns_from_origin_method method) + bt_component_class_source_message_iterator_seek_beginning_method seek_method, + bt_component_class_source_message_iterator_can_seek_beginning_method can_seek_method) { BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method"); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); - comp_cls->methods.msg_iter_can_seek_ns_from_origin = method; - BT_LIB_LOGD("Set source component class's message iterator \"can seek nanoseconds from origin\" method" + comp_cls->methods.msg_iter_seek_beginning = seek_method; + comp_cls->methods.msg_iter_can_seek_beginning = can_seek_method; + BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" methods" ": %!+C", comp_cls); return BT_FUNC_STATUS_OK; } diff --git a/src/lib/graph/iterator.c b/src/lib/graph/iterator.c index 951776a1..511a1f98 100644 --- a/src/lib/graph/iterator.c +++ b/src/lib/graph/iterator.c @@ -1748,9 +1748,7 @@ bt_self_component_port_input_message_iterator_seek_ns_from_origin( if (can_seek_by_itself) { /* The iterator knows how to seek to a particular time, let it handle this. */ - BT_ASSERT_PRE_DEV(iterator->methods.seek_ns_from_origin, - "Message iterator does not implement `seek_ns_from_origin` method: %!+i", - iterator); + BT_ASSERT(iterator->methods.seek_ns_from_origin); BT_LIB_LOGD("Calling user's \"seek nanoseconds from origin\" method: " "%![iter-]+i, ns=%" PRId64, iterator, ns_from_origin); status = iterator->methods.seek_ns_from_origin(iterator, diff --git a/src/lib/graph/message/iterator.h b/src/lib/graph/message/iterator.h index 412fe904..52a1c046 100644 --- a/src/lib/graph/message/iterator.h +++ b/src/lib/graph/message/iterator.h @@ -122,9 +122,13 @@ struct bt_self_component_port_input_message_iterator { struct { bt_self_component_port_input_message_iterator_next_method next; + + /* These two are always both set or both unset. */ bt_self_component_port_input_message_iterator_seek_ns_from_origin_method seek_ns_from_origin; - bt_self_component_port_input_message_iterator_seek_beginning_method seek_beginning; bt_self_component_port_input_message_iterator_can_seek_ns_from_origin_method can_seek_ns_from_origin; + + /* These two are always both set or both unset. */ + bt_self_component_port_input_message_iterator_seek_beginning_method seek_beginning; bt_self_component_port_input_message_iterator_can_seek_beginning_method can_seek_beginning; } methods; diff --git a/src/lib/plugin/plugin-so.c b/src/lib/plugin/plugin-so.c index 0f6ec1c6..b33f2053 100644 --- a/src/lib/plugin/plugin-so.c +++ b/src/lib/plugin/plugin-so.c @@ -959,51 +959,27 @@ int bt_plugin_so_init(struct bt_plugin *plugin, } if (cc_full_descr->methods.source.msg_iter_seek_ns_from_origin) { - ret = bt_component_class_source_set_message_iterator_seek_ns_from_origin_method( - src_comp_class, - cc_full_descr->methods.source.msg_iter_seek_ns_from_origin); - if (ret) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set source component class's message iterator \"seek nanoseconds from origin\" method."); - status = BT_FUNC_STATUS_MEMORY_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); - goto end; - } - } - - if (cc_full_descr->methods.source.msg_iter_seek_beginning) { - ret = bt_component_class_source_set_message_iterator_seek_beginning_method( - src_comp_class, - cc_full_descr->methods.source.msg_iter_seek_beginning); - if (ret) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set source component class's message iterator \"seek beginning\" method."); - status = BT_FUNC_STATUS_MEMORY_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); - goto end; - } - } - - if (cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin) { - ret = bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method( + ret = bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods( src_comp_class, + cc_full_descr->methods.source.msg_iter_seek_ns_from_origin, cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set source component class's message iterator \"can seek nanoseconds from origin\" method."); + "Cannot set source component class's message iterator \"seek nanoseconds from origin\" methods."); status = BT_FUNC_STATUS_MEMORY_ERROR; BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); goto end; } } - if (cc_full_descr->methods.source.msg_iter_can_seek_beginning) { - ret = bt_component_class_source_set_message_iterator_can_seek_beginning_method( + if (cc_full_descr->methods.source.msg_iter_seek_beginning) { + ret = bt_component_class_source_set_message_iterator_seek_beginning_methods( src_comp_class, + cc_full_descr->methods.source.msg_iter_seek_beginning, cc_full_descr->methods.source.msg_iter_can_seek_beginning); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set source component class's message iterator \"can seek beginning\" method."); + "Cannot set source component class's message iterator \"seek beginning\" methods."); status = BT_FUNC_STATUS_MEMORY_ERROR; BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); goto end; @@ -1117,51 +1093,27 @@ int bt_plugin_so_init(struct bt_plugin *plugin, } if (cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin) { - ret = bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method( - flt_comp_class, - cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin); - if (ret) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set filter component class's message iterator \"seek nanoseconds from origin\" method."); - status = BT_FUNC_STATUS_MEMORY_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); - goto end; - } - } - - if (cc_full_descr->methods.filter.msg_iter_seek_beginning) { - ret = bt_component_class_filter_set_message_iterator_seek_beginning_method( - flt_comp_class, - cc_full_descr->methods.filter.msg_iter_seek_beginning); - if (ret) { - BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set filter component class's message iterator \"seek beginning\" method."); - status = BT_FUNC_STATUS_MEMORY_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); - goto end; - } - } - - if (cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin) { - ret = bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method( + ret = bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods( flt_comp_class, + cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin, cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set filter component class's message iterator \"can seek nanoseconds from origin\" method."); + "Cannot set filter component class's message iterator \"seek nanoseconds from origin\" methods."); status = BT_FUNC_STATUS_MEMORY_ERROR; BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); goto end; } } - if (cc_full_descr->methods.filter.msg_iter_can_seek_beginning) { - ret = bt_component_class_filter_set_message_iterator_can_seek_beginning_method( + if (cc_full_descr->methods.filter.msg_iter_seek_beginning) { + ret = bt_component_class_filter_set_message_iterator_seek_beginning_methods( flt_comp_class, + cc_full_descr->methods.filter.msg_iter_seek_beginning, cc_full_descr->methods.filter.msg_iter_can_seek_beginning); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set filter component class's message iterator \"can seek beginning\" method."); + "Cannot set filter component class's message iterator \"seek beginning\" methods."); status = BT_FUNC_STATUS_MEMORY_ERROR; BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); goto end; diff --git a/src/plugins/ctf/plugin.c b/src/plugins/ctf/plugin.c index 96758b01..f4b2b506 100644 --- a/src/plugins/ctf/plugin.c +++ b/src/plugins/ctf/plugin.c @@ -55,8 +55,8 @@ BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD(fs, ctf_fs_iterator_init); BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_FINALIZE_METHOD(fs, ctf_fs_iterator_finalize); -BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD(fs, - ctf_fs_iterator_seek_beginning); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHODS(fs, + ctf_fs_iterator_seek_beginning, NULL); /* ctf.fs sink */ BT_PLUGIN_SINK_COMPONENT_CLASS(fs, ctf_fs_sink_consume); diff --git a/src/plugins/lttng-utils/plugin.c b/src/plugins/lttng-utils/plugin.c index c295c9bb..6b180cff 100644 --- a/src/plugins/lttng-utils/plugin.c +++ b/src/plugins/lttng-utils/plugin.c @@ -51,9 +51,9 @@ BT_PLUGIN_FILTER_COMPONENT_CLASS_FINALIZE_METHOD_WITH_ID(lttng_utils, debug_info, debug_info_comp_finalize); BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_WITH_ID( lttng_utils, debug_info, debug_info_msg_iter_init); -BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_WITH_ID( - lttng_utils, debug_info, debug_info_msg_iter_seek_beginning); -BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD_WITH_ID( - lttng_utils, debug_info, debug_info_msg_iter_can_seek_beginning); +BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHODS_WITH_ID( + lttng_utils, debug_info, + debug_info_msg_iter_seek_beginning, + debug_info_msg_iter_can_seek_beginning); BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_FINALIZE_METHOD_WITH_ID( lttng_utils, debug_info, debug_info_msg_iter_finalize); diff --git a/src/plugins/text/plugin.c b/src/plugins/text/plugin.c index 24e187c3..e21ff92d 100644 --- a/src/plugins/text/plugin.c +++ b/src/plugins/text/plugin.c @@ -57,10 +57,8 @@ BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD(dmesg, dmesg_msg_iter_init); BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_FINALIZE_METHOD(dmesg, dmesg_msg_iter_finalize); -BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD(dmesg, - dmesg_msg_iter_seek_beginning); -BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD(dmesg, - dmesg_msg_iter_can_seek_beginning); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHODS(dmesg, + dmesg_msg_iter_seek_beginning, dmesg_msg_iter_can_seek_beginning); /* details sink */ BT_PLUGIN_SINK_COMPONENT_CLASS(details, details_consume); diff --git a/src/plugins/utils/plugin.c b/src/plugins/utils/plugin.c index 3f46fb65..6ae2fd95 100644 --- a/src/plugins/utils/plugin.c +++ b/src/plugins/utils/plugin.c @@ -84,7 +84,5 @@ BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD(muxer, muxer_msg_iter_init); BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_FINALIZE_METHOD(muxer, muxer_msg_iter_finalize); -BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD(muxer, - muxer_msg_iter_seek_beginning); -BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD(muxer, - muxer_msg_iter_can_seek_beginning); +BT_PLUGIN_FILTER_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHODS(muxer, + muxer_msg_iter_seek_beginning, muxer_msg_iter_can_seek_beginning); diff --git a/tests/bindings/python/bt2/test_message_iterator.py b/tests/bindings/python/bt2/test_message_iterator.py index 37f6dc87..d03cdb30 100644 --- a/tests/bindings/python/bt2/test_message_iterator.py +++ b/tests/bindings/python/bt2/test_message_iterator.py @@ -465,6 +465,13 @@ def _setup_seek_test( class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): + def test_can_seek_beginning_without_seek_beginning(self): + with self.assertRaisesRegex( + bt2._IncompleteUserClass, + "cannot create component class 'MySource': message iterator class implements _user_can_seek_beginning but not _user_seek_beginning", + ): + _setup_seek_test(SimpleSink, user_can_seek_beginning=lambda: None) + def test_can_seek_beginning(self): class MySink(bt2._UserSinkComponent): def __init__(self, config, params, obj): @@ -484,7 +491,9 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): return input_port_iter_can_seek_beginning graph = _setup_seek_test( - MySink, user_can_seek_beginning=_user_can_seek_beginning + MySink, + user_can_seek_beginning=_user_can_seek_beginning, + user_seek_beginning=lambda: None, ) input_port_iter_can_seek_beginning = True @@ -560,7 +569,9 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): raise ValueError('moustiquaire') graph = _setup_seek_test( - MySink, user_can_seek_beginning=_user_can_seek_beginning + MySink, + user_can_seek_beginning=_user_can_seek_beginning, + user_seek_beginning=lambda: None, ) with self.assertRaises(bt2._Error) as ctx: @@ -587,7 +598,9 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): return 'Amqui' graph = _setup_seek_test( - MySink, user_can_seek_beginning=_user_can_seek_beginning + MySink, + user_can_seek_beginning=_user_can_seek_beginning, + user_seek_beginning=lambda: None, ) with self.assertRaises(bt2._Error) as ctx: @@ -663,25 +676,47 @@ class UserMessageIteratorSeekBeginningTestCase(unittest.TestCase): class UserMessageIteratorSeekNsFromOriginTestCase(unittest.TestCase): + def test_can_seek_ns_from_origin_without_seek_ns_from_origin(self): + # Test the case where: + # + # - can_seek_ns_from_origin: Returns True (don't really care, as long + # as it's provided) + # - seek_ns_from_origin provided: No + # - can the iterator seek beginning: Don't care + # - can the iterator seek forward: Don't care + for can_seek_ns_from_origin in (False, True): + for iter_can_seek_beginning in (False, True): + for iter_can_seek_forward in (False, True): + with self.assertRaisesRegex( + bt2._IncompleteUserClass, + "cannot create component class 'MySource': message iterator class implements _user_can_seek_ns_from_origin but not _user_seek_ns_from_origin", + ): + self._can_seek_ns_from_origin_test( + None, + user_can_seek_ns_from_origin_ret_val=True, + user_seek_ns_from_origin_provided=False, + iter_can_seek_beginning=iter_can_seek_beginning, + iter_can_seek_forward=iter_can_seek_forward, + ) + def test_can_seek_ns_from_origin_returns_true(self): # Test the case where: # # - can_seek_ns_from_origin: returns True - # - seek_ns_from_origin provided: Don't care + # - seek_ns_from_origin provided: Yes # - can the iterator seek beginning: Don't care # - can the iterator seek forward: Don't care # # We expect iter.can_seek_ns_from_origin to return True. - for user_seek_ns_from_origin_provided in (False, True): - for iter_can_seek_beginning in (False, True): - for iter_can_seek_forward in (False, True): - self._can_seek_ns_from_origin_test( - expected_outcome=True, - user_can_seek_ns_from_origin_ret_val=True, - user_seek_ns_from_origin_provided=user_seek_ns_from_origin_provided, - iter_can_seek_beginning=iter_can_seek_beginning, - iter_can_seek_forward=iter_can_seek_forward, - ) + for iter_can_seek_beginning in (False, True): + for iter_can_seek_forward in (False, True): + self._can_seek_ns_from_origin_test( + expected_outcome=True, + user_can_seek_ns_from_origin_ret_val=True, + user_seek_ns_from_origin_provided=True, + iter_can_seek_beginning=iter_can_seek_beginning, + iter_can_seek_forward=iter_can_seek_forward, + ) def test_can_seek_ns_from_origin_returns_false_can_seek_beginning_forward_seekable( self @@ -689,19 +724,18 @@ class UserMessageIteratorSeekNsFromOriginTestCase(unittest.TestCase): # Test the case where: # # - can_seek_ns_from_origin: returns False - # - seek_ns_from_origin provided: Don't care + # - seek_ns_from_origin provided: Yes # - can the iterator seek beginning: Yes # - can the iterator seek forward: Yes # # We expect iter.can_seek_ns_from_origin to return True. - for user_seek_ns_from_origin_provided in (False, True): - self._can_seek_ns_from_origin_test( - expected_outcome=True, - user_can_seek_ns_from_origin_ret_val=False, - user_seek_ns_from_origin_provided=user_seek_ns_from_origin_provided, - iter_can_seek_beginning=True, - iter_can_seek_forward=True, - ) + self._can_seek_ns_from_origin_test( + expected_outcome=True, + user_can_seek_ns_from_origin_ret_val=False, + user_seek_ns_from_origin_provided=True, + iter_can_seek_beginning=True, + iter_can_seek_forward=True, + ) def test_can_seek_ns_from_origin_returns_false_can_seek_beginning_not_forward_seekable( self @@ -709,19 +743,18 @@ class UserMessageIteratorSeekNsFromOriginTestCase(unittest.TestCase): # Test the case where: # # - can_seek_ns_from_origin: returns False - # - seek_ns_from_origin provided: Don't care + # - seek_ns_from_origin provided: Yes # - can the iterator seek beginning: Yes # - can the iterator seek forward: No # # We expect iter.can_seek_ns_from_origin to return False. - for user_seek_ns_from_origin_provided in (False, True): - self._can_seek_ns_from_origin_test( - expected_outcome=False, - user_can_seek_ns_from_origin_ret_val=False, - user_seek_ns_from_origin_provided=user_seek_ns_from_origin_provided, - iter_can_seek_beginning=True, - iter_can_seek_forward=False, - ) + self._can_seek_ns_from_origin_test( + expected_outcome=False, + user_can_seek_ns_from_origin_ret_val=False, + user_seek_ns_from_origin_provided=True, + iter_can_seek_beginning=True, + iter_can_seek_forward=False, + ) def test_can_seek_ns_from_origin_returns_false_cant_seek_beginning_forward_seekable( self @@ -729,16 +762,15 @@ class UserMessageIteratorSeekNsFromOriginTestCase(unittest.TestCase): # Test the case where: # # - can_seek_ns_from_origin: returns False - # - seek_ns_from_origin provided: Don't care + # - seek_ns_from_origin provided: Yes # - can the iterator seek beginning: No # - can the iterator seek forward: Yes # # We expect iter.can_seek_ns_from_origin to return False. - # for user_seek_ns_from_origin_provided in (False, True): self._can_seek_ns_from_origin_test( expected_outcome=False, user_can_seek_ns_from_origin_ret_val=False, - user_seek_ns_from_origin_provided=False, + user_seek_ns_from_origin_provided=True, iter_can_seek_beginning=False, iter_can_seek_forward=True, ) @@ -749,19 +781,18 @@ class UserMessageIteratorSeekNsFromOriginTestCase(unittest.TestCase): # Test the case where: # # - can_seek_ns_from_origin: returns False - # - seek_ns_from_origin provided: Don't care + # - seek_ns_from_origin provided: Yes # - can the iterator seek beginning: No # - can the iterator seek forward: No # # We expect iter.can_seek_ns_from_origin to return False. - for user_seek_ns_from_origin_provided in (False, True): - self._can_seek_ns_from_origin_test( - expected_outcome=False, - user_can_seek_ns_from_origin_ret_val=False, - user_seek_ns_from_origin_provided=user_seek_ns_from_origin_provided, - iter_can_seek_beginning=False, - iter_can_seek_forward=False, - ) + self._can_seek_ns_from_origin_test( + expected_outcome=False, + user_can_seek_ns_from_origin_ret_val=False, + user_seek_ns_from_origin_provided=True, + iter_can_seek_beginning=False, + iter_can_seek_forward=False, + ) def test_no_can_seek_ns_from_origin_seek_ns_from_origin(self): # Test the case where: @@ -942,7 +973,9 @@ class UserMessageIteratorSeekNsFromOriginTestCase(unittest.TestCase): raise ValueError('Joutel') graph = _setup_seek_test( - MySink, user_can_seek_ns_from_origin=_user_can_seek_ns_from_origin + MySink, + user_can_seek_ns_from_origin=_user_can_seek_ns_from_origin, + user_seek_ns_from_origin=lambda: None, ) with self.assertRaises(bt2._Error) as ctx: @@ -969,7 +1002,9 @@ class UserMessageIteratorSeekNsFromOriginTestCase(unittest.TestCase): return 'Nitchequon' graph = _setup_seek_test( - MySink, user_can_seek_ns_from_origin=_user_can_seek_ns_from_origin + MySink, + user_can_seek_ns_from_origin=_user_can_seek_ns_from_origin, + user_seek_ns_from_origin=lambda: None, ) with self.assertRaises(bt2._Error) as ctx: -- 2.34.1