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";
21 bt_component_class_get_supported_mip_versions_method_status
22 dummy_supported_mip_versions(
23 bt_self_component_class_sink
*self_component_class
__attribute__((unused
)),
24 const bt_value
*params
__attribute__((unused
)),
25 void *initialize_method_data
__attribute__((unused
)),
26 bt_logging_level logging_level
__attribute__((unused
)),
27 bt_integer_range_set_unsigned
*supported_versions
) {
28 return (int) bt_integer_range_set_unsigned_add_range(supported_versions
, 0, 1);
32 void destroy_private_dummy_data(struct dummy
*dummy
)
34 bt_message_iterator_put_ref(dummy
->msg_iter
);
39 void dummy_finalize(bt_self_component_sink
*comp
)
44 dummy
= bt_self_component_get_data(
45 bt_self_component_sink_as_self_component(comp
));
47 destroy_private_dummy_data(dummy
);
51 struct bt_param_validation_map_value_entry_descr dummy_params
[] = {
52 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
55 bt_component_class_initialize_method_status
dummy_init(
56 bt_self_component_sink
*self_comp_sink
,
57 bt_self_component_sink_configuration
*config
__attribute__((unused
)),
58 const bt_value
*params
,
59 void *init_method_data
__attribute__((unused
)))
61 bt_self_component
*self_comp
=
62 bt_self_component_sink_as_self_component(self_comp_sink
);
63 const bt_component
*comp
= bt_self_component_as_component(self_comp
);
64 bt_logging_level log_level
= bt_component_get_logging_level(comp
);
65 bt_component_class_initialize_method_status status
;
66 bt_self_component_add_port_status add_port_status
;
67 struct dummy
*dummy
= g_new0(struct dummy
, 1);
68 enum bt_param_validation_status validation_status
;
69 gchar
*validate_error
= NULL
;
72 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
76 validation_status
= bt_param_validation_validate(params
,
77 dummy_params
, &validate_error
);
78 if (validation_status
== BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR
) {
79 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR
;
81 } else if (validation_status
== BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR
) {
82 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR
;
83 BT_COMP_LOGE_APPEND_CAUSE(self_comp
, "%s", validate_error
);
87 add_port_status
= bt_self_component_sink_add_input_port(self_comp_sink
,
89 if (add_port_status
!= BT_SELF_COMPONENT_ADD_PORT_STATUS_OK
) {
90 status
= (int) add_port_status
;
94 bt_self_component_set_data(self_comp
, dummy
);
96 status
= BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK
;
100 destroy_private_dummy_data(dummy
);
103 g_free(validate_error
);
108 bt_component_class_sink_graph_is_configured_method_status
dummy_graph_is_configured(
109 bt_self_component_sink
*comp
)
111 bt_component_class_sink_graph_is_configured_method_status status
;
112 bt_message_iterator_create_from_sink_component_status
115 bt_message_iterator
*iterator
;
117 dummy
= bt_self_component_get_data(
118 bt_self_component_sink_as_self_component(comp
));
120 msg_iter_status
= bt_message_iterator_create_from_sink_component(
121 comp
, bt_self_component_sink_borrow_input_port_by_name(comp
,
122 in_port_name
), &iterator
);
123 if (msg_iter_status
!= BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK
) {
124 status
= (int) msg_iter_status
;
128 BT_MESSAGE_ITERATOR_MOVE_REF(
129 dummy
->msg_iter
, iterator
);
131 status
= BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK
;
137 bt_component_class_sink_consume_method_status
dummy_consume(
138 bt_self_component_sink
*component
)
140 bt_message_array_const msgs
;
143 bt_message_iterator_next_status next_status
;
145 bt_self_component
*self_comp
=
146 bt_self_component_sink_as_self_component(component
);
148 dummy
= bt_self_component_get_data(self_comp
);
149 BT_ASSERT_DBG(dummy
);
150 BT_ASSERT_DBG(dummy
->msg_iter
);
152 /* Consume one message */
153 next_status
= bt_message_iterator_next(
154 dummy
->msg_iter
, &msgs
, &count
);
155 switch (next_status
) {
156 case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK
:
157 for (i
= 0; i
< count
; i
++) {
158 bt_message_put_ref(msgs
[i
]);
162 case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR
:
163 case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR
:
164 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT(
166 "Failed to get messages from upstream component");
172 return (int) next_status
;