-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSmallGroupServerDispatcher.cpp
More file actions
55 lines (48 loc) · 1.08 KB
/
Copy pathSmallGroupServerDispatcher.cpp
File metadata and controls
55 lines (48 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "SmallGroupServerDispatcher.hpp"
#include <iostream>
BEGIN_XE_NAMESPACE
SmallGroupServerDispatcher::SmallGroupServerDispatcher(
SmallGroupConnectionManager &manager,
std::weak_ptr<void> conn,
std::function<void(Blob, std::weak_ptr<void>)> sendFunc) :
_manager(manager),
_conn(conn),
_sendFunc(sendFunc)
{ }
JoinResult SmallGroupServerDispatcher::joinGroup(int groupId)
{
return _manager.joinGroup(_conn, groupId);
}
void SmallGroupServerDispatcher::broadcast(Blob blob)
{
auto connections = _manager.connectionsInGroup(_conn);
std::cout << "broadcast()\n";
if (connections != nullptr)
{
std::cout << "connections != nullptr\n";
for (auto conn : *connections)
{
std::cout << "sending\n";
_sendFunc(blob, conn);
}
}
}
void SmallGroupServerDispatcher::forward(Blob blob)
{
auto connections = _manager.connectionsInGroup(_conn);
if (connections != nullptr)
{
for (auto conn : *connections)
{
if (conn != _conn)
{
_sendFunc(blob, conn);
}
}
}
}
void SmallGroupServerDispatcher::reply(Blob blob)
{
_sendFunc(blob, _conn);
}
END_XE_NAMESPACE