sink.utils.dummy: remove unnecessary check in dummy_consume()
[babeltrace.git] / src / plugins / utils / dummy / dummy.c
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
5 */
6
7#define BT_COMP_LOG_SELF_COMP self_comp
8#define BT_LOG_OUTPUT_LEVEL log_level
9#define BT_LOG_TAG "PLUGIN/SINK.UTILS.DUMMY"
10#include "logging/comp-logging.h"
11
12#include <babeltrace2/babeltrace.h>
13#include "common/macros.h"
14#include "common/assert.h"
15#include "dummy.h"
16#include "plugins/common/param-validation/param-validation.h"
17
18static
19const char * const in_port_name = "in";
20
21static
22void destroy_private_dummy_data(struct dummy *dummy)
23{
24 bt_message_iterator_put_ref(dummy->msg_iter);
25 g_free(dummy);
26
27}
28
29void dummy_finalize(bt_self_component_sink *comp)
30{
31 struct dummy *dummy;
32
33 BT_ASSERT(comp);
34 dummy = bt_self_component_get_data(
35 bt_self_component_sink_as_self_component(comp));
36 BT_ASSERT(dummy);
37 destroy_private_dummy_data(dummy);
38}
39
40static
41struct bt_param_validation_map_value_entry_descr dummy_params[] = {
42 BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
43};
44
45bt_component_class_initialize_method_status dummy_init(
46 bt_self_component_sink *self_comp_sink,
47 bt_self_component_sink_configuration *config __attribute__((unused)),
48 const bt_value *params,
49 void *init_method_data __attribute__((unused)))
50{
51 bt_self_component *self_comp =
52 bt_self_component_sink_as_self_component(self_comp_sink);
53 const bt_component *comp = bt_self_component_as_component(self_comp);
54 bt_logging_level log_level = bt_component_get_logging_level(comp);
55 bt_component_class_initialize_method_status status;
56 bt_self_component_add_port_status add_port_status;
57 struct dummy *dummy = g_new0(struct dummy, 1);
58 enum bt_param_validation_status validation_status;
59 gchar *validate_error = NULL;
60
61 if (!dummy) {
62 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
63 goto end;
64 }
65
66 validation_status = bt_param_validation_validate(params,
67 dummy_params, &validate_error);
68 if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) {
69 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
70 goto error;
71 } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) {
72 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
73 BT_COMP_LOGE_APPEND_CAUSE(self_comp, "%s", validate_error);
74 goto error;
75 }
76
77 add_port_status = bt_self_component_sink_add_input_port(self_comp_sink,
78 "in", NULL, NULL);
79 if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) {
80 status = (int) add_port_status;
81 goto error;
82 }
83
84 bt_self_component_set_data(self_comp, dummy);
85
86 status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
87 goto end;
88
89error:
90 destroy_private_dummy_data(dummy);
91
92end:
93 g_free(validate_error);
94
95 return status;
96}
97
98bt_component_class_sink_graph_is_configured_method_status dummy_graph_is_configured(
99 bt_self_component_sink *comp)
100{
101 bt_component_class_sink_graph_is_configured_method_status status;
102 bt_message_iterator_create_from_sink_component_status
103 msg_iter_status;
104 struct dummy *dummy;
105 bt_message_iterator *iterator;
106
107 dummy = bt_self_component_get_data(
108 bt_self_component_sink_as_self_component(comp));
109 BT_ASSERT(dummy);
110 msg_iter_status = bt_message_iterator_create_from_sink_component(
111 comp, bt_self_component_sink_borrow_input_port_by_name(comp,
112 in_port_name), &iterator);
113 if (msg_iter_status != BT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
114 status = (int) msg_iter_status;
115 goto end;
116 }
117
118 BT_MESSAGE_ITERATOR_MOVE_REF(
119 dummy->msg_iter, iterator);
120
121 status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
122
123end:
124 return status;
125}
126
127bt_component_class_sink_consume_method_status dummy_consume(
128 bt_self_component_sink *component)
129{
130 bt_message_array_const msgs;
131 uint64_t count;
132 struct dummy *dummy;
133 bt_message_iterator_next_status next_status;
134 uint64_t i;
135 bt_self_component *self_comp =
136 bt_self_component_sink_as_self_component(component);
137
138 dummy = bt_self_component_get_data(self_comp);
139 BT_ASSERT_DBG(dummy);
140 BT_ASSERT_DBG(dummy->msg_iter);
141
142 /* Consume one message */
143 next_status = bt_message_iterator_next(
144 dummy->msg_iter, &msgs, &count);
145 switch (next_status) {
146 case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK:
147 for (i = 0; i < count; i++) {
148 bt_message_put_ref(msgs[i]);
149 }
150
151 break;
152 case BT_MESSAGE_ITERATOR_NEXT_STATUS_ERROR:
153 case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
154 BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_COMPONENT(
155 self_comp,
156 "Failed to get messages from upstream component");
157 break;
158 default:
159 break;
160 }
161
162 return (int) next_status;
163}
This page took 0.022507 seconds and 4 git commands to generate.