blob: 7cce3d163b02636943032617d99686d826dc9668 (
plain)
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
56
57
58
59
60
|
#pragma once
#include "EpistmoolServer/Connection.hpp"
#include <QMultiHash>
#include <QObject>
#include <unordered_map>
#include <vector>
namespace Epistmool::Server {
struct SessionId {
int index;
static SessionId makeInvalid();
bool isInvalid() const;
bool operator==(const SessionId&) const = default;
};
class Session
{
friend class SessionManager;
private:
std::vector<ConnectionId> mConnections;
SessionId mSessionId;
public:
explicit Session(SessionId id);
SessionId getSessionId() const;
const std::vector<ConnectionId>& getConnections() const;
};
class SessionManager : public QObject
{
Q_OBJECT
friend class Session;
private:
// Use this intead of QHash for 1. pointer stability 2. Session is a move-only type
std::unordered_map<int, Session> mSessions;
QMultiHash<int, int> mConnection2SessionMap;
int mNextIndex;
public:
explicit SessionManager(QObject* parent = nullptr);
Session* findOrCreateSession(SessionId id);
Session* findSession(SessionId id);
void addConnection(SessionId id, ConnectionId connId);
public slots:
void dropConnection(Epistmool::Server::ConnectionId connId);
};
} // namespace Epistmool::Server
|