2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2019 EfficiOS Inc. and Linux Foundation
7 #ifndef BABELTRACE2_GRAPH_PORT_H
8 #define BABELTRACE2_GRAPH_PORT_H
10 #ifndef __BT_IN_BABELTRACE_H
11 # error "Please include <babeltrace2/babeltrace.h> instead."
16 #include <babeltrace2/types.h>
23 @defgroup api-port Ports
27 \bt_c_comp input and output ports.
29 A <strong><em>port</em></strong> is a point of \bt_conn between
32 @image html component-zoom.png
34 A port is a \ref api-fund-shared-object "shared object": get a new
35 reference with bt_port_get_ref() and put an existing reference with
38 The common C type of a port is #bt_port.
40 There are two types of ports:
43 <dt>\anchor api-port-in Input port</dt>
45 Input connection point from which \bt_p_msg are received.
47 Filter and sink components have input ports.
49 An input port's specific type is #bt_port_input and its type
50 enumerator is #BT_PORT_TYPE_INPUT.
52 \ref api-fund-c-typing "Upcast" the #bt_port_input type to the
53 #bt_port type with bt_port_input_as_port_const().
55 Get a new input port reference with bt_port_input_get_ref() and put
56 an existing one with bt_port_input_put_ref().
59 <dt>\anchor api-port-out Output port</dt>
61 Output connection point to which messages are sent.
63 Source and filter components have output ports.
65 An output port's specific type is #bt_port_output and its type
66 enumerator is #BT_PORT_TYPE_OUTPUT.
68 \ref api-fund-c-typing "Upcast" the #bt_port_output type to the
69 #bt_port type with bt_port_output_as_port_const().
71 Get a new output port reference with bt_port_output_get_ref() and
72 put an existing one with bt_port_output_put_ref().
76 Get a port's type enumerator with bt_port_get_type(). You can also use
77 the bt_port_is_input() and bt_port_is_output() helper functions.
79 A \bt_comp can add a port with:
81 - bt_self_component_source_add_output_port()
82 - bt_self_component_filter_add_input_port()
83 - bt_self_component_filter_add_output_port()
84 - bt_self_component_sink_add_input_port()
86 Borrow a port's \bt_conn, if any, with
87 bt_port_borrow_connection_const().
89 Borrow the component to which a port belongs with
90 bt_port_borrow_component_const().
94 A port has the following common properties:
98 \anchor api-port-prop-name
104 For a given \bt_comp:
106 - Each input port has a unique name.
107 - Each output port has a unique name.
109 A port's name is set when the component adds it; you cannot change
112 Get a port's name with bt_port_get_name().
116 \anchor api-port-prop-is-connected
120 Whether or not the port is currently connected to another port.
122 Get whether or not a port is connected with bt_port_is_connected().
124 When a port is unconnected, bt_port_borrow_connection_const()
136 @typedef struct bt_port bt_port;
141 @typedef struct bt_port_input bt_port_input;
146 @typedef struct bt_port_output bt_port_output;
161 Port type enumerators.
163 typedef enum bt_port_type
{
168 BT_PORT_TYPE_INPUT
= 1 << 0,
174 BT_PORT_TYPE_OUTPUT
= 1 << 1,
179 Returns the type enumerator of the port \bt_p{port}.
182 Port of which to get the type enumerator
185 Type enumerator of \bt_p{port}.
187 @bt_pre_not_null{port}
189 @sa bt_port_is_input() —
190 Returns whether or not a port is an \bt_iport.
191 @sa bt_port_is_output() —
192 Returns whether or not a port is an \bt_oport.
194 extern bt_port_type
bt_port_get_type(const bt_port
*port
);
198 Returns whether or not the port \bt_p{port} is an \bt_iport.
204 #BT_TRUE if \bt_p{port} is an input port.
206 @bt_pre_not_null{port}
208 @sa bt_port_get_type() —
209 Returns the type enumerator of a port.
212 bt_bool
bt_port_is_input(const bt_port
*port
)
214 return bt_port_get_type(port
) == BT_PORT_TYPE_INPUT
;
219 Returns whether or not the port \bt_p{port} is an \bt_oport.
225 #BT_TRUE if \bt_p{port} is an output port.
227 @bt_pre_not_null{port}
229 @sa bt_port_get_type() —
230 Returns the type enumerator of a port.
233 bt_bool
bt_port_is_output(const bt_port
*port
)
235 return bt_port_get_type(port
) == BT_PORT_TYPE_OUTPUT
;
241 @name Connection access
247 Borrows the \bt_conn of the port \bt_p{port}.
249 This function returns \c NULL if \bt_p{port} is unconnected
250 (bt_port_is_connected() returns #BT_FALSE).
253 Port of which to borrow the connection.
256 \em Borrowed reference of the connection of \bt_p{port}.
258 @bt_pre_not_null{port}
260 extern const bt_connection
*bt_port_borrow_connection_const(
261 const bt_port
*port
);
266 @name Component access
272 Borrows the \bt_comp to which the port \bt_p{port} belongs.
275 Port of which to borrow the component which owns it.
278 \em Borrowed reference of the component which owns \bt_p{port}.
280 @bt_pre_not_null{port}
282 extern const bt_component
*bt_port_borrow_component_const(
283 const bt_port
*port
);
294 Returns the name of the port \bt_p{port}.
296 See the \ref api-port-prop-name "name" property.
299 Port of which to get the name.
303 Name of \bt_p{port}, or \c NULL if none.
305 The returned pointer remains valid as long as \bt_p{port} exists.
308 @bt_pre_not_null{port}
310 extern const char *bt_port_get_name(const bt_port
*port
);
314 Returns whether or not the port \bt_p{port} is connected.
316 See the \ref api-port-prop-is-connected "is connected?" property.
319 Port of which to get whether or not it's connected.
322 #BT_TRUE if \bt_p{port} is connected.
324 @bt_pre_not_null{port}
326 extern bt_bool
bt_port_is_connected(const bt_port
*port
);
331 @name Reference count (common)
337 Increments the \ref api-fund-shared-object "reference count" of
338 the port \bt_p{port}.
342 Port of which to increment the reference count.
347 @sa bt_port_put_ref() —
348 Decrements the reference count of a port.
350 extern void bt_port_get_ref(const bt_port
*port
);
354 Decrements the \ref api-fund-shared-object "reference count" of
355 the port \bt_p{port}.
359 Port of which to decrement the reference count.
364 @sa bt_port_get_ref() —
365 Increments the reference count of a port.
367 extern void bt_port_put_ref(const bt_port
*port
);
371 Decrements the reference count of the port
372 \bt_p{_port}, and then sets \bt_p{_port} to \c NULL.
376 Port of which to decrement the reference count.
381 @bt_pre_assign_expr{_port}
383 #define BT_PORT_PUT_REF_AND_RESET(_port) \
385 bt_port_put_ref(_port); \
391 Decrements the reference count of the port \bt_p{_dst}, sets
392 \bt_p{_dst} to \bt_p{_src}, and then sets \bt_p{_src} to \c NULL.
394 This macro effectively moves a port reference from the
395 expression \bt_p{_src} to the expression \bt_p{_dst}, putting the
396 existing \bt_p{_dst} reference.
400 Destination expression.
411 @bt_pre_assign_expr{_dst}
412 @bt_pre_assign_expr{_src}
414 #define BT_PORT_MOVE_REF(_dst, _src) \
416 bt_port_put_ref(_dst); \
430 \ref api-fund-c-typing "Upcasts" the \bt_iport \bt_p{port} to the
431 common #bt_port type.
435 Input port to upcast.
441 \bt_p{port} as a common port.
444 const bt_port
*bt_port_input_as_port_const(const bt_port_input
*port
)
446 return __BT_UPCAST_CONST(bt_port
, port
);
451 Increments the \ref api-fund-shared-object "reference count" of
452 the \bt_iport \bt_p{port}.
456 Input port of which to increment the reference count.
461 @sa bt_port_input_put_ref() —
462 Decrements the reference count of an input port.
464 extern void bt_port_input_get_ref(const bt_port_input
*port
);
468 Decrements the \ref api-fund-shared-object "reference count" of
469 the \bt_iport \bt_p{port}.
473 Input port of which to decrement the reference count.
478 @sa bt_port_input_get_ref() —
479 Increments the reference count of an input port.
481 extern void bt_port_input_put_ref(const bt_port_input
*port
);
485 Decrements the reference count of the \bt_iport
486 \bt_p{_port}, and then sets \bt_p{_port} to \c NULL.
490 Input port of which to decrement the reference count.
495 @bt_pre_assign_expr{_port}
497 #define BT_PORT_INPUT_PUT_REF_AND_RESET(_port) \
499 bt_port_input_put_ref(_port); \
505 Decrements the reference count of the \bt_iport \bt_p{_dst}, sets
506 \bt_p{_dst} to \bt_p{_src}, and then sets \bt_p{_src} to \c NULL.
508 This macro effectively moves an \bt_iport reference from the
509 expression \bt_p{_src} to the expression \bt_p{_dst}, putting the
510 existing \bt_p{_dst} reference.
514 Destination expression.
525 @bt_pre_assign_expr{_dst}
526 @bt_pre_assign_expr{_src}
528 #define BT_PORT_INPUT_MOVE_REF(_dst, _src) \
530 bt_port_input_put_ref(_dst); \
544 \ref api-fund-c-typing "Upcasts" the \bt_oport \bt_p{port} to the
545 common #bt_port type.
549 Output port to upcast.
555 \bt_p{port} as a common port.
558 const bt_port
*bt_port_output_as_port_const(const bt_port_output
*port
)
560 return __BT_UPCAST_CONST(bt_port
, port
);
565 Increments the \ref api-fund-shared-object "reference count" of
566 the \bt_oport \bt_p{port}.
570 Output port of which to increment the reference count.
575 @sa bt_port_output_put_ref() —
576 Decrements the reference count of a \bt_oport.
578 extern void bt_port_output_get_ref(const bt_port_output
*port
);
582 Decrements the \ref api-fund-shared-object "reference count" of
583 the \bt_oport \bt_p{port}.
587 Output port of which to decrement the reference count.
592 @sa bt_port_output_get_ref() —
593 Increments the reference count of a \bt_oport.
595 extern void bt_port_output_put_ref(const bt_port_output
*port
);
599 Decrements the reference count of the \bt_oport
600 \bt_p{_port}, and then sets \bt_p{_port} to \c NULL.
604 Output port of which to decrement the reference count.
609 @bt_pre_assign_expr{_port}
611 #define BT_PORT_OUTPUT_PUT_REF_AND_RESET(_port) \
613 bt_port_output_put_ref(_port); \
619 Decrements the reference count of the \bt_oport \bt_p{_dst}, sets
620 \bt_p{_dst} to \bt_p{_src}, and then sets \bt_p{_src} to \c NULL.
622 This macro effectively moves an \bt_oport reference from the
623 expression \bt_p{_src} to the expression \bt_p{_dst}, putting the
624 existing \bt_p{_dst} reference.
628 Destination expression.
639 @bt_pre_assign_expr{_dst}
640 @bt_pre_assign_expr{_src}
642 #define BT_PORT_OUTPUT_MOVE_REF(_dst, _src) \
644 bt_port_output_put_ref(_dst); \
657 #endif /* BABELTRACE2_GRAPH_PORT_H */
This page took 0.045019 seconds and 4 git commands to generate.