Logging: standardize logging tags
[babeltrace.git] / src / lib / graph / port.c
CommitLineData
8b285017 1/*
e2f7325d 2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
8b285017 3 * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8b285017
JG
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
350ad6c1 24#define BT_LOG_TAG "LIB/PORT"
578e048b 25#include "lib/lib-logging.h"
f3034355 26
578e048b
MJ
27#include "common/assert.h"
28#include "lib/assert-pre.h"
3fadfbc0
MJ
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>
578e048b
MJ
35#include "lib/object.h"
36#include "compat/compiler.h"
37
38#include "component.h"
39#include "connection.h"
40#include "port.h"
8b285017
JG
41
42static
d94d92ac 43void destroy_port(struct bt_object *obj)
8b285017 44{
d94d92ac 45 struct bt_port *port = (void *) obj;
8b285017 46
3f7d4d90 47 BT_LIB_LOGI("Destroying port: %!+p", port);
f3034355 48
8b285017
JG
49 if (port->name) {
50 g_string_free(port->name, TRUE);
d94d92ac 51 port->name = NULL;
8b285017 52 }
f3034355 53
8b285017
JG
54 g_free(port);
55}
56
57BT_HIDDEN
58struct bt_port *bt_port_create(struct bt_component *parent_component,
3e9b0023 59 enum bt_port_type type, const char *name, void *user_data)
8b285017 60{
72b913fb 61 struct bt_port *port = NULL;
8b285017 62
f6ccaed9
PP
63 BT_ASSERT(name);
64 BT_ASSERT(parent_component);
65 BT_ASSERT(type == BT_PORT_TYPE_INPUT || type == BT_PORT_TYPE_OUTPUT);
d94d92ac 66 BT_ASSERT(strlen(name) > 0);
8b285017
JG
67 port = g_new0(struct bt_port, 1);
68 if (!port) {
f3034355 69 BT_LOGE_STR("Failed to allocate one port.");
8b285017
JG
70 goto end;
71 }
72
3f7d4d90 73 BT_LIB_LOGI("Creating port for component: %![comp-]+c, port-type=%s, "
d94d92ac
PP
74 "port-name=\"%s\"", parent_component, bt_port_type_string(type),
75 name);
76 bt_object_init_shared_with_parent(&port->base, destroy_port);
8b285017
JG
77 port->name = g_string_new(name);
78 if (!port->name) {
f3034355 79 BT_LOGE_STR("Failed to allocate one GString.");
65300d60 80 BT_OBJECT_PUT_REF_AND_RESET(port);
8b285017
JG
81 goto end;
82 }
83
84 port->type = type;
3e9b0023 85 port->user_data = user_data;
3fea54f6 86 bt_object_set_parent(&port->base, &parent_component->base);
3f7d4d90 87 BT_LIB_LOGI("Created port for component: "
d94d92ac 88 "%![comp-]+c, %![port-]+p", parent_component, port);
f3034355 89
8b285017
JG
90end:
91 return port;
92}
93
0d72b8c3 94const char *bt_port_get_name(const struct bt_port *port)
8b285017 95{
d94d92ac
PP
96 BT_ASSERT_PRE_NON_NULL(port, "Port");
97 return port->name->str;
8b285017
JG
98}
99
0d72b8c3 100enum bt_port_type bt_port_get_type(const struct bt_port *port)
8b285017 101{
d94d92ac
PP
102 BT_ASSERT_PRE_NON_NULL(port, "Port");
103 return port->type;
8b285017
JG
104}
105
0d72b8c3
PP
106const struct bt_connection *bt_port_borrow_connection_const(
107 const struct bt_port *port)
8b285017 108{
d94d92ac
PP
109 BT_ASSERT_PRE_NON_NULL(port, "Port");
110 return port->connection;
8b285017
JG
111}
112
0d72b8c3
PP
113const struct bt_component *bt_port_borrow_component_const(
114 const struct bt_port *port)
890882ef 115{
d94d92ac 116 BT_ASSERT_PRE_NON_NULL(port, "Port");
0d72b8c3 117 return bt_port_borrow_component_inline(port);
890882ef
PP
118}
119
d94d92ac
PP
120struct bt_self_component *bt_self_component_port_borrow_component(
121 struct bt_self_component_port *port)
890882ef 122{
d94d92ac
PP
123 BT_ASSERT_PRE_NON_NULL(port, "Port");
124 return (void *) bt_object_borrow_parent((void *) port);
890882ef
PP
125}
126
8b285017 127BT_HIDDEN
72b913fb 128void bt_port_set_connection(struct bt_port *port,
8b285017 129 struct bt_connection *connection)
72b913fb
PP
130{
131 /*
132 * Don't take a reference on connection as its existence is
133 * guaranteed by the existence of the graph in which the
134 * connection exists.
135 */
136 port->connection = connection;
3f7d4d90 137 BT_LIB_LOGI("Set port's connection: %![port-]+p, %![conn-]+x", port,
d94d92ac 138 connection);
72b913fb
PP
139}
140
0d72b8c3 141bt_bool bt_port_is_connected(const struct bt_port *port)
8b285017 142{
d94d92ac
PP
143 BT_ASSERT_PRE_NON_NULL(port, "Port");
144 return port->connection ? BT_TRUE : BT_FALSE;
8b285017 145}
a45a0b60 146
0d72b8c3 147void *bt_self_component_port_get_data(const struct bt_self_component_port *port)
a45a0b60 148{
d94d92ac
PP
149 BT_ASSERT_PRE_NON_NULL(port, "Port");
150 return ((struct bt_port *) port)->user_data;
a45a0b60 151}
c5b9b441
PP
152
153void bt_port_get_ref(const struct bt_port *port)
154{
155 bt_object_get_ref(port);
156}
157
158void bt_port_put_ref(const struct bt_port *port)
159{
160 bt_object_put_ref(port);
161}
162
163void bt_port_input_get_ref(const struct bt_port_input *port_input)
164{
165 bt_object_get_ref(port_input);
166}
167
168void bt_port_input_put_ref(const struct bt_port_input *port_input)
169{
170 bt_object_put_ref(port_input);
171}
172
173void bt_port_output_get_ref(const struct bt_port_output *port_output)
174{
175 bt_object_get_ref(port_output);
176}
177
178void bt_port_output_put_ref(const struct bt_port_output *port_output)
179{
180 bt_object_put_ref(port_output);
181}
This page took 0.049267 seconds and 4 git commands to generate.