Graph API: split into private and public APIs
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 21 Nov 2018 13:34:20 +0000 (08:34 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
12 files changed:
cli/babeltrace.c
include/Makefile.am
include/babeltrace/babeltrace.h
include/babeltrace/graph/graph-internal.h
include/babeltrace/graph/graph.h
include/babeltrace/graph/private-graph.h [new file with mode: 0644]
lib/graph/graph.c
lib/graph/iterator.c
plugins/ctf/lttng-live/lttng-live.c
tests/lib/test_bt_notification_iterator.c
tests/lib/test_graph_topo.c
tests/lib/test_plugin.c

index efc883e2d4f18a2c3e361d84636ecc8dd69ec97f..b9a1b335c510d31f93ee8574582e4889cfcf05ca 100644 (file)
@@ -1,8 +1,4 @@
 /*
- * babeltrace.c
- *
- * Babeltrace Trace Converter
- *
  * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
  *
  * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
@@ -73,19 +69,20 @@ static const char* log_level_env_var_names[] = {
 };
 
 /* Application's processing graph (weak) */
-static struct bt_graph *the_graph;
+static struct bt_private_graph *the_graph;
 static struct bt_query_executor *the_query_executor;
 static bool canceled = false;
 
 GPtrArray *loaded_plugins;
 
 #ifdef __MINGW32__
+
 #include <windows.h>
 
 static
 BOOL WINAPI signal_handler(DWORD signal) {
        if (the_graph) {
-               bt_graph_cancel(the_graph);
+               bt_private_graph_cancel(the_graph);
        }
 
        canceled = true;
@@ -100,7 +97,9 @@ void set_signal_handler(void)
                BT_LOGE("Failed to set the ctrl+c handler.");
        }
 }
+
 #else /* __MINGW32__ */
+
 static
 void signal_handler(int signum)
 {
@@ -109,7 +108,7 @@ void signal_handler(int signum)
        }
 
        if (the_graph) {
-               bt_graph_cancel(the_graph);
+               bt_private_graph_cancel(the_graph);
        }
 
        if (the_query_executor) {
@@ -133,6 +132,7 @@ void set_signal_handler(void)
                sigaction(SIGINT, &new_action, NULL);
        }
 }
+
 #endif /* __MINGW32__ */
 
 static
