Debian Codegraph @

analyzers/src/watch/nc_windows/header_window.cpp

raw ◀ ▶
3 Debian patches touch this file
1 //------------------------------------------------------------------------------
2 // Author: Vitali Adamenka
3 // Description: Source for descripne ncurses header window.
4 // Copyright (c) 2015 EPAM Systems. All Rights Reserved.
5 //------------------------------------------------------------------------------
6 /*
7 This file is part of Nfstrace.
8
9 Nfstrace is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, version 2 of the License.
12
13 Nfstrace is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Nfstrace. If not, see <http://www.gnu.org/licenses/>.
20 */
21 //------------------------------------------------------------------------------
22 #include <algorithm>
23 #include <ctime>
24 #include <stdexcept>
25
26 #include <unistd.h>
27
28 #include "header_window.h"
29 #include "nc_window_const.h"
30 //------------------------------------------------------------------------------
31 namespace HEADER
32 {
33 const int MEMO_LINE = 1;
34 const int HOST_LINE = 2;
35 const int DATE_LINE = 3;
36 const int ELAPSED_LINE = 4;
37 const int HOST_SIZE = 128;
38 }
39
40 void HeaderWindow::destroy()
41 {
42 if(_window == nullptr)
43 {
44 return;
45 }
46 werase(_window);
47 wclear(_window);
48 delwin(_window);
49 _window = nullptr;
50 }
51
52 HeaderWindow::HeaderWindow(MainWindow& w)
53 : _start_time{time(NULL)}
54 {
55 if(w._window == nullptr)
56 {
57 throw std::runtime_error("Initialization of Header window failed.");
58 }
59 resize(w);
60 }
61
62 HeaderWindow::~HeaderWindow()
63 {
64 }
65
66 void HeaderWindow::update()
67 {
68 if(_window == nullptr)
69 {
70 return;
71 }
72 time_t actual_time = time(nullptr);
73 tm* t = localtime(&actual_time);
74 time_t shift_time = actual_time - _start_time;
75 /* tm starts with 0 month and 1900 year*/
76 mvwprintw(_window, HEADER::DATE_LINE, FIRST_CHAR_POS, "Date: \t %d.%d.%d \t Time: %d:%d:%d ", t->tm_mday, t->tm_mon + 1, t->tm_year + 1900, t->tm_hour, t->tm_min, t->tm_sec);
•77 mvwprintw(_window, HEADER::ELAPSED_LINE, FIRST_CHAR_POS, "Elapsed time: \t %jd days; %jd:%jd:%jd",
78 (intmax_t)shift_time / SECINDAY, (intmax_t)shift_time % SECINDAY / SECINHOUR, (intmax_t)shift_time % SECINHOUR / SECINMIN, (intmax_t)shift_time % SECINMIN);
79 wrefresh(_window);
80 }
81
82 void HeaderWindow::resize(MainWindow& m)
83 {
84 if(_window != nullptr)
85 {
86 destroy();
87 }
88 if(m._window != nullptr)
89 {
•90 _window = subwin(m._window, std::min(static_cast<int>(getmaxy(m._window) - 1 ), GUI_HEADER_HEIGHT), std::min(static_cast<int>(getmaxx(m._window) - 1 ), GUI_LENGTH), 0, 0);
91 }
92 if(_window != nullptr)
93 {
94 werase(_window);
95 wborder(_window, ACS_VLINE, ACS_VLINE, ACS_HLINE, ACS_HLINE, ACS_ULCORNER, ACS_URCORNER, ACS_LLCORNER, ACS_LRCORNER);
96 char HOST_NAME[HEADER::HOST_SIZE];
97 gethostname(HOST_NAME, HEADER::HOST_SIZE);
98 mvwprintw(_window, HEADER::MEMO_LINE, FIRST_CHAR_POS, "%s", "Nfstrace watch plugin. To scroll press up or down keys. Ctrl + c to exit.");
99 mvwprintw(_window, HEADER::HOST_LINE, FIRST_CHAR_POS, "Host name:\t %s", HOST_NAME);
100 }
101 }
102 //------------------------------------------------------------------------------