*/
#define BT_LOG_TAG "COMP"
-#include <babeltrace/lib-logging-internal.h>
-
-#include <babeltrace/assert-internal.h>
-#include <babeltrace/assert-pre-internal.h>
-#include <babeltrace/graph/self-component.h>
-#include <babeltrace/graph/component-const.h>
-#include <babeltrace/graph/component-source-const.h>
-#include <babeltrace/graph/component-filter-const.h>
-#include <babeltrace/graph/component-sink-const.h>
-#include <babeltrace/graph/component-internal.h>
-#include <babeltrace/graph/component-class-internal.h>
-#include <babeltrace/graph/component-source-internal.h>
-#include <babeltrace/graph/component-filter-internal.h>
-#include <babeltrace/graph/component-sink-internal.h>
-#include <babeltrace/graph/connection-internal.h>
-#include <babeltrace/graph/graph-internal.h>
-#include <babeltrace/graph/message-iterator-internal.h>
-#include <babeltrace/graph/port-internal.h>
-#include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/compiler-internal.h>
-#include <babeltrace/types.h>
-#include <babeltrace/value.h>
-#include <babeltrace/value-internal.h>
+#include <babeltrace2/lib-logging-internal.h>
+
+#include <babeltrace2/assert-internal.h>
+#include <babeltrace2/assert-pre-internal.h>
+#include <babeltrace2/graph/self-component.h>
+#include <babeltrace2/graph/component-const.h>
+#include <babeltrace2/graph/component-source-const.h>
+#include <babeltrace2/graph/component-filter-const.h>
+#include <babeltrace2/graph/component-sink-const.h>
+#include <babeltrace2/graph/component-internal.h>
+#include <babeltrace2/graph/component-class-internal.h>
+#include <babeltrace2/graph/component-source-internal.h>
+#include <babeltrace2/graph/component-filter-internal.h>
+#include <babeltrace2/graph/component-sink-internal.h>
+#include <babeltrace2/graph/connection-internal.h>
+#include <babeltrace2/graph/graph-internal.h>
+#include <babeltrace2/graph/message-iterator-internal.h>
+#include <babeltrace2/graph/port-internal.h>
+#include <babeltrace2/babeltrace-internal.h>
+#include <babeltrace2/compiler-internal.h>
+#include <babeltrace2/types.h>
+#include <babeltrace2/value.h>
+#include <babeltrace2/value-internal.h>
#include <stdint.h>
#include <inttypes.h>
}
static
-struct bt_port *add_port(
+enum bt_self_component_status add_port(
struct bt_component *component, GPtrArray *ports,
- enum bt_port_type port_type, const char *name, void *user_data)
+ enum bt_port_type port_type, const char *name, void *user_data,
+ struct bt_port **port)
{
struct bt_port *new_port = NULL;
struct bt_graph *graph = NULL;
+ enum bt_self_component_status status;
BT_ASSERT_PRE_NON_NULL(component, "Component");
BT_ASSERT_PRE_NON_NULL(name, "Name");
BT_ASSERT_PRE(graph && !bt_graph_is_canceled(graph),
"Component's graph is canceled: %![comp-]+c, %![graph-]+g",
component, graph);
- BT_ASSERT_PRE(!graph->is_configured,
+ BT_ASSERT_PRE(
+ graph->config_state == BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
"Component's graph is already configured: "
"%![comp-]+c, %![graph-]+g", component, graph);
new_port = bt_port_create(component, port_type, name, user_data);
if (!new_port) {
BT_LOGE_STR("Cannot create port object.");
- goto end;
+ status = BT_SELF_COMPONENT_STATUS_NOMEM;
+ goto error;
}
/*
/*
* Notify the graph's creator that a new port was added.
*/
- bt_object_get_ref(bt_component_borrow_graph(component));
graph = bt_component_borrow_graph(component);
if (graph) {
- bt_graph_notify_port_added(graph, new_port);
- BT_OBJECT_PUT_REF_AND_RESET(graph);
+ enum bt_graph_listener_status listener_status;
+
+ listener_status = bt_graph_notify_port_added(graph, new_port);
+ if (listener_status != BT_GRAPH_LISTENER_STATUS_OK) {
+ bt_graph_make_faulty(graph);
+ status = listener_status;
+ goto error;
+ }
}
BT_LIB_LOGD("Created and added port to component: "
"%![comp-]+c, %![port-]+p", component, new_port);
+ *port = new_port;
+ status = BT_SELF_COMPONENT_STATUS_OK;
+
+ goto end;
+error:
+ /*
+ * We need to release the reference that we would otherwise have
+ * returned to the caller.
+ */
+ BT_PORT_PUT_REF_AND_RESET(new_port);
+
end:
- return new_port;
+ return status;
}
BT_HIDDEN
return component->name->str;
}
-struct bt_component_class *bt_component_borrow_class(
+const struct bt_component_class *bt_component_borrow_class_const(
const struct bt_component *component)
{
BT_ASSERT_PRE_NON_NULL(component, "Component");
}
BT_HIDDEN
-struct bt_port_input *bt_component_add_input_port(
+enum bt_self_component_status bt_component_add_input_port(
struct bt_component *component, const char *name,
- void *user_data)
+ void *user_data, struct bt_port **port)
{
/* add_port() logs details */
- return (void *)
- add_port(component, component->input_ports,
- BT_PORT_TYPE_INPUT, name, user_data);
+ return add_port(component, component->input_ports,
+ BT_PORT_TYPE_INPUT, name, user_data, port);
}
BT_HIDDEN
-struct bt_port_output *bt_component_add_output_port(
+enum bt_self_component_status bt_component_add_output_port(
struct bt_component *component, const char *name,
- void *user_data)
+ void *user_data, struct bt_port **port)
{
/* add_port() logs details */
- return (void *)
- add_port(component, component->output_ports,
- BT_PORT_TYPE_OUTPUT, name, user_data);
+ return add_port(component, component->output_ports,
+ BT_PORT_TYPE_OUTPUT, name, user_data, port);
}
BT_HIDDEN