lib: private functions: do not repeat `private` word
[babeltrace.git] / plugins / utils / dummy / dummy.c
CommitLineData
e0dfa761
PP
1/*
2 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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
20 * SOFTWARE.
21 */
22
9d408fca 23#include <babeltrace/babeltrace.h>
0d8b4d8e 24#include <babeltrace/babeltrace-internal.h>
c2b71c92 25#include <plugins-common.h>
f6ccaed9 26#include <babeltrace/assert-internal.h>
c2b71c92
JG
27#include "dummy.h"
28
c2b71c92
JG
29void destroy_private_dummy_data(struct dummy *dummy)
30{
65300d60 31 bt_object_put_ref(dummy->notif_iter);
c2b71c92
JG
32 g_free(dummy);
33}
34
64cadc66 35void dummy_finalize(struct bt_private_component *component)
c2b71c92
JG
36{
37 struct dummy *dummy;
38
f6ccaed9 39 BT_ASSERT(component);
890882ef 40 dummy = bt_private_component_get_user_data(component);
f6ccaed9 41 BT_ASSERT(dummy);
c2b71c92
JG
42 destroy_private_dummy_data(dummy);
43}
44
890882ef 45enum bt_component_status dummy_init(struct bt_private_component *component,
c2b71c92
JG
46 struct bt_value *params, UNUSED_VAR void *init_method_data)
47{
48 enum bt_component_status ret;
49 struct dummy *dummy = g_new0(struct dummy, 1);
50
51 if (!dummy) {
52 ret = BT_COMPONENT_STATUS_NOMEM;
53 goto end;
54 }
55
28e6ca8b 56 ret = bt_private_component_sink_add_input_port(component,
147337a3
PP
57 "in", NULL, NULL);
58 if (ret != BT_COMPONENT_STATUS_OK) {
b9d103be
PP
59 goto end;
60 }
61
890882ef 62 ret = bt_private_component_set_user_data(component, dummy);
c2b71c92
JG
63 if (ret != BT_COMPONENT_STATUS_OK) {
64 goto error;
65 }
d19348b6
PP
66
67 goto end;
68
c2b71c92
JG
69error:
70 destroy_private_dummy_data(dummy);
d19348b6
PP
71
72end:
c2b71c92
JG
73 return ret;
74}
75
bf55043c 76enum bt_component_status dummy_port_connected(
890882ef 77 struct bt_private_component *component,
8f4799f7
PP
78 struct bt_private_port *self_port,
79 struct bt_port *other_port)
c2b71c92 80{
bf55043c 81 enum bt_component_status status = BT_COMPONENT_STATUS_OK;
c2b71c92
JG
82 struct dummy *dummy;
83 struct bt_notification_iterator *iterator;
890882ef 84 struct bt_private_connection *connection;
73d5c1ad 85 enum bt_connection_status conn_status;
c2b71c92 86
890882ef 87 dummy = bt_private_component_get_user_data(component);
f6ccaed9 88 BT_ASSERT(dummy);
28e6ca8b 89 connection = bt_private_port_get_connection(self_port);
f6ccaed9 90 BT_ASSERT(connection);
73d5c1ad 91 conn_status = bt_private_connection_create_notification_iterator(
f42867e2 92 connection, &iterator);
73d5c1ad 93 if (conn_status != BT_CONNECTION_STATUS_OK) {
bf55043c 94 status = BT_COMPONENT_STATUS_ERROR;
c2b71c92
JG
95 goto end;
96 }
97
65300d60 98 BT_OBJECT_MOVE_REF(dummy->notif_iter, iterator);
0d8b4d8e 99
c2b71c92 100end:
65300d60 101 bt_object_put_ref(connection);
bf55043c 102 return status;
c2b71c92 103}
e0dfa761 104
890882ef 105enum bt_component_status dummy_consume(struct bt_private_component *component)
e0dfa761 106{
8812600c 107 enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
d4393e08
PP
108 bt_notification_array notifs;
109 uint64_t count;
c2b71c92 110 struct dummy *dummy;
d19348b6 111 enum bt_notification_iterator_status it_ret;
d4393e08 112 uint64_t i;
e0dfa761 113
890882ef 114 dummy = bt_private_component_get_user_data(component);
f6ccaed9 115 BT_ASSERT(dummy);
e0dfa761 116
d19348b6
PP
117 if (unlikely(!dummy->notif_iter)) {
118 ret = BT_COMPONENT_STATUS_END;
119 goto end;
e0dfa761
PP
120 }
121
d19348b6 122 /* Consume one notification */
07245ac2 123 it_ret = bt_private_connection_notification_iterator_next(
d4393e08 124 dummy->notif_iter, &notifs, &count);
d19348b6 125 switch (it_ret) {
d4393e08
PP
126 case BT_NOTIFICATION_ITERATOR_STATUS_OK:
127 ret = BT_COMPONENT_STATUS_OK;
128
129 for (i = 0; i < count; i++) {
65300d60 130 bt_object_put_ref(notifs[i]);
d4393e08
PP
131 }
132
133 break;
d19348b6
PP
134 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
135 ret = BT_COMPONENT_STATUS_AGAIN;
136 goto end;
137 case BT_NOTIFICATION_ITERATOR_STATUS_END:
e0dfa761 138 ret = BT_COMPONENT_STATUS_END;
d19348b6 139 goto end;
d4393e08
PP
140 case BT_NOTIFICATION_ITERATOR_STATUS_ERROR:
141 ret = BT_COMPONENT_STATUS_ERROR;
142 goto end;
d19348b6
PP
143 default:
144 break;
e0dfa761 145 }
d19348b6 146
e0dfa761 147end:
e0dfa761
PP
148 return ret;
149}
This page took 0.042245 seconds and 4 git commands to generate.