Remove useless component/iterator validation functions
[babeltrace.git] / lib / graph / sink.c
1 /*
2 * sink.c
3 *
4 * Babeltrace Sink Component
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
29 #include <babeltrace/compiler-internal.h>
30 #include <babeltrace/values.h>
31 #include <babeltrace/graph/component-sink-internal.h>
32 #include <babeltrace/graph/component-internal.h>
33 #include <babeltrace/graph/notification.h>
34
35 BT_HIDDEN
36 void bt_component_sink_destroy(struct bt_component *component)
37 {
38 }
39
40 BT_HIDDEN
41 struct bt_component *bt_component_sink_create(
42 struct bt_component_class *class, struct bt_value *params)
43 {
44 struct bt_component_sink *sink = NULL;
45
46 sink = g_new0(struct bt_component_sink, 1);
47 if (!sink) {
48 goto end;
49 }
50
51 end:
52 return sink ? &sink->parent : NULL;
53 }
54
55 BT_HIDDEN
56 enum bt_component_status bt_component_sink_consume(
57 struct bt_component *component)
58 {
59 enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
60 struct bt_component_class_sink *sink_class = NULL;
61
62 if (!component) {
63 ret = BT_COMPONENT_STATUS_INVALID;
64 goto end;
65 }
66
67 if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) {
68 ret = BT_COMPONENT_STATUS_UNSUPPORTED;
69 goto end;
70 }
71
72 sink_class = container_of(component->class, struct bt_component_class_sink, parent);
73 assert(sink_class->methods.consume);
74 ret = sink_class->methods.consume(bt_private_component_from_component(component));
75 end:
76 return ret;
77 }
78
79 int64_t bt_component_sink_get_input_port_count(struct bt_component *component)
80 {
81 int64_t ret;
82
83 if (!component ||
84 component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
85 ret = (int64_t) -1;
86 goto end;
87 }
88
89 ret = bt_component_get_input_port_count(component);
90 end:
91 return ret;
92 }
93
94 struct bt_port *bt_component_sink_get_input_port_by_name(
95 struct bt_component *component, const char *name)
96 {
97 struct bt_port *port = NULL;
98
99 if (!component || !name ||
100 component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
101 goto end;
102 }
103
104 port = bt_component_get_input_port_by_name(component, name);
105 end:
106 return port;
107 }
108
109 struct bt_port *bt_component_sink_get_input_port_by_index(
110 struct bt_component *component, uint64_t index)
111 {
112 struct bt_port *port = NULL;
113
114 if (!component ||
115 component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
116 goto end;
117 }
118
119 port = bt_component_get_input_port_by_index(component, index);
120 end:
121 return port;
122 }
123
124 struct bt_private_port *
125 bt_private_component_sink_get_input_private_port_by_index(
126 struct bt_private_component *private_component, uint64_t index)
127 {
128 return bt_private_port_from_port(
129 bt_component_sink_get_input_port_by_index(
130 bt_component_from_private(private_component), index));
131 }
132
133 struct bt_private_port *
134 bt_private_component_sink_get_input_private_port_by_name(
135 struct bt_private_component *private_component,
136 const char *name)
137 {
138 return bt_private_port_from_port(
139 bt_component_sink_get_input_port_by_name(
140 bt_component_from_private(private_component), name));
141 }
142
143 struct bt_private_port *bt_private_component_sink_add_input_private_port(
144 struct bt_private_component *private_component,
145 const char *name, void *user_data)
146 {
147 struct bt_port *port = NULL;
148 struct bt_component *component =
149 bt_component_from_private(private_component);
150
151 if (!component ||
152 component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
153 goto end;
154 }
155
156 port = bt_component_add_input_port(component, name, user_data);
157 end:
158 return bt_private_port_from_port(port);
159 }
This page took 0.03265 seconds and 4 git commands to generate.