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 <babeltrace2/babeltrace.h>
24 #include "common/macros.h"
25 #include "common/assert.h"
29 const char * const in_port_name
= "in";
31 void destroy_private_dummy_data(struct dummy
*dummy
)
33 bt_self_component_port_input_message_iterator_put_ref(dummy
->msg_iter
);
39 void dummy_finalize(bt_self_component_sink
*comp
)
44 dummy
= bt_self_component_get_data(
45 bt_self_component_sink_as_self_component(comp
));
47 destroy_private_dummy_data(dummy
);
51 bt_self_component_status
dummy_init(
52 bt_self_component_sink
*component
,
53 const bt_value
*params
,
54 __attribute__((unused
)) void *init_method_data
)
56 bt_self_component_status ret
;
57 struct dummy
*dummy
= g_new0(struct dummy
, 1);
60 ret
= BT_SELF_COMPONENT_STATUS_NOMEM
;
64 ret
= bt_self_component_sink_add_input_port(component
,
66 if (ret
!= BT_SELF_COMPONENT_STATUS_OK
) {
70 bt_self_component_set_data(
71 bt_self_component_sink_as_self_component(component
), dummy
);
75 destroy_private_dummy_data(dummy
);
82 bt_self_component_status
dummy_graph_is_configured(
83 bt_self_component_sink
*comp
)
85 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(
93 bt_self_component_sink_borrow_input_port_by_name(comp
,
96 status
= BT_SELF_COMPONENT_STATUS_NOMEM
;
100 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
101 dummy
->msg_iter
, iterator
);
108 bt_self_component_status
dummy_consume(
109 bt_self_component_sink
*component
)
111 bt_self_component_status ret
= BT_SELF_COMPONENT_STATUS_OK
;
112 bt_message_array_const msgs
;
115 bt_message_iterator_status it_ret
;
118 dummy
= bt_self_component_get_data(
119 bt_self_component_sink_as_self_component(component
));
122 if (G_UNLIKELY(!dummy
->msg_iter
)) {
123 ret
= BT_SELF_COMPONENT_STATUS_END
;
127 /* Consume one message */
128 it_ret
= bt_self_component_port_input_message_iterator_next(
129 dummy
->msg_iter
, &msgs
, &count
);
131 case BT_MESSAGE_ITERATOR_STATUS_OK
:
132 ret
= BT_SELF_COMPONENT_STATUS_OK
;
134 for (i
= 0; i
< count
; i
++) {
135 bt_message_put_ref(msgs
[i
]);
139 case BT_MESSAGE_ITERATOR_STATUS_AGAIN
:
140 ret
= BT_SELF_COMPONENT_STATUS_AGAIN
;
142 case BT_MESSAGE_ITERATOR_STATUS_END
:
143 ret
= BT_SELF_COMPONENT_STATUS_END
;
145 case BT_MESSAGE_ITERATOR_STATUS_ERROR
:
146 ret
= BT_SELF_COMPONENT_STATUS_ERROR
;
148 case BT_MESSAGE_ITERATOR_STATUS_NOMEM
:
149 ret
= BT_SELF_COMPONENT_STATUS_NOMEM
;