#ifndef SHAREDSTATE_H #define SHAREDSTATE_H #include "TemplateMatchs.h" #include "UrlRouter.h" #include #include #include #include #include #include #include class HttpSession; class WebSocketSession; // Represents the shared server state class SharedState:public std::enable_shared_from_this { // This mutex synchronizes all access to sessions_ std::mutex mutex_; // Keep a list of all the connected clients std::unordered_set sessions_; public: using Request = boost::beast::http::request; using Handler = std::function; SharedState(boost::asio::io_context &ioContext,std::string doc_root); const Handler *find(boost::urls::segments_encoded_view path, TemplateMatchStorageBase &matches) const noexcept ; inline std::string_view docRoot() const noexcept { return m_docRoot; } std::string_view galleryRoot() const noexcept; inline std::string_view fileRoot() const { return m_fileRoot; } void setFileRoot(const std::string_view &root); std::string_view notebookRoot() const; void setNotebookRoot(const std::string_view &root); void join(WebSocketSession *session); void leave(WebSocketSession *session); /** * @brief Broadcast a message to all websocket client sessions */ void send(std::string message); private: boost::asio::io_context &m_ioContext; std::shared_ptr > m_router; std::string m_docRoot; std::string m_galleryRoot = "/root/photos"; std::string m_fileRoot; std::string m_notebookRoot; }; using SharedStatePtr = std::shared_ptr; #endif // SHAREDSTATE_H