-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
76 lines (59 loc) · 1.42 KB
/
main.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
#include "LEDControl.h"
#include "CPUData.h"
#include "NetworkData.h"
#include "BOINCData.h"
#include <thread>
#include <chrono>
#include <iostream>
#include <csignal>
#include <cstring>
#include <iomanip>
#include <ctime>
using namespace std;
//necessary globals for signal handling
namespace
{
volatile sig_atomic_t done = 0;
void caught_signal(int signal)
{
done = signal;
}
}
int main()
{
//set up signal handling
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = caught_signal;
sigfillset(&sa.sa_mask);
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
LEDControl led_control; //must be instantiated first
CPUData cpu_data(&led_control);
BOINCData boinc_data(&led_control);
NetworkData network_data(&led_control);
uint64_t update = 0;
while(!done)
{
this_thread::sleep_for(chrono::seconds(5));
//timestamp for logs
char timestamp[64];
time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime(timestamp, sizeof(timestamp), "%Y%m%d %H:%M:%S", timeinfo);
cout << timestamp << endl;
update++;
cout << " net " << update << endl;
network_data.update();
network_data.display();
cout << " cpu " << update << endl;
cpu_data.update();
cpu_data.display();
cout << " boinc " << update << endl;
boinc_data.update();
boinc_data.display();
}
return 0;
}