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 61 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 54 of file GroupsManager.cpp.

54 {
56 }
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 167 of file GroupsManager.cpp.

169 {
170 if (groups.contains(group)) {
171 for (const SubProtocol* client : groups[group]) {
172 if (client != excludedClient) {
173 sendToClient(client);
174 }
175 }
176 }
177 }
std::map< std::string, std::set< SubProtocol * > > groups

References groups.

Referenced by web::websocket::server::SubProtocol::forEachClient().

Here is the caller graph for this function:

◆ instance()

◆ 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 93 of file GroupsManager.cpp.

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

References groups, and web::websocket::SubProtocol< SocketContextUpgradeT >::sendMessage().

Referenced by web::websocket::server::SubProtocol::sendBroadcast().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendBroadcast() [2/2]

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

Definition at line 106 of file GroupsManager.cpp.

106 {
107 if (groups.contains(group)) {
108 for (const SubProtocol* client : groups[group]) {
109 if (client != excludedClient) {
110 client->sendMessage(message);
111 }
112 }
113 }
114 }

References groups, and web::websocket::SubProtocol< SocketContextUpgradeT >::sendMessage().

Referenced by web::websocket::server::SubProtocol::sendBroadcast().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 150 of file GroupsManager.cpp.

153 {
154 if (groups.contains(group)) {
155 for (const SubProtocol* client : groups[group]) {
156 if (client != excludedClient) {
157 client->sendMessageEnd(message, messageLength);
158 }
159 }
160 }
161 }

References groups, and web::websocket::SubProtocol< SocketContextUpgradeT >::sendMessageEnd().

Referenced by web::websocket::server::SubProtocol::sendBroadcastEnd(), sendBroadcastEnd(), and web::websocket::server::SubProtocol::sendBroadcastEnd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendBroadcastEnd() [2/2]

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

Definition at line 163 of file GroupsManager.cpp.

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

References sendBroadcastEnd().

Here is the call graph for this function:

◆ 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 133 of file GroupsManager.cpp.

136 {
137 if (groups.contains(group)) {
138 for (const SubProtocol* client : groups[group]) {
139 if (client != excludedClient) {
140 client->sendMessageFrame(message, messageLength);
141 }
142 }
143 }
144 }

References groups, and web::websocket::SubProtocol< SocketContextUpgradeT >::sendMessageFrame().

Referenced by web::websocket::server::SubProtocol::sendBroadcastFrame(), sendBroadcastFrame(), and web::websocket::server::SubProtocol::sendBroadcastFrame().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendBroadcastFrame() [2/2]

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

Definition at line 146 of file GroupsManager.cpp.

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

References sendBroadcastFrame().

Here is the call graph for this function:

◆ 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 116 of file GroupsManager.cpp.

119 {
120 if (groups.contains(group)) {
121 for (const SubProtocol* client : groups[group]) {
122 if (client != excludedClient) {
123 client->sendMessageStart(message, messageLength);
124 }
125 }
126 }
127 }

References groups, and web::websocket::SubProtocol< SocketContextUpgradeT >::sendMessageStart().

Referenced by web::websocket::server::SubProtocol::sendBroadcastStart(), and sendBroadcastStart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendBroadcastStart() [2/2]

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

Definition at line 129 of file GroupsManager.cpp.

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

References sendBroadcastStart().

Referenced by web::websocket::server::SubProtocol::sendBroadcastStart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subscribe()

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

Definition at line 62 of file GroupsManager.cpp.

62 {
63 if (group.empty()) {
64 group = subProtocol->getName();
65 }
66
67 if (subProtocol->group != group) {
68 const std::string newChannel = subProtocol->getName() + "/" + group;
69
70 groups[newChannel].insert(subProtocol);
71
72 if (!subProtocol->group.empty()) {
73 unsubscribe(subProtocol);
74 }
75
76 subProtocol->group = newChannel;
77 }
78 }
void unsubscribe(SubProtocol *subProtocol)

References web::websocket::SubProtocol< SocketContextUpgradeT >::getName(), web::websocket::server::SubProtocol::group, groups, and unsubscribe().

Referenced by web::websocket::server::SubProtocol::SubProtocol(), and web::websocket::server::SubProtocol::subscribe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unsubscribe()

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

Definition at line 80 of file GroupsManager.cpp.

80 {
81 if (groups.contains(subProtocol->group)) {
82 groups[subProtocol->group].erase(subProtocol);
83
84 if (groups[subProtocol->group].empty()) {
85 groups.erase(subProtocol->group);
86 if (groups.empty()) {
87 delete this;
88 }
89 }
90 }
91 }

References web::websocket::server::SubProtocol::group, and groups.

Referenced by subscribe(), and web::websocket::server::SubProtocol::~SubProtocol().

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

◆ groupsManager

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

Definition at line 95 of file GroupsManager.h.

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


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