X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bindings%2Fpython%2Fpython-complements.c;h=0e3bbdf1a3e237859eb4c98998a1148a1f0ed2ee;hb=5df9e303fa9d81b3a6d989612c7a98039ec76fd1;hp=b6f1d5a88891a98e0081409b3f6d1bfaec956fbf;hpb=024e61817685a20caceb4e3ef3bdc019a7af6b6e;p=babeltrace.git diff --git a/bindings/python/python-complements.c b/bindings/python/python-complements.c index b6f1d5a8..0e3bbdf1 100644 --- a/bindings/python/python-complements.c +++ b/bindings/python/python-complements.c @@ -16,30 +16,26 @@ * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ #include "python-complements.h" -#include -#include - -/* 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include /* List-related functions ---------------------------------------------------- @@ -96,7 +92,7 @@ struct bt_ctf_event_decl *_bt_python_decl_one_from_list( /* decl_fields */ struct bt_ctf_field_decl **_by_python_field_decl_listcaller( struct bt_ctf_event_decl *event_decl, - enum bt_ctf_scope scope, + enum ctf_scope scope, unsigned int *len) { struct bt_ctf_field_decl **list; @@ -135,6 +131,68 @@ end: return array; } +struct bt_declaration *_bt_python_get_array_element_declaration( + struct bt_declaration *field) +{ + struct declaration_array *array_decl; + struct bt_declaration *ret = NULL; + + if (!field) { + goto end; + } + + array_decl = container_of(field, struct declaration_array, p); + ret = array_decl->elem; +end: + return ret; +} + +struct bt_declaration *_bt_python_get_sequence_element_declaration( + struct bt_declaration *field) +{ + struct declaration_sequence *sequence_decl; + struct bt_declaration *ret = NULL; + + if (!field) { + goto end; + } + + sequence_decl = container_of(field, struct declaration_sequence, p); + ret = sequence_decl->elem; +end: + return ret; +} + +const char *_bt_python_get_array_string(struct bt_definition *field) +{ + struct definition_array *array; + const char *ret = NULL; + + if (!field) { + goto end; + } + + array = container_of(field, struct definition_array, p); + ret = array->string->str; +end: + return ret; +} + +const char *_bt_python_get_sequence_string(struct bt_definition *field) +{ + struct definition_sequence *sequence; + const char *ret = NULL; + + if (!field) { + goto end; + } + + sequence = container_of(field, struct definition_sequence, p); + ret = sequence->string->str; +end: + return ret; +} + struct definition_sequence *_bt_python_get_sequence_from_def( struct bt_definition *field) { @@ -174,3 +232,192 @@ 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; +} + +const char *_bt_python_ctf_event_class_get_field_name( + struct bt_ctf_event_class *event_class, size_t index) +{ + int ret; + const char *name; + struct bt_ctf_field_type *type; + + ret = bt_ctf_event_class_get_field(event_class, &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_event_class_get_field_type( + struct bt_ctf_event_class *event_class, size_t index) +{ + int ret; + const char *name; + struct bt_ctf_field_type *type; + + ret = bt_ctf_event_class_get_field(event_class, &name, &type, + index); + return !ret ? type : NULL; +} + +int _bt_python_ctf_clock_get_uuid_index(struct bt_ctf_clock *clock, + size_t index, unsigned char *value) +{ + int ret = 0; + const unsigned char *uuid; + + if (index >= 16) { + ret = -1; + goto end; + } + + uuid = bt_ctf_clock_get_uuid(clock); + if (!uuid) { + ret = -1; + goto end; + } + + *value = uuid[index]; +end: + return ret; +} + +int _bt_python_ctf_clock_set_uuid_index(struct bt_ctf_clock *clock, + size_t index, unsigned char value) +{ + int ret = 0; + + if (index >= 16) { + ret = -1; + goto end; + } + + clock->uuid[index] = value; +end: + return ret; +} + +/* + * Python 3.5 changes the StopIteration exception clearing behaviour which + * erroneously marks swig clean-up function as having failed. This explicit + * allocation function is intended as a work-around so SWIG doesn't manage + * the lifetime of a "temporary" object by itself. + */ +struct bt_iter_pos *_bt_python_create_iter_pos(void) +{ + return g_new0(struct bt_iter_pos, 1); +} + +struct bt_ctf_iter *_bt_python_ctf_iter_create_intersect( + struct bt_context *ctx, + struct bt_iter_pos *inter_begin_pos, + struct bt_iter_pos *inter_end_pos) +{ + return bt_ctf_iter_create_intersect(ctx, &inter_begin_pos, + &inter_end_pos); +} + +int _bt_python_trace_collection_has_intersection(struct bt_context *ctx) +{ + int ret; + int64_t begin, end; + + ret = ctf_find_tc_stream_packet_intersection_union(ctx, &begin, &end); + + return ret == 0 ? 1 : 0; +}