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
;
54 bt_self_message_iterator
*self_msg_iter
;
59 bt_message
*tmp_event_msg
;
60 uint64_t last_clock_value
;
63 STATE_EMIT_STREAM_BEGINNING
,
65 STATE_EMIT_STREAM_END
,
70 struct dmesg_component
{
71 bt_logging_level log_level
;
75 bt_bool read_from_stdin
;
79 bt_self_component_source
*self_comp_src
;
80 bt_self_component
*self_comp
;
81 bt_trace_class
*trace_class
;
82 bt_stream_class
*stream_class
;
83 bt_event_class
*event_class
;
86 bt_clock_class
*clock_class
;
90 bt_field_class
*create_event_payload_fc(struct dmesg_component
*dmesg_comp
,
91 bt_trace_class
*trace_class
)
93 bt_field_class
*root_fc
= NULL
;
94 bt_field_class
*fc
= NULL
;
97 root_fc
= bt_field_class_structure_create(trace_class
);
99 BT_COMP_LOGE_STR("Cannot create an empty structure field class object.");
103 fc
= bt_field_class_string_create(trace_class
);
105 BT_COMP_LOGE_STR("Cannot create a string field class object.");
109 ret
= bt_field_class_structure_append_member(root_fc
,
112 BT_COMP_LOGE("Cannot add `str` member to structure field class: "
120 BT_FIELD_CLASS_PUT_REF_AND_RESET(root_fc
);
123 bt_field_class_put_ref(fc
);
128 int create_meta(struct dmesg_component
*dmesg_comp
, bool has_ts
)
130 bt_field_class
*fc
= NULL
;
133 dmesg_comp
->trace_class
= bt_trace_class_create(dmesg_comp
->self_comp
);
134 if (!dmesg_comp
->trace_class
) {
135 BT_COMP_LOGE_STR("Cannot create an empty trace class object.");
139 dmesg_comp
->stream_class
= bt_stream_class_create(
140 dmesg_comp
->trace_class
);
141 if (!dmesg_comp
->stream_class
) {
142 BT_COMP_LOGE_STR("Cannot create a stream class object.");
147 dmesg_comp
->clock_class
= bt_clock_class_create(
148 dmesg_comp
->self_comp
);
149 if (!dmesg_comp
->clock_class
) {
150 BT_COMP_LOGE_STR("Cannot create clock class.");
155 * The `dmesg` timestamp's origin is not the Unix epoch,
156 * it's the boot time.
158 bt_clock_class_set_origin_is_unix_epoch(dmesg_comp
->clock_class
,
161 ret
= bt_stream_class_set_default_clock_class(
162 dmesg_comp
->stream_class
, dmesg_comp
->clock_class
);
164 BT_COMP_LOGE_STR("Cannot set stream class's default clock class.");
169 dmesg_comp
->event_class
= bt_event_class_create(
170 dmesg_comp
->stream_class
);
171 if (!dmesg_comp
->event_class
) {
172 BT_COMP_LOGE_STR("Cannot create an event class object.");
176 ret
= bt_event_class_set_name(dmesg_comp
->event_class
, "string");
178 BT_COMP_LOGE_STR("Cannot set event class's name.");
182 fc
= create_event_payload_fc(dmesg_comp
, dmesg_comp
->trace_class
);
184 BT_COMP_LOGE_STR("Cannot create event payload field class.");
188 ret
= bt_event_class_set_payload_field_class(dmesg_comp
->event_class
, fc
);
190 BT_COMP_LOGE_STR("Cannot set event class's event payload field class.");
200 bt_field_class_put_ref(fc
);
205 struct bt_param_validation_map_value_entry_descr dmesg_params
[] = {
206 { "no-extract-timestamp", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { .type
= BT_VALUE_TYPE_BOOL
} },
207 { "path", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL
, { .type
= BT_VALUE_TYPE_STRING
} },
208 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
212 bt_component_class_initialize_method_status
handle_params(
213 struct dmesg_component
*dmesg_comp
,
214 const bt_value
*params
)
216 const bt_value
*no_timestamp
= NULL
;
217 const bt_value
*path
= NULL
;
218 bt_component_class_initialize_method_status status
;
219 enum bt_param_validation_status validation_status
;
220 gchar
*validate_error
= NULL
;
222 validation_status
= bt_param_validation_validate(params
,
223 dmesg_params
, &validate_error
);
224 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
225 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
227 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
228 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
229 BT_COMP_LOGE_APPEND_CAUSE(dmesg_comp
->self_comp
,
230 "%s", validate_error
);
234 no_timestamp
= bt_value_map_borrow_entry_value_const(params
,
235 "no-extract-timestamp");
237 dmesg_comp
->params
.no_timestamp
=
238 bt_value_bool_get(no_timestamp
);
241 path
= bt_value_map_borrow_entry_value_const(params
, "path");
243 const char *path_str
= bt_value_string_get(path
);
245 g_string_assign(dmesg_comp
->params
.path
, path_str
);
247 dmesg_comp
->params
.read_from_stdin
= true;
250 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
252 g_free(validate_error
);
258 int create_stream_and_trace(struct dmesg_component
*dmesg_comp
)
261 const char *trace_name
= NULL
;
262 gchar
*basename
= NULL
;
264 dmesg_comp
->trace
= bt_trace_create(dmesg_comp
->trace_class
);
265 if (!dmesg_comp
->trace
) {
266 BT_COMP_LOGE_STR("Cannot create trace object.");
270 if (dmesg_comp
->params
.read_from_stdin
) {
271 trace_name
= "STDIN";
273 basename
= g_path_get_basename(dmesg_comp
->params
.path
->str
);
276 if (strcmp(basename
, G_DIR_SEPARATOR_S
) != 0 &&
277 strcmp(basename
, ".") != 0) {
278 trace_name
= basename
;
283 ret
= bt_trace_set_name(dmesg_comp
->trace
, trace_name
);
285 BT_COMP_LOGE("Cannot set trace's name: name=\"%s\"",
291 dmesg_comp
->stream
= bt_stream_create(dmesg_comp
->stream_class
,
293 if (!dmesg_comp
->stream
) {
294 BT_COMP_LOGE_STR("Cannot create stream object.");
310 int try_create_meta_stream(struct dmesg_component
*dmesg_comp
, bool has_ts
)
314 if (dmesg_comp
->trace
) {
315 /* Already created */
319 ret
= create_meta(dmesg_comp
, has_ts
);
321 BT_COMP_LOGE("Cannot create metadata objects: dmesg-comp-addr=%p",
326 ret
= create_stream_and_trace(dmesg_comp
);
328 BT_COMP_LOGE("Cannot create stream object: "
329 "dmesg-comp-addr=%p", dmesg_comp
);
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
);
363 bt_component_class_initialize_method_status
create_port(
364 bt_self_component_source
*self_comp
)
366 bt_component_class_initialize_method_status status
;
367 bt_self_component_add_port_status add_port_status
;
369 add_port_status
= bt_self_component_source_add_output_port(self_comp
,
371 switch (add_port_status
) {
372 case BT_SELF_COMPONENT_ADD_PORT_STATUS_OK
:
373 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
375 case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR
:
376 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
378 case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR
:
379 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
389 bt_component_class_initialize_method_status
dmesg_init(
390 bt_self_component_source
*self_comp_src
,
391 bt_self_component_source_configuration
*config
,
392 const bt_value
*params
, void *init_method_data
)
394 struct dmesg_component
*dmesg_comp
= g_new0(struct dmesg_component
, 1);
395 bt_component_class_initialize_method_status status
;
396 bt_self_component
*self_comp
=
397 bt_self_component_source_as_self_component(self_comp_src
);
398 const bt_component
*comp
= bt_self_component_as_component(self_comp
);
399 bt_logging_level log_level
= bt_component_get_logging_level(comp
);
402 /* Implicit log level is not available here */
403 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR
, log_level
, self_comp
,
404 "Failed to allocate one dmesg component structure.");
405 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
409 dmesg_comp
->log_level
= log_level
;
410 dmesg_comp
->self_comp
= self_comp
;
411 dmesg_comp
->self_comp_src
= self_comp_src
;
412 dmesg_comp
->params
.path
= g_string_new(NULL
);
413 if (!dmesg_comp
->params
.path
) {
414 BT_COMP_LOGE_STR("Failed to allocate a GString.");
415 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
419 status
= handle_params(dmesg_comp
, params
);
420 if (status
!= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
) {
421 BT_COMP_LOGE("Invalid parameters: comp-addr=%p", self_comp
);
422 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
426 if (!dmesg_comp
->params
.read_from_stdin
&&
427 !g_file_test(dmesg_comp
->params
.path
->str
,
428 G_FILE_TEST_IS_REGULAR
)) {
429 BT_COMP_LOGE("Input path is not a regular file: "
430 "comp-addr=%p, path=\"%s\"", self_comp
,
431 dmesg_comp
->params
.path
->str
);
432 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
436 status
= create_port(self_comp_src
);
437 if (status
!= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
) {
441 bt_self_component_set_data(self_comp
, dmesg_comp
);
442 BT_COMP_LOGI_STR("Component initialized.");
444 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
448 destroy_dmesg_component(dmesg_comp
);
449 bt_self_component_set_data(self_comp
, NULL
);
456 void dmesg_finalize(bt_self_component_source
*self_comp
)
458 destroy_dmesg_component(bt_self_component_get_data(
459 bt_self_component_source_as_self_component(self_comp
)));
463 bt_message
*create_init_event_msg_from_line(
464 struct dmesg_msg_iter
*msg_iter
,
465 const char *line
, const char **new_start
)
468 bt_message
*msg
= NULL
;
469 bool has_timestamp
= false;
470 unsigned long sec
, usec
, msec
;
471 unsigned int year
, mon
, mday
, hour
, min
;
474 struct dmesg_component
*dmesg_comp
= msg_iter
->dmesg_comp
;
478 if (dmesg_comp
->params
.no_timestamp
) {
482 /* Extract time from input line */
483 if (sscanf(line
, "[%lu.%lu] ", &sec
, &usec
) == 2) {
484 ts
= (uint64_t) sec
* USEC_PER_SEC
+ (uint64_t) usec
;
487 * The clock class we use has a 1 GHz frequency: convert
491 has_timestamp
= true;
492 } else if (sscanf(line
, "[%u-%u-%u %u:%u:%lu.%lu] ",
493 &year
, &mon
, &mday
, &hour
, &min
,
498 memset(&ti
, 0, sizeof(ti
));
499 ti
.tm_year
= year
- 1900; /* From 1900 */
500 ti
.tm_mon
= mon
- 1; /* 0 to 11 */
506 ep_sec
= bt_timegm(&ti
);
507 if (ep_sec
!= (time_t) -1) {
508 ts
= (uint64_t) ep_sec
* NSEC_PER_SEC
509 + (uint64_t) msec
* NSEC_PER_MSEC
;
512 has_timestamp
= true;
516 /* Set new start for the message portion of the line */
517 *new_start
= strchr(line
, ']');
518 BT_ASSERT_DBG(*new_start
);
521 if ((*new_start
)[0] == ' ') {
528 * At this point, we know if the stream class's event header
529 * field class should have a timestamp or not, so we can lazily
530 * create the metadata and stream objects.
532 ret
= try_create_meta_stream(dmesg_comp
, has_timestamp
);
534 /* try_create_meta_stream() logs errors */
538 if (dmesg_comp
->clock_class
) {
539 msg
= bt_message_event_create_with_default_clock_snapshot(
540 msg_iter
->self_msg_iter
,
541 dmesg_comp
->event_class
, dmesg_comp
->stream
, ts
);
542 msg_iter
->last_clock_value
= ts
;
544 msg
= bt_message_event_create(msg_iter
->self_msg_iter
,
545 dmesg_comp
->event_class
, dmesg_comp
->stream
);
549 BT_COMP_LOGE_STR("Cannot create event message.");
553 event
= bt_message_event_borrow_event(msg
);
554 BT_ASSERT_DBG(event
);
558 BT_MESSAGE_PUT_REF_AND_RESET(msg
);
565 int fill_event_payload_from_line(struct dmesg_component
*dmesg_comp
,
566 const char *line
, bt_event
*event
)
568 bt_field
*ep_field
= NULL
;
569 bt_field
*str_field
= NULL
;
573 ep_field
= bt_event_borrow_payload_field(event
);
574 BT_ASSERT_DBG(ep_field
);
575 str_field
= bt_field_structure_borrow_member_field_by_index(
578 BT_COMP_LOGE_STR("Cannot borrow `timestamp` field from event payload structure field.");
583 if (line
[len
- 1] == '\n') {
584 /* Do not include the newline character in the payload */
588 bt_field_string_clear(str_field
);
589 ret
= bt_field_string_append_with_length(str_field
, line
, len
);
591 BT_COMP_LOGE("Cannot append value to string field object: "
606 bt_message
*create_msg_from_line(
607 struct dmesg_msg_iter
*dmesg_msg_iter
, const char *line
)
609 struct dmesg_component
*dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
610 bt_event
*event
= NULL
;
611 bt_message
*msg
= NULL
;
612 const char *new_start
;
615 msg
= create_init_event_msg_from_line(dmesg_msg_iter
,
618 BT_COMP_LOGE_STR("Cannot create and initialize event message from line.");
622 event
= bt_message_event_borrow_event(msg
);
623 BT_ASSERT_DBG(event
);
624 ret
= fill_event_payload_from_line(dmesg_comp
, new_start
, event
);
626 BT_COMP_LOGE("Cannot fill event payload field from line: "
634 BT_MESSAGE_PUT_REF_AND_RESET(msg
);
641 void destroy_dmesg_msg_iter(struct dmesg_msg_iter
*dmesg_msg_iter
)
643 struct dmesg_component
*dmesg_comp
;
645 if (!dmesg_msg_iter
) {
649 dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
651 if (dmesg_msg_iter
->fp
&& dmesg_msg_iter
->fp
!= stdin
) {
652 if (fclose(dmesg_msg_iter
->fp
)) {
653 BT_COMP_LOGE_ERRNO("Cannot close input file", ".");
657 bt_message_put_ref(dmesg_msg_iter
->tmp_event_msg
);
658 free(dmesg_msg_iter
->linebuf
);
659 g_free(dmesg_msg_iter
);
665 bt_message_iterator_class_initialize_method_status
dmesg_msg_iter_init(
666 bt_self_message_iterator
*self_msg_iter
,
667 bt_self_message_iterator_configuration
*config
,
668 bt_self_component_port_output
*self_port
)
670 bt_self_component
*self_comp
=
671 bt_self_message_iterator_borrow_component(self_msg_iter
);
672 struct dmesg_component
*dmesg_comp
= bt_self_component_get_data(self_comp
);
673 struct dmesg_msg_iter
*dmesg_msg_iter
=
674 g_new0(struct dmesg_msg_iter
, 1);
675 bt_message_iterator_class_initialize_method_status status
=
676 BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK
;
678 if (!dmesg_msg_iter
) {
679 BT_COMP_LOGE_STR("Failed to allocate on dmesg message iterator structure.");
683 BT_ASSERT(dmesg_comp
);
684 dmesg_msg_iter
->dmesg_comp
= dmesg_comp
;
685 dmesg_msg_iter
->self_msg_iter
= self_msg_iter
;
687 if (dmesg_comp
->params
.read_from_stdin
) {
688 dmesg_msg_iter
->fp
= stdin
;
690 dmesg_msg_iter
->fp
= fopen(dmesg_comp
->params
.path
->str
, "r");
691 if (!dmesg_msg_iter
->fp
) {
692 BT_COMP_LOGE_ERRNO("Cannot open input file in read mode", ": path=\"%s\"",
693 dmesg_comp
->params
.path
->str
);
698 bt_self_message_iterator_set_data(self_msg_iter
,
703 destroy_dmesg_msg_iter(dmesg_msg_iter
);
704 bt_self_message_iterator_set_data(self_msg_iter
, NULL
);
706 status
= BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
714 void dmesg_msg_iter_finalize(
715 bt_self_message_iterator
*priv_msg_iter
)
717 destroy_dmesg_msg_iter(bt_self_message_iterator_get_data(
722 bt_message_iterator_class_next_method_status
dmesg_msg_iter_next_one(
723 struct dmesg_msg_iter
*dmesg_msg_iter
,
727 struct dmesg_component
*dmesg_comp
;
728 bt_message_iterator_class_next_method_status status
=
729 BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
;
731 BT_ASSERT_DBG(dmesg_msg_iter
);
732 dmesg_comp
= dmesg_msg_iter
->dmesg_comp
;
733 BT_ASSERT_DBG(dmesg_comp
);
735 if (dmesg_msg_iter
->state
== STATE_DONE
) {
736 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END
;
740 if (dmesg_msg_iter
->tmp_event_msg
||
741 dmesg_msg_iter
->state
== STATE_EMIT_STREAM_END
) {
747 bool only_spaces
= true;
749 len
= bt_getline(&dmesg_msg_iter
->linebuf
,
750 &dmesg_msg_iter
->linebuf_len
, dmesg_msg_iter
->fp
);
752 if (errno
== EINVAL
) {
753 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR
;
754 } else if (errno
== ENOMEM
) {
755 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_MEMORY_ERROR
;
757 if (dmesg_msg_iter
->state
== STATE_EMIT_STREAM_BEGINNING
) {
758 /* Stream did not even begin */
759 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_END
;
763 dmesg_msg_iter
->state
=
764 STATE_EMIT_STREAM_END
;
772 BT_ASSERT_DBG(dmesg_msg_iter
->linebuf
);
774 /* Ignore empty lines, once trimmed */
775 for (ch
= dmesg_msg_iter
->linebuf
; *ch
!= '\0'; ch
++) {
787 dmesg_msg_iter
->tmp_event_msg
= create_msg_from_line(
788 dmesg_msg_iter
, dmesg_msg_iter
->linebuf
);
789 if (!dmesg_msg_iter
->tmp_event_msg
) {
790 BT_COMP_LOGE("Cannot create event message from line: "
791 "dmesg-comp-addr=%p, line=\"%s\"", dmesg_comp
,
792 dmesg_msg_iter
->linebuf
);
797 BT_ASSERT_DBG(dmesg_comp
->trace
);
799 switch (dmesg_msg_iter
->state
) {
800 case STATE_EMIT_STREAM_BEGINNING
:
801 BT_ASSERT_DBG(dmesg_msg_iter
->tmp_event_msg
);
802 *msg
= bt_message_stream_beginning_create(
803 dmesg_msg_iter
->self_msg_iter
, dmesg_comp
->stream
);
804 dmesg_msg_iter
->state
= STATE_EMIT_EVENT
;
806 case STATE_EMIT_EVENT
:
807 BT_ASSERT_DBG(dmesg_msg_iter
->tmp_event_msg
);
808 *msg
= dmesg_msg_iter
->tmp_event_msg
;
809 dmesg_msg_iter
->tmp_event_msg
= NULL
;
811 case STATE_EMIT_STREAM_END
:
812 *msg
= bt_message_stream_end_create(
813 dmesg_msg_iter
->self_msg_iter
, dmesg_comp
->stream
);
814 dmesg_msg_iter
->state
= STATE_DONE
;
821 BT_COMP_LOGE("Cannot create message: dmesg-comp-addr=%p",
823 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_ERROR
;
831 bt_message_iterator_class_next_method_status
dmesg_msg_iter_next(
832 bt_self_message_iterator
*self_msg_iter
,
833 bt_message_array_const msgs
, uint64_t capacity
,
836 struct dmesg_msg_iter
*dmesg_msg_iter
=
837 bt_self_message_iterator_get_data(
839 bt_message_iterator_class_next_method_status status
=
840 BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
;
843 while (i
< capacity
&&
844 status
== BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
) {
845 bt_message
*priv_msg
= NULL
;
847 status
= dmesg_msg_iter_next_one(dmesg_msg_iter
,
850 if (status
== BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
) {
857 * Even if dmesg_msg_iter_next_one() returned
858 * something else than
859 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK, we
860 * accumulated message objects in the output
861 * message array, so we need to return
862 * BT_SELF_MESSAGE_ITERATOR_STATUS_OK so that they
863 * are transfered to downstream. This other status
864 * occurs again the next time muxer_msg_iter_do_next()
865 * is called, possibly without any accumulated
866 * message, in which case we'll return it.
869 status
= BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK
;
876 bt_message_iterator_class_can_seek_beginning_method_status
877 dmesg_msg_iter_can_seek_beginning(
878 bt_self_message_iterator
*self_msg_iter
, bt_bool
*can_seek
)
880 struct dmesg_msg_iter
*dmesg_msg_iter
=
881 bt_self_message_iterator_get_data(self_msg_iter
);
883 /* Can't seek the beginning of the standard input stream */
884 *can_seek
= !dmesg_msg_iter
->dmesg_comp
->params
.read_from_stdin
;
886 return BT_MESSAGE_ITERATOR_CLASS_CAN_SEEK_BEGINNING_METHOD_STATUS_OK
;
890 bt_message_iterator_class_seek_beginning_method_status
891 dmesg_msg_iter_seek_beginning(
892 bt_self_message_iterator
*self_msg_iter
)
894 struct dmesg_msg_iter
*dmesg_msg_iter
=
895 bt_self_message_iterator_get_data(self_msg_iter
);
897 BT_ASSERT(!dmesg_msg_iter
->dmesg_comp
->params
.read_from_stdin
);
899 BT_MESSAGE_PUT_REF_AND_RESET(dmesg_msg_iter
->tmp_event_msg
);
900 dmesg_msg_iter
->last_clock_value
= 0;
901 dmesg_msg_iter
->state
= STATE_EMIT_STREAM_BEGINNING
;
902 return BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_OK
;