-
Notifications
You must be signed in to change notification settings - Fork 0
/
loop.cpp
86 lines (57 loc) · 1.55 KB
/
loop.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
#include <thread>
#include "podman.hpp"
#include "mutex.hpp"
#include "ubus.hpp"
#include "log.hpp"
#include "loop.hpp"
bool Loop::sig_exit(void) {
std::lock_guard<std::mutex> guard(this -> sig_mutex);
return this -> _sig_exit;
}
bool Loop::running(void) {
std::lock_guard<std::mutex> guard(this -> sig_mutex);
return this -> _running;
}
int Loop::delay(void) {
std::lock_guard<std::mutex> guard(this -> sig_mutex);
return this -> _delay;
}
void Loop::set_sig_exit(bool state) {
std::lock_guard<std::mutex> guard(this -> sig_mutex);
this -> _sig_exit = state;
}
void Loop::set_running(bool state) {
std::lock_guard<std::mutex> guard(this -> sig_mutex);
this -> _running = state;
}
void Loop::set_delay(int delay) {
std::lock_guard<std::mutex> guard(this -> sig_mutex);
this -> _delay = delay;
}
void Loop::sleep(int ms) {
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
void Loop::run(void) {
if ( this -> running())
return;
bool minimalSleep = false;
this -> set_running(true);
int __delay = this -> delay();
this -> sleep((int)(__delay * 0.5));
while ( !this -> sig_exit()) {
if ( podman_data -> status != Podman::PODMAN_STATUS::RUNNING ) {
log::debug << "connection to podman socket unverified." << std::endl;
log::vverbose << "attempting to connect to podman socket" << std::endl;
Podman::init(podman_data);
this -> sleep(__delay * 2);
continue;
}
podman_scheduler -> run();
this -> sleep(__delay);
}
this -> set_running(false);
}
Loop main_loop;
void run_main_loop(void) {
main_loop.run();
}