Add Python bindings for CTF-IR event-types getters
[babeltrace.git] / bindings / python / python-complements.c
index 3172c74fc07fc2619d1f7d52a3fc0884378ef8c0..c6c7c8e62e74ee395578fd5d6ca9b9ff7ff79f69 100644 (file)
 #include "python-complements.h"
 #include <babeltrace/ctf-ir/event-types-internal.h>
 #include <babeltrace/ctf-ir/event-fields-internal.h>
-
-/* FILE functions
-   ----------------------------------------------------
-*/
-
-FILE *_bt_file_open(char *file_path, char *mode)
-{
-       FILE *fp = stdout;
-       if (file_path != NULL)
-               fp = fopen(file_path, mode);
-       return fp;
-}
-
-void _bt_file_close(FILE *fp)
-{
-       if (fp != NULL)
-               fclose(fp);
-}
-
+#include <babeltrace/ctf-ir/event-types.h>
 
 /* List-related functions
    ----------------------------------------------------
@@ -236,3 +218,94 @@ enum ctf_type_id _bt_python_get_field_type(const struct bt_ctf_field *field)
 end:
        return type_id;
 }
+
+/*
+ * Swig doesn't handle returning pointers via output arguments properly...
+ * These functions only wrap the ctf-ir functions to provide them directly
+ * as regular return values.
+ */
+const char *_bt_python_ctf_field_type_enumeration_get_mapping(
+               struct bt_ctf_field_type *enumeration, size_t index,
+               int64_t *range_start, int64_t *range_end)
+{
+       int ret;
+       const char *name;
+
+       ret = bt_ctf_field_type_enumeration_get_mapping(enumeration, index,
+               &name, range_start, range_end);
+       return !ret ? name : NULL;
+}
+
+const char *_bt_python_ctf_field_type_enumeration_get_mapping_unsigned(
+               struct bt_ctf_field_type *enumeration, size_t index,
+               uint64_t *range_start, uint64_t *range_end)
+{
+       int ret;
+       const char *name;
+
+       ret = bt_ctf_field_type_enumeration_get_mapping_unsigned(enumeration,
+               index, &name, range_start, range_end);
+       return !ret ? name : NULL;
+}
+
+const char *_bt_python_ctf_field_type_structure_get_field_name(
+               struct bt_ctf_field_type *structure, size_t index)
+{
+       int ret;
+       const char *name;
+       struct bt_ctf_field_type *type;
+
+       ret = bt_ctf_field_type_structure_get_field(structure, &name, &type,
+               index);
+       if (ret) {
+               name = NULL;
+               goto end;
+       }
+
+       bt_ctf_field_type_put(type);
+end:
+       return name;
+}
+
+struct bt_ctf_field_type *_bt_python_ctf_field_type_structure_get_field_type(
+               struct bt_ctf_field_type *structure, size_t index)
+{
+       int ret;
+       const char *name;
+       struct bt_ctf_field_type *type;
+
+       ret = bt_ctf_field_type_structure_get_field(structure, &name, &type,
+               index);
+       return !ret ? type : NULL;
+}
+
+const char *_bt_python_ctf_field_type_variant_get_field_name(
+               struct bt_ctf_field_type *variant, size_t index)
+{
+       int ret;
+       const char *name;
+       struct bt_ctf_field_type *type;
+
+       ret = bt_ctf_field_type_variant_get_field(variant, &name, &type,
+               index);
+       if (ret) {
+               name = NULL;
+               goto end;
+       }
+
+       bt_ctf_field_type_put(type);
+end:
+       return name;
+}
+
+struct bt_ctf_field_type *_bt_python_ctf_field_type_variant_get_field_type(
+               struct bt_ctf_field_type *variant, size_t index)
+{
+       int ret;
+       const char *name;
+       struct bt_ctf_field_type *type;
+
+       ret = bt_ctf_field_type_variant_get_field(variant, &name, &type,
+               index);
+       return !ret ? type : NULL;
+}
This page took 0.025571 seconds and 4 git commands to generate.