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
);
30 void dummy_finalize(bt_self_component_sink
*comp
)
35 dummy
= bt_self_component_get_data(
36 bt_self_component_sink_as_self_component(comp
));
38 destroy_private_dummy_data(dummy
);
42 struct bt_param_validation_map_value_entry_descr dummy_params
[] = {
43 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
47 bt_component_class_initialize_method_status
dummy_init(
48 bt_self_component_sink
*self_comp_sink
,
49 bt_self_component_sink_configuration
*config
,
50 const bt_value
*params
,
51 __attribute__((unused
)) void *init_method_data
)
53 bt_self_component
*self_comp
=
54 bt_self_component_sink_as_self_component(self_comp_sink
);
55 const bt_component
*comp
= bt_self_component_as_component(self_comp
);
56 bt_logging_level log_level
= bt_component_get_logging_level(comp
);
57 bt_component_class_initialize_method_status status
;
58 bt_self_component_add_port_status add_port_status
;
59 struct dummy
*dummy
= g_new0(struct dummy
, 1);
60 enum bt_param_validation_status validation_status
;
61 gchar
*validate_error
= NULL
;
64 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
68 validation_status
= bt_param_validation_validate(params
,
69 dummy_params
, &validate_error
);
70 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
71 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
73 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
74 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
75 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "%s", validate_error
);
79 add_port_status
= bt_self_component_sink_add_input_port(self_comp_sink
,
81 if (add_port_status
!= BT_SELF_COMPONENT_ADD_PORT_STATUS_OK
) {
82 status
= (int) add_port_status
;
86 bt_self_component_set_data(self_comp
, dummy
);
88 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
92 destroy_private_dummy_data(dummy
);
95 g_free(validate_error
);
101 bt_component_class_sink_graph_is_configured_method_status
dummy_graph_is_configured(
102 bt_self_component_sink
*comp
)
104 bt_component_class_sink_graph_is_configured_method_status status
;
105 bt_message_iterator_create_from_sink_component_status
108 bt_message_iterator
*iterator
;
110 dummy
= bt_self_component_get_data(
111 bt_self_component_sink_as_self_component(comp
));
113 msg_iter_status
= bt_message_iterator_create_from_sink_component(
114 comp
, bt_self_component_sink_borrow_input_port_by_name(comp
,
115 in_port_name
), &iterator
);
116 if (msg_iter_status
!= BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK
) {
117 status
= (int) msg_iter_status
;
121 BT_MESSAGE_ITERATOR_MOVE_REF(
122 dummy
->msg_iter
, iterator
);
124 status
= BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK
;
131 bt_component_class_sink_consume_method_status
dummy_consume(
132 bt_self_component_sink
*component
)
134 bt_component_class_sink_consume_method_status status
=
135 BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK
;
136 bt_message_array_const msgs
;
139 bt_message_iterator_next_status next_status
;
142 dummy
= bt_self_component_get_data(
143 bt_self_component_sink_as_self_component(component
));
144 BT_ASSERT_DBG(dummy
);
146 if (G_UNLIKELY(!dummy
->msg_iter
)) {
147 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END
;
151 /* Consume one message */
152 next_status
= bt_message_iterator_next(
153 dummy
->msg_iter
, &msgs
, &count
);
154 switch (next_status
) {
155 case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK
:
156 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK
;
158 for (i
= 0; i
< count
; i
++) {
159 bt_message_put_ref(msgs
[i
]);
163 case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN
:
164 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN
;
166 case BT_MESSAGE_ITERATOR_NEXT_STATUS_END
:
167 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END
;
169 case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR
:
170 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR
;
172 case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR
:
173 status
= BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR
;