This commit is contained in:
2024-08-29 15:00:27 +02:00
parent 6c6a60e980
commit 21a2c16607
31 changed files with 457 additions and 409 deletions
+19 -11
View File
@@ -16,17 +16,22 @@ using websocketpp::lib::placeholders::_2;
* on_message queue send to all channels
*/
enum action_type {
enum action_type
{
SUBSCRIBE,
UNSUBSCRIBE,
MESSAGE,
BROADCAST
};
struct action {
action(action_type t, websocketpp::connection_hdl h) : type(t), hdl(h) {}
action(action_type t, websocketpp::connection_hdl h, Server::message_ptr m)
: type(t), hdl(h), msg(m) {}
struct action
{
action(action_type t, websocketpp::connection_hdl h) : type(t), hdl(h)
{
}
action(action_type t, websocketpp::connection_hdl h, Server::message_ptr m) : type(t), hdl(h), msg(m)
{
}
action_type type;
websocketpp::connection_hdl hdl;
@@ -35,22 +40,25 @@ struct action {
class Websocket
{
public:
Websocket(uint16_t port, std::ostream* out, std::ostream* err, std::function<std::string(std::string)> on_message, std::function<std::string()> on_update);
public:
Websocket(uint16_t port, std::ostream *out, std::ostream *err, std::function<std::string(std::string)> on_message,
std::function<std::string()> on_update);
void run();
void stop();
void process_messages();
void process_broadcast();
private:
private:
void on_open(websocketpp::connection_hdl hdl);
void on_close(websocketpp::connection_hdl hdl);
void on_message(websocketpp::connection_hdl hdl, Server::message_ptr msg);
private:
private:
std::function<std::string(std::string)> m_on_message;
std::function<std::string()> m_on_update;
Server m_server;
Server m_server;
uint16_t m_port;
typedef std::set<websocketpp::connection_hdl,std::owner_less<websocketpp::connection_hdl>> con_list;
typedef std::set<websocketpp::connection_hdl, std::owner_less<websocketpp::connection_hdl>> con_list;
con_list m_connections;
std::queue<action> m_actions;