From: Jérémie Galarneau Date: Mon, 5 Jun 2023 21:39:39 +0000 (-0400) Subject: lttng: move session_list to the lttng::cli namespace X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6e11909ebb204e4a0f9651dc6c58f74c8376a094;p=lttng-tools.git lttng: move session_list to the lttng::cli namespace 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 Change-Id: I32d0354a6985b8c6fb58813cf880ef04a10678dd --- diff --git a/src/bin/lttng/commands/destroy.cpp b/src/bin/lttng/commands/destroy.cpp index 0bffb30bd..019906a20 100644 --- a/src/bin/lttng/commands/destroy.cpp +++ b/src/bin/lttng/commands/destroy.cpp @@ -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; diff --git a/src/bin/lttng/commands/start.cpp b/src/bin/lttng/commands/start.cpp index 79c9d8973..2552062e5 100644 --- a/src/bin/lttng/commands/start.cpp +++ b/src/bin/lttng/commands/start.cpp @@ -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; diff --git a/src/bin/lttng/commands/stop.cpp b/src/bin/lttng/commands/stop.cpp index cc4296bfb..d2e0bee14 100644 --- a/src/bin/lttng/commands/stop.cpp +++ b/src/bin/lttng/commands/stop.cpp @@ -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; diff --git a/src/bin/lttng/utils.cpp b/src/bin/lttng/utils.cpp index cf9590c3e..e65c01753 100644 --- a/src/bin/lttng/utils.cpp +++ b/src/bin/lttng/utils.cpp @@ -665,9 +665,10 @@ end: namespace { template -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(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(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(); } diff --git a/src/bin/lttng/utils.hpp b/src/bin/lttng/utils.hpp index 326f0ae74..dfbbc25b2 100644 --- a/src/bin/lttng/utils.hpp +++ b/src/bin/lttng/utils.hpp @@ -9,6 +9,7 @@ #define _LTTNG_UTILS_H #include +#include #include #include @@ -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 */