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