Commit | Line | Data |
---|---|---|
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 |
18 | static |
19 | const char * const in_port_name = "in"; | |
20 | ||
7c7301d5 | 21 | static |
c2b71c92 JG |
22 | void 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 | ||
d94d92ac | 29 | BT_HIDDEN |
b19ff26f | 30 | void dummy_finalize(bt_self_component_sink *comp) |
c2b71c92 JG |
31 | { |
32 | struct dummy *dummy; | |
33 | ||
d94d92ac PP |
34 | BT_ASSERT(comp); |
35 | dummy = bt_self_component_get_data( | |
707b7d35 | 36 | bt_self_component_sink_as_self_component(comp)); |
f6ccaed9 | 37 | BT_ASSERT(dummy); |
c2b71c92 JG |
38 | destroy_private_dummy_data(dummy); |
39 | } | |
40 | ||
d9120ccb | 41 | static |
b7045dd7 SM |
42 | struct bt_param_validation_map_value_entry_descr dummy_params[] = { |
43 | BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END | |
44 | }; | |
45 | ||
d94d92ac | 46 | BT_HIDDEN |
21a9f056 | 47 | bt_component_class_initialize_method_status dummy_init( |
b7045dd7 | 48 | bt_self_component_sink *self_comp_sink, |
59225a3e | 49 | bt_self_component_sink_configuration *config, |
b19ff26f | 50 | const bt_value *params, |
c88dd1cb | 51 | __attribute__((unused)) void *init_method_data) |
c2b71c92 | 52 | { |
b7045dd7 SM |
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; | |
d24d5663 | 58 | bt_self_component_add_port_status add_port_status; |
c2b71c92 | 59 | struct dummy *dummy = g_new0(struct dummy, 1); |
b7045dd7 SM |
60 | enum bt_param_validation_status validation_status; |
61 | gchar *validate_error = NULL; | |
c2b71c92 JG |
62 | |
63 | if (!dummy) { | |
21a9f056 | 64 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
c2b71c92 JG |
65 | goto end; |
66 | } | |
67 | ||
b7045dd7 SM |
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; | |
72 | goto error; | |
73 | } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) { | |
21a9f056 | 74 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; |
b7045dd7 | 75 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "%s", validate_error); |
c2b71c92 | 76 | goto error; |
b7045dd7 SM |
77 | } |
78 | ||
79 | add_port_status = bt_self_component_sink_add_input_port(self_comp_sink, | |
80 | "in", NULL, NULL); | |
81 | if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) { | |
82 | status = (int) add_port_status; | |
d24d5663 | 83 | goto error; |
c2b71c92 | 84 | } |
d19348b6 | 85 | |
b7045dd7 SM |
86 | bt_self_component_set_data(self_comp, dummy); |
87 | ||
88 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; | |
d19348b6 PP |
89 | goto end; |
90 | ||
c2b71c92 JG |
91 | error: |
92 | destroy_private_dummy_data(dummy); | |
d19348b6 PP |
93 | |
94 | end: | |
b7045dd7 SM |
95 | g_free(validate_error); |
96 | ||
d24d5663 | 97 | return status; |
c2b71c92 JG |
98 | } |
99 | ||
d94d92ac | 100 | BT_HIDDEN |
d24d5663 | 101 | bt_component_class_sink_graph_is_configured_method_status dummy_graph_is_configured( |
5badd463 | 102 | bt_self_component_sink *comp) |
c2b71c92 | 103 | { |
e803df70 | 104 | bt_component_class_sink_graph_is_configured_method_status status; |
9a2c8b8e | 105 | bt_message_iterator_create_from_sink_component_status |
e803df70 | 106 | msg_iter_status; |
c2b71c92 | 107 | struct dummy *dummy; |
9a2c8b8e | 108 | bt_message_iterator *iterator; |
c2b71c92 | 109 | |
d94d92ac | 110 | dummy = bt_self_component_get_data( |
707b7d35 | 111 | bt_self_component_sink_as_self_component(comp)); |
f6ccaed9 | 112 | BT_ASSERT(dummy); |
9a2c8b8e | 113 | msg_iter_status = bt_message_iterator_create_from_sink_component( |
ca02df0a | 114 | comp, bt_self_component_sink_borrow_input_port_by_name(comp, |
e803df70 | 115 | in_port_name), &iterator); |
9a2c8b8e | 116 | if (msg_iter_status != BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) { |
e803df70 | 117 | status = (int) msg_iter_status; |
c2b71c92 JG |
118 | goto end; |
119 | } | |
120 | ||
9a2c8b8e | 121 | BT_MESSAGE_ITERATOR_MOVE_REF( |
d6e69534 | 122 | dummy->msg_iter, iterator); |
0d8b4d8e | 123 | |
e803df70 SM |
124 | status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK; |
125 | ||
c2b71c92 | 126 | end: |
bf55043c | 127 | return status; |
c2b71c92 | 128 | } |
e0dfa761 | 129 | |
d94d92ac | 130 | BT_HIDDEN |
d24d5663 | 131 | bt_component_class_sink_consume_method_status dummy_consume( |
b19ff26f | 132 | bt_self_component_sink *component) |
e0dfa761 | 133 | { |
d24d5663 PP |
134 | bt_component_class_sink_consume_method_status status = |
135 | BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; | |
d6e69534 | 136 | bt_message_array_const msgs; |
d4393e08 | 137 | uint64_t count; |
c2b71c92 | 138 | struct dummy *dummy; |
d24d5663 | 139 | bt_message_iterator_next_status next_status; |
d4393e08 | 140 | uint64_t i; |
e0dfa761 | 141 | |
d94d92ac | 142 | dummy = bt_self_component_get_data( |
707b7d35 | 143 | bt_self_component_sink_as_self_component(component)); |
98b15851 | 144 | BT_ASSERT_DBG(dummy); |
e0dfa761 | 145 | |
91d81473 | 146 | if (G_UNLIKELY(!dummy->msg_iter)) { |
d24d5663 | 147 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END; |
d19348b6 | 148 | goto end; |
e0dfa761 PP |
149 | } |
150 | ||
d6e69534 | 151 | /* Consume one message */ |
9a2c8b8e | 152 | next_status = bt_message_iterator_next( |
d6e69534 | 153 | dummy->msg_iter, &msgs, &count); |
d24d5663 PP |
154 | switch (next_status) { |
155 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK: | |
156 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; | |
d4393e08 PP |
157 | |
158 | for (i = 0; i < count; i++) { | |
d6e69534 | 159 | bt_message_put_ref(msgs[i]); |
d4393e08 PP |
160 | } |
161 | ||
162 | break; | |
d24d5663 PP |
163 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN: |
164 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN; | |
d19348b6 | 165 | goto end; |
d24d5663 PP |
166 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_END: |
167 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END; | |
d19348b6 | 168 | goto end; |
d24d5663 PP |
169 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR: |
170 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; | |
d94d92ac | 171 | goto end; |
d24d5663 PP |
172 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR: |
173 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR; | |
d4393e08 | 174 | goto end; |
d19348b6 PP |
175 | default: |
176 | break; | |
e0dfa761 | 177 | } |
d19348b6 | 178 | |
e0dfa761 | 179 | end: |
d24d5663 | 180 | return status; |
e0dfa761 | 181 | } |