代码拉取完成,页面将自动刷新
From 869102d02e8779c648e53e70809855acb606b475 Mon Sep 17 00:00:00 2001
From: Robert Altnoeder <robert.altnoeder@linbit.com>
Date: Tue, 13 Feb 2024 14:26:04 +0100
Subject: [PATCH 050/100] DRBDmon: Add commands /select, /deselect,
/deselect-all (alias for /clear-selection)
---
user/drbdmon/terminal/GlobalCommandConsts.cpp | 5 +-
user/drbdmon/terminal/GlobalCommandConsts.h | 3 +
user/drbdmon/terminal/GlobalCommandsImpl.cpp | 12 ++-
user/drbdmon/terminal/GlobalCommandsImpl.h | 7 +-
user/drbdmon/terminal/MDspConnections.cpp | 94 ++++++++++++++++++-
user/drbdmon/terminal/MDspConnections.h | 2 +
user/drbdmon/terminal/MDspPeerVolumes.cpp | 64 +++++++++++++
user/drbdmon/terminal/MDspResources.cpp | 65 ++++++++++++-
user/drbdmon/terminal/MDspResources.h | 2 +
user/drbdmon/terminal/MDspTaskQueue.cpp | 2 +-
user/drbdmon/terminal/MDspVolumes.cpp | 29 +++++-
11 files changed, 275 insertions(+), 10 deletions(-)
diff --git a/user/drbdmon/terminal/GlobalCommandConsts.cpp b/user/drbdmon/terminal/GlobalCommandConsts.cpp
index 521e92ef..8c692878 100644
--- a/user/drbdmon/terminal/GlobalCommandConsts.cpp
+++ b/user/drbdmon/terminal/GlobalCommandConsts.cpp
@@ -7,8 +7,11 @@ namespace cmd_names
const std::string KEY_CMD_DISPLAY("DISPLAY");
const std::string KEY_CMD_COLORS("COLORS");
const std::string KEY_CMD_CHARSET("CHARSET");
+ const std::string KEY_CMD_SELECT("SELECT");
const std::string KEY_CMD_SELECT_ALL("SELECT-ALL");
- const std::string KEY_CMD_DESELECT("CLEAR-SELECTION");
+ const std::string KEY_CMD_DESELECT("DESELECT");
+ const std::string KEY_CMD_DESELECT_ALL("DESELECT-ALL");
+ const std::string KEY_CMD_CLEAR_SELECTION("CLEAR-SELECTION");
const std::string KEY_CMD_CURSOR("CURSOR");
const std::string KEY_CMD_RESOURCE("RESOURCE");
const std::string KEY_CMD_CONNECTION("CONNECTION");
diff --git a/user/drbdmon/terminal/GlobalCommandConsts.h b/user/drbdmon/terminal/GlobalCommandConsts.h
index e02bd41a..a55974a7 100644
--- a/user/drbdmon/terminal/GlobalCommandConsts.h
+++ b/user/drbdmon/terminal/GlobalCommandConsts.h
@@ -10,8 +10,11 @@ namespace cmd_names
extern const std::string KEY_CMD_DISPLAY;
extern const std::string KEY_CMD_COLORS;
extern const std::string KEY_CMD_CHARSET;
+ extern const std::string KEY_CMD_SELECT;
extern const std::string KEY_CMD_SELECT_ALL;
extern const std::string KEY_CMD_DESELECT;
+ extern const std::string KEY_CMD_DESELECT_ALL;
+ extern const std::string KEY_CMD_CLEAR_SELECTION;
extern const std::string KEY_CMD_CURSOR;
extern const std::string KEY_CMD_RESOURCE;
extern const std::string KEY_CMD_CONNECTION;
diff --git a/user/drbdmon/terminal/GlobalCommandsImpl.cpp b/user/drbdmon/terminal/GlobalCommandsImpl.cpp
index 16eb71d6..26e45ece 100644
--- a/user/drbdmon/terminal/GlobalCommandsImpl.cpp
+++ b/user/drbdmon/terminal/GlobalCommandsImpl.cpp
@@ -17,8 +17,11 @@ GlobalCommandsImpl::GlobalCommandsImpl(ComponentsHub& comp_hub, Configuration& c
entry_display(&cmd_names::KEY_CMD_DISPLAY, &GlobalCommandsImpl::cmd_display),
entry_colors(&cmd_names::KEY_CMD_COLORS, &GlobalCommandsImpl::cmd_colors),
entry_charset(&cmd_names::KEY_CMD_CHARSET, &GlobalCommandsImpl::cmd_charset),
+ entry_select(&cmd_names::KEY_CMD_SELECT, &GlobalCommandsImpl::local_command),
+ entry_deselect(&cmd_names::KEY_CMD_DESELECT, &GlobalCommandsImpl::local_command),
entry_select_all(&cmd_names::KEY_CMD_SELECT_ALL, &GlobalCommandsImpl::cmd_select_all),
- entry_deselect(&cmd_names::KEY_CMD_DESELECT, &GlobalCommandsImpl::cmd_deselect),
+ entry_deselect_all(&cmd_names::KEY_CMD_DESELECT_ALL, &GlobalCommandsImpl::cmd_deselect_all),
+ entry_clear_selection(&cmd_names::KEY_CMD_CLEAR_SELECTION, &GlobalCommandsImpl::cmd_deselect_all),
entry_cursor(&cmd_names::KEY_CMD_CURSOR, &GlobalCommandsImpl::local_command),
entry_resource(&cmd_names::KEY_CMD_RESOURCE, &GlobalCommandsImpl::cmd_resource),
entry_connection(&cmd_names::KEY_CMD_CONNECTION, &GlobalCommandsImpl::cmd_connection),
@@ -28,8 +31,11 @@ GlobalCommandsImpl::GlobalCommandsImpl(ComponentsHub& comp_hub, Configuration& c
add_command(entry_display);
add_command(entry_colors);
add_command(entry_charset);
- add_command(entry_select_all);
+ add_command(entry_select);
add_command(entry_deselect);
+ add_command(entry_select_all);
+ add_command(entry_deselect_all);
+ add_command(entry_clear_selection);
add_command(entry_cursor);
add_command(entry_resource);
add_command(entry_connection);
@@ -181,7 +187,7 @@ bool GlobalCommandsImpl::cmd_select_all(const std::string& command, StringTokeni
return accepted;
}
-bool GlobalCommandsImpl::cmd_deselect(const std::string& command, StringTokenizer& tokenizer)
+bool GlobalCommandsImpl::cmd_deselect_all(const std::string& command, StringTokenizer& tokenizer)
{
bool accepted = false;
DisplayId::display_page active_page = dsp_comp_hub.dsp_selector->get_active_page();
diff --git a/user/drbdmon/terminal/GlobalCommandsImpl.h b/user/drbdmon/terminal/GlobalCommandsImpl.h
index ac871be0..aa72863c 100644
--- a/user/drbdmon/terminal/GlobalCommandsImpl.h
+++ b/user/drbdmon/terminal/GlobalCommandsImpl.h
@@ -27,8 +27,11 @@ class GlobalCommandsImpl : public GlobalCommands, public CommandsBase<GlobalComm
Entry entry_display;
Entry entry_colors;
Entry entry_charset;
- Entry entry_select_all;
+ Entry entry_select;
Entry entry_deselect;
+ Entry entry_select_all;
+ Entry entry_deselect_all;
+ Entry entry_clear_selection;
Entry entry_cursor;
Entry entry_resource;
Entry entry_connection;
@@ -39,7 +42,7 @@ class GlobalCommandsImpl : public GlobalCommands, public CommandsBase<GlobalComm
bool cmd_colors(const std::string& command, StringTokenizer& tokenizer);
bool cmd_charset(const std::string& command, StringTokenizer& tokenizer);
bool cmd_select_all(const std::string& command, StringTokenizer& tokenizer);
- bool cmd_deselect(const std::string& command, StringTokenizer& tokenizer);
+ bool cmd_deselect_all(const std::string& command, StringTokenizer& tokenizer);
bool cmd_resource(const std::string& command, StringTokenizer& tokenizer);
bool cmd_connection(const std::string& command, StringTokenizer& tokenizer);
bool cmd_volume(const std::string& command, StringTokenizer& tokenizer);
diff --git a/user/drbdmon/terminal/MDspConnections.cpp b/user/drbdmon/terminal/MDspConnections.cpp
index b340b1cb..5b6f39cb 100644
--- a/user/drbdmon/terminal/MDspConnections.cpp
+++ b/user/drbdmon/terminal/MDspConnections.cpp
@@ -448,6 +448,64 @@ void MDspConnections::display_at_page()
}
}
+// @throws std::bad_alloc, string_matching::PatternLimitException
+bool MDspConnections::change_selection(const std::string& pattern_text, const bool select_flag)
+{
+ DrbdResource* const rsc = dsp_comp_hub.get_monitor_resource();
+ bool matched = false;
+ if (rsc != nullptr)
+ {
+ std::unique_ptr<string_matching::PatternItem> pattern;
+ string_matching::process_pattern(pattern_text, pattern);
+
+ DrbdResource::ConnectionsIterator con_iter = rsc->connections_iterator();
+ if (is_problem_mode(rsc))
+ {
+ while (con_iter.has_next())
+ {
+ DrbdConnection* const con = con_iter.next();
+ if (problem_filter(con))
+ {
+ const std::string& con_name = con->get_name();
+ if (string_matching::match_text(con_name, pattern.get()))
+ {
+ matched = true;
+ if (select_flag)
+ {
+ dsp_comp_hub.dsp_shared->select_connection(con_name);
+ }
+ else
+ {
+ dsp_comp_hub.dsp_shared->deselect_connection(con_name);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ while (con_iter.has_next())
+ {
+ DrbdConnection* const con = con_iter.next();
+ const std::string& con_name = con->get_name();
+ if (string_matching::match_text(con_name, pattern.get()))
+ {
+ matched = true;
+ if (select_flag)
+ {
+ dsp_comp_hub.dsp_shared->select_connection(con_name);
+ }
+ else
+ {
+ dsp_comp_hub.dsp_shared->deselect_connection(con_name);
+ }
+ }
+ }
+ }
+ }
+ return matched;
+}
+
void MDspConnections::clear_selection()
{
dsp_comp_hub.dsp_shared->clear_connections_selection();
@@ -679,6 +737,40 @@ bool MDspConnections::execute_command(const std::string& command, StringTokenize
}
}
else
+ if (command == cmd_names::KEY_CMD_SELECT || command == cmd_names::KEY_CMD_DESELECT)
+ {
+ if (tokenizer.has_next())
+ {
+ std::string cmd_arg = tokenizer.next();
+ if (string_matching::is_pattern(cmd_arg))
+ {
+ try
+ {
+ accepted = change_selection(cmd_arg, command == cmd_names::KEY_CMD_SELECT);
+ }
+ catch (string_matching::PatternLimitException&)
+ {
+ std::string error_msg(command);
+ error_msg += " command rejected: Excessive number of wildcard characters";
+ dsp_comp_hub.log->add_entry(MessageLog::log_level::ALERT, error_msg);
+ }
+ }
+ else
+ {
+ if (command == cmd_names::KEY_CMD_SELECT)
+ {
+ dsp_comp_hub.dsp_shared->select_connection(cmd_arg);
+ }
+ else
+ {
+ dsp_comp_hub.dsp_shared->deselect_connection(cmd_arg);
+ }
+ accepted = true;
+ }
+ }
+ return accepted;
+ }
+ else
if (command == cmd_names::KEY_CMD_SELECT_ALL)
{
DrbdResource* const rsc = dsp_comp_hub.get_monitor_resource();
@@ -699,7 +791,7 @@ bool MDspConnections::execute_command(const std::string& command, StringTokenize
accepted = true;
}
else
- if (command == cmd_names::KEY_CMD_DESELECT)
+ if (command == cmd_names::KEY_CMD_DESELECT_ALL || command == cmd_names::KEY_CMD_CLEAR_SELECTION)
{
clear_selection();
accepted = true;
diff --git a/user/drbdmon/terminal/MDspConnections.h b/user/drbdmon/terminal/MDspConnections.h
index 2a203b97..0e48d92b 100644
--- a/user/drbdmon/terminal/MDspConnections.h
+++ b/user/drbdmon/terminal/MDspConnections.h
@@ -27,6 +27,8 @@ class MDspConnections : public MDspStdListBase
virtual bool mouse_action(MouseEvent& mouse) override;
virtual bool execute_command(const std::string& command, StringTokenizer& tokenizer);
+ // @throws std::bad_alloc, string_matching::PatternLimitException
+ virtual bool change_selection(const std::string& pattern_text, const bool select_flag);
virtual void clear_selection() override;
virtual void cursor_to_next_item() override;
diff --git a/user/drbdmon/terminal/MDspPeerVolumes.cpp b/user/drbdmon/terminal/MDspPeerVolumes.cpp
index e0d95a8c..b2e62e0d 100644
--- a/user/drbdmon/terminal/MDspPeerVolumes.cpp
+++ b/user/drbdmon/terminal/MDspPeerVolumes.cpp
@@ -136,6 +136,70 @@ bool MDspPeerVolumes::execute_command(const std::string& command, StringTokenize
}
}
}
+ else
+ if (command == cmd_names::KEY_CMD_SELECT || command == cmd_names::KEY_CMD_DESELECT)
+ {
+ if (tokenizer.has_next())
+ {
+ const std::string obj_id = tokenizer.next();
+ try
+ {
+ const uint16_t vlm_id = dsaext::parse_unsigned_int16(obj_id);
+ if (command == cmd_names::KEY_CMD_SELECT)
+ {
+ select_volume(vlm_id);
+ }
+ else
+ {
+ deselect_volume(vlm_id);
+ }
+ accepted = true;
+ }
+ catch (dsaext::NumberFormatException&)
+ {
+ // ignored, command rejected
+ }
+ }
+ return accepted;
+ }
+ else
+ if (command == cmd_names::KEY_CMD_SELECT_ALL)
+ {
+ DrbdResource* const rsc = dsp_comp_hub.get_monitor_resource();
+ DrbdConnection* const con = dsp_comp_hub.get_monitor_connection();
+ if (rsc != nullptr && con != nullptr)
+ {
+ DrbdConnection::VolumesIterator vlm_iter(*con);
+ if (is_problem_mode(rsc, con))
+ {
+ while (vlm_iter.has_next())
+ {
+ DrbdVolume* const peer_vlm = vlm_iter.next();
+ if (problem_filter(peer_vlm))
+ {
+ const uint16_t vlm_nr = peer_vlm->get_volume_nr();
+ select_volume(vlm_nr);
+ }
+ }
+ }
+ else
+ {
+ while (vlm_iter.has_next())
+ {
+ DrbdVolume* const peer_vlm = vlm_iter.next();
+ const uint16_t vlm_nr = peer_vlm->get_volume_nr();
+ select_volume(vlm_nr);
+ }
+ }
+ }
+ accepted = true;
+ }
+ else
+ if (command == cmd_names::KEY_CMD_DESELECT_ALL || command == cmd_names::KEY_CMD_CLEAR_SELECTION)
+ {
+ clear_selection();
+ accepted = true;
+ }
if (accepted)
{
dsp_comp_hub.dsp_selector->refresh_display();
diff --git a/user/drbdmon/terminal/MDspResources.cpp b/user/drbdmon/terminal/MDspResources.cpp
index af8d4609..3a66e264 100644
--- a/user/drbdmon/terminal/MDspResources.cpp
+++ b/user/drbdmon/terminal/MDspResources.cpp
@@ -631,6 +631,40 @@ bool MDspResources::execute_command(const std::string& command, StringTokenizer&
}
}
else
+ if (command == cmd_names::KEY_CMD_SELECT || command == cmd_names::KEY_CMD_DESELECT)
+ {
+ if (tokenizer.has_next())
+ {
+ std::string cmd_arg = tokenizer.next();
+ if (string_matching::is_pattern(cmd_arg))
+ {
+ try
+ {
+ accepted = change_selection(cmd_arg, command == cmd_names::KEY_CMD_SELECT);
+ }
+ catch (string_matching::PatternLimitException&)
+ {
+ std::string error_msg(command);
+ error_msg += " command rejected: Excessive number of wildcard characters";
+ dsp_comp_hub.log->add_entry(MessageLog::log_level::ALERT, error_msg);
+ }
+ }
+ else
+ {
+ if (command == cmd_names::KEY_CMD_SELECT)
+ {
+ dsp_comp_hub.dsp_shared->select_resource(cmd_arg);
+ }
+ else
+ {
+ dsp_comp_hub.dsp_shared->deselect_resource(cmd_arg);
+ }
+ accepted = true;
+ }
+ }
+ return accepted;
+ }
+ else
if (command == cmd_names::KEY_CMD_SELECT_ALL)
{
ResourcesMap& selected_map = select_resources_map();
@@ -643,7 +677,7 @@ bool MDspResources::execute_command(const std::string& command, StringTokenizer&
accepted = true;
}
else
- if (command == cmd_names::KEY_CMD_DESELECT)
+ if (command == cmd_names::KEY_CMD_DESELECT_ALL || command == cmd_names::KEY_CMD_CLEAR_SELECTION)
{
clear_selection();
@@ -722,6 +756,35 @@ void MDspResources::toggle_select_cursor_item()
}
}
+// @throws std::bad_alloc, string_matching::PatternLimitException
+bool MDspResources::change_selection(const std::string& pattern_text, const bool select_flag)
+{
+ ResourcesMap& selected_map = select_resources_map();
+ std::unique_ptr<string_matching::PatternItem> pattern;
+ string_matching::process_pattern(pattern_text, pattern);
+
+ bool matched = false;
+ ResourcesMap::KeysIterator rsc_iter(selected_map);
+ while (rsc_iter.has_next())
+ {
+ const std::string* const rsc_name_ptr = rsc_iter.next();
+ const std::string& rsc_name = *rsc_name_ptr;
+ if (string_matching::match_text(rsc_name, pattern.get()))
+ {
+ matched = true;
+ if (select_flag)
+ {
+ dsp_comp_hub.dsp_shared->select_resource(rsc_name);
+ }
+ else
+ {
+ dsp_comp_hub.dsp_shared->deselect_resource(rsc_name);
+ }
+ }
+ }
+ return matched;
+}
+
// Public entry point to private/non-virtual clear_selection_impl, which is also used by the destructor
void MDspResources::clear_selection()
{
diff --git a/user/drbdmon/terminal/MDspResources.h b/user/drbdmon/terminal/MDspResources.h
index 1520cfbe..df99722c 100644
--- a/user/drbdmon/terminal/MDspResources.h
+++ b/user/drbdmon/terminal/MDspResources.h
@@ -26,6 +26,8 @@ class MDspResources : public MDspStdListBase
virtual bool execute_command(const std::string& command, StringTokenizer& tokenizer);
virtual void clear_selection() override;
+ // @throws std::bad_alloc, string_matching::PatternLimitException
+ virtual bool change_selection(const std::string& pattern_text, const bool select_flag);
virtual void cursor_to_next_item() override;
virtual void cursor_to_previous_item() override;
diff --git a/user/drbdmon/terminal/MDspTaskQueue.cpp b/user/drbdmon/terminal/MDspTaskQueue.cpp
index 2e5fd0c1..d45f36aa 100644
--- a/user/drbdmon/terminal/MDspTaskQueue.cpp
+++ b/user/drbdmon/terminal/MDspTaskQueue.cpp
@@ -339,7 +339,7 @@ bool MDspTaskQueue::execute_command(const std::string& command, StringTokenizer&
accepted = true;
}
else
- if (command == cmd_names::KEY_CMD_DESELECT)
+ if (command == cmd_names::KEY_CMD_DESELECT_ALL || command == cmd_names::KEY_CMD_CLEAR_SELECTION)
{
dsp_comp_hub.dsp_shared->clear_task_selection(selection_map);
dsp_comp_hub.dsp_selector->refresh_display();
diff --git a/user/drbdmon/terminal/MDspVolumes.cpp b/user/drbdmon/terminal/MDspVolumes.cpp
index af769cbe..ce5e09b1 100644
--- a/user/drbdmon/terminal/MDspVolumes.cpp
+++ b/user/drbdmon/terminal/MDspVolumes.cpp
@@ -365,10 +365,37 @@ bool MDspVolumes::execute_command(const std::string& command, StringTokenizer& t
}
catch (dsaext::NumberFormatException&)
{
+ // ignored, command rejected
}
}
}
else
+ if (command == cmd_names::KEY_CMD_SELECT || command == cmd_names::KEY_CMD_DESELECT)
+ {
+ if (tokenizer.has_next())
+ {
+ const std::string obj_id = tokenizer.next();
+ try
+ {
+ const uint16_t vlm_id = dsaext::parse_unsigned_int16(obj_id);
+ if (command == cmd_names::KEY_CMD_SELECT)
+ {
+ dsp_comp_hub.dsp_shared->select_volume(vlm_id);
+ }
+ else
+ {
+ dsp_comp_hub.dsp_shared->deselect_volume(vlm_id);
+ }
+ accepted = true;
+ }
+ catch (dsaext::NumberFormatException&)
+ {
+ // ignored, command rejected
+ }
+ }
+ return accepted;
+ }
+ else
if (command == cmd_names::KEY_CMD_SELECT_ALL)
{
DrbdResource* const rsc = dsp_comp_hub.get_monitor_resource();
@@ -389,7 +416,7 @@ bool MDspVolumes::execute_command(const std::string& command, StringTokenizer& t
accepted = true;
}
else
- if (command == cmd_names::KEY_CMD_DESELECT)
+ if (command == cmd_names::KEY_CMD_DESELECT_ALL || command == cmd_names::KEY_CMD_CLEAR_SELECTION)
{
clear_selection();
accepted = true;
--
2.33.1.windows.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。