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 66 of file warema-jalousien.cpp.

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

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

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

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

Referenced by main().

◆ jalousien

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 55 of file warema-jalousien.cpp.

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

Referenced by main().