Commit | Line | Data |
---|---|---|
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 | |
ecd7492f MJ |
24 | void bt_component_source_destroy( |
25 | struct bt_component *component __attribute__((unused))) | |
d94d92ac PP |
26 | { |
27 | } | |
28 | ||
d94d92ac | 29 | struct bt_component *bt_component_source_create( |
ecd7492f | 30 | const struct bt_component_class *class __attribute__((unused))) |
d94d92ac PP |
31 | { |
32 | struct bt_component_source *source = NULL; | |
33 | ||
34 | source = g_new0(struct bt_component_source, 1); | |
35 | if (!source) { | |
870631a2 PP |
36 | BT_LIB_LOGE_APPEND_CAUSE( |
37 | "Failed to allocate one source component."); | |
d94d92ac PP |
38 | goto end; |
39 | } | |
40 | ||
41 | end: | |
42 | return (void *) source; | |
43 | } | |
44 | ||
1353b066 | 45 | BT_EXPORT |
752d0e47 SM |
46 | const bt_component_class_source * |
47 | bt_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 | ||
1353b066 | 62 | BT_EXPORT |
d94d92ac | 63 | uint64_t bt_component_source_get_output_port_count( |
0d72b8c3 | 64 | const struct bt_component_source *comp) |
d94d92ac | 65 | { |
1778c2a4 PP |
66 | /* bt_component_get_output_port_count() checks preconditions */ |
67 | return bt_component_get_output_port_count((void *) comp, __func__); | |
d94d92ac PP |
68 | } |
69 | ||
1353b066 | 70 | BT_EXPORT |
0d72b8c3 PP |
71 | const struct bt_port_output * |
72 | bt_component_source_borrow_output_port_by_name_const( | |
73 | const struct bt_component_source *comp, const char *name) | |
d94d92ac | 74 | { |
1778c2a4 PP |
75 | /* |
76 | * bt_component_borrow_output_port_by_name() logs details/errors | |
77 | * and checks preconditions. | |
78 | */ | |
79 | return bt_component_borrow_output_port_by_name((void *) comp, name, | |
80 | __func__); | |
d94d92ac PP |
81 | } |
82 | ||
1353b066 | 83 | BT_EXPORT |
d94d92ac PP |
84 | struct bt_self_component_port_output * |
85 | bt_self_component_source_borrow_output_port_by_name( | |
86 | struct bt_self_component_source *comp, const char *name) | |
87 | { | |
1778c2a4 PP |
88 | /* |
89 | * bt_component_borrow_output_port_by_name() logs details/errors | |
90 | * and checks preconditions. | |
91 | */ | |
d94d92ac | 92 | return (void *) bt_component_borrow_output_port_by_name( |
1778c2a4 | 93 | (void *) comp, name, __func__); |
d94d92ac PP |
94 | } |
95 | ||
1353b066 | 96 | BT_EXPORT |
0d72b8c3 PP |
97 | const struct bt_port_output * |
98 | bt_component_source_borrow_output_port_by_index_const( | |
99 | const struct bt_component_source *comp, uint64_t index) | |
d94d92ac | 100 | { |
1778c2a4 PP |
101 | /* |
102 | * bt_component_borrow_output_port_by_index() logs | |
103 | * details/errors and checks preconditions. | |
104 | */ | |
105 | return bt_component_borrow_output_port_by_index((void *) comp, index, | |
106 | __func__); | |
d94d92ac PP |
107 | } |
108 | ||
1353b066 | 109 | BT_EXPORT |
d94d92ac PP |
110 | struct bt_self_component_port_output * |
111 | bt_self_component_source_borrow_output_port_by_index( | |
112 | struct bt_self_component_source *comp, uint64_t index) | |
113 | { | |
1778c2a4 PP |
114 | /* |
115 | * bt_component_borrow_output_port_by_index() logs | |
116 | * details/errors and checks preconditions. | |
117 | */ | |
d94d92ac | 118 | return (void *) bt_component_borrow_output_port_by_index( |
1778c2a4 | 119 | (void *) comp, index, __func__); |
d94d92ac PP |
120 | } |
121 | ||
1353b066 | 122 | BT_EXPORT |
d24d5663 | 123 | enum bt_self_component_add_port_status bt_self_component_source_add_output_port( |
d94d92ac PP |
124 | struct bt_self_component_source *self_comp, |
125 | const char *name, void *user_data, | |
126 | struct bt_self_component_port_output **self_port) | |
127 | { | |
128 | struct bt_component *comp = (void *) self_comp; | |
d24d5663 | 129 | enum bt_self_component_add_port_status status; |
d94d92ac PP |
130 | struct bt_port *port = NULL; |
131 | ||
1778c2a4 PP |
132 | /* |
133 | * bt_component_add_output_port() logs details/errors and checks | |
134 | * preconditions. | |
135 | */ | |
136 | status = bt_component_add_output_port(comp, name, user_data, &port, | |
137 | __func__); | |
d24d5663 | 138 | if (status != BT_FUNC_STATUS_OK) { |
d94d92ac PP |
139 | goto end; |
140 | } | |
141 | ||
142 | if (self_port) { | |
143 | /* Move reference to user */ | |
144 | *self_port = (void *) port; | |
d94d92ac PP |
145 | } |
146 | ||
147 | end: | |
148 | bt_object_put_ref(port); | |
149 | return status; | |
150 | } | |
c5b9b441 | 151 | |
1353b066 | 152 | BT_EXPORT |
c5b9b441 PP |
153 | void bt_component_source_get_ref( |
154 | const struct bt_component_source *component_source) | |
155 | { | |
156 | bt_object_get_ref(component_source); | |
157 | } | |
158 | ||
1353b066 | 159 | BT_EXPORT |
c5b9b441 PP |
160 | void bt_component_source_put_ref( |
161 | const struct bt_component_source *component_source) | |
162 | { | |
163 | bt_object_put_ref(component_source); | |
164 | } |