代码拉取完成,页面将自动刷新
From 61a52d98fecae92ec9dd3ef86a22a4265fb07e0b Mon Sep 17 00:00:00 2001
From: Robert Altnoeder <robert.altnoeder@linbit.com>
Date: Thu, 15 Feb 2024 15:19:15 +0100
Subject: [PATCH 058/100] DRBDmon: Add MDspPeerVolumeDetail
---
.../drbdmon/terminal/MDspPeerVolumeDetail.cpp | 294 ++++++++++++++++++
user/drbdmon/terminal/MDspPeerVolumeDetail.h | 35 +++
user/drbdmon/terminal/MDspPeerVolumes.cpp | 12 +-
user/drbdmon/terminal/MDspPeerVolumes.h | 3 +-
4 files changed, 337 insertions(+), 7 deletions(-)
create mode 100644 user/drbdmon/terminal/MDspPeerVolumeDetail.cpp
create mode 100644 user/drbdmon/terminal/MDspPeerVolumeDetail.h
diff --git a/user/drbdmon/terminal/MDspPeerVolumeDetail.cpp b/user/drbdmon/terminal/MDspPeerVolumeDetail.cpp
new file mode 100644
index 00000000..8739ae33
--- /dev/null
+++ b/user/drbdmon/terminal/MDspPeerVolumeDetail.cpp
@@ -0,0 +1,294 @@
+#include <terminal/MDspPeerVolumeDetail.h>
+#include <terminal/DisplayUpdateEvent.h>
+#include <terminal/DisplayConsts.h>
+#include <terminal/KeyCodes.h>
+#include <terminal/HelpText.h>
+#include <objects/DrbdResource.h>
+#include <string>
+
+MDspPeerVolumeDetail::MDspPeerVolumeDetail(const ComponentsHub& comp_hub):
+ MDspMenuBase::MDspMenuBase(comp_hub)
+{
+ cmd_fn_actions =
+ [this]() -> void
+ {
+ opt_actions();
+ };
+ cmd_actions = std::unique_ptr<ClickableCommand>(
+ new ClickableCommand("A", 1, 15, 1, 20, cmd_fn_actions)
+ );
+}
+
+MDspPeerVolumeDetail::~MDspPeerVolumeDetail() noexcept
+{
+}
+
+void MDspPeerVolumeDetail::display_content()
+{
+ dsp_comp_hub.dsp_common->display_page_id(DisplayId::MDSP_PEER_VLM_DETAIL);
+
+ dsp_comp_hub.dsp_io->cursor_xy(1, DisplayConsts::PAGE_NAV_Y + 1);
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->emphasis_text.c_str());
+ dsp_comp_hub.dsp_io->write_text("Peer volume details");
+
+ uint32_t current_line = DisplayConsts::PAGE_NAV_Y + 3;
+ dsp_comp_hub.dsp_io->cursor_xy(1, current_line);
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->emphasis_text.c_str());
+ dsp_comp_hub.dsp_io->write_text("Resource:");
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->rst.c_str());
+ dsp_comp_hub.dsp_io->cursor_xy(21, current_line);
+ if (!dsp_comp_hub.dsp_shared->monitor_rsc.empty())
+ {
+ DrbdResource* const rsc = dsp_comp_hub.get_monitor_resource();
+ const std::string& rsc_name = (rsc != nullptr ? rsc->get_name() : dsp_comp_hub.dsp_shared->monitor_rsc);
+ dsp_comp_hub.dsp_io->write_string_field(rsc_name, dsp_comp_hub.term_cols - 20, false);
+ ++current_line;
+
+ dsp_comp_hub.dsp_io->cursor_xy(1, current_line);
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->emphasis_text.c_str());
+ dsp_comp_hub.dsp_io->write_text("Connection:");
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->rst.c_str());
+ dsp_comp_hub.dsp_io->cursor_xy(21, current_line);
+
+ if (!dsp_comp_hub.dsp_shared->monitor_con.empty())
+ {
+ DrbdConnection* const con = dsp_comp_hub.get_monitor_connection();
+ const std::string& con_name = (con != nullptr ? con->get_name() : dsp_comp_hub.dsp_shared->monitor_con);
+ dsp_comp_hub.dsp_io->write_string_field(con_name, dsp_comp_hub.term_cols - 20, false);
+ ++current_line;
+
+ const uint16_t vlm_nr = dsp_comp_hub.dsp_shared->monitor_peer_vlm;
+
+ dsp_comp_hub.dsp_io->cursor_xy(1, current_line);
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->emphasis_text.c_str());
+ dsp_comp_hub.dsp_io->write_text("Volume:");
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->rst.c_str());
+ dsp_comp_hub.dsp_io->cursor_xy(21, current_line);
+ if (vlm_nr != DisplayConsts::VLM_NONE)
+ {
+ dsp_comp_hub.dsp_io->write_fmt("%u", static_cast<unsigned int> (vlm_nr));
+ ++current_line;
+
+ dsp_comp_hub.dsp_io->cursor_xy(1, current_line);
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->emphasis_text.c_str());
+ dsp_comp_hub.dsp_io->write_text("Status:");
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->rst.c_str());
+ dsp_comp_hub.dsp_io->cursor_xy(21, current_line);
+
+ if (rsc != nullptr)
+ {
+ if (con != nullptr)
+ {
+ DrbdVolume* const vlm = con->get_volume(vlm_nr);
+ if (vlm != nullptr)
+ {
+ if (vlm->has_alert_state() || vlm->has_warn_state())
+ {
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->alert.c_str());
+ dsp_comp_hub.dsp_io->write_text("Degraded");
+ }
+ else
+ {
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->norm.c_str());
+ dsp_comp_hub.dsp_io->write_text("Normal");
+ }
+ ++current_line;
+
+ dsp_comp_hub.dsp_io->cursor_xy(1, current_line);
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->emphasis_text.c_str());
+ dsp_comp_hub.dsp_io->write_text("Disk state:");
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->rst.c_str());
+ dsp_comp_hub.dsp_io->cursor_xy(21, current_line);
+ if (vlm->has_disk_alert())
+ {
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->alert.c_str());
+ }
+ else
+ {
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->norm.c_str());
+ }
+ const char* const disk_state_label = vlm->get_disk_state_label();
+ DrbdVolume::disk_state vlm_disk_state = vlm->get_disk_state();
+ dsp_comp_hub.dsp_io->write_text(disk_state_label);
+ if (vlm_disk_state == DrbdVolume::disk_state::DISKLESS)
+ {
+ if (vlm->has_disk_alert())
+ {
+ dsp_comp_hub.dsp_io->write_text(" (Detached/Failed)");
+ }
+ else
+ {
+ dsp_comp_hub.dsp_io->write_text(" (DRBD client)");
+ }
+ }
+ ++current_line;
+
+ dsp_comp_hub.dsp_io->cursor_xy(1, current_line);
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->emphasis_text.c_str());
+ dsp_comp_hub.dsp_io->write_text("Replication state:");
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->rst.c_str());
+ dsp_comp_hub.dsp_io->cursor_xy(21, current_line);
+ if (vlm->has_replication_alert())
+ {
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->alert.c_str());
+ }
+ else
+ if (vlm->has_replication_warning())
+ {
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->warn.c_str());
+ }
+ else
+ {
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->norm.c_str());
+ }
+ const char* const repl_state_label = vlm->get_replication_state_label();
+ dsp_comp_hub.dsp_io->write_text(repl_state_label);
+ ++current_line;
+
+ dsp_comp_hub.dsp_io->cursor_xy(1, current_line);
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->emphasis_text.c_str());
+ dsp_comp_hub.dsp_io->write_text("Quorum:");
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->rst.c_str());
+ dsp_comp_hub.dsp_io->cursor_xy(21, current_line);
+ if (vlm->has_quorum_alert())
+ {
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->alert.c_str());
+ dsp_comp_hub.dsp_io->write_text("No");
+ }
+ else
+ {
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->norm.c_str());
+ dsp_comp_hub.dsp_io->write_text("Yes");
+ }
+
+ if (is_action_available())
+ {
+ current_line += 2;
+ dsp_comp_hub.dsp_io->cursor_xy(1, current_line);
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->hotkey_field.c_str());
+ dsp_comp_hub.dsp_io->write_text(" A ");
+ dsp_comp_hub.dsp_io->write_text(dsp_comp_hub.active_color_table->hotkey_label.c_str());
+ dsp_comp_hub.dsp_io->write_text(" Actions");
+
+ if (current_line != saved_options_line)
+ {
+ clear_options();
+ options_configured = false;
+ }
+
+ if (!options_configured)
+ {
+ cmd_actions->clickable_area.row = current_line;
+
+ add_option_clickable(*cmd_actions);
+
+ saved_options_line = current_line;
+ options_configured = true;
+ }
+ }
+ }
+ else
+ {
+ dsp_comp_hub.dsp_io->write_text("Volume not active");
+ }
+ }
+ else
+ {
+ dsp_comp_hub.dsp_io->write_text("Connection not active");
+ }
+ }
+ else
+ {
+ dsp_comp_hub.dsp_io->write_text("Resource not active");
+ }
+ }
+ else
+ {
+ dsp_comp_hub.dsp_io->write_text("No selected volume");
+ }
+ }
+ else
+ {
+ dsp_comp_hub.dsp_io->write_text("No selected connection");
+ }
+ }
+ else
+ {
+ dsp_comp_hub.dsp_io->write_text("No selected resource");
+ }
+}
+
+uint64_t MDspPeerVolumeDetail::get_update_mask() noexcept
+{
+ return update_event::UPDATE_FLAG_DRBD;
+}
+
+bool MDspPeerVolumeDetail::key_pressed(const uint32_t key)
+{
+ // Skip MDspMenuBase, not using the option field
+ bool intercepted = MDspBase::key_pressed(key);
+ if (!intercepted)
+ {
+ if (key == KeyCodes::FUNC_01)
+ {
+ helptext::open_help_page(helptext::id_type::PVLM_DETAIL, dsp_comp_hub);
+ intercepted = true;
+ }
+ else
+ if (key == static_cast<uint32_t> ('A') || key == static_cast<uint32_t> ('a'))
+ {
+ opt_actions();
+ intercepted = true;
+ }
+ }
+ return intercepted;
+}
+
+void MDspPeerVolumeDetail::text_cursor_ops()
+{
+ // no-op; prevents MDspMenuBase from positioning the cursor for the option field, which is not used
+}
+
+void MDspPeerVolumeDetail::display_activated()
+{
+ MDspBase::display_activated();
+ dsp_comp_hub.dsp_shared->ovrd_peer_volume_selection = true;
+}
+
+void MDspPeerVolumeDetail::display_deactivated()
+{
+ MDspBase::display_deactivated();
+ clear_options();
+ options_configured = false;
+}
+
+void MDspPeerVolumeDetail::opt_actions()
+{
+ if (is_action_available())
+ {
+ dsp_comp_hub.dsp_selector->switch_to_display(DisplayId::display_page::PEER_VLM_ACTIONS);
+ }
+}
+
+bool MDspPeerVolumeDetail::is_action_available()
+{
+ bool available = false;
+ const uint16_t vlm_nr = dsp_comp_hub.dsp_shared->monitor_peer_vlm;
+ if (vlm_nr != DisplayConsts::VLM_NONE)
+ {
+ DrbdConnection* const con = dsp_comp_hub.get_monitor_connection();
+ if (con != nullptr)
+ {
+ DrbdConnection::state con_state = con->get_connection_state();
+ if (con_state == DrbdConnection::state::CONNECTED)
+ {
+ DrbdVolume* const vlm = con->get_volume(dsp_comp_hub.dsp_shared->monitor_peer_vlm);
+ if (vlm != nullptr)
+ {
+ available = true;
+ }
+ }
+ }
+ }
+ return available;
+}
diff --git a/user/drbdmon/terminal/MDspPeerVolumeDetail.h b/user/drbdmon/terminal/MDspPeerVolumeDetail.h
new file mode 100644
index 00000000..3261b27a
--- /dev/null
+++ b/user/drbdmon/terminal/MDspPeerVolumeDetail.h
@@ -0,0 +1,35 @@
+#ifndef MDSPPEERVOLUMEDETAIL_H
+#define MDSPPEERVOLUMEDETAIL_H
+
+#include <default_types.h>
+#include <terminal/MDspMenuBase.h>
+
+class MDspPeerVolumeDetail : public MDspMenuBase
+{
+ public:
+ MDspPeerVolumeDetail(const ComponentsHub& comp_hub);
+ virtual ~MDspPeerVolumeDetail() noexcept;
+
+ virtual void display_content() override;
+ virtual uint64_t get_update_mask() noexcept override;
+ virtual bool key_pressed(const uint32_t key) override;
+
+ virtual void text_cursor_ops() override;
+
+ virtual void display_activated() override;
+ virtual void display_deactivated() override;
+
+ private:
+ bool options_configured {false};
+
+ uint32_t saved_options_line {0};
+
+ std::function<void()> cmd_fn_actions;
+
+ std::unique_ptr<ClickableCommand> cmd_actions;
+
+ void opt_actions();
+ bool is_action_available();
+};
+
+#endif /* MDSPPEERVOLUMEDETAIL_H */
diff --git a/user/drbdmon/terminal/MDspPeerVolumes.cpp b/user/drbdmon/terminal/MDspPeerVolumes.cpp
index 3bfed7b9..4ffe760d 100644
--- a/user/drbdmon/terminal/MDspPeerVolumes.cpp
+++ b/user/drbdmon/terminal/MDspPeerVolumes.cpp
@@ -418,6 +418,7 @@ void MDspPeerVolumes::display_at_cursor()
DrbdConnection* const con = dsp_comp_hub.get_monitor_connection();
if (rsc != nullptr && con != nullptr)
{
+ const bool selecting = dsp_comp_hub.dsp_shared->have_peer_volumes_selection();
const uint16_t vlm_count = con->get_volume_count();
const bool problem_mode_flag = is_problem_mode(rsc, con);
dsp_comp_hub.dsp_common->display_problem_mode_label(problem_mode_flag);
@@ -456,7 +457,7 @@ void MDspPeerVolumes::display_at_cursor()
if (problem_filter(vlm))
{
dsp_comp_hub.dsp_io->cursor_xy(1, PEER_VLM_LIST_Y + line_nr);
- write_volume_line(vlm, current_line);
+ write_volume_line(vlm, current_line, selecting);
++line_nr;
}
}
@@ -489,7 +490,7 @@ void MDspPeerVolumes::display_at_cursor()
{
DrbdVolume* const vlm = dsp_vlm_iter.next();
dsp_comp_hub.dsp_io->cursor_xy(1, PEER_VLM_LIST_Y + line_nr);
- write_volume_line(vlm, current_line);
+ write_volume_line(vlm, current_line, selecting);
++line_nr;
}
}
@@ -510,6 +511,7 @@ void MDspPeerVolumes::display_at_page()
DrbdConnection* const con = dsp_comp_hub.get_monitor_connection();
if (dsp_rsc != nullptr && con != nullptr)
{
+ const bool selecting = dsp_comp_hub.dsp_shared->have_peer_volumes_selection();
const uint32_t lines_per_page = get_lines_per_page();
const bool problem_mode_flag = is_problem_mode(dsp_rsc, con);
dsp_comp_hub.dsp_common->display_problem_mode_label(problem_mode_flag);
@@ -533,7 +535,7 @@ void MDspPeerVolumes::display_at_page()
if (problem_filter(dsp_vlm))
{
dsp_io->cursor_xy(1, PEER_VLM_LIST_Y + line_nr);
- write_volume_line(dsp_vlm, current_line);
+ write_volume_line(dsp_vlm, current_line, selecting);
++line_nr;
}
}
@@ -557,7 +559,7 @@ void MDspPeerVolumes::display_at_page()
{
DrbdVolume* const vlm = vlm_iter.next();
dsp_io->cursor_xy(1, PEER_VLM_LIST_Y + line_nr);
- write_volume_line(vlm, current_line);
+ write_volume_line(vlm, current_line, selecting);
++line_nr;
}
}
@@ -630,7 +632,7 @@ void MDspPeerVolumes::list_item_clicked(MouseEvent& mouse)
}
}
-void MDspPeerVolumes::write_volume_line(DrbdVolume* const vlm, uint32_t& current_line)
+void MDspPeerVolumes::write_volume_line(DrbdVolume* const vlm, uint32_t& current_line, const bool selecting)
{
DisplayIo* const dsp_io = dsp_comp_hub.dsp_io;
dsp_io->cursor_xy(1, current_line);
diff --git a/user/drbdmon/terminal/MDspPeerVolumes.h b/user/drbdmon/terminal/MDspPeerVolumes.h
index adb23fe7..44a24763 100644
--- a/user/drbdmon/terminal/MDspPeerVolumes.h
+++ b/user/drbdmon/terminal/MDspPeerVolumes.h
@@ -56,7 +56,6 @@ class MDspPeerVolumes : public MDspStdListBase
std::string displayed_con;
uint16_t cursor_vlm {DisplayConsts::VLM_NONE};
- bool selecting {false};
std::function<bool(DrbdVolume*)> problem_filter;
std::function<const uint16_t&(DrbdVolume*)> vlm_key_func;
@@ -65,7 +64,7 @@ class MDspPeerVolumes : public MDspStdListBase
void display_at_cursor();
void display_at_page();
void list_item_clicked(MouseEvent& mouse);
- void write_volume_line(DrbdVolume* const vlm, uint32_t& current_line);
+ void write_volume_line(DrbdVolume* const vlm, uint32_t& current_line, const bool selecting);
bool is_problem_mode(DrbdResource* const rsc, DrbdConnection* const con);
uint32_t get_lines_per_page();
--
2.33.1.windows.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。