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/babeltrace.h"
25 #include "plugins/plugins-common.h"
26 #include "common/assert.h"
30 const char * const in_port_name
= "in";
32 void destroy_private_dummy_data(struct dummy
*dummy
)
34 bt_self_component_port_input_message_iterator_put_ref(dummy
->msg_iter
);
40 void dummy_finalize(bt_self_component_sink
*comp
)
45 dummy
= bt_self_component_get_data(
46 bt_self_component_sink_as_self_component(comp
));
48 destroy_private_dummy_data(dummy
);
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
)
57 bt_self_component_status ret
;
58 struct dummy
*dummy
= g_new0(struct dummy
, 1);
61 ret
= BT_SELF_COMPONENT_STATUS_NOMEM
;
65 ret
= bt_self_component_sink_add_input_port(component
,
67 if (ret
!= BT_SELF_COMPONENT_STATUS_OK
) {
71 bt_self_component_set_data(
72 bt_self_component_sink_as_self_component(component
), dummy
);
76 destroy_private_dummy_data(dummy
);
83 bt_self_component_status
dummy_graph_is_configured(
84 bt_self_component_sink
*comp
)
86 bt_self_component_status status
= BT_SELF_COMPONENT_STATUS_OK
;
88 bt_self_component_port_input_message_iterator
*iterator
;
90 dummy
= bt_self_component_get_data(
91 bt_self_component_sink_as_self_component(comp
));
93 iterator
= bt_self_component_port_input_message_iterator_create(
94 bt_self_component_sink_borrow_input_port_by_name(comp
,
97 status
= BT_SELF_COMPONENT_STATUS_NOMEM
;
101 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
102 dummy
->msg_iter
, iterator
);
109 bt_self_component_status
dummy_consume(
110 bt_self_component_sink
*component
)
112 bt_self_component_status ret
= BT_SELF_COMPONENT_STATUS_OK
;
113 bt_message_array_const msgs
;
116 bt_message_iterator_status it_ret
;
119 dummy
= bt_self_component_get_data(
120 bt_self_component_sink_as_self_component(component
));
123 if (unlikely(!dummy
->msg_iter
)) {
124 ret
= BT_SELF_COMPONENT_STATUS_END
;
128 /* Consume one message */
129 it_ret
= bt_self_component_port_input_message_iterator_next(
130 dummy
->msg_iter
, &msgs
, &count
);
132 case BT_MESSAGE_ITERATOR_STATUS_OK
:
133 ret
= BT_SELF_COMPONENT_STATUS_OK
;
135 for (i
= 0; i
< count
; i
++) {
136 bt_message_put_ref(msgs
[i
]);
140 case BT_MESSAGE_ITERATOR_STATUS_AGAIN
:
141 ret
= BT_SELF_COMPONENT_STATUS_AGAIN
;
143 case BT_MESSAGE_ITERATOR_STATUS_END
:
144 ret
= BT_SELF_COMPONENT_STATUS_END
;
146 case BT_MESSAGE_ITERATOR_STATUS_ERROR
:
147 ret
= BT_SELF_COMPONENT_STATUS_ERROR
;
149 case BT_MESSAGE_ITERATOR_STATUS_NOMEM
:
150 ret
= BT_SELF_COMPONENT_STATUS_NOMEM
;