diff options
author | rtk0c <[email protected]> | 2022-06-27 00:13:08 +0000 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-27 00:13:08 +0000 |
commit | 8a23aa89a58d3a90d5851b449b5552e1fcdcaded (patch) | |
tree | 86a527705eafe1ba36d6d5744afeddad196c0eeb /server-v1/source/EpistmoolServer/Session.hpp | |
parent | 9ad9af9f2596b91e1dd65e71543f75b0644e8283 (diff) |
(From git) Initial server setup
git-svn-id: file:///home/arch/svn/epistmool/trunk@4 71f44415-077c-4ad7-a976-72ddbf76608f
Diffstat (limited to 'server-v1/source/EpistmoolServer/Session.hpp')
-rw-r--r-- | server-v1/source/EpistmoolServer/Session.hpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/server-v1/source/EpistmoolServer/Session.hpp b/server-v1/source/EpistmoolServer/Session.hpp new file mode 100644 index 0000000..931c428 --- /dev/null +++ b/server-v1/source/EpistmoolServer/Session.hpp @@ -0,0 +1,59 @@ +#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; +}; + +class Session +{ + friend class SessionManager; + +private: + std::vector<ConnectionId> mConnections; + SessionId mSessionId; + +public: + 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 |