Add Babeltrace 2 Python bindings
[babeltrace.git] / bindings / python / bt2 / native_btplugin.i
CommitLineData
81447b5b
PP
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%{
26#include <babeltrace/plugin/plugin.h>
27#include <assert.h>
28%}
29
30/* Types */
31struct bt_plugin;
32
33/* Status */
34enum bt_plugin_status {
35 BT_PLUGIN_STATUS_OK = 0,
36 BT_PLUGIN_STATUS_ERROR = -1,
37 BT_PLUGIN_STATUS_NOMEM = -4,
38};
39
40/* Functions */
41const char *bt_plugin_get_name(struct bt_plugin *plugin);
42const char *bt_plugin_get_author(struct bt_plugin *plugin);
43const char *bt_plugin_get_license(struct bt_plugin *plugin);
44const char *bt_plugin_get_description(struct bt_plugin *plugin);
45const char *bt_plugin_get_path(struct bt_plugin *plugin);
46enum bt_plugin_status bt_plugin_get_version(struct bt_plugin *plugin,
47 unsigned int *OUTPUT, unsigned int *OUTPUT, unsigned int *OUTPUT,
48 const char **BTOUTSTR);
49int bt_plugin_get_component_class_count(struct bt_plugin *plugin);
50struct bt_component_class *bt_plugin_get_component_class(
51 struct bt_plugin *plugin, size_t index);
52struct bt_component_class *bt_plugin_get_component_class_by_name_and_type(
53 struct bt_plugin *plugin, const char *name,
54 enum bt_component_class_type type);
55
56%{
57static PyObject *bt_py3_plugin_ptrs_list_from_bt_plugins(struct bt_plugin **plugins)
58{
59 PyObject *py_plugin_ptrs = NULL;
60 struct bt_plugin **plugin_at;
61
62 if (!plugins) {
63 goto error;
64 }
65
66 py_plugin_ptrs = PyList_New(0);
67 if (!py_plugin_ptrs) {
68 goto error;
69 }
70
71 plugin_at = plugins;
72
73 while (*plugin_at) {
74 struct bt_plugin *plugin = *plugin_at;
75 PyObject *py_plugin_ptr;
76 int ret;
77
78 py_plugin_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(plugin),
79 SWIGTYPE_p_bt_plugin, 0);
80 if (!py_plugin_ptr) {
81 goto error;
82 }
83
84 ret = PyList_Append(py_plugin_ptrs, py_plugin_ptr);
85 Py_DECREF(py_plugin_ptr);
86 if (ret < 0) {
87 goto error;
88 }
89
90 plugin_at++;
91 }
92
93 goto end;
94
95error:
96 Py_XDECREF(py_plugin_ptrs);
97 py_plugin_ptrs = Py_None;
98 Py_INCREF(py_plugin_ptrs);
99
100 if (plugins) {
101 /*
102 * Put existing plugin references since they are not
103 * moved to the caller.
104 */
105 plugin_at = plugins;
106
107 while (*plugin_at) {
108 bt_put(*plugin_at);
109 plugin_at++;
110 }
111 }
112
113end:
114 PyErr_Clear();
115 free(plugins);
116 return py_plugin_ptrs;
117}
118
119static PyObject *bt_py3_plugin_create_all_from_file(const char *path)
120{
121 return bt_py3_plugin_ptrs_list_from_bt_plugins(
122 bt_plugin_create_all_from_file(path));
123}
124
125static PyObject *bt_py3_plugin_create_all_from_dir(const char *path,
126 bool recurse)
127{
128 return bt_py3_plugin_ptrs_list_from_bt_plugins(
129 bt_plugin_create_all_from_dir(path, recurse));
130}
131%}
132
133PyObject *bt_py3_plugin_create_all_from_file(const char *path);
134PyObject *bt_py3_plugin_create_all_from_dir(const char *path,
135 bool recurse);
This page took 0.037955 seconds and 4 git commands to generate.