2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 #define BT_LOG_TAG "LIB/COMPONENT-SOURCE"
9 #include "lib/logging.h"
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>
18 #include "component-source.h"
19 #include "component.h"
21 #include "message/iterator.h"
22 #include "lib/func-status.h"
25 void bt_component_source_destroy(struct bt_component
*component
)
30 struct bt_component
*bt_component_source_create(
31 const struct bt_component_class
*class)
33 struct bt_component_source
*source
= NULL
;
35 source
= g_new0(struct bt_component_source
, 1);
37 BT_LIB_LOGE_APPEND_CAUSE(
38 "Failed to allocate one source component.");
43 return (void *) source
;
46 const bt_component_class_source
*
47 bt_component_source_borrow_class_const(
48 const bt_component_source
*component
)
50 struct bt_component_class
*cls
;
52 BT_ASSERT_PRE_DEV_COMP_NON_NULL(component
);
54 cls
= component
->parent
.class;
57 BT_ASSERT_DBG(cls
->type
== BT_COMPONENT_CLASS_TYPE_SOURCE
);
59 return (bt_component_class_source
*) cls
;
62 uint64_t bt_component_source_get_output_port_count(
63 const struct bt_component_source
*comp
)
65 /* bt_component_get_output_port_count() checks preconditions */
66 return bt_component_get_output_port_count((void *) comp
, __func__
);
69 const struct bt_port_output
*
70 bt_component_source_borrow_output_port_by_name_const(
71 const struct bt_component_source
*comp
, const char *name
)
74 * bt_component_borrow_output_port_by_name() logs details/errors
75 * and checks preconditions.
77 return bt_component_borrow_output_port_by_name((void *) comp
, name
,
81 struct bt_self_component_port_output
*
82 bt_self_component_source_borrow_output_port_by_name(
83 struct bt_self_component_source
*comp
, const char *name
)
86 * bt_component_borrow_output_port_by_name() logs details/errors
87 * and checks preconditions.
89 return (void *) bt_component_borrow_output_port_by_name(
90 (void *) comp
, name
, __func__
);
93 const struct bt_port_output
*
94 bt_component_source_borrow_output_port_by_index_const(
95 const struct bt_component_source
*comp
, uint64_t index
)
98 * bt_component_borrow_output_port_by_index() logs
99 * details/errors and checks preconditions.
101 return bt_component_borrow_output_port_by_index((void *) comp
, index
,
105 struct bt_self_component_port_output
*
106 bt_self_component_source_borrow_output_port_by_index(
107 struct bt_self_component_source
*comp
, uint64_t index
)
110 * bt_component_borrow_output_port_by_index() logs
111 * details/errors and checks preconditions.
113 return (void *) bt_component_borrow_output_port_by_index(
114 (void *) comp
, index
, __func__
);
117 enum bt_self_component_add_port_status
bt_self_component_source_add_output_port(
118 struct bt_self_component_source
*self_comp
,
119 const char *name
, void *user_data
,
120 struct bt_self_component_port_output
**self_port
)
122 struct bt_component
*comp
= (void *) self_comp
;
123 enum bt_self_component_add_port_status status
;
124 struct bt_port
*port
= NULL
;
126 BT_ASSERT_PRE_NO_ERROR();
127 BT_ASSERT_PRE_OUTPUT_PORT_NAME_UNIQUE(comp
, name
);
130 * bt_component_add_output_port() logs details/errors and checks
133 status
= bt_component_add_output_port(comp
, name
, user_data
, &port
,
135 if (status
!= BT_FUNC_STATUS_OK
) {
140 /* Move reference to user */
141 *self_port
= (void *) port
;
145 bt_object_put_ref(port
);
149 void bt_component_source_get_ref(
150 const struct bt_component_source
*component_source
)
152 bt_object_get_ref(component_source
);
155 void bt_component_source_put_ref(
156 const struct bt_component_source
*component_source
)
158 bt_object_put_ref(component_source
);