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