Fix -Wmissing-prototypes/-Wmissing-declarations warnings
[babeltrace.git] / src / plugins / utils / dummy / dummy.c
CommitLineData
e0dfa761
PP
1/*
2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
92962796
SM
23#define BT_COMP_LOG_SELF_COMP self_comp
24#define BT_LOG_OUTPUT_LEVEL log_level
25#define BT_LOG_TAG "PLUGIN/SINK.UTILS.DUMMY"
26#include "logging/comp-logging.h"
27
71c5da58 28#include <babeltrace2/babeltrace.h>
85e7137b 29#include "common/macros.h"
57952005 30#include "common/assert.h"
c2b71c92 31#include "dummy.h"
92962796 32#include "plugins/common/param-validation/param-validation.h"
c2b71c92 33
1043fdea
PP
34static
35const char * const in_port_name = "in";
36
f3847c75 37static
c2b71c92
JG
38void destroy_private_dummy_data(struct dummy *dummy)
39{
b09a5592 40 bt_self_component_port_input_message_iterator_put_ref(dummy->msg_iter);
c2b71c92 41 g_free(dummy);
834e9996 42
c2b71c92
JG
43}
44
834e9996 45BT_HIDDEN
8eee8ea2 46void dummy_finalize(bt_self_component_sink *comp)
c2b71c92
JG
47{
48 struct dummy *dummy;
49
834e9996
PP
50 BT_ASSERT(comp);
51 dummy = bt_self_component_get_data(
bb61965b 52 bt_self_component_sink_as_self_component(comp));
8b45963b 53 BT_ASSERT(dummy);
c2b71c92
JG
54 destroy_private_dummy_data(dummy);
55}
56
92962796
SM
57struct bt_param_validation_map_value_entry_descr dummy_params[] = {
58 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
59};
60
834e9996 61BT_HIDDEN
4175c1d5 62bt_component_class_initialize_method_status dummy_init(
92962796 63 bt_self_component_sink *self_comp_sink,
e3250e61 64 bt_self_component_sink_configuration *config,
8eee8ea2 65 const bt_value *params,
f807570c 66 __attribute__((unused)) void *init_method_data)
c2b71c92 67{
92962796
SM
68 bt_self_component *self_comp =
69 bt_self_component_sink_as_self_component(self_comp_sink);
70 const bt_component *comp = bt_self_component_as_component(self_comp);
71 bt_logging_level log_level = bt_component_get_logging_level(comp);
72 bt_component_class_initialize_method_status status;
fb25b9e3 73 bt_self_component_add_port_status add_port_status;
c2b71c92 74 struct dummy *dummy = g_new0(struct dummy, 1);
92962796
SM
75 enum bt_param_validation_status validation_status;
76 gchar *validate_error = NULL;
c2b71c92
JG
77
78 if (!dummy) {
4175c1d5 79 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
c2b71c92
JG
80 goto end;
81 }
82
92962796
SM
83 validation_status = bt_param_validation_validate(params,
84 dummy_params, &validate_error);
85 if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) {
86 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
87 goto error;
88 } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) {
4175c1d5 89 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
92962796 90 BT_COMP_LOGE_APPEND_CAUSE(self_comp, "%s", validate_error);
c2b71c92 91 goto error;
92962796
SM
92 }
93
94 add_port_status = bt_self_component_sink_add_input_port(self_comp_sink,
95 "in", NULL, NULL);
96 if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) {
97 status = (int) add_port_status;
fb25b9e3 98 goto error;
c2b71c92 99 }
d83d78e7 100
92962796
SM
101 bt_self_component_set_data(self_comp, dummy);
102
103 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
d83d78e7
PP
104 goto end;
105
c2b71c92
JG
106error:
107 destroy_private_dummy_data(dummy);
d83d78e7
PP
108
109end:
92962796
SM
110 g_free(validate_error);
111
fb25b9e3 112 return status;
c2b71c92
JG
113}
114
834e9996 115BT_HIDDEN
fb25b9e3 116bt_component_class_sink_graph_is_configured_method_status dummy_graph_is_configured(
1043fdea 117 bt_self_component_sink *comp)
c2b71c92 118{
ab8b2b1b
SM
119 bt_component_class_sink_graph_is_configured_method_status status;
120 bt_self_component_port_input_message_iterator_create_from_sink_component_status
121 msg_iter_status;
c2b71c92 122 struct dummy *dummy;
b09a5592 123 bt_self_component_port_input_message_iterator *iterator;
c2b71c92 124
834e9996 125 dummy = bt_self_component_get_data(
bb61965b 126 bt_self_component_sink_as_self_component(comp));
8b45963b 127 BT_ASSERT(dummy);
ab8b2b1b 128 msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component(
692f1a01 129 comp, bt_self_component_sink_borrow_input_port_by_name(comp,
ab8b2b1b
SM
130 in_port_name), &iterator);
131 if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
132 status = (int) msg_iter_status;
c2b71c92
JG
133 goto end;
134 }
135
b09a5592
PP
136 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
137 dummy->msg_iter, iterator);
0d8b4d8e 138
ab8b2b1b
SM
139 status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
140
c2b71c92 141end:
634f394c 142 return status;
c2b71c92 143}
e0dfa761 144
834e9996 145BT_HIDDEN
fb25b9e3 146bt_component_class_sink_consume_method_status dummy_consume(
8eee8ea2 147 bt_self_component_sink *component)
e0dfa761 148{
fb25b9e3
PP
149 bt_component_class_sink_consume_method_status status =
150 BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
b09a5592 151 bt_message_array_const msgs;
3fd7b79d 152 uint64_t count;
c2b71c92 153 struct dummy *dummy;
fb25b9e3 154 bt_message_iterator_next_status next_status;
3fd7b79d 155 uint64_t i;
e0dfa761 156
834e9996 157 dummy = bt_self_component_get_data(
bb61965b 158 bt_self_component_sink_as_self_component(component));
ec4a3354 159 BT_ASSERT_DBG(dummy);
e0dfa761 160
85e7137b 161 if (G_UNLIKELY(!dummy->msg_iter)) {
fb25b9e3 162 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END;
d83d78e7 163 goto end;
e0dfa761
PP
164 }
165
b09a5592 166 /* Consume one message */
fb25b9e3 167 next_status = bt_self_component_port_input_message_iterator_next(
b09a5592 168 dummy->msg_iter, &msgs, &count);
fb25b9e3
PP
169 switch (next_status) {
170 case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK:
171 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
3fd7b79d
PP
172
173 for (i = 0; i < count; i++) {
b09a5592 174 bt_message_put_ref(msgs[i]);
3fd7b79d
PP
175 }
176
177 break;
fb25b9e3
PP
178 case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN:
179 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN;
d83d78e7 180 goto end;
fb25b9e3
PP
181 case BT_MESSAGE_ITERATOR_NEXT_STATUS_END:
182 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END;
d83d78e7 183 goto end;
fb25b9e3
PP
184 case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR:
185 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
834e9996 186 goto end;
fb25b9e3
PP
187 case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
188 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR;
3fd7b79d 189 goto end;
d83d78e7
PP
190 default:
191 break;
e0dfa761 192 }
d83d78e7 193
e0dfa761 194end:
fb25b9e3 195 return status;
e0dfa761 196}
This page took 0.059001 seconds and 4 git commands to generate.