2d0c6aa4a15c86a29c56425da35312cdf402b255
[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/macros.h"
25 #include "common/assert.h"
26 #include "dummy.h"
27
28 static
29 const char * const in_port_name = "in";
30
31 void destroy_private_dummy_data(struct dummy *dummy)
32 {
33 bt_self_component_port_input_message_iterator_put_ref(dummy->msg_iter);
34 g_free(dummy);
35
36 }
37
38 BT_HIDDEN
39 void dummy_finalize(bt_self_component_sink *comp)
40 {
41 struct dummy *dummy;
42
43 BT_ASSERT(comp);
44 dummy = bt_self_component_get_data(
45 bt_self_component_sink_as_self_component(comp));
46 BT_ASSERT(dummy);
47 destroy_private_dummy_data(dummy);
48 }
49
50 BT_HIDDEN
51 bt_component_class_initialize_method_status dummy_init(
52 bt_self_component_sink *component,
53 bt_self_component_sink_configuration *config,
54 const bt_value *params,
55 __attribute__((unused)) void *init_method_data)
56 {
57 bt_component_class_initialize_method_status status =
58 BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
59 bt_self_component_add_port_status add_port_status;
60 struct dummy *dummy = g_new0(struct dummy, 1);
61
62 if (!dummy) {
63 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
64 goto end;
65 }
66
67 add_port_status = bt_self_component_sink_add_input_port(component,
68 "in", NULL, NULL);
69 switch (add_port_status) {
70 case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR:
71 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
72 goto error;
73 case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR:
74 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
75 goto error;
76 default:
77 break;
78 }
79
80 bt_self_component_set_data(
81 bt_self_component_sink_as_self_component(component), dummy);
82 goto end;
83
84 error:
85 destroy_private_dummy_data(dummy);
86
87 end:
88 return status;
89 }
90
91 BT_HIDDEN
92 bt_component_class_sink_graph_is_configured_method_status dummy_graph_is_configured(
93 bt_self_component_sink *comp)
94 {
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;
98 struct dummy *dummy;
99 bt_self_component_port_input_message_iterator *iterator;
100
101 dummy = bt_self_component_get_data(
102 bt_self_component_sink_as_self_component(comp));
103 BT_ASSERT(dummy);
104 msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component(
105 comp, bt_self_component_sink_borrow_input_port_by_name(comp,
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;
109 goto end;
110 }
111
112 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
113 dummy->msg_iter, iterator);
114
115 status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
116
117 end:
118 return status;
119 }
120
121 BT_HIDDEN
122 bt_component_class_sink_consume_method_status dummy_consume(
123 bt_self_component_sink *component)
124 {
125 bt_component_class_sink_consume_method_status status =
126 BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
127 bt_message_array_const msgs;
128 uint64_t count;
129 struct dummy *dummy;
130 bt_message_iterator_next_status next_status;
131 uint64_t i;
132
133 dummy = bt_self_component_get_data(
134 bt_self_component_sink_as_self_component(component));
135 BT_ASSERT(dummy);
136
137 if (G_UNLIKELY(!dummy->msg_iter)) {
138 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END;
139 goto end;
140 }
141
142 /* Consume one message */
143 next_status = bt_self_component_port_input_message_iterator_next(
144 dummy->msg_iter, &msgs, &count);
145 switch (next_status) {
146 case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK:
147 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
148
149 for (i = 0; i < count; i++) {
150 bt_message_put_ref(msgs[i]);
151 }
152
153 break;
154 case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN:
155 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_AGAIN;
156 goto end;
157 case BT_MESSAGE_ITERATOR_NEXT_STATUS_END:
158 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_END;
159 goto end;
160 case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR:
161 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
162 goto end;
163 case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
164 status = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_MEMORY_ERROR;
165 goto end;
166 default:
167 break;
168 }
169
170 end:
171 return status;
172 }
This page took 0.032373 seconds and 3 git commands to generate.