2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
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"
28 #include <babeltrace2/babeltrace.h>
29 #include "common/macros.h"
30 #include "common/assert.h"
32 #include "plugins/common/param-validation/param-validation.h"
35 const char * const in_port_name
= "in";
38 void destroy_private_dummy_data(struct dummy
*dummy
)
40 bt_self_component_port_input_message_iterator_put_ref(dummy
->msg_iter
);
46 void dummy_finalize(bt_self_component_sink
*comp
)
51 dummy
= bt_self_component_get_data(
52 bt_self_component_sink_as_self_component(comp
));
54 destroy_private_dummy_data(dummy
);
58 struct bt_param_validation_map_value_entry_descr dummy_params
[] = {
59 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
63 bt_component_class_initialize_method_status
dummy_init(
64 bt_self_component_sink
*self_comp_sink
,
65 bt_self_component_sink_configuration
*config
,
66 const bt_value
*params
,
67 __attribute__((unused
)) void *init_method_data
)
69 bt_self_component
*self_comp
=
70 bt_self_component_sink_as_self_component(self_comp_sink
);
71 const bt_component
*comp
= bt_self_component_as_component(self_comp
);
72 bt_logging_level log_level
= bt_component_get_logging_level(comp
);
73 bt_component_class_initialize_method_status status
;
74 bt_self_component_add_port_status add_port_status
;
75 struct dummy
*dummy
= g_new0(struct dummy
, 1);
76 enum bt_param_validation_status validation_status
;
77 gchar
*validate_error
= NULL
;
80 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
84 validation_status
= bt_param_validation_validate(params
,
85 dummy_params
, &validate_error
);
86 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
87 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
89 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
90 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
91 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "%s", validate_error
);
95 add_port_status
= bt_self_component_sink_add_input_port(self_comp_sink
,
97 if (add_port_status
!= BT_SELF_COMPONENT_ADD_PORT_STATUS_OK
) {
98 status
= (int) add_port_status
;
102 bt_self_component_set_data(self_comp
, dummy
);
104 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
108 destroy_private_dummy_data(dummy
);
111 g_free(validate_error
);
117 bt_component_class_sink_graph_is_configured_method_status
dummy_graph_is_configured(
118 bt_self_component_sink
*comp
)
120 bt_component_class_sink_graph_is_configured_method_status status
;
121 bt_self_component_port_input_message_iterator_create_from_sink_component_status
124 bt_self_component_port_input_message_iterator
*iterator
;
126 dummy
= bt_self_component_get_data(
127 bt_self_component_sink_as_self_component(comp
));
129 msg_iter_status
= bt_self_component_port_input_message_iterator_create_from_sink_component(
130 comp
, bt_self_component_sink_borrow_input_port_by_name(comp
,
131 in_port_name
), &iterator
);
132 if (msg_iter_status
!= BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK
) {
133 status
= (int) msg_iter_status
;
137 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
138 dummy
->msg_iter
, iterator
);
140 status
= BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK
;
147 bt_component_class_sink_consume_method_status
dummy_consume(
148 bt_self_component_sink
*component
)
150 bt_component_class_sink_consume_method_status status
=
151 BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK
;
152 bt_message_array_const msgs
;
155 bt_message_iterator_next_status next_status
;
158 dummy
= bt_self_component_get_data(
159 bt_self_component_sink_as_self_component(component
));
160 BT_ASSERT_DBG(dummy
);
162 if (G_UNLIKELY(!dummy
->msg_iter
)) {
163 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END
;
167 /* Consume one message */
168 next_status
= bt_self_component_port_input_message_iterator_next(
169 dummy
->msg_iter
, &msgs
, &count
);
170 switch (next_status
) {
171 case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK
:
172 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK
;
174 for (i
= 0; i
< count
; i
++) {
175 bt_message_put_ref(msgs
[i
]);
179 case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN
:
180 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN
;
182 case BT_MESSAGE_ITERATOR_NEXT_STATUS_END
:
183 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END
;
185 case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR
:
186 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR
;
188 case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR
:
189 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR
;