2 * SPDX-License-Identifier: MIT
4 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
5 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
8 #define BT_COMP_LOG_SELF_COMP (dmesg_comp->self_comp)
9 #define BT_LOG_OUTPUT_LEVEL (dmesg_comp->log_level)
10 #define BT_LOG_TAG "PLUGIN/SRC.TEXT.DMESG"
11 #include "logging/comp-logging.h"
19 #include "common/common.h"
20 #include "common/assert.h"
21 #include <babeltrace2/babeltrace.h>
22 #include "compat/utc.h"
23 #include "compat/stdio.h"
25 #include "plugins/common/param-validation/param-validation.h"
27 #define NSEC_PER_USEC 1000UL
28 #define NSEC_PER_MSEC 1000000UL
29 #define NSEC_PER_SEC 1000000000ULL
30 #define USEC_PER_SEC 1000000UL
32 struct dmesg_component
;
34 struct dmesg_msg_iter
{
35 struct dmesg_component
*dmesg_comp
;
38 bt_self_message_iterator
*self_msg_iter
;
43 bt_message
*tmp_event_msg
;
44 uint64_t last_clock_value
;
47 STATE_EMIT_STREAM_BEGINNING
,
49 STATE_EMIT_STREAM_END
,
54 struct dmesg_component
{
55 bt_logging_level log_level
;
59 bt_bool read_from_stdin
;
63 bt_self_component_source
*self_comp_src
;
64 bt_self_component
*self_comp
;
65 bt_trace_class
*trace_class
;
66 bt_stream_class
*stream_class
;
67 bt_event_class
*event_class
;
70 bt_clock_class
*clock_class
;
74 bt_field_class
*create_event_payload_fc(struct dmesg_component
*dmesg_comp
,
75 bt_trace_class
*trace_class
)
77 bt_field_class
*root_fc
= NULL
;
78 bt_field_class
*fc
= NULL
;
79 bt_field_class_structure_append_member_status append_member_status
;
81 root_fc
= bt_field_class_structure_create(trace_class
);
83 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
84 "Cannot create an empty structure field class object.");
88 fc
= bt_field_class_string_create(trace_class
);
90 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
91 "Cannot create a string field class object.");
95 append_member_status
= bt_field_class_structure_append_member(root_fc
,
97 if (append_member_status
!= BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK
) {
98 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
99 "Cannot add `str` member to structure field class: ret=%d",
100 append_member_status
);
107 BT_FIELD_CLASS_PUT_REF_AND_RESET(root_fc
);
110 bt_field_class_put_ref(fc
);
115 int create_meta(struct dmesg_component
*dmesg_comp
, bool has_ts
)
117 bt_field_class
*fc
= NULL
;
120 dmesg_comp
->trace_class
= bt_trace_class_create(dmesg_comp
->self_comp
);
121 if (!dmesg_comp
->trace_class
) {
122 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
123 "Cannot create an empty trace class object.");
127 dmesg_comp
->stream_class
= bt_stream_class_create(
128 dmesg_comp
->trace_class
);
129 if (!dmesg_comp
->stream_class
) {
130 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
131 "Cannot create a stream class object.");
136 dmesg_comp
->clock_class
= bt_clock_class_create(
137 dmesg_comp
->self_comp
);
138 if (!dmesg_comp
->clock_class
) {
139 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
140 "Cannot create clock class.");
145 * The `dmesg` timestamp's origin is not the Unix epoch,
146 * it's the boot time.
148 bt_clock_class_set_origin_is_unix_epoch(dmesg_comp
->clock_class
,
151 ret
= bt_stream_class_set_default_clock_class(
152 dmesg_comp
->stream_class
, dmesg_comp
->clock_class
);
154 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
155 "Cannot set stream class's default clock class.");
160 dmesg_comp
->event_class
= bt_event_class_create(
161 dmesg_comp
->stream_class
);
162 if (!dmesg_comp
->event_class
) {
163 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
164 "Cannot create an event class object.");
168 ret
= bt_event_class_set_name(dmesg_comp
->event_class
, "string");
170 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
171 "Cannot set event class's name.");
175 fc
= create_event_payload_fc(dmesg_comp
, dmesg_comp
->trace_class
);
177 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
178 "Cannot create event payload field class.");
182 ret
= bt_event_class_set_payload_field_class(dmesg_comp
->event_class
, fc
);
184 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
185 "Cannot set event class's event payload field class.");
195 bt_field_class_put_ref(fc
);
200 struct bt_param_validation_map_value_entry_descr dmesg_params
[] = {
201 { "no-extract-timestamp", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { .type
= BT_VALUE_TYPE_BOOL
} },
202 { "path", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { .type
= BT_VALUE_TYPE_STRING
} },
203 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
207 bt_component_class_initialize_method_status
handle_params(
208 struct dmesg_component
*dmesg_comp
,
209 const bt_value
*params
)
211 const bt_value
*no_timestamp
= NULL
;
212 const bt_value
*path
= NULL
;
213 bt_component_class_initialize_method_status status
;
214 enum bt_param_validation_status validation_status
;
215 gchar
*validate_error
= NULL
;
217 validation_status
= bt_param_validation_validate(params
,
218 dmesg_params
, &validate_error
);
219 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
220 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
222 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
223 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
224 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
225 "%s", validate_error
);
229 no_timestamp
= bt_value_map_borrow_entry_value_const(params
,
230 "no-extract-timestamp");
232 dmesg_comp
->params
.no_timestamp
=
233 bt_value_bool_get(no_timestamp
);
236 path
= bt_value_map_borrow_entry_value_const(params
, "path");
238 const char *path_str
= bt_value_string_get(path
);
240 g_string_assign(dmesg_comp
->params
.path
, path_str
);
242 dmesg_comp
->params
.read_from_stdin
= true;
245 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
247 g_free(validate_error
);
253 int create_stream_and_trace(struct dmesg_component
*dmesg_comp
)
256 const char *trace_name
= NULL
;
257 gchar
*basename
= NULL
;
259 dmesg_comp
->trace
= bt_trace_create(dmesg_comp
->trace_class
);
260 if (!dmesg_comp
->trace
) {
261 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
262 "Cannot create trace object.");
266 if (dmesg_comp
->params
.read_from_stdin
) {
267 trace_name
= "STDIN";
269 basename
= g_path_get_basename(dmesg_comp
->params
.path
->str
);
272 if (strcmp(basename
, G_DIR_SEPARATOR_S
) != 0 &&
273 strcmp(basename
, ".") != 0) {
274 trace_name
= basename
;
279 ret
= bt_trace_set_name(dmesg_comp
->trace
, trace_name
);
281 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
282 "Cannot set trace's name: name=\"%s\"",
288 dmesg_comp
->stream
= bt_stream_create(dmesg_comp
->stream_class
,
290 if (!dmesg_comp
->stream
) {
291 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
292 "Cannot create stream object.");
308 int try_create_meta_stream(struct dmesg_component
*dmesg_comp
, bool has_ts
)
312 if (dmesg_comp
->trace
) {
313 /* Already created */
317 ret
= create_meta(dmesg_comp
, has_ts
);
319 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
320 "Cannot create metadata objects: dmesg-comp-addr=%p",
325 ret
= create_stream_and_trace(dmesg_comp
);
327 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
328 "Cannot create stream object: dmesg-comp-addr=%p",
343 void destroy_dmesg_component(struct dmesg_component
*dmesg_comp
)
349 if (dmesg_comp
->params
.path
) {
350 g_string_free(dmesg_comp
->params
.path
, TRUE
);
353 bt_trace_put_ref(dmesg_comp
->trace
);
354 bt_stream_class_put_ref(dmesg_comp
->stream_class
);
355 bt_event_class_put_ref(dmesg_comp
->event_class
);
356 bt_stream_put_ref(dmesg_comp
->stream
);
357 bt_clock_class_put_ref(dmesg_comp
->clock_class
);
358 bt_trace_class_put_ref(dmesg_comp
->trace_class
);
362 bt_component_class_initialize_method_status
dmesg_init(
363 bt_self_component_source
*self_comp_src
,
364 bt_self_component_source_configuration
*config
__attribute__((unused
)),
365 const bt_value
*params
,
366 void *init_method_data
__attribute__((unused
)))
368 struct dmesg_component
*dmesg_comp
= g_new0(struct dmesg_component
, 1);
369 bt_component_class_initialize_method_status status
;
370 bt_self_component
*self_comp
=
371 bt_self_component_source_as_self_component(self_comp_src
);
372 const bt_component
*comp
= bt_self_component_as_component(self_comp
);
373 bt_logging_level log_level
= bt_component_get_logging_level(comp
);
374 bt_self_component_add_port_status add_port_status
;
378 * Don't use BT_COMP_LOGE_APPEND_CAUSE, as `dmesg_comp` is not
381 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_comp
,
382 "Failed to allocate one dmesg component structure.");
383 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT(self_comp
,
384 "Failed to allocate one dmesg component structure.");
385 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
389 dmesg_comp
->log_level
= log_level
;
390 dmesg_comp
->self_comp
= self_comp
;
391 dmesg_comp
->self_comp_src
= self_comp_src
;
392 dmesg_comp
->params
.path
= g_string_new(NULL
);
393 if (!dmesg_comp
->params
.path
) {
394 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "Failed to allocate a GString.");
395 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
399 status
= handle_params(dmesg_comp
, params
);
400 if (status
!= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
) {
401 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
402 "Invalid parameters: comp-addr=%p", self_comp
);
403 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
407 if (!dmesg_comp
->params
.read_from_stdin
&&
408 !g_file_test(dmesg_comp
->params
.path
->str
,
409 G_FILE_TEST_IS_REGULAR
)) {
410 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
411 "Input path is not a regular file: "
412 "comp-addr=%p, path=\"%s\"", self_comp
,
413 dmesg_comp
->params
.path
->str
);
414 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
418 add_port_status
= bt_self_component_source_add_output_port(
419 self_comp_src
, "out", NULL
, NULL
);
420 if (add_port_status
!= BT_SELF_COMPONENT_ADD_PORT_STATUS_OK
) {
421 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "Failed to add output port.");
422 status
= (int) add_port_status
;
426 bt_self_component_set_data(self_comp
, dmesg_comp
);
427 BT_COMP_LOGI_STR("Component initialized.");
429 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
433 destroy_dmesg_component(dmesg_comp
);
434 bt_self_component_set_data(self_comp
, NULL
);
440 void dmesg_finalize(bt_self_component_source
*self_comp
)
442 destroy_dmesg_component(bt_self_component_get_data(
443 bt_self_component_source_as_self_component(self_comp
)));
447 bt_message
*create_init_event_msg_from_line(
448 struct dmesg_msg_iter
*msg_iter
,
449 const char *line
, const char **new_start
)
452 bt_message
*msg
= NULL
;
453 bool has_timestamp
= false;
454 unsigned long sec
, usec
, msec
;
455 unsigned int year
, mon
, mday
, hour
, min
;
458 struct dmesg_component
*dmesg_comp
= msg_iter
->dmesg_comp
;
462 if (dmesg_comp
->params
.no_timestamp
) {
466 /* Extract time from input line */
467 if (sscanf(line
, "[%lu.%lu] ", &sec
, &usec
) == 2) {
468 ts
= (uint64_t) sec
* USEC_PER_SEC
+ (uint64_t) usec
;
471 * The clock class we use has a 1 GHz frequency: convert
475 has_timestamp
= true;
476 } else if (sscanf(line
, "[%u-%u-%u %u:%u:%lu.%lu] ",
477 &year
, &mon
, &mday
, &hour
, &min
,
482 memset(&ti
, 0, sizeof(ti
));
483 ti
.tm_year
= year
- 1900; /* From 1900 */
484 ti
.tm_mon
= mon
- 1; /* 0 to 11 */
490 ep_sec
= bt_timegm(&ti
);
491 if (ep_sec
!= (time_t) -1) {
492 ts
= (uint64_t) ep_sec
* NSEC_PER_SEC
493 + (uint64_t) msec
* NSEC_PER_MSEC
;
496 has_timestamp
= true;
500 /* Set new start for the message portion of the line */
501 *new_start
= strchr(line
, ']');
502 BT_ASSERT_DBG(*new_start
);
505 if ((*new_start
)[0] == ' ') {
512 * At this point, we know if the stream class's event header
513 * field class should have a timestamp or not, so we can lazily
514 * create the metadata and stream objects.
516 ret
= try_create_meta_stream(dmesg_comp
, has_timestamp
);
518 /* try_create_meta_stream() logs errors */
522 if (dmesg_comp
->clock_class
) {
523 msg
= bt_message_event_create_with_default_clock_snapshot(
524 msg_iter
->self_msg_iter
,
525 dmesg_comp
->event_class
, dmesg_comp
->stream
, ts
);
526 msg_iter
->last_clock_value
= ts
;
528 msg
= bt_message_event_create(msg_iter
->self_msg_iter
,
529 dmesg_comp
->event_class
, dmesg_comp
->stream
);
533 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
534 "Cannot create event message.");
538 event
= bt_message_event_borrow_event(msg
);
539 BT_ASSERT_DBG(event
);
543 BT_MESSAGE_PUT_REF_AND_RESET(msg
);
550 int fill_event_payload_from_line(struct dmesg_component
*dmesg_comp
,
551 const char *line
, bt_event
*event
)
553 bt_field
*ep_field
= NULL
;
554 bt_field
*str_field
= NULL
;
558 ep_field
= bt_event_borrow_payload_field(event
);
559 BT_ASSERT_DBG(ep_field
);
560 str_field
= bt_field_structure_borrow_member_field_by_index(
563 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
564 "Cannot borrow `timestamp` field from event payload structure field.");
569 if (line
[len
- 1] == '\n') {
570 /* Do not include the newline character in the payload */
574 bt_field_string_clear(str_field
);
575 ret
= bt_field_string_append_with_length(str_field
, line
, len
);
577 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
578 "Cannot append value to string field object: len=%zu", len
);
592 bt_message
*create_msg_from_line(
593 struct dmesg_msg_iter
*dmesg_msg_iter
, const char *line
)
595 struct dmesg_component
*dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
596 bt_event
*event
= NULL
;
597 bt_message
*msg
= NULL
;
598 const char *new_start
;
601 msg
= create_init_event_msg_from_line(dmesg_msg_iter
,
604 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
605 "Cannot create and initialize event message from line.");
609 event
= bt_message_event_borrow_event(msg
);
610 BT_ASSERT_DBG(event
);
611 ret
= fill_event_payload_from_line(dmesg_comp
, new_start
, event
);
613 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
614 "Cannot fill event payload field from line: ret=%d", ret
);
621 BT_MESSAGE_PUT_REF_AND_RESET(msg
);
628 void destroy_dmesg_msg_iter(struct dmesg_msg_iter
*dmesg_msg_iter
)
630 struct dmesg_component
*dmesg_comp
;
632 if (!dmesg_msg_iter
) {
636 dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
638 if (dmesg_msg_iter
->fp
&& dmesg_msg_iter
->fp
!= stdin
) {
639 if (fclose(dmesg_msg_iter
->fp
)) {
640 BT_COMP_LOGE_APPEND_CAUSE_ERRNO(dmesg_comp
->self_comp
,
641 "Cannot close input file", ".");
645 bt_message_put_ref(dmesg_msg_iter
->tmp_event_msg
);
646 free(dmesg_msg_iter
->linebuf
);
647 g_free(dmesg_msg_iter
);
652 bt_message_iterator_class_initialize_method_status
dmesg_msg_iter_init(
653 bt_self_message_iterator
*self_msg_iter
,
654 bt_self_message_iterator_configuration
*config
__attribute__((unused
)),
655 bt_self_component_port_output
*self_port
__attribute__((unused
)))
657 bt_self_component
*self_comp
=
658 bt_self_message_iterator_borrow_component(self_msg_iter
);
659 struct dmesg_component
*dmesg_comp
= bt_self_component_get_data(self_comp
);
660 struct dmesg_msg_iter
*dmesg_msg_iter
=
661 g_new0(struct dmesg_msg_iter
, 1);
662 bt_message_iterator_class_initialize_method_status status
;
664 if (!dmesg_msg_iter
) {
665 BT_COMP_LOGE_APPEND_CAUSE(self_comp
,
666 "Failed to allocate on dmesg message iterator structure.");
667 status
= BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
671 BT_ASSERT(dmesg_comp
);
672 dmesg_msg_iter
->dmesg_comp
= dmesg_comp
;
673 dmesg_msg_iter
->self_msg_iter
= self_msg_iter
;
675 if (dmesg_comp
->params
.read_from_stdin
) {
676 dmesg_msg_iter
->fp
= stdin
;
678 dmesg_msg_iter
->fp
= fopen(dmesg_comp
->params
.path
->str
, "r");
679 if (!dmesg_msg_iter
->fp
) {
680 BT_COMP_LOGE_APPEND_CAUSE_ERRNO(self_comp
,
681 "Cannot open input file in read mode", ": path=\"%s\"",
682 dmesg_comp
->params
.path
->str
);
683 status
= BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
688 bt_self_message_iterator_set_data(self_msg_iter
,
691 status
= BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK
;
695 destroy_dmesg_msg_iter(dmesg_msg_iter
);
696 bt_self_message_iterator_set_data(self_msg_iter
, NULL
);
702 void dmesg_msg_iter_finalize(
703 bt_self_message_iterator
*priv_msg_iter
)
705 destroy_dmesg_msg_iter(bt_self_message_iterator_get_data(
710 bt_message_iterator_class_next_method_status
dmesg_msg_iter_next_one(
711 struct dmesg_msg_iter
*dmesg_msg_iter
,
715 struct dmesg_component
*dmesg_comp
;
716 bt_message_iterator_class_next_method_status status
;
718 BT_ASSERT_DBG(dmesg_msg_iter
);
719 dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
720 BT_ASSERT_DBG(dmesg_comp
);
722 if (dmesg_msg_iter
->state
== STATE_DONE
) {
723 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END
;
727 if (dmesg_msg_iter
->tmp_event_msg
||
728 dmesg_msg_iter
->state
== STATE_EMIT_STREAM_END
) {
734 bool only_spaces
= true;
736 len
= bt_getline(&dmesg_msg_iter
->linebuf
,
737 &dmesg_msg_iter
->linebuf_len
, dmesg_msg_iter
->fp
);
739 if (errno
== EINVAL
) {
740 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR
;
742 } else if (errno
== ENOMEM
) {
743 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_MEMORY_ERROR
;
746 if (dmesg_msg_iter
->state
== STATE_EMIT_STREAM_BEGINNING
) {
747 /* Stream did not even begin */
748 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END
;
752 dmesg_msg_iter
->state
=
753 STATE_EMIT_STREAM_END
;
759 BT_ASSERT_DBG(dmesg_msg_iter
->linebuf
);
761 /* Ignore empty lines, once trimmed */
762 for (ch
= dmesg_msg_iter
->linebuf
; *ch
!= '\0'; ch
++) {
763 if (!isspace((unsigned char) *ch
)) {
774 dmesg_msg_iter
->tmp_event_msg
= create_msg_from_line(
775 dmesg_msg_iter
, dmesg_msg_iter
->linebuf
);
776 if (!dmesg_msg_iter
->tmp_event_msg
) {
777 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
778 "Cannot create event message from line: "
779 "dmesg-comp-addr=%p, line=\"%s\"", dmesg_comp
,
780 dmesg_msg_iter
->linebuf
);
781 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR
;
786 BT_ASSERT_DBG(dmesg_comp
->trace
);
788 switch (dmesg_msg_iter
->state
) {
789 case STATE_EMIT_STREAM_BEGINNING
:
790 BT_ASSERT_DBG(dmesg_msg_iter
->tmp_event_msg
);
791 *msg
= bt_message_stream_beginning_create(
792 dmesg_msg_iter
->self_msg_iter
, dmesg_comp
->stream
);
793 dmesg_msg_iter
->state
= STATE_EMIT_EVENT
;
795 case STATE_EMIT_EVENT
:
796 BT_ASSERT_DBG(dmesg_msg_iter
->tmp_event_msg
);
797 *msg
= dmesg_msg_iter
->tmp_event_msg
;
798 dmesg_msg_iter
->tmp_event_msg
= NULL
;
800 case STATE_EMIT_STREAM_END
:
801 *msg
= bt_message_stream_end_create(
802 dmesg_msg_iter
->self_msg_iter
, dmesg_comp
->stream
);
803 dmesg_msg_iter
->state
= STATE_DONE
;
810 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
811 "Cannot create message: dmesg-comp-addr=%p",
813 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR
;
817 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
;
823 bt_message_iterator_class_next_method_status
dmesg_msg_iter_next(
824 bt_self_message_iterator
*self_msg_iter
,
825 bt_message_array_const msgs
, uint64_t capacity
,
828 struct dmesg_msg_iter
*dmesg_msg_iter
=
829 bt_self_message_iterator_get_data(
831 bt_message_iterator_class_next_method_status status
=
832 BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
;
835 while (i
< capacity
&&
836 status
== BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
) {
837 bt_message
*priv_msg
= NULL
;
839 status
= dmesg_msg_iter_next_one(dmesg_msg_iter
,
842 if (status
== BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
) {
849 * Even if dmesg_msg_iter_next_one() returned
850 * something else than
851 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK, we
852 * accumulated message objects in the output
853 * message array, so we need to return
854 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK so that they
855 * are transfered to downstream. This other status
856 * occurs again the next time muxer_msg_iter_do_next()
857 * is called, possibly without any accumulated
858 * message, in which case we'll return it.
861 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
;
867 bt_message_iterator_class_can_seek_beginning_method_status
868 dmesg_msg_iter_can_seek_beginning(
869 bt_self_message_iterator
*self_msg_iter
, bt_bool
*can_seek
)
871 struct dmesg_msg_iter
*dmesg_msg_iter
=
872 bt_self_message_iterator_get_data(self_msg_iter
);
874 /* Can't seek the beginning of the standard input stream */
875 *can_seek
= !dmesg_msg_iter
->dmesg_comp
->params
.read_from_stdin
;
877 return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_OK
;
880 bt_message_iterator_class_seek_beginning_method_status
881 dmesg_msg_iter_seek_beginning(
882 bt_self_message_iterator
*self_msg_iter
)
884 struct dmesg_msg_iter
*dmesg_msg_iter
=
885 bt_self_message_iterator_get_data(self_msg_iter
);
887 BT_ASSERT(!dmesg_msg_iter
->dmesg_comp
->params
.read_from_stdin
);
889 BT_MESSAGE_PUT_REF_AND_RESET(dmesg_msg_iter
->tmp_event_msg
);
890 dmesg_msg_iter
->last_clock_value
= 0;
891 dmesg_msg_iter
->state
= STATE_EMIT_STREAM_BEGINNING
;
892 return BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_OK
;