-
Notifications
You must be signed in to change notification settings - Fork 6
/
abstractrpm.h
96 lines (73 loc) · 2.32 KB
/
abstractrpm.h
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
95
96
#ifndef ABSTRACTRPM_H
#define ABSTRACTRPM_H
#include <Wt/WObject>
#include <Wt/WString>
#include <Wt/WServer>
#include <Wt/Json/Object>
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
class ComputerView;
class View;
class AbstractRPM : public Wt::WObject
{
protected:
struct Gpio
{
int pin;
bool inverted;
};
struct Computer
{
Wt::WString name;
Wt::WString ipAddress;
double ping;
Gpio powerLed;
Gpio powerSwitch;
Gpio atxSwitch;
std::vector<Wt::WString> read_ACL;
std::vector<Wt::WString> write_ACL;
};
std::vector<Computer> _computers;
private:
boost::mutex computerStateLock;
std::map< Wt::WString, bool > _powerLedState;
std::map< Wt::WString, Wt::WString > _computerLogs;
std::shared_ptr<Wt::WServer> server;
boost::mutex viewsLock;
std::map< std::string, View* > views;
boost::thread gpioPollingThread;
boost::thread pingPollingThread;
boost::mutex pollingThreadsExitLock;
bool shouldExit;
enum AccesssType { READ = 0, WRITE };
bool parseConfiguration(Wt::Json::Object &conf);
bool parseComputer(Wt::Json::Object &computer);
Gpio parseGpio(Wt::Json::Object &gpio);
void setPingDelay(const Wt::WString &computerName, double delay);
void pollInputs();
void pollPings();
std::string currentUser() const;
bool currentUserIsInAccessList(const Wt::WString &computerName,
AccesssType type) const;
protected:
const Computer *findComputer(const Wt::WString &computerName) const;
void setPowerLedState(const Wt::WString &computerName, bool state);
void consoleAddData(const Wt::WString &computerName, const Wt::WString &data);
void startPolling();
public:
AbstractRPM(std::shared_ptr<Wt::WServer> server, Wt::Json::Object conf);
void addView(View* view);
bool deleteView(std::string sessionId);
bool powerLedState(const Wt::WString &computerName);
/* input events */
void atx_force_off(const Wt::WString &computerName);
void atx_force_on(const Wt::WString &computerName);
void atx_reset(const Wt::WString &computerName);
void pw_switch_press(const Wt::WString &computerName);
void pw_switch_force_off(const Wt::WString &computerName);
/* to be re-implemented by the backend */
virtual bool gpioIsValid(const struct Gpio &gpio);
virtual bool readGPIO(const struct Gpio &gpio);
virtual void writeGPIO(const struct Gpio &gpio, int value);
};
#endif // ABSTRACTRPM_H