Add support for variant fields in the Python bindings
[babeltrace.git] / formats / ctf / events.c
index 3cf3b88f710234c851f5bf8ece79c2ab10fff594..f38278aadc6d64ebd4be1f5d9165bf31b313f339 100644 (file)
@@ -289,8 +289,8 @@ struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *ctf_event
        cfs = container_of(event->stream, const struct ctf_file_stream,
                        parent);
        trace = cfs->parent.stream_class->trace;
-       if (trace->ctx)
-               ret = trace->ctx;
+       if (trace->parent.ctx)
+               ret = trace->parent.ctx;
 
        return ret;
 }
@@ -309,8 +309,8 @@ int bt_ctf_event_get_handle_id(const struct bt_ctf_event *ctf_event)
        cfs = container_of(event->stream, const struct ctf_file_stream,
                        parent);
        trace = cfs->parent.stream_class->trace;
-       if (trace->handle)
-               ret = trace->handle->id;
+       if (trace->parent.handle)
+               ret = trace->parent.handle->id;
 
        return ret;
 }
@@ -608,6 +608,42 @@ char *bt_ctf_get_string(const struct bt_definition *field)
        return ret;
 }
 
+double bt_ctf_get_float(const struct bt_definition *field)
+{
+       double ret = 0.0;
+
+       if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_FLOAT) {
+               ret = bt_get_float(field);
+       } else {
+               bt_ctf_field_set_error(-EINVAL);
+       }
+
+       return ret;
+}
+
+const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field)
+{
+       const struct bt_definition *ret = NULL;
+
+       if (field && bt_ctf_field_type(
+               bt_ctf_get_decl_from_def(field)) == CTF_TYPE_VARIANT) {
+               struct definition_variant *variant = container_of(field,
+                       struct definition_variant, p);
+
+               ret = bt_variant_get_current_field(variant);
+       } else {
+               bt_ctf_field_set_error(-EINVAL);
+       }
+
+       return ret;
+}
+       } else {
+               bt_ctf_field_set_error(-EINVAL);
+       }
+
+       return ret;
+}
+
 int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
                struct bt_ctf_event_decl * const **list,
                unsigned int *count)
@@ -653,11 +689,11 @@ int bt_ctf_get_decl_fields(struct bt_ctf_event_decl *event_decl,
        gpointer *ret_list = NULL;
        GPtrArray *fields_array = NULL;
        int ret = 0;
-       *count = 0;
 
        if (!event_decl || !list || !count)
                return -EINVAL;
 
+       *count = 0;
        switch (scope) {
        case BT_EVENT_CONTEXT:
                if (event_decl->context_decl) {
This page took 0.023433 seconds and 4 git commands to generate.