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