Commit | Line | Data |
---|---|---|
0777b693 JG |
1 | /* |
2 | * source.c | |
3 | * | |
0d884c50 | 4 | * Babeltrace Source Component |
0777b693 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 | ||
6baaaa1b PP |
29 | #define BT_LOG_TAG "COMP-SOURCE" |
30 | #include <babeltrace/lib-logging-internal.h> | |
31 | ||
b8a06801 | 32 | #include <babeltrace/ref.h> |
3d9990ac | 33 | #include <babeltrace/compiler-internal.h> |
5c563278 | 34 | #include <babeltrace/graph/private-component.h> |
b2e0c907 PP |
35 | #include <babeltrace/graph/component-source-internal.h> |
36 | #include <babeltrace/graph/component-internal.h> | |
37 | #include <babeltrace/graph/port-internal.h> | |
38 | #include <babeltrace/graph/notification-iterator.h> | |
39 | #include <babeltrace/graph/notification-iterator-internal.h> | |
bd7cc15b | 40 | #include <babeltrace/graph/graph.h> |
0777b693 | 41 | |
72b913fb | 42 | BT_HIDDEN |
366e034f JG |
43 | void bt_component_source_destroy(struct bt_component *component) |
44 | { | |
366e034f JG |
45 | } |
46 | ||
8738a040 | 47 | BT_HIDDEN |
fb2dcc52 | 48 | struct bt_component *bt_component_source_create( |
36712f1d | 49 | struct bt_component_class *class) |
0777b693 | 50 | { |
0d884c50 | 51 | struct bt_component_source *source = NULL; |
38b48196 | 52 | |
0d884c50 | 53 | source = g_new0(struct bt_component_source, 1); |
0777b693 | 54 | if (!source) { |
6baaaa1b | 55 | BT_LOGE_STR("Failed to allocate one source component."); |
0777b693 JG |
56 | goto end; |
57 | } | |
58 | ||
0777b693 JG |
59 | end: |
60 | return source ? &source->parent : NULL; | |
61 | } | |
47e5a032 | 62 | |
544d0515 | 63 | int64_t bt_component_source_get_output_port_count( |
6baaaa1b | 64 | struct bt_component *component) |
366e034f | 65 | { |
544d0515 | 66 | int64_t ret; |
366e034f | 67 | |
6baaaa1b PP |
68 | if (!component) { |
69 | BT_LOGW_STR("Invalid parameter: component is NULL."); | |
70 | ret = (int64_t) -1; | |
366e034f JG |
71 | goto end; |
72 | } | |
73 | ||
6baaaa1b PP |
74 | if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { |
75 | BT_LOGW("Invalid parameter: component's class is not a source component class: " | |
76 | "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", | |
77 | component, bt_component_get_name(component), | |
78 | bt_component_class_type_string(component->class->type)); | |
79 | ret = (int64_t) -1; | |
80 | goto end; | |
81 | } | |
82 | ||
83 | /* bt_component_get_output_port_count() logs details/errors */ | |
544d0515 | 84 | ret = bt_component_get_output_port_count(component); |
6baaaa1b | 85 | |
366e034f | 86 | end: |
544d0515 | 87 | return ret; |
366e034f JG |
88 | } |
89 | ||
9ac68eb1 | 90 | struct bt_port *bt_component_source_get_output_port_by_name( |
366e034f JG |
91 | struct bt_component *component, const char *name) |
92 | { | |
72b913fb | 93 | struct bt_port *port = NULL; |
366e034f | 94 | |
6baaaa1b PP |
95 | if (!component) { |
96 | BT_LOGW_STR("Invalid parameter: component is NULL."); | |
97 | goto end; | |
98 | } | |
99 | ||
100 | if (!name) { | |
101 | BT_LOGW_STR("Invalid parameter: name is NULL."); | |
102 | goto end; | |
103 | } | |
104 | ||
105 | if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { | |
106 | BT_LOGW("Invalid parameter: component's class is not a source component class: " | |
107 | "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", | |
108 | component, bt_component_get_name(component), | |
109 | bt_component_class_type_string(component->class->type)); | |
366e034f JG |
110 | goto end; |
111 | } | |
112 | ||
6baaaa1b | 113 | /* bt_component_get_output_port_by_name() logs details/errors */ |
9ac68eb1 | 114 | port = bt_component_get_output_port_by_name(component, name); |
6baaaa1b | 115 | |
366e034f | 116 | end: |
72b913fb | 117 | return port; |
366e034f JG |
118 | } |
119 | ||
9ac68eb1 PP |
120 | struct bt_port *bt_component_source_get_output_port_by_index( |
121 | struct bt_component *component, uint64_t index) | |
366e034f JG |
122 | { |
123 | struct bt_port *port = NULL; | |
366e034f | 124 | |
6baaaa1b PP |
125 | if (!component) { |
126 | BT_LOGW_STR("Invalid parameter: component is NULL."); | |
127 | goto end; | |
128 | } | |
129 | ||
130 | if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { | |
131 | BT_LOGW("Invalid parameter: component's class is not a source component class: " | |
132 | "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", | |
133 | component, bt_component_get_name(component), | |
134 | bt_component_class_type_string(component->class->type)); | |
366e034f JG |
135 | goto end; |
136 | } | |
137 | ||
6baaaa1b | 138 | /* bt_component_get_output_port_by_index() logs details/errors */ |
9ac68eb1 | 139 | port = bt_component_get_output_port_by_index(component, index); |
6baaaa1b | 140 | |
366e034f JG |
141 | end: |
142 | return port; | |
143 | } | |
144 | ||
9ac68eb1 PP |
145 | struct bt_private_port * |
146 | bt_private_component_source_get_output_private_port_by_name( | |
890882ef PP |
147 | struct bt_private_component *private_component, |
148 | const char *name) | |
149 | { | |
6baaaa1b | 150 | /* bt_component_source_get_output_port_by_name() logs details/errors */ |
9ac68eb1 PP |
151 | return bt_private_port_from_port( |
152 | bt_component_source_get_output_port_by_name( | |
6d137876 | 153 | bt_component_borrow_from_private(private_component), name)); |
890882ef PP |
154 | } |
155 | ||
156 | struct bt_private_port * | |
9ac68eb1 PP |
157 | bt_private_component_source_get_output_private_port_by_index( |
158 | struct bt_private_component *private_component, uint64_t index) | |
890882ef | 159 | { |
6baaaa1b | 160 | /* bt_component_source_get_output_port_by_index() logs details/errors */ |
890882ef | 161 | return bt_private_port_from_port( |
9ac68eb1 | 162 | bt_component_source_get_output_port_by_index( |
6d137876 | 163 | bt_component_borrow_from_private(private_component), index)); |
890882ef PP |
164 | } |
165 | ||
147337a3 | 166 | enum bt_component_status bt_private_component_source_add_output_private_port( |
890882ef | 167 | struct bt_private_component *private_component, |
147337a3 PP |
168 | const char *name, void *user_data, |
169 | struct bt_private_port **user_priv_port) | |
366e034f | 170 | { |
147337a3 | 171 | enum bt_component_status status = BT_COMPONENT_STATUS_OK; |
72b913fb | 172 | struct bt_port *port = NULL; |
890882ef | 173 | struct bt_component *component = |
6d137876 | 174 | bt_component_borrow_from_private(private_component); |
bd7cc15b | 175 | struct bt_graph *graph; |
366e034f | 176 | |
6baaaa1b PP |
177 | if (!component) { |
178 | BT_LOGW_STR("Invalid parameter: component is NULL."); | |
147337a3 | 179 | status = BT_COMPONENT_STATUS_INVALID; |
366e034f JG |
180 | goto end; |
181 | } | |
182 | ||
6baaaa1b PP |
183 | if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { |
184 | BT_LOGW("Invalid parameter: component's class is not a source component class: " | |
185 | "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", | |
186 | component, bt_component_get_name(component), | |
187 | bt_component_class_type_string(component->class->type)); | |
147337a3 | 188 | status = BT_COMPONENT_STATUS_INVALID; |
6baaaa1b PP |
189 | goto end; |
190 | } | |
191 | ||
bd7cc15b PP |
192 | graph = bt_component_borrow_graph(component); |
193 | ||
194 | if (graph && bt_graph_is_canceled(graph)) { | |
43ca7dcc | 195 | BT_LOGW("Cannot add output port to source component: graph is canceled: " |
bd7cc15b PP |
196 | "comp-addr=%p, comp-name=\"%s\", graph-addr=%p", |
197 | component, bt_component_get_name(component), | |
198 | bt_component_borrow_graph(component)); | |
199 | status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED; | |
200 | goto end; | |
201 | } | |
202 | ||
6baaaa1b | 203 | /* bt_component_add_output_port() logs details and errors */ |
3e9b0023 | 204 | port = bt_component_add_output_port(component, name, user_data); |
147337a3 PP |
205 | if (!port) { |
206 | status = BT_COMPONENT_STATUS_NOMEM; | |
207 | goto end; | |
208 | } | |
209 | ||
210 | if (user_priv_port) { | |
211 | /* Move reference to user */ | |
212 | *user_priv_port = bt_private_port_from_port(port); | |
213 | port = NULL; | |
214 | } | |
6baaaa1b | 215 | |
366e034f | 216 | end: |
147337a3 PP |
217 | bt_put(port); |
218 | return status; | |
366e034f | 219 | } |