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