#include <stdint.h>
#include <babeltrace/graph/component.h>
+#include <babeltrace/graph/component-status.h>
#ifdef __cplusplus
extern "C" {
bt_private_component_filter_get_output_private_port_by_index(
struct bt_private_component *private_component, uint64_t index);
-extern struct bt_private_port *
+extern enum bt_component_status
bt_private_component_filter_add_output_private_port(
struct bt_private_component *private_component,
- const char *name, void *user_data);
+ const char *name, void *user_data,
+ struct bt_private_port **private_port);
extern struct bt_private_port *
bt_private_component_filter_get_input_private_port_by_name(
bt_private_component_filter_get_input_private_port_by_index(
struct bt_private_component *private_component, uint64_t index);
-extern struct bt_private_port *
+extern enum bt_component_status
bt_private_component_filter_add_input_private_port(
struct bt_private_component *private_component,
- const char *name, void *user_data);
+ const char *name, void *user_data,
+ struct bt_private_port **private_port);
#ifdef __cplusplus
}
#include <stdint.h>
#include <babeltrace/graph/component.h>
+#include <babeltrace/graph/component-status.h>
#ifdef __cplusplus
extern "C" {
bt_private_component_sink_get_input_private_port_by_index(
struct bt_private_component *private_component, uint64_t index);
-extern struct bt_private_port *
+extern enum bt_component_status
bt_private_component_sink_add_input_private_port(
struct bt_private_component *private_component,
- const char *name, void *user_data);
+ const char *name, void *user_data,
+ struct bt_private_port **private_port);
#ifdef __cplusplus
}
#include <stdint.h>
#include <babeltrace/graph/component.h>
+#include <babeltrace/graph/component-status.h>
#ifdef __cplusplus
extern "C" {
struct bt_private_component *private_component,
uint64_t index);
-extern struct bt_private_port *
+extern enum bt_component_status
bt_private_component_source_add_output_private_port(
struct bt_private_component *private_component,
- const char *name, void *user_data);
+ const char *name, void *user_data,
+ struct bt_private_port **private_port);
#ifdef __cplusplus
}
bt_component_from_private(private_component), name));
}
-struct bt_private_port *bt_private_component_filter_add_input_private_port(
+enum bt_component_status bt_private_component_filter_add_input_private_port(
struct bt_private_component *private_component,
- const char *name, void *user_data)
+ const char *name, void *user_data,
+ struct bt_private_port **user_priv_port)
{
+ enum bt_component_status status = BT_COMPONENT_STATUS_OK;
struct bt_port *port = NULL;
struct bt_component *component =
bt_component_from_private(private_component);
if (!component) {
BT_LOGW_STR("Invalid parameter: component is NULL.");
+ status = BT_COMPONENT_STATUS_INVALID;
goto end;
}
"comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
component, bt_component_get_name(component),
bt_component_class_type_string(component->class->type));
+ status = BT_COMPONENT_STATUS_INVALID;
goto end;
}
/* bt_component_add_input_port() logs details/errors */
port = bt_component_add_input_port(component, name, user_data);
+ if (!port) {
+ status = BT_COMPONENT_STATUS_NOMEM;
+ goto end;
+ }
+
+ if (user_priv_port) {
+ /* Move reference to user */
+ *user_priv_port = bt_private_port_from_port(port);
+ port = NULL;
+ }
end:
- return bt_private_port_from_port(port);
+ bt_put(port);
+ return status;
}
struct bt_private_port *
bt_component_from_private(private_component), name));
}
-struct bt_private_port *bt_private_component_filter_add_output_private_port(
+enum bt_component_status bt_private_component_filter_add_output_private_port(
struct bt_private_component *private_component,
- const char *name, void *user_data)
+ const char *name, void *user_data,
+ struct bt_private_port **user_priv_port)
{
+ enum bt_component_status status = BT_COMPONENT_STATUS_OK;
struct bt_port *port = NULL;
struct bt_component *component =
bt_component_from_private(private_component);
if (!component) {
BT_LOGW_STR("Invalid parameter: component is NULL.");
+ status = BT_COMPONENT_STATUS_INVALID;
goto end;
}
"comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
component, bt_component_get_name(component),
bt_component_class_type_string(component->class->type));
+ status = BT_COMPONENT_STATUS_INVALID;
goto end;
}
/* bt_component_add_output_port() logs details/errors */
port = bt_component_add_output_port(component, name, user_data);
+ if (!port) {
+ status = BT_COMPONENT_STATUS_NOMEM;
+ goto end;
+ }
+
+ if (user_priv_port) {
+ /* Move reference to user */
+ *user_priv_port = bt_private_port_from_port(port);
+ port = NULL;
+ }
end:
- return bt_private_port_from_port(port);
+ bt_put(port);
+ return status;
}
bt_component_from_private(private_component), name));
}
-struct bt_private_port *bt_private_component_sink_add_input_private_port(
+enum bt_component_status bt_private_component_sink_add_input_private_port(
struct bt_private_component *private_component,
- const char *name, void *user_data)
+ const char *name, void *user_data,
+ struct bt_private_port **user_priv_port)
{
+ enum bt_component_status status = BT_COMPONENT_STATUS_OK;
struct bt_port *port = NULL;
struct bt_component *component =
bt_component_from_private(private_component);
if (!component) {
BT_LOGW_STR("Invalid parameter: component is NULL.");
+ status = BT_COMPONENT_STATUS_INVALID;
goto end;
}
"comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
component, bt_component_get_name(component),
bt_component_class_type_string(component->class->type));
+ status = BT_COMPONENT_STATUS_INVALID;
goto end;
}
/* bt_component_add_input_port() logs details/errors */
port = bt_component_add_input_port(component, name, user_data);
+ if (!port) {
+ status = BT_COMPONENT_STATUS_NOMEM;
+ goto end;
+ }
+
+ if (user_priv_port) {
+ /* Move reference to user */
+ *user_priv_port = bt_private_port_from_port(port);
+ port = NULL;
+ }
end:
- return bt_private_port_from_port(port);
+ bt_put(port);
+ return status;
}
bt_component_from_private(private_component), index));
}
-struct bt_private_port *bt_private_component_source_add_output_private_port(
+enum bt_component_status bt_private_component_source_add_output_private_port(
struct bt_private_component *private_component,
- const char *name, void *user_data)
+ const char *name, void *user_data,
+ struct bt_private_port **user_priv_port)
{
+ enum bt_component_status status = BT_COMPONENT_STATUS_OK;
struct bt_port *port = NULL;
struct bt_component *component =
bt_component_from_private(private_component);
if (!component) {
BT_LOGW_STR("Invalid parameter: component is NULL.");
+ status = BT_COMPONENT_STATUS_INVALID;
goto end;
}
"comp-addr=%p, comp-name=\"%s\", comp-class-type=%s",
component, bt_component_get_name(component),
bt_component_class_type_string(component->class->type));
+ status = BT_COMPONENT_STATUS_INVALID;
goto end;
}
/* bt_component_add_output_port() logs details and errors */
port = bt_component_add_output_port(component, name, user_data);
+ if (!port) {
+ status = BT_COMPONENT_STATUS_NOMEM;
+ goto end;
+ }
+
+ if (user_priv_port) {
+ /* Move reference to user */
+ *user_priv_port = bt_private_port_from_port(port);
+ port = NULL;
+ }
end:
- return bt_private_port_from_port(port);
+ bt_put(port);
+ return status;
}
struct writer_component *writer_component = create_writer_component();
struct bt_value *value = NULL;
const char *path;
- void *priv_port;
if (!writer_component) {
ret = BT_COMPONENT_STATUS_NOMEM;
goto end;
}
- priv_port = bt_private_component_sink_add_input_private_port(component,
- "in", NULL);
- if (!priv_port) {
- ret = BT_COMPONENT_STATUS_NOMEM;
+ ret = bt_private_component_sink_add_input_private_port(component,
+ "in", NULL, NULL);
+ if (ret != BT_COMPONENT_STATUS_OK) {
goto end;
}
- bt_put(priv_port);
-
value = bt_value_map_get(params, "path");
if (!value || bt_value_is_null(value) || !bt_value_is_string(value)) {
fprintf(writer_component->err,
struct ctf_fs_ds_file_group *ds_file_group)
{
int ret = 0;
- struct bt_private_port *port = NULL;
struct ctf_fs_port_data *port_data = NULL;
GString *port_name = NULL;
struct ctf_fs_component *ctf_fs = ctf_fs_trace->ctf_fs;
}
port_data->ds_file_group = ds_file_group;
- port = bt_private_component_source_add_output_private_port(
- ctf_fs->priv_comp, port_name->str, port_data);
- if (!port) {
+ ret = bt_private_component_source_add_output_private_port(
+ ctf_fs->priv_comp, port_name->str, port_data, NULL);
+ if (ret) {
goto error;
}
g_string_free(port_name, TRUE);
}
- bt_put(port);
port_data_destroy(port_data);
return ret;
}
ret = sprintf(name, STREAM_NAME_PREFIX "%" PRIu64, stream_iter->viewer_stream_id);
assert(ret > 0);
strcpy(stream_iter->name, name);
- private_port = bt_private_component_source_add_output_private_port(
- lttng_live->private_component, name, stream_iter);
- if (!private_port) {
+ ret = bt_private_component_source_add_output_private_port(
+ lttng_live->private_component, name, stream_iter,
+ &private_port);
+ if (ret) {
return -1;
}
BT_LOGI("Added port %s", name);
BT_PUT(component);
if (nr_ports == 1) {
assert(!lttng_live->no_stream_port);
- lttng_live->no_stream_port =
- bt_private_component_source_add_output_private_port(lttng_live->private_component,
- "no-stream", lttng_live->no_stream_iter);
- if (!lttng_live->no_stream_port) {
+ ret = bt_private_component_source_add_output_private_port(lttng_live->private_component,
+ "no-stream", lttng_live->no_stream_iter,
+ <tng_live->no_stream_port);
+ if (ret) {
return -1;
}
lttng_live->no_stream_iter->port = lttng_live->no_stream_port;
lttng_live->no_stream_iter = g_new0(struct lttng_live_no_stream_iterator, 1);
lttng_live->no_stream_iter->p.type = LIVE_STREAM_TYPE_NO_STREAM;
lttng_live->no_stream_iter->lttng_live = lttng_live;
-
- lttng_live->no_stream_port =
- bt_private_component_source_add_output_private_port(
+ ret = bt_private_component_source_add_output_private_port(
lttng_live->private_component, "no-stream",
- lttng_live->no_stream_iter);
+ lttng_live->no_stream_iter,
+ <tng_live->no_stream_port);
+ if (ret != BT_COMPONENT_STATUS_OK) {
+ goto end;
+ }
+
lttng_live->no_stream_iter->port = lttng_live->no_stream_port;
ret = bt_private_component_set_user_data(private_component, lttng_live);
{
enum bt_component_status ret;
struct debug_info_component *debug_info = create_debug_info_component_data();
- struct bt_private_port *priv_port = NULL;
if (!debug_info) {
ret = BT_COMPONENT_STATUS_NOMEM;
goto error;
}
- priv_port = bt_private_component_filter_add_input_private_port(
- component, "in", NULL);
- if (!priv_port) {
- ret = BT_COMPONENT_STATUS_ERROR;
+ ret = bt_private_component_filter_add_input_private_port(
+ component, "in", NULL, NULL);
+ if (ret != BT_COMPONENT_STATUS_OK) {
goto end;
}
- BT_PUT(priv_port);
- priv_port = bt_private_component_filter_add_output_private_port(
- component, "out", NULL);
- if (!priv_port) {
- ret = BT_COMPONENT_STATUS_ERROR;
+ ret = bt_private_component_filter_add_output_private_port(
+ component, "out", NULL, NULL);
+ if (ret != BT_COMPONENT_STATUS_OK) {
goto end;
}
- BT_PUT(priv_port);
ret = init_from_params(debug_info, params);
end:
{
enum bt_component_status ret;
struct pretty_component *pretty = create_pretty();
- void *priv_port;
if (!pretty) {
ret = BT_COMPONENT_STATUS_NOMEM;
goto end;
}
- priv_port = bt_private_component_sink_add_input_private_port(component,
- "in", NULL);
- if (!priv_port) {
- ret = BT_COMPONENT_STATUS_NOMEM;
+ ret = bt_private_component_sink_add_input_private_port(component,
+ "in", NULL, NULL);
+ if (ret != BT_COMPONENT_STATUS_OK) {
goto end;
}
- bt_put(priv_port);
-
pretty->out = stdout;
pretty->err = stderr;
{
enum bt_component_status ret;
struct dummy *dummy = g_new0(struct dummy, 1);
- void *priv_port;
if (!dummy) {
ret = BT_COMPONENT_STATUS_NOMEM;
goto end;
}
- priv_port = bt_private_component_sink_add_input_private_port(component,
- "in", NULL);
- if (!priv_port) {
- ret = BT_COMPONENT_STATUS_NOMEM;
+ ret = bt_private_component_sink_add_input_private_port(component,
+ "in", NULL, NULL);
+ if (ret != BT_COMPONENT_STATUS_OK) {
goto end;
}
- bt_put(priv_port);
dummy->iterators = g_ptr_array_new_with_free_func(
(GDestroyNotify) bt_put);
if (!dummy->iterators) {
}
static
-int ensure_available_input_port(struct bt_private_component *priv_comp)
+enum bt_component_status ensure_available_input_port(
+ struct bt_private_component *priv_comp)
{
struct muxer_comp *muxer_comp =
bt_private_component_get_user_data(priv_comp);
- int ret = 0;
+ enum bt_component_status status = BT_COMPONENT_STATUS_OK;
GString *port_name = NULL;
- void *priv_port = NULL;
assert(muxer_comp);
port_name = g_string_new("in");
if (!port_name) {
- ret = -1;
+ status = BT_COMPONENT_STATUS_NOMEM;
goto end;
}
g_string_append_printf(port_name, "%u", muxer_comp->next_port_num);
- priv_port = bt_private_component_filter_add_input_private_port(
- priv_comp, port_name->str, NULL);
- if (!priv_port) {
- ret = -1;
+ status = bt_private_component_filter_add_input_private_port(
+ priv_comp, port_name->str, NULL, NULL);
+ if (status != BT_COMPONENT_STATUS_OK) {
goto end;
}
g_string_free(port_name, TRUE);
}
- bt_put(priv_port);
- return ret;
+ return status;
}
static
-int create_output_port(struct bt_private_component *priv_comp)
+enum bt_component_status create_output_port(
+ struct bt_private_component *priv_comp)
{
- void *priv_port;
- int ret = 0;
-
- priv_port = bt_private_component_filter_add_output_private_port(
- priv_comp, "out", NULL);
- if (!priv_port) {
- ret = -1;
- }
-
- bt_put(priv_port);
- return ret;
+ return bt_private_component_filter_add_output_private_port(
+ priv_comp, "out", NULL, NULL);
}
static
muxer_comp->priv_comp = priv_comp;
ret = bt_private_component_set_user_data(priv_comp, muxer_comp);
assert(ret == 0);
- ret = ensure_available_input_port(priv_comp);
- if (ret) {
+ status = ensure_available_input_port(priv_comp);
+ if (status != BT_COMPONENT_STATUS_OK) {
goto error;
}
destroy_muxer_comp(muxer_comp);
ret = bt_private_component_set_user_data(priv_comp, NULL);
assert(ret == 0);
- status = BT_COMPONENT_STATUS_ERROR;
+
+ if (status == BT_COMPONENT_STATUS_OK) {
+ status = BT_COMPONENT_STATUS_ERROR;
+ }
end:
return status;
{
enum bt_component_status ret;
struct trimmer *trimmer = create_trimmer_data();
- struct bt_private_port *priv_port = NULL;
if (!trimmer) {
ret = BT_COMPONENT_STATUS_NOMEM;
}
/* Create input and output ports */
- priv_port = bt_private_component_filter_add_input_private_port(
- component, "in", NULL);
- if (!priv_port) {
+ ret = bt_private_component_filter_add_input_private_port(
+ component, "in", NULL, NULL);
+ if (ret != BT_COMPONENT_STATUS_OK) {
goto error;
}
- bt_put(priv_port);
- priv_port = bt_private_component_filter_add_output_private_port(
- component, "out", NULL);
- if (!priv_port) {
+ ret = bt_private_component_filter_add_output_private_port(
+ component, "out", NULL, NULL);
+ if (ret != BT_COMPONENT_STATUS_OK) {
goto error;
}
ret = init_from_params(trimmer, params);
end:
- bt_put(priv_port);
return ret;
error:
destroy_trimmer_data(trimmer);
struct bt_private_component *private_component,
struct bt_value *params, void *init_method_data)
{
- void *priv_port;
+ int ret;
- priv_port = bt_private_component_source_add_output_private_port(
- private_component, "out", NULL);
- assert(priv_port);
- bt_put(priv_port);
+ ret = bt_private_component_source_add_output_private_port(
+ private_component, "out", NULL, NULL);
+ assert(ret == 0);
return BT_COMPONENT_STATUS_OK;
}
{
struct sink_user_data *user_data = g_new0(struct sink_user_data, 1);
int ret;
- void *priv_port;
assert(user_data);
ret = bt_private_component_set_user_data(private_component,
user_data);
assert(ret == 0);
- priv_port = bt_private_component_sink_add_input_private_port(
- private_component, "in", NULL);
- assert(priv_port);
- bt_put(priv_port);
+ ret = bt_private_component_sink_add_input_private_port(
+ private_component, "in", NULL, NULL);
+ assert(ret == 0);
return BT_COMPONENT_STATUS_OK;
}
struct bt_private_port *self_private_port,
struct bt_port *other_port)
{
- struct bt_private_port *port;
+ int ret;
struct event event = {
.type = COMP_PORT_CONNECTED,
switch (current_test) {
case TEST_SRC_ADDS_PORT_IN_PORT_CONNECTED:
- port = bt_private_component_source_add_output_private_port(
- private_component, "hello", NULL);
- assert(port);
- bt_put(port);
+ ret = bt_private_component_source_add_output_private_port(
+ private_component, "hello", NULL, NULL);
+ assert(ret == 0);
break;
default:
break;
enum bt_component_status src_init(struct bt_private_component *priv_comp,
struct bt_value *params, void *init_method_data)
{
- void *priv_port;
+ int ret;
- priv_port = bt_private_component_source_add_output_private_port(
- priv_comp, "out", NULL);
- assert(priv_port);
- bt_put(priv_port);
+ ret = bt_private_component_source_add_output_private_port(
+ priv_comp, "out", NULL, NULL);
+ assert(ret == 0);
return BT_COMPONENT_STATUS_OK;
}
enum bt_component_status sink_init(struct bt_private_component *priv_comp,
struct bt_value *params, void *init_method_data)
{
- void *priv_port;
+ int ret;
- priv_port = bt_private_component_sink_add_input_private_port(priv_comp,
- "in", NULL);
- assert(priv_port);
- bt_put(priv_port);
+ ret = bt_private_component_sink_add_input_private_port(priv_comp,
+ "in", NULL, NULL);
+ assert(ret == 0);
return BT_COMPONENT_STATUS_OK;
}
bt_private_notification_iterator_get_user_data(priv_iterator);
struct bt_private_component *private_component =
bt_private_notification_iterator_get_private_component(priv_iterator);
+ int ret;
assert(user_data);
assert(private_component);
break;
case TEST_SINGLE_END_THEN_MULTIPLE_FULL:
if (user_data->iter_index == 0) {
- struct bt_private_port *priv_port;
-
- priv_port = bt_private_component_source_add_output_private_port(
- private_component, "out1", NULL);
- assert(priv_port);
- bt_put(priv_port);
- priv_port = bt_private_component_source_add_output_private_port(
- private_component, "out2", NULL);
- assert(priv_port);
- bt_put(priv_port);
+ ret = bt_private_component_source_add_output_private_port(
+ private_component, "out1", NULL, NULL);
+ assert(ret == 0);
+ ret = bt_private_component_source_add_output_private_port(
+ private_component, "out2", NULL, NULL);
+ assert(ret == 0);
next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_END;
} else {
next_return = src_iter_next_seq(user_data);
next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_AGAIN;
user_data->at++;
} else {
- struct bt_private_port *priv_port;
-
- priv_port = bt_private_component_source_add_output_private_port(
- private_component, "out1", NULL);
- assert(priv_port);
- bt_put(priv_port);
- priv_port = bt_private_component_source_add_output_private_port(
- private_component, "out2", NULL);
- assert(priv_port);
- bt_put(priv_port);
+ ret = bt_private_component_source_add_output_private_port(
+ private_component, "out1", NULL, NULL);
+ assert(ret == 0);
+ ret = bt_private_component_source_add_output_private_port(
+ private_component, "out2", NULL, NULL);
+ assert(ret == 0);
next_return.status = BT_NOTIFICATION_ITERATOR_STATUS_END;
}
} else {
struct bt_private_component *private_component,
struct bt_value *params, void *init_method_data)
{
- struct bt_private_port *priv_port;
+ int ret;
size_t nb_ports;
switch (current_test) {
}
if (nb_ports >= 1) {
- priv_port = bt_private_component_source_add_output_private_port(
- private_component, "out0", NULL);
- assert(priv_port);
- bt_put(priv_port);
+ ret = bt_private_component_source_add_output_private_port(
+ private_component, "out0", NULL, NULL);
+ assert(ret == 0);
}
if (nb_ports >= 2) {
- priv_port = bt_private_component_source_add_output_private_port(
- private_component, "out1", NULL);
- assert(priv_port);
- bt_put(priv_port);
+ ret = bt_private_component_source_add_output_private_port(
+ private_component, "out1", NULL, NULL);
+ assert(ret == 0);
}
if (nb_ports >= 3) {
- priv_port = bt_private_component_source_add_output_private_port(
- private_component, "out2", NULL);
- assert(priv_port);
- bt_put(priv_port);
+ ret = bt_private_component_source_add_output_private_port(
+ private_component, "out2", NULL, NULL);
+ assert(ret == 0);
}
if (nb_ports >= 4) {
- priv_port = bt_private_component_source_add_output_private_port(
- private_component, "out3", NULL);
- assert(priv_port);
- bt_put(priv_port);
+ ret = bt_private_component_source_add_output_private_port(
+ private_component, "out3", NULL, NULL);
+ assert(ret == 0);
}
return BT_COMPONENT_STATUS_OK;
{
struct sink_user_data *user_data = g_new0(struct sink_user_data, 1);
int ret;
- void *priv_port;
assert(user_data);
ret = bt_private_component_set_user_data(private_component,
user_data);
assert(ret == 0);
- priv_port = bt_private_component_sink_add_input_private_port(
- private_component, "in", NULL);
- assert(priv_port);
- bt_put(priv_port);
+ ret = bt_private_component_sink_add_input_private_port(
+ private_component, "in", NULL, NULL);
+ assert(ret == 0);
return BT_COMPONENT_STATUS_OK;
}