Fix: lib: add NULL check for destroy_listeners in destroy_component_class
[babeltrace.git] / src / lib / graph / component-sink.c
... / ...
CommitLineData
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-SINK"
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/value.h>
15#include <babeltrace2/graph/self-component.h>
16#include <babeltrace2/graph/component.h>
17#include <babeltrace2/graph/graph.h>
18
19#include "component-sink.h"
20#include "component.h"
21#include "graph.h"
22#include "lib/func-status.h"
23
24BT_HIDDEN
25void bt_component_sink_destroy(struct bt_component *component)
26{
27}
28
29BT_HIDDEN
30struct bt_component *bt_component_sink_create(
31 const struct bt_component_class *class)
32{
33 struct bt_component_sink *sink = NULL;
34
35 sink = g_new0(struct bt_component_sink, 1);
36 if (!sink) {
37 BT_LIB_LOGE_APPEND_CAUSE(
38 "Failed to allocate one sink component.");
39 goto end;
40 }
41
42end:
43 return (void *) sink;
44}
45
46const bt_component_class_sink *
47bt_component_sink_borrow_class_const(
48 const bt_component_sink *component)
49{
50 struct bt_component_class *cls;
51
52 BT_ASSERT_PRE_DEV_COMP_NON_NULL(component);
53
54 cls = component->parent.class;
55
56 BT_ASSERT_DBG(cls);
57 BT_ASSERT_DBG(cls->type == BT_COMPONENT_CLASS_TYPE_SINK);
58
59 return (bt_component_class_sink *) cls;
60}
61
62uint64_t bt_component_sink_get_input_port_count(
63 const struct bt_component_sink *component)
64{
65 /* bt_component_get_input_port_count() checks preconditions */
66 return bt_component_get_input_port_count((void *) component, __func__);
67}
68
69const struct bt_port_input *
70bt_component_sink_borrow_input_port_by_name_const(
71 const struct bt_component_sink *component, const char *name)
72{
73 /*
74 * bt_component_borrow_input_port_by_name() logs details/errors
75 * and checks preconditions.
76 */
77 return bt_component_borrow_input_port_by_name((void *) component, name,
78 __func__);
79}
80
81struct bt_self_component_port_input *
82bt_self_component_sink_borrow_input_port_by_name(
83 struct bt_self_component_sink *component, const char *name)
84{
85 /*
86 * bt_component_borrow_input_port_by_name() logs details/errors
87 * and checks preconditions.
88 */
89 return (void *) bt_component_borrow_input_port_by_name(
90 (void *) component, name, __func__);
91}
92
93const struct bt_port_input *bt_component_sink_borrow_input_port_by_index_const(
94 const struct bt_component_sink *component, uint64_t index)
95{
96 /*
97 * bt_component_borrow_input_port_by_index() logs details/errors
98 * and checks preconditions.
99 */
100 return bt_component_borrow_input_port_by_index(
101 (void *) component, index, __func__);
102}
103
104struct bt_self_component_port_input *
105bt_self_component_sink_borrow_input_port_by_index(
106 struct bt_self_component_sink *component, uint64_t index)
107{
108 /*
109 * bt_component_borrow_input_port_by_index() logs details/errors
110 * and checks preconditions.
111 */
112 return (void *) bt_component_borrow_input_port_by_index(
113 (void *) component, index, __func__);
114}
115
116enum bt_self_component_add_port_status bt_self_component_sink_add_input_port(
117 struct bt_self_component_sink *self_comp,
118 const char *name, void *user_data,
119 struct bt_self_component_port_input **self_port)
120{
121 enum bt_self_component_add_port_status status;
122 struct bt_port *port = NULL;
123 struct bt_component *comp = (void *) self_comp;
124
125 BT_ASSERT_PRE_NO_ERROR();
126
127 /*
128 * bt_component_add_input_port() logs details/errors and checks
129 * preconditions.
130 */
131 status = bt_component_add_input_port(comp, name, user_data, &port,
132 __func__);
133 if (status != BT_FUNC_STATUS_OK) {
134 goto end;
135 }
136
137 if (self_port) {
138 /* Move reference to user */
139 *self_port = (void *) port;
140 }
141
142end:
143 bt_object_put_ref(port);
144 return status;
145}
146
147bt_bool bt_self_component_sink_is_interrupted(
148 const struct bt_self_component_sink *self_comp)
149{
150 struct bt_component *comp = (void *) self_comp;
151
152 BT_ASSERT_PRE_COMP_NON_NULL(comp);
153 return (bt_bool) bt_graph_is_interrupted(
154 bt_component_borrow_graph(comp));
155}
156
157void bt_component_sink_get_ref(
158 const struct bt_component_sink *component_sink)
159{
160 bt_object_get_ref(component_sink);
161}
162
163void bt_component_sink_put_ref(
164 const struct bt_component_sink *component_sink)
165{
166 bt_object_put_ref(component_sink);
167}
This page took 0.023566 seconds and 4 git commands to generate.