Graph API: split into private and public APIs
[babeltrace.git] / cli / babeltrace.c
index 8e17c2a10458ced2cd046bae543be6caab2f9a2e..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
@@ -438,7 +438,6 @@ void print_value_rec(FILE *fp, struct bt_value *value, size_t indent)
        const char *str_val;
        int size;
        int i;
-       enum bt_value_status status;
 
        if (!value) {
                return;
@@ -450,37 +449,25 @@ void print_value_rec(FILE *fp, struct bt_value *value, size_t indent)
                        bt_common_color_reset());
                break;
        case BT_VALUE_TYPE_BOOL:
-               status = bt_value_bool_get(value, &bool_val);
-               if (status != BT_VALUE_STATUS_OK) {
-                       goto error;
-               }
+               bool_val = bt_value_bool_get(value);
                fprintf(fp, "%s%s%s%s\n", bt_common_color_bold(),
                        bt_common_color_fg_cyan(), bool_val ? "yes" : "no",
                        bt_common_color_reset());
                break;
        case BT_VALUE_TYPE_INTEGER:
-               status = bt_value_integer_get(value, &int_val);
-               if (status != BT_VALUE_STATUS_OK) {
-                       goto error;
-               }
+               int_val = bt_value_integer_get(value);
                fprintf(fp, "%s%s%" PRId64 "%s\n", bt_common_color_bold(),
                        bt_common_color_fg_red(), int_val,
                        bt_common_color_reset());
                break;
        case BT_VALUE_TYPE_REAL:
-               status = bt_value_real_get(value, &dbl_val);
-               if (status != BT_VALUE_STATUS_OK) {
-                       goto error;
-               }
+               dbl_val = bt_value_real_get(value);
                fprintf(fp, "%s%s%lf%s\n", bt_common_color_bold(),
                        bt_common_color_fg_red(), dbl_val,
                        bt_common_color_reset());
                break;
        case BT_VALUE_TYPE_STRING:
-               status = bt_value_string_get(value, &str_val);
-               if (status != BT_VALUE_STATUS_OK) {
-                       goto error;
-               }
+               str_val = bt_value_string_get(value);
                fprintf(fp, "%s%s%s%s\n", bt_common_color_bold(),
                        bt_common_color_fg_green(), str_val,
                        bt_common_color_reset());
@@ -762,15 +749,10 @@ int load_dynamic_plugins(struct bt_value *plugin_paths)
                struct bt_value *plugin_path_value = NULL;
                const char *plugin_path;
                struct bt_plugin_set *plugin_set;
-               enum bt_value_status status;
 
                plugin_path_value = bt_value_array_borrow_element_by_index(
                        plugin_paths, i);
-               status = bt_value_string_get(plugin_path_value, &plugin_path);
-               if (status != BT_VALUE_STATUS_OK) {
-                       BT_LOGD_STR("Cannot get plugin path string.");
-                       continue;
-               }
+               plugin_path = bt_value_string_get(plugin_path_value);
 
                /*
                 * Skip this if the directory does not exist because
@@ -1235,32 +1217,28 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                        BT_LOGE_STR("Unexpected empty array \"url\" entry.");
                        goto error;
                }
-               ret = bt_value_string_get(v, &url_text);
-               BT_ASSERT(ret == 0);
+               url_text = bt_value_string_get(v);
                fprintf(out_stream, "%s", url_text);
                v = bt_value_map_borrow_entry_value(map, "timer-us");
                if (!v) {
                        BT_LOGE_STR("Unexpected empty array \"timer-us\" entry.");
                        goto error;
                }
-               ret = bt_value_integer_get(v, &timer_us);
-               BT_ASSERT(ret == 0);
+               timer_us = bt_value_integer_get(v);
                fprintf(out_stream, " (timer = %" PRIu64 ", ", timer_us);
                v = bt_value_map_borrow_entry_value(map, "stream-count");
                if (!v) {
                        BT_LOGE_STR("Unexpected empty array \"stream-count\" entry.");
                        goto error;
                }
-               ret = bt_value_integer_get(v, &streams);
-               BT_ASSERT(ret == 0);
+               streams = bt_value_integer_get(v);
                fprintf(out_stream, "%" PRIu64 " stream(s), ", streams);
                v = bt_value_map_borrow_entry_value(map, "client-count");
                if (!v) {
                        BT_LOGE_STR("Unexpected empty array \"client-count\" entry.");
                        goto error;
                }
-               ret = bt_value_integer_get(v, &clients);
-               BT_ASSERT(ret == 0);
+               clients = bt_value_integer_get(v);
                fprintf(out_stream, "%" PRIu64 " client(s) connected)\n", clients);
        }
 
@@ -1356,8 +1334,7 @@ int cmd_print_ctf_metadata(struct bt_config *cfg)
                goto end;
        }
 
-       ret = bt_value_string_get(metadata_text_value, &metadata_text);
-       BT_ASSERT(ret == 0);
+       metadata_text = bt_value_string_get(metadata_text_value);
 
        if (cfg->cmd_data.print_ctf_metadata.output_path->len > 0) {
                out_stream =
@@ -1460,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;
@@ -1691,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);
@@ -1727,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) {
@@ -2043,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.");
@@ -2122,14 +2099,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx,
                goto error;
        }
 
-       value_status = bt_value_string_get(component_path_value, &path);
-       if (value_status != BT_VALUE_STATUS_OK) {
-               BT_LOGD("Cannot get path string value: component-name=%s",
-                       cfg_comp->instance_name->str);
-               ret = -1;
-               goto error;
-       }
-
+       path = bt_value_string_get(component_path_value);
        query_params = bt_private_value_map_create();
        if (!query_params) {
                BT_LOGE_STR("Cannot create query parameters.");
@@ -2209,19 +2179,8 @@ int set_stream_intersections(struct cmd_run_ctx *ctx,
                        goto error;
                }
 
-               value_status = bt_value_integer_get(intersection_begin, &begin);
-               if (value_status != BT_VALUE_STATUS_OK) {
-                       ret = -1;
-                       BT_LOGD_STR("Cannot retrieve value of intersection-range-ns \'begin\' field from query result.");
-                       goto error;
-               }
-
-               value_status = bt_value_integer_get(intersection_end, &end);
-               if (value_status != BT_VALUE_STATUS_OK) {
-                       ret = -1;
-                       BT_LOGD_STR("Cannot retrieve value of intersection-range-ns \'end\' field from query result.");
-                       goto error;
-               }
+               begin = bt_value_integer_get(intersection_begin);
+               end = bt_value_integer_get(intersection_end);
 
                if (begin < 0 || end < 0 || end < begin) {
                        BT_LOGW("Invalid trace stream intersection values: "
@@ -2309,13 +2268,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx,
                                goto error;
                        }
 
-                       value_status = bt_value_string_get(stream_path_value,
-                               &stream_path);
-                       if (value_status != BT_VALUE_STATUS_OK) {
-                               ret = -1;
-                               goto error;
-                       }
-
+                       stream_path = bt_value_string_get(stream_path_value);
                        port_id->port_name = strdup(stream_path);
                        if (!port_id->port_name) {
                                ret = -1;
@@ -2382,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) {
@@ -2607,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
@@ -2616,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) {
@@ -2626,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;
                        }
@@ -2637,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;
                                        }
This page took 0.028724 seconds and 4 git commands to generate.