@@ -1437,7 +1437,7 @@ struct cmd_run_ctx {
        GHashTable *components;
 
        /* Owned by this */
-       struct bt_graph *graph;
+       struct bt_private_graph *graph;
 
        /* Weak */
        struct bt_config *cfg;
@@ -1668,7 +1668,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component(
                        ret = 0;
 
                        ctx->connect_ports = false;
-                       graph_status = bt_graph_add_component(ctx->graph,
+                       graph_status = bt_private_graph_add_component(ctx->graph,
                                trimmer_class, trimmer_name,
                                bt_value_borrow_from_private(trimmer_params),
                                &trimmer);
@@ -1704,7 +1704,7 @@ int cmd_run_ctx_connect_upstream_port_to_downstream_component(
                }
 
                /* We have a winner! */
-               status = bt_graph_connect_ports(ctx->graph,
+               status = bt_private_graph_connect_ports(ctx->graph,
                        upstream_port, downstream_port, NULL);
                BT_OBJECT_PUT_REF_AND_RESET(downstream_port);
                switch (status) {
@@ -2020,34 +2020,34 @@ int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg)
                }
        }
 
-       ctx->graph = bt_graph_create();
+       ctx->graph = bt_private_graph_create();
        if (!ctx->graph) {
                goto error;
        }
 
        the_graph = ctx->graph;
-       ret = bt_graph_add_port_added_listener(ctx->graph,
+       ret = bt_private_graph_add_port_added_listener(ctx->graph,
                graph_port_added_listener, NULL, ctx);
        if (ret < 0) {
                BT_LOGE_STR("Cannot add \"port added\" listener to graph.");
                goto error;
        }
 
-       ret = bt_graph_add_port_removed_listener(ctx->graph,
+       ret = bt_private_graph_add_port_removed_listener(ctx->graph,
                graph_port_removed_listener, NULL, ctx);
        if (ret < 0) {
                BT_LOGE_STR("Cannot add \"port removed\" listener to graph.");
                goto error;
        }
 
-       ret = bt_graph_add_ports_connected_listener(ctx->graph,
+       ret = bt_private_graph_add_ports_connected_listener(ctx->graph,
                graph_ports_connected_listener, NULL, ctx);
        if (ret < 0) {
                BT_LOGE_STR("Cannot add \"ports connected\" listener to graph.");
                goto error;
        }
 
-       ret = bt_graph_add_ports_disconnected_listener(ctx->graph,
+       ret = bt_private_graph_add_ports_disconnected_listener(ctx->graph,
                graph_ports_disconnected_listener, NULL, ctx);
        if (ret < 0) {
                BT_LOGE_STR("Cannot add \"ports disconnected\" listener to graph.");
@@ -2335,7 +2335,7 @@ int cmd_run_ctx_create_components_from_config_components(
                        goto error;
                }
 
-               ret = bt_graph_add_component(ctx->graph, comp_cls,
+               ret = bt_private_graph_add_component(ctx->graph, comp_cls,
                        cfg_comp->instance_name->str,
                        bt_value_borrow_from_private(cfg_comp->params), &comp);
                if (ret) {
@@ -2560,7 +2560,7 @@ int cmd_run(struct bt_config *cfg)
 
        /* Run the graph */
        while (true) {
-               enum bt_graph_status graph_status = bt_graph_run(ctx.graph);
+               enum bt_graph_status graph_status = bt_private_graph_run(ctx.graph);
 
                /*
                 * Reset console in case something messed with console
@@ -2569,7 +2569,7 @@ int cmd_run(struct bt_config *cfg)
                printf("%s", bt_common_color_reset());
                fflush(stdout);
                fprintf(stderr, "%s", bt_common_color_reset());
-               BT_LOGV("bt_graph_run() returned: status=%s",
+               BT_LOGV("bt_private_graph_run() returned: status=%s",
                        bt_graph_status_str(graph_status));
 
                switch (graph_status) {
@@ -2579,7 +2579,8 @@ int cmd_run(struct bt_config *cfg)
                        BT_LOGI_STR("Graph was canceled by user.");
                        goto error;
                case BT_GRAPH_STATUS_AGAIN:
-                       if (bt_graph_is_canceled(ctx.graph)) {
+                       if (bt_graph_is_canceled(
+                                       bt_graph_borrow_from_private(ctx.graph))) {
                                BT_LOGI_STR("Graph was canceled by user.");
                                goto error;
                        }
@@ -2590,7 +2591,8 @@ int cmd_run(struct bt_config *cfg)
                                        cfg->cmd_data.run.retry_duration_us);
 
                                if (usleep(cfg->cmd_data.run.retry_duration_us)) {
-                                       if (bt_graph_is_canceled(ctx.graph)) {
+                                       if (bt_graph_is_canceled(
+                                                       bt_graph_borrow_from_private(ctx.graph))) {
                                                BT_LOGI_STR("Graph was canceled by user.");
                                                goto error;
                                        }
index 842a63d6cacb15e4817038d1542c158284112eff..5c0b79fc83252bad56da5660bbc720456fd9cc4a 100644 (file)
@@ -114,7 +114,6 @@ babeltracectfirinclude_HEADERS = \
        babeltrace/ctf-ir/trace.h \
        babeltrace/ctf-ir/utils.h
 
-
 # Trace IR API
 babeltracetraceirincludedir = "$(includedir)/babeltrace/trace-ir"
 babeltracetraceirinclude_HEADERS = \
@@ -177,6 +176,7 @@ babeltracegraphinclude_HEADERS = \
        babeltrace/graph/private-connection-notification-iterator.h \
        babeltrace/graph/private-connection-private-notification-iterator.h \
        babeltrace/graph/private-connection.h \
+       babeltrace/graph/private-graph.h \
        babeltrace/graph/private-notification-event.h \
        babeltrace/graph/private-notification-inactivity.h \
        babeltrace/graph/private-notification-packet.h \
index 2cf04c80d3681d1ee0c7a1acc41af24ad0f594e4..77471a2ec31b709e17ca6d82b6c3b2c97f450a26 100644 (file)
 #include <babeltrace/graph/private-connection-notification-iterator.h>
 #include <babeltrace/graph/private-connection-private-notification-iterator.h>
 #include <babeltrace/graph/private-connection.h>
+#include <babeltrace/graph/private-graph.h>
 #include <babeltrace/graph/private-notification-event.h>
 #include <babeltrace/graph/private-notification-inactivity.h>
 #include <babeltrace/graph/private-notification-packet.h>
index 3907568f3865df774614f6e9ec3c8b6d3b08cec3..81b736766e71985637b564dde7f3002e0480212e 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 #include <babeltrace/graph/graph.h>
+#include <babeltrace/graph/connection-internal.h>
 #include <babeltrace/graph/component-status.h>
 #include <babeltrace/graph/notification.h>
 #include <babeltrace/babeltrace-internal.h>
index 31d9c4212e284c1fc104cfe92bd9b7406c7c9f74..f44bee7f3c12328ae0f3557781daeeacdc1c3ab8 100644 (file)
@@ -2,8 +2,6 @@
 #define BABELTRACE_GRAPH_GRAPH_H
 
 /*
- * BabelTrace - Babeltrace Graph Interface
- *
  * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
 extern "C" {
 #endif
 
-struct bt_port;
-struct bt_connection;
-struct bt_component;
-struct bt_component_class;
-struct bt_value;
+struct bt_graph;
 
 enum bt_graph_status {
        BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION = 111,
@@ -61,74 +55,6 @@ enum bt_graph_status {
        BT_GRAPH_STATUS_NOMEM = BT_COMPONENT_STATUS_NOMEM,
 };
 
-typedef void (*bt_graph_port_added_listener)(struct bt_port *port,
-               void *data);
-typedef void (*bt_graph_port_removed_listener)(struct bt_component *component,
-               struct bt_port *port, void *data);
-typedef void (*bt_graph_ports_connected_listener)(struct bt_port *upstream_port,
-               struct bt_port *downstream_port, void *data);
-typedef void (*bt_graph_ports_disconnected_listener)(
-               struct bt_component *upstream_component,
-               struct bt_component *downstream_component,
-               struct bt_port *upstream_port, struct bt_port *downstream_port,
-               void *data);
-typedef void (* bt_graph_listener_removed)(void *data);
-
-extern struct bt_graph *bt_graph_create(void);
-
-extern enum bt_graph_status bt_graph_add_component(
-               struct bt_graph *graph,
-               struct bt_component_class *component_class,
-               const char *name, struct bt_value *params,
-               struct bt_component **component);
-
-extern enum bt_graph_status bt_graph_add_component_with_init_method_data(
-               struct bt_graph *graph,
-               struct bt_component_class *component_class,
-               const char *name, struct bt_value *params,
-               void *init_method_data,
-               struct bt_component **component);
-
-/**
- * Creates a connection between two components using the two ports specified
- * and adds the connection and components (if not already added) to the graph.
- */
-extern enum bt_graph_status bt_graph_connect_ports(struct bt_graph *graph,
-               struct bt_port *upstream, struct bt_port *downstream,
-               struct bt_connection **connection);
-
-/**
- * Run graph to completion or until a single sink is left and "AGAIN" is received.
- *
- * Runs "bt_component_sink_consume()" on all sinks in round-robin until they all
- * indicate that the end is reached or that an error occured.
- */
-extern enum bt_graph_status bt_graph_run(struct bt_graph *graph);
-
-/**
- * Runs "bt_component_sink_consume()" on the graph's sinks. Each invokation will
- * invoke "bt_component_sink_consume()" on the next sink, in round-robin, until
- * they all indicated that the end is reached.
- */
-extern enum bt_graph_status bt_graph_consume(struct bt_graph *graph);
-
-extern int bt_graph_add_port_added_listener(struct bt_graph *graph,
-               bt_graph_port_added_listener listener,
-               bt_graph_listener_removed listener_removed, void *data);
-
-extern int bt_graph_add_port_removed_listener(struct bt_graph *graph,
-               bt_graph_port_removed_listener listener,
-               bt_graph_listener_removed listener_removed, void *data);
-
-extern int bt_graph_add_ports_connected_listener(struct bt_graph *graph,
-               bt_graph_ports_connected_listener listener,
-               bt_graph_listener_removed listener_removed, void *data);
-
-extern int bt_graph_add_ports_disconnected_listener(struct bt_graph *graph,
-               bt_graph_ports_disconnected_listener listener,
-               bt_graph_listener_removed listener_removed, void *data);
-
-extern enum bt_graph_status bt_graph_cancel(struct bt_graph *graph);
 extern bt_bool bt_graph_is_canceled(struct bt_graph *graph);
 
 #ifdef __cplusplus
diff --git a/include/babeltrace/graph/private-graph.h b/include/babeltrace/graph/private-graph.h
new file mode 100644 (file)
index 0000000..4a1fe1a
--- /dev/null
@@ -0,0 +1,136 @@
+#ifndef BABELTRACE_GRAPH_PRIVATE_GRAPH_H
+#define BABELTRACE_GRAPH_PRIVATE_GRAPH_H
+
+/*
+ * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/* For bt_bool */
+#include <babeltrace/types.h>
+
+/* For enum bt_graph_status */
+#include <babeltrace/graph/graph.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bt_graph;
+struct bt_private_graph;
+struct bt_port;
+struct bt_connection;
+struct bt_component;
+struct bt_component_class;
+struct bt_value;
+
+typedef void (*bt_private_graph_port_added_listener)(struct bt_port *port,
+               void *data);
+
+typedef void (*bt_private_graph_port_removed_listener)(
+               struct bt_component *component,
+               struct bt_port *port, void *data);
+
+typedef void (*bt_private_graph_ports_connected_listener)(
+               struct bt_port *upstream_port,
+               struct bt_port *downstream_port, void *data);
+
+typedef void (*bt_private_graph_ports_disconnected_listener)(
+               struct bt_component *upstream_component,
+               struct bt_component *downstream_component,
+               struct bt_port *upstream_port, struct bt_port *downstream_port,
+               void *data);
+
+typedef void (* bt_private_graph_listener_removed)(void *data);
+
+extern struct bt_graph *bt_graph_borrow_from_private(
+               struct bt_private_graph *priv_graph);
+
+extern struct bt_private_graph *bt_private_graph_create(void);
+
+extern enum bt_graph_status bt_private_graph_add_component(
+               struct bt_private_graph *graph,
+               struct bt_component_class *component_class,
+               const char *name, struct bt_value *params,
+               struct bt_component **component);
+
+extern enum bt_graph_status
+bt_private_graph_add_component_with_init_method_data(
+               struct bt_private_graph *graph,
+               struct bt_component_class *component_class,
+               const char *name, struct bt_value *params,
+               void *init_method_data, struct bt_component **component);
+
+/**
+ * Creates a connection between two components using the two ports specified
+ * and adds the connection and components (if not already added) to the graph.
+ */
+extern enum bt_graph_status bt_private_graph_connect_ports(
+               struct bt_private_graph *graph,
+               struct bt_port *upstream, struct bt_port *downstream,
+               struct bt_connection **connection);
+
+/**
+ * Run graph to completion or until a single sink is left and "AGAIN" is received.
+ *
+ * Runs "bt_component_sink_consume()" on all sinks in round-robin until they all
+ * indicate that the end is reached or that an error occured.
+ */
+extern enum bt_graph_status bt_private_graph_run(
+               struct bt_private_graph *graph);
+
+/**
+ * Runs "bt_component_sink_consume()" on the graph's sinks. Each invokation will
+ * invoke "bt_component_sink_consume()" on the next sink, in round-robin, until
+ * they all indicated that the end is reached.
+ */
+extern enum bt_graph_status bt_private_graph_consume(
+               struct bt_private_graph *graph);
+
+extern int bt_private_graph_add_port_added_listener(
+               struct bt_private_graph *graph,
+               bt_private_graph_port_added_listener listener,
+               bt_private_graph_listener_removed listener_removed, void *data);
+
+extern int bt_private_graph_add_port_removed_listener(
+               struct bt_private_graph *graph,
+               bt_private_graph_port_removed_listener listener,
+               bt_private_graph_listener_removed listener_removed, void *data);
+
+extern int bt_private_graph_add_ports_connected_listener(
+               struct bt_private_graph *graph,
+               bt_private_graph_ports_connected_listener listener,
+               bt_private_graph_listener_removed listener_removed, void *data);
+
+extern int bt_private_graph_add_ports_disconnected_listener(
+               struct bt_private_graph *graph,
+               bt_private_graph_ports_disconnected_listener listener,
+               bt_private_graph_listener_removed listener_removed, void *data);
+
+extern enum bt_graph_status bt_private_graph_cancel(
+               struct bt_private_graph *graph);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BABELTRACE_GRAPH_PRIVATE_GRAPH_H */
index c01d0b5b743bf7188459b446f026d2dddbff7f23..722cb2ee28a73fc525e90e92253a51b969edf964 100644 (file)
@@ -1,8 +1,4 @@
 /*
- * graph.c
- *
- * Babeltrace Plugin Component Graph
- *
  * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
  *
@@ -29,6 +25,7 @@
 #include <babeltrace/lib-logging-internal.h>
 
 #include <babeltrace/graph/component-internal.h>
+#include <babeltrace/graph/private-graph.h>
 #include <babeltrace/graph/graph-internal.h>
 #include <babeltrace/graph/connection-internal.h>
 #include <babeltrace/graph/component-sink-internal.h>
@@ -51,7 +48,7 @@
 
 struct bt_graph_listener {
        void *func;
-       bt_graph_listener_removed removed;
+       bt_private_graph_listener_removed removed;
        void *data;
 };
 
@@ -126,7 +123,7 @@ void bt_graph_destroy(struct bt_object *obj)
         * Cancel the graph to disallow some operations, like creating
         * notification iterators and adding ports to components.
         */
-       (void) bt_graph_cancel(graph);
+       (void) bt_private_graph_cancel((void *) graph);
 
        /* Call all remove listeners */
        call_remove_listeners(graph->listeners.port_added);
@@ -201,7 +198,7 @@ void notify_notification_graph_is_destroyed(struct bt_notification *notif)
        bt_notification_unlink_graph(notif);
 }
 
-struct bt_graph *bt_graph_create(void)
+struct bt_private_graph *bt_private_graph_create(void)
 {
        struct bt_graph *graph;
        int ret;
@@ -292,16 +289,18 @@ struct bt_graph *bt_graph_create(void)
        BT_LOGD("Created graph object: addr=%p", graph);
 
 end:
-       return graph;
+       return (void *) graph;
 error:
        BT_OBJECT_PUT_REF_AND_RESET(graph);
        goto end;
 }
 
-enum bt_graph_status bt_graph_connect_ports(struct bt_graph *graph,
+enum bt_graph_status bt_private_graph_connect_ports(
+               struct bt_private_graph *priv_graph,
                struct bt_port *upstream_port, struct bt_port *downstream_port,
                struct bt_connection **user_connection)
 {
+       struct bt_graph *graph = (void *) priv_graph;
        enum bt_graph_status status = BT_GRAPH_STATUS_OK;
        struct bt_connection *connection = NULL;
        struct bt_graph *upstream_graph = NULL;
@@ -648,8 +647,10 @@ end:
        return status;
 }
 
-enum bt_graph_status bt_graph_consume(struct bt_graph *graph)
+enum bt_graph_status bt_private_graph_consume(
+               struct bt_private_graph *priv_graph)
 {
+       struct bt_graph *graph = (void *) priv_graph;
        enum bt_graph_status status;
 
        BT_ASSERT_PRE_NON_NULL(graph, "Graph");
@@ -662,8 +663,10 @@ enum bt_graph_status bt_graph_consume(struct bt_graph *graph)
        return status;
 }
 
-enum bt_graph_status bt_graph_run(struct bt_graph *graph)
+enum bt_graph_status bt_private_graph_run(
+               struct bt_private_graph *priv_graph)
 {
+       struct bt_graph *graph = (void *) priv_graph;
        enum bt_graph_status status = BT_GRAPH_STATUS_OK;
 
        if (!graph) {
@@ -744,11 +747,12 @@ int add_listener(GArray *listeners, void *func, void *removed, void *data)
        return listeners->len - 1;
 }
 
-int bt_graph_add_port_added_listener(
-               struct bt_graph *graph,
-               bt_graph_port_added_listener listener,
-               bt_graph_listener_removed listener_removed, void *data)
+int bt_private_graph_add_port_added_listener(
+               struct bt_private_graph *priv_graph,
+               bt_private_graph_port_added_listener listener,
+               bt_private_graph_listener_removed listener_removed, void *data)
 {
+       struct bt_graph *graph = (void *) priv_graph;
        int ret;
 
        if (!graph) {
@@ -780,11 +784,12 @@ end:
        return ret;
 }
 
-int bt_graph_add_port_removed_listener(
-               struct bt_graph *graph,
-               bt_graph_port_removed_listener listener,
-               bt_graph_listener_removed listener_removed, void *data)
+int bt_private_graph_add_port_removed_listener(
+               struct bt_private_graph *priv_graph,
+               bt_private_graph_port_removed_listener listener,
+               bt_private_graph_listener_removed listener_removed, void *data)
 {
+       struct bt_graph *graph = (void *) priv_graph;
        int ret;
 
        if (!graph) {
@@ -816,11 +821,12 @@ end:
        return ret;
 }
 
-int bt_graph_add_ports_connected_listener(
-               struct bt_graph *graph,
-               bt_graph_ports_connected_listener listener,
-               bt_graph_listener_removed listener_removed, void *data)
+int bt_private_graph_add_ports_connected_listener(
+               struct bt_private_graph *priv_graph,
+               bt_private_graph_ports_connected_listener listener,
+               bt_private_graph_listener_removed listener_removed, void *data)
 {
+       struct bt_graph *graph = (void *) priv_graph;
        int ret;
 
        if (!graph) {
@@ -852,11 +858,12 @@ end:
        return ret;
 }
 
-int bt_graph_add_ports_disconnected_listener(
-               struct bt_graph *graph,
-               bt_graph_ports_disconnected_listener listener,
-               bt_graph_listener_removed listener_removed, void *data)
+int bt_private_graph_add_ports_disconnected_listener(
+               struct bt_private_graph *priv_graph,
+               bt_private_graph_ports_disconnected_listener listener,
+               bt_private_graph_listener_removed listener_removed, void *data)
 {
+       struct bt_graph *graph = (void *) priv_graph;
        int ret;
 
        if (!graph) {
@@ -901,7 +908,7 @@ void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port)
                struct bt_graph_listener listener =
                        g_array_index(graph->listeners.port_added,
                                struct bt_graph_listener, i);
-               bt_graph_port_added_listener func = listener.func;
+               bt_private_graph_port_added_listener func = listener.func;
 
                BT_ASSERT(func);
                func(port, listener.data);
@@ -922,7 +929,7 @@ void bt_graph_notify_port_removed(struct bt_graph *graph,
                struct bt_graph_listener listener =
                        g_array_index(graph->listeners.port_removed,
                                struct bt_graph_listener, i);
-               bt_graph_port_removed_listener func = listener.func;
+               bt_private_graph_port_removed_listener func = listener.func;
 
                BT_ASSERT(func);
                func(comp, port, listener.data);
@@ -946,7 +953,7 @@ void bt_graph_notify_ports_connected(struct bt_graph *graph,
                struct bt_graph_listener listener =
                        g_array_index(graph->listeners.ports_connected,
                                struct bt_graph_listener, i);
-               bt_graph_ports_connected_listener func = listener.func;
+               bt_private_graph_ports_connected_listener func = listener.func;
 
                BT_ASSERT(func);
                func(upstream_port, downstream_port, listener.data);
@@ -972,7 +979,7 @@ void bt_graph_notify_ports_disconnected(struct bt_graph *graph,
                struct bt_graph_listener listener =
                        g_array_index(graph->listeners.ports_disconnected,
                                struct bt_graph_listener, i);
-               bt_graph_ports_disconnected_listener func = listener.func;
+               bt_private_graph_ports_disconnected_listener func = listener.func;
 
                BT_ASSERT(func);
                func(upstream_comp, downstream_comp, upstream_port,
@@ -980,8 +987,10 @@ void bt_graph_notify_ports_disconnected(struct bt_graph *graph,
        }
 }
 
-enum bt_graph_status bt_graph_cancel(struct bt_graph *graph)
+enum bt_graph_status bt_private_graph_cancel(
+               struct bt_private_graph *priv_graph)
 {
+       struct bt_graph *graph = (void *) priv_graph;
        enum bt_graph_status ret = BT_GRAPH_STATUS_OK;
 
        if (!graph) {
@@ -1023,13 +1032,14 @@ void bt_graph_remove_connection(struct bt_graph *graph,
        g_ptr_array_remove(graph->connections, connection);
 }
 
-enum bt_graph_status bt_graph_add_component_with_init_method_data(
-               struct bt_graph *graph,
+enum bt_graph_status bt_private_graph_add_component_with_init_method_data(
+               struct bt_private_graph *priv_graph,
                struct bt_component_class *component_class,
                const char *name, struct bt_value *params,
                void *init_method_data,
                struct bt_component **user_component)
 {
+       struct bt_graph *graph = (void *) priv_graph;
        enum bt_graph_status graph_status = BT_GRAPH_STATUS_OK;
        enum bt_component_status comp_status;
        struct bt_component *component = NULL;
@@ -1194,13 +1204,13 @@ end:
        return graph_status;
 }
 
-enum bt_graph_status bt_graph_add_component(
-               struct bt_graph *graph,
+enum bt_graph_status bt_private_graph_add_component(
+               struct bt_private_graph *graph,
                struct bt_component_class *component_class,
                const char *name, struct bt_value *params,
                struct bt_component **component)
 {
-       return bt_graph_add_component_with_init_method_data(graph,
+       return bt_private_graph_add_component_with_init_method_data(graph,
                component_class, name, params, NULL, component);
 }
 
@@ -1305,3 +1315,9 @@ void bt_graph_add_notification(struct bt_graph *graph,
         */
        g_ptr_array_add(graph->notifications, notif);
 }
+
+struct bt_graph *bt_graph_borrow_from_private(
+               struct bt_private_graph *priv_graph)
+{
+       return (void *) priv_graph;
+}
index 11aca63bab425b4e551c203cd193c0ed0fdcb1ca..ffaf7d453778f40b88d0e0d153b3495f1e52d5fc 100644 (file)
@@ -53,6 +53,7 @@
 #include <babeltrace/graph/notification-stream.h>
 #include <babeltrace/graph/notification-stream-internal.h>
 #include <babeltrace/graph/port.h>
+#include <babeltrace/graph/private-graph.h>
 #include <babeltrace/graph/graph-internal.h>
 #include <babeltrace/types.h>
 #include <babeltrace/assert-internal.h>
@@ -919,8 +920,8 @@ struct bt_notification_iterator *bt_output_port_notification_iterator_create(
        colander_data.notifs = (void *) iterator->base.notifs->pdata;
        colander_data.count_addr = &iterator->count;
 
-       graph_status = bt_graph_add_component_with_init_method_data(
-               iterator->graph, colander_comp_cls, colander_comp_name,
+       graph_status = bt_private_graph_add_component_with_init_method_data(
+               (void *) iterator->graph, colander_comp_cls, colander_comp_name,
                NULL, &colander_data, &iterator->colander);
        if (graph_status != BT_GRAPH_STATUS_OK) {
                BT_LOGW("Cannot add colander sink component to graph: "
@@ -937,7 +938,7 @@ struct bt_notification_iterator *bt_output_port_notification_iterator_create(
        colander_in_port = bt_component_sink_get_input_port_by_index(
                iterator->colander, 0);
        BT_ASSERT(colander_in_port);
-       graph_status = bt_graph_connect_ports(iterator->graph,
+       graph_status = bt_private_graph_connect_ports((void *) iterator->graph,
                output_port, colander_in_port, NULL);
        if (graph_status != BT_GRAPH_STATUS_OK) {
                BT_LOGW("Cannot add colander sink component to graph: "
index 098a183659249937a88c548241300a6e04a54462..1f0b84468404377553c7a7cf405a020653ab886c 100644 (file)
@@ -92,7 +92,7 @@ bt_bool lttng_live_is_canceled(struct lttng_live_component *lttng_live)
 
        component = bt_component_from_private(lttng_live->private_component);
        graph = bt_component_get_graph(component);
-       ret = bt_graph_is_canceled(graph);
+       ret = bt_private_graph_is_canceled(graph);
        bt_object_put_ref(graph);
        bt_object_put_ref(component);
        return ret;
index 988f84e7e38d6324a3f2756f233735072107509f..606decdf411d69aa87b4c62d7869635d139a54cb 100644 (file)
@@ -54,7 +54,7 @@ struct test_event {
 static bool debug = false;
 static enum test current_test;
 static GArray *test_events;
-static struct bt_graph *graph;
+static struct bt_private_graph *graph;
 static struct bt_private_connection_private_notification_iterator *cur_notif_iter;
 static struct bt_private_stream_class *src_stream_class;
 static struct bt_private_event_class *src_event_class;
@@ -692,7 +692,7 @@ void sink_finalize(struct bt_private_component *private_component)
 }
 
 static
-void create_source_sink(struct bt_graph *graph, struct bt_component **source,
+void create_source_sink(struct bt_private_graph *graph, struct bt_component **source,
                struct bt_component **sink)
 {
        struct bt_component_class *src_comp_class;
@@ -716,7 +716,7 @@ void create_source_sink(struct bt_graph *graph, struct bt_component **source,
                ret = bt_component_class_source_set_notification_iterator_finalize_method(
                        src_comp_class, src_iter_finalize);
                BT_ASSERT(ret == 0);
-               ret = bt_graph_add_component(graph, src_comp_class, "source",
+               ret = bt_private_graph_add_component(graph, src_comp_class, "source",
                        NULL, source);
                BT_ASSERT(ret == 0);
                bt_object_put_ref(src_comp_class);
@@ -735,7 +735,7 @@ void create_source_sink(struct bt_graph *graph, struct bt_component **source,
                ret = bt_component_class_set_port_connected_method(
                        sink_comp_class, sink_port_connected);
                BT_ASSERT(ret == 0);
-               ret = bt_graph_add_component(graph, sink_comp_class, "sink",
+               ret = bt_private_graph_add_component(graph, sink_comp_class, "sink",
                        NULL, sink);
                BT_ASSERT(ret == 0);
                bt_object_put_ref(sink_comp_class);
@@ -756,7 +756,7 @@ void do_std_test(enum test test, const char *name,
        current_test = test;
        diag("test: %s", name);
        BT_ASSERT(!graph);
-       graph = bt_graph_create();
+       graph = bt_private_graph_create();
        BT_ASSERT(graph);
        create_source_sink(graph, &src_comp, &sink_comp);
 
@@ -765,7 +765,7 @@ void do_std_test(enum test test, const char *name,
        BT_ASSERT(upstream_port);
        downstream_port = bt_component_sink_get_input_port_by_name(sink_comp, "in");
        BT_ASSERT(downstream_port);
-       graph_status = bt_graph_connect_ports(graph, upstream_port,
+       graph_status = bt_private_graph_connect_ports(graph, upstream_port,
                downstream_port, NULL);
        bt_object_put_ref(upstream_port);
        bt_object_put_ref(downstream_port);
@@ -773,7 +773,7 @@ void do_std_test(enum test test, const char *name,
        /* Run the graph until the end */
        while (graph_status == BT_GRAPH_STATUS_OK ||
                        graph_status == BT_GRAPH_STATUS_AGAIN) {
-               graph_status = bt_graph_run(graph);
+               graph_status = bt_private_graph_run(graph);
        }
 
        ok(graph_status == BT_GRAPH_STATUS_END, "graph finishes without any error");
@@ -850,7 +850,7 @@ void test_output_port_notification_iterator(void)
        current_test = TEST_OUTPUT_PORT_NOTIFICATION_ITERATOR;
        diag("test: output port notification iterator");
        BT_ASSERT(!graph);
-       graph = bt_graph_create();
+       graph = bt_private_graph_create();
        BT_ASSERT(graph);
        create_source_sink(graph, &src_comp, NULL);
 
index c3b50e0950539679777cb0adc2c09e4c48c2958b..bb29db0b1a5a9eac4d5fb4dcbcc2eff5f27ee88c 100644 (file)
@@ -24,6 +24,7 @@
 #include <babeltrace/graph/component.h>
 #include <babeltrace/graph/component-source.h>
 #include <babeltrace/graph/component-sink.h>
+#include <babeltrace/graph/private-graph.h>
 #include <babeltrace/graph/graph.h>
 #include <babeltrace/graph/connection.h>
 #include <babeltrace/graph/port.h>
@@ -591,46 +592,46 @@ void fini_test(void)
 }
 
 static
-struct bt_component *create_src(struct bt_graph *graph)
+struct bt_component *create_src(struct bt_private_graph *graph)
 {
        struct bt_component *comp;
        int ret;
 
-       ret = bt_graph_add_component(graph, src_comp_class, "src-comp", NULL,
+       ret = bt_private_graph_add_component(graph, src_comp_class, "src-comp", NULL,
                &comp);
        BT_ASSERT(ret == 0);
        return comp;
 }
 
 static
-struct bt_component *create_sink(struct bt_graph *graph)
+struct bt_component *create_sink(struct bt_private_graph *graph)
 {
        struct bt_component *comp;
        int ret;
 
-       ret = bt_graph_add_component(graph, sink_comp_class, "sink-comp",
+       ret = bt_private_graph_add_component(graph, sink_comp_class, "sink-comp",
                NULL, &comp);
        BT_ASSERT(ret == 0);
        return comp;
 }
 
 static
-struct bt_graph *create_graph(void)
+struct bt_private_graph *create_graph(void)
 {
-       struct bt_graph *graph = bt_graph_create();
+       struct bt_private_graph *graph = bt_private_graph_create();
        int ret;
 
        BT_ASSERT(graph);
-       ret = bt_graph_add_port_added_listener(graph, graph_port_added, NULL,
+       ret = bt_private_graph_add_port_added_listener(graph, graph_port_added, NULL,
                NULL);
        BT_ASSERT(ret >= 0);
-       ret = bt_graph_add_port_removed_listener(graph, graph_port_removed,
+       ret = bt_private_graph_add_port_removed_listener(graph, graph_port_removed,
                NULL, NULL);
        BT_ASSERT(ret >= 0);
-       ret = bt_graph_add_ports_connected_listener(graph,
+       ret = bt_private_graph_add_ports_connected_listener(graph,
                graph_ports_connected, NULL, NULL);
        BT_ASSERT(ret >= 0);
-       ret = bt_graph_add_ports_disconnected_listener(graph,
+       ret = bt_private_graph_add_ports_disconnected_listener(graph,
                graph_ports_disconnected, NULL, NULL);
        BT_ASSERT(ret >= 0);
        return graph;
@@ -650,7 +651,7 @@ void test_sink_removes_port_in_port_connected_then_src_removes_disconnected_port
        int ret;
        struct bt_component *src;
        struct bt_component *sink;
-       struct bt_graph *graph;
+       struct bt_private_graph *graph;
        struct bt_port *src_def_port;
        struct bt_port *sink_def_port;
        struct bt_connection *conn;
@@ -677,7 +678,7 @@ void test_sink_removes_port_in_port_connected_then_src_removes_disconnected_port
        BT_ASSERT(src_def_port);
        sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in");
        BT_ASSERT(sink_def_port);
-       status = bt_graph_connect_ports(graph, src_def_port, sink_def_port,
+       status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port,
                &conn);
        BT_ASSERT(status == 0);
        BT_ASSERT(conn);
@@ -751,7 +752,7 @@ void test_sink_removes_port_in_port_connected_then_src_removes_disconnected_port
 
        /* Consume sink once */
        clear_events();
-       ret = bt_graph_consume(graph);
+       ret = bt_private_graph_consume(graph);
        BT_ASSERT(ret == 0);
 
        /* We're supposed to have 5 new events */
@@ -828,7 +829,7 @@ void test_sink_removes_port_in_port_connected(void)
        int ret;
        struct bt_component *src;
        struct bt_component *sink;
-       struct bt_graph *graph;
+       struct bt_private_graph *graph;
        struct bt_port *src_def_port;
        struct bt_port *sink_def_port;
        struct bt_connection *conn;
@@ -854,7 +855,7 @@ void test_sink_removes_port_in_port_connected(void)
        BT_ASSERT(src_def_port);
        sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in");
        BT_ASSERT(sink_def_port);
-       status = bt_graph_connect_ports(graph, src_def_port, sink_def_port,
+       status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port,
                &conn);
        BT_ASSERT(status == 0);
 
@@ -927,7 +928,7 @@ void test_sink_removes_port_in_port_connected(void)
 
        /* Consume sink once */
        clear_events();
-       ret = bt_graph_consume(graph);
+       ret = bt_private_graph_consume(graph);
        BT_ASSERT(ret == 0);
 
        /* We're supposed to have 4 new events */
@@ -988,7 +989,7 @@ void test_src_adds_port_in_port_connected(void)
 {
        struct bt_component *src;
        struct bt_component *sink;
-       struct bt_graph *graph;
+       struct bt_private_graph *graph;
        struct bt_port *src_def_port;
        struct bt_port *sink_def_port;
        struct bt_port *src_hello_port;
@@ -1012,7 +1013,7 @@ void test_src_adds_port_in_port_connected(void)
        BT_ASSERT(src_def_port);
        sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in");
        BT_ASSERT(sink_def_port);
-       status = bt_graph_connect_ports(graph, src_def_port, sink_def_port,
+       status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port,
                &conn);
        BT_ASSERT(status == 0);
        src_hello_port = bt_component_source_get_output_port_by_name(src,
@@ -1111,7 +1112,7 @@ void test_simple(void)
 {
        struct bt_component *src;
        struct bt_component *sink;
-       struct bt_graph *graph;
+       struct bt_private_graph *graph;
        struct bt_port *src_def_port;
        struct bt_port *sink_def_port;
        struct bt_connection *conn;
@@ -1132,7 +1133,7 @@ void test_simple(void)
        BT_ASSERT(src_def_port);
        sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in");
        BT_ASSERT(sink_def_port);
-       status = bt_graph_connect_ports(graph, src_def_port, sink_def_port,
+       status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port,
                &conn);
        BT_ASSERT(status == 0);
 
@@ -1216,7 +1217,7 @@ void test_src_port_connected_error(void)
 {
        struct bt_component *src;
        struct bt_component *sink;
-       struct bt_graph *graph;
+       struct bt_private_graph *graph;
        struct bt_port *src_def_port;
        struct bt_port *sink_def_port;
        struct bt_connection *conn = NULL;
@@ -1234,10 +1235,10 @@ void test_src_port_connected_error(void)
        BT_ASSERT(src_def_port);
        sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in");
        BT_ASSERT(sink_def_port);
-       status = bt_graph_connect_ports(graph, src_def_port, sink_def_port,
+       status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port,
                &conn);
        ok(status != BT_GRAPH_STATUS_OK,
-               "bt_graph_connect_ports() returns an error");
+               "bt_private_graph_connect_ports() returns an error");
        ok(!conn, "returned connection is NULL");
 
        /* We're supposed to have 5 events */
@@ -1295,7 +1296,7 @@ void test_sink_port_connected_error(void)
 {
        struct bt_component *src;
        struct bt_component *sink;
-       struct bt_graph *graph;
+       struct bt_private_graph *graph;
        struct bt_port *src_def_port;
        struct bt_port *sink_def_port;
        struct bt_connection *conn = NULL;
@@ -1316,10 +1317,10 @@ void test_sink_port_connected_error(void)
        BT_ASSERT(src_def_port);
        sink_def_port = bt_component_sink_get_input_port_by_name(sink, "in");
        BT_ASSERT(sink_def_port);
-       status = bt_graph_connect_ports(graph, src_def_port, sink_def_port,
+       status = bt_private_graph_connect_ports(graph, src_def_port, sink_def_port,
                &conn);
        ok(status != BT_GRAPH_STATUS_OK,
-               "bt_graph_connect_ports() returns an error");
+               "bt_private_graph_connect_ports() returns an error");
        ok(!conn, "returned connection is NULL");
 
        /* We're supposed to have 5 events */
@@ -1395,7 +1396,7 @@ void test_sink_port_connected_error(void)
 static
 void test_empty_graph(void)
 {
-       struct bt_graph *graph;
+       struct bt_private_graph *graph;
 
        prepare_test(TEST_EMPTY_GRAPH, "empty graph");
        graph = create_graph();
index c11fd12f9773d3d98e71a1a3d2790d623a3cffbf..eb4fd2ae2397820c07ced439c8933ca215ebe0da 100644 (file)
@@ -1,8 +1,4 @@
 /*
- * test_plugin.c
- *
- * Trace IR Reference Count test
- *
  * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -24,6 +20,7 @@
 #include <babeltrace/values.h>
 #include <babeltrace/private-values.h>
 #include <babeltrace/graph/component.h>
+#include <babeltrace/graph/private-graph.h>
 #include <babeltrace/graph/graph.h>
 #include <babeltrace/graph/query-executor.h>
 #include <stdlib.h>
@@ -166,7 +163,7 @@ static void test_sfs(const char *plugin_dir)
        struct bt_value *results;
        struct bt_value *object;
        struct bt_value *res_params;
-       struct bt_graph *graph;
+       struct bt_private_graph *graph;
        const char *object_str;
        enum bt_graph_status graph_ret;
        struct bt_query_executor *query_exec = bt_query_executor_create();
@@ -243,30 +240,30 @@ static void test_sfs(const char *plugin_dir)
 
        diag("> putting the plugin object here");
        BT_OBJECT_PUT_REF_AND_RESET(plugin);
-       graph = bt_graph_create();
+       graph = bt_private_graph_create();
        BT_ASSERT(graph);
-       graph_ret = bt_graph_add_component(graph, sink_comp_class, "the-sink",
+       graph_ret = bt_private_graph_add_component(graph, sink_comp_class, "the-sink",
                NULL, &sink_component);
        ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component,
-               "bt_graph_add_component() still works after the plugin object is destroyed");
+               "bt_private_graph_add_component() still works after the plugin object is destroyed");
        BT_OBJECT_PUT_REF_AND_RESET(sink_component);
        BT_OBJECT_PUT_REF_AND_RESET(source_comp_class);
        bt_object_put_ref(graph);
-       graph = bt_graph_create();
+       graph = bt_private_graph_create();
        BT_ASSERT(graph);
-       graph_ret = bt_graph_add_component(graph, sink_comp_class, "the-sink",
+       graph_ret = bt_private_graph_add_component(graph, sink_comp_class, "the-sink",
                NULL, &sink_component);
        ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component,
-               "bt_graph_add_component() still works after the source component class object is destroyed");
+               "bt_private_graph_add_component() still works after the source component class object is destroyed");
        BT_OBJECT_PUT_REF_AND_RESET(sink_component);
        BT_OBJECT_PUT_REF_AND_RESET(filter_comp_class);
        bt_object_put_ref(graph);
-       graph = bt_graph_create();
+       graph = bt_private_graph_create();
        BT_ASSERT(graph);
-       graph_ret = bt_graph_add_component(graph, sink_comp_class, "the-sink",
+       graph_ret = bt_private_graph_add_component(graph, sink_comp_class, "the-sink",
                NULL, &sink_component);
        ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component,
-               "bt_graph_add_component() still works after the filter component class object is destroyed");
+               "bt_private_graph_add_component() still works after the filter component class object is destroyed");
        BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
        BT_OBJECT_PUT_REF_AND_RESET(sink_component);
 
This page took 0.042573 seconds and 4 git commands to generate.