51 lines
1.8 KiB
C++
51 lines
1.8 KiB
C++
#ifndef __SETTINGS_H__
|
|
#define __SETTINGS_H__
|
|
|
|
#include "ApplicationSettings.h"
|
|
#include "Singleton.h"
|
|
#include "router.hpp"
|
|
#include <boost/asio/system_timer.hpp>
|
|
#include <boost/beast/http/string_body.hpp>
|
|
#include <thread>
|
|
|
|
class HttpSession;
|
|
class ChatRoom;
|
|
class SystemUsage;
|
|
class IoContext;
|
|
|
|
class Application : public ApplicationSettings<Application>, public std::enable_shared_from_this<Application> {
|
|
public:
|
|
using Pointer = std::shared_ptr<Application>;
|
|
using Request = boost::beast::http::request<boost::beast::http::string_body>;
|
|
using RequestHandler = std::function<void(HttpSession &, const Request &, const boost::urls::matches &)>;
|
|
|
|
BUILD_SETTING(std::string, Server, "0.0.0.0");
|
|
BUILD_SETTING(uint16_t, Port, 8081);
|
|
BUILD_SETTING(uint32_t, Threads, std::thread::hardware_concurrency());
|
|
BUILD_SETTING(std::string, DocumentRoot, ".");
|
|
BUILD_SETTING(std::string, Sqlte3Path, "database.sqlite");
|
|
BUILD_SETTING(std::string, HomeAssistantAccessToken, "");
|
|
BUILD_SETTING(std::string, Live2dModelsRoot, "./live2d");
|
|
|
|
INITIALIZE_FIELDS(Server, Port, Threads, DocumentRoot);
|
|
Application(const std::string &path);
|
|
boost::asio::io_context &ioContext();
|
|
int exec();
|
|
|
|
const RequestHandler *find(boost::urls::segments_encoded_view path,
|
|
boost::urls::matches_base &matches) const noexcept;
|
|
void insertUrl(std::string_view url, RequestHandler &&handler);
|
|
|
|
protected:
|
|
void alarmTask();
|
|
|
|
private:
|
|
int m_status = 0;
|
|
std::shared_ptr<IoContext> m_ioContext;
|
|
std::shared_ptr<boost::urls::router<RequestHandler>> m_router;
|
|
std::shared_ptr<boost::asio::system_timer> m_timer;
|
|
std::shared_ptr<ChatRoom> m_charRoom;
|
|
std::shared_ptr<SystemUsage> m_systemUsage;
|
|
};
|
|
|
|
#endif // __SETTINGS_H__
|