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