tap-driver.sh: flush stdout after each test result
[babeltrace.git] / lib / graph / port.c
1 /*
2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #define BT_LOG_TAG "PORT"
25 #include <babeltrace2/lib-logging-internal.h>
26
27 #include <babeltrace2/assert-internal.h>
28 #include <babeltrace2/assert-pre-internal.h>
29 #include <babeltrace2/graph/port-const.h>
30 #include <babeltrace2/graph/port-input-const.h>
31 #include <babeltrace2/graph/port-output-const.h>
32 #include <babeltrace2/graph/self-component-port.h>
33 #include <babeltrace2/graph/self-component-port-input.h>
34 #include <babeltrace2/graph/self-component-port-output.h>
35 #include <babeltrace2/graph/component-internal.h>
36 #include <babeltrace2/graph/port-internal.h>
37 #include <babeltrace2/graph/connection-internal.h>
38 #include <babeltrace2/object-internal.h>
39 #include <babeltrace2/compiler-internal.h>
40
41 static
42 void destroy_port(struct bt_object *obj)
43 {
44 struct bt_port *port = (void *) obj;
45
46 BT_LIB_LOGD("Destroying port: %!+p", port);
47
48 if (port->name) {
49 g_string_free(port->name, TRUE);
50 port->name = NULL;
51 }
52
53 g_free(port);
54 }
55
56 BT_HIDDEN
57 struct bt_port *bt_port_create(struct bt_component *parent_component,
58 enum bt_port_type type, const char *name, void *user_data)
59 {
60 struct bt_port *port = NULL;
61
62 BT_ASSERT(name);
63 BT_ASSERT(parent_component);
64 BT_ASSERT(type == BT_PORT_TYPE_INPUT || type == BT_PORT_TYPE_OUTPUT);
65 BT_ASSERT(strlen(name) > 0);
66 port = g_new0(struct bt_port, 1);
67 if (!port) {
68 BT_LOGE_STR("Failed to allocate one port.");
69 goto end;
70 }
71
72 BT_LIB_LOGD("Creating port for component: %![comp-]+c, port-type=%s, "
73 "port-name=\"%s\"", parent_component, bt_port_type_string(type),
74 name);
75 bt_object_init_shared_with_parent(&port->base, destroy_port);
76 port->name = g_string_new(name);
77 if (!port->name) {
78 BT_LOGE_STR("Failed to allocate one GString.");
79 BT_OBJECT_PUT_REF_AND_RESET(port);
80 goto end;
81 }
82
83 port->type = type;
84 port->user_data = user_data;
85 bt_object_set_parent(&port->base, &parent_component->base);
86 BT_LIB_LOGD("Created port for component: "
87 "%![comp-]+c, %![port-]+p", parent_component, port);
88
89 end:
90 return port;
91 }
92
93 const char *bt_port_get_name(const struct bt_port *port)
94 {
95 BT_ASSERT_PRE_NON_NULL(port, "Port");
96 return port->name->str;
97 }
98
99 enum bt_port_type bt_port_get_type(const struct bt_port *port)
100 {
101 BT_ASSERT_PRE_NON_NULL(port, "Port");
102 return port->type;
103 }
104
105 const struct bt_connection *bt_port_borrow_connection_const(
106 const struct bt_port *port)
107 {
108 BT_ASSERT_PRE_NON_NULL(port, "Port");
109 return port->connection;
110 }
111
112 const struct bt_component *bt_port_borrow_component_const(
113 const struct bt_port *port)
114 {
115 BT_ASSERT_PRE_NON_NULL(port, "Port");
116 return bt_port_borrow_component_inline(port);
117 }
118
119 struct bt_self_component *bt_self_component_port_borrow_component(
120 struct bt_self_component_port *port)
121 {
122 BT_ASSERT_PRE_NON_NULL(port, "Port");
123 return (void *) bt_object_borrow_parent((void *) port);
124 }
125
126 BT_HIDDEN
127 void bt_port_set_connection(struct bt_port *port,
128 struct bt_connection *connection)
129 {
130 /*
131 * Don't take a reference on connection as its existence is
132 * guaranteed by the existence of the graph in which the
133 * connection exists.
134 */
135 port->connection = connection;
136 BT_LIB_LOGV("Set port's connection: %![port-]+p, %![conn-]+x", port,
137 connection);
138 }
139
140 bt_bool bt_port_is_connected(const struct bt_port *port)
141 {
142 BT_ASSERT_PRE_NON_NULL(port, "Port");
143 return port->connection ? BT_TRUE : BT_FALSE;
144 }
145
146 void *bt_self_component_port_get_data(const struct bt_self_component_port *port)
147 {
148 BT_ASSERT_PRE_NON_NULL(port, "Port");
149 return ((struct bt_port *) port)->user_data;
150 }
151
152 void bt_port_get_ref(const struct bt_port *port)
153 {
154 bt_object_get_ref(port);
155 }
156
157 void bt_port_put_ref(const struct bt_port *port)
158 {
159 bt_object_put_ref(port);
160 }
161
162 void bt_port_input_get_ref(const struct bt_port_input *port_input)
163 {
164 bt_object_get_ref(port_input);
165 }
166
167 void bt_port_input_put_ref(const struct bt_port_input *port_input)
168 {
169 bt_object_put_ref(port_input);
170 }
171
172 void bt_port_output_get_ref(const struct bt_port_output *port_output)
173 {
174 bt_object_get_ref(port_output);
175 }
176
177 void bt_port_output_put_ref(const struct bt_port_output *port_output)
178 {
179 bt_object_put_ref(port_output);
180 }
This page took 0.032975 seconds and 4 git commands to generate.