Move enum bt_component_type to component.h
[babeltrace.git] / include / babeltrace / component / component.h
CommitLineData
33b34c43
PP
1#ifndef BABELTRACE_COMPONENT_COMPONENT_H
2#define BABELTRACE_COMPONENT_COMPONENT_H
43de0e13
JG
3
4/*
33b34c43 5 * BabelTrace - Babeltrace Component Interface
43de0e13
JG
6 *
7 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 *
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 */
29
33b34c43
PP
30#include <babeltrace/component/notification/iterator.h>
31#include <babeltrace/values.h>
32#include <stdio.h>
30d619df 33
43de0e13
JG
34#ifdef __cplusplus
35extern "C" {
36#endif
37
d1b057f5
PP
38/**
39 * Component type.
40 */
41enum bt_component_type {
42 BT_COMPONENT_TYPE_UNKNOWN = -1,
43
44 /** A source component is a notification generator. */
45 BT_COMPONENT_TYPE_SOURCE = 0,
46
47 /** A sink component handles incoming notifications. */
48 BT_COMPONENT_TYPE_SINK = 1,
49
50 /** A filter component implements both Source and Sink interfaces. */
51 BT_COMPONENT_TYPE_FILTER = 2,
52};
53
33b34c43
PP
54/**
55 * Status code. Errors are always negative.
56 */
57enum bt_component_status {
58 /** No error, okay. */
59 BT_COMPONENT_STATUS_OK = 0,
60 /** No more work to be done by this component. **/
61 BT_COMPONENT_STATUS_END = 1,
62 /**
63 * Component can't process a notification at this time
64 * (e.g. would block), try again later.
65 */
66 BT_COMPONENT_STATUS_AGAIN = 2,
67 /** General error. */
68 BT_COMPONENT_STATUS_ERROR = -1,
69 /** Unsupported component feature. */
70 BT_COMPONENT_STATUS_UNSUPPORTED = -2,
71 /** Invalid arguments. */
72 BT_COMPONENT_STATUS_INVALID = -3,
73 /** Memory allocation failure. */
74 BT_COMPONENT_STATUS_NOMEM = -4,
75};
76
77struct bt_component_class;
47e5a032 78struct bt_component;
7c7c0433 79struct bt_value;
38b48196 80
43de0e13 81/**
633edee0 82 * Component private data deallocation function type.
43de0e13 83 *
760051fa 84 * @param component Component instance
43de0e13 85 */
760051fa 86typedef void (*bt_component_destroy_cb)(struct bt_component *component);
43de0e13 87
2bd8a567 88/**
38b48196 89 * Component initialization function type.
8738a040 90 *
38b48196
JG
91 * A component's private data and required callbacks must be set by this
92 * function.
2bd8a567 93 *
633edee0 94 * @param component Component instance
7c7c0433 95 * @param params A dictionary of component parameters
480dc8ed 96 * @returns One of #bt_component_status values
2bd8a567 97 */
38b48196 98typedef enum bt_component_status (*bt_component_init_cb)(
7c7c0433 99 struct bt_component *component, struct bt_value *params);
8738a040 100
33b34c43 101
8738a040
JG
102/**
103 * Get a component's private data.
104 *
105 * @param component Component of which to get the private data
106 * @returns Component's private data
107 */
108extern void *bt_component_get_private_data(struct bt_component *component);
47e5a032 109
8738a040
JG
110/**
111 * Set a component's private data.
112 *
113 * @param component Component of which to set the private data
114 * @param data Component private data
115 * @returns One of #bt_component_status values
116 */
117extern enum bt_component_status bt_component_set_private_data(
118 struct bt_component *component, void *data);
119
120/**
121 * Set a component's private data cleanup function.
122 *
123 * @param component Component of which to set the private data destruction
124 * function
125 * @param data Component private data clean-up function
126 * @returns One of #bt_component_status values
127 */
128extern enum bt_component_status bt_component_set_destroy_cb(
129 struct bt_component *component,
130 bt_component_destroy_cb destroy);
131
132/** bt_component_souce */
133/**
134 * Iterator initialization function type.
135 *
136 * A notification iterator's private data, deinitialization, next, and get
137 * callbacks must be set by this function.
138 *
30d619df 139 * @param source Source component instance
8738a040
JG
140 * @param iterator Notification iterator instance
141 */
142typedef enum bt_component_status (*bt_component_source_init_iterator_cb)(
30d619df 143 struct bt_component *, struct bt_notification_iterator *);
2bd8a567 144
8738a040
JG
145/**
146 * Set a source component's iterator initialization function.
147 *
30d619df 148 * @param source Source component instance
8738a040
JG
149 * @param init_iterator Notification iterator initialization callback
150 */
151extern enum bt_component_status
30d619df 152bt_component_source_set_iterator_init_cb(struct bt_component *source,
8738a040
JG
153 bt_component_source_init_iterator_cb init_iterator);
154
155/** bt_component_sink */
2bd8a567 156/**
fec2a9f2 157 * Notification consumption function type.
2bd8a567 158 *
fec2a9f2
JG
159 * @param sink Sink component instance
160 * @returns One of #bt_component_status values
161 */
162typedef enum bt_component_status (*bt_component_sink_consume_cb)(
163 struct bt_component *);
164
165/**
166 * Iterator addition function type.
167 *
168 * A sink component may choose to refuse the addition of an iterator
169 * by not returning BT_COMPONENT_STATUS_OK.
0dfd8ee4 170 *
30d619df 171 * @param sink Sink component instance
633edee0 172 * @returns One of #bt_component_status values
2bd8a567 173 */
fec2a9f2
JG
174typedef enum bt_component_status (*bt_component_sink_add_iterator_cb)(
175 struct bt_component *, struct bt_notification_iterator *);
2bd8a567 176
8738a040 177/**
fec2a9f2 178 * Set a sink component's consumption callback.
8738a040 179 *
fec2a9f2
JG
180 * @param sink Sink component instance
181 * @param consume Consumption callback
182 * @returns One of #bt_component_status values
8738a040
JG
183 */
184extern enum bt_component_status
fec2a9f2
JG
185bt_component_sink_set_consume_cb(struct bt_component *sink,
186 bt_component_sink_consume_cb consume);
8738a040 187
30d619df 188/**
fec2a9f2 189 * Set a sink component's iterator addition callback.
30d619df 190 *
fec2a9f2
JG
191 * @param sink Sink component instance
192 * @param add_iterator Iterator addition callback
193 * @returns One of #bt_component_status values
30d619df
JG
194 */
195extern enum bt_component_status
fec2a9f2
JG
196bt_component_sink_set_add_iterator_cb(struct bt_component *sink,
197 bt_component_sink_add_iterator_cb add_iterator);
198
199/* Defaults to 1. */
200extern enum bt_component_status
201bt_component_sink_set_minimum_input_count(struct bt_component *sink,
202 unsigned int minimum);
203
204/* Defaults to 1. */
205extern enum bt_component_status
206bt_component_sink_set_maximum_input_count(struct bt_component *sink,
207 unsigned int maximum);
208
209extern enum bt_component_status
210bt_component_sink_get_input_count(struct bt_component *sink,
211 unsigned int *count);
212
213/* May return NULL after an interator has reached its end. */
214extern enum bt_component_status
215bt_component_sink_get_input_iterator(struct bt_component *sink,
216 unsigned int input, struct bt_notification_iterator **iterator);
30d619df 217
34ac9eaf
JG
218/** bt_component_filter */
219/**
220 * Iterator initialization function type.
221 *
222 * A notification iterator's private data, deinitialization, next, and get
223 * callbacks must be set by this function.
224 *
225 * @param filter Filter component instance
226 * @param iterator Notification iterator instance
227 */
228typedef enum bt_component_status (*bt_component_filter_init_iterator_cb)(
229 struct bt_component *, struct bt_notification_iterator *);
230
231/**
232 * Iterator addition function type.
233 *
234 * A filter component may choose to refuse the addition of an iterator
235 * by not returning BT_COMPONENT_STATUS_OK.
236 *
237 * @param filter Filter component instance
238 * @returns One of #bt_component_status values
239 */
240typedef enum bt_component_status (*bt_component_filter_add_iterator_cb)(
241 struct bt_component *, struct bt_notification_iterator *);
242
243/**
244 * Set a filter component's iterator initialization function.
245 *
246 * @param filter Filter component instance
247 * @param init_iterator Notification iterator initialization callback
248 */
249extern enum bt_component_status
250bt_component_filter_set_iterator_init_cb(struct bt_component *filter,
251 bt_component_filter_init_iterator_cb init_iterator);
252
253/**
254 * Set a filter component's iterator addition callback.
255 *
256 * @param filter Filter component instance
257 * @param add_iterator Iterator addition callback
258 * @returns One of #bt_component_status values
259 */
260extern enum bt_component_status
261bt_component_filter_set_add_iterator_cb(struct bt_component *filter,
262 bt_component_filter_add_iterator_cb add_iterator);
263
264/* Defaults to 1. */
265extern enum bt_component_status
266bt_component_filter_set_minimum_input_count(struct bt_component *filter,
267 unsigned int minimum);
268
269/* Defaults to 1. */
270extern enum bt_component_status
271bt_component_filter_set_maximum_input_count(struct bt_component *filter,
272 unsigned int maximum);
273
274extern enum bt_component_status
275bt_component_filter_get_input_count(struct bt_component *filter,
276 unsigned int *count);
277
278/* May return NULL after an interator has reached its end. */
279extern enum bt_component_status
280bt_component_filter_get_input_iterator(struct bt_component *filter,
281 unsigned int input, struct bt_notification_iterator **iterator);
282
43de0e13 283/**
33b34c43 284 * Create an instance of a component from a component class.
43de0e13 285 *
33b34c43
PP
286 * @param component_class Component class of which to create an instance
287 * @param name Name of the new component instance, optional
288 * @param params A dictionary of component parameters
289 * @returns Returns a pointer to a new component instance
cab3f160 290 */
33b34c43
PP
291extern struct bt_component *bt_component_create(
292 struct bt_component_class *component_class, const char *name,
293 struct bt_value *params);
cab3f160 294
d97bac96 295/**
33b34c43 296 * Get component's name.
d97bac96 297 *
33b34c43
PP
298 * @param component Component instance of which to get the name
299 * @returns Returns a pointer to the component's name
d97bac96 300 */
33b34c43 301extern const char *bt_component_get_name(struct bt_component *component);
8738a040 302
d97bac96 303/**
33b34c43 304 * Set component's name.
d97bac96 305 *
33b34c43
PP
306 * @param component Component instance of which to set the name
307 * @param name New component name (will be copied)
308 * @returns One of #bt_component_status values
d97bac96 309 */
33b34c43
PP
310extern enum bt_component_status bt_component_set_name(
311 struct bt_component *component, const char *name);
47e5a032 312
d97bac96 313/**
33b34c43 314 * Get component's class.
d97bac96 315 *
33b34c43
PP
316 * @param component Component instance of which to get the class
317 * @returns The component's class
d97bac96 318 */
33b34c43
PP
319extern struct bt_component_class *bt_component_get_class(
320 struct bt_component *component);
47e5a032 321
43de0e13
JG
322#ifdef __cplusplus
323}
324#endif
325
33b34c43 326#endif /* BABELTRACE_COMPONENT_COMPONENT_H */
This page took 0.042562 seconds and 4 git commands to generate.