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