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 MJ |
25 | #include "plugins/plugins-common.h" |
26 | #include "common/assert.h" | |
c2b71c92 JG |
27 | #include "dummy.h" |
28 | ||
5badd463 PP |
29 | static |
30 | const char * const in_port_name = "in"; | |
31 | ||
c2b71c92 JG |
32 | void destroy_private_dummy_data(struct dummy *dummy) |
33 | { | |
d6e69534 | 34 | bt_self_component_port_input_message_iterator_put_ref(dummy->msg_iter); |
c2b71c92 | 35 | g_free(dummy); |
d94d92ac | 36 | |
c2b71c92 JG |
37 | } |
38 | ||
d94d92ac | 39 | BT_HIDDEN |
b19ff26f | 40 | void dummy_finalize(bt_self_component_sink *comp) |
c2b71c92 JG |
41 | { |
42 | struct dummy *dummy; | |
43 | ||
d94d92ac PP |
44 | BT_ASSERT(comp); |
45 | dummy = bt_self_component_get_data( | |
707b7d35 | 46 | bt_self_component_sink_as_self_component(comp)); |
f6ccaed9 | 47 | BT_ASSERT(dummy); |
c2b71c92 JG |
48 | destroy_private_dummy_data(dummy); |
49 | } | |
50 | ||
d94d92ac | 51 | BT_HIDDEN |
4cdfc5e8 | 52 | bt_self_component_status dummy_init( |
b19ff26f PP |
53 | bt_self_component_sink *component, |
54 | const bt_value *params, | |
05e21286 | 55 | UNUSED_VAR void *init_method_data) |
c2b71c92 | 56 | { |
4cdfc5e8 | 57 | bt_self_component_status ret; |
c2b71c92 JG |
58 | struct dummy *dummy = g_new0(struct dummy, 1); |
59 | ||
60 | if (!dummy) { | |
d94d92ac | 61 | ret = BT_SELF_COMPONENT_STATUS_NOMEM; |
c2b71c92 JG |
62 | goto end; |
63 | } | |
64 | ||
d94d92ac | 65 | ret = bt_self_component_sink_add_input_port(component, |
147337a3 | 66 | "in", NULL, NULL); |
d94d92ac | 67 | if (ret != BT_SELF_COMPONENT_STATUS_OK) { |
c2b71c92 JG |
68 | goto error; |
69 | } | |
d19348b6 | 70 | |
d94d92ac | 71 | bt_self_component_set_data( |
707b7d35 | 72 | bt_self_component_sink_as_self_component(component), dummy); |
d19348b6 PP |
73 | goto end; |
74 | ||
c2b71c92 JG |
75 | error: |
76 | destroy_private_dummy_data(dummy); | |
d19348b6 PP |
77 | |
78 | end: | |
c2b71c92 JG |
79 | return ret; |
80 | } | |
81 | ||
d94d92ac | 82 | BT_HIDDEN |
5badd463 PP |
83 | bt_self_component_status dummy_graph_is_configured( |
84 | bt_self_component_sink *comp) | |
c2b71c92 | 85 | { |
4cdfc5e8 | 86 | bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK; |
c2b71c92 | 87 | struct dummy *dummy; |
d6e69534 | 88 | bt_self_component_port_input_message_iterator *iterator; |
c2b71c92 | 89 | |
d94d92ac | 90 | dummy = bt_self_component_get_data( |
707b7d35 | 91 | bt_self_component_sink_as_self_component(comp)); |
f6ccaed9 | 92 | BT_ASSERT(dummy); |
d6e69534 | 93 | iterator = bt_self_component_port_input_message_iterator_create( |
5badd463 PP |
94 | bt_self_component_sink_borrow_input_port_by_name(comp, |
95 | in_port_name)); | |
d94d92ac PP |
96 | if (!iterator) { |
97 | status = BT_SELF_COMPONENT_STATUS_NOMEM; | |
c2b71c92 JG |
98 | goto end; |
99 | } | |
100 | ||
d6e69534 PP |
101 | BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF( |
102 | dummy->msg_iter, iterator); | |
0d8b4d8e | 103 | |
c2b71c92 | 104 | end: |
bf55043c | 105 | return status; |
c2b71c92 | 106 | } |
e0dfa761 | 107 | |
d94d92ac | 108 | BT_HIDDEN |
4cdfc5e8 | 109 | bt_self_component_status dummy_consume( |
b19ff26f | 110 | bt_self_component_sink *component) |
e0dfa761 | 111 | { |
4cdfc5e8 | 112 | bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK; |
d6e69534 | 113 | bt_message_array_const msgs; |
d4393e08 | 114 | uint64_t count; |
c2b71c92 | 115 | struct dummy *dummy; |
4cdfc5e8 | 116 | bt_message_iterator_status it_ret; |
d4393e08 | 117 | uint64_t i; |
e0dfa761 | 118 | |
d94d92ac | 119 | dummy = bt_self_component_get_data( |
707b7d35 | 120 | bt_self_component_sink_as_self_component(component)); |
f6ccaed9 | 121 | BT_ASSERT(dummy); |
e0dfa761 | 122 | |
91d81473 | 123 | if (G_UNLIKELY(!dummy->msg_iter)) { |
d94d92ac | 124 | ret = BT_SELF_COMPONENT_STATUS_END; |
d19348b6 | 125 | goto end; |
e0dfa761 PP |
126 | } |
127 | ||
d6e69534 PP |
128 | /* Consume one message */ |
129 | it_ret = bt_self_component_port_input_message_iterator_next( | |
130 | dummy->msg_iter, &msgs, &count); | |
d19348b6 | 131 | switch (it_ret) { |
d6e69534 | 132 | case BT_MESSAGE_ITERATOR_STATUS_OK: |
d94d92ac | 133 | ret = BT_SELF_COMPONENT_STATUS_OK; |
d4393e08 PP |
134 | |
135 | for (i = 0; i < count; i++) { | |
d6e69534 | 136 | bt_message_put_ref(msgs[i]); |
d4393e08 PP |
137 | } |
138 | ||
139 | break; | |
d6e69534 | 140 | case BT_MESSAGE_ITERATOR_STATUS_AGAIN: |
d94d92ac | 141 | ret = BT_SELF_COMPONENT_STATUS_AGAIN; |
d19348b6 | 142 | goto end; |
d6e69534 | 143 | case BT_MESSAGE_ITERATOR_STATUS_END: |
d94d92ac | 144 | ret = BT_SELF_COMPONENT_STATUS_END; |
d19348b6 | 145 | goto end; |
d6e69534 | 146 | case BT_MESSAGE_ITERATOR_STATUS_ERROR: |
d94d92ac PP |
147 | ret = BT_SELF_COMPONENT_STATUS_ERROR; |
148 | goto end; | |
d6e69534 | 149 | case BT_MESSAGE_ITERATOR_STATUS_NOMEM: |
d94d92ac | 150 | ret = BT_SELF_COMPONENT_STATUS_NOMEM; |
d4393e08 | 151 | goto end; |
d19348b6 PP |
152 | default: |
153 | break; | |
e0dfa761 | 154 | } |
d19348b6 | 155 | |
e0dfa761 | 156 | end: |
e0dfa761 PP |
157 | return ret; |
158 | } |