From 61fd44ac72299fadcaa04c19c4ffee7bfa6ccadb Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 1 May 2019 10:17:33 -0400 Subject: [PATCH] lib: Add functions to borrow specialized component classes from specialized components The API currently contains a function to obtain a 'bt_component_class *' from a 'bt_component *'. This patch adds functions to obtain a specialized component class from a specialized component. For example, a 'bt_component_class_source *' from a 'bt_component_source *'. Change-Id: Ide192c7759f630adbc884def2e5c462ce2b8f973 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/1161 Tested-by: jenkins Reviewed-by: Philippe Proulx --- bindings/python/bt2/bt2/native_bt_component.i | 12 ++++++++++++ .../babeltrace/graph/component-filter-const.h | 6 +++++- include/babeltrace/graph/component-sink-const.h | 6 +++++- .../babeltrace/graph/component-source-const.h | 6 +++++- lib/graph/component-filter.c | 16 ++++++++++++++++ lib/graph/component-sink.c | 16 ++++++++++++++++ lib/graph/component-source.c | 16 ++++++++++++++++ 7 files changed, 75 insertions(+), 3 deletions(-) diff --git a/bindings/python/bt2/bt2/native_bt_component.i b/bindings/python/bt2/bt2/native_bt_component.i index 012b194f..6612ad9c 100644 --- a/bindings/python/bt2/bt2/native_bt_component.i +++ b/bindings/python/bt2/bt2/native_bt_component.i @@ -90,6 +90,10 @@ extern void bt_component_put_ref(const bt_component *component); const bt_component *bt_component_source_as_component_const( const bt_component_source *component); +extern const bt_component_class_source * +bt_component_source_borrow_class_const( + const bt_component_source *component); + extern uint64_t bt_component_source_get_output_port_count( const bt_component_source *component); @@ -112,6 +116,10 @@ extern void bt_component_source_put_ref( const bt_component *bt_component_filter_as_component_const( const bt_component_filter *component); +extern const bt_component_class_filter * +bt_component_filter_borrow_class_const( + const bt_component_filter *component); + extern uint64_t bt_component_filter_get_input_port_count( const bt_component_filter *component); @@ -145,6 +153,10 @@ extern void bt_component_filter_put_ref( const bt_component *bt_component_sink_as_component_const( const bt_component_sink *component); +extern const bt_component_class_sink * +bt_component_sink_borrow_class_const( + const bt_component_sink *component); + extern uint64_t bt_component_sink_get_input_port_count( const bt_component_sink *component); diff --git a/include/babeltrace/graph/component-filter-const.h b/include/babeltrace/graph/component-filter-const.h index 546761e3..545691cd 100644 --- a/include/babeltrace/graph/component-filter-const.h +++ b/include/babeltrace/graph/component-filter-const.h @@ -28,7 +28,7 @@ /* * For bt_component, bt_component_filter, bt_port_input, bt_port_output, - * __BT_UPCAST_CONST + * __BT_UPCAST_CONST, bt_component_class_filter */ #include @@ -43,6 +43,10 @@ const bt_component *bt_component_filter_as_component_const( return __BT_UPCAST_CONST(bt_component, component); } +extern const bt_component_class_filter * +bt_component_filter_borrow_class_const( + const bt_component_filter *component); + extern uint64_t bt_component_filter_get_input_port_count( const bt_component_filter *component); diff --git a/include/babeltrace/graph/component-sink-const.h b/include/babeltrace/graph/component-sink-const.h index d0bd773d..5ce67982 100644 --- a/include/babeltrace/graph/component-sink-const.h +++ b/include/babeltrace/graph/component-sink-const.h @@ -28,7 +28,7 @@ /* * For bt_component, bt_component_filter, bt_port_input, - * __BT_UPCAST_CONST + * __BT_UPCAST_CONST, bt_component_class_sink */ #include @@ -43,6 +43,10 @@ const bt_component *bt_component_sink_as_component_const( return __BT_UPCAST_CONST(bt_component, component); } +extern const bt_component_class_sink * +bt_component_sink_borrow_class_const( + const bt_component_sink *component); + extern uint64_t bt_component_sink_get_input_port_count( const bt_component_sink *component); diff --git a/include/babeltrace/graph/component-source-const.h b/include/babeltrace/graph/component-source-const.h index 628f22db..8604359a 100644 --- a/include/babeltrace/graph/component-source-const.h +++ b/include/babeltrace/graph/component-source-const.h @@ -28,7 +28,7 @@ /* * For bt_component, bt_component_filter, bt_port_output, - * __BT_UPCAST_CONST + * __BT_UPCAST_CONST, bt_component_class_source */ #include @@ -43,6 +43,10 @@ const bt_component *bt_component_source_as_component_const( return __BT_UPCAST_CONST(bt_component, component); } +extern const bt_component_class_source * +bt_component_source_borrow_class_const( + const bt_component_source *component); + extern uint64_t bt_component_source_get_output_port_count( const bt_component_source *component); diff --git a/lib/graph/component-filter.c b/lib/graph/component-filter.c index 32a12924..c1c730ca 100644 --- a/lib/graph/component-filter.c +++ b/lib/graph/component-filter.c @@ -56,6 +56,22 @@ end: return (void *) filter; } +const bt_component_class_filter * +bt_component_filter_borrow_class_const( + const bt_component_filter *component) +{ + struct bt_component_class *cls; + + BT_ASSERT_PRE_NON_NULL(component, "Component"); + + cls = component->parent.class; + + BT_ASSERT(cls); + BT_ASSERT(cls->type == BT_COMPONENT_CLASS_TYPE_FILTER); + + return (bt_component_class_filter *) cls; +} + uint64_t bt_component_filter_get_output_port_count( const struct bt_component_filter *comp) { diff --git a/lib/graph/component-sink.c b/lib/graph/component-sink.c index 41a9a376..30c15609 100644 --- a/lib/graph/component-sink.c +++ b/lib/graph/component-sink.c @@ -55,6 +55,22 @@ end: return (void *) sink; } +const bt_component_class_sink * +bt_component_sink_borrow_class_const( + const bt_component_sink *component) +{ + struct bt_component_class *cls; + + BT_ASSERT_PRE_NON_NULL(component, "Component"); + + cls = component->parent.class; + + BT_ASSERT(cls); + BT_ASSERT(cls->type == BT_COMPONENT_CLASS_TYPE_SINK); + + return (bt_component_class_sink *) cls; +} + uint64_t bt_component_sink_get_input_port_count( const struct bt_component_sink *component) { diff --git a/lib/graph/component-source.c b/lib/graph/component-source.c index 39755af4..b638c332 100644 --- a/lib/graph/component-source.c +++ b/lib/graph/component-source.c @@ -57,6 +57,22 @@ end: return (void *) source; } +const bt_component_class_source * +bt_component_source_borrow_class_const( + const bt_component_source *component) +{ + struct bt_component_class *cls; + + BT_ASSERT_PRE_NON_NULL(component, "Component"); + + cls = component->parent.class; + + BT_ASSERT(cls); + BT_ASSERT(cls->type == BT_COMPONENT_CLASS_TYPE_SOURCE); + + return (bt_component_class_source *) cls; +} + uint64_t bt_component_source_get_output_port_count( const struct bt_component_source *comp) { -- 2.34.1