Cleanup: remove private babeltrace.h
[babeltrace.git] / src / 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
71c5da58 23#include <babeltrace2/babeltrace.h>
85e7137b 24#include "common/macros.h"
57952005
MJ
25#include "plugins/plugins-common.h"
26#include "common/assert.h"
c2b71c92
JG
27#include "dummy.h"
28
1043fdea
PP
29static
30const char * const in_port_name = "in";
31
c2b71c92
JG
32void destroy_private_dummy_data(struct dummy *dummy)
33{
b09a5592 34 bt_self_component_port_input_message_iterator_put_ref(dummy->msg_iter);
c2b71c92 35 g_free(dummy);
834e9996 36
c2b71c92
JG
37}
38
834e9996 39BT_HIDDEN
8eee8ea2 40void dummy_finalize(bt_self_component_sink *comp)
c2b71c92
JG
41{
42 struct dummy *dummy;
43
834e9996
PP
44 BT_ASSERT(comp);
45 dummy = bt_self_component_get_data(
bb61965b 46 bt_self_component_sink_as_self_component(comp));
8b45963b 47 BT_ASSERT(dummy);
c2b71c92
JG
48 destroy_private_dummy_data(dummy);
49}
50
834e9996 51BT_HIDDEN
ee78f405 52bt_self_component_status dummy_init(
8eee8ea2
PP
53 bt_self_component_sink *component,
54 const bt_value *params,
ce141536 55 UNUSED_VAR void *init_method_data)
c2b71c92 56{
ee78f405 57 bt_self_component_status ret;
c2b71c92
JG
58 struct dummy *dummy = g_new0(struct dummy, 1);
59
60 if (!dummy) {
834e9996 61 ret = BT_SELF_COMPONENT_STATUS_NOMEM;
c2b71c92
JG
62 goto end;
63 }
64
834e9996 65 ret = bt_self_component_sink_add_input_port(component,
147337a3 66 "in", NULL, NULL);
834e9996 67 if (ret != BT_SELF_COMPONENT_STATUS_OK) {
c2b71c92
JG
68 goto error;
69 }
d83d78e7 70
834e9996 71 bt_self_component_set_data(
bb61965b 72 bt_self_component_sink_as_self_component(component), dummy);
d83d78e7
PP
73 goto end;
74
c2b71c92
JG
75error:
76 destroy_private_dummy_data(dummy);
d83d78e7
PP
77
78end:
c2b71c92
JG
79 return ret;
80}
81
834e9996 82BT_HIDDEN
1043fdea
PP
83bt_self_component_status dummy_graph_is_configured(
84 bt_self_component_sink *comp)
c2b71c92 85{
ee78f405 86 bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
c2b71c92 87 struct dummy *dummy;
b09a5592 88 bt_self_component_port_input_message_iterator *iterator;
c2b71c92 89
834e9996 90 dummy = bt_self_component_get_data(
bb61965b 91 bt_self_component_sink_as_self_component(comp));
8b45963b 92 BT_ASSERT(dummy);
b09a5592 93 iterator = bt_self_component_port_input_message_iterator_create(
1043fdea
PP
94 bt_self_component_sink_borrow_input_port_by_name(comp,
95 in_port_name));
834e9996
PP
96 if (!iterator) {
97 status = BT_SELF_COMPONENT_STATUS_NOMEM;
c2b71c92
JG
98 goto end;
99 }
100
b09a5592
PP
101 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
102 dummy->msg_iter, iterator);
0d8b4d8e 103
c2b71c92 104end:
634f394c 105 return status;
c2b71c92 106}
e0dfa761 107
834e9996 108BT_HIDDEN
ee78f405 109bt_self_component_status dummy_consume(
8eee8ea2 110 bt_self_component_sink *component)
e0dfa761 111{
ee78f405 112 bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK;
b09a5592 113 bt_message_array_const msgs;
3fd7b79d 114 uint64_t count;
c2b71c92 115 struct dummy *dummy;
ee78f405 116 bt_message_iterator_status it_ret;
3fd7b79d 117 uint64_t i;
e0dfa761 118
834e9996 119 dummy = bt_self_component_get_data(
bb61965b 120 bt_self_component_sink_as_self_component(component));
8b45963b 121 BT_ASSERT(dummy);
e0dfa761 122
85e7137b 123 if (G_UNLIKELY(!dummy->msg_iter)) {
834e9996 124 ret = BT_SELF_COMPONENT_STATUS_END;
d83d78e7 125 goto end;
e0dfa761
PP
126 }
127
b09a5592
PP
128 /* Consume one message */
129 it_ret = bt_self_component_port_input_message_iterator_next(
130 dummy->msg_iter, &msgs, &count);
d83d78e7 131 switch (it_ret) {
b09a5592 132 case BT_MESSAGE_ITERATOR_STATUS_OK:
834e9996 133 ret = BT_SELF_COMPONENT_STATUS_OK;
3fd7b79d
PP
134
135 for (i = 0; i < count; i++) {
b09a5592 136 bt_message_put_ref(msgs[i]);
3fd7b79d
PP
137 }
138
139 break;
b09a5592 140 case BT_MESSAGE_ITERATOR_STATUS_AGAIN:
834e9996 141 ret = BT_SELF_COMPONENT_STATUS_AGAIN;
d83d78e7 142 goto end;
b09a5592 143 case BT_MESSAGE_ITERATOR_STATUS_END:
834e9996 144 ret = BT_SELF_COMPONENT_STATUS_END;
d83d78e7 145 goto end;
b09a5592 146 case BT_MESSAGE_ITERATOR_STATUS_ERROR:
834e9996
PP
147 ret = BT_SELF_COMPONENT_STATUS_ERROR;
148 goto end;
b09a5592 149 case BT_MESSAGE_ITERATOR_STATUS_NOMEM:
834e9996 150 ret = BT_SELF_COMPONENT_STATUS_NOMEM;
3fd7b79d 151 goto end;
d83d78e7
PP
152 default:
153 break;
e0dfa761 154 }
d83d78e7 155
e0dfa761 156end:
e0dfa761
PP
157 return ret;
158}
This page took 0.046857 seconds and 4 git commands to generate.