layout source from main
This commit is contained in:
14
src/app/app_state.hpp
Normal file
14
src/app/app_state.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace lm {
|
||||
|
||||
struct AppState
|
||||
{
|
||||
std::filesystem::path data_path;
|
||||
nlohmann::json state;
|
||||
};
|
||||
|
||||
} // namespace lm
|
||||
40
src/app/lidar_manager_app.cpp
Normal file
40
src/app/lidar_manager_app.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "app/lidar_manager_app.hpp"
|
||||
|
||||
#include "server/api_server.hpp"
|
||||
#include "server/static_file_server.hpp"
|
||||
#include "storage/state_repository.hpp"
|
||||
|
||||
#include <httplib.h>
|
||||
#include <cstdio>
|
||||
|
||||
namespace lm {
|
||||
|
||||
LidarManagerApp::LidarManagerApp(int port,
|
||||
std::filesystem::path www_root,
|
||||
std::filesystem::path data_path)
|
||||
: port_(port), www_root_(std::move(www_root)), data_path_(std::move(data_path))
|
||||
{
|
||||
}
|
||||
|
||||
int LidarManagerApp::run()
|
||||
{
|
||||
StateRepository repo(data_path_);
|
||||
repo.load();
|
||||
|
||||
httplib::Server svr;
|
||||
ApiServer api(repo);
|
||||
api.registerRoutes(svr);
|
||||
StaticFileServer::mount(svr, www_root_);
|
||||
|
||||
std::fprintf(stderr,
|
||||
"lidar_manager_web listening on http://0.0.0.0:%d (www=%s, state=%s, models=%s)\n",
|
||||
port_,
|
||||
www_root_.string().c_str(),
|
||||
data_path_.string().c_str(),
|
||||
(data_path_.parent_path() / "models").string().c_str());
|
||||
|
||||
svr.listen("0.0.0.0", port_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace lm
|
||||
20
src/app/lidar_manager_app.hpp
Normal file
20
src/app/lidar_manager_app.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
namespace lm {
|
||||
|
||||
class LidarManagerApp
|
||||
{
|
||||
public:
|
||||
LidarManagerApp(int port, std::filesystem::path www_root, std::filesystem::path data_path);
|
||||
|
||||
int run();
|
||||
|
||||
private:
|
||||
int port_;
|
||||
std::filesystem::path www_root_;
|
||||
std::filesystem::path data_path_;
|
||||
};
|
||||
|
||||
} // namespace lm
|
||||
Reference in New Issue
Block a user