Move to kernel style SPDX license identifiers
[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-pre.h"
13#include "lib/assert-post.h"
14#include "compat/compiler.h"
15#include <babeltrace2/value.h>
16#include <babeltrace2/graph/self-component.h>
17#include <babeltrace2/graph/component.h>
18#include <babeltrace2/graph/graph.h>
19
20#include "component-sink.h"
21#include "component.h"
22#include "graph.h"
23#include "lib/func-status.h"
24
25BT_HIDDEN
26void bt_component_sink_destroy(struct bt_component *component)
27{
28}
29
30BT_HIDDEN
31struct bt_component *bt_component_sink_create(
32 const struct bt_component_class *class)
33{
34 struct bt_component_sink *sink = NULL;
35
36 BT_ASSERT_PRE_NO_ERROR();
37
38 sink = g_new0(struct bt_component_sink, 1);
39 if (!sink) {
40 BT_LIB_LOGE_APPEND_CAUSE(
41 "Failed to allocate one sink component.");
42 goto end;
43 }
44
45end:
46 return (void *) sink;
47}
48
49const bt_component_class_sink *
50bt_component_sink_borrow_class_const(
51 const bt_component_sink *component)
52{
53 struct bt_component_class *cls;
54
55 BT_ASSERT_PRE_DEV_NON_NULL(component, "Component");
56
57 cls = component->parent.class;
58
59 BT_ASSERT_DBG(cls);
60 BT_ASSERT_DBG(cls->type == BT_COMPONENT_CLASS_TYPE_SINK);
61
62 return (bt_component_class_sink *) cls;
63}
64
65uint64_t bt_component_sink_get_input_port_count(
66 const struct bt_component_sink *component)
67{
68 /* bt_component_get_input_port_count() logs details/errors */
69 return bt_component_get_input_port_count((void *) component);
70}
71
72const struct bt_port_input *
73bt_component_sink_borrow_input_port_by_name_const(
74 const struct bt_component_sink *component, const char *name)
75{
76 /* bt_component_borrow_input_port_by_name() logs details/errors */
77 return bt_component_borrow_input_port_by_name((void *) component, name);
78}
79
80struct bt_self_component_port_input *
81bt_self_component_sink_borrow_input_port_by_name(
82 struct bt_self_component_sink *component, const char *name)
83{
84 /* bt_component_borrow_input_port_by_name() logs details/errors */
85 return (void *) bt_component_borrow_input_port_by_name(
86 (void *) component, name);
87}
88
89const struct bt_port_input *bt_component_sink_borrow_input_port_by_index_const(
90 const struct bt_component_sink *component, uint64_t index)
91{
92 /* bt_component_borrow_input_port_by_index() logs details/errors */
93 return bt_component_borrow_input_port_by_index(
94 (void *) component, index);
95}
96
97struct bt_self_component_port_input *
98bt_self_component_sink_borrow_input_port_by_index(
99 struct bt_self_component_sink *component, uint64_t index)
100{
101 /* bt_component_borrow_input_port_by_index() logs details/errors */
102 return (void *) bt_component_borrow_input_port_by_index(
103 (void *) component, index);
104}
105
106enum bt_self_component_add_port_status bt_self_component_sink_add_input_port(
107 struct bt_self_component_sink *self_comp,
108 const char *name, void *user_data,
109 struct bt_self_component_port_input **self_port)
110{
111 enum bt_self_component_add_port_status status;
112 struct bt_port *port = NULL;
113 struct bt_component *comp = (void *) self_comp;
114
115 BT_ASSERT_PRE_NO_ERROR();
116
117 /* bt_component_add_input_port() logs details/errors */
118 status = bt_component_add_input_port(comp, name, user_data, &port);
119 if (status != BT_FUNC_STATUS_OK) {
120 goto end;
121 }
122
123 if (self_port) {
124 /* Move reference to user */
125 *self_port = (void *) port;
126 }
127
128end:
129 bt_object_put_ref(port);
130 return status;
131}
132
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
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.022447 seconds and 4 git commands to generate.