#include <babeltrace/graph/component-source.h>
#include <babeltrace/graph/component-filter.h>
#include <babeltrace/graph/port.h>
+#include <babeltrace/graph/notification-internal.h>
+#include <babeltrace/graph/notification-event-internal.h>
+#include <babeltrace/graph/notification-packet-internal.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/types.h>
#include <babeltrace/values.h>
#include <babeltrace/values-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <unistd.h>
#include <glib.h>
{
int ret = 0;
- assert(listeners);
+ BT_ASSERT(listeners);
*listeners = g_array_new(FALSE, TRUE, sizeof(struct bt_graph_listener));
if (!*listeners) {
BT_LOGE_STR("Failed to allocate one GArray.");
* ensures that this function is not called two times.
*/
BT_LOGD("Destroying graph: addr=%p", graph);
- obj->ref_count.count++;
+ obj->ref_count++;
/*
* Cancel the graph to disallow some operations, like creating
call_remove_listeners(graph->listeners.ports_connected);
call_remove_listeners(graph->listeners.ports_disconnected);
+ if (graph->notifications) {
+ g_ptr_array_free(graph->notifications, TRUE);
+ }
+
if (graph->connections) {
BT_LOGD_STR("Destroying connections.");
g_ptr_array_free(graph->connections, TRUE);
}
+
if (graph->components) {
BT_LOGD_STR("Destroying components.");
g_ptr_array_free(graph->components, TRUE);
}
+
if (graph->sinks_to_consume) {
g_queue_free(graph->sinks_to_consume);
}
g_array_free(graph->listeners.ports_disconnected, TRUE);
}
+ bt_object_pool_finalize(&graph->event_notif_pool);
+ bt_object_pool_finalize(&graph->packet_begin_notif_pool);
+ bt_object_pool_finalize(&graph->packet_end_notif_pool);
g_free(graph);
}
+static
+void destroy_notification_event(struct bt_notification *notif,
+ struct bt_graph *graph)
+{
+ bt_notification_event_destroy(notif);
+}
+
+static
+void destroy_notification_packet_begin(struct bt_notification *notif,
+ struct bt_graph *graph)
+{
+ bt_notification_packet_begin_destroy(notif);
+}
+
+static
+void destroy_notification_packet_end(struct bt_notification *notif,
+ struct bt_graph *graph)
+{
+ bt_notification_packet_end_destroy(notif);
+}
+
+static
+void notify_notification_graph_is_destroyed(struct bt_notification *notif)
+{
+ bt_notification_unlink_graph(notif);
+}
+
struct bt_graph *bt_graph_create(void)
{
struct bt_graph *graph;
goto end;
}
- bt_object_init(graph, bt_graph_destroy);
-
- graph->connections = g_ptr_array_new_with_free_func(bt_object_release);
+ bt_object_init_shared(&graph->base, bt_graph_destroy);
+ graph->connections = g_ptr_array_new_with_free_func(
+ (GDestroyNotify) bt_object_try_spec_release);
if (!graph->connections) {
BT_LOGE_STR("Failed to allocate one GPtrArray.");
goto error;
}
- graph->components = g_ptr_array_new_with_free_func(bt_object_release);
+ graph->components = g_ptr_array_new_with_free_func(
+ (GDestroyNotify) bt_object_try_spec_release);
if (!graph->components) {
BT_LOGE_STR("Failed to allocate one GPtrArray.");
goto error;
goto error;
}
+ ret = bt_object_pool_initialize(&graph->event_notif_pool,
+ (bt_object_pool_new_object_func) bt_notification_event_new,
+ (bt_object_pool_destroy_object_func) destroy_notification_event,
+ graph);
+ if (ret) {
+ BT_LOGE("Failed to initialize event notification pool: ret=%d",
+ ret);
+ goto error;
+ }
+
+ ret = bt_object_pool_initialize(&graph->packet_begin_notif_pool,
+ (bt_object_pool_new_object_func) bt_notification_packet_begin_new,
+ (bt_object_pool_destroy_object_func) destroy_notification_packet_begin,
+ graph);
+ if (ret) {
+ BT_LOGE("Failed to initialize packet beginning notification pool: ret=%d",
+ ret);
+ goto error;
+ }
+
+ ret = bt_object_pool_initialize(&graph->packet_end_notif_pool,
+ (bt_object_pool_new_object_func) bt_notification_packet_end_new,
+ (bt_object_pool_destroy_object_func) destroy_notification_packet_end,
+ graph);
+ if (ret) {
+ BT_LOGE("Failed to initialize packet end notification pool: ret=%d",
+ ret);
+ goto error;
+ }
+
+ graph->notifications = g_ptr_array_new_with_free_func(
+ (GDestroyNotify) notify_notification_graph_is_destroyed);
BT_LOGD("Created graph object: addr=%p", graph);
end:
struct bt_component *upstream_component = NULL;
struct bt_component *downstream_component = NULL;
enum bt_component_status component_status;
- bt_bool init_can_consume;
+ bt_bool init_can_consume;
if (!graph) {
BT_LOGW_STR("Invalid parameter: graph is NULL.");
enum bt_graph_status status = BT_GRAPH_STATUS_OK;
enum bt_component_status comp_status;
- assert(sink);
+ BT_ASSERT(sink);
comp_status = bt_component_sink_consume(sink);
BT_LOGV("Consumed from sink: addr=%p, name=\"%s\", status=%s",
sink, bt_component_get_name(sink),
"comp-addr=%p, comp-name=\"%s\"",
graph, sink, bt_component_get_name(sink));
- assert(bt_component_borrow_graph(sink) == graph);
+ BT_ASSERT(bt_component_borrow_graph(sink) == graph);
if (g_queue_is_empty(graph->sinks_to_consume)) {
BT_LOGV_STR("Graph's sink queue is empty: end of graph.");
}
sink_node = g_queue_pop_nth_link(graph->sinks_to_consume, index);
- assert(sink_node);
+ BT_ASSERT(sink_node);
status = consume_sink_node(graph, sink_node);
end:
GList *current_node;
BT_LOGV("Making next sink consume: addr=%p", graph);
-
- if (!graph->has_sink) {
- BT_LOGW_STR("Graph has no sink component.");
- status = BT_GRAPH_STATUS_NO_SINK;
- goto end;
- }
+ BT_ASSERT_PRE(graph->has_sink,
+ "Graph has no sink component: %!+g", graph);
if (g_queue_is_empty(graph->sinks_to_consume)) {
BT_LOGV_STR("Graph's sink queue is empty: end of graph.");
enum bt_graph_status bt_graph_consume(struct bt_graph *graph)
{
- enum bt_graph_status status = BT_GRAPH_STATUS_OK;
-
- if (!graph) {
- BT_LOGW_STR("Invalid parameter: graph is NULL.");
- status = BT_GRAPH_STATUS_INVALID;
- goto end;
- }
-
- if (graph->canceled) {
- BT_LOGW("Invalid parameter: graph is canceled: "
- "graph-addr=%p", graph);
- status = BT_GRAPH_STATUS_CANCELED;
- goto end;
- }
-
- if (!graph->can_consume) {
- BT_LOGW_STR("Cannot consume graph in its current state.");
- status = BT_GRAPH_STATUS_CANNOT_CONSUME;
- goto end;
- }
+ enum bt_graph_status status;
+ BT_ASSERT_PRE_NON_NULL(graph, "Graph");
+ BT_ASSERT_PRE(!graph->canceled, "Graph is canceled: %!+g", graph);
+ BT_ASSERT_PRE(graph->can_consume,
+ "Cannot consume graph in its current state: %!+g", graph);
graph->can_consume = BT_FALSE;
status = bt_graph_consume_no_check(graph);
graph->can_consume = BT_TRUE;
-
-end:
return status;
}
struct bt_graph_listener, i);
bt_graph_port_added_listener func = listener.func;
- assert(func);
+ BT_ASSERT(func);
func(port, listener.data);
}
}
struct bt_graph_listener, i);
bt_graph_port_removed_listener func = listener.func;
- assert(func);
+ BT_ASSERT(func);
func(comp, port, listener.data);
}
}
struct bt_graph_listener, i);
bt_graph_ports_connected_listener func = listener.func;
- assert(func);
+ BT_ASSERT(func);
func(upstream_port, downstream_port, listener.data);
}
}
struct bt_graph_listener, i);
bt_graph_ports_disconnected_listener func = listener.func;
- assert(func);
+ BT_ASSERT(func);
func(upstream_comp, downstream_comp, upstream_port,
downstream_port, listener.data);
}
void bt_graph_remove_connection(struct bt_graph *graph,
struct bt_connection *connection)
{
- assert(graph);
- assert(connection);
+ BT_ASSERT(graph);
+ BT_ASSERT(connection);
BT_LOGV("Removing graph's connection: graph-addr=%p, conn-addr=%p",
graph, connection);
g_ptr_array_remove(graph->connections, connection);
uint64_t i;
int ret = 0;
- assert(graph);
- assert(component);
- assert(component->base.ref_count.count == 0);
- assert(bt_component_borrow_graph(component) == graph);
+ BT_ASSERT(graph);
+ BT_ASSERT(component);
+ BT_ASSERT(component->base.ref_count == 0);
+ BT_ASSERT(bt_component_borrow_graph(component) == graph);
init_can_consume = graph->can_consume;
count = bt_component_get_input_port_count(component);
struct bt_port *port =
bt_component_get_input_port_by_index(component, i);
- assert(port);
+ BT_ASSERT(port);
bt_put(port);
if (bt_port_is_connected(port)) {
struct bt_port *port =
bt_component_get_output_port_by_index(component, i);
- assert(port);
+ BT_ASSERT(port);
bt_put(port);
if (bt_port_is_connected(port)) {
}
/*
- * This calls bt_object_release() on the component, and since
- * its reference count is 0, its destructor is called. Its
+ * This calls bt_object_try_spec_release() on the component, and
+ * since its reference count is 0, its destructor is called. Its
* destructor calls the user's finalization method (if set).
*/
g_ptr_array_remove(graph->components, component);
graph->can_consume = init_can_consume;
return ret;
}
+
+BT_HIDDEN
+void bt_graph_add_notification(struct bt_graph *graph,
+ struct bt_notification *notif)
+{
+ BT_ASSERT(graph);
+ BT_ASSERT(notif);
+
+ /*
+ * It's okay not to take a reference because, when a
+ * notification's reference count drops to 0, either:
+ *
+ * * It is recycled back to one of this graph's pool.
+ * * It is destroyed because it doesn't have any link to any
+ * graph, which means the original graph is already destroyed.
+ */
+ g_ptr_array_add(graph->notifications, notif);
+}