2 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
3 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #define BT_COMP_LOG_SELF_COMP (dmesg_comp->self_comp)
25 #define BT_LOG_OUTPUT_LEVEL (dmesg_comp->log_level)
26 #define BT_LOG_TAG "PLUGIN/SRC.TEXT.DMESG"
27 #include "logging/comp-logging.h"
35 #include "common/common.h"
36 #include "common/assert.h"
37 #include <babeltrace2/babeltrace.h>
38 #include "compat/utc.h"
39 #include "compat/stdio.h"
41 #include "plugins/common/param-validation/param-validation.h"
43 #define NSEC_PER_USEC 1000UL
44 #define NSEC_PER_MSEC 1000000UL
45 #define NSEC_PER_SEC 1000000000ULL
46 #define USEC_PER_SEC 1000000UL
48 struct dmesg_component
;
50 struct dmesg_msg_iter
{
51 struct dmesg_component
*dmesg_comp
;
52 bt_self_message_iterator
*pc_msg_iter
; /* Weak */
56 bt_message
*tmp_event_msg
;
57 uint64_t last_clock_value
;
60 STATE_EMIT_STREAM_BEGINNING
,
62 STATE_EMIT_STREAM_END
,
67 struct dmesg_component
{
68 bt_logging_level log_level
;
72 bt_bool read_from_stdin
;
76 bt_self_component_source
*self_comp_src
;
77 bt_self_component
*self_comp
;
78 bt_trace_class
*trace_class
;
79 bt_stream_class
*stream_class
;
80 bt_event_class
*event_class
;
83 bt_clock_class
*clock_class
;
87 bt_field_class
*create_event_payload_fc(struct dmesg_component
*dmesg_comp
,
88 bt_trace_class
*trace_class
)
90 bt_field_class
*root_fc
= NULL
;
91 bt_field_class
*fc
= NULL
;
94 root_fc
= bt_field_class_structure_create(trace_class
);
96 BT_COMP_LOGE_STR("Cannot create an empty structure field class object.");
100 fc
= bt_field_class_string_create(trace_class
);
102 BT_COMP_LOGE_STR("Cannot create a string field class object.");
106 ret
= bt_field_class_structure_append_member(root_fc
,
109 BT_COMP_LOGE("Cannot add `str` member to structure field class: "
117 BT_FIELD_CLASS_PUT_REF_AND_RESET(root_fc
);
120 bt_field_class_put_ref(fc
);
125 int create_meta(struct dmesg_component
*dmesg_comp
, bool has_ts
)
127 bt_field_class
*fc
= NULL
;
130 dmesg_comp
->trace_class
= bt_trace_class_create(dmesg_comp
->self_comp
);
131 if (!dmesg_comp
->trace_class
) {
132 BT_COMP_LOGE_STR("Cannot create an empty trace class object.");
136 dmesg_comp
->stream_class
= bt_stream_class_create(
137 dmesg_comp
->trace_class
);
138 if (!dmesg_comp
->stream_class
) {
139 BT_COMP_LOGE_STR("Cannot create a stream class object.");
144 dmesg_comp
->clock_class
= bt_clock_class_create(
145 dmesg_comp
->self_comp
);
146 if (!dmesg_comp
->clock_class
) {
147 BT_COMP_LOGE_STR("Cannot create clock class.");
152 * The `dmesg` timestamp's origin is not the Unix epoch,
153 * it's the boot time.
155 bt_clock_class_set_origin_is_unix_epoch(dmesg_comp
->clock_class
,
158 ret
= bt_stream_class_set_default_clock_class(
159 dmesg_comp
->stream_class
, dmesg_comp
->clock_class
);
161 BT_COMP_LOGE_STR("Cannot set stream class's default clock class.");
166 dmesg_comp
->event_class
= bt_event_class_create(
167 dmesg_comp
->stream_class
);
168 if (!dmesg_comp
->event_class
) {
169 BT_COMP_LOGE_STR("Cannot create an event class object.");
173 ret
= bt_event_class_set_name(dmesg_comp
->event_class
, "string");
175 BT_COMP_LOGE_STR("Cannot set event class's name.");
179 fc
= create_event_payload_fc(dmesg_comp
, dmesg_comp
->trace_class
);
181 BT_COMP_LOGE_STR("Cannot create event payload field class.");
185 ret
= bt_event_class_set_payload_field_class(dmesg_comp
->event_class
, fc
);
187 BT_COMP_LOGE_STR("Cannot set event class's event payload field class.");
197 bt_field_class_put_ref(fc
);
201 struct bt_param_validation_map_value_entry_descr dmesg_params
[] = {
202 { "no-extract-timestamp", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { .type
= BT_VALUE_TYPE_BOOL
} },
203 { "path", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { .type
= BT_VALUE_TYPE_STRING
} },
204 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
208 bt_component_class_initialize_method_status
handle_params(
209 struct dmesg_component
*dmesg_comp
,
210 const bt_value
*params
)
212 const bt_value
*no_timestamp
= NULL
;
213 const bt_value
*path
= NULL
;
214 bt_component_class_initialize_method_status status
;
215 enum bt_param_validation_status validation_status
;
216 gchar
*validate_error
= NULL
;
218 validation_status
= bt_param_validation_validate(params
,
219 dmesg_params
, &validate_error
);
220 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
221 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
223 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
224 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
225 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
226 "%s", validate_error
);
230 no_timestamp
= bt_value_map_borrow_entry_value_const(params
,
231 "no-extract-timestamp");
233 dmesg_comp
->params
.no_timestamp
=
234 bt_value_bool_get(no_timestamp
);
237 path
= bt_value_map_borrow_entry_value_const(params
, "path");
239 const char *path_str
= bt_value_string_get(path
);
241 g_string_assign(dmesg_comp
->params
.path
, path_str
);
243 dmesg_comp
->params
.read_from_stdin
= true;
246 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
248 g_free(validate_error
);
254 int create_stream_and_trace(struct dmesg_component
*dmesg_comp
)
257 const char *trace_name
= NULL
;
258 gchar
*basename
= NULL
;
260 dmesg_comp
->trace
= bt_trace_create(dmesg_comp
->trace_class
);
261 if (!dmesg_comp
->trace
) {
262 BT_COMP_LOGE_STR("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("Cannot set trace's name: name=\"%s\"",
287 dmesg_comp
->stream
= bt_stream_create(dmesg_comp
->stream_class
,
289 if (!dmesg_comp
->stream
) {
290 BT_COMP_LOGE_STR("Cannot create stream object.");
306 int try_create_meta_stream(struct dmesg_component
*dmesg_comp
, bool has_ts
)
310 if (dmesg_comp
->trace
) {
311 /* Already created */
315 ret
= create_meta(dmesg_comp
, has_ts
);
317 BT_COMP_LOGE("Cannot create metadata objects: dmesg-comp-addr=%p",
322 ret
= create_stream_and_trace(dmesg_comp
);
324 BT_COMP_LOGE("Cannot create stream object: "
325 "dmesg-comp-addr=%p", dmesg_comp
);
339 void destroy_dmesg_component(struct dmesg_component
*dmesg_comp
)
345 if (dmesg_comp
->params
.path
) {
346 g_string_free(dmesg_comp
->params
.path
, TRUE
);
349 bt_trace_put_ref(dmesg_comp
->trace
);
350 bt_stream_class_put_ref(dmesg_comp
->stream_class
);
351 bt_event_class_put_ref(dmesg_comp
->event_class
);
352 bt_stream_put_ref(dmesg_comp
->stream
);
353 bt_clock_class_put_ref(dmesg_comp
->clock_class
);
354 bt_trace_class_put_ref(dmesg_comp
->trace_class
);
359 bt_component_class_initialize_method_status
create_port(
360 bt_self_component_source
*self_comp
)
362 bt_component_class_initialize_method_status status
;
363 bt_self_component_add_port_status add_port_status
;
365 add_port_status
= bt_self_component_source_add_output_port(self_comp
,
367 switch (add_port_status
) {
368 case BT_SELF_COMPONENT_ADD_PORT_STATUS_OK
:
369 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
371 case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR
:
372 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
374 case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR
:
375 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
385 bt_component_class_initialize_method_status
dmesg_init(
386 bt_self_component_source
*self_comp_src
,
387 bt_self_component_source_configuration
*config
,
388 const bt_value
*params
, void *init_method_data
)
390 struct dmesg_component
*dmesg_comp
= g_new0(struct dmesg_component
, 1);
391 bt_component_class_initialize_method_status status
;
392 bt_self_component
*self_comp
=
393 bt_self_component_source_as_self_component(self_comp_src
);
394 const bt_component
*comp
= bt_self_component_as_component(self_comp
);
395 bt_logging_level log_level
= bt_component_get_logging_level(comp
);
398 /* Implicit log level is not available here */
399 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_comp
,
400 "Failed to allocate one dmesg component structure.");
401 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
405 dmesg_comp
->log_level
= log_level
;
406 dmesg_comp
->self_comp
= self_comp
;
407 dmesg_comp
->self_comp_src
= self_comp_src
;
408 dmesg_comp
->params
.path
= g_string_new(NULL
);
409 if (!dmesg_comp
->params
.path
) {
410 BT_COMP_LOGE_STR("Failed to allocate a GString.");
411 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
415 status
= handle_params(dmesg_comp
, params
);
416 if (status
!= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
) {
417 BT_COMP_LOGE("Invalid parameters: comp-addr=%p", self_comp
);
418 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
422 if (!dmesg_comp
->params
.read_from_stdin
&&
423 !g_file_test(dmesg_comp
->params
.path
->str
,
424 G_FILE_TEST_IS_REGULAR
)) {
425 BT_COMP_LOGE("Input path is not a regular file: "
426 "comp-addr=%p, path=\"%s\"", self_comp
,
427 dmesg_comp
->params
.path
->str
);
428 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
432 status
= create_port(self_comp_src
);
433 if (status
!= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
) {
437 bt_self_component_set_data(self_comp
, dmesg_comp
);
438 BT_COMP_LOGI_STR("Component initialized.");
440 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
444 destroy_dmesg_component(dmesg_comp
);
445 bt_self_component_set_data(self_comp
, NULL
);
452 void dmesg_finalize(bt_self_component_source
*self_comp
)
454 destroy_dmesg_component(bt_self_component_get_data(
455 bt_self_component_source_as_self_component(self_comp
)));
459 bt_message
*create_init_event_msg_from_line(
460 struct dmesg_msg_iter
*msg_iter
,
461 const char *line
, const char **new_start
)
464 bt_message
*msg
= NULL
;
465 bool has_timestamp
= false;
466 unsigned long sec
, usec
, msec
;
467 unsigned int year
, mon
, mday
, hour
, min
;
470 struct dmesg_component
*dmesg_comp
= msg_iter
->dmesg_comp
;
474 if (dmesg_comp
->params
.no_timestamp
) {
478 /* Extract time from input line */
479 if (sscanf(line
, "[%lu.%lu] ", &sec
, &usec
) == 2) {
480 ts
= (uint64_t) sec
* USEC_PER_SEC
+ (uint64_t) usec
;
483 * The clock class we use has a 1 GHz frequency: convert
487 has_timestamp
= true;
488 } else if (sscanf(line
, "[%u-%u-%u %u:%u:%lu.%lu] ",
489 &year
, &mon
, &mday
, &hour
, &min
,
494 memset(&ti
, 0, sizeof(ti
));
495 ti
.tm_year
= year
- 1900; /* From 1900 */
496 ti
.tm_mon
= mon
- 1; /* 0 to 11 */
502 ep_sec
= bt_timegm(&ti
);
503 if (ep_sec
!= (time_t) -1) {
504 ts
= (uint64_t) ep_sec
* NSEC_PER_SEC
505 + (uint64_t) msec
* NSEC_PER_MSEC
;
508 has_timestamp
= true;
512 /* Set new start for the message portion of the line */
513 *new_start
= strchr(line
, ']');
514 BT_ASSERT_DBG(*new_start
);
517 if ((*new_start
)[0] == ' ') {
524 * At this point, we know if the stream class's event header
525 * field class should have a timestamp or not, so we can lazily
526 * create the metadata and stream objects.
528 ret
= try_create_meta_stream(dmesg_comp
, has_timestamp
);
530 /* try_create_meta_stream() logs errors */
534 if (dmesg_comp
->clock_class
) {
535 msg
= bt_message_event_create_with_default_clock_snapshot(
536 msg_iter
->pc_msg_iter
,
537 dmesg_comp
->event_class
, dmesg_comp
->stream
, ts
);
538 msg_iter
->last_clock_value
= ts
;
540 msg
= bt_message_event_create(msg_iter
->pc_msg_iter
,
541 dmesg_comp
->event_class
, dmesg_comp
->stream
);
545 BT_COMP_LOGE_STR("Cannot create event message.");
549 event
= bt_message_event_borrow_event(msg
);
550 BT_ASSERT_DBG(event
);
554 BT_MESSAGE_PUT_REF_AND_RESET(msg
);
561 int fill_event_payload_from_line(struct dmesg_component
*dmesg_comp
,
562 const char *line
, bt_event
*event
)
564 bt_field
*ep_field
= NULL
;
565 bt_field
*str_field
= NULL
;
569 ep_field
= bt_event_borrow_payload_field(event
);
570 BT_ASSERT_DBG(ep_field
);
571 str_field
= bt_field_structure_borrow_member_field_by_index(
574 BT_COMP_LOGE_STR("Cannot borrow `timestamp` field from event payload structure field.");
579 if (line
[len
- 1] == '\n') {
580 /* Do not include the newline character in the payload */
584 bt_field_string_clear(str_field
);
585 ret
= bt_field_string_append_with_length(str_field
, line
, len
);
587 BT_COMP_LOGE("Cannot append value to string field object: "
602 bt_message
*create_msg_from_line(
603 struct dmesg_msg_iter
*dmesg_msg_iter
, const char *line
)
605 struct dmesg_component
*dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
606 bt_event
*event
= NULL
;
607 bt_message
*msg
= NULL
;
608 const char *new_start
;
611 msg
= create_init_event_msg_from_line(dmesg_msg_iter
,
614 BT_COMP_LOGE_STR("Cannot create and initialize event message from line.");
618 event
= bt_message_event_borrow_event(msg
);
619 BT_ASSERT_DBG(event
);
620 ret
= fill_event_payload_from_line(dmesg_comp
, new_start
, event
);
622 BT_COMP_LOGE("Cannot fill event payload field from line: "
630 BT_MESSAGE_PUT_REF_AND_RESET(msg
);
637 void destroy_dmesg_msg_iter(struct dmesg_msg_iter
*dmesg_msg_iter
)
639 struct dmesg_component
*dmesg_comp
;
641 if (!dmesg_msg_iter
) {
645 dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
647 if (dmesg_msg_iter
->fp
&& dmesg_msg_iter
->fp
!= stdin
) {
648 if (fclose(dmesg_msg_iter
->fp
)) {
649 BT_COMP_LOGE_ERRNO("Cannot close input file", ".");
653 bt_message_put_ref(dmesg_msg_iter
->tmp_event_msg
);
654 free(dmesg_msg_iter
->linebuf
);
655 g_free(dmesg_msg_iter
);
661 bt_component_class_message_iterator_initialize_method_status
dmesg_msg_iter_init(
662 bt_self_message_iterator
*self_msg_iter
,
663 bt_self_message_iterator_configuration
*config
,
664 bt_self_component_source
*self_comp
,
665 bt_self_component_port_output
*self_port
)
667 struct dmesg_component
*dmesg_comp
= bt_self_component_get_data(
668 bt_self_component_source_as_self_component(self_comp
));
669 struct dmesg_msg_iter
*dmesg_msg_iter
=
670 g_new0(struct dmesg_msg_iter
, 1);
671 bt_component_class_message_iterator_initialize_method_status status
=
672 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_OK
;
674 if (!dmesg_msg_iter
) {
675 BT_COMP_LOGE_STR("Failed to allocate on dmesg message iterator structure.");
679 BT_ASSERT(dmesg_comp
);
680 dmesg_msg_iter
->dmesg_comp
= dmesg_comp
;
681 dmesg_msg_iter
->pc_msg_iter
= self_msg_iter
;
683 if (dmesg_comp
->params
.read_from_stdin
) {
684 dmesg_msg_iter
->fp
= stdin
;
686 dmesg_msg_iter
->fp
= fopen(dmesg_comp
->params
.path
->str
, "r");
687 if (!dmesg_msg_iter
->fp
) {
688 BT_COMP_LOGE_ERRNO("Cannot open input file in read mode", ": path=\"%s\"",
689 dmesg_comp
->params
.path
->str
);
694 bt_self_message_iterator_set_data(self_msg_iter
,
699 destroy_dmesg_msg_iter(dmesg_msg_iter
);
700 bt_self_message_iterator_set_data(self_msg_iter
, NULL
);
702 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INITIALIZE_METHOD_STATUS_ERROR
;
710 void dmesg_msg_iter_finalize(
711 bt_self_message_iterator
*priv_msg_iter
)
713 destroy_dmesg_msg_iter(bt_self_message_iterator_get_data(
718 bt_component_class_message_iterator_next_method_status
dmesg_msg_iter_next_one(
719 struct dmesg_msg_iter
*dmesg_msg_iter
,
723 struct dmesg_component
*dmesg_comp
;
724 bt_component_class_message_iterator_next_method_status status
=
725 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
727 BT_ASSERT_DBG(dmesg_msg_iter
);
728 dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
729 BT_ASSERT_DBG(dmesg_comp
);
731 if (dmesg_msg_iter
->state
== STATE_DONE
) {
732 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END
;
736 if (dmesg_msg_iter
->tmp_event_msg
||
737 dmesg_msg_iter
->state
== STATE_EMIT_STREAM_END
) {
743 bool only_spaces
= true;
745 len
= bt_getline(&dmesg_msg_iter
->linebuf
,
746 &dmesg_msg_iter
->linebuf_len
, dmesg_msg_iter
->fp
);
748 if (errno
== EINVAL
) {
749 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
750 } else if (errno
== ENOMEM
) {
751 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR
;
753 if (dmesg_msg_iter
->state
== STATE_EMIT_STREAM_BEGINNING
) {
754 /* Stream did not even begin */
755 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_END
;
759 dmesg_msg_iter
->state
=
760 STATE_EMIT_STREAM_END
;
768 BT_ASSERT_DBG(dmesg_msg_iter
->linebuf
);
770 /* Ignore empty lines, once trimmed */
771 for (ch
= dmesg_msg_iter
->linebuf
; *ch
!= '\0'; ch
++) {
783 dmesg_msg_iter
->tmp_event_msg
= create_msg_from_line(
784 dmesg_msg_iter
, dmesg_msg_iter
->linebuf
);
785 if (!dmesg_msg_iter
->tmp_event_msg
) {
786 BT_COMP_LOGE("Cannot create event message from line: "
787 "dmesg-comp-addr=%p, line=\"%s\"", dmesg_comp
,
788 dmesg_msg_iter
->linebuf
);
793 BT_ASSERT_DBG(dmesg_comp
->trace
);
795 switch (dmesg_msg_iter
->state
) {
796 case STATE_EMIT_STREAM_BEGINNING
:
797 BT_ASSERT_DBG(dmesg_msg_iter
->tmp_event_msg
);
798 *msg
= bt_message_stream_beginning_create(
799 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->stream
);
800 dmesg_msg_iter
->state
= STATE_EMIT_EVENT
;
802 case STATE_EMIT_EVENT
:
803 BT_ASSERT_DBG(dmesg_msg_iter
->tmp_event_msg
);
804 *msg
= dmesg_msg_iter
->tmp_event_msg
;
805 dmesg_msg_iter
->tmp_event_msg
= NULL
;
807 case STATE_EMIT_STREAM_END
:
808 *msg
= bt_message_stream_end_create(
809 dmesg_msg_iter
->pc_msg_iter
, dmesg_comp
->stream
);
810 dmesg_msg_iter
->state
= STATE_DONE
;
817 BT_COMP_LOGE("Cannot create message: dmesg-comp-addr=%p",
819 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR
;
827 bt_component_class_message_iterator_next_method_status
dmesg_msg_iter_next(
828 bt_self_message_iterator
*self_msg_iter
,
829 bt_message_array_const msgs
, uint64_t capacity
,
832 struct dmesg_msg_iter
*dmesg_msg_iter
=
833 bt_self_message_iterator_get_data(
835 bt_component_class_message_iterator_next_method_status status
=
836 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
839 while (i
< capacity
&&
840 status
== BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
) {
841 bt_message
*priv_msg
= NULL
;
843 status
= dmesg_msg_iter_next_one(dmesg_msg_iter
,
846 if (status
== BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
) {
853 * Even if dmesg_msg_iter_next_one() returned
854 * something else than
855 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK, we
856 * accumulated message objects in the output
857 * message array, so we need to return
858 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK so that they
859 * are transfered to downstream. This other status
860 * occurs again the next time muxer_msg_iter_do_next()
861 * is called, possibly without any accumulated
862 * message, in which case we'll return it.
865 status
= BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK
;
872 bt_component_class_message_iterator_can_seek_beginning_method_status
873 dmesg_msg_iter_can_seek_beginning(
874 bt_self_message_iterator
*self_msg_iter
, bt_bool
*can_seek
)
876 struct dmesg_msg_iter
*dmesg_msg_iter
=
877 bt_self_message_iterator_get_data(self_msg_iter
);
879 /* Can't seek the beginning of the standard input stream */
880 *can_seek
= !dmesg_msg_iter
->dmesg_comp
->params
.read_from_stdin
;
882 return BT_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD_STATUS_OK
;
886 bt_component_class_message_iterator_seek_beginning_method_status
887 dmesg_msg_iter_seek_beginning(
888 bt_self_message_iterator
*self_msg_iter
)
890 struct dmesg_msg_iter
*dmesg_msg_iter
=
891 bt_self_message_iterator_get_data(self_msg_iter
);
893 BT_ASSERT(!dmesg_msg_iter
->dmesg_comp
->params
.read_from_stdin
);
895 BT_MESSAGE_PUT_REF_AND_RESET(dmesg_msg_iter
->tmp_event_msg
);
896 dmesg_msg_iter
->last_clock_value
= 0;
897 dmesg_msg_iter
->state
= STATE_EMIT_STREAM_BEGINNING
;
898 return BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_STATUS_OK
;