SNode.C
Loading...
Searching...
No Matches
SubProtocol.cpp
Go to the documentation of this file.
1
/*
2
* SNode.C - a slim toolkit for network communication
3
* Copyright (C) Volker Christian <me@vchrist.at>
4
* 2020, 2021, 2022, 2023, 2024, 2025
5
*
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published
8
* by the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#
include
"web/websocket/server/SubProtocol.h"
21
22
#
include
"web/websocket/SubProtocol.hpp"
23
#
include
"web/websocket/server/GroupsManager.h"
24
25
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
26
27
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
28
29
namespace
web::websocket::server {
30
31
SubProtocol::SubProtocol(SubProtocolContext* subProtocolContext,
const
std::string& name,
int
pingInterval,
int
maxFlyingPings)
32
: Super(subProtocolContext, name, pingInterval, maxFlyingPings) {
33
GroupsManager::instance()->subscribe(
this
);
34
}
35
36
SubProtocol::~SubProtocol() {
37
GroupsManager::instance()->unsubscribe(
this
);
38
}
39
40
void
SubProtocol::subscribe(
const
std::string& group) {
41
GroupsManager::instance()->subscribe(
this
, group);
42
// subscibe(group, this);
43
// unsubscribe(this->group, this);
44
// this->group = group;
45
}
46
47
void
SubProtocol::sendBroadcast(
const
std::string& message,
bool
excludeSelf) {
48
GroupsManager::instance()->sendBroadcast(group, message, excludeSelf ?
this
:
nullptr
);
49
}
50
51
void
SubProtocol::sendBroadcast(
const
char
* message, std::size_t messageLength,
bool
excludeSelf) {
52
GroupsManager::instance()->sendBroadcast(group, message, messageLength, excludeSelf ?
this
:
nullptr
);
53
}
54
55
void
SubProtocol::sendBroadcastStart(
const
char
* message, std::size_t messageLength,
bool
excludeSelf) {
56
GroupsManager::instance()->sendBroadcastStart(group, message, messageLength, excludeSelf ?
this
:
nullptr
);
57
}
58
59
void
SubProtocol::sendBroadcastStart(
const
std::string& message,
bool
excludeSelf) {
60
GroupsManager::instance()->sendBroadcastStart(group, message, excludeSelf ?
this
:
nullptr
);
61
}
62
63
void
SubProtocol::sendBroadcastFrame(
const
char
* message, std::size_t messageLength,
bool
excludeSelf) {
64
GroupsManager::instance()->sendBroadcastFrame(group, message, messageLength, excludeSelf ?
this
:
nullptr
);
65
}
66
67
void
SubProtocol::sendBroadcastFrame(
const
std::string& message,
bool
excludeSelf) {
68
GroupsManager::instance()->sendBroadcastFrame(group, message.data(), message.length(), excludeSelf ?
this
:
nullptr
);
69
}
70
71
void
SubProtocol::sendBroadcastEnd(
const
char
* message, std::size_t messageLength,
bool
excludeSelf) {
72
GroupsManager::instance()->sendBroadcastEnd(group, message, messageLength, excludeSelf ?
this
:
nullptr
);
73
}
74
75
void
SubProtocol::sendBroadcastEnd(
const
std::string& message,
bool
excludeSelf) {
76
GroupsManager::instance()->sendBroadcastEnd(group, message.data(), message.length(), excludeSelf ?
this
:
nullptr
);
77
}
78
79
void
SubProtocol::forEachClient(
const
std::function<
void
(
const
SubProtocol*)>& sendToClient,
bool
excludeSelf) {
80
GroupsManager::instance()->forEachClient(group, sendToClient, excludeSelf ?
this
:
nullptr
);
81
}
82
83
}
// namespace web::websocket::server
84
85
template
class
web::websocket::SubProtocol<web::websocket::server::SocketContextUpgrade>;
web
websocket
server
SubProtocol.cpp
Generated on Mon Feb 10 2025 20:22:09 for SNode.C by
1.11.0