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/plugin/plugin-dev.h>
24 #include <babeltrace/graph/connection.h>
25 #include <babeltrace/graph/component.h>
26 #include <babeltrace/graph/private-component.h>
27 #include <babeltrace/graph/private-component-sink.h>
28 #include <babeltrace/graph/private-port.h>
29 #include <babeltrace/graph/port.h>
30 #include <babeltrace/graph/private-connection.h>
31 #include <babeltrace/graph/component-sink.h>
32 #include <babeltrace/graph/notification-iterator.h>
33 #include <babeltrace/graph/notification.h>
34 #include <babeltrace/babeltrace-internal.h>
35 #include <plugins-common.h>
40 void destroy_private_dummy_data(struct dummy
*dummy
)
42 if (dummy
->iterators
) {
43 g_ptr_array_free(dummy
->iterators
, TRUE
);
48 void dummy_finalize(struct bt_private_component
*component
)
53 dummy
= bt_private_component_get_user_data(component
);
55 destroy_private_dummy_data(dummy
);
58 enum bt_component_status
dummy_init(struct bt_private_component
*component
,
59 struct bt_value
*params
, UNUSED_VAR
void *init_method_data
)
61 enum bt_component_status ret
;
62 struct dummy
*dummy
= g_new0(struct dummy
, 1);
65 ret
= BT_COMPONENT_STATUS_NOMEM
;
69 ret
= bt_private_component_sink_add_input_private_port(component
,
71 if (ret
!= BT_COMPONENT_STATUS_OK
) {
75 dummy
->iterators
= g_ptr_array_new_with_free_func(
76 (GDestroyNotify
) bt_put
);
77 if (!dummy
->iterators
) {
78 ret
= BT_COMPONENT_STATUS_NOMEM
;
82 ret
= bt_private_component_set_user_data(component
, dummy
);
83 if (ret
!= BT_COMPONENT_STATUS_OK
) {
89 destroy_private_dummy_data(dummy
);
93 void dummy_port_connected(
94 struct bt_private_component
*component
,
95 struct bt_private_port
*self_port
,
96 struct bt_port
*other_port
)
99 struct bt_notification_iterator
*iterator
;
100 struct bt_private_connection
*connection
;
101 enum bt_connection_status conn_status
;
103 dummy
= bt_private_component_get_user_data(component
);
105 connection
= bt_private_port_get_private_connection(self_port
);
107 conn_status
= bt_private_connection_create_notification_iterator(
108 connection
, NULL
, &iterator
);
109 if (conn_status
!= BT_CONNECTION_STATUS_OK
) {
114 g_ptr_array_add(dummy
->iterators
, iterator
);
120 enum bt_component_status
dummy_consume(struct bt_private_component
*component
)
122 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
123 struct bt_notification
*notif
= NULL
;
127 dummy
= bt_private_component_get_user_data(component
);
130 if (unlikely(dummy
->error
)) {
131 ret
= BT_COMPONENT_STATUS_ERROR
;
135 /* Consume one notification from each iterator. */
136 for (i
= 0; i
< dummy
->iterators
->len
; i
++) {
137 struct bt_notification_iterator
*it
;
138 enum bt_notification_iterator_status it_ret
;
140 it
= g_ptr_array_index(dummy
->iterators
, i
);
142 it_ret
= bt_notification_iterator_next(it
);
144 case BT_NOTIFICATION_ITERATOR_STATUS_ERROR
:
145 ret
= BT_COMPONENT_STATUS_ERROR
;
147 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
148 ret
= BT_COMPONENT_STATUS_AGAIN
;
150 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
151 g_ptr_array_remove_index(dummy
->iterators
, i
);
159 if (dummy
->iterators
->len
== 0) {
160 ret
= BT_COMPONENT_STATUS_END
;