lttng: move session_list to the lttng::cli namespace
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 5 Jun 2023 21:39:39 +0000 (17:39 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 5 Jun 2023 21:39:39 +0000 (17:39 -0400)
This is a preliminary step to re-use the random_access_container util to
replace the implementation of session_list. No behaviour change is
intended by this change.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I32d0354a6985b8c6fb58813cf880ef04a10678dd

src/bin/lttng/commands/destroy.cpp
src/bin/lttng/commands/start.cpp
src/bin/lttng/commands/stop.cpp
src/bin/lttng/utils.cpp
src/bin/lttng/utils.hpp

index 0bffb30bdb86ac1399516eba05c6bc74bb787e11..019906a208d1af7bc0673413f045d783bf3a2ae4 100644 (file)
@@ -255,13 +255,13 @@ cmd_error_code destroy_session(const lttng_session& session)
        return CMD_SUCCESS;
 }
 
-cmd_error_code destroy_sessions(const session_spec& spec)
+cmd_error_code destroy_sessions(const lttng::cli::session_spec& spec)
 {
        bool had_warning = false;
        bool had_error = false;
        bool listing_failed = false;
 
-       const auto sessions = [&listing_failed, &spec]() -> session_list {
+       const auto sessions = [&listing_failed, &spec]() -> lttng::cli::session_list {
                try {
                        return list_sessions(spec);
                } catch (const lttng::ctl::error& ctl_exception) {
@@ -272,7 +272,8 @@ cmd_error_code destroy_sessions(const session_spec& spec)
                }
        }();
 
-       if (!listing_failed && sessions.size() == 0 && spec.type_ == session_spec::type::NAME) {
+       if (!listing_failed && sessions.size() == 0 &&
+           spec.type_ == lttng::cli::session_spec::type::NAME) {
                ERR_FMT("Session `{}` not found", spec.value);
                return CMD_ERROR;
        }
@@ -289,7 +290,7 @@ cmd_error_code destroy_sessions(const session_spec& spec)
                } catch (const lttng::ctl::error& ctl_exception) {
                        switch (ctl_exception.code()) {
                        case LTTNG_ERR_NO_SESSION:
-                               if (spec.type_ != session_spec::type::NAME) {
+                               if (spec.type_ != lttng::cli::session_spec::type::NAME) {
                                        /* Session destroyed during command, ignore and carry-on. */
                                        sub_ret = CMD_SUCCESS;
                                        break;
@@ -335,8 +336,8 @@ int cmd_destroy(int argc, const char **argv)
        bool success;
        static poptContext pc;
        const char *leftover = nullptr;
-       struct session_spec spec(session_spec::type::NAME);
-       session_list const sessions;
+       lttng::cli::session_spec spec(lttng::cli::session_spec::type::NAME);
+       lttng::cli::session_list const sessions;
 
        pc = poptGetContext(nullptr, argc, argv, long_options, 0);
        poptReadDefaultConfig(pc, 0);
@@ -355,10 +356,10 @@ int cmd_destroy(int argc, const char **argv)
                        list_cmd_options(stdout, long_options);
                        goto end;
                case OPT_ALL:
-                       spec.type_ = session_spec::type::ALL;
+                       spec.type_ = lttng::cli::session_spec::type::ALL;
                        break;
                case OPT_ENABLE_GLOB:
-                       spec.type_ = session_spec::type::GLOB_PATTERN;
+                       spec.type_ = lttng::cli::session_spec::type::GLOB_PATTERN;
                        break;
                default:
                        command_ret = CMD_UNDEFINED;
index 79c9d89734efad73d1f753e3567bde632c11276f..2552062e5bff43e6f0f8c4d9418b50cc741fdcd9 100644 (file)
@@ -103,13 +103,13 @@ cmd_error_code start_tracing(const char *session_name)
        return CMD_SUCCESS;
 }
 
-cmd_error_code start_tracing(const session_spec& spec) noexcept
+cmd_error_code start_tracing(const lttng::cli::session_spec& spec) noexcept
 {
        bool had_warning = false;
        bool had_error = false;
        bool listing_failed = false;
 
-       const auto sessions = [&listing_failed, &spec]() -> session_list {
+       const auto sessions = [&listing_failed, &spec]() -> lttng::cli::session_list {
                try {
                        return list_sessions(spec);
                } catch (const lttng::ctl::error& ctl_exception) {
@@ -120,7 +120,8 @@ cmd_error_code start_tracing(const session_spec& spec) noexcept
                }
        }();
 
-       if (!listing_failed && sessions.size() == 0 && spec.type_ == session_spec::type::NAME) {
+       if (!listing_failed && sessions.size() == 0 &&
+           spec.type_ == lttng::cli::session_spec::type::NAME) {
                ERR_FMT("Session `{}` not found", spec.value);
                return CMD_ERROR;
        }
@@ -141,7 +142,7 @@ cmd_error_code start_tracing(const session_spec& spec) noexcept
                                sub_ret = CMD_SUCCESS;
                                break;
                        case LTTNG_ERR_NO_SESSION:
-                               if (spec.type_ != session_spec::type::NAME) {
+                               if (spec.type_ != lttng::cli::session_spec::type::NAME) {
                                        /* Session destroyed during command, ignore and carry-on. */
                                        sub_ret = CMD_SUCCESS;
                                        break;
@@ -189,7 +190,7 @@ int cmd_start(int argc, const char **argv)
        bool success = true;
        static poptContext pc;
        const char *leftover = nullptr;
-       session_spec session_spec(session_spec::type::NAME);
+       lttng::cli::session_spec session_spec(lttng::cli::session_spec::type::NAME);
 
        pc = poptGetContext(nullptr, argc, argv, long_options, 0);
        poptReadDefaultConfig(pc, 0);
@@ -208,10 +209,10 @@ int cmd_start(int argc, const char **argv)
                        list_cmd_options(stdout, long_options);
                        goto end;
                case OPT_ENABLE_GLOB:
-                       session_spec.type_ = session_spec::type::GLOB_PATTERN;
+                       session_spec.type_ = lttng::cli::session_spec::type::GLOB_PATTERN;
                        break;
                case OPT_ALL:
-                       session_spec.type_ = session_spec::type::ALL;
+                       session_spec.type_ = lttng::cli::session_spec::type::ALL;
                        break;
                default:
                        command_ret = CMD_UNDEFINED;
index cc4296bfb71f0e589182056ef2624477d263cf89..d2e0bee14e5bc2f504e5a22bcadfaac1dd09de20 100644 (file)
@@ -132,13 +132,13 @@ cmd_error_code stop_tracing(const char *session_name)
        return CMD_SUCCESS;
 }
 
-cmd_error_code stop_tracing(const session_spec& spec) noexcept
+cmd_error_code stop_tracing(const lttng::cli::session_spec& spec) noexcept
 {
        bool had_warning = false;
        bool had_error = false;
        bool listing_failed = false;
 
-       const auto sessions = [&listing_failed, &spec]() -> session_list {
+       const auto sessions = [&listing_failed, &spec]() -> lttng::cli::session_list {
                try {
                        return list_sessions(spec);
                } catch (const lttng::ctl::error& ctl_exception) {
@@ -149,7 +149,8 @@ cmd_error_code stop_tracing(const session_spec& spec) noexcept
                }
        }();
 
-       if (!listing_failed && sessions.size() == 0 && spec.type_ == session_spec::type::NAME) {
+       if (!listing_failed && sessions.size() == 0 &&
+           spec.type_ == lttng::cli::session_spec::type::NAME) {
                ERR_FMT("Session `{}` not found", spec.value);
                return CMD_ERROR;
        }
@@ -170,7 +171,7 @@ cmd_error_code stop_tracing(const session_spec& spec) noexcept
                                sub_ret = CMD_SUCCESS;
                                break;
                        case LTTNG_ERR_NO_SESSION:
-                               if (spec.type_ != session_spec::type::NAME) {
+                               if (spec.type_ != lttng::cli::session_spec::type::NAME) {
                                        /* Session destroyed during command, ignore and carry-on. */
                                        sub_ret = CMD_SUCCESS;
                                        break;
@@ -218,7 +219,7 @@ int cmd_stop(int argc, const char **argv)
        bool success = true;
        static poptContext pc;
        const char *leftover = nullptr;
-       struct session_spec session_spec(session_spec::type::NAME);
+       lttng::cli::session_spec session_spec(lttng::cli::session_spec::type::NAME);
 
        pc = poptGetContext(nullptr, argc, argv, long_options, 0);
        poptReadDefaultConfig(pc, 0);
@@ -237,10 +238,10 @@ int cmd_stop(int argc, const char **argv)
                        list_cmd_options(stdout, long_options);
                        goto end;
                case OPT_ENABLE_GLOB:
-                       session_spec.type_ = session_spec::type::GLOB_PATTERN;
+                       session_spec.type_ = lttng::cli::session_spec::type::GLOB_PATTERN;
                        break;
                case OPT_ALL:
-                       session_spec.type_ = session_spec::type::ALL;
+                       session_spec.type_ = lttng::cli::session_spec::type::ALL;
                        break;
                default:
                        command_ret = CMD_UNDEFINED;
index cf9590c3eba081c5905af0c8293fbb47f75a80fd..e65c01753e04fec18ccd78a0fac5c6a24b3a316a 100644 (file)
@@ -665,9 +665,10 @@ end:
 
 namespace {
 template <typename FilterFunctionType>
-session_list get_sessions(const FilterFunctionType& filter, bool return_first_match_only = false)
+lttng::cli::session_list get_sessions(const FilterFunctionType& filter,
+                                     bool return_first_match_only = false)
 {
-       session_list list;
+       lttng::cli::session_list list;
 
        {
                int list_ret;
@@ -680,7 +681,7 @@ session_list get_sessions(const FilterFunctionType& filter, bool return_first_ma
                                        static_cast<lttng_error_code>(list_ret));
                }
 
-               list = session_list(psessions, list_ret);
+               list = lttng::cli::session_list(psessions, list_ret);
        }
 
        std::size_t write_to = 0;
@@ -696,7 +697,7 @@ session_list get_sessions(const FilterFunctionType& filter, bool return_first_ma
                ++write_to;
 
                if (return_first_match_only) {
-                       return session_list(std::move(list), 1);
+                       return lttng::cli::session_list(std::move(list), 1);
                }
        }
 
@@ -706,22 +707,23 @@ session_list get_sessions(const FilterFunctionType& filter, bool return_first_ma
 }
 } /* namespace */
 
-session_list list_sessions(const struct session_spec& spec)
+lttng::cli::session_list lttng::cli::list_sessions(const struct session_spec& spec)
 {
        switch (spec.type_) {
-       case session_spec::type::NAME:
+       case lttng::cli::session_spec::type::NAME:
                if (spec.value == nullptr) {
                        const auto configured_name =
                                lttng::make_unique_wrapper<char, lttng::free>(get_session_name());
 
                        if (configured_name) {
-                               const struct session_spec new_spec(session_spec::type::NAME,
-                                                                  configured_name.get());
+                               const struct lttng::cli::session_spec new_spec(
+                                       lttng::cli::session_spec::type::NAME,
+                                       configured_name.get());
 
                                return list_sessions(new_spec);
                        }
 
-                       return session_list();
+                       return lttng::cli::session_list();
                }
 
                return get_sessions(
@@ -729,13 +731,13 @@ session_list list_sessions(const struct session_spec& spec)
                                return strcmp(session.name, spec.value) == 0;
                        },
                        true);
-       case session_spec::type::GLOB_PATTERN:
+       case lttng::cli::session_spec::type::GLOB_PATTERN:
                return get_sessions([&spec](const lttng_session& session) {
                        return fnmatch(spec.value, session.name, 0) == 0;
                });
-       case session_spec::type::ALL:
+       case lttng::cli::session_spec::type::ALL:
                return get_sessions([](const lttng_session&) { return true; });
        }
 
-       return session_list();
+       return lttng::cli::session_list();
 }
index 326f0ae746396312e235d105af4a8c4b8fe66011..dfbbc25b28056e71bbbeab4b7d44c6cbb46679d7 100644 (file)
@@ -9,6 +9,7 @@
 #define _LTTNG_UTILS_H
 
 #include <common/argpar/argpar.h>
+#include <common/container-wrapper.hpp>
 #include <common/dynamic-array.hpp>
 #include <common/make-unique-wrapper.hpp>
 
@@ -25,6 +26,9 @@ extern pid_t sessiond_pid;
 
 struct cmd_struct;
 
+namespace lttng {
+namespace cli {
+
 struct session_spec {
        enum class type {
                NAME,
@@ -166,6 +170,10 @@ private:
                _sessions;
 };
 
+lttng::cli::session_list list_sessions(const struct session_spec& spec);
+} /* namespace cli */
+} /* namespace lttng */
+
 char *get_session_name(void);
 char *get_session_name_quiet(void);
 void list_commands(struct cmd_struct *commands, FILE *ofp);
@@ -206,6 +214,4 @@ int print_trace_archive_location(const struct lttng_trace_archive_location *loca
 int validate_exclusion_list(const char *event_name,
                            const struct lttng_dynamic_pointer_array *exclusions);
 
-session_list list_sessions(const struct session_spec& spec);
-
 #endif /* _LTTNG_UTILS_H */
This page took 0.032408 seconds and 4 git commands to generate.