-
Notifications
You must be signed in to change notification settings - Fork 0
/
serverUI.cpp
83 lines (73 loc) · 1.76 KB
/
serverUI.cpp
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
#include "server.hpp"
#include "util.hpp"
#include "serverUI.hpp"
void mainScreen();
void close_serverUI(int sig);
using namespace std;
FSServerUI::FSServerUI(FileSyncServer* serv) {
server = serv;
}
void FSServerUI::start() {
init();
running = true;
thread = std::thread(&FSServerUI::run, this);
}
void FSServerUI::close() {
running = false;
thread.join();
}
void FSServerUI::run() {
int ch;
int h, w;
int sessions = server->countSessions();
int users = server->countUsers();
getmaxyx(stdscr, h, w);
// create log window
WINDOW* info_win = newwin(h/2, w/2, 0, 0);
WINDOW* log_win = newwin(h, w/2, 0, w/2);
nodelay(info_win, TRUE);
nodelay(log_win, TRUE);
box(info_win, 0, 0);
box(log_win, 0, 0);
// refresh();
//start running
wrefresh(info_win);
wrefresh(log_win);
while (running) {
getmaxyx(stdscr, h, w);
if (server->qlogsemaphore.trywait() == 0) {
server->qlogmutex.lock();
int lines = 0;
werase(log_win);
for (auto ii = server->qlog.begin(); ii != server->qlog.end() && lines < (h-4); ++ii) {
wmove(log_win, h-2-(lines++), 2);
wprintw(log_win, (*ii).c_str());
}
server->qlogmutex.unlock();
box(log_win, 0, 0);
wrefresh(log_win);
}
sessions = server->countSessions();
users = server->countUsers();
wmove(info_win, 1, 2);
wprintw(info_win ,"sessions: %2d", sessions);
wmove(info_win, 3, 2);
wprintw(info_win ,"users: %2d", users);
wmove(info_win, 0, 0);
wrefresh(info_win);
if ((ch = wgetch(info_win)) == ERR) {
// no input
} else {
// user pressed a key
switch (ch) {
case 'q':
case 'Q':
server->stop();
break;
default:
break;
}
}
}
end();
}