Commit | Line | Data |
---|---|---|
a0bcd369 PP |
1 | /* |
2 | * Copyright 2019 Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | * of this software and associated documentation files (the "Software"), to deal | |
6 | * in the Software without restriction, including without limitation the rights | |
7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | * copies of the Software, and to permit persons to whom the Software is | |
9 | * furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
20 | * SOFTWARE. | |
21 | */ | |
22 | ||
91174480 | 23 | #define BT_COMP_LOG_SELF_COMP (details_comp->self_comp) |
e13e69fc | 24 | #define BT_LOG_OUTPUT_LEVEL (details_comp->log_level) |
b03487ab | 25 | #define BT_LOG_TAG "PLUGIN/SINK.TEXT.DETAILS" |
3fa1b6a3 | 26 | #include "logging/comp-logging.h" |
a0bcd369 PP |
27 | |
28 | #include <babeltrace2/babeltrace.h> | |
29 | ||
30 | #include "common/common.h" | |
31 | #include "common/assert.h" | |
32 | #include "details.h" | |
33 | #include "write.h" | |
baa5e3aa | 34 | #include "plugins/common/param-validation/param-validation.h" |
a0bcd369 PP |
35 | |
36 | #define LOG_WRONG_PARAM_TYPE(_name, _value, _exp_type) \ | |
37 | do { \ | |
91174480 | 38 | BT_COMP_LOGE("Wrong `%s` parameter type: type=%s, " \ |
a0bcd369 PP |
39 | "expected-type=%s", \ |
40 | (_name), bt_common_value_type_string( \ | |
41 | bt_value_get_type(_value)), \ | |
42 | bt_common_value_type_string(_exp_type)); \ | |
43 | } while (0) | |
44 | ||
baa5e3aa SM |
45 | #define IN_PORT_NAME "in" |
46 | #define COLOR_PARAM_NAME "color" | |
47 | #define WITH_METADATA_PARAM_NAME "with-metadata" | |
48 | #define WITH_DATA_PARAM_NAME "with-data" | |
49 | #define WITH_TIME_PARAM_NAME "with-time" | |
50 | #define WITH_TRACE_NAME_PARAM_NAME "with-trace-name" | |
51 | #define WITH_STREAM_CLASS_NAME_PARAM_NAME "with-stream-class-name" | |
52 | #define WITH_STREAM_NAME_PARAM_NAME "with-stream-name" | |
53 | #define WITH_UUID_PARAM_NAME "with-uuid" | |
54 | #define COMPACT_PARAM_NAME "compact" | |
a0bcd369 PP |
55 | |
56 | BT_HIDDEN | |
57 | void details_destroy_details_trace_class_meta( | |
58 | struct details_trace_class_meta *details_tc_meta) | |
59 | { | |
60 | if (!details_tc_meta) { | |
61 | goto end; | |
62 | } | |
63 | ||
64 | if (details_tc_meta->objects) { | |
65 | g_hash_table_destroy(details_tc_meta->objects); | |
66 | details_tc_meta->objects = NULL; | |
67 | } | |
68 | ||
69 | g_free(details_tc_meta); | |
70 | ||
71 | end: | |
72 | return; | |
73 | } | |
74 | ||
75 | BT_HIDDEN | |
76 | struct details_trace_class_meta *details_create_details_trace_class_meta(void) | |
77 | { | |
78 | struct details_trace_class_meta *details_tc_meta = | |
79 | g_new0(struct details_trace_class_meta, 1); | |
80 | ||
81 | if (!details_tc_meta) { | |
82 | goto end; | |
83 | } | |
84 | ||
85 | details_tc_meta->objects = g_hash_table_new( | |
86 | g_direct_hash, g_direct_equal); | |
87 | if (!details_tc_meta->objects) { | |
88 | details_destroy_details_trace_class_meta(details_tc_meta); | |
89 | details_tc_meta = NULL; | |
90 | goto end; | |
91 | } | |
92 | ||
93 | details_tc_meta->tc_destruction_listener_id = UINT64_C(-1); | |
94 | ||
95 | end: | |
96 | return details_tc_meta; | |
97 | } | |
98 | ||
99 | static | |
100 | void destroy_details_comp(struct details_comp *details_comp) | |
101 | { | |
102 | GHashTableIter iter; | |
103 | gpointer key, value; | |
104 | ||
105 | if (!details_comp) { | |
106 | goto end; | |
107 | } | |
108 | ||
109 | if (details_comp->meta) { | |
110 | /* | |
111 | * Remove trace class destruction listeners, because | |
112 | * otherwise, when they are called, `details_comp` | |
113 | * (their user data) won't exist anymore (we're | |
114 | * destroying it here). | |
115 | */ | |
116 | g_hash_table_iter_init(&iter, details_comp->meta); | |
117 | ||
118 | while (g_hash_table_iter_next(&iter, &key, &value)) { | |
119 | struct details_trace_class_meta *details_tc_meta = | |
120 | value; | |
121 | ||
122 | if (details_tc_meta->tc_destruction_listener_id != | |
123 | UINT64_C(-1)) { | |
0fb60f5d PP |
124 | if (bt_trace_class_remove_destruction_listener( |
125 | (const void *) key, | |
126 | details_tc_meta->tc_destruction_listener_id)) { | |
127 | bt_current_thread_clear_error(); | |
128 | } | |
a0bcd369 PP |
129 | } |
130 | } | |
131 | ||
132 | g_hash_table_destroy(details_comp->meta); | |
133 | details_comp->meta = NULL; | |
134 | } | |
135 | ||
136 | if (details_comp->traces) { | |
137 | /* | |
138 | * Remove trace destruction listeners, because | |
139 | * otherwise, when they are called, `details_comp` won't | |
140 | * exist anymore (we're destroying it here). | |
141 | */ | |
142 | g_hash_table_iter_init(&iter, details_comp->traces); | |
143 | ||
144 | while (g_hash_table_iter_next(&iter, &key, &value)) { | |
145 | struct details_trace *details_trace = value; | |
146 | ||
0fb60f5d PP |
147 | if (bt_trace_remove_destruction_listener( |
148 | (const void *) key, | |
149 | details_trace->trace_destruction_listener_id)) { | |
150 | bt_current_thread_clear_error(); | |
151 | } | |
a0bcd369 PP |
152 | } |
153 | ||
154 | g_hash_table_destroy(details_comp->traces); | |
155 | details_comp->traces = NULL; | |
156 | } | |
157 | ||
158 | if (details_comp->str) { | |
159 | g_string_free(details_comp->str, TRUE); | |
160 | details_comp->str = NULL; | |
161 | } | |
162 | ||
163 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET( | |
164 | details_comp->msg_iter); | |
165 | g_free(details_comp); | |
166 | ||
167 | end: | |
168 | return; | |
169 | } | |
170 | ||
171 | static | |
e13e69fc PP |
172 | struct details_comp *create_details_comp( |
173 | bt_self_component_sink *self_comp_sink) | |
a0bcd369 PP |
174 | { |
175 | struct details_comp *details_comp = g_new0(struct details_comp, 1); | |
e13e69fc PP |
176 | bt_self_component *self_comp = |
177 | bt_self_component_sink_as_self_component(self_comp_sink); | |
a0bcd369 PP |
178 | |
179 | if (!details_comp) { | |
180 | goto error; | |
181 | } | |
182 | ||
e13e69fc PP |
183 | details_comp->log_level = bt_component_get_logging_level( |
184 | bt_self_component_as_component(self_comp)); | |
91174480 | 185 | details_comp->self_comp = self_comp; |
a0bcd369 PP |
186 | details_comp->meta = g_hash_table_new_full(g_direct_hash, |
187 | g_direct_equal, NULL, | |
188 | (GDestroyNotify) details_destroy_details_trace_class_meta); | |
189 | if (!details_comp->meta) { | |
190 | goto error; | |
191 | } | |
192 | ||
193 | details_comp->traces = g_hash_table_new_full(g_direct_hash, | |
194 | g_direct_equal, NULL, g_free); | |
195 | if (!details_comp->traces) { | |
196 | goto error; | |
197 | } | |
198 | ||
199 | details_comp->str = g_string_new(NULL); | |
200 | if (!details_comp->str) { | |
201 | goto error; | |
202 | } | |
203 | ||
204 | goto end; | |
205 | ||
206 | error: | |
207 | destroy_details_comp(details_comp); | |
208 | details_comp = NULL; | |
209 | ||
210 | end: | |
211 | return details_comp; | |
212 | } | |
213 | ||
214 | BT_HIDDEN | |
215 | void details_finalize(bt_self_component_sink *comp) | |
216 | { | |
217 | struct details_comp *details_comp; | |
218 | ||
219 | BT_ASSERT(comp); | |
220 | details_comp = bt_self_component_get_data( | |
221 | bt_self_component_sink_as_self_component(comp)); | |
222 | BT_ASSERT(details_comp); | |
223 | destroy_details_comp(details_comp); | |
224 | } | |
225 | ||
226 | static | |
baa5e3aa | 227 | void configure_bool_opt(struct details_comp *details_comp, |
a0bcd369 PP |
228 | const bt_value *params, const char *param_name, |
229 | bool default_value, bool *opt_value) | |
230 | { | |
a0bcd369 PP |
231 | const bt_value *value; |
232 | ||
233 | *opt_value = default_value; | |
234 | value = bt_value_map_borrow_entry_value_const(params, param_name); | |
235 | if (value) { | |
a0bcd369 PP |
236 | *opt_value = (bool) bt_value_bool_get(value); |
237 | } | |
a0bcd369 PP |
238 | } |
239 | ||
baa5e3aa SM |
240 | static const char *color_choices[] = { "never", "auto", "always", NULL }; |
241 | ||
242 | static const struct bt_param_validation_map_value_entry_descr details_params[] = { | |
243 | { COLOR_PARAM_NAME, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { BT_VALUE_TYPE_STRING, .string = { | |
244 | .choices = color_choices, | |
245 | } } }, | |
246 | { WITH_METADATA_PARAM_NAME, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, | |
247 | { WITH_DATA_PARAM_NAME, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, | |
248 | { COMPACT_PARAM_NAME, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, | |
249 | { WITH_TIME_PARAM_NAME, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, | |
250 | { WITH_TRACE_NAME_PARAM_NAME, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, | |
251 | { WITH_STREAM_CLASS_NAME_PARAM_NAME, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, | |
252 | { WITH_STREAM_NAME_PARAM_NAME, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, | |
253 | { WITH_UUID_PARAM_NAME, BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } }, | |
254 | BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END | |
255 | }; | |
256 | ||
a0bcd369 | 257 | static |
baa5e3aa SM |
258 | bt_component_class_initialize_method_status configure_details_comp( |
259 | struct details_comp *details_comp, | |
a0bcd369 PP |
260 | const bt_value *params) |
261 | { | |
baa5e3aa | 262 | bt_component_class_initialize_method_status status; |
a0bcd369 PP |
263 | const bt_value *value; |
264 | const char *str; | |
baa5e3aa SM |
265 | enum bt_param_validation_status validation_status; |
266 | gchar *validate_error = NULL; | |
267 | ||
268 | validation_status = bt_param_validation_validate(params, | |
269 | details_params, &validate_error); | |
270 | if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) { | |
271 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; | |
272 | goto end; | |
273 | } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) { | |
274 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; | |
275 | BT_COMP_LOGE_APPEND_CAUSE(details_comp->self_comp, | |
276 | "%s", validate_error); | |
277 | goto end; | |
278 | } | |
a0bcd369 PP |
279 | |
280 | /* Colorize output? */ | |
281 | details_comp->cfg.with_color = bt_common_colors_supported(); | |
baa5e3aa | 282 | value = bt_value_map_borrow_entry_value_const(params, COLOR_PARAM_NAME); |
a0bcd369 | 283 | if (value) { |
a0bcd369 PP |
284 | str = bt_value_string_get(value); |
285 | ||
286 | if (strcmp(str, "never") == 0) { | |
287 | details_comp->cfg.with_color = false; | |
288 | } else if (strcmp(str, "auto") == 0) { | |
289 | details_comp->cfg.with_color = | |
290 | bt_common_colors_supported(); | |
a0bcd369 | 291 | } else { |
baa5e3aa SM |
292 | BT_ASSERT(strcmp(str, "always") == 0); |
293 | ||
294 | details_comp->cfg.with_color = true; | |
a0bcd369 PP |
295 | } |
296 | } | |
297 | ||
298 | /* With metadata objects? */ | |
baa5e3aa | 299 | configure_bool_opt(details_comp, params, WITH_METADATA_PARAM_NAME, |
a0bcd369 | 300 | true, &details_comp->cfg.with_meta); |
a0bcd369 | 301 | |
08ef09ae | 302 | /* With data objects? */ |
baa5e3aa | 303 | configure_bool_opt(details_comp, params, WITH_DATA_PARAM_NAME, |
08ef09ae | 304 | true, &details_comp->cfg.with_data); |
08ef09ae | 305 | |
a0bcd369 | 306 | /* Compact? */ |
baa5e3aa | 307 | configure_bool_opt(details_comp, params, COMPACT_PARAM_NAME, |
a0bcd369 | 308 | false, &details_comp->cfg.compact); |
a0bcd369 PP |
309 | |
310 | /* With time? */ | |
baa5e3aa | 311 | configure_bool_opt(details_comp, params, WITH_TIME_PARAM_NAME, |
a0bcd369 | 312 | true, &details_comp->cfg.with_time); |
a0bcd369 | 313 | |
a0bcd369 | 314 | /* With trace name? */ |
baa5e3aa SM |
315 | configure_bool_opt(details_comp, params, |
316 | WITH_TRACE_NAME_PARAM_NAME, | |
a0bcd369 | 317 | true, &details_comp->cfg.with_trace_name); |
a0bcd369 PP |
318 | |
319 | /* With stream class name? */ | |
baa5e3aa SM |
320 | configure_bool_opt(details_comp, params, |
321 | WITH_STREAM_CLASS_NAME_PARAM_NAME, | |
a0bcd369 | 322 | true, &details_comp->cfg.with_stream_class_name); |
a0bcd369 PP |
323 | |
324 | /* With stream name? */ | |
baa5e3aa SM |
325 | configure_bool_opt(details_comp, params, |
326 | WITH_STREAM_NAME_PARAM_NAME, | |
a0bcd369 | 327 | true, &details_comp->cfg.with_stream_name); |
a0bcd369 PP |
328 | |
329 | /* With UUID? */ | |
baa5e3aa SM |
330 | configure_bool_opt(details_comp, params, |
331 | WITH_UUID_PARAM_NAME, true, &details_comp->cfg.with_uuid); | |
a0bcd369 | 332 | |
baa5e3aa | 333 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; |
a0bcd369 PP |
334 | goto end; |
335 | ||
a0bcd369 | 336 | end: |
baa5e3aa SM |
337 | g_free(validate_error); |
338 | ||
339 | return status; | |
a0bcd369 PP |
340 | } |
341 | ||
342 | static | |
343 | void log_configuration(bt_self_component_sink *comp, | |
344 | struct details_comp *details_comp) | |
345 | { | |
91174480 | 346 | BT_COMP_LOGI("Configuration for `sink.text.details` component `%s`:", |
a0bcd369 PP |
347 | bt_component_get_name(bt_self_component_as_component( |
348 | bt_self_component_sink_as_self_component(comp)))); | |
91174480 PP |
349 | BT_COMP_LOGI(" Colorize output: %d", details_comp->cfg.with_color); |
350 | BT_COMP_LOGI(" Compact: %d", details_comp->cfg.compact); | |
351 | BT_COMP_LOGI(" With metadata: %d", details_comp->cfg.with_meta); | |
352 | BT_COMP_LOGI(" With time: %d", details_comp->cfg.with_time); | |
91174480 PP |
353 | BT_COMP_LOGI(" With trace name: %d", details_comp->cfg.with_trace_name); |
354 | BT_COMP_LOGI(" With stream class name: %d", | |
a0bcd369 | 355 | details_comp->cfg.with_stream_class_name); |
91174480 PP |
356 | BT_COMP_LOGI(" With stream name: %d", details_comp->cfg.with_stream_name); |
357 | BT_COMP_LOGI(" With UUID: %d", details_comp->cfg.with_uuid); | |
a0bcd369 PP |
358 | } |
359 | ||
360 | BT_HIDDEN | |
4175c1d5 | 361 | bt_component_class_initialize_method_status details_init( |
e3250e61 SM |
362 | bt_self_component_sink *comp, |
363 | bt_self_component_sink_configuration *config, | |
a0bcd369 PP |
364 | const bt_value *params, |
365 | __attribute__((unused)) void *init_method_data) | |
366 | { | |
4175c1d5 FD |
367 | bt_component_class_initialize_method_status status = |
368 | BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; | |
fb25b9e3 | 369 | bt_self_component_add_port_status add_port_status; |
a0bcd369 PP |
370 | struct details_comp *details_comp = NULL; |
371 | ||
fb25b9e3 | 372 | add_port_status = bt_self_component_sink_add_input_port(comp, |
baa5e3aa | 373 | IN_PORT_NAME, NULL, NULL); |
fb25b9e3 PP |
374 | switch (add_port_status) { |
375 | case BT_SELF_COMPONENT_ADD_PORT_STATUS_OK: | |
4175c1d5 | 376 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; |
fb25b9e3 PP |
377 | break; |
378 | case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR: | |
4175c1d5 | 379 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; |
fb25b9e3 PP |
380 | break; |
381 | case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR: | |
4175c1d5 | 382 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
fb25b9e3 PP |
383 | break; |
384 | default: | |
385 | abort(); | |
a0bcd369 PP |
386 | } |
387 | ||
e13e69fc | 388 | details_comp = create_details_comp(comp); |
a0bcd369 | 389 | if (!details_comp) { |
4175c1d5 | 390 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
a0bcd369 PP |
391 | goto error; |
392 | } | |
393 | ||
394 | if (configure_details_comp(details_comp, params)) { | |
91174480 | 395 | BT_COMP_LOGE_STR("Failed to configure component."); |
a0bcd369 PP |
396 | goto error; |
397 | } | |
398 | ||
399 | log_configuration(comp, details_comp); | |
400 | bt_self_component_set_data( | |
401 | bt_self_component_sink_as_self_component(comp), details_comp); | |
402 | goto end; | |
403 | ||
404 | error: | |
4175c1d5 FD |
405 | if (status == BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) { |
406 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; | |
a0bcd369 PP |
407 | } |
408 | ||
409 | destroy_details_comp(details_comp); | |
410 | ||
411 | end: | |
412 | return status; | |
413 | } | |
414 | ||
415 | BT_HIDDEN | |
fb25b9e3 PP |
416 | bt_component_class_sink_graph_is_configured_method_status |
417 | details_graph_is_configured(bt_self_component_sink *comp) | |
a0bcd369 | 418 | { |
ab8b2b1b SM |
419 | bt_component_class_sink_graph_is_configured_method_status status; |
420 | bt_self_component_port_input_message_iterator_create_from_sink_component_status | |
421 | msg_iter_status; | |
a0bcd369 PP |
422 | bt_self_component_port_input_message_iterator *iterator; |
423 | struct details_comp *details_comp; | |
424 | bt_self_component_port_input *in_port; | |
425 | ||
426 | details_comp = bt_self_component_get_data( | |
427 | bt_self_component_sink_as_self_component(comp)); | |
428 | BT_ASSERT(details_comp); | |
429 | in_port = bt_self_component_sink_borrow_input_port_by_name(comp, | |
baa5e3aa | 430 | IN_PORT_NAME); |
a0bcd369 PP |
431 | if (!bt_port_is_connected(bt_port_input_as_port_const( |
432 | bt_self_component_port_input_as_port_input(in_port)))) { | |
91174480 | 433 | BT_COMP_LOGE("Single input port is not connected: " |
baa5e3aa | 434 | "port-name=\"%s\"", IN_PORT_NAME); |
fb25b9e3 | 435 | status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_ERROR; |
a0bcd369 PP |
436 | goto end; |
437 | } | |
438 | ||
ab8b2b1b | 439 | msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component( |
692f1a01 | 440 | comp, bt_self_component_sink_borrow_input_port_by_name(comp, |
baa5e3aa | 441 | IN_PORT_NAME), &iterator); |
ab8b2b1b SM |
442 | if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) { |
443 | status = (int) msg_iter_status; | |
a0bcd369 PP |
444 | goto end; |
445 | } | |
446 | ||
447 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF( | |
448 | details_comp->msg_iter, iterator); | |
449 | ||
ab8b2b1b SM |
450 | status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK; |
451 | ||
a0bcd369 PP |
452 | end: |
453 | return status; | |
454 | } | |
455 | ||
456 | BT_HIDDEN | |
fb25b9e3 PP |
457 | bt_component_class_sink_consume_method_status |
458 | details_consume(bt_self_component_sink *comp) | |
a0bcd369 | 459 | { |
fb25b9e3 PP |
460 | bt_component_class_sink_consume_method_status ret = |
461 | BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; | |
a0bcd369 PP |
462 | bt_message_array_const msgs; |
463 | uint64_t count; | |
464 | struct details_comp *details_comp; | |
fb25b9e3 | 465 | bt_message_iterator_next_status next_status; |
a0bcd369 PP |
466 | uint64_t i; |
467 | ||
468 | details_comp = bt_self_component_get_data( | |
469 | bt_self_component_sink_as_self_component(comp)); | |
ec4a3354 PP |
470 | BT_ASSERT_DBG(details_comp); |
471 | BT_ASSERT_DBG(details_comp->msg_iter); | |
a0bcd369 PP |
472 | |
473 | /* Consume messages */ | |
fb25b9e3 | 474 | next_status = bt_self_component_port_input_message_iterator_next( |
a0bcd369 | 475 | details_comp->msg_iter, &msgs, &count); |
fb25b9e3 PP |
476 | switch (next_status) { |
477 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK: | |
478 | ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; | |
a0bcd369 PP |
479 | |
480 | for (i = 0; i < count; i++) { | |
481 | int print_ret = details_write_message(details_comp, | |
482 | msgs[i]); | |
483 | ||
484 | if (print_ret) { | |
485 | for (; i < count; i++) { | |
486 | /* Put all remaining messages */ | |
487 | bt_message_put_ref(msgs[i]); | |
488 | } | |
489 | ||
fb25b9e3 | 490 | ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; |
a0bcd369 PP |
491 | goto end; |
492 | } | |
493 | ||
494 | /* Print output buffer to standard output and flush */ | |
495 | if (details_comp->str->len > 0) { | |
496 | printf("%s", details_comp->str->str); | |
497 | fflush(stdout); | |
498 | details_comp->printed_something = true; | |
499 | } | |
500 | ||
501 | /* Put this message */ | |
502 | bt_message_put_ref(msgs[i]); | |
503 | } | |
504 | ||
505 | break; | |
fb25b9e3 PP |
506 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN: |
507 | ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN; | |
a0bcd369 | 508 | goto end; |
fb25b9e3 PP |
509 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_END: |
510 | ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END; | |
a0bcd369 | 511 | goto end; |
fb25b9e3 PP |
512 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR: |
513 | ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; | |
a0bcd369 | 514 | goto end; |
fb25b9e3 PP |
515 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR: |
516 | ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR; | |
a0bcd369 PP |
517 | goto end; |
518 | default: | |
519 | abort(); | |
520 | } | |
521 | ||
522 | end: | |
523 | return ret; | |
524 | } |