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_put(dummy
->notif_iter
);
35 void dummy_finalize(struct bt_private_component
*component
)
40 dummy
= bt_private_component_get_user_data(component
);
42 destroy_private_dummy_data(dummy
);
45 enum bt_component_status
dummy_init(struct bt_private_component
*component
,
46 struct bt_value
*params
, UNUSED_VAR
void *init_method_data
)
48 enum bt_component_status ret
;
49 struct dummy
*dummy
= g_new0(struct dummy
, 1);
52 ret
= BT_COMPONENT_STATUS_NOMEM
;
56 ret
= bt_private_component_sink_add_input_private_port(component
,
58 if (ret
!= BT_COMPONENT_STATUS_OK
) {
62 ret
= bt_private_component_set_user_data(component
, dummy
);
63 if (ret
!= BT_COMPONENT_STATUS_OK
) {
70 destroy_private_dummy_data(dummy
);
76 void dummy_port_connected(
77 struct bt_private_component
*component
,
78 struct bt_private_port
*self_port
,
79 struct bt_port
*other_port
)
82 struct bt_notification_iterator
*iterator
;
83 struct bt_private_connection
*connection
;
84 enum bt_connection_status conn_status
;
86 dummy
= bt_private_component_get_user_data(component
);
88 connection
= bt_private_port_get_private_connection(self_port
);
89 BT_ASSERT(connection
);
90 conn_status
= bt_private_connection_create_notification_iterator(
91 connection
, &iterator
);
92 if (conn_status
!= BT_CONNECTION_STATUS_OK
) {
97 BT_MOVE(dummy
->notif_iter
, iterator
);
103 enum bt_component_status
dummy_consume(struct bt_private_component
*component
)
105 enum bt_component_status ret
= BT_COMPONENT_STATUS_OK
;
106 struct bt_notification
*notif
= NULL
;
108 enum bt_notification_iterator_status it_ret
;
110 dummy
= bt_private_component_get_user_data(component
);
113 if (unlikely(dummy
->error
)) {
114 ret
= BT_COMPONENT_STATUS_ERROR
;
118 if (unlikely(!dummy
->notif_iter
)) {
119 ret
= BT_COMPONENT_STATUS_END
;
123 /* Consume one notification */
124 it_ret
= bt_private_connection_notification_iterator_next(
125 dummy
->notif_iter
, ¬if
);
127 case BT_NOTIFICATION_ITERATOR_STATUS_ERROR
:
128 ret
= BT_COMPONENT_STATUS_ERROR
;
130 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN
:
131 ret
= BT_COMPONENT_STATUS_AGAIN
;
133 case BT_NOTIFICATION_ITERATOR_STATUS_END
:
134 ret
= BT_COMPONENT_STATUS_END
;