File: DebugDisplay.cpp

package info (click to toggle)
drbd-utils 9.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,388 kB
  • sloc: ansic: 43,698; xml: 15,968; cpp: 7,783; sh: 3,699; makefile: 1,353; perl: 353
file content (102 lines) | stat: -rw-r--r-- 2,905 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <DebugDisplay.h>
#include <DrbdMon.h>

DebugDisplay::DebugDisplay(
    ResourcesMap& resources_map_ref,
    MessageLog&   log_ref,
    HotkeysMap&   hotkeys_info_ref
):
    resources_map(resources_map_ref),
    log(log_ref),
    hotkeys_info(hotkeys_info_ref)
{
}

DebugDisplay::~DebugDisplay() noexcept
{
}

void DebugDisplay::initial_display()
{
    display_header();
    std::fputs("Reading initial DRBD status\n", stdout);
}

void DebugDisplay::status_display()
{
    display_header();

    ResourcesMap::ValuesIterator res_iter(resources_map);
    while (res_iter.has_next())
    {
        DrbdResource& resource = *(res_iter.next());
        const std::string& res_name = resource.get_name();
        std::fprintf(stdout, "Resource %s\n", res_name.c_str());

        std::fputs("  Volumes:\n", stdout);
        VolumesMap::ValuesIterator vol_iter = resource.volumes_iterator();
        while (vol_iter.has_next())
        {
            DrbdVolume& volume = *(vol_iter.next());
            uint16_t vol_id = volume.get_volume_nr();

            fprintf(stdout, "  * Volume #%u\n", (unsigned int) vol_id);
        }

        std::fputs("  Connections:\n", stdout);
        ConnectionsMap::ValuesIterator conn_iter = resource.connections_iterator();
        while (conn_iter.has_next())
        {
            DrbdConnection& connection = *(conn_iter.next());
            const std::string& conn_name = connection.get_name();
            std::fprintf(stdout, "  * Connection -> %s\n", conn_name.c_str());

            std::fputs("  Peer Volumes:\n", stdout);
            VolumesMap::ValuesIterator peer_vol_iter = connection.volumes_iterator();
            while (peer_vol_iter.has_next())
            {
                DrbdVolume& volume = *(peer_vol_iter.next());
                uint16_t vol_id = volume.get_volume_nr();

                std::fprintf(stdout, "    * Peer-Volume #%u\n", (unsigned int) vol_id);
            }
        }
    }

    display_hotkeys_info();

    std::fputc('\n', stdout);
    std::fflush(stdout);
}

void DebugDisplay::display_header() const
{
    std::fprintf(stdout, "%s DebugDisplay v%s\n\n", DrbdMon::PROGRAM_NAME.c_str(), DrbdMon::VERSION.c_str());
}

void DebugDisplay::set_terminal_size(uint16_t size_x, uint16_t size_y)
{
    // no-op
}

void DebugDisplay::display_hotkeys_info() const
{
    HotkeysMap::NodesIterator hotkeys_iter(hotkeys_info);
    size_t count = hotkeys_iter.get_size();
    for (size_t index = 0; index < count; ++index)
    {
        HotkeysMap::Node* node = hotkeys_iter.next();
        const char hotkey = *(node->get_key());
        const std::string& description = *(node->get_value());
        if (index > 0)
        {
            std::fputs(" / ", stdout);
        }
        std::fprintf(stdout, "%c => %s", hotkey, description.c_str());
    }
    std::fputc('\n', stdout);
}

void DebugDisplay::key_pressed(const char key)
{
}