Remove useless component/iterator validation functions
[babeltrace.git] / lib / graph / sink.c
CommitLineData
0d884c50
JG
1/*
2 * sink.c
3 *
47e5a032 4 * Babeltrace Sink Component
0d884c50
JG
5 *
6 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
3d9990ac 29#include <babeltrace/compiler-internal.h>
fec2a9f2 30#include <babeltrace/values.h>
b2e0c907
PP
31#include <babeltrace/graph/component-sink-internal.h>
32#include <babeltrace/graph/component-internal.h>
33#include <babeltrace/graph/notification.h>
0d884c50 34
72b913fb 35BT_HIDDEN
fec2a9f2
JG
36void bt_component_sink_destroy(struct bt_component *component)
37{
fec2a9f2
JG
38}
39
8738a040 40BT_HIDDEN
fb2dcc52 41struct bt_component *bt_component_sink_create(
7c7c0433 42 struct bt_component_class *class, struct bt_value *params)
0d884c50
JG
43{
44 struct bt_component_sink *sink = NULL;
0d884c50 45
0d884c50
JG
46 sink = g_new0(struct bt_component_sink, 1);
47 if (!sink) {
48 goto end;
49 }
50
0d884c50
JG
51end:
52 return sink ? &sink->parent : NULL;
53}
fa55ed98 54
973a2bd1 55BT_HIDDEN
fec2a9f2
JG
56enum bt_component_status bt_component_sink_consume(
57 struct bt_component *component)
fa55ed98
JG
58{
59 enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
d3e4dcd8 60 struct bt_component_class_sink *sink_class = NULL;
fa55ed98 61
fec2a9f2 62 if (!component) {
30d619df 63 ret = BT_COMPONENT_STATUS_INVALID;
fa55ed98
JG
64 goto end;
65 }
66
d3e4dcd8 67 if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) {
fa55ed98
JG
68 ret = BT_COMPONENT_STATUS_UNSUPPORTED;
69 goto end;
70 }
71
d3e4dcd8
PP
72 sink_class = container_of(component->class, struct bt_component_class_sink, parent);
73 assert(sink_class->methods.consume);
890882ef 74 ret = sink_class->methods.consume(bt_private_component_from_component(component));
fa55ed98
JG
75end:
76 return ret;
77}
34a9ed19 78
544d0515 79int64_t bt_component_sink_get_input_port_count(struct bt_component *component)
952ebade 80{
544d0515 81 int64_t ret;
952ebade 82
544d0515 83 if (!component ||
72b913fb 84 component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
9ac68eb1 85 ret = (int64_t) -1;
952ebade
JG
86 goto end;
87 }
88
544d0515 89 ret = bt_component_get_input_port_count(component);
fec2a9f2 90end:
544d0515 91 return ret;
fec2a9f2
JG
92}
93
9ac68eb1 94struct bt_port *bt_component_sink_get_input_port_by_name(
366e034f 95 struct bt_component *component, const char *name)
fec2a9f2 96{
72b913fb 97 struct bt_port *port = NULL;
fec2a9f2 98
366e034f
JG
99 if (!component || !name ||
100 component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
fec2a9f2
JG
101 goto end;
102 }
103
9ac68eb1 104 port = bt_component_get_input_port_by_name(component, name);
fec2a9f2 105end:
72b913fb 106 return port;
fec2a9f2
JG
107}
108
9ac68eb1
PP
109struct bt_port *bt_component_sink_get_input_port_by_index(
110 struct bt_component *component, uint64_t index)
fec2a9f2 111{
366e034f 112 struct bt_port *port = NULL;
fec2a9f2 113
366e034f
JG
114 if (!component ||
115 component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
fec2a9f2
JG
116 goto end;
117 }
118
9ac68eb1 119 port = bt_component_get_input_port_by_index(component, index);
fec2a9f2 120end:
366e034f 121 return port;
fec2a9f2
JG
122}
123
890882ef 124struct bt_private_port *
9ac68eb1
PP
125bt_private_component_sink_get_input_private_port_by_index(
126 struct bt_private_component *private_component, uint64_t index)
890882ef
PP
127{
128 return bt_private_port_from_port(
9ac68eb1 129 bt_component_sink_get_input_port_by_index(
890882ef
PP
130 bt_component_from_private(private_component), index));
131}
132
b9d103be
PP
133struct bt_private_port *
134bt_private_component_sink_get_input_private_port_by_name(
135 struct bt_private_component *private_component,
136 const char *name)
890882ef
PP
137{
138 return bt_private_port_from_port(
b9d103be
PP
139 bt_component_sink_get_input_port_by_name(
140 bt_component_from_private(private_component), name));
890882ef
PP
141}
142
143struct bt_private_port *bt_private_component_sink_add_input_private_port(
144 struct bt_private_component *private_component,
3e9b0023 145 const char *name, void *user_data)
366e034f 146{
72b913fb 147 struct bt_port *port = NULL;
890882ef
PP
148 struct bt_component *component =
149 bt_component_from_private(private_component);
fec2a9f2 150
366e034f
JG
151 if (!component ||
152 component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
fec2a9f2
JG
153 goto end;
154 }
155
3e9b0023 156 port = bt_component_add_input_port(component, name, user_data);
fec2a9f2 157end:
890882ef 158 return bt_private_port_from_port(port);
fec2a9f2 159}
This page took 0.036748 seconds and 4 git commands to generate.