Initial commit
This commit is contained in:
75
.gitignore
vendored
Normal file
75
.gitignore
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
# This file is used to ignore files which are generated
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
*~
|
||||
*.autosave
|
||||
*.a
|
||||
*.core
|
||||
*.moc
|
||||
*.o
|
||||
*.obj
|
||||
*.orig
|
||||
*.rej
|
||||
*.so
|
||||
*.so.*
|
||||
*_pch.h.cpp
|
||||
*_resource.rc
|
||||
*.qm
|
||||
.#*
|
||||
*.*#
|
||||
core
|
||||
!core/
|
||||
tags
|
||||
.DS_Store
|
||||
.directory
|
||||
*.debug
|
||||
Makefile*
|
||||
*.prl
|
||||
*.app
|
||||
moc_*.cpp
|
||||
ui_*.h
|
||||
qrc_*.cpp
|
||||
Thumbs.db
|
||||
*.res
|
||||
*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
|
||||
# qtcreator generated files
|
||||
*.pro.user*
|
||||
CMakeLists.txt.user*
|
||||
|
||||
# xemacs temporary files
|
||||
*.flc
|
||||
|
||||
# Vim temporary files
|
||||
.*.swp
|
||||
|
||||
# Visual Studio generated files
|
||||
*.ib_pdb_index
|
||||
*.idb
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.sln
|
||||
*.suo
|
||||
*.vcproj
|
||||
*vcproj.*.*.user
|
||||
*.ncb
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.vcxproj
|
||||
*vcxproj.*
|
||||
|
||||
# MinGW generated files
|
||||
*.Debug
|
||||
*.Release
|
||||
|
||||
# Python byte code
|
||||
*.pyc
|
||||
|
||||
# Binaries
|
||||
# --------
|
||||
*.dll
|
||||
*.exe
|
||||
|
||||
build/
|
||||
35
CMakeLists.txt
Normal file
35
CMakeLists.txt
Normal file
@@ -0,0 +1,35 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
project(noolite-srv LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_executable(noolite-srv
|
||||
main.cpp
|
||||
)
|
||||
|
||||
include(FetchContent)
|
||||
# cpp-httplib
|
||||
FetchContent_Declare(
|
||||
httplib
|
||||
GIT_REPOSITORY https://gogs.dended.keenetic.pro/ded/cpp-httplib.git
|
||||
GIT_TAG master
|
||||
)
|
||||
FetchContent_MakeAvailable(httplib)
|
||||
|
||||
# noolite
|
||||
FetchContent_Declare(
|
||||
noolite
|
||||
GIT_REPOSITORY https://gogs.dended.keenetic.pro/ded/noolitelib.git
|
||||
GIT_TAG master
|
||||
)
|
||||
FetchContent_MakeAvailable(noolite)
|
||||
|
||||
target_link_libraries(noolite-srv httplib noolite)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS noolite-srv
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
17
Dockerfile
Normal file
17
Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM alpine:latest AS builder
|
||||
LABEL stage=builder
|
||||
|
||||
RUN apk add --no-cache git cmake clang ninja libusb-dev
|
||||
|
||||
WORKDIR /build
|
||||
COPY . .
|
||||
|
||||
RUN cmake CMakeLists.txt -DCMAKE_GENERATOR:STRING=Ninja -DCMAKE_BUILD_TYPE:STRING=MinSizeRel -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++-17 && cmake --build . --target all
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
run apk add --no-cache libstdc++ libusb
|
||||
|
||||
COPY --from=builder /build/noolite-srv /bin/noolite-srv
|
||||
|
||||
CMD ["/bin/noolite-srv"]
|
||||
53
main.cpp
Normal file
53
main.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user