SNode.C
Loading...
Searching...
No Matches
warema-jalousien.cpp File Reference
Include dependency graph for warema-jalousien.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static std::map< std::string, std::string > jalousien
 
static std::map< std::string, std::string > actions = {{"open", "up"}, {"close", "down"}, {"stop", "stop"}}
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 67 of file warema-jalousien.cpp.

67 {
68 WebApp::init(argc, argv);
69
70 legacy::in::WebApp webApp("werema");
71
72 // tls::WebApp wa;
73
74 webApp.get("/jalousien/:id", [] APPLICATION(req, res) {
75 VLOG(1) << "Param: " << req->param("id");
76 VLOG(1) << "Qurey: " << req->query("action");
77
78 std::string arguments = "aircontrol -t " + jalousien[req->param("id")] + "_" + actions[req->query("action")];
79
80 int ret = system(arguments.c_str());
81 ret = (ret >> 8) & 0xFF;
82 /* ret:
83 Bits 15-8 = Exit code.
84 Bit 7 = 1 if a core dump was produced.
85 Bits 6-0 = Signal number that killed the process.
86 */
87
88 switch (ret) {
89 case 0:
90 res->status(200).send("OK: " + arguments);
91 break;
92 case 127:
93 res->status(404).send("ERROR not found: " + arguments);
94 break;
95 }
96 });
97
98 webApp.use([] APPLICATION(req, res) {
99 res->status(404).send("No Jalousie specified");
100 });
101
102 webApp.listen(8080,
103 [instanceName = webApp.getConfig().getInstanceName()](const legacy::in::WebApp::SocketAddress& socketAddress,
104 const core::socket::State& state) {
105 switch (state) {
107 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
108 break;
110 VLOG(1) << instanceName << ": disabled";
111 break;
113 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
114 break;
116 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
117 break;
118 }
119 });
120
121 return WebApp::start();
122}
#define APPLICATION(req, res)
Definition Router.h:68
static constexpr int DISABLED
Definition State.h:56
static constexpr int ERROR
Definition State.h:57
static constexpr int FATAL
Definition State.h:58
static constexpr int OK
Definition State.h:55
typename Server::SocketAddress SocketAddress
Definition WebAppT.h:70
static void init(int argc, char *argv[])
Definition WebApp.cpp:56
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
Definition WebApp.cpp:60
static std::map< std::string, std::string > jalousien
static std::map< std::string, std::string > actions

References actions, core::socket::State::DISABLED, core::socket::State::ERROR, core::socket::State::FATAL, core::socket::Socket< ConfigT >::getConfig(), net::config::ConfigInstance::getInstanceName(), express::WebApp::init(), jalousien, net::in::stream::SocketServer< SocketAcceptorT, ConfigSocketServerT, SocketContextFactoryT, Args >::listen(), core::socket::State::OK, express::Request::param(), express::Request::query(), express::Response::send(), express::WebApp::start(), express::Response::status(), net::in::SocketAddress::toString(), express::WebAppT< ServerT >::WebAppT(), and core::socket::State::what().

Here is the call graph for this function:

Variable Documentation

◆ actions

static std::map< std::string, std::string > actions = {{"open", "up"}, {"close", "down"}, {"stop", "stop"}}
static

Definition at line 65 of file warema-jalousien.cpp.

65{{"open", "up"}, {"close", "down"}, {"stop", "stop"}};

Referenced by main().

◆ jalousien

static std::map< std::string, std::string > jalousien
static
Initial value:
= {{"kueche", "kueche"},
{"strasse", "strasse"},
{"esstisch", "esstisch"},
{"balkon", "balkon"},
{"schlafzimmer", "schlafzimmer"},
{"arbeitszimmer", "arbeitszimmer"},
{"comfort", "komfort"},
{"all", "alle"}}

Definition at line 56 of file warema-jalousien.cpp.

56 {{"kueche", "kueche"},
57 {"strasse", "strasse"},
58 {"esstisch", "esstisch"},
59 {"balkon", "balkon"},
60 {"schlafzimmer", "schlafzimmer"},
61 {"arbeitszimmer", "arbeitszimmer"},
62 {"comfort", "komfort"},
63 {"all", "alle"}};

Referenced by main().