lib: assign a unique ID to each pre/postcond. and report it on failure
[babeltrace.git] / src / lib / graph / component-source.c
CommitLineData
d94d92ac 1/*
0235b0db
MJ
2 * SPDX-License-Identifier: MIT
3 *
e2f7325d 4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
d94d92ac 5 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
d94d92ac
PP
6 */
7
350ad6c1 8#define BT_LOG_TAG "LIB/COMPONENT-SOURCE"
c2d9d9cf 9#include "lib/logging.h"
d94d92ac 10
578e048b 11#include "common/assert.h"
d98421f2 12#include "lib/assert-cond.h"
578e048b 13#include "compat/compiler.h"
43c59509
PP
14#include <babeltrace2/graph/self-component.h>
15#include <babeltrace2/graph/component.h>
3fadfbc0 16#include <babeltrace2/graph/graph.h>
d94d92ac 17
578e048b
MJ
18#include "component-source.h"
19#include "component.h"
20#include "port.h"
21#include "message/iterator.h"
d24d5663 22#include "lib/func-status.h"
578e048b 23
d94d92ac
PP
24BT_HIDDEN
25void bt_component_source_destroy(struct bt_component *component)
26{
27}
28
29BT_HIDDEN
30struct bt_component *bt_component_source_create(
0d72b8c3 31 const struct bt_component_class *class)
d94d92ac
PP
32{
33 struct bt_component_source *source = NULL;
34
35 source = g_new0(struct bt_component_source, 1);
36 if (!source) {
870631a2
PP
37 BT_LIB_LOGE_APPEND_CAUSE(
38 "Failed to allocate one source component.");
d94d92ac
PP
39 goto end;
40 }
41
42end:
43 return (void *) source;
44}
45
752d0e47
SM
46const bt_component_class_source *
47bt_component_source_borrow_class_const(
48 const bt_component_source *component)
49{
50 struct bt_component_class *cls;
51
d5b13b9b 52 BT_ASSERT_PRE_DEV_COMP_NON_NULL(component);
752d0e47
SM
53
54 cls = component->parent.class;
55
98b15851
PP
56 BT_ASSERT_DBG(cls);
57 BT_ASSERT_DBG(cls->type == BT_COMPONENT_CLASS_TYPE_SOURCE);
752d0e47
SM
58
59 return (bt_component_class_source *) cls;
60}
61
d94d92ac 62uint64_t bt_component_source_get_output_port_count(
0d72b8c3 63 const struct bt_component_source *comp)
d94d92ac 64{
1778c2a4
PP
65 /* bt_component_get_output_port_count() checks preconditions */
66 return bt_component_get_output_port_count((void *) comp, __func__);
d94d92ac
PP
67}
68
0d72b8c3
PP
69const struct bt_port_output *
70bt_component_source_borrow_output_port_by_name_const(
71 const struct bt_component_source *comp, const char *name)
d94d92ac 72{
1778c2a4
PP
73 /*
74 * bt_component_borrow_output_port_by_name() logs details/errors
75 * and checks preconditions.
76 */
77 return bt_component_borrow_output_port_by_name((void *) comp, name,
78 __func__);
d94d92ac
PP
79}
80
81struct bt_self_component_port_output *
82bt_self_component_source_borrow_output_port_by_name(
83 struct bt_self_component_source *comp, const char *name)
84{
1778c2a4
PP
85 /*
86 * bt_component_borrow_output_port_by_name() logs details/errors
87 * and checks preconditions.
88 */
d94d92ac 89 return (void *) bt_component_borrow_output_port_by_name(
1778c2a4 90 (void *) comp, name, __func__);
d94d92ac
PP
91}
92
0d72b8c3
PP
93const struct bt_port_output *
94bt_component_source_borrow_output_port_by_index_const(
95 const struct bt_component_source *comp, uint64_t index)
d94d92ac 96{
1778c2a4
PP
97 /*
98 * bt_component_borrow_output_port_by_index() logs
99 * details/errors and checks preconditions.
100 */
101 return bt_component_borrow_output_port_by_index((void *) comp, index,
102 __func__);
d94d92ac
PP
103}
104
105struct bt_self_component_port_output *
106bt_self_component_source_borrow_output_port_by_index(
107 struct bt_self_component_source *comp, uint64_t index)
108{
1778c2a4
PP
109 /*
110 * bt_component_borrow_output_port_by_index() logs
111 * details/errors and checks preconditions.
112 */
d94d92ac 113 return (void *) bt_component_borrow_output_port_by_index(
1778c2a4 114 (void *) comp, index, __func__);
d94d92ac
PP
115}
116
d24d5663 117enum bt_self_component_add_port_status bt_self_component_source_add_output_port(
d94d92ac
PP
118 struct bt_self_component_source *self_comp,
119 const char *name, void *user_data,
120 struct bt_self_component_port_output **self_port)
121{
122 struct bt_component *comp = (void *) self_comp;
d24d5663 123 enum bt_self_component_add_port_status status;
d94d92ac
PP
124 struct bt_port *port = NULL;
125
17f3083a 126 BT_ASSERT_PRE_NO_ERROR();
157a98ed 127 BT_ASSERT_PRE_OUTPUT_PORT_NAME_UNIQUE(comp, name);
17f3083a 128
1778c2a4
PP
129 /*
130 * bt_component_add_output_port() logs details/errors and checks
131 * preconditions.
132 */
133 status = bt_component_add_output_port(comp, name, user_data, &port,
134 __func__);
d24d5663 135 if (status != BT_FUNC_STATUS_OK) {
d94d92ac
PP
136 goto end;
137 }
138
139 if (self_port) {
140 /* Move reference to user */
141 *self_port = (void *) port;
d94d92ac
PP
142 }
143
144end:
145 bt_object_put_ref(port);
146 return status;
147}
c5b9b441
PP
148
149void bt_component_source_get_ref(
150 const struct bt_component_source *component_source)
151{
152 bt_object_get_ref(component_source);
153}
154
155void bt_component_source_put_ref(
156 const struct bt_component_source *component_source)
157{
158 bt_object_put_ref(component_source);
159}
This page took 0.063047 seconds and 4 git commands to generate.