-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetwork.class.cpp
66 lines (56 loc) · 2.04 KB
/
Network.class.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
// ************************************************************************** //
// //
// ::: :::::::: //
// Network.class.cpp :+: :+: :+: //
// +:+ +:+ +:+ //
// By: oposhiva <marvin@42.fr> +#+ +:+ +#+ //
// +#+#+#+#+#+ +#+ //
// Created: 2017/11/12 15:14:00 by oposhiva #+# #+# //
// Updated: 2017/11/12 15:14:00 by oposhiva ### ########.fr //
// //
// ************************************************************************** //
#include "Network.class.hpp"
#include <ncurses.h>
#include <sstream>
Network::Network() {
this->set_x( 0 );
this->set_y( 29 );
this->set_width( 54 );
this->set_height( 6 );
this->set_name( " Network throughput module" );
}
Network::Network( Network const &rhs ) {
*this = rhs;
}
Network & Network::operator=( Network const &rhs ) {
this->set_x(rhs.get_x());
this->set_y(rhs.get_y());
this->set_width(rhs.get_width());
this->set_height(rhs.get_height());
return ( *this );
}
std::string Network::getInfo() const {
std::string ret;
std::stringstream stream;
FILE *filename;
char buff[1024];
if(not (filename = popen("/usr/bin/top | /usr/bin/head -n9 | /usr/bin/grep 'Network'", "r")))
return ( "Error!" );
while(fgets(buff, sizeof(buff), filename))
stream << buff;
pclose( filename );
ret = " " + stream.str();
ret.insert(36, 1, '\n');
ret.insert(37, 2, '\t');
return ( ret );
}
void Network::print() {
move(get_y() + 1, get_x() + 1);
attron(COLOR_PAIR(2));
printw("%s", (this->get_name()).c_str());
attroff(COLOR_PAIR(2));
move(get_y() + 3, get_x() + 1);
printw("%s", (getInfo()).c_str());
this->bord();
}
Network::~Network() {}