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 | ||
3fadfbc0 | 23 | #include <babeltrace2/babeltrace.h> |
91d81473 | 24 | #include "common/macros.h" |
578e048b | 25 | #include "common/assert.h" |
c2b71c92 JG |
26 | #include "dummy.h" |
27 | ||
5badd463 PP |
28 | static |
29 | const char * const in_port_name = "in"; | |
30 | ||
c2b71c92 JG |
31 | void destroy_private_dummy_data(struct dummy *dummy) |
32 | { | |
d6e69534 | 33 | bt_self_component_port_input_message_iterator_put_ref(dummy->msg_iter); |
c2b71c92 | 34 | g_free(dummy); |
d94d92ac | 35 | |
c2b71c92 JG |
36 | } |
37 | ||
d94d92ac | 38 | BT_HIDDEN |
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 | ||
d94d92ac | 50 | BT_HIDDEN |
21a9f056 | 51 | bt_component_class_initialize_method_status dummy_init( |
b19ff26f | 52 | bt_self_component_sink *component, |
59225a3e | 53 | bt_self_component_sink_configuration *config, |
b19ff26f | 54 | const bt_value *params, |
c88dd1cb | 55 | __attribute__((unused)) void *init_method_data) |
c2b71c92 | 56 | { |
21a9f056 FD |
57 | bt_component_class_initialize_method_status status = |
58 | BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK; | |
d24d5663 | 59 | bt_self_component_add_port_status add_port_status; |
c2b71c92 JG |
60 | struct dummy *dummy = g_new0(struct dummy, 1); |
61 | ||
62 | if (!dummy) { | |
21a9f056 | 63 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
c2b71c92 JG |
64 | goto end; |
65 | } | |
66 | ||
d24d5663 | 67 | add_port_status = bt_self_component_sink_add_input_port(component, |
147337a3 | 68 | "in", NULL, NULL); |
d24d5663 PP |
69 | switch (add_port_status) { |
70 | case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR: | |
21a9f056 | 71 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR; |
c2b71c92 | 72 | goto error; |
d24d5663 | 73 | case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR: |
21a9f056 | 74 | status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR; |
d24d5663 PP |
75 | goto error; |
76 | default: | |
77 | break; | |
c2b71c92 | 78 | } |
d19348b6 | 79 | |
d94d92ac | 80 | bt_self_component_set_data( |
707b7d35 | 81 | bt_self_component_sink_as_self_component(component), dummy); |
d19348b6 PP |
82 | goto end; |
83 | ||
c2b71c92 JG |
84 | error: |
85 | destroy_private_dummy_data(dummy); | |
d19348b6 PP |
86 | |
87 | end: | |
d24d5663 | 88 | return status; |
c2b71c92 JG |
89 | } |
90 | ||
d94d92ac | 91 | BT_HIDDEN |
d24d5663 | 92 | bt_component_class_sink_graph_is_configured_method_status dummy_graph_is_configured( |
5badd463 | 93 | bt_self_component_sink *comp) |
c2b71c92 | 94 | { |
e803df70 SM |
95 | bt_component_class_sink_graph_is_configured_method_status status; |
96 | bt_self_component_port_input_message_iterator_create_from_sink_component_status | |
97 | msg_iter_status; | |
c2b71c92 | 98 | struct dummy *dummy; |
d6e69534 | 99 | bt_self_component_port_input_message_iterator *iterator; |
c2b71c92 | 100 | |
d94d92ac | 101 | dummy = bt_self_component_get_data( |
707b7d35 | 102 | bt_self_component_sink_as_self_component(comp)); |
f6ccaed9 | 103 | BT_ASSERT(dummy); |
e803df70 | 104 | msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component( |
ca02df0a | 105 | comp, bt_self_component_sink_borrow_input_port_by_name(comp, |
e803df70 SM |
106 | in_port_name), &iterator); |
107 | if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) { | |
108 | status = (int) msg_iter_status; | |
c2b71c92 JG |
109 | goto end; |
110 | } | |
111 | ||
d6e69534 PP |
112 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF( |
113 | dummy->msg_iter, iterator); | |
0d8b4d8e | 114 | |
e803df70 SM |
115 | status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK; |
116 | ||
c2b71c92 | 117 | end: |
bf55043c | 118 | return status; |
c2b71c92 | 119 | } |
e0dfa761 | 120 | |
d94d92ac | 121 | BT_HIDDEN |
d24d5663 | 122 | bt_component_class_sink_consume_method_status dummy_consume( |
b19ff26f | 123 | bt_self_component_sink *component) |
e0dfa761 | 124 | { |
d24d5663 PP |
125 | bt_component_class_sink_consume_method_status status = |
126 | BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; | |
d6e69534 | 127 | bt_message_array_const msgs; |
d4393e08 | 128 | uint64_t count; |
c2b71c92 | 129 | struct dummy *dummy; |
d24d5663 | 130 | bt_message_iterator_next_status next_status; |
d4393e08 | 131 | uint64_t i; |
e0dfa761 | 132 | |
d94d92ac | 133 | dummy = bt_self_component_get_data( |
707b7d35 | 134 | bt_self_component_sink_as_self_component(component)); |
f6ccaed9 | 135 | BT_ASSERT(dummy); |
e0dfa761 | 136 | |
91d81473 | 137 | if (G_UNLIKELY(!dummy->msg_iter)) { |
d24d5663 | 138 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END; |
d19348b6 | 139 | goto end; |
e0dfa761 PP |
140 | } |
141 | ||
d6e69534 | 142 | /* Consume one message */ |
d24d5663 | 143 | next_status = bt_self_component_port_input_message_iterator_next( |
d6e69534 | 144 | dummy->msg_iter, &msgs, &count); |
d24d5663 PP |
145 | switch (next_status) { |
146 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK: | |
147 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK; | |
d4393e08 PP |
148 | |
149 | for (i = 0; i < count; i++) { | |
d6e69534 | 150 | bt_message_put_ref(msgs[i]); |
d4393e08 PP |
151 | } |
152 | ||
153 | break; | |
d24d5663 PP |
154 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN: |
155 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN; | |
d19348b6 | 156 | goto end; |
d24d5663 PP |
157 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_END: |
158 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END; | |
d19348b6 | 159 | goto end; |
d24d5663 PP |
160 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR: |
161 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR; | |
d94d92ac | 162 | goto end; |
d24d5663 PP |
163 | case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR: |
164 | status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR; | |
d4393e08 | 165 | goto end; |
d19348b6 PP |
166 | default: |
167 | break; | |
e0dfa761 | 168 | } |
d19348b6 | 169 | |
e0dfa761 | 170 | end: |
d24d5663 | 171 | return status; |
e0dfa761 | 172 | } |