#ifndef __SETTINGS_H__ #define __SETTINGS_H__ #include "ApplicationSettings.h" #include "Singleton.h" #include #include #include #include "matches.hpp" class HttpSession; class SystemUsage; class IoContext; class SignalServer; namespace Nng { namespace Asio { class Socket; } } // namespace Nng class ApplicationPrivate; class Application : public ApplicationSettings, public std::enable_shared_from_this { public: using Pointer = std::shared_ptr; using Request = boost::beast::http::request; using RequestHandler = std::function; BUILD_SETTING(std::string, Server, "0.0.0.0"); BUILD_SETTING(uint16_t, Port, 8081); BUILD_SETTING(uint16_t, WtPort, 8082); BUILD_SETTING(uint32_t, Threads, std::thread::hardware_concurrency()); BUILD_SETTING(std::string, ApplicationRoot, "."); // 内部配置文件,不应被外部访问 BUILD_SETTING(std::string, DocumentRoot, "."); // 外部可访问的公共文件 BUILD_SETTING(std::string, HomeAssistantAccessToken, ""); BUILD_SETTING(std::string, MeiliSearchApiKey, ""); BUILD_SETTING(std::string, MeiliSearchConfig, ""); INITIALIZE_FIELDS(Server, Port, Threads, ApplicationRoot, DocumentRoot); Application(const std::string &path); ~Application(); boost::asio::io_context &ioContext(); int exec(); void startAcceptHttpConnections(const std::string &address, uint16_t port); void insertUrl(std::string_view url, RequestHandler &&handler); static void requetExit(); protected: void alarmTask(); void startAcceptRequest(); void asyncAcceptHttpConnections(); private: ApplicationPrivate *m_d = nullptr; int m_status = 0; std::shared_ptr m_ioContext; std::shared_ptr m_timer; std::shared_ptr m_systemUsage; std::shared_ptr m_replyer; std::shared_ptr m_signalServer; }; #endif // __SETTINGS_H__