web_server 初步改
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "Graph_Session.hpp"
|
||||
#include "Plot.hpp"
|
||||
#include <drogon/WebSocketController.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
@@ -7,31 +7,27 @@
|
||||
namespace aethera::web {
|
||||
class Graph_WebSocket final : public std::enable_shared_from_this<Graph_WebSocket> {
|
||||
public:
|
||||
Graph_WebSocket(drogon::WebSocketConnectionPtr connection, std::shared_ptr<Graph_Session> session);
|
||||
Graph_WebSocket(drogon::WebSocketConnectionPtr connection, std::shared_ptr<Plot> plot);
|
||||
~Graph_WebSocket();
|
||||
Graph_WebSocket(const Graph_WebSocket&) = delete;
|
||||
Graph_WebSocket& operator=(const Graph_WebSocket&) = delete;
|
||||
using Callback = std::function<void(std::string_view)>;
|
||||
void start();
|
||||
void receive(std::string_view message);
|
||||
void close();
|
||||
void register_callback(std::string key, Callback callback);
|
||||
void unregister_callback(std::string_view key);
|
||||
void send(std::string_view key, std::string_view frame);
|
||||
private:
|
||||
struct Private;
|
||||
std::unique_ptr<Private> d; /* Drogon 连接与图会话绑定。 */
|
||||
};
|
||||
class Graph_WebSocket_Controller final : public drogon::WebSocketController<Graph_WebSocket_Controller, false> {
|
||||
public:
|
||||
explicit Graph_WebSocket_Controller(std::shared_ptr<Graph_Registry> registry);
|
||||
explicit Graph_WebSocket_Controller(std::shared_ptr<Plot_Registry> registry);
|
||||
void handleNewMessage(const drogon::WebSocketConnectionPtr& connection, std::string&& message, const drogon::WebSocketMessageType& type) override;
|
||||
void handleNewConnection(const drogon::HttpRequestPtr& request, const drogon::WebSocketConnectionPtr& connection) override;
|
||||
void handleConnectionClosed(const drogon::WebSocketConnectionPtr& connection) override;
|
||||
WS_PATH_LIST_BEGIN
|
||||
WS_ADD_PATH_VIA_REGEX("^/ws/graphs/[^/]+$");
|
||||
WS_ADD_PATH_VIA_REGEX("^/ws/plot/[^/]+$");
|
||||
WS_PATH_LIST_END
|
||||
private:
|
||||
std::shared_ptr<Graph_Registry> registry; /* 所有图 WebSocket 共用的会话注册表。 */
|
||||
std::shared_ptr<Plot_Registry> registry; /* 所有 WebSocket 共用的 Plot 注册表。 */
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user