Move to kernel style SPDX license identifiers
[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-pre.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 BT_HIDDEN
25 void bt_component_source_destroy(struct bt_component *component)
26 {
27 }
28
29 BT_HIDDEN
30 struct bt_component *bt_component_source_create(
31 const struct bt_component_class *class)
32 {
33 struct bt_component_source *source = NULL;
34
35 BT_ASSERT_PRE_NO_ERROR();
36
37 source = g_new0(struct bt_component_source, 1);
38 if (!source) {
39 BT_LIB_LOGE_APPEND_CAUSE(
40 "Failed to allocate one source component.");
41 goto end;
42 }
43
44 end:
45 return (void *) source;
46 }
47
48 const bt_component_class_source *
49 bt_component_source_borrow_class_const(
50 const bt_component_source *component)
51 {
52 struct bt_component_class *cls;
53
54 BT_ASSERT_PRE_DEV_NON_NULL(component, "Component");
55
56 cls = component->parent.class;
57
58 BT_ASSERT_DBG(cls);
59 BT_ASSERT_DBG(cls->type == BT_COMPONENT_CLASS_TYPE_SOURCE);
60
61 return (bt_component_class_source *) cls;
62 }
63
64 uint64_t bt_component_source_get_output_port_count(
65 const struct bt_component_source *comp)
66 {
67 return bt_component_get_output_port_count((void *) comp);
68 }
69
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 return bt_component_borrow_output_port_by_name((void *) comp, name);
75 }
76
77 struct bt_self_component_port_output *
78 bt_self_component_source_borrow_output_port_by_name(
79 struct bt_self_component_source *comp, const char *name)
80 {
81 return (void *) bt_component_borrow_output_port_by_name(
82 (void *) comp, name);
83 }
84
85 const struct bt_port_output *
86 bt_component_source_borrow_output_port_by_index_const(
87 const struct bt_component_source *comp, uint64_t index)
88 {
89 return bt_component_borrow_output_port_by_index((void *) comp, index);
90 }
91
92 struct bt_self_component_port_output *
93 bt_self_component_source_borrow_output_port_by_index(
94 struct bt_self_component_source *comp, uint64_t index)
95 {
96 return (void *) bt_component_borrow_output_port_by_index(
97 (void *) comp, index);
98 }
99
100 enum bt_self_component_add_port_status bt_self_component_source_add_output_port(
101 struct bt_self_component_source *self_comp,
102 const char *name, void *user_data,
103 struct bt_self_component_port_output **self_port)
104 {
105 struct bt_component *comp = (void *) self_comp;
106 enum bt_self_component_add_port_status status;
107 struct bt_port *port = NULL;
108
109 BT_ASSERT_PRE_NO_ERROR();
110
111 /* bt_component_add_output_port() logs details and errors */
112 status = bt_component_add_output_port(comp, name, user_data, &port);
113 if (status != BT_FUNC_STATUS_OK) {
114 goto end;
115 }
116
117 if (self_port) {
118 /* Move reference to user */
119 *self_port = (void *) port;
120 }
121
122 end:
123 bt_object_put_ref(port);
124 return status;
125 }
126
127 void bt_component_source_get_ref(
128 const struct bt_component_source *component_source)
129 {
130 bt_object_get_ref(component_source);
131 }
132
133 void bt_component_source_put_ref(
134 const struct bt_component_source *component_source)
135 {
136 bt_object_put_ref(component_source);
137 }
This page took 0.03118 seconds and 4 git commands to generate.