2 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
3 * Copyright 2017 Philippe Proulx <jeremie.galarneau@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
27 #include <babeltrace/babeltrace-internal.h>
28 #include <babeltrace/graph/component.h>
29 #include <babeltrace/graph/clock-class-priority-map.h>
32 struct dmesg_component
;
34 struct dmesg_notif_iter
{
35 struct dmesg_component
*dmesg_comp
;
39 struct dmesg_component
{
45 struct bt_ctf_packet
*packet
;
46 struct bt_ctf_event_class
*event_class
;
47 struct bt_ctf_stream
*stream
;
48 struct bt_clock_class_priority_map
*cc_prio_map
;
52 int check_params(struct dmesg_component
*dmesg_comp
, struct bt_value
*params
)
54 struct bt_value
*read_from_stdin
;
55 struct bt_value
*path
;
59 if (!params
|| !bt_value_is_map(params
)) {
60 fprintf(stderr
, "Expecting a map value as parameters.\n");
64 read_from_stdin
= bt_value_map_get(params
, "read-from-stdin");
65 if (read_from_stdin
) {
66 if (!bt_value_is_bool(read_from_stdin
)) {
67 fprintf(stderr
, "Expecting a boolean value for `read-from-stdin` parameter.\n");
71 ret
= bt_value_bool_get(read_from_stdin
,
72 &dmesg_comp
->params
.read_from_stdin
);
76 path
= bt_value_map_get(params
, "path");
78 if (dmesg_comp
->params
.read_from_stdin
) {
79 fprintf(stderr
, "Cannot specify both `read-from-stdin` and `path` parameters.\n");
83 if (!bt_value_is_string(path
)) {
84 fprintf(stderr
, "Expecting a string value for `path` parameter.\n");
88 ret
= bt_value_bool_get(path
, &path_str
);
90 g_string_assign(dmesg_comp
->params
.path
, path_str
);
92 if (!dmesg_comp
->params
.read_from_stdin
) {
93 fprintf(stderr
, "Expecting `path` parameter or `read-from-stdin` parameter set to true.\n");
104 bt_put(read_from_stdin
);
113 void destroy_dmesg_component(struct dmesg_component
*dmesg_comp
)
119 if (dmesg_comp
->params
.path
) {
120 g_string_free(dmesg_comp
->params
.path
, TRUE
);
123 bt_put(dmesg_comp
->packet
);
124 bt_put(dmesg_comp
->event_class
);
125 bt_put(dmesg_comp
->stream
);
126 bt_put(dmesg_comp
->cc_prio_map
);
131 enum bt_component_status
dmesg_init(struct bt_private_component
*priv_comp
,
132 struct bt_value
*params
, void *init_method_data
)
135 struct dmesg_component
*dmesg_comp
= g_new0(struct dmesg_component
, 1);
136 enum bt_component_status status
= BT_COMPONENT_STATUS_OK
;
142 dmesg_comp
->params
.path
= g_string_new(NULL
);
143 if (!dmesg_comp
->params
.path
) {
147 ret
= check_params(dmesg_comp
, params
);
157 destroy_dmesg_component(dmesg_comp
);
158 status
= BT_COMPONENT_STATUS_ERROR
;
165 void dmesg_finalize(struct bt_private_component
*priv_comp
)
171 enum bt_notification_iterator_status
dmesg_notif_iter_init(
172 struct bt_private_notification_iterator
*priv_notif_iter
,
173 struct bt_private_port
*priv_port
)
179 void dmesg_iterator_finalize(
180 struct bt_private_notification_iterator
*priv_notif_iter
)
186 struct bt_notification_iterator_next_return
dmesg_notif_iter_next(
187 struct bt_private_notification_iterator
*priv_notif_iter
)