lib: make graph API const-correct
[babeltrace.git] / plugins / utils / dummy / dummy.c
CommitLineData
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
9d408fca 23#include <babeltrace/babeltrace.h>
0d8b4d8e 24#include <babeltrace/babeltrace-internal.h>
c2b71c92 25#include <plugins-common.h>
f6ccaed9 26#include <babeltrace/assert-internal.h>
c2b71c92
JG
27#include "dummy.h"
28
c2b71c92
JG
29void destroy_private_dummy_data(struct dummy *dummy)
30{
65300d60 31 bt_object_put_ref(dummy->notif_iter);
c2b71c92 32 g_free(dummy);
d94d92ac 33
c2b71c92
JG
34}
35
d94d92ac
PP
36BT_HIDDEN
37void dummy_finalize(struct bt_self_component_sink *comp)
c2b71c92
JG
38{
39 struct dummy *dummy;
40
d94d92ac
PP
41 BT_ASSERT(comp);
42 dummy = bt_self_component_get_data(
707b7d35 43 bt_self_component_sink_as_self_component(comp));
f6ccaed9 44 BT_ASSERT(dummy);
c2b71c92
JG
45 destroy_private_dummy_data(dummy);
46}
47
d94d92ac
PP
48BT_HIDDEN
49enum bt_self_component_status dummy_init(
50 struct bt_self_component_sink *component,
05e21286
PP
51 const struct bt_value *params,
52 UNUSED_VAR void *init_method_data)
c2b71c92 53{
d94d92ac 54 enum bt_self_component_status ret;
c2b71c92
JG
55 struct dummy *dummy = g_new0(struct dummy, 1);
56
57 if (!dummy) {
d94d92ac 58 ret = BT_SELF_COMPONENT_STATUS_NOMEM;
c2b71c92
JG
59 goto end;
60 }
61
d94d92ac 62 ret = bt_self_component_sink_add_input_port(component,
147337a3 63 "in", NULL, NULL);
d94d92ac 64 if (ret != BT_SELF_COMPONENT_STATUS_OK) {
c2b71c92
JG
65 goto error;
66 }
d19348b6 67
d94d92ac 68 bt_self_component_set_data(
707b7d35 69 bt_self_component_sink_as_self_component(component), dummy);
d19348b6
PP
70 goto end;
71
c2b71c92
JG
72error:
73 destroy_private_dummy_data(dummy);
d19348b6
PP
74
75end:
c2b71c92
JG
76 return ret;
77}
78
d94d92ac
PP
79BT_HIDDEN
80enum bt_self_component_status dummy_port_connected(
81 struct bt_self_component_sink *comp,
82 struct bt_self_component_port_input *self_port,
0d72b8c3 83 const struct bt_port_output *other_port)
c2b71c92 84{
d94d92ac 85 enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
c2b71c92 86 struct dummy *dummy;
d94d92ac 87 struct bt_self_component_port_input_notification_iterator *iterator;
c2b71c92 88
d94d92ac 89 dummy = bt_self_component_get_data(
707b7d35 90 bt_self_component_sink_as_self_component(comp));
f6ccaed9 91 BT_ASSERT(dummy);
d94d92ac
PP
92 iterator = bt_self_component_port_input_notification_iterator_create(
93 self_port);
94 if (!iterator) {
95 status = BT_SELF_COMPONENT_STATUS_NOMEM;
c2b71c92
JG
96 goto end;
97 }
98
65300d60 99 BT_OBJECT_MOVE_REF(dummy->notif_iter, iterator);
0d8b4d8e 100
c2b71c92 101end:
bf55043c 102 return status;
c2b71c92 103}
e0dfa761 104
d94d92ac
PP
105BT_HIDDEN
106enum bt_self_component_status dummy_consume(
107 struct bt_self_component_sink *component)
e0dfa761 108{
d94d92ac 109 enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK;
0d72b8c3 110 bt_notification_array_const notifs;
d4393e08 111 uint64_t count;
c2b71c92 112 struct dummy *dummy;
d19348b6 113 enum bt_notification_iterator_status it_ret;
d4393e08 114 uint64_t i;
e0dfa761 115
d94d92ac 116 dummy = bt_self_component_get_data(
707b7d35 117 bt_self_component_sink_as_self_component(component));
f6ccaed9 118 BT_ASSERT(dummy);
e0dfa761 119
d19348b6 120 if (unlikely(!dummy->notif_iter)) {
d94d92ac 121 ret = BT_SELF_COMPONENT_STATUS_END;
d19348b6 122 goto end;
e0dfa761
PP
123 }
124
d19348b6 125 /* Consume one notification */
d94d92ac 126 it_ret = bt_self_component_port_input_notification_iterator_next(
d4393e08 127 dummy->notif_iter, &notifs, &count);
d19348b6 128 switch (it_ret) {
d4393e08 129 case BT_NOTIFICATION_ITERATOR_STATUS_OK:
d94d92ac 130 ret = BT_SELF_COMPONENT_STATUS_OK;
d4393e08
PP
131
132 for (i = 0; i < count; i++) {
65300d60 133 bt_object_put_ref(notifs[i]);
d4393e08
PP
134 }
135
136 break;
d19348b6 137 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
d94d92ac 138 ret = BT_SELF_COMPONENT_STATUS_AGAIN;
d19348b6
PP
139 goto end;
140 case BT_NOTIFICATION_ITERATOR_STATUS_END:
d94d92ac 141 ret = BT_SELF_COMPONENT_STATUS_END;
d19348b6 142 goto end;
d4393e08 143 case BT_NOTIFICATION_ITERATOR_STATUS_ERROR:
d94d92ac
PP
144 ret = BT_SELF_COMPONENT_STATUS_ERROR;
145 goto end;
146 case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM:
147 ret = BT_SELF_COMPONENT_STATUS_NOMEM;
d4393e08 148 goto end;
d19348b6
PP
149 default:
150 break;
e0dfa761 151 }
d19348b6 152
e0dfa761 153end:
e0dfa761
PP
154 return ret;
155}
This page took 0.046362 seconds and 4 git commands to generate.