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