ctf: bt_ctf_notif_iter_get_next_notification(): require CC prio. map
[babeltrace.git] / include / babeltrace / plugin / plugin-internal.h
CommitLineData
33b34c43
PP
1#ifndef BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H
2#define BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H
fb2dcc52
JG
3
4/*
5 * BabelTrace - Plug-in Internal
6 *
7 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 *
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 */
29
30#include <babeltrace/babeltrace-internal.h>
33b34c43 31#include <babeltrace/plugin/plugin-dev.h>
b8a06801 32#include <babeltrace/object-internal.h>
33b34c43 33#include <stdbool.h>
55bb57e0 34#include <glib.h>
fb2dcc52 35
55bb57e0
PP
36enum bt_plugin_type {
37 BT_PLUGIN_TYPE_SO = 0,
38 BT_PLUGIN_TYPE_PYTHON = 1,
fb2dcc52
JG
39};
40
33b34c43
PP
41struct bt_plugin {
42 struct bt_object base;
55bb57e0 43 enum bt_plugin_type type;
33b34c43 44 bool frozen;
cba174d5 45
33b34c43
PP
46 /* Array of pointers to bt_component_class (owned by this) */
47 GPtrArray *comp_classes;
6ba0b073 48
55bb57e0
PP
49 /* Info (owned by this) */
50 struct {
51 GString *path;
52 GString *name;
53 GString *author;
54 GString *license;
55 GString *description;
56 struct {
57 unsigned int major;
58 unsigned int minor;
59 unsigned int patch;
60 GString *extra;
61 } version;
62 bool path_set;
63 bool name_set;
64 bool author_set;
65 bool license_set;
66 bool description_set;
67 bool version_set;
68 } info;
69
70 /* Value depends on the specific plugin type */
71 void *spec_data;
6fbd4105 72 void (*destroy_spec_data)(struct bt_plugin *);
33b34c43 73};
fb2dcc52 74
6fbd4105
PP
75static inline
76void bt_plugin_destroy(struct bt_object *obj)
77{
78 struct bt_plugin *plugin;
79
80 assert(obj);
81 plugin = container_of(obj, struct bt_plugin, base);
82
83 if (plugin->destroy_spec_data) {
84 plugin->destroy_spec_data(plugin);
85 }
86
87 if (plugin->comp_classes) {
88 g_ptr_array_free(plugin->comp_classes, TRUE);
89 }
90
91 if (plugin->info.name) {
92 g_string_free(plugin->info.name, TRUE);
93 }
94
95 if (plugin->info.path) {
96 g_string_free(plugin->info.path, TRUE);
97 }
98
99 if (plugin->info.description) {
100 g_string_free(plugin->info.description, TRUE);
101 }
102
103 if (plugin->info.author) {
104 g_string_free(plugin->info.author, TRUE);
105 }
106
107 if (plugin->info.license) {
108 g_string_free(plugin->info.license, TRUE);
109 }
110
111 if (plugin->info.version.extra) {
112 g_string_free(plugin->info.version.extra, TRUE);
113 }
114
115 g_free(plugin);
116}
117
118static inline
119struct bt_plugin *bt_plugin_create_empty(enum bt_plugin_type type)
120{
121 struct bt_plugin *plugin = NULL;
122
123 plugin = g_new0(struct bt_plugin, 1);
124 if (!plugin) {
125 goto error;
126 }
127
128 bt_object_init(plugin, bt_plugin_destroy);
129 plugin->type = type;
130
131 /* Create empty array of component classes */
132 plugin->comp_classes =
133 g_ptr_array_new_with_free_func((GDestroyNotify) bt_put);
134 if (!plugin->comp_classes) {
135 goto error;
136 }
137
138 /* Create empty info */
139 plugin->info.name = g_string_new(NULL);
140 if (!plugin->info.name) {
141 goto error;
142 }
143
144 plugin->info.path = g_string_new(NULL);
145 if (!plugin->info.path) {
146 goto error;
147 }
148
149 plugin->info.description = g_string_new(NULL);
150 if (!plugin->info.description) {
151 goto error;
152 }
153
154 plugin->info.author = g_string_new(NULL);
155 if (!plugin->info.author) {
156 goto error;
157 }
158
159 plugin->info.license = g_string_new(NULL);
160 if (!plugin->info.license) {
161 goto error;
162 }
163
164 plugin->info.version.extra = g_string_new(NULL);
165 if (!plugin->info.version.extra) {
166 goto error;
167 }
168
169 goto end;
170
171error:
172 BT_PUT(plugin);
173
174end:
175 return plugin;
176}
55bb57e0
PP
177
178static inline
179void bt_plugin_set_path(struct bt_plugin *plugin, const char *path)
180{
181 assert(plugin);
182 assert(path);
183 g_string_assign(plugin->info.path, path);
184 plugin->info.path_set = true;
185}
186
187static inline
188void bt_plugin_set_name(struct bt_plugin *plugin, const char *name)
189{
190 assert(plugin);
191 assert(name);
192 g_string_assign(plugin->info.name, name);
193 plugin->info.name_set = true;
194}
195
196static inline
197void bt_plugin_set_description(struct bt_plugin *plugin,
198 const char *description)
199{
200 assert(plugin);
201 assert(description);
202 g_string_assign(plugin->info.description, description);
203 plugin->info.description_set = true;
204}
205
206static inline
207void bt_plugin_set_author(struct bt_plugin *plugin, const char *author)
208{
209 assert(plugin);
210 assert(author);
211 g_string_assign(plugin->info.author, author);
212 plugin->info.author_set = true;
213}
214
215static inline
216void bt_plugin_set_license(struct bt_plugin *plugin, const char *license)
217{
218 assert(plugin);
219 assert(license);
220 g_string_assign(plugin->info.license, license);
221 plugin->info.license_set = true;
222}
223
224static inline
225void bt_plugin_set_version(struct bt_plugin *plugin, unsigned int major,
226 unsigned int minor, unsigned int patch, const char *extra)
227{
228 assert(plugin);
229 plugin->info.version.major = major;
230 plugin->info.version.minor = minor;
231 plugin->info.version.patch = patch;
232
233 if (extra) {
234 g_string_assign(plugin->info.version.extra, extra);
235 }
236
237 plugin->info.version_set = true;
238}
239
240static inline
241void bt_plugin_freeze(struct bt_plugin *plugin)
242{
243 assert(plugin);
244 plugin->frozen = true;
245}
246
33b34c43 247#endif /* BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H */
This page took 0.036539 seconds and 4 git commands to generate.