Initial commit

This commit is contained in:
2024-05-29 11:22:00 +02:00
commit 4dd36db312
4 changed files with 180 additions and 0 deletions

53
main.cpp Normal file
View File

@@ -0,0 +1,53 @@
#include <iostream>
#include <httplib.h>
#include <noolite.h>
namespace App {
constexpr auto DefaultPort = 8888;
constexpr auto DefaultHost = "0.0.0.0";
static httplib::Server *srv = nullptr;
}
void signalHandler(int signum) {
std::cout << "\n\nInterrupt signal (" << signum << ") received.\n";
if (App::srv) {
App::srv->stop();
delete App::srv;
}
exit(signum);
}
int main(int argc, char *argv[])
{
std::signal(SIGINT, signalHandler);
App::srv = new httplib::Server();
App::srv->Get("/", [](const httplib::Request &, httplib::Response &res) {
noolitelib::Noolite adapter;
if (adapter.sendCommand(0, noolitelib::Switch)) {
res.set_content("{\"Result\":\"Successful\"}", "application/json");
} else {
res.set_content("{\"Result\":\"Failed\"}", "application/json");
}
});
auto host = App::DefaultHost;
auto port = App::DefaultPort;
if (argc > 1) {
host = argv[1];
}
if (argc > 2) {
port = atoi(argv[2]);
}
App::srv->listen(host, port);
return 0;
}