4 * Babeltrace Connection
6 * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
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
29 #include <babeltrace/component/connection-internal.h>
30 #include <babeltrace/component/graph-internal.h>
31 #include <babeltrace/component/port-internal.h>
32 #include <babeltrace/component/component-source-internal.h>
33 #include <babeltrace/component/component-filter-internal.h>
34 #include <babeltrace/object-internal.h>
35 #include <babeltrace/compiler.h>
39 void bt_connection_destroy(struct bt_object
*obj
)
41 struct bt_connection
*connection
= container_of(obj
,
42 struct bt_connection
, base
);
45 * No bt_put on ports as a connection only holds _weak_ references
52 struct bt_connection
*bt_connection_create(
53 struct bt_graph
*graph
,
54 struct bt_port
*upstream
, struct bt_port
*downstream
)
56 struct bt_connection
*connection
= NULL
;
58 if (bt_port_get_type(upstream
) != BT_PORT_TYPE_OUTPUT
) {
61 if (bt_port_get_type(downstream
) != BT_PORT_TYPE_INPUT
) {
65 connection
= g_new0(struct bt_connection
, 1);
70 bt_object_init(connection
, bt_connection_destroy
);
71 /* Weak references are taken, see comment in header. */
72 connection
->output_port
= upstream
;
73 connection
->input_port
= downstream
;
74 bt_port_add_connection(upstream
, connection
);
75 bt_port_add_connection(downstream
, connection
);
76 bt_object_set_parent(connection
, &graph
->base
);
81 struct bt_port
*bt_connection_get_input_port(
82 struct bt_connection
*connection
)
84 return connection
? connection
->input_port
: NULL
;
87 struct bt_port
*bt_connection_get_output_port(
88 struct bt_connection
*connection
)
90 return connection
? connection
->output_port
: NULL
;
93 struct bt_notification_iterator
*
94 bt_connection_create_notification_iterator(struct bt_connection
*connection
)
96 struct bt_component
*upstream_component
= NULL
;
97 struct bt_notification_iterator
*it
= NULL
;
103 upstream_component
= bt_port_get_component(connection
->output_port
);
104 assert(upstream_component
);
106 switch (bt_component_get_class_type(upstream_component
)) {
107 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
108 it
= bt_component_source_create_notification_iterator(
111 case BT_COMPONENT_CLASS_TYPE_FILTER
:
112 it
= bt_component_filter_create_notification_iterator(
119 bt_put(upstream_component
);