X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcli%2Fbabeltrace2.c;h=b67acd74cac7aa708292ccbde5eb0ddecef88286;hb=056deb59eb33e87c06c0067907768ab08aff74a2;hp=9699b0c3b5e46fba695fbbf6d4614df0f413f559;hpb=9b4f9b425f2efce9a6ccc25f7ae062ebc1116a7d;p=babeltrace.git diff --git a/src/cli/babeltrace2.c b/src/cli/babeltrace2.c index 9699b0c3..b67acd74 100644 --- a/src/cli/babeltrace2.c +++ b/src/cli/babeltrace2.c @@ -29,7 +29,6 @@ #include "common/common.h" #include #include -#include #include #include #include @@ -40,6 +39,7 @@ #include "babeltrace2-cfg-cli-args.h" #include "babeltrace2-cfg-cli-args-default.h" #include "babeltrace2-plugins.h" +#include "babeltrace2-query.h" #define ENV_BABELTRACE_WARN_COMMAND_NAME_DIRECTORY_CLASH "BABELTRACE_CLI_WARN_COMMAND_NAME_DIRECTORY_CLASH" #define ENV_BABELTRACE_CLI_LOG_LEVEL "BABELTRACE_CLI_LOG_LEVEL" @@ -57,7 +57,6 @@ static const char* log_level_env_var_names[] = { /* Application's interrupter (owned by this) */ static bt_interrupter *the_interrupter; -static volatile bool interrupted = false; #ifdef __MINGW32__ @@ -69,7 +68,6 @@ BOOL WINAPI signal_handler(DWORD signal) { bt_interrupter_set(the_interrupter); } - interrupted = true; return TRUE; } @@ -93,8 +91,6 @@ void signal_handler(int signum) if (the_interrupter) { bt_interrupter_set(the_interrupter); } - - interrupted = true; } static @@ -119,106 +115,10 @@ int query(struct bt_config *cfg, const bt_component_class *comp_cls, const char *obj, const bt_value *params, const bt_value **user_result, const char **fail_reason) { - const bt_value *result = NULL; - bt_query_executor_query_status query_status; - bt_query_executor *query_exec; - *fail_reason = "unknown error"; - int ret = 0; - - BT_ASSERT(fail_reason); - BT_ASSERT(user_result); - query_exec = bt_query_executor_create(); - if (!query_exec) { - BT_CLI_LOGE_APPEND_CAUSE("Cannot create a query executor."); - goto error; - } - - bt_query_executor_add_interrupter(query_exec, the_interrupter); - - if (interrupted) { - BT_CLI_LOGW_APPEND_CAUSE( - "Interrupted by user before executing the query: " - "comp-cls-addr=%p, comp-cls-name=\"%s\", " - "query-obj=\"%s\"", comp_cls, - bt_component_class_get_name(comp_cls), obj); - *fail_reason = "interrupted by user"; - goto error; - } - - while (true) { - query_status = bt_query_executor_query( - query_exec, comp_cls, obj, params, - cfg->log_level, &result); - switch (query_status) { - case BT_QUERY_EXECUTOR_QUERY_STATUS_OK: - goto ok; - case BT_QUERY_EXECUTOR_QUERY_STATUS_AGAIN: - { - const uint64_t sleep_time_us = 100000; - - if (bt_interrupter_is_set(the_interrupter)) { - *fail_reason = "interrupted by user"; - goto error; - } - - /* Wait 100 ms and retry */ - BT_LOGD("Got BT_QUERY_EXECUTOR_QUERY_STATUS_AGAIN: sleeping: " - "time-us=%" PRIu64, sleep_time_us); - - if (usleep(sleep_time_us)) { - if (bt_interrupter_is_set(the_interrupter)) { - BT_CLI_LOGW_APPEND_CAUSE( - "Query was interrupted by user: " - "comp-cls-addr=%p, comp-cls-name=\"%s\", " - "query-obj=\"%s\"", comp_cls, - bt_component_class_get_name(comp_cls), - obj); - *fail_reason = "interrupted by user"; - goto error; - } - } - - continue; - } - case BT_QUERY_EXECUTOR_QUERY_STATUS_ERROR: - if (bt_interrupter_is_set(the_interrupter)) { - *fail_reason = "interrupted by user"; - goto error; - } - - goto error; - case BT_QUERY_EXECUTOR_QUERY_STATUS_INVALID_OBJECT: - *fail_reason = "invalid or unknown query object"; - goto error; - case BT_QUERY_EXECUTOR_QUERY_STATUS_INVALID_PARAMS: - *fail_reason = "invalid query parameters"; - goto error; - case BT_QUERY_EXECUTOR_QUERY_STATUS_MEMORY_ERROR: - *fail_reason = "not enough memory"; - goto error; - default: - BT_LOGF("Unknown query status: status=%s", - bt_common_func_status_string(query_status)); - abort(); - } - } - -ok: - *user_result = result; - result = NULL; - goto end; - -error: - ret = -1; - -end: - bt_query_executor_put_ref(query_exec); - bt_value_put_ref(result); - return ret; + return cli_query(comp_cls, obj, params, cfg->log_level, + the_interrupter, user_result, fail_reason); } - - typedef const void *(*plugin_borrow_comp_cls_func_t)( const bt_plugin *, const char *); @@ -1845,7 +1745,7 @@ int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg) } } - ctx->graph = bt_graph_create(); + ctx->graph = bt_graph_create(0); if (!ctx->graph) { goto error; } @@ -1901,11 +1801,11 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, const bt_component_class *comp_cls = bt_component_class_source_as_component_class_const(src_comp_cls); - ret = query(ctx->cfg, comp_cls, "trace-info", + ret = query(ctx->cfg, comp_cls, "babeltrace.trace-info", cfg_comp->params, &query_result, &fail_reason); if (ret) { - BT_LOGD("Component class does not support the `trace-info` query: %s: " + BT_LOGD("Component class does not support the `babeltrace.trace-info` query: %s: " "comp-class-name=\"%s\"", fail_reason, bt_component_class_get_name(comp_cls)); ret = -1; @@ -1915,7 +1815,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx, BT_ASSERT(query_result); if (!bt_value_is_array(query_result)) { - BT_LOGD("Unexpected format of \'trace-info\' query result: " + BT_LOGD("Unexpected format of `babeltrace.trace-info` query result: " "component-class-name=%s", bt_component_class_get_name(comp_cls)); ret = -1; @@ -2311,7 +2211,7 @@ int cmd_run(struct bt_config *cfg) goto error; } - if (interrupted) { + if (bt_interrupter_is_set(the_interrupter)) { BT_CLI_LOGW_APPEND_CAUSE( "Interrupted by user before creating components."); goto error; @@ -2325,7 +2225,7 @@ int cmd_run(struct bt_config *cfg) goto error; } - if (interrupted) { + if (bt_interrupter_is_set(the_interrupter)) { BT_CLI_LOGW_APPEND_CAUSE( "Interrupted by user before connecting components."); goto error; @@ -2340,12 +2240,6 @@ int cmd_run(struct bt_config *cfg) goto error; } - if (interrupted) { - BT_CLI_LOGW_APPEND_CAUSE( - "Interrupted by user before running the graph."); - goto error; - } - BT_LOGI_STR("Running the graph."); /* Run the graph */ @@ -2637,9 +2531,7 @@ void print_error_causes(void) } end: - if (folded) { - g_string_free(folded, TRUE); - } + BT_ASSERT(!folded); if (error) { bt_error_release(error);