-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHostNameModule.cpp
94 lines (74 loc) · 2.52 KB
/
HostNameModule.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
86
87
88
89
90
91
92
93
94
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HostNameModule.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kdenisov <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/03 16:03:12 by kdenisov #+# #+# */
/* Updated: 2019/11/14 11:12:57 by kdenisov ### ########.fr */
/* */
/* ************************************************************************** */
#include <fstream>
#include <unistd.h>
#include <string>
#include "includes/HostNameModule.hpp"
HostNameModule::HostNameModule() {
}
HostNameModule::HostNameModule(int pos, int gpos) : _pos(pos), _gpos(gpos) {
this->_module = "HOSTNAME";
char buff[50];
gethostname(buff, sizeof(buff) - 1);
this->_host = "Hostname: ";
this->_host += buff;
system("whoami > ./logs/userlog");
std::ifstream ifs("./logs/userlog");
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 user;
std::getline(ifs, user);
this->_user = "Username: " + user;
ifs.close();
}
HostNameModule::~HostNameModule() {
}
HostNameModule::HostNameModule(HostNameModule const & src) {
*this = src;
}
HostNameModule & HostNameModule::operator=(HostNameModule const & rfs) {
this->_module = rfs._module;
this->_host = rfs._host;
this->_user = rfs._user;
this->_pos = rfs._pos;
this->_gpos = rfs._gpos;
return (*this);
}
void HostNameModule::render(IMonitorDisplay *d) {
d->render(this);
}
void HostNameModule::refresh() {
}
std::string HostNameModule::getName() const {
return (this->_module);
}
int HostNameModule::getPos() const {
return (this->_pos);
}
int HostNameModule::getGPos() const {
return (this->_gpos);
}
std::string HostNameModule::getHostName() const {
return (this->_host);
}
std::string HostNameModule::getUserName() const {
return (this->_user);
}
int HostNameModule::getSize(std::string const name) const {
return (name.length());
}