Babeltrace python binding
[babeltrace.git] / bindings / python / python-complements.c
CommitLineData
24a3136a
DS
1/*
2 * python-complements.c
3 *
4 * Babeltrace Python module complements, required for Python bindings
5 *
6 * Copyright 2012 EfficiOS Inc.
7 *
8 * Author: Danny Serres <danny.serres@efficios.com>
9 *
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:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 */
20
21#include "python-complements.h"
22
23/* FILE functions
24 ----------------------------------------------------
25*/
26
27FILE *_bt_file_open(char *file_path, char *mode)
28{
29 FILE *fp = stdout;
30 if (file_path != NULL)
31 fp = fopen(file_path, mode);
32 return fp;
33}
34
35void _bt_file_close(FILE *fp)
36{
37 if (fp != NULL)
38 fclose(fp);
39}
40
41
42/* List-related functions
43 ----------------------------------------------------
44*/
45
46/* ctf-field-list */
47struct definition **_bt_python_field_listcaller(
48 const struct bt_ctf_event *ctf_event,
49 const struct definition *scope)
50{
51 struct definition **list;
52 unsigned int count;
53 int ret;
54
55 ret = bt_ctf_get_field_list(ctf_event, scope,
56 (const struct definition * const **)&list, &count);
57
58 if (ret < 0) /* For python to know an error occured */
59 list = NULL;
60 else /* For python to know the end is reached */
61 list[count] = NULL;
62
63 return list;
64}
65
66struct definition *_bt_python_field_one_from_list(
67 struct definition **list, int index)
68{
69 return list[index];
70}
71
72/* event_decl_list */
73struct bt_ctf_event_decl **_bt_python_event_decl_listcaller(
74 int handle_id, struct bt_context *ctx)
75{
76 struct bt_ctf_event_decl **list;
77 unsigned int count;
78 int ret;
79
80 ret = bt_ctf_get_event_decl_list(handle_id, ctx,
81 (struct bt_ctf_event_decl * const **)&list, &count);
82
83 if (ret < 0) /* For python to know an error occured */
84 list = NULL;
85 else /* For python to know the end is reached */
86 list[count] = NULL;
87
88 return list;
89}
90
91struct bt_ctf_event_decl *_bt_python_decl_one_from_list(
92 struct bt_ctf_event_decl **list, int index)
93{
94 return list[index];
95}
96
97/* decl_fields */
98struct bt_ctf_field_decl **_by_python_field_decl_listcaller(
99 struct bt_ctf_event_decl *event_decl,
100 enum bt_ctf_scope scope)
101{
102 struct bt_ctf_field_decl **list;
103 unsigned int count;
104 int ret;
105
106 ret = bt_ctf_get_decl_fields(event_decl, scope,
107 (const struct bt_ctf_field_decl * const **)&list, &count);
108
109 if (ret < 0) /* For python to know an error occured */
110 list = NULL;
111 else /* For python to know the end is reached */
112 list[count] = NULL;
113
114 return list;
115}
116
117struct bt_ctf_field_decl *_bt_python_field_decl_one_from_list(
118 struct bt_ctf_field_decl **list, int index)
119{
120 return list[index];
121}
This page took 0.02733 seconds and 4 git commands to generate.