src.ctf.lttng-live: use C++ value wrappers for query parameters
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 12 Dec 2023 16:28:06 +0000 (16:28 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -0400)
Change-Id: Ie64cef32650dbc62238429b10c30a0c8ffd5dac3
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8476
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12391
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/lttng-live/lttng-live.cpp

index 26beceda15fb5595eae19734112caeca21ccec81..9f62305ef2babfc543dad924fb8cba58796462b2 100644 (file)
@@ -1684,18 +1684,18 @@ static struct bt_param_validation_map_value_entry_descr list_sessions_params[] =
     BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END};
 
 static bt_component_class_query_method_status
-lttng_live_query_list_sessions(const bt_value *params, const bt_value **result,
+lttng_live_query_list_sessions(const bt2::ConstMapValue params, const bt_value **result,
                                const bt2c::Logger& logger)
 {
     bt_component_class_query_method_status status;
-    const bt_value *url_value = NULL;
     const char *url;
     live_viewer_connection::UP viewer_connection;
     enum lttng_live_viewer_status viewer_status;
     enum bt_param_validation_status validation_status;
     gchar *validate_error = NULL;
 
-    validation_status = bt_param_validation_validate(params, list_sessions_params, &validate_error);
+    validation_status =
+        bt_param_validation_validate(params.libObjPtr(), list_sessions_params, &validate_error);
     if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) {
         status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_MEMORY_ERROR;
         goto error;
@@ -1705,8 +1705,7 @@ lttng_live_query_list_sessions(const bt_value *params, const bt_value **result,
         goto error;
     }
 
-    url_value = bt_value_map_borrow_entry_value_const(params, URL_PARAM);
-    url = bt_value_string_get(url_value);
+    url = params[URL_PARAM]->asString().value();
 
     viewer_status = live_viewer_connection_create(url, true, NULL, logger, viewer_connection);
     if (viewer_status != LTTNG_LIVE_VIEWER_STATUS_OK) {
@@ -1743,12 +1742,11 @@ end:
 }
 
 static bt_component_class_query_method_status
-lttng_live_query_support_info(const bt_value *params, const bt_value **result,
+lttng_live_query_support_info(const bt2::ConstMapValue params, const bt_value **result,
                               const bt2c::Logger& logger)
 {
     bt_component_class_query_method_status status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_OK;
-    const bt_value *input_type_value;
-    const bt_value *input_value;
+    bt2::OptionalBorrowedObject<bt2::ConstValue> inputValue;
     double weight = 0;
     struct bt_common_lttng_live_url_parts parts = {};
     bt_common_lttng_live_url_parts_deleter partsDeleter {parts};
@@ -1757,34 +1755,34 @@ lttng_live_query_support_info(const bt_value *params, const bt_value **result,
     __attribute__((unused)) bt_self_component *self_comp = NULL;
 
     *result = NULL;
-    input_type_value = bt_value_map_borrow_entry_value_const(params, "type");
-    if (!input_type_value) {
+    const auto typeValue = params["type"];
+    if (!typeValue) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Missing expected `type` parameter.");
         goto error;
     }
 
-    if (!bt_value_is_string(input_type_value)) {
+    if (!typeValue->isString()) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "`type` parameter is not a string value.");
         goto error;
     }
 
-    if (strcmp(bt_value_string_get(input_type_value), "string") != 0) {
+    if (strcmp(typeValue->asString().value(), "string") != 0) {
         /* We don't handle file system paths */
         goto create_result;
     }
 
-    input_value = bt_value_map_borrow_entry_value_const(params, "input");
-    if (!input_value) {
+    inputValue = params["input"];
+    if (!inputValue) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Missing expected `input` parameter.");
         goto error;
     }
 
-    if (!bt_value_is_string(input_value)) {
+    if (!inputValue->isString()) {
         BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "`input` parameter is not a string value.");
         goto error;
     }
 
-    parts = bt_common_parse_lttng_live_url(bt_value_string_get(input_value), NULL, 0);
+    parts = bt_common_parse_lttng_live_url(inputValue->asString().value(), NULL, 0);
     if (parts.session_name) {
         /*
          * Looks pretty much like an LTTng live URL: we got the
@@ -1824,11 +1822,12 @@ bt_component_class_query_method_status lttng_live_query(bt_self_component_class_
         bt2c::Logger logger {bt2::SelfComponentClass {comp_class},
                              bt2::PrivateQueryExecutor {priv_query_exec},
                              "PLUGIN/SRC.CTF.LTTNG-LIVE/QUERY"};
+        const bt2::ConstMapValue paramsObj(params);
 
         if (strcmp(object, "sessions") == 0) {
-            status = lttng_live_query_list_sessions(params, result, logger);
+            status = lttng_live_query_list_sessions(paramsObj, result, logger);
         } else if (strcmp(object, "babeltrace.support-info") == 0) {
-            status = lttng_live_query_support_info(params, result, logger);
+            status = lttng_live_query_support_info(paramsObj, result, logger);
         } else {
             BT_CPPLOGI_SPEC(logger, "Unknown query object `{}`", object);
             status = BT_COMPONENT_CLASS_QUERY_METHOD_STATUS_UNKNOWN_OBJECT;
This page took 0.027868 seconds and 4 git commands to generate.