From 740faaf49474c4127165a73f0eacd921d1daf145 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 15 Mar 2019 18:03:01 -0400 Subject: [PATCH] lib: metadata: add missing non-const borrowing accessors Add a few missing non-const borrowing accessors in the metadata part of trace IR. They are not strictly needed for anything written in C (because since you own the non-const object, you typically don't need to read a property that you set yourself), but they will help make some binding wrapper APIs symmetrical. Signed-off-by: Philippe Proulx --- include/babeltrace/trace-ir/event-class.h | 6 ++ include/babeltrace/trace-ir/field-class.h | 19 +++++ include/babeltrace/trace-ir/stream-class.h | 8 ++ lib/trace-ir/event-class.c | 15 ++++ lib/trace-ir/field-class.c | 90 ++++++++++++++++++---- lib/trace-ir/stream-class.c | 16 ++++ 6 files changed, 137 insertions(+), 17 deletions(-) diff --git a/include/babeltrace/trace-ir/event-class.h b/include/babeltrace/trace-ir/event-class.h index 7067b582..50cefeff 100644 --- a/include/babeltrace/trace-ir/event-class.h +++ b/include/babeltrace/trace-ir/event-class.h @@ -61,10 +61,16 @@ extern bt_event_class_status bt_event_class_set_specific_context_field_class(bt_event_class *event_class, bt_field_class *field_class); +extern bt_field_class * +bt_event_class_borrow_specific_context_field_class(bt_event_class *event_class); + extern bt_event_class_status bt_event_class_set_payload_field_class( bt_event_class *event_class, bt_field_class *field_class); +extern bt_field_class *bt_event_class_borrow_payload_field_class( + bt_event_class *event_class); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/trace-ir/field-class.h b/include/babeltrace/trace-ir/field-class.h index df5f87d9..a23deb58 100644 --- a/include/babeltrace/trace-ir/field-class.h +++ b/include/babeltrace/trace-ir/field-class.h @@ -86,6 +86,14 @@ extern bt_field_class_status bt_field_class_structure_append_member( bt_field_class *struct_field_class, const char *name, bt_field_class *field_class); +extern void bt_field_class_structure_borrow_member_by_index( + bt_field_class *struct_field_class, uint64_t index, + const char **name, bt_field_class **field_class); + +extern +bt_field_class *bt_field_class_structure_borrow_member_field_class_by_name( + bt_field_class *field_class, const char *name); + extern bt_field_class *bt_field_class_static_array_create( bt_trace_class *trace_class, bt_field_class *elem_field_class, uint64_t length); @@ -94,6 +102,9 @@ extern bt_field_class *bt_field_class_dynamic_array_create( bt_trace_class *trace_class, bt_field_class *elem_field_class); +extern bt_field_class *bt_field_class_array_borrow_element_field_class( + bt_field_class *field_class); + extern bt_field_class_status bt_field_class_dynamic_array_set_length_field_class( bt_field_class *field_class, @@ -110,6 +121,14 @@ extern bt_field_class_status bt_field_class_variant_append_option( bt_field_class *var_field_class, const char *name, bt_field_class *field_class); +extern void bt_field_class_variant_borrow_option_by_index( + bt_field_class *variant_field_class, uint64_t index, + const char **name, bt_field_class **field_class); + +extern +bt_field_class *bt_field_class_variant_borrow_option_field_class_by_name( + bt_field_class *field_class, const char *name); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/trace-ir/stream-class.h b/include/babeltrace/trace-ir/stream-class.h index 836979df..863f2936 100644 --- a/include/babeltrace/trace-ir/stream-class.h +++ b/include/babeltrace/trace-ir/stream-class.h @@ -65,11 +65,19 @@ bt_stream_class_set_packet_context_field_class( bt_stream_class *stream_class, bt_field_class *field_class); +extern bt_field_class * +bt_stream_class_borrow_packet_context_field_class( + bt_stream_class *stream_class); + extern bt_stream_class_status bt_stream_class_set_event_common_context_field_class( bt_stream_class *stream_class, bt_field_class *field_class); +extern bt_field_class * +bt_stream_class_borrow_event_common_context_field_class( + bt_stream_class *stream_class); + extern bt_event_class * bt_stream_class_borrow_event_class_by_index( bt_stream_class *stream_class, uint64_t index); diff --git a/lib/trace-ir/event-class.c b/lib/trace-ir/event-class.c index 6ed174bb..0dc3f672 100644 --- a/lib/trace-ir/event-class.c +++ b/lib/trace-ir/event-class.c @@ -273,6 +273,14 @@ bt_event_class_borrow_specific_context_field_class_const( return event_class->specific_context_fc; } +struct bt_field_class * +bt_event_class_borrow_specific_context_field_class( + struct bt_event_class *event_class) +{ + BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); + return event_class->specific_context_fc; +} + enum bt_event_class_status bt_event_class_set_specific_context_field_class( struct bt_event_class *event_class, struct bt_field_class *field_class) @@ -329,6 +337,13 @@ const struct bt_field_class *bt_event_class_borrow_payload_field_class_const( return event_class->payload_fc; } +struct bt_field_class *bt_event_class_borrow_payload_field_class( + struct bt_event_class *event_class) +{ + BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); + return event_class->payload_fc; +} + enum bt_event_class_status bt_event_class_set_payload_field_class( struct bt_event_class *event_class, struct bt_field_class *field_class) diff --git a/lib/trace-ir/field-class.c b/lib/trace-ir/field-class.c index 02a59d94..59a2c1f5 100644 --- a/lib/trace-ir/field-class.c +++ b/lib/trace-ir/field-class.c @@ -787,7 +787,8 @@ enum bt_field_class_status bt_field_class_structure_append_member( { BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); return append_named_field_class_to_container_field_class((void *) fc, name, member_fc); } @@ -798,17 +799,18 @@ uint64_t bt_field_class_structure_get_member_count( struct bt_field_class_structure *struct_fc = (void *) fc; BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); return (uint64_t) struct_fc->common.named_fcs->len; } static -void borrow_named_field_class_from_container_field_class_at_index_const( - const struct bt_field_class_named_field_class_container *fc, +void borrow_named_field_class_from_container_field_class_at_index( + struct bt_field_class_named_field_class_container *fc, uint64_t index, const char **name, - const struct bt_field_class **out_fc) + struct bt_field_class **out_fc) { - const struct bt_named_field_class *named_fc; + struct bt_named_field_class *named_fc; BT_ASSERT(fc); BT_ASSERT_PRE_NON_NULL(name, "Name"); @@ -824,19 +826,31 @@ void bt_field_class_structure_borrow_member_by_index_const( const char **name, const struct bt_field_class **out_fc) { BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class"); - borrow_named_field_class_from_container_field_class_at_index_const( + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); + borrow_named_field_class_from_container_field_class_at_index( + (void *) fc, index, name, (void *) out_fc); +} + +void bt_field_class_structure_borrow_member_by_index( + struct bt_field_class *fc, uint64_t index, + const char **name, struct bt_field_class **out_fc) +{ + BT_ASSERT_PRE_NON_NULL(fc, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); + borrow_named_field_class_from_container_field_class_at_index( (void *) fc, index, name, out_fc); } static -const struct bt_field_class * -borrow_field_class_from_container_field_class_by_name_const( - const struct bt_field_class_named_field_class_container *fc, +struct bt_field_class * +borrow_field_class_from_container_field_class_by_name( + struct bt_field_class_named_field_class_container *fc, const char *name) { - const struct bt_field_class *ret_fc = NULL; - const struct bt_named_field_class *named_fc; + struct bt_field_class *ret_fc = NULL; + struct bt_named_field_class *named_fc; gpointer orig_key; gpointer value; @@ -860,8 +874,20 @@ bt_field_class_structure_borrow_member_field_class_by_name_const( const struct bt_field_class *fc, const char *name) { BT_ASSERT_PRE_NON_NULL(fc, "Field class"); - BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, "Field class"); - return borrow_field_class_from_container_field_class_by_name_const( + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); + return borrow_field_class_from_container_field_class_by_name( + (void *) fc, name); +} + +struct bt_field_class * +bt_field_class_structure_borrow_member_field_class_by_name( + struct bt_field_class *fc, const char *name) +{ + BT_ASSERT_PRE_NON_NULL(fc, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_STRUCTURE, + "Field class"); + return borrow_field_class_from_container_field_class_by_name( (void *) fc, name); } @@ -944,7 +970,17 @@ bt_field_class_variant_borrow_option_field_class_by_name_const( { BT_ASSERT_PRE_NON_NULL(fc, "Field class"); BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); - return borrow_field_class_from_container_field_class_by_name_const( + return borrow_field_class_from_container_field_class_by_name( + (void *) fc, name); +} + +struct bt_field_class * +bt_field_class_variant_borrow_option_field_class_by_name( + struct bt_field_class *fc, const char *name) +{ + BT_ASSERT_PRE_NON_NULL(fc, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); + return borrow_field_class_from_container_field_class_by_name( (void *) fc, name); } @@ -963,7 +999,17 @@ void bt_field_class_variant_borrow_option_by_index_const( { BT_ASSERT_PRE_NON_NULL(fc, "Field class"); BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); - borrow_named_field_class_from_container_field_class_at_index_const( + borrow_named_field_class_from_container_field_class_at_index( + (void *) fc, index, name, (void *) out_fc); +} + +void bt_field_class_variant_borrow_option_by_index( + struct bt_field_class *fc, uint64_t index, + const char **name, struct bt_field_class **out_fc) +{ + BT_ASSERT_PRE_NON_NULL(fc, "Field class"); + BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_VARIANT, "Field class"); + borrow_named_field_class_from_container_field_class_at_index( (void *) fc, index, name, out_fc); } @@ -1047,6 +1093,16 @@ bt_field_class_array_borrow_element_field_class_const( return array_fc->element_fc; } +struct bt_field_class * +bt_field_class_array_borrow_element_field_class(struct bt_field_class *fc) +{ + struct bt_field_class_array *array_fc = (void *) fc; + + BT_ASSERT_PRE_NON_NULL(fc, "Field class"); + BT_ASSERT_PRE_FC_IS_ARRAY(fc, "Field class"); + return array_fc->element_fc; +} + uint64_t bt_field_class_static_array_get_length(const struct bt_field_class *fc) { const struct bt_field_class_static_array *array_fc = (const void *) fc; diff --git a/lib/trace-ir/stream-class.c b/lib/trace-ir/stream-class.c index b76580d5..12713742 100644 --- a/lib/trace-ir/stream-class.c +++ b/lib/trace-ir/stream-class.c @@ -284,6 +284,14 @@ bt_stream_class_borrow_packet_context_field_class_const( return stream_class->packet_context_fc; } +struct bt_field_class * +bt_stream_class_borrow_packet_context_field_class( + struct bt_stream_class *stream_class) +{ + BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); + return stream_class->packet_context_fc; +} + enum bt_stream_class_status bt_stream_class_set_packet_context_field_class( struct bt_stream_class *stream_class, struct bt_field_class *field_class) @@ -334,6 +342,14 @@ bt_stream_class_borrow_event_common_context_field_class_const( return stream_class->event_common_context_fc; } +struct bt_field_class * +bt_stream_class_borrow_event_common_context_field_class( + struct bt_stream_class *stream_class) +{ + BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class"); + return stream_class->event_common_context_fc; +} + enum bt_stream_class_status bt_stream_class_set_event_common_context_field_class( struct bt_stream_class *stream_class, -- 2.34.1