SNode.C
Loading...
Searching...
No Matches
web::websocket::server::GroupsManager Class Reference

#include <GroupsManager.h>

Collaboration diagram for web::websocket::server::GroupsManager:

Public Member Functions

 GroupsManager ()=default
 
 GroupsManager (const GroupsManager &)=delete
 
GroupsManageroperator= (const GroupsManager &)=delete
 
void subscribe (SubProtocol *subProtocol, std::string group="")
 
void unsubscribe (SubProtocol *subProtocol)
 
void sendBroadcast (const std::string &group, const char *message, std::size_t messageLength, const SubProtocol *excludedClient)
 
void sendBroadcast (const std::string &group, const std::string &message, const SubProtocol *excludedClient)
 
void sendBroadcastStart (const std::string &group, const char *message, std::size_t messageLength, const SubProtocol *excludedClient)
 
void sendBroadcastStart (const std::string &group, const std::string &message, const SubProtocol *excludedClient)
 
void sendBroadcastFrame (const std::string &group, const char *message, std::size_t messageLength, const SubProtocol *excludedClient)
 
void sendBroadcastFrame (const std::string &group, const std::string &message, const SubProtocol *excludedClient)
 
void sendBroadcastEnd (const std::string &group, const char *message, std::size_t messageLength, const SubProtocol *excludedClient)
 
void sendBroadcastEnd (const std::string &group, const std::string &message, const SubProtocol *excludedClient)
 
void forEachClient (const std::string &group, const std::function< void(const SubProtocol *)> &sendToClient, const SubProtocol *excludedClient)
 

Static Public Member Functions

static GroupsManagerinstance ()
 

Static Public Attributes

static GroupsManagergroupsManager = nullptr
 

Private Member Functions

 ~GroupsManager ()
 

Private Attributes

std::map< std::string, std::set< SubProtocol * > > groups
 

Detailed Description

Definition at line 39 of file GroupsManager.h.

Constructor & Destructor Documentation

◆ GroupsManager() [1/2]

web::websocket::server::GroupsManager::GroupsManager ( )
default

Referenced by instance().

Here is the caller graph for this function:

◆ GroupsManager() [2/2]

web::websocket::server::GroupsManager::GroupsManager ( const GroupsManager & )
delete

◆ ~GroupsManager()

web::websocket::server::GroupsManager::~GroupsManager ( )
private

Definition at line 32 of file GroupsManager.cpp.

32 {
34 }
static GroupsManager * groupsManager

References groupsManager.

Member Function Documentation

◆ forEachClient()

void web::websocket::server::GroupsManager::forEachClient ( const std::string & group,
const std::function< void(const SubProtocol *)> & sendToClient,
const SubProtocol * excludedClient )

Definition at line 145 of file GroupsManager.cpp.

147 {
148 if (groups.contains(group)) {
149 for (const SubProtocol* client : groups[group]) {
150 if (client != excludedClient) {
151 sendToClient(client);
152 }
153 }
154 }
155 }
std::map< std::string, std::set< SubProtocol * > > groups

◆ instance()

GroupsManager * web::websocket::server::GroupsManager::instance ( )
static

Definition at line 36 of file GroupsManager.cpp.

References GroupsManager(), and groupsManager.

Here is the call graph for this function:

◆ operator=()

GroupsManager & web::websocket::server::GroupsManager::operator= ( const GroupsManager & )
delete

◆ sendBroadcast() [1/2]

void web::websocket::server::GroupsManager::sendBroadcast ( const std::string & group,
const char * message,
std::size_t messageLength,
const SubProtocol * excludedClient )

Definition at line 71 of file GroupsManager.cpp.

74 {
75 if (groups.contains(group)) {
76 for (const SubProtocol* client : groups[group]) {
77 if (client != excludedClient) {
78 client->sendMessage(message, messageLength);
79 }
80 }
81 }
82 }

◆ sendBroadcast() [2/2]

void web::websocket::server::GroupsManager::sendBroadcast ( const std::string & group,
const std::string & message,
const SubProtocol * excludedClient )

Definition at line 84 of file GroupsManager.cpp.

84 {
85 if (groups.contains(group)) {
86 for (const SubProtocol* client : groups[group]) {
87 if (client != excludedClient) {
88 client->sendMessage(message);
89 }
90 }
91 }
92 }

◆ sendBroadcastEnd() [1/2]

void web::websocket::server::GroupsManager::sendBroadcastEnd ( const std::string & group,
const char * message,
std::size_t messageLength,
const SubProtocol * excludedClient )

Definition at line 128 of file GroupsManager.cpp.

131 {
132 if (groups.contains(group)) {
133 for (const SubProtocol* client : groups[group]) {
134 if (client != excludedClient) {
135 client->sendMessageEnd(message, messageLength);
136 }
137 }
138 }
139 }

◆ sendBroadcastEnd() [2/2]

void web::websocket::server::GroupsManager::sendBroadcastEnd ( const std::string & group,
const std::string & message,
const SubProtocol * excludedClient )

Definition at line 141 of file GroupsManager.cpp.

141 {
142 sendBroadcastEnd(group, message.data(), message.length(), excludedClient);
143 }
void sendBroadcastEnd(const std::string &group, const char *message, std::size_t messageLength, const SubProtocol *excludedClient)

◆ sendBroadcastFrame() [1/2]

void web::websocket::server::GroupsManager::sendBroadcastFrame ( const std::string & group,
const char * message,
std::size_t messageLength,
const SubProtocol * excludedClient )

Definition at line 111 of file GroupsManager.cpp.

114 {
115 if (groups.contains(group)) {
116 for (const SubProtocol* client : groups[group]) {
117 if (client != excludedClient) {
118 client->sendMessageFrame(message, messageLength);
119 }
120 }
121 }
122 }

◆ sendBroadcastFrame() [2/2]

void web::websocket::server::GroupsManager::sendBroadcastFrame ( const std::string & group,
const std::string & message,
const SubProtocol * excludedClient )

Definition at line 124 of file GroupsManager.cpp.

124 {
125 sendBroadcastFrame(group, message.data(), message.length(), excludedClient);
126 }
void sendBroadcastFrame(const std::string &group, const char *message, std::size_t messageLength, const SubProtocol *excludedClient)

◆ sendBroadcastStart() [1/2]

void web::websocket::server::GroupsManager::sendBroadcastStart ( const std::string & group,
const char * message,
std::size_t messageLength,
const SubProtocol * excludedClient )

Definition at line 94 of file GroupsManager.cpp.

97 {
98 if (groups.contains(group)) {
99 for (const SubProtocol* client : groups[group]) {
100 if (client != excludedClient) {
101 client->sendMessageStart(message, messageLength);
102 }
103 }
104 }
105 }

◆ sendBroadcastStart() [2/2]

void web::websocket::server::GroupsManager::sendBroadcastStart ( const std::string & group,
const std::string & message,
const SubProtocol * excludedClient )

Definition at line 107 of file GroupsManager.cpp.

107 {
108 sendBroadcastStart(group, message.data(), message.length(), excludedClient);
109 }
void sendBroadcastStart(const std::string &group, const char *message, std::size_t messageLength, const SubProtocol *excludedClient)

◆ subscribe()

void web::websocket::server::GroupsManager::subscribe ( SubProtocol * subProtocol,
std::string group = "" )

Definition at line 40 of file GroupsManager.cpp.

40 {
41 if (group.empty()) {
42 group = subProtocol->getName();
43 }
44
45 if (subProtocol->group != group) {
46 const std::string newChannel = subProtocol->getName() + "/" + group;
47
48 groups[newChannel].insert(subProtocol);
49
50 if (!subProtocol->group.empty()) {
51 unsubscribe(subProtocol);
52 }
53
54 subProtocol->group = newChannel;
55 }
56 }
void unsubscribe(SubProtocol *subProtocol)

References web::websocket::server::SubProtocol::group, and unsubscribe().

Here is the call graph for this function:

◆ unsubscribe()

void web::websocket::server::GroupsManager::unsubscribe ( SubProtocol * subProtocol)

Definition at line 58 of file GroupsManager.cpp.

58 {
59 if (groups.contains(subProtocol->group)) {
60 groups[subProtocol->group].erase(subProtocol);
61
62 if (groups[subProtocol->group].empty()) {
63 groups.erase(subProtocol->group);
64 if (groups.empty()) {
65 delete this;
66 }
67 }
68 }
69 }

Referenced by subscribe().

Here is the caller graph for this function:

Member Data Documentation

◆ groups

std::map<std::string, std::set<SubProtocol*> > web::websocket::server::GroupsManager::groups
private

Definition at line 76 of file GroupsManager.h.

◆ groupsManager

GroupsManager * web::websocket::server::GroupsManager::groupsManager = nullptr
static

Definition at line 73 of file GroupsManager.h.

Referenced by instance(), and ~GroupsManager().


The documentation for this class was generated from the following files: