4 * Babeltrace Python module complements, required for Python bindings
6 * Copyright 2012 EfficiOS Inc.
8 * Author: Danny Serres <danny.serres@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
21 #include "python-complements.h"
22 #include <babeltrace/ctf-writer/event-types-internal.h>
23 #include <babeltrace/ctf-writer/event-fields-internal.h>
26 ----------------------------------------------------
29 FILE *_bt_file_open(char *file_path
, char *mode
)
32 if (file_path
!= NULL
)
33 fp
= fopen(file_path
, mode
);
37 void _bt_file_close(FILE *fp
)
44 /* List-related functions
45 ----------------------------------------------------
49 struct bt_definition
**_bt_python_field_listcaller(
50 const struct bt_ctf_event
*ctf_event
,
51 const struct bt_definition
*scope
,
54 struct bt_definition
**list
;
57 ret
= bt_ctf_get_field_list(ctf_event
, scope
,
58 (const struct bt_definition
* const **)&list
, len
);
60 if (ret
< 0) /* For python to know an error occured */
66 struct bt_definition
*_bt_python_field_one_from_list(
67 struct bt_definition
**list
, int index
)
73 struct bt_ctf_event_decl
**_bt_python_event_decl_listcaller(
75 struct bt_context
*ctx
,
78 struct bt_ctf_event_decl
**list
;
81 ret
= bt_ctf_get_event_decl_list(handle_id
, ctx
,
82 (struct bt_ctf_event_decl
* const **)&list
, len
);
84 if (ret
< 0) /* For python to know an error occured */
90 struct bt_ctf_event_decl
*_bt_python_decl_one_from_list(
91 struct bt_ctf_event_decl
**list
, int index
)
97 struct bt_ctf_field_decl
**_by_python_field_decl_listcaller(
98 struct bt_ctf_event_decl
*event_decl
,
99 enum bt_ctf_scope scope
,
102 struct bt_ctf_field_decl
**list
;
105 ret
= bt_ctf_get_decl_fields(event_decl
, scope
,
106 (const struct bt_ctf_field_decl
* const **)&list
, len
);
108 if (ret
< 0) /* For python to know an error occured */
114 struct bt_ctf_field_decl
*_bt_python_field_decl_one_from_list(
115 struct bt_ctf_field_decl
**list
, int index
)
120 struct definition_array
*_bt_python_get_array_from_def(
121 struct bt_definition
*field
)
123 const struct bt_declaration
*array_decl
;
124 struct definition_array
*array
= NULL
;
130 array_decl
= bt_ctf_get_decl_from_def(field
);
131 if (bt_ctf_field_type(array_decl
) == CTF_TYPE_ARRAY
) {
132 array
= container_of(field
, struct definition_array
, p
);
138 struct bt_declaration
*_bt_python_get_array_element_declaration(
139 struct bt_declaration
*field
)
141 struct declaration_array
*array_decl
;
142 struct bt_declaration
*ret
= NULL
;
148 array_decl
= container_of(field
, struct declaration_array
, p
);
149 ret
= array_decl
->elem
;
154 struct bt_declaration
*_bt_python_get_sequence_element_declaration(
155 struct bt_declaration
*field
)
157 struct declaration_sequence
*sequence_decl
;
158 struct bt_declaration
*ret
= NULL
;
164 sequence_decl
= container_of(field
, struct declaration_sequence
, p
);
165 ret
= sequence_decl
->elem
;
170 const char *_bt_python_get_array_string(struct bt_definition
*field
)
172 struct definition_array
*array
;
173 const char *ret
= NULL
;
179 array
= container_of(field
, struct definition_array
, p
);
180 ret
= array
->string
->str
;
185 const char *_bt_python_get_sequence_string(struct bt_definition
*field
)
187 struct definition_sequence
*sequence
;
188 const char *ret
= NULL
;
194 sequence
= container_of(field
, struct definition_sequence
, p
);
195 ret
= sequence
->string
->str
;
200 struct definition_sequence
*_bt_python_get_sequence_from_def(
201 struct bt_definition
*field
)
203 if (field
&& bt_ctf_field_type(
204 bt_ctf_get_decl_from_def(field
)) == CTF_TYPE_SEQUENCE
) {
205 return container_of(field
, struct definition_sequence
, p
);
211 int _bt_python_field_integer_get_signedness(const struct bt_ctf_field
*field
)
215 if (!field
|| field
->type
->declaration
->id
!= CTF_TYPE_INTEGER
) {
220 const struct bt_ctf_field_type_integer
*type
= container_of(field
->type
,
221 const struct bt_ctf_field_type_integer
, parent
);
222 ret
= type
->declaration
.signedness
;
227 enum ctf_type_id
_bt_python_get_field_type(const struct bt_ctf_field
*field
)
229 enum ctf_type_id type_id
= CTF_TYPE_UNKNOWN
;
235 type_id
= field
->type
->declaration
->id
;