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