2 * SPDX-License-Identifier: MIT
4 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
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"
12 #include <babeltrace2/babeltrace.h>
13 #include "common/macros.h"
14 #include "common/assert.h"
16 #include "plugins/common/param-validation/param-validation.h"
19 const char * const in_port_name
= "in";
22 void destroy_private_dummy_data(struct dummy
*dummy
)
24 bt_message_iterator_put_ref(dummy
->msg_iter
);
29 void dummy_finalize(bt_self_component_sink
*comp
)
34 dummy
= bt_self_component_get_data(
35 bt_self_component_sink_as_self_component(comp
));
37 destroy_private_dummy_data(dummy
);
41 struct bt_param_validation_map_value_entry_descr dummy_params
[] = {
42 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
45 bt_component_class_initialize_method_status
dummy_init(
46 bt_self_component_sink
*self_comp_sink
,
47 bt_self_component_sink_configuration
*config
__attribute__((unused
)),
48 const bt_value
*params
,
49 void *init_method_data
__attribute__((unused
)))
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
;
56 bt_self_component_add_port_status add_port_status
;
57 struct dummy
*dummy
= g_new0(struct dummy
, 1);
58 enum bt_param_validation_status validation_status
;
59 gchar
*validate_error
= NULL
;
62 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
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
;
71 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
72 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
73 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "%s", validate_error
);
77 add_port_status
= bt_self_component_sink_add_input_port(self_comp_sink
,
79 if (add_port_status
!= BT_SELF_COMPONENT_ADD_PORT_STATUS_OK
) {
80 status
= (int) add_port_status
;
84 bt_self_component_set_data(self_comp
, dummy
);
86 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
90 destroy_private_dummy_data(dummy
);
93 g_free(validate_error
);
98 bt_component_class_sink_graph_is_configured_method_status
dummy_graph_is_configured(
99 bt_self_component_sink
*comp
)
101 bt_component_class_sink_graph_is_configured_method_status status
;
102 bt_message_iterator_create_from_sink_component_status
105 bt_message_iterator
*iterator
;
107 dummy
= bt_self_component_get_data(
108 bt_self_component_sink_as_self_component(comp
));
110 msg_iter_status
= bt_message_iterator_create_from_sink_component(
111 comp
, bt_self_component_sink_borrow_input_port_by_name(comp
,
112 in_port_name
), &iterator
);
113 if (msg_iter_status
!= BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK
) {
114 status
= (int) msg_iter_status
;
118 BT_MESSAGE_ITERATOR_MOVE_REF(
119 dummy
->msg_iter
, iterator
);
121 status
= BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK
;
127 bt_component_class_sink_consume_method_status
dummy_consume(
128 bt_self_component_sink
*component
)
130 bt_component_class_sink_consume_method_status status
;
131 bt_message_array_const msgs
;
134 bt_message_iterator_next_status next_status
;
136 bt_self_component
*self_comp
=
137 bt_self_component_sink_as_self_component(component
);
139 dummy
= bt_self_component_get_data(self_comp
);
140 BT_ASSERT_DBG(dummy
);
142 if (G_UNLIKELY(!dummy
->msg_iter
)) {
143 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END
;
147 /* Consume one message */
148 next_status
= bt_message_iterator_next(
149 dummy
->msg_iter
, &msgs
, &count
);
150 switch (next_status
) {
151 case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK
:
152 for (i
= 0; i
< count
; i
++) {
153 bt_message_put_ref(msgs
[i
]);
157 case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR
:
158 case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR
:
159 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT(
161 "Failed to get messages from upstream component");
167 status
= (int) next_status
;