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