Commit | Line | Data |
---|---|---|
fb2dcc52 | 1 | /* |
3310b217 | 2 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
fb2dcc52 JG |
3 | * |
4 | * Author: Jérémie Galarneau <jeremie.galarneau@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 THE | |
22 | * SOFTWARE. | |
23 | */ | |
24 | ||
a3aacb6f PP |
25 | #define BT_LOG_TAG "COMP-CLASS" |
26 | #include <babeltrace/lib-logging-internal.h> | |
27 | ||
3d9990ac | 28 | #include <babeltrace/compiler-internal.h> |
7b53201c PP |
29 | #include <babeltrace/graph/component-class.h> |
30 | #include <babeltrace/graph/component-class-const.h> | |
31 | #include <babeltrace/graph/component-class-source.h> | |
32 | #include <babeltrace/graph/component-class-source-const.h> | |
33 | #include <babeltrace/graph/component-class-filter.h> | |
34 | #include <babeltrace/graph/component-class-filter-const.h> | |
35 | #include <babeltrace/graph/component-class-sink.h> | |
36 | #include <babeltrace/graph/component-class-sink-const.h> | |
b2e0c907 | 37 | #include <babeltrace/graph/component-class-internal.h> |
8138bfe1 | 38 | #include <babeltrace/object.h> |
c55a9f58 | 39 | #include <babeltrace/types.h> |
8b45963b | 40 | #include <babeltrace/assert-internal.h> |
834e9996 | 41 | #include <babeltrace/assert-pre-internal.h> |
fb2dcc52 JG |
42 | #include <glib.h> |
43 | ||
834e9996 | 44 | #define BT_ASSERT_PRE_COMP_CLS_HOT(_cc) \ |
7b53201c | 45 | BT_ASSERT_PRE_HOT(((const struct bt_component_class *) (_cc)), \ |
834e9996 PP |
46 | "Component class", ": %!+C", (_cc)) |
47 | ||
fb2dcc52 | 48 | static |
834e9996 | 49 | void destroy_component_class(struct bt_object *obj) |
fb2dcc52 JG |
50 | { |
51 | struct bt_component_class *class; | |
33b34c43 | 52 | int i; |
fb2dcc52 | 53 | |
8b45963b | 54 | BT_ASSERT(obj); |
b8a06801 | 55 | class = container_of(obj, struct bt_component_class, base); |
33b34c43 | 56 | |
834e9996 | 57 | BT_LIB_LOGD("Destroying component class: %!+C", class); |
a3aacb6f | 58 | |
33b34c43 PP |
59 | /* Call destroy listeners in reverse registration order */ |
60 | for (i = class->destroy_listeners->len - 1; i >= 0; i--) { | |
d3e4dcd8 | 61 | struct bt_component_class_destroy_listener *listener = |
33b34c43 | 62 | &g_array_index(class->destroy_listeners, |
d3e4dcd8 | 63 | struct bt_component_class_destroy_listener, |
33b34c43 PP |
64 | i); |
65 | ||
a3aacb6f PP |
66 | BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p", |
67 | listener->func, listener->data); | |
33b34c43 PP |
68 | listener->func(class, listener->data); |
69 | } | |
70 | ||
fb2dcc52 JG |
71 | if (class->name) { |
72 | g_string_free(class->name, TRUE); | |
834e9996 | 73 | class->name = NULL; |
fb2dcc52 | 74 | } |
834e9996 | 75 | |
7c7c0433 JG |
76 | if (class->description) { |
77 | g_string_free(class->description, TRUE); | |
834e9996 | 78 | class->description = NULL; |
7c7c0433 | 79 | } |
834e9996 | 80 | |
5536d9a6 PP |
81 | if (class->help) { |
82 | g_string_free(class->help, TRUE); | |
834e9996 | 83 | class->help = NULL; |
5536d9a6 | 84 | } |
834e9996 | 85 | |
33b34c43 PP |
86 | if (class->destroy_listeners) { |
87 | g_array_free(class->destroy_listeners, TRUE); | |
834e9996 | 88 | class->destroy_listeners = NULL; |
33b34c43 | 89 | } |
b8a06801 | 90 | |
fb2dcc52 JG |
91 | g_free(class); |
92 | } | |
93 | ||
d3e4dcd8 PP |
94 | static |
95 | int bt_component_class_init(struct bt_component_class *class, | |
96 | enum bt_component_class_type type, const char *name) | |
fb2dcc52 | 97 | { |
d3e4dcd8 PP |
98 | int ret = 0; |
99 | ||
834e9996 | 100 | bt_object_init_shared(&class->base, destroy_component_class); |
d3e4dcd8 PP |
101 | class->type = type; |
102 | class->name = g_string_new(name); | |
103 | if (!class->name) { | |
a3aacb6f | 104 | BT_LOGE_STR("Failed to allocate a GString."); |
d3e4dcd8 PP |
105 | goto error; |
106 | } | |
107 | ||
108 | class->description = g_string_new(NULL); | |
109 | if (!class->description) { | |
a3aacb6f | 110 | BT_LOGE_STR("Failed to allocate a GString."); |
d3e4dcd8 PP |
111 | goto error; |
112 | } | |
113 | ||
5536d9a6 PP |
114 | class->help = g_string_new(NULL); |
115 | if (!class->help) { | |
a3aacb6f | 116 | BT_LOGE_STR("Failed to allocate a GString."); |
5536d9a6 PP |
117 | goto error; |
118 | } | |
119 | ||
d3e4dcd8 PP |
120 | class->destroy_listeners = g_array_new(FALSE, TRUE, |
121 | sizeof(struct bt_component_class_destroy_listener)); | |
122 | if (!class->destroy_listeners) { | |
a3aacb6f | 123 | BT_LOGE_STR("Failed to allocate a GArray."); |
d3e4dcd8 PP |
124 | goto error; |
125 | } | |
126 | ||
127 | goto end; | |
6ba0b073 | 128 | |
d3e4dcd8 | 129 | error: |
8138bfe1 | 130 | BT_OBJECT_PUT_REF_AND_RESET(class); |
d3e4dcd8 PP |
131 | ret = -1; |
132 | ||
133 | end: | |
134 | return ret; | |
135 | } | |
136 | ||
7b53201c | 137 | struct bt_component_class_source *bt_component_class_source_create( |
834e9996 | 138 | const char *name, |
7b53201c | 139 | bt_component_class_source_notification_iterator_next_method method) |
d3e4dcd8 PP |
140 | { |
141 | struct bt_component_class_source *source_class = NULL; | |
142 | int ret; | |
143 | ||
834e9996 PP |
144 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
145 | BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method"); | |
a3aacb6f PP |
146 | BT_LOGD("Creating source component class: " |
147 | "name=\"%s\", notif-iter-next-method-addr=%p", | |
fe7265b5 | 148 | name, method); |
d3e4dcd8 PP |
149 | source_class = g_new0(struct bt_component_class_source, 1); |
150 | if (!source_class) { | |
a3aacb6f | 151 | BT_LOGE_STR("Failed to allocate one source component class."); |
fb2dcc52 JG |
152 | goto end; |
153 | } | |
154 | ||
a3aacb6f | 155 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
156 | ret = bt_component_class_init(&source_class->parent, |
157 | BT_COMPONENT_CLASS_TYPE_SOURCE, name); | |
158 | if (ret) { | |
159 | /* | |
160 | * If bt_component_class_init() fails, the component | |
161 | * class is put, therefore its memory is already | |
162 | * freed. | |
163 | */ | |
164 | source_class = NULL; | |
165 | goto end; | |
166 | } | |
167 | ||
834e9996 PP |
168 | source_class->methods.notif_iter_next = method; |
169 | BT_LIB_LOGD("Created source component class: %!+C", source_class); | |
d3e4dcd8 PP |
170 | |
171 | end: | |
834e9996 | 172 | return (void *) source_class; |
d3e4dcd8 PP |
173 | } |
174 | ||
7b53201c PP |
175 | struct bt_component_class_filter *bt_component_class_filter_create( |
176 | const char *name, | |
177 | bt_component_class_filter_notification_iterator_next_method method) | |
d3e4dcd8 PP |
178 | { |
179 | struct bt_component_class_filter *filter_class = NULL; | |
180 | int ret; | |
181 | ||
834e9996 PP |
182 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
183 | BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method"); | |
a3aacb6f PP |
184 | BT_LOGD("Creating filter component class: " |
185 | "name=\"%s\", notif-iter-next-method-addr=%p", | |
fe7265b5 | 186 | name, method); |
d3e4dcd8 PP |
187 | filter_class = g_new0(struct bt_component_class_filter, 1); |
188 | if (!filter_class) { | |
a3aacb6f | 189 | BT_LOGE_STR("Failed to allocate one filter component class."); |
d3e4dcd8 | 190 | goto end; |
6ba0b073 PP |
191 | } |
192 | ||
a3aacb6f | 193 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
194 | ret = bt_component_class_init(&filter_class->parent, |
195 | BT_COMPONENT_CLASS_TYPE_FILTER, name); | |
196 | if (ret) { | |
197 | /* | |
198 | * If bt_component_class_init() fails, the component | |
199 | * class is put, therefore its memory is already | |
200 | * freed. | |
201 | */ | |
202 | filter_class = NULL; | |
33b34c43 PP |
203 | goto end; |
204 | } | |
d3e4dcd8 | 205 | |
834e9996 PP |
206 | filter_class->methods.notif_iter_next = method; |
207 | BT_LIB_LOGD("Created filter component class: %!+C", filter_class); | |
d3e4dcd8 | 208 | |
fb2dcc52 | 209 | end: |
834e9996 | 210 | return (void *) filter_class; |
d3e4dcd8 PP |
211 | } |
212 | ||
7b53201c PP |
213 | struct bt_component_class_sink *bt_component_class_sink_create( |
214 | const char *name, bt_component_class_sink_consume_method method) | |
d3e4dcd8 PP |
215 | { |
216 | struct bt_component_class_sink *sink_class = NULL; | |
217 | int ret; | |
218 | ||
834e9996 PP |
219 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
220 | BT_ASSERT_PRE_NON_NULL(method, "Consume next method"); | |
a3aacb6f PP |
221 | BT_LOGD("Creating sink component class: " |
222 | "name=\"%s\", consume-method-addr=%p", | |
fe7265b5 | 223 | name, method); |
d3e4dcd8 PP |
224 | sink_class = g_new0(struct bt_component_class_sink, 1); |
225 | if (!sink_class) { | |
a3aacb6f | 226 | BT_LOGE_STR("Failed to allocate one sink component class."); |
d3e4dcd8 PP |
227 | goto end; |
228 | } | |
229 | ||
a3aacb6f | 230 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
231 | ret = bt_component_class_init(&sink_class->parent, |
232 | BT_COMPONENT_CLASS_TYPE_SINK, name); | |
233 | if (ret) { | |
234 | /* | |
235 | * If bt_component_class_init() fails, the component | |
236 | * class is put, therefore its memory is already | |
237 | * freed. | |
238 | */ | |
239 | sink_class = NULL; | |
240 | goto end; | |
241 | } | |
242 | ||
fe7265b5 | 243 | sink_class->methods.consume = method; |
834e9996 | 244 | BT_LIB_LOGD("Created sink component class: %!+C", sink_class); |
d3e4dcd8 PP |
245 | |
246 | end: | |
834e9996 | 247 | return (void *) sink_class; |
d3e4dcd8 PP |
248 | } |
249 | ||
7b53201c PP |
250 | int bt_component_class_source_set_init_method( |
251 | struct bt_component_class_source *comp_cls, | |
252 | bt_component_class_source_init_method method) | |
d3e4dcd8 | 253 | { |
834e9996 PP |
254 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
255 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
256 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
257 | comp_cls->methods.init = method; | |
258 | BT_LIB_LOGV("Set source component class's initialization method: " | |
259 | "%!+C", comp_cls); | |
260 | return 0; | |
d3e4dcd8 PP |
261 | } |
262 | ||
7b53201c PP |
263 | int bt_component_class_filter_set_init_method( |
264 | struct bt_component_class_filter *comp_cls, | |
265 | bt_component_class_filter_init_method method) | |
efa96d5d | 266 | { |
834e9996 PP |
267 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
268 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
269 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
270 | comp_cls->methods.init = method; | |
271 | BT_LIB_LOGV("Set filter component class's initialization method: " | |
272 | "%!+C", comp_cls); | |
273 | return 0; | |
efa96d5d PP |
274 | } |
275 | ||
7b53201c PP |
276 | int bt_component_class_sink_set_init_method( |
277 | struct bt_component_class_sink *comp_cls, | |
278 | bt_component_class_sink_init_method method) | |
2d41b99e | 279 | { |
834e9996 PP |
280 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
281 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
282 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
283 | comp_cls->methods.init = method; | |
284 | BT_LIB_LOGV("Set sink component class's initialization method: " | |
285 | "%!+C", comp_cls); | |
286 | return 0; | |
72b913fb PP |
287 | } |
288 | ||
7b53201c PP |
289 | int bt_component_class_source_set_finalize_method( |
290 | struct bt_component_class_source *comp_cls, | |
291 | bt_component_class_source_finalize_method method) | |
0d8b4d8e | 292 | { |
834e9996 PP |
293 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
294 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
295 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
296 | comp_cls->methods.finalize = method; | |
297 | BT_LIB_LOGV("Set source component class's finalization method: " | |
298 | "%!+C", comp_cls); | |
299 | return 0; | |
0d8b4d8e PP |
300 | } |
301 | ||
7b53201c PP |
302 | int bt_component_class_filter_set_finalize_method( |
303 | struct bt_component_class_filter *comp_cls, | |
304 | bt_component_class_filter_finalize_method method) | |
72b913fb | 305 | { |
834e9996 PP |
306 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
307 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
308 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
309 | comp_cls->methods.finalize = method; | |
310 | BT_LIB_LOGV("Set filter component class's finalization method: " | |
311 | "%!+C", comp_cls); | |
312 | return 0; | |
2d41b99e JG |
313 | } |
314 | ||
7b53201c PP |
315 | int bt_component_class_sink_set_finalize_method( |
316 | struct bt_component_class_sink *comp_cls, | |
317 | bt_component_class_sink_finalize_method method) | |
d3e4dcd8 | 318 | { |
834e9996 PP |
319 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
320 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
321 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
322 | comp_cls->methods.finalize = method; | |
323 | BT_LIB_LOGV("Set sink component class's finalization method: " | |
324 | "%!+C", comp_cls); | |
325 | return 0; | |
d3e4dcd8 PP |
326 | } |
327 | ||
7b53201c PP |
328 | int bt_component_class_source_set_query_method( |
329 | struct bt_component_class_source *comp_cls, | |
330 | bt_component_class_source_query_method method) | |
d3eb6e8f | 331 | { |
834e9996 PP |
332 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
333 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
334 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
335 | comp_cls->methods.query = method; | |
336 | BT_LIB_LOGV("Set source component class's query method: " | |
337 | "%!+C", comp_cls); | |
338 | return 0; | |
d3eb6e8f PP |
339 | } |
340 | ||
7b53201c PP |
341 | int bt_component_class_filter_set_query_method( |
342 | struct bt_component_class_filter *comp_cls, | |
343 | bt_component_class_filter_query_method method) | |
d3eb6e8f | 344 | { |
834e9996 PP |
345 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
346 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
347 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
348 | comp_cls->methods.query = method; | |
349 | BT_LIB_LOGV("Set filter component class's query method: " | |
350 | "%!+C", comp_cls); | |
351 | return 0; | |
352 | } | |
a3aacb6f | 353 | |
7b53201c PP |
354 | int bt_component_class_sink_set_query_method( |
355 | struct bt_component_class_sink *comp_cls, | |
356 | bt_component_class_sink_query_method method) | |
834e9996 | 357 | { |
834e9996 PP |
358 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
359 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
360 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
361 | comp_cls->methods.query = method; | |
362 | BT_LIB_LOGV("Set sink component class's query method: " | |
363 | "%!+C", comp_cls); | |
364 | return 0; | |
365 | } | |
d3eb6e8f | 366 | |
7b53201c PP |
367 | int bt_component_class_filter_set_accept_input_port_connection_method( |
368 | struct bt_component_class_filter *comp_cls, | |
369 | bt_component_class_filter_accept_input_port_connection_method method) | |
834e9996 | 370 | { |
834e9996 PP |
371 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
372 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
373 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
374 | comp_cls->methods.accept_input_port_connection = method; | |
375 | BT_LIB_LOGV("Set filter component class's \"accept input port connection\" method" | |
376 | ": %!+C", comp_cls); | |
377 | return 0; | |
378 | } | |
d3eb6e8f | 379 | |
7b53201c PP |
380 | int bt_component_class_sink_set_accept_input_port_connection_method( |
381 | struct bt_component_class_sink *comp_cls, | |
382 | bt_component_class_sink_accept_input_port_connection_method method) | |
834e9996 | 383 | { |
834e9996 PP |
384 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
385 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
386 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
387 | comp_cls->methods.accept_input_port_connection = method; | |
388 | BT_LIB_LOGV("Set sink component class's \"accept input port connection\" method" | |
389 | ": %!+C", comp_cls); | |
390 | return 0; | |
d3eb6e8f PP |
391 | } |
392 | ||
7b53201c PP |
393 | int bt_component_class_source_set_accept_output_port_connection_method( |
394 | struct bt_component_class_source *comp_cls, | |
395 | bt_component_class_source_accept_output_port_connection_method method) | |
d3eb6e8f | 396 | { |
834e9996 PP |
397 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
398 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
399 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
400 | comp_cls->methods.accept_output_port_connection = method; | |
401 | BT_LIB_LOGV("Set source component class's \"accept output port connection\" method" | |
402 | ": %!+C", comp_cls); | |
403 | return 0; | |
404 | } | |
d3eb6e8f | 405 | |
7b53201c PP |
406 | int bt_component_class_filter_set_accept_output_port_connection_method( |
407 | struct bt_component_class_filter *comp_cls, | |
408 | bt_component_class_filter_accept_output_port_connection_method method) | |
834e9996 | 409 | { |
834e9996 PP |
410 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
411 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
412 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
413 | comp_cls->methods.accept_output_port_connection = method; | |
414 | BT_LIB_LOGV("Set filter component class's \"accept output port connection\" method" | |
415 | ": %!+C", comp_cls); | |
416 | return 0; | |
417 | } | |
a3aacb6f | 418 | |
7b53201c PP |
419 | int bt_component_class_filter_set_input_port_connected_method( |
420 | struct bt_component_class_filter *comp_cls, | |
421 | bt_component_class_filter_input_port_connected_method method) | |
834e9996 | 422 | { |
834e9996 PP |
423 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
424 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
425 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
426 | comp_cls->methods.input_port_connected = method; | |
427 | BT_LIB_LOGV("Set filter component class's \"input port connected\" method" | |
428 | ": %!+C", comp_cls); | |
429 | return 0; | |
430 | } | |
a3aacb6f | 431 | |
7b53201c PP |
432 | int bt_component_class_sink_set_input_port_connected_method( |
433 | struct bt_component_class_sink *comp_cls, | |
434 | bt_component_class_sink_input_port_connected_method method) | |
834e9996 | 435 | { |
834e9996 PP |
436 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
437 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
438 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
439 | comp_cls->methods.input_port_connected = method; | |
440 | BT_LIB_LOGV("Set sink component class's \"input port connected\" method" | |
441 | ": %!+C", comp_cls); | |
442 | return 0; | |
443 | } | |
a3aacb6f | 444 | |
7b53201c PP |
445 | int bt_component_class_source_set_output_port_connected_method( |
446 | struct bt_component_class_source *comp_cls, | |
447 | bt_component_class_source_output_port_connected_method method) | |
834e9996 | 448 | { |
834e9996 PP |
449 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
450 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
451 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
452 | comp_cls->methods.output_port_connected = method; | |
453 | BT_LIB_LOGV("Set source component class's \"output port connected\" method" | |
454 | ": %!+C", comp_cls); | |
455 | return 0; | |
456 | } | |
d3eb6e8f | 457 | |
7b53201c PP |
458 | int bt_component_class_filter_set_output_port_connected_method( |
459 | struct bt_component_class_filter *comp_cls, | |
460 | bt_component_class_filter_output_port_connected_method method) | |
834e9996 | 461 | { |
834e9996 PP |
462 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
463 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
464 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
465 | comp_cls->methods.output_port_connected = method; | |
466 | BT_LIB_LOGV("Set filter component class's \"output port connected\" method" | |
467 | ": %!+C", comp_cls); | |
468 | return 0; | |
469 | } | |
d3eb6e8f | 470 | |
7b53201c PP |
471 | int bt_component_class_filter_set_input_port_disconnected_method( |
472 | struct bt_component_class_filter *comp_cls, | |
473 | bt_component_class_filter_input_port_disconnected_method method) | |
834e9996 | 474 | { |
834e9996 PP |
475 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
476 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
477 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
478 | comp_cls->methods.input_port_disconnected = method; | |
479 | BT_LIB_LOGV("Set filter component class's \"input port disconnected\" method" | |
480 | ": %!+C", comp_cls); | |
481 | return 0; | |
d3eb6e8f PP |
482 | } |
483 | ||
7b53201c PP |
484 | int bt_component_class_sink_set_input_port_disconnected_method( |
485 | struct bt_component_class_sink *comp_cls, | |
486 | bt_component_class_sink_input_port_disconnected_method method) | |
d3eb6e8f | 487 | { |
834e9996 PP |
488 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
489 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
490 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
491 | comp_cls->methods.input_port_disconnected = method; | |
492 | BT_LIB_LOGV("Set sink component class's \"input port disconnected\" method" | |
493 | ": %!+C", comp_cls); | |
494 | return 0; | |
495 | } | |
d3eb6e8f | 496 | |
7b53201c PP |
497 | int bt_component_class_source_set_output_port_disconnected_method( |
498 | struct bt_component_class_source *comp_cls, | |
499 | bt_component_class_source_output_port_disconnected_method method) | |
834e9996 | 500 | { |
834e9996 PP |
501 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
502 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
503 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
504 | comp_cls->methods.output_port_disconnected = method; | |
505 | BT_LIB_LOGV("Set source component class's \"output port disconnected\" method" | |
506 | ": %!+C", comp_cls); | |
507 | return 0; | |
508 | } | |
a3aacb6f | 509 | |
7b53201c PP |
510 | int bt_component_class_filter_set_output_port_disconnected_method( |
511 | struct bt_component_class_filter *comp_cls, | |
512 | bt_component_class_filter_output_port_disconnected_method method) | |
834e9996 | 513 | { |
834e9996 PP |
514 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
515 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
516 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
517 | comp_cls->methods.output_port_disconnected = method; | |
518 | BT_LIB_LOGV("Set filter component class's \"output port disconnected\" method" | |
519 | ": %!+C", comp_cls); | |
520 | return 0; | |
521 | } | |
a3aacb6f | 522 | |
7b53201c PP |
523 | int bt_component_class_source_set_notification_iterator_init_method( |
524 | struct bt_component_class_source *comp_cls, | |
525 | bt_component_class_source_notification_iterator_init_method method) | |
834e9996 | 526 | { |
834e9996 PP |
527 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
528 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
529 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
530 | comp_cls->methods.notif_iter_init = method; | |
531 | BT_LIB_LOGV("Set source component class's notification iterator initialization method" | |
532 | ": %!+C", comp_cls); | |
533 | return 0; | |
534 | } | |
a3aacb6f | 535 | |
7b53201c PP |
536 | int bt_component_class_filter_set_notification_iterator_init_method( |
537 | struct bt_component_class_filter *comp_cls, | |
538 | bt_component_class_filter_notification_iterator_init_method method) | |
834e9996 | 539 | { |
834e9996 PP |
540 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
541 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
542 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
543 | comp_cls->methods.notif_iter_init = method; | |
544 | BT_LIB_LOGV("Set filter component class's notification iterator initialization method" | |
545 | ": %!+C", comp_cls); | |
546 | return 0; | |
547 | } | |
d3eb6e8f | 548 | |
7b53201c PP |
549 | int bt_component_class_source_set_notification_iterator_finalize_method( |
550 | struct bt_component_class_source *comp_cls, | |
551 | bt_component_class_source_notification_iterator_finalize_method method) | |
834e9996 | 552 | { |
834e9996 PP |
553 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
554 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
555 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
556 | comp_cls->methods.notif_iter_finalize = method; | |
557 | BT_LIB_LOGV("Set source component class's notification iterator finalization method" | |
558 | ": %!+C", comp_cls); | |
559 | return 0; | |
560 | } | |
d3eb6e8f | 561 | |
7b53201c PP |
562 | int bt_component_class_filter_set_notification_iterator_finalize_method( |
563 | struct bt_component_class_filter *comp_cls, | |
564 | bt_component_class_filter_notification_iterator_finalize_method method) | |
834e9996 | 565 | { |
834e9996 PP |
566 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
567 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
568 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
569 | comp_cls->methods.notif_iter_finalize = method; | |
570 | BT_LIB_LOGV("Set filter component class's notification iterator finalization method" | |
571 | ": %!+C", comp_cls); | |
572 | return 0; | |
d3eb6e8f PP |
573 | } |
574 | ||
7b53201c PP |
575 | int bt_component_class_set_description( |
576 | struct bt_component_class *comp_cls, | |
d3e4dcd8 PP |
577 | const char *description) |
578 | { | |
834e9996 PP |
579 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
580 | BT_ASSERT_PRE_NON_NULL(description, "Description"); | |
581 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
582 | g_string_assign(comp_cls->description, description); | |
583 | BT_LIB_LOGV("Set component class's description: " | |
a3aacb6f | 584 | "addr=%p, name=\"%s\", type=%s", |
834e9996 PP |
585 | comp_cls, |
586 | bt_component_class_get_name(comp_cls), | |
587 | bt_component_class_type_string(comp_cls->type)); | |
588 | return 0; | |
fb2dcc52 | 589 | } |
38b48196 | 590 | |
7b53201c PP |
591 | int bt_component_class_set_help( |
592 | struct bt_component_class *comp_cls, | |
5536d9a6 PP |
593 | const char *help) |
594 | { | |
834e9996 PP |
595 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
596 | BT_ASSERT_PRE_NON_NULL(help, "Help"); | |
597 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
598 | g_string_assign(comp_cls->help, help); | |
599 | BT_LIB_LOGV("Set component class's help text: %!+C", comp_cls); | |
600 | return 0; | |
5536d9a6 PP |
601 | } |
602 | ||
7b53201c | 603 | const char *bt_component_class_get_name(const struct bt_component_class *comp_cls) |
38b48196 | 604 | { |
834e9996 PP |
605 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
606 | return comp_cls->name->str; | |
38b48196 JG |
607 | } |
608 | ||
d3e4dcd8 | 609 | enum bt_component_class_type bt_component_class_get_type( |
7b53201c | 610 | const struct bt_component_class *comp_cls) |
38b48196 | 611 | { |
834e9996 PP |
612 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
613 | return comp_cls->type; | |
38b48196 JG |
614 | } |
615 | ||
33b34c43 | 616 | const char *bt_component_class_get_description( |
7b53201c | 617 | const struct bt_component_class *comp_cls) |
38b48196 | 618 | { |
834e9996 PP |
619 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
620 | return comp_cls->description && | |
621 | comp_cls->description->str[0] != '\0' ? | |
622 | comp_cls->description->str : NULL; | |
38b48196 | 623 | } |
7c7c0433 | 624 | |
5536d9a6 | 625 | const char *bt_component_class_get_help( |
7b53201c | 626 | const struct bt_component_class *comp_cls) |
5536d9a6 | 627 | { |
834e9996 PP |
628 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
629 | return comp_cls->help && | |
630 | comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL; | |
5536d9a6 PP |
631 | } |
632 | ||
33b34c43 | 633 | BT_HIDDEN |
834e9996 PP |
634 | void bt_component_class_add_destroy_listener( |
635 | struct bt_component_class *comp_cls, | |
33b34c43 | 636 | bt_component_class_destroy_listener_func func, void *data) |
7c7c0433 | 637 | { |
d3e4dcd8 | 638 | struct bt_component_class_destroy_listener listener; |
33b34c43 | 639 | |
834e9996 | 640 | BT_ASSERT(comp_cls); |
8b45963b | 641 | BT_ASSERT(func); |
33b34c43 PP |
642 | listener.func = func; |
643 | listener.data = data; | |
834e9996 PP |
644 | g_array_append_val(comp_cls->destroy_listeners, listener); |
645 | BT_LIB_LOGV("Added destroy listener to component class: " | |
646 | "%![cc-]+C, listener-func-addr=%p", comp_cls, func); | |
7c7c0433 | 647 | } |
d3e4dcd8 | 648 | |
834e9996 | 649 | BT_HIDDEN |
7b53201c | 650 | void _bt_component_class_freeze(const struct bt_component_class *comp_cls) |
1e4d8103 | 651 | { |
834e9996 PP |
652 | BT_ASSERT(comp_cls); |
653 | BT_LIB_LOGD("Freezing component class: %!+C", comp_cls); | |
7b53201c | 654 | ((struct bt_component_class *) comp_cls)->frozen = true; |
1e4d8103 | 655 | } |