cleanup: fix incorrect gcc fallthrough warnings
[babeltrace.git] / src / plugins / utils / dummy / dummy.c
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
5 */
6
7#define BT_COMP_LOG_SELF_COMP self_comp
8#define BT_LOG_OUTPUT_LEVEL log_level
9#define BT_LOG_TAG "PLUGIN/SINK.UTILS.DUMMY"
10#include "logging/comp-logging.h"
11
12#include <babeltrace2/babeltrace.h>
13#include "common/macros.h"
14#include "common/assert.h"
15#include "dummy.h"
16#include "plugins/common/param-validation/param-validation.h"
17
18static
19const char * const in_port_name = "in";
20
21bt_component_class_get_supported_mip_versions_method_status
22dummy_supported_mip_versions(
23 bt_self_component_class_sink *self_component_class __attribute__((unused)),
24 const bt_value *params __attribute__((unused)),
25 void *initialize_method_data __attribute__((unused)),
26 bt_logging_level logging_level __attribute__((unused)),
27 bt_integer_range_set_unsigned *supported_versions) {
28 return (int) bt_integer_range_set_unsigned_add_range(supported_versions, 0, 1);
29}
30
31static
32void destroy_private_dummy_data(struct dummy *dummy)
33{
34 bt_message_iterator_put_ref(dummy->msg_iter);
35 g_free(dummy);
36
37}
38
39void dummy_finalize(bt_self_component_sink *comp)
40{
41 struct dummy *dummy;
42
43 BT_ASSERT(comp);
44 dummy = bt_self_component_get_data(
45 bt_self_component_sink_as_self_component(comp));
46 BT_ASSERT(dummy);
47 destroy_private_dummy_data(dummy);
48}
49
50static
51struct bt_param_validation_map_value_entry_descr dummy_params[] = {
52 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
53};
54
55bt_component_class_initialize_method_status dummy_init(
56 bt_self_component_sink *self_comp_sink,
57 bt_self_component_sink_configuration *config __attribute__((unused)),
58 const bt_value *params,
59 void *init_method_data __attribute__((unused)))
60{
61 bt_self_component *self_comp =
62 bt_self_component_sink_as_self_component(self_comp_sink);
63 const bt_component *comp = bt_self_component_as_component(self_comp);
64 bt_logging_level log_level = bt_component_get_logging_level(comp);
65 bt_component_class_initialize_method_status status;
66 bt_self_component_add_port_status add_port_status;
67 struct dummy *dummy = g_new0(struct dummy, 1);
68 enum bt_param_validation_status validation_status;
69 gchar *validate_error = NULL;
70
71 if (!dummy) {
72 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
73 goto end;
74 }
75
76 validation_status = bt_param_validation_validate(params,
77 dummy_params, &validate_error);
78 if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) {
79 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
80 goto error;
81 } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) {
82 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
83 BT_COMP_LOGE_APPEND_CAUSE(self_comp, "%s", validate_error);
84 goto error;
85 }
86
87 add_port_status = bt_self_component_sink_add_input_port(self_comp_sink,
88 "in", NULL, NULL);
89 if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) {
90 status = (int) add_port_status;
91 goto error;
92 }
93
94 bt_self_component_set_data(self_comp, dummy);
95
96 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
97 goto end;
98
99error:
100 destroy_private_dummy_data(dummy);
101
102end:
103 g_free(validate_error);
104
105 return status;
106}
107
108bt_component_class_sink_graph_is_configured_method_status dummy_graph_is_configured(
109 bt_self_component_sink *comp)
110{
111 bt_component_class_sink_graph_is_configured_method_status status;
112 bt_message_iterator_create_from_sink_component_status
113 msg_iter_status;
114 struct dummy *dummy;
115 bt_message_iterator *iterator;
116
117 dummy = bt_self_component_get_data(
118 bt_self_component_sink_as_self_component(comp));
119 BT_ASSERT(dummy);
120 msg_iter_status = bt_message_iterator_create_from_sink_component(
121 comp, bt_self_component_sink_borrow_input_port_by_name(comp,
122 in_port_name), &iterator);
123 if (msg_iter_status != BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
124 status = (int) msg_iter_status;
125 goto end;
126 }
127
128 BT_MESSAGE_ITERATOR_MOVE_REF(
129 dummy->msg_iter, iterator);
130
131 status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
132
133end:
134 return status;
135}
136
137bt_component_class_sink_consume_method_status dummy_consume(
138 bt_self_component_sink *component)
139{
140 bt_message_array_const msgs;
141 uint64_t count;
142 struct dummy *dummy;
143 bt_message_iterator_next_status next_status;
144 uint64_t i;
145 bt_self_component *self_comp =
146 bt_self_component_sink_as_self_component(component);
147
148 dummy = bt_self_component_get_data(self_comp);
149 BT_ASSERT_DBG(dummy);
150 BT_ASSERT_DBG(dummy->msg_iter);
151
152 /* Consume one message */
153 next_status = bt_message_iterator_next(
154 dummy->msg_iter, &msgs, &count);
155 switch (next_status) {
156 case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK:
157 for (i = 0; i < count; i++) {
158 bt_message_put_ref(msgs[i]);
159 }
160
161 break;
162 case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR:
163 case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
164 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT(
165 self_comp,
166 "Failed to get messages from upstream component");
167 break;
168 default:
169 break;
170 }
171
172 return (int) next_status;
173}
This page took 0.023883 seconds and 5 git commands to generate.