extern uint64_t bt_field_class_structure_get_member_count(
const bt_field_class *field_class);
-extern void bt_field_class_structure_borrow_member_by_index_const(
- const bt_field_class *struct_field_class, uint64_t index,
- const char **name, const bt_field_class **field_class);
+extern const bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_index_const(
+ const bt_field_class *field_class, uint64_t index);
-extern
-const bt_field_class *
-bt_field_class_structure_borrow_member_field_class_by_name_const(
+extern const bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_name_const(
const bt_field_class *field_class, const char *name);
+extern const char *bt_field_class_structure_member_get_name(
+ const bt_field_class_structure_member *member);
+
+extern const bt_field_class *
+bt_field_class_structure_member_borrow_field_class_const(
+ const bt_field_class_structure_member *member);
+
extern const bt_field_class *
bt_field_class_array_borrow_element_field_class_const(
const bt_field_class *field_class);
extern uint64_t bt_field_class_variant_get_option_count(
const bt_field_class *field_class);
-extern void bt_field_class_variant_borrow_option_by_index_const(
- const bt_field_class *variant_field_class, uint64_t index,
- const char **name, const bt_field_class **field_class);
+extern const bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_index_const(
+ const bt_field_class *field_class, uint64_t index);
-extern
-const bt_field_class *
-bt_field_class_variant_borrow_option_field_class_by_name_const(
- const bt_field_class *field_class,
- const char *name);
+extern const bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_name_const(
+ const bt_field_class *field_class, const char *name);
+
+extern const char *bt_field_class_variant_option_get_name(
+ const bt_field_class_variant_option *option);
+
+extern const bt_field_class *
+bt_field_class_variant_option_borrow_field_class_const(
+ const bt_field_class_variant_option *option);
extern void bt_field_class_get_ref(const bt_field_class *field_class);
/* Owned by this */
struct bt_field_class *fc;
+
+ bool frozen;
};
+struct bt_field_class_structure_member;
+struct bt_field_class_variant_option;
+
/*
* This is the base field class for a container of named field classes.
* Structure and variant field classes inherit this.
# define bt_field_class_freeze(_fc)
#endif
+BT_HIDDEN
+void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc);
+
+#ifdef BT_DEV_MODE
+# define bt_named_field_class_freeze _bt_named_field_class_freeze
+#else
+# define bt_named_field_class_freeze(_named_fc)
+#endif
+
/*
* This function recursively marks `field_class` and its children as
* being part of a trace. This is used to validate that all field classes
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_structure_member *
+bt_field_class_structure_borrow_member_by_index(
+ bt_field_class *field_class, uint64_t index);
-extern
-bt_field_class *bt_field_class_structure_borrow_member_field_class_by_name(
+extern bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_name(
bt_field_class *field_class, const char *name);
extern bt_field_class *bt_field_class_static_array_create(
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_variant_option *
+bt_field_class_variant_borrow_option_by_index(
+ bt_field_class *field_class, uint64_t index);
-extern
-bt_field_class *bt_field_class_variant_borrow_option_field_class_by_name(
- bt_field_class *field_class, const char *name);
+extern bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_name(
+ bt_field_class *field_class, char *name);
+
+extern bt_field_class *bt_field_class_variant_option_borrow_field_class(
+ bt_field_class_variant_option *option);
#ifdef __cplusplus
}
typedef struct bt_field_class bt_field_class;
typedef struct bt_field_class_signed_enumeration_mapping_ranges bt_field_class_signed_enumeration_mapping_ranges;
typedef struct bt_field_class_unsigned_enumeration_mapping_ranges bt_field_class_unsigned_enumeration_mapping_ranges;
+typedef struct bt_field_class_structure_member bt_field_class_structure_member;
+typedef struct bt_field_class_variant_option bt_field_class_variant_option;
typedef struct bt_field_path bt_field_path;
typedef struct bt_graph bt_graph;
typedef struct bt_message bt_message;
bt_object_get_no_null_check(fc);
g_hash_table_insert(container_fc->name_to_index, named_fc->name->str,
GUINT_TO_POINTER(container_fc->named_fcs->len - 1));
+
+ /*
+ * Freeze the field class, but not the named field class (the
+ * user can still modify it, if possible, until the container
+ * itself is frozen).
+ */
bt_field_class_freeze(fc);
end:
}
static
-void borrow_named_field_class_from_container_field_class_at_index(
+struct bt_named_field_class *
+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,
- struct bt_field_class **out_fc)
+ uint64_t index)
{
- struct bt_named_field_class *named_fc;
-
BT_ASSERT(fc);
- BT_ASSERT_PRE_NON_NULL(name, "Name");
- BT_ASSERT_PRE_NON_NULL(out_fc, "Field class (output)");
BT_ASSERT_PRE_VALID_INDEX(index, fc->named_fcs->len);
- named_fc = BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, index);
- *name = named_fc->name->str;
- *out_fc = named_fc->fc;
+ return BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc, index);
}
-void bt_field_class_structure_borrow_member_by_index_const(
- const struct bt_field_class *fc, uint64_t index,
- const char **name, const struct bt_field_class **out_fc)
+const struct bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_index_const(
+ const struct bt_field_class *fc, uint64_t index)
{
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, (void *) out_fc);
+ return (const void *)
+ borrow_named_field_class_from_container_field_class_at_index(
+ (void *) fc, index);
}
-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)
+struct bt_field_class_structure_member *
+bt_field_class_structure_borrow_member_by_index(
+ struct bt_field_class *fc, uint64_t index)
{
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);
+ return (void *)
+ borrow_named_field_class_from_container_field_class_at_index(
+ (void *) fc, index);
}
static
-struct bt_field_class *
-borrow_field_class_from_container_field_class_by_name(
+struct bt_named_field_class *
+borrow_named_field_class_from_container_field_class_by_name(
struct bt_field_class_named_field_class_container *fc,
const char *name)
{
- struct bt_field_class *ret_fc = NULL;
- struct bt_named_field_class *named_fc;
+ struct bt_named_field_class *named_fc = NULL;
gpointer orig_key;
gpointer value;
named_fc = BT_FIELD_CLASS_NAMED_FC_AT_INDEX(fc,
GPOINTER_TO_UINT(value));
- ret_fc = named_fc->fc;
end:
- return ret_fc;
+ return named_fc;
}
-const struct bt_field_class *
+const struct bt_field_class_structure_member *
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(
+ return (const void *)
+ borrow_named_field_class_from_container_field_class_by_name(
(void *) fc, name);
}
-struct bt_field_class *
+struct bt_field_class_structure_member *
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(
+ return (void *)
+ borrow_named_field_class_from_container_field_class_by_name(
(void *) fc, name);
}
+const char *bt_field_class_structure_member_get_name(
+ const struct bt_field_class_structure_member *member)
+{
+ const struct bt_named_field_class *named_fc = (const void *) member;
+
+ BT_ASSERT_PRE_NON_NULL(member, "Structure field class member");
+ return named_fc->name->str;
+}
+
+const struct bt_field_class *
+bt_field_class_structure_member_borrow_field_class_const(
+ const struct bt_field_class_structure_member *member)
+{
+ const struct bt_named_field_class *named_fc = (const void *) member;
+
+ BT_ASSERT_PRE_NON_NULL(member, "Structure field class member");
+ return named_fc->fc;
+}
+
+struct bt_field_class *
+bt_field_class_structure_member_borrow_field_class(
+ struct bt_field_class_structure_member *member)
+{
+ struct bt_named_field_class *named_fc = (void *) member;
+
+ BT_ASSERT_PRE_NON_NULL(member, "Structure field class member");
+ return named_fc->fc;
+}
+
static
void destroy_variant_field_class(struct bt_object *obj)
{
name, option_fc);
}
-const struct bt_field_class *
+const struct bt_field_class_variant_option *
bt_field_class_variant_borrow_option_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_VARIANT, "Field class");
- return borrow_field_class_from_container_field_class_by_name(
- (void *) fc, name);
+ return (const void *)
+ borrow_named_field_class_from_container_field_class_by_name(
+ (void *) fc, name);
}
-struct bt_field_class *
+struct bt_field_class_variant_option *
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);
+ return (void *)
+ borrow_named_field_class_from_container_field_class_by_name(
+ (void *) fc, name);
}
uint64_t bt_field_class_variant_get_option_count(const struct bt_field_class *fc)
return (uint64_t) var_fc->common.named_fcs->len;
}
-void bt_field_class_variant_borrow_option_by_index_const(
- const struct bt_field_class *fc, uint64_t index,
- const char **name, const struct bt_field_class **out_fc)
+const struct bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_index_const(
+ const struct bt_field_class *fc, uint64_t index)
{
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, (void *) out_fc);
+ return (const void *)
+ borrow_named_field_class_from_container_field_class_at_index(
+ (void *) fc, index);
}
-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)
+struct bt_field_class_variant_option *
+bt_field_class_variant_borrow_option_by_index(
+ struct bt_field_class *fc, uint64_t index)
{
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);
+ return (void *)
+ borrow_named_field_class_from_container_field_class_at_index(
+ (void *) fc, index);
+}
+
+const char *bt_field_class_variant_option_get_name(
+ const struct bt_field_class_variant_option *option)
+{
+ const struct bt_named_field_class *named_fc = (const void *) option;
+
+ BT_ASSERT_PRE_NON_NULL(option, "Variant field class option");
+ return named_fc->name->str;
+}
+
+const struct bt_field_class *
+bt_field_class_variant_option_borrow_field_class_const(
+ const struct bt_field_class_variant_option *option)
+{
+ const struct bt_named_field_class *named_fc = (const void *) option;
+
+ BT_ASSERT_PRE_NON_NULL(option, "Variant field class option");
+ return named_fc->fc;
+}
+
+struct bt_field_class *
+bt_field_class_variant_option_borrow_field_class(
+ struct bt_field_class_variant_option *option)
+{
+ struct bt_named_field_class *named_fc = (void *) option;
+
+ BT_ASSERT_PRE_NON_NULL(option, "Variant field class option");
+ return named_fc->fc;
}
const struct bt_field_path *
}
BT_HIDDEN
-void _bt_field_class_freeze(const struct bt_field_class *fc)
+void _bt_field_class_freeze(const struct bt_field_class *c_fc)
{
+ struct bt_field_class *fc = (void *) c_fc;
+
/*
* Element/member/option field classes are frozen when added to
* their owner.
*/
BT_ASSERT(fc);
- ((struct bt_field_class *) fc)->frozen = true;
+ fc->frozen = true;
+
+ switch (fc->type) {
+ case BT_FIELD_CLASS_TYPE_STRUCTURE:
+ case BT_FIELD_CLASS_TYPE_VARIANT:
+ {
+ struct bt_field_class_named_field_class_container *container_fc =
+ (void *) fc;
+ uint64_t i;
+
+ for (i = 0; i < container_fc->named_fcs->len; i++) {
+ struct bt_named_field_class *named_fc =
+ BT_FIELD_CLASS_NAMED_FC_AT_INDEX(
+ container_fc, i);
+
+ bt_named_field_class_freeze(named_fc);
+ }
+
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+BT_HIDDEN
+void _bt_named_field_class_freeze(const struct bt_named_field_class *named_fc)
+{
+ BT_ASSERT(named_fc);
+ ((struct bt_named_field_class *) named_fc)->frozen = true;
+ bt_field_class_freeze(named_fc->fc);
}
BT_HIDDEN
uint64_t i, nb_member_struct;
const bt_field *in_member_field;
bt_field *out_member_field;
- const bt_field_class *in_field_class, *in_member_field_class;
+ const bt_field_class *in_field_class;
const char *in_member_name;
in_field_class = bt_field_borrow_class_const(in_field);
* the debug-info was added.
*/
for (i = 0; i < nb_member_struct; i++) {
- bt_field_class_structure_borrow_member_by_index_const(
- in_field_class, i, &in_member_name,
- &in_member_field_class);
+ const bt_field_class_structure_member *member =
+ bt_field_class_structure_borrow_member_by_index_const(
+ in_field_class, i);
+ in_member_name =
+ bt_field_class_structure_member_get_name(
+ member);
in_member_field =
bt_field_structure_borrow_member_field_by_name_const(
in_field, in_member_name);
fp_index_count = bt_field_path_get_index_count(fp);
curr_fc = fc;
for (i = 0; i < fp_index_count; i++) {
- const char *fc_name;
bt_field_class_type fc_type = bt_field_class_get_type(curr_fc);
uint64_t curr_index = bt_field_path_get_index_by_index(fp, i);
switch (fc_type) {
case BT_FIELD_CLASS_TYPE_STRUCTURE:
- bt_field_class_structure_borrow_member_by_index_const(
- curr_fc, curr_index, &fc_name, &curr_fc);
+ {
+ const bt_field_class_structure_member *member =
+ bt_field_class_structure_borrow_member_by_index_const(
+ curr_fc, curr_index);
+ curr_fc = bt_field_class_structure_member_borrow_field_class_const(
+ member);
break;
+ }
case BT_FIELD_CLASS_TYPE_VARIANT:
- bt_field_class_variant_borrow_option_by_index_const(
- curr_fc, curr_index, &fc_name, &curr_fc);
+ {
+ const bt_field_class_variant_option *option =
+ bt_field_class_variant_borrow_option_by_index_const(
+ curr_fc, curr_index);
+ curr_fc = bt_field_class_variant_option_borrow_field_class_const(
+ option);
break;
+ }
default:
abort();
}
/* Iterate over all the members of the struct. */
for (i = 0; i < struct_member_count; i++) {
+ const bt_field_class_structure_member *member;
const char *member_name;
const bt_field_class *member_fc;
bt_field_class *out_member_field_class;
- bt_field_class_structure_borrow_member_by_index_const(
- in_field_class, i, &member_name, &member_fc);
+ member = bt_field_class_structure_borrow_member_by_index_const(
+ in_field_class, i);
+ member_fc = bt_field_class_structure_member_borrow_field_class_const(
+ member);
+ member_name = bt_field_class_structure_member_get_name(member);
BT_LOGD("Copying structure field class's field: "
"index=%" PRId64 ", "
"member-fc-addr=%p, field-name=\"%s\"",
variant_option_count =
bt_field_class_variant_get_option_count(in_field_class);
for (i = 0; i < variant_option_count; i++) {
- const bt_field_class *option;
+ const bt_field_class *option_fc;
const char *option_name;
bt_field_class *out_option_field_class;
bt_field_class_status status;
+ const bt_field_class_variant_option *option;
- bt_field_class_variant_borrow_option_by_index_const(in_field_class,
- i, &option_name, &option);
-
+ option = bt_field_class_variant_borrow_option_by_index_const(
+ in_field_class, i);
+ option_fc = bt_field_class_variant_option_borrow_field_class_const(
+ option);
+ option_name = bt_field_class_variant_option_get_name(option);
out_option_field_class = create_field_class_copy_internal(
- md_maps, option);
+ md_maps, option_fc);
if (!out_option_field_class) {
BT_LOGE_STR("Cannot copy field class.");
ret = -1;
goto error;
}
- ret = copy_field_class_content_internal(md_maps, option,
+ ret = copy_field_class_content_internal(md_maps, option_fc,
out_option_field_class);
if (ret) {
BT_LOGE_STR("Error copying content of option variant "
bt_bool is_event_common_ctx_dbg_info_compatible(const bt_field_class *in_field_class,
const char *debug_info_field_class_name)
{
- const bt_field_class *ip_fc, *vpid_fc, *debug_info_fc;
+ const bt_field_class_structure_member *member;
+ const bt_field_class *ip_fc, *vpid_fc;
bt_bool match = BT_FALSE;
/*
* If the debug info field is already present in the event common
* context. Do not try to add it.
*/
- debug_info_fc =
- bt_field_class_structure_borrow_member_field_class_by_name_const(
+ member =
+ bt_field_class_structure_borrow_member_by_name_const(
in_field_class, debug_info_field_class_name);
- if (debug_info_fc) {
+ if (member) {
goto end;
}
* Verify that the ip and vpid field are present and of the right field
* class.
*/
- ip_fc = bt_field_class_structure_borrow_member_field_class_by_name_const(
+ member = bt_field_class_structure_borrow_member_by_name_const(
in_field_class, IP_FIELD_NAME);
- if (!ip_fc) {
+ if (!member) {
goto end;
}
+ ip_fc = bt_field_class_structure_member_borrow_field_class_const(
+ member);
if (bt_field_class_get_type(ip_fc) !=
BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER) {
match = BT_FALSE;
goto end;
}
- vpid_fc = bt_field_class_structure_borrow_member_field_class_by_name_const(
+ member = bt_field_class_structure_borrow_member_by_name_const(
in_field_class, VPID_FIELD_NAME);
- if (!vpid_fc) {
+ if (!member) {
goto end;
}
+ vpid_fc = bt_field_class_structure_member_borrow_field_class_const(
+ member);
+
if (bt_field_class_get_type(vpid_fc) !=
BT_FIELD_CLASS_TYPE_SIGNED_INTEGER) {
goto end;
}
match = BT_TRUE;
+
end:
return match;
}
int ret = 0;
const char *field_name;
const bt_field *field = NULL;
- const bt_field_class *field_class = NULL;;
+ const bt_field_class_structure_member *member;
field = bt_field_structure_borrow_member_field_by_index_const(_struct, i);
if (!field) {
goto end;
}
- bt_field_class_structure_borrow_member_by_index_const(struct_class, i,
- &field_name, &field_class);
+ member = bt_field_class_structure_borrow_member_by_index_const(
+ struct_class, i);
+ field_name = bt_field_class_structure_member_get_name(member);
if (filter_fields && !filter_field_name(pretty, field_name,
filter_fields, filter_array_len)) {