-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisksModule.cpp
85 lines (68 loc) · 2.27 KB
/
DisksModule.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
84
85
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* DisksModule.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kdenisov <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/03 16:04:44 by kdenisov #+# #+# */
/* Updated: 2019/11/14 11:12:25 by kdenisov ### ########.fr */
/* */
/* ************************************************************************** */
#include <fstream>
#include <unistd.h>
#include <string>
#include <sys/sysctl.h>
#include "includes/DisksModule.hpp"
DisksModule::DisksModule() {
}
DisksModule::DisksModule(int pos, int gpos) : _pos(pos), _gpos(gpos) {
this->_module = "DISKS";
refresh();
}
DisksModule::~DisksModule() {
}
DisksModule::DisksModule(DisksModule const & src) {
*this = src;
}
DisksModule & DisksModule::operator=(DisksModule const & rfs) {
this->_module = rfs._module;
this->_info = rfs._info;
this->_pos = rfs._pos;
this->_gpos = rfs._gpos;
return (*this);
}
void DisksModule::render(IMonitorDisplay *d) {
d->render(this);
}
void DisksModule::refresh() {
system("top -l 1 | grep \"Disks\" | awk '{print $2\" \"$3\" \"$4\" \"$5}' > ./logs/disklog");
std::ifstream ifs("./logs/disklog");
try {
if (!ifs.is_open())
throw std::exception();
}
catch(std::exception& e) {
std::cerr << e.what() << "(" << getName() << ")" << ": Failed on openning file" << std::endl;
exit(1);
}
std::string buff;
std::getline(ifs, buff);
this->_info = buff;
ifs.close();
}
std::string DisksModule::getName() const {
return (this->_module);
}
int DisksModule::getPos() const {
return (this->_pos);
}
int DisksModule::getGPos() const {
return (this->_gpos);
}
std::string DisksModule::getInfo() const {
return (this->_info);
}
int DisksModule::getSize(std::string const name) const {
return (name.length());
}