lib: bt_plugin_find*(): return status code; add "fail on load error" param
[babeltrace.git] / src / bindings / python / bt2 / bt2 / native_bt_plugin.i
1 /*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 /* Output argument typemap for plugin output (always appends) */
26 %typemap(in, numinputs=0)
27 (const bt_plugin **OUT)
28 (bt_plugin *temp_plugin = NULL) {
29 $1 = &temp_plugin;
30 }
31
32 %typemap(argout)
33 (const bt_plugin **OUT) {
34 if (*$1) {
35 /* SWIG_Python_AppendOutput() steals the created object */
36 $result = SWIG_Python_AppendOutput($result,
37 SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
38 SWIGTYPE_p_bt_plugin, 0));
39 } else {
40 /* SWIG_Python_AppendOutput() steals Py_None */
41 Py_INCREF(Py_None);
42 $result = SWIG_Python_AppendOutput($result, Py_None);
43 }
44 }
45
46 /* Output argument typemap for plugin set output (always appends) */
47 %typemap(in, numinputs=0)
48 (const bt_plugin_set **OUT)
49 (bt_plugin_set *temp_plugin_set = NULL) {
50 $1 = &temp_plugin_set;
51 }
52
53 %typemap(argout)
54 (const bt_plugin_set **OUT) {
55 if (*$1) {
56 /* SWIG_Python_AppendOutput() steals the created object */
57 $result = SWIG_Python_AppendOutput($result,
58 SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
59 SWIGTYPE_p_bt_plugin_set, 0));
60 } else {
61 /* SWIG_Python_AppendOutput() steals Py_None */
62 Py_INCREF(Py_None);
63 $result = SWIG_Python_AppendOutput($result, Py_None);
64 }
65 }
66
67 /* From plugin-const.h */
68
69 typedef enum bt_plugin_status {
70 BT_PLUGIN_STATUS_OK = 0,
71 BT_PLUGIN_STATUS_NOT_FOUND = 2,
72 BT_PLUGIN_STATUS_ERROR = -1,
73 BT_PLUGIN_STATUS_LOADING_ERROR = -2,
74 BT_PLUGIN_STATUS_NOMEM = -12,
75 } bt_plugin_status;
76
77 extern const char *bt_plugin_get_name(const bt_plugin *plugin);
78
79 extern const char *bt_plugin_get_author(const bt_plugin *plugin);
80
81 extern const char *bt_plugin_get_license(const bt_plugin *plugin);
82
83 extern const char *bt_plugin_get_description(const bt_plugin *plugin);
84
85 extern const char *bt_plugin_get_path(const bt_plugin *plugin);
86
87 extern uint64_t bt_plugin_get_source_component_class_count(
88 const bt_plugin *plugin);
89
90 extern uint64_t bt_plugin_get_filter_component_class_count(
91 const bt_plugin *plugin);
92
93 extern uint64_t bt_plugin_get_sink_component_class_count(
94 const bt_plugin *plugin);
95
96 extern const bt_component_class_source *
97 bt_plugin_borrow_source_component_class_by_index_const(
98 const bt_plugin *plugin, uint64_t index);
99
100 extern const bt_component_class_filter *
101 bt_plugin_borrow_filter_component_class_by_index_const(
102 const bt_plugin *plugin, uint64_t index);
103
104 extern const bt_component_class_sink *
105 bt_plugin_borrow_sink_component_class_by_index_const(
106 const bt_plugin *plugin, uint64_t index);
107
108 extern const bt_component_class_source *
109 bt_plugin_borrow_source_component_class_by_name_const(
110 const bt_plugin *plugin, const char *name);
111
112 extern const bt_component_class_filter *
113 bt_plugin_borrow_filter_component_class_by_name_const(
114 const bt_plugin *plugin, const char *name);
115
116 extern const bt_component_class_sink *
117 bt_plugin_borrow_sink_component_class_by_name_const(
118 const bt_plugin *plugin, const char *name);
119
120 extern void bt_plugin_get_ref(const bt_plugin *plugin);
121
122 extern void bt_plugin_put_ref(const bt_plugin *plugin);
123
124 /* From plugin-set-const.h */
125
126 extern uint64_t bt_plugin_set_get_plugin_count(
127 const bt_plugin_set *plugin_set);
128
129 extern const bt_plugin *bt_plugin_set_borrow_plugin_by_index_const(
130 const bt_plugin_set *plugin_set, uint64_t index);
131
132 extern void bt_plugin_set_get_ref(const bt_plugin_set *plugin_set);
133
134 extern void bt_plugin_set_put_ref(const bt_plugin_set *plugin_set);
135
136 /* Helpers */
137
138 bt_property_availability bt_plugin_get_version_wrapper(
139 const bt_plugin *plugin, unsigned int *OUT,
140 unsigned int *OUT, unsigned int *OUT, const char **OUT);
141
142 bt_plugin_status bt_plugin_find_wrapper(const char *plugin_name,
143 bt_bool fail_on_load_error, const bt_plugin **OUT);
144
145 bt_plugin_status bt_plugin_find_all_from_file_wrapper(
146 const char *path, bt_bool fail_on_load_error,
147 const bt_plugin_set **OUT);
148
149 bt_plugin_status bt_plugin_find_all_from_dir_wrapper(
150 const char *path, bt_bool recurse, bt_bool fail_on_load_error,
151 const bt_plugin_set **OUT);
152
153 %{
154
155 /*
156 * This *_wrapper() functions below ensure that when the API function
157 * fails, the output parameter is set to `NULL`. This is necessary
158 * because the epilogue of the `something **OUT` typemap will use that
159 * value to make a Python object. We can't rely on the initial value of
160 * `*OUT`; it could point to unreadable memory.
161 */
162
163 bt_property_availability bt_plugin_get_version_wrapper(
164 const bt_plugin *plugin, unsigned int *major,
165 unsigned int *minor, unsigned int *patch, const char **extra)
166 {
167 bt_property_availability ret;
168
169 ret = bt_plugin_get_version(plugin, major, minor, patch, extra);
170
171 if (ret == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) {
172 *extra = NULL;
173 }
174
175 return ret;
176 }
177
178 bt_plugin_status bt_plugin_find_wrapper(const char *plugin_name,
179 bt_bool fail_on_load_error, const bt_plugin **plugin)
180 {
181 bt_plugin_status status;
182
183 status = bt_plugin_find(plugin_name, fail_on_load_error,
184 plugin);
185 if (status != BT_PLUGIN_STATUS_OK) {
186 *plugin = NULL;
187 }
188
189 return status;
190 }
191
192 bt_plugin_status bt_plugin_find_all_from_file_wrapper(
193 const char *path, bt_bool fail_on_load_error,
194 const bt_plugin_set **plugin_set)
195 {
196 bt_plugin_status status;
197
198 status = bt_plugin_find_all_from_file(path, fail_on_load_error,
199 plugin_set);
200 if (status != BT_PLUGIN_STATUS_OK) {
201 *plugin_set = NULL;
202 }
203
204 return status;
205 }
206
207 bt_plugin_status bt_plugin_find_all_from_dir_wrapper(
208 const char *path, bt_bool recurse, bt_bool fail_on_load_error,
209 const bt_plugin_set **plugin_set)
210 {
211 bt_plugin_status status;
212
213 status = bt_plugin_find_all_from_dir(path, recurse, fail_on_load_error,
214 plugin_set);
215 if (status != BT_PLUGIN_STATUS_OK) {
216 *plugin_set = NULL;
217 }
218
219 return status;
220 }
221
222 %}
This page took 0.037603 seconds and 4 git commands to generate.