2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 #include <babeltrace/babeltrace.h>
24 #include <babeltrace/babeltrace-internal.h>
25 #include <plugins-common.h>
26 #include <babeltrace/assert-internal.h>
29 void destroy_private_dummy_data(struct dummy
*dummy
)
31 bt_self_component_port_input_message_iterator_put_ref(dummy
->msg_iter
);
37 void dummy_finalize(bt_self_component_sink
*comp
)
42 dummy
= bt_self_component_get_data(
43 bt_self_component_sink_as_self_component(comp
));
45 destroy_private_dummy_data(dummy
);
49 enum bt_self_component_status
dummy_init(
50 bt_self_component_sink
*component
,
51 const bt_value
*params
,
52 UNUSED_VAR
void *init_method_data
)
54 enum bt_self_component_status ret
;
55 struct dummy
*dummy
= g_new0(struct dummy
, 1);
58 ret
= BT_SELF_COMPONENT_STATUS_NOMEM
;
62 ret
= bt_self_component_sink_add_input_port(component
,
64 if (ret
!= BT_SELF_COMPONENT_STATUS_OK
) {
68 bt_self_component_set_data(
69 bt_self_component_sink_as_self_component(component
), dummy
);
73 destroy_private_dummy_data(dummy
);
80 enum bt_self_component_status
dummy_port_connected(
81 bt_self_component_sink
*comp
,
82 bt_self_component_port_input
*self_port
,
83 const bt_port_output
*other_port
)
85 enum bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
87 bt_self_component_port_input_message_iterator
*iterator
;
89 dummy
= bt_self_component_get_data(
90 bt_self_component_sink_as_self_component(comp
));
92 iterator
= bt_self_component_port_input_message_iterator_create(
95 status
= BT_SELF_COMPONENT_STATUS_NOMEM
;
99 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
100 dummy
->msg_iter
, iterator
);
107 enum bt_self_component_status
dummy_consume(
108 bt_self_component_sink
*component
)
110 enum bt_self_component_status ret
= BT_SELF_COMPONENT_STATUS_OK
;
111 bt_message_array_const msgs
;
114 enum bt_message_iterator_status it_ret
;
117 dummy
= bt_self_component_get_data(
118 bt_self_component_sink_as_self_component(component
));
121 if (unlikely(!dummy
->msg_iter
)) {
122 ret
= BT_SELF_COMPONENT_STATUS_END
;
126 /* Consume one message */
127 it_ret
= bt_self_component_port_input_message_iterator_next(
128 dummy
->msg_iter
, &msgs
, &count
);
130 case BT_MESSAGE_ITERATOR_STATUS_OK
:
131 ret
= BT_SELF_COMPONENT_STATUS_OK
;
133 for (i
= 0; i
< count
; i
++) {
134 bt_message_put_ref(msgs
[i
]);
138 case BT_MESSAGE_ITERATOR_STATUS_AGAIN
:
139 ret
= BT_SELF_COMPONENT_STATUS_AGAIN
;
141 case BT_MESSAGE_ITERATOR_STATUS_END
:
142 ret
= BT_SELF_COMPONENT_STATUS_END
;
144 case BT_MESSAGE_ITERATOR_STATUS_ERROR
:
145 ret
= BT_SELF_COMPONENT_STATUS_ERROR
;
147 case BT_MESSAGE_ITERATOR_STATUS_NOMEM
:
148 ret
= BT_SELF_COMPONENT_STATUS_NOMEM
;