configure: re-enable '-Wunused-parameter'
[babeltrace.git] / src / plugins / utils / dummy / dummy.c
CommitLineData
e0dfa761 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
e0dfa761 3 *
0235b0db 4 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
e0dfa761
PP
5 */
6
b7045dd7
SM
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
3fadfbc0 12#include <babeltrace2/babeltrace.h>
91d81473 13#include "common/macros.h"
578e048b 14#include "common/assert.h"
c2b71c92 15#include "dummy.h"
b7045dd7 16#include "plugins/common/param-validation/param-validation.h"
c2b71c92 17
5badd463
PP
18static
19const char * const in_port_name = "in";
20
7c7301d5 21static
c2b71c92
JG
22void destroy_private_dummy_data(struct dummy *dummy)
23{
9a2c8b8e 24 bt_message_iterator_put_ref(dummy->msg_iter);
c2b71c92 25 g_free(dummy);
d94d92ac 26
c2b71c92
JG
27}
28
b19ff26f 29void dummy_finalize(bt_self_component_sink *comp)
c2b71c92
JG
30{
31 struct dummy *dummy;
32
d94d92ac
PP
33 BT_ASSERT(comp);
34 dummy = bt_self_component_get_data(
707b7d35 35 bt_self_component_sink_as_self_component(comp));
f6ccaed9 36 BT_ASSERT(dummy);
c2b71c92
JG
37 destroy_private_dummy_data(dummy);
38}
39
d9120ccb 40static
b7045dd7
SM
41struct bt_param_validation_map_value_entry_descr dummy_params[] = {
42 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
43};
44
21a9f056 45bt_component_class_initialize_method_status dummy_init(
b7045dd7 46 bt_self_component_sink *self_comp_sink,
ecd7492f 47 bt_self_component_sink_configuration *config __attribute__((unused)),
b19ff26f 48 const bt_value *params,
ecd7492f 49 void *init_method_data __attribute__((unused)))
c2b71c92 50{
b7045dd7
SM
51 bt_self_component *self_comp =
52 bt_self_component_sink_as_self_component(self_comp_sink);
53 const bt_component *comp = bt_self_component_as_component(self_comp);
54 bt_logging_level log_level = bt_component_get_logging_level(comp);
55 bt_component_class_initialize_method_status status;
d24d5663 56 bt_self_component_add_port_status add_port_status;
c2b71c92 57 struct dummy *dummy = g_new0(struct dummy, 1);
b7045dd7
SM
58 enum bt_param_validation_status validation_status;
59 gchar *validate_error = NULL;
c2b71c92
JG
60
61 if (!dummy) {
21a9f056 62 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
c2b71c92
JG
63 goto end;
64 }
65
b7045dd7
SM
66 validation_status = bt_param_validation_validate(params,
67 dummy_params, &validate_error);
68 if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) {
69 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
70 goto error;
71 } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) {
21a9f056 72 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
b7045dd7 73 BT_COMP_LOGE_APPEND_CAUSE(self_comp, "%s", validate_error);
c2b71c92 74 goto error;
b7045dd7
SM
75 }
76
77 add_port_status = bt_self_component_sink_add_input_port(self_comp_sink,
78 "in", NULL, NULL);
79 if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) {
80 status = (int) add_port_status;
d24d5663 81 goto error;
c2b71c92 82 }
d19348b6 83
b7045dd7
SM
84 bt_self_component_set_data(self_comp, dummy);
85
86 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
d19348b6
PP
87 goto end;
88
c2b71c92
JG
89error:
90 destroy_private_dummy_data(dummy);
d19348b6
PP
91
92end:
b7045dd7
SM
93 g_free(validate_error);
94
d24d5663 95 return status;
c2b71c92
JG
96}
97
d24d5663 98bt_component_class_sink_graph_is_configured_method_status dummy_graph_is_configured(
5badd463 99 bt_self_component_sink *comp)
c2b71c92 100{
e803df70 101 bt_component_class_sink_graph_is_configured_method_status status;
9a2c8b8e 102 bt_message_iterator_create_from_sink_component_status
e803df70 103 msg_iter_status;
c2b71c92 104 struct dummy *dummy;
9a2c8b8e 105 bt_message_iterator *iterator;
c2b71c92 106
d94d92ac 107 dummy = bt_self_component_get_data(
707b7d35 108 bt_self_component_sink_as_self_component(comp));
f6ccaed9 109 BT_ASSERT(dummy);
9a2c8b8e 110 msg_iter_status = bt_message_iterator_create_from_sink_component(
ca02df0a 111 comp, bt_self_component_sink_borrow_input_port_by_name(comp,
e803df70 112 in_port_name), &iterator);
9a2c8b8e 113 if (msg_iter_status != BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
e803df70 114 status = (int) msg_iter_status;
c2b71c92
JG
115 goto end;
116 }
117
9a2c8b8e 118 BT_MESSAGE_ITERATOR_MOVE_REF(
d6e69534 119 dummy->msg_iter, iterator);
0d8b4d8e 120
e803df70
SM
121 status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
122
c2b71c92 123end:
bf55043c 124 return status;
c2b71c92 125}
e0dfa761 126
d24d5663 127bt_component_class_sink_consume_method_status dummy_consume(
b19ff26f 128 bt_self_component_sink *component)
e0dfa761 129{
d24d5663
PP
130 bt_component_class_sink_consume_method_status status =
131 BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
d6e69534 132 bt_message_array_const msgs;
d4393e08 133 uint64_t count;
c2b71c92 134 struct dummy *dummy;
d24d5663 135 bt_message_iterator_next_status next_status;
d4393e08 136 uint64_t i;
e0dfa761 137
d94d92ac 138 dummy = bt_self_component_get_data(
707b7d35 139 bt_self_component_sink_as_self_component(component));
98b15851 140 BT_ASSERT_DBG(dummy);
e0dfa761 141
91d81473 142 if (G_UNLIKELY(!dummy->msg_iter)) {
d24d5663 143 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END;
d19348b6 144 goto end;
e0dfa761
PP
145 }
146
d6e69534 147 /* Consume one message */
9a2c8b8e 148 next_status = bt_message_iterator_next(
d6e69534 149 dummy->msg_iter, &msgs, &count);
d24d5663
PP
150 switch (next_status) {
151 case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK:
152 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
d4393e08
PP
153
154 for (i = 0; i < count; i++) {
d6e69534 155 bt_message_put_ref(msgs[i]);
d4393e08
PP
156 }
157
158 break;
d24d5663
PP
159 case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN:
160 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN;
d19348b6 161 goto end;
d24d5663
PP
162 case BT_MESSAGE_ITERATOR_NEXT_STATUS_END:
163 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END;
d19348b6 164 goto end;
d24d5663
PP
165 case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR:
166 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
d94d92ac 167 goto end;
d24d5663
PP
168 case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
169 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR;
d4393e08 170 goto end;
d19348b6
PP
171 default:
172 break;
e0dfa761 173 }
d19348b6 174
e0dfa761 175end:
d24d5663 176 return status;
e0dfa761 177}
This page took 0.094299 seconds and 4 git commands to generate.