From: Philippe Proulx Date: Fri, 30 Nov 2018 22:15:03 +0000 (-0500) Subject: lib: have separate `BT_QUERY_EXECUTOR_STATUS` and `BT_QUERY_STATUS` X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=d72535e6e6b00451170da6797ddeb7e0d66f0e0b;hp=5bb956fb21656a273b9c1d325c382378c66d5515;p=babeltrace.git lib: have separate `BT_QUERY_EXECUTOR_STATUS` and `BT_QUERY_STATUS` The former is for the query executor API, the latter is returned by an actual user-defined query method. `BT_QUERY_STATUS` does not have "canceled" and "unsupported" entries, so we can remove those checks from bt_private_query_executor_query() after calling the user method. Signed-off-by: Philippe Proulx --- diff --git a/cli/babeltrace.c b/cli/babeltrace.c index 29a54a58..8a917a79 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -173,7 +173,7 @@ int query(struct bt_component_class *comp_cls, const char *obj, const char **fail_reason) { struct bt_value *result = NULL; - enum bt_query_status status; + enum bt_query_executor_status status; *fail_reason = "unknown error"; int ret = 0; @@ -198,14 +198,14 @@ int query(struct bt_component_class *comp_cls, const char *obj, status = bt_private_query_executor_query(the_query_executor, comp_cls, obj, params, &result); switch (status) { - case BT_QUERY_STATUS_OK: + case BT_QUERY_EXECUTOR_STATUS_OK: goto ok; - case BT_QUERY_STATUS_AGAIN: + case BT_QUERY_EXECUTOR_STATUS_AGAIN: { const uint64_t sleep_time_us = 100000; /* Wait 100 ms and retry */ - BT_LOGV("Got BT_QUERY_STATUS_AGAIN: sleeping: " + BT_LOGV("Got BT_QUERY_EXECUTOR_STATUS_AGAIN: sleeping: " "time-us=%" PRIu64, sleep_time_us); if (usleep(sleep_time_us)) { @@ -223,18 +223,21 @@ int query(struct bt_component_class *comp_cls, const char *obj, continue; } - case BT_QUERY_STATUS_EXECUTOR_CANCELED: + case BT_QUERY_EXECUTOR_STATUS_CANCELED: *fail_reason = "canceled by user"; goto error; - case BT_QUERY_STATUS_ERROR: + case BT_QUERY_EXECUTOR_STATUS_ERROR: goto error; - case BT_QUERY_STATUS_INVALID_OBJECT: + case BT_QUERY_EXECUTOR_STATUS_INVALID_OBJECT: *fail_reason = "invalid or unknown query object"; goto error; - case BT_QUERY_STATUS_INVALID_PARAMS: + case BT_QUERY_EXECUTOR_STATUS_INVALID_PARAMS: *fail_reason = "invalid query parameters"; goto error; - case BT_QUERY_STATUS_NOMEM: + case BT_QUERY_EXECUTOR_STATUS_UNSUPPORTED: + *fail_reason = "unsupported action"; + goto error; + case BT_QUERY_EXECUTOR_STATUS_NOMEM: *fail_reason = "not enough memory"; goto error; default: diff --git a/include/babeltrace/graph/private-component-class-filter.h b/include/babeltrace/graph/private-component-class-filter.h index 3830a50c..2e09c120 100644 --- a/include/babeltrace/graph/private-component-class-filter.h +++ b/include/babeltrace/graph/private-component-class-filter.h @@ -31,13 +31,11 @@ /* For enum bt_self_component_status */ #include -/* For enum bt_query_status */ -#include /* For enum bt_self_notification_iterator_status */ #include -/* For struct bt_private_component_class_query_method_return */ +/* For enum bt_query_status */ #include #ifdef __cplusplus diff --git a/include/babeltrace/graph/private-component-class-sink.h b/include/babeltrace/graph/private-component-class-sink.h index 9a1b7151..c347ac47 100644 --- a/include/babeltrace/graph/private-component-class-sink.h +++ b/include/babeltrace/graph/private-component-class-sink.h @@ -32,9 +32,6 @@ #include /* For enum bt_query_status */ -#include - -/* For struct bt_private_component_class_query_method_return */ #include #ifdef __cplusplus diff --git a/include/babeltrace/graph/private-component-class-source.h b/include/babeltrace/graph/private-component-class-source.h index 3238a623..c9d495b8 100644 --- a/include/babeltrace/graph/private-component-class-source.h +++ b/include/babeltrace/graph/private-component-class-source.h @@ -31,13 +31,10 @@ /* For enum bt_self_component_status */ #include -/* For enum bt_query_status */ -#include - /* For enum bt_self_notification_iterator_status */ #include -/* For struct bt_private_component_class_query_method_return */ +/* For enum bt_query_status */ #include #ifdef __cplusplus diff --git a/include/babeltrace/graph/private-component-class.h b/include/babeltrace/graph/private-component-class.h index c8a76305..804f21e8 100644 --- a/include/babeltrace/graph/private-component-class.h +++ b/include/babeltrace/graph/private-component-class.h @@ -23,7 +23,7 @@ * SOFTWARE. */ -/* For enum bt_query_status */ +/* For enum bt_query_executor_status */ #include #ifdef __cplusplus @@ -33,6 +33,15 @@ extern "C" { struct bt_component_class; struct bt_private_component_class; +enum bt_query_status { + BT_QUERY_STATUS_OK = BT_QUERY_EXECUTOR_STATUS_OK, + BT_QUERY_STATUS_AGAIN = BT_QUERY_EXECUTOR_STATUS_AGAIN, + BT_QUERY_STATUS_ERROR = BT_QUERY_EXECUTOR_STATUS_ERROR, + BT_QUERY_STATUS_NOMEM = BT_QUERY_EXECUTOR_STATUS_NOMEM, + BT_QUERY_STATUS_INVALID_OBJECT = BT_QUERY_EXECUTOR_STATUS_INVALID_OBJECT, + BT_QUERY_STATUS_INVALID_PARAMS = BT_QUERY_EXECUTOR_STATUS_INVALID_PARAMS, +}; + static inline struct bt_component_class * bt_private_component_class_as_component_class( diff --git a/include/babeltrace/graph/private-query-executor.h b/include/babeltrace/graph/private-query-executor.h index 2eeb48a3..2a2058c2 100644 --- a/include/babeltrace/graph/private-query-executor.h +++ b/include/babeltrace/graph/private-query-executor.h @@ -23,7 +23,7 @@ * SOFTWARE. */ -/* For enum bt_query_status */ +/* For enum bt_query_executor_status */ #include #ifdef __cplusplus @@ -46,14 +46,14 @@ extern struct bt_private_query_executor *bt_private_query_executor_create(void); extern -enum bt_query_status bt_private_query_executor_query( +enum bt_query_executor_status bt_private_query_executor_query( struct bt_private_query_executor *query_executor, struct bt_component_class *component_class, const char *object, struct bt_value *params, struct bt_value **result); extern -enum bt_query_status bt_private_query_executor_cancel( +enum bt_query_executor_status bt_private_query_executor_cancel( struct bt_private_query_executor *query_executor); #ifdef __cplusplus diff --git a/include/babeltrace/graph/query-executor-internal.h b/include/babeltrace/graph/query-executor-internal.h index 9bf247ef..23bc2f40 100644 --- a/include/babeltrace/graph/query-executor-internal.h +++ b/include/babeltrace/graph/query-executor-internal.h @@ -25,6 +25,8 @@ #include #include +#include +#include struct bt_query_executor { struct bt_object base; @@ -38,10 +40,6 @@ static inline const char *bt_query_status_string(enum bt_query_status status) return "BT_QUERY_STATUS_OK"; case BT_QUERY_STATUS_AGAIN: return "BT_QUERY_STATUS_AGAIN"; - case BT_QUERY_STATUS_EXECUTOR_CANCELED: - return "BT_QUERY_STATUS_EXECUTOR_CANCELED"; - case BT_QUERY_STATUS_UNSUPPORTED: - return "BT_QUERY_STATUS_UNSUPPORTED"; case BT_QUERY_STATUS_ERROR: return "BT_QUERY_STATUS_ERROR"; case BT_QUERY_STATUS_INVALID_OBJECT: @@ -55,4 +53,29 @@ static inline const char *bt_query_status_string(enum bt_query_status status) } }; +static inline const char *bt_query_executor_status_string( + enum bt_query_executor_status status) +{ + switch (status) { + case BT_QUERY_EXECUTOR_STATUS_OK: + return "BT_QUERY_EXECUTOR_STATUS_OK"; + case BT_QUERY_EXECUTOR_STATUS_AGAIN: + return "BT_QUERY_EXECUTOR_STATUS_AGAIN"; + case BT_QUERY_EXECUTOR_STATUS_CANCELED: + return "BT_QUERY_EXECUTOR_STATUS_CANCELED"; + case BT_QUERY_EXECUTOR_STATUS_UNSUPPORTED: + return "BT_QUERY_EXECUTOR_STATUS_UNSUPPORTED"; + case BT_QUERY_EXECUTOR_STATUS_ERROR: + return "BT_QUERY_EXECUTOR_STATUS_ERROR"; + case BT_QUERY_EXECUTOR_STATUS_INVALID_OBJECT: + return "BT_QUERY_EXECUTOR_STATUS_INVALID_OBJECT"; + case BT_QUERY_EXECUTOR_STATUS_INVALID_PARAMS: + return "BT_QUERY_EXECUTOR_STATUS_INVALID_PARAMS"; + case BT_QUERY_EXECUTOR_STATUS_NOMEM: + return "BT_QUERY_EXECUTOR_STATUS_NOMEM"; + default: + return "(unknown)"; + } +}; + #endif /* BABELTRACE_GRAPH_QUERY_EXECUTOR_INTERNAL_H */ diff --git a/include/babeltrace/graph/query-executor.h b/include/babeltrace/graph/query-executor.h index 3b81ec65..abdb16ce 100644 --- a/include/babeltrace/graph/query-executor.h +++ b/include/babeltrace/graph/query-executor.h @@ -32,15 +32,15 @@ extern "C" { struct bt_query_executor; -enum bt_query_status { - BT_QUERY_STATUS_OK = 0, - BT_QUERY_STATUS_AGAIN = 11, - BT_QUERY_STATUS_UNSUPPORTED = 95, - BT_QUERY_STATUS_EXECUTOR_CANCELED = 125, - BT_QUERY_STATUS_ERROR = -1, - BT_QUERY_STATUS_NOMEM = -12, - BT_QUERY_STATUS_INVALID_OBJECT = -23, - BT_QUERY_STATUS_INVALID_PARAMS = -24, +enum bt_query_executor_status { + BT_QUERY_EXECUTOR_STATUS_OK = 0, + BT_QUERY_EXECUTOR_STATUS_AGAIN = 11, + BT_QUERY_EXECUTOR_STATUS_UNSUPPORTED = 95, + BT_QUERY_EXECUTOR_STATUS_CANCELED = 125, + BT_QUERY_EXECUTOR_STATUS_ERROR = -1, + BT_QUERY_EXECUTOR_STATUS_NOMEM = -12, + BT_QUERY_EXECUTOR_STATUS_INVALID_OBJECT = -23, + BT_QUERY_EXECUTOR_STATUS_INVALID_PARAMS = -24, }; extern diff --git a/lib/graph/query-executor.c b/lib/graph/query-executor.c index 2029de84..ab295711 100644 --- a/lib/graph/query-executor.c +++ b/lib/graph/query-executor.c @@ -64,7 +64,7 @@ end: return (void *) query_exec; } -enum bt_query_status bt_private_query_executor_query( +enum bt_query_executor_status bt_private_query_executor_query( struct bt_private_query_executor *priv_query_exec, struct bt_component_class *comp_cls, const char *object, struct bt_value *params, @@ -75,6 +75,7 @@ enum bt_query_status bt_private_query_executor_query( struct bt_query_executor *query_exec = (void *) priv_query_exec; enum bt_query_status status; + enum bt_query_executor_status exec_status; method_t method = NULL; BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor"); @@ -117,7 +118,7 @@ enum bt_query_status bt_private_query_executor_query( /* Not an error: nothing to query */ BT_LIB_LOGD("Component class has no registered query method: " "%!+C", comp_cls); - status = BT_QUERY_STATUS_UNSUPPORTED; + exec_status = BT_QUERY_EXECUTOR_STATUS_UNSUPPORTED; goto end; } @@ -128,23 +129,20 @@ enum bt_query_status bt_private_query_executor_query( status = method(comp_cls, query_exec, object, params, user_result); BT_LIB_LOGD("User method returned: status=%s, %![res-]+v", bt_query_status_string(status), *user_result); - BT_ASSERT_PRE(status != BT_QUERY_STATUS_EXECUTOR_CANCELED && - status != BT_QUERY_STATUS_UNSUPPORTED, - "Unexpected (illegal) returned status: status=%s", - bt_query_status_string(status)); BT_ASSERT_PRE(status != BT_QUERY_STATUS_OK || *user_result, "User method returned `BT_QUERY_STATUS_OK` without a result."); + exec_status = (int) status; if (query_exec->canceled) { BT_OBJECT_PUT_REF_AND_RESET(*user_result); - status = BT_QUERY_STATUS_EXECUTOR_CANCELED; + status = BT_QUERY_EXECUTOR_STATUS_CANCELED; goto end; } end: - return status; + return exec_status; } -enum bt_query_status bt_private_query_executor_cancel( +enum bt_query_executor_status bt_private_query_executor_cancel( struct bt_private_query_executor *priv_query_exec) { struct bt_query_executor *query_exec = (void *) priv_query_exec; @@ -152,7 +150,7 @@ enum bt_query_status bt_private_query_executor_cancel( BT_ASSERT_PRE_NON_NULL(query_exec, "Query executor"); query_exec->canceled = BT_TRUE; BT_LOGV("Canceled query executor: addr=%p", query_exec); - return BT_QUERY_STATUS_OK; + return BT_QUERY_EXECUTOR_STATUS_OK; } bt_bool bt_query_executor_is_canceled(struct bt_query_executor *query_exec)