Commit | Line | Data |
---|---|---|
e0dfa761 PP |
1 | /* |
2 | * Copyright 2017 Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
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: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
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 | |
20 | * SOFTWARE. | |
21 | */ | |
22 | ||
b7045dd7 SM |
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" | |
27 | ||
3fadfbc0 | 28 | #include <babeltrace2/babeltrace.h> |
91d81473 | 29 | #include "common/macros.h" |
578e048b | 30 | #include "common/assert.h" |
c2b71c92 | 31 | #include "dummy.h" |
b7045dd7 | 32 | #include "plugins/common/param-validation/param-validation.h" |
c2b71c92 | 33 | |
5badd463 PP |
34 | static |
35 | const char * const in_port_name = "in"; | |
36 | ||
7c7301d5 | 37 | static |
c2b71c92 JG |
38 | void destroy_private_dummy_data(struct dummy *dummy) |
39 | { | |
d6e69534 | 40 | bt_self_component_port_input_message_iterator_put_ref(dummy->msg_iter); |
c2b71c92 | 41 | g_free(dummy); |
d94d92ac | 42 | |
c2b71c92 JG |
43 | } |
44 | ||
d94d92ac | 45 | BT_HIDDEN |
b19ff26f | 46 | void dummy_finalize(bt_self_component_sink *comp) |
c2b71c92 JG |
47 | { |
48 | struct dummy *dummy; | |
49 | ||
d94d92ac PP |
50 | BT_ASSERT(comp); |
51 | dummy = bt_self_component_get_data( | |
707b7d35 | 52 | bt_self_component_sink_as_self_component(comp)); |
f6ccaed9 | 53 | BT_ASSERT(dummy); |
c2b71c92 JG |
54 | destroy_private_dummy_data(dummy); |
55 | } | |
56 | ||
d9120ccb | 57 | static |
b7045dd7 SM |
58 | struct bt_param_validation_map_value_entry_descr dummy_params[] = { |
59 | BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END | |
60 | }; | |
61 | ||
d94d92ac | 62 | BT_HIDDEN |
21a9f056 | 63 | bt_component_class_initialize_method_status dummy_init( |
b7045dd7 | 64 | bt_self_component_sink *self_comp_sink, |
59225a3e | 65 | bt_self_component_sink_configuration *config, |
b19ff26f | 66 | const bt_value *params, |
c88dd1cb | 67 | __attribute__((unused)) void *init_method_data) |
c2b71c92 | 68 | { |
b7045dd7 SM |
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; | |
d24d5663 | 74 | bt_self_component_add_port_status add_port_status; |
c2b71c92 | 75 | struct dummy *dummy = g_new0(struct dummy, 1); |
b7045dd7 SM |
76 | enum bt_param_validation_status validation_status; |
77 | gchar *validate_error = NULL; | |
c2b71c92 JG |
78 | |
79 | if (!dummy) { | |
21a9f056 | 80 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
c2b71c92 JG |
81 | goto end; |
82 | } | |
83 | ||
b7045dd7 SM |
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; | |
88 | goto error; | |
89 | } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) { | |
21a9f056 | 90 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; |
b7045dd7 | 91 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "%s", validate_error); |
c2b71c92 | 92 | goto error; |
b7045dd7 SM |
93 | } |
94 | ||
95 | add_port_status = bt_self_component_sink_add_input_port(self_comp_sink, | |
96 | "in", NULL, NULL); | |
97 | if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) { | |
98 | status = (int) add_port_status; | |
d24d5663 | 99 | goto error; |
c2b71c92 | 100 | } |
d19348b6 | 101 | |
b7045dd7 SM |
102 | bt_self_component_set_data(self_comp, dummy); |
103 | ||
104 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; | |
d19348b6 PP |
105 | goto end; |
106 | ||
c2b71c92 JG |
107 | error: |
108 | destroy_private_dummy_data(dummy); | |
d19348b6 PP |
109 | |
110 | end: | |
b7045dd7 SM |
111 | g_free(validate_error); |
112 | ||
d24d5663 | 113 | return status; |
c2b71c92 JG |
114 | } |
115 | ||
d94d92ac | 116 | BT_HIDDEN |
d24d5663 | 117 | bt_component_class_sink_graph_is_configured_method_status dummy_graph_is_configured( |
5badd463 | 118 | bt_self_component_sink *comp) |
c2b71c92 | 119 | { |
e803df70 SM |
120 | bt_component_class_sink_graph_is_configured_method_status status; |
121 | bt_self_component_port_input_message_iterator_create_from_sink_component_status | |
122 | msg_iter_status; | |
c2b71c92 | 123 | struct dummy *dummy; |
d6e69534 | 124 | bt_self_component_port_input_message_iterator *iterator; |
c2b71c92 | 125 | |
d94d92ac | 126 | dummy = bt_self_component_get_data( |
707b7d35 | 127 | bt_self_component_sink_as_self_component(comp)); |
f6ccaed9 | 128 | BT_ASSERT(dummy); |
e803df70 | 129 | msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component( |
ca02df0a | 130 | comp, bt_self_component_sink_borrow_input_port_by_name(comp, |
e803df70 SM |
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; | |
c2b71c92 JG |
134 | goto end; |
135 | } | |
136 | ||
d6e69534 PP |
137 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF( |
138 | dummy->msg_iter, iterator); | |
0d8b4d8e | 139 | |
e803df70 SM |
140 | status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK; |
141 | ||
c2b71c92 | 142 | end: |
bf55043c | 143 | return status; |
c2b71c92 | 144 | } |
e0dfa761 | 145 | |
d94d92ac | 146 | BT_HIDDEN |
d24d5663 | 147 | bt_component_class_sink_consume_method_status dummy_consume( |
b19ff26f | 148 | bt_self_component_sink *component) |
e0dfa761 | 149 | { |
d24d5663 PP |
150 | bt_component_class_sink_consume_method_status status = |
151 | BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; | |
d6e69534 | 152 | bt_message_array_const msgs; |
d4393e08 | 153 | uint64_t count; |
c2b71c92 | 154 | struct dummy *dummy; |
d24d5663 | 155 | bt_message_iterator_next_status next_status; |
d4393e08 | 156 | uint64_t i; |
e0dfa761 | 157 | |
d94d92ac | 158 | dummy = bt_self_component_get_data( |
707b7d35 | 159 | bt_self_component_sink_as_self_component(component)); |
98b15851 | 160 | BT_ASSERT_DBG(dummy); |
e0dfa761 | 161 | |
91d81473 | 162 | if (G_UNLIKELY(!dummy->msg_iter)) { |
d24d5663 | 163 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END; |
d19348b6 | 164 | goto end; |
e0dfa761 PP |
165 | } |
166 | ||
d6e69534 | 167 | /* Consume one message */ |
d24d5663 | 168 | next_status = bt_self_component_port_input_message_iterator_next( |
d6e69534 | 169 | dummy->msg_iter, &msgs, &count); |
d24d5663 PP |
170 | switch (next_status) { |
171 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK: | |
172 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; | |
d4393e08 PP |
173 | |
174 | for (i = 0; i < count; i++) { | |
d6e69534 | 175 | bt_message_put_ref(msgs[i]); |
d4393e08 PP |
176 | } |
177 | ||
178 | break; | |
d24d5663 PP |
179 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN: |
180 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN; | |
d19348b6 | 181 | goto end; |
d24d5663 PP |
182 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_END: |
183 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END; | |
d19348b6 | 184 | goto end; |
d24d5663 PP |
185 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR: |
186 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; | |
d94d92ac | 187 | goto end; |
d24d5663 PP |
188 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR: |
189 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR; | |
d4393e08 | 190 | goto end; |
d19348b6 PP |
191 | default: |
192 | break; | |
e0dfa761 | 193 | } |
d19348b6 | 194 | |
e0dfa761 | 195 | end: |
d24d5663 | 196 | return status; |
e0dfa761 | 197 | } |