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) {
}
}();
- 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;
}
} 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;
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);
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;
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) {
}
}();
- 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;
}
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;
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);
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;
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) {
}
}();
- 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;
}
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;
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);
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;
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;
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;
++write_to;
if (return_first_match_only) {
- return session_list(std::move(list), 1);
+ return lttng::cli::session_list(std::move(list), 1);
}
}
}
} /* 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(
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();
}
#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>
struct cmd_struct;
+namespace lttng {
+namespace cli {
+
struct session_spec {
enum class type {
NAME,
_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);
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 */