diff options
Diffstat (limited to 'server-v1/source/EpistmoolServer/Connection.hpp')
-rw-r--r-- | server-v1/source/EpistmoolServer/Connection.hpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/server-v1/source/EpistmoolServer/Connection.hpp b/server-v1/source/EpistmoolServer/Connection.hpp new file mode 100644 index 0000000..78e34db --- /dev/null +++ b/server-v1/source/EpistmoolServer/Connection.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include <QObject> +#include <vector> + +class QLocalServer; +class QJsonDocument; + +namespace Epistmool::Server { + +struct ConnectionId +{ + int index; + int generation; + + static ConnectionId createInvalid(); + bool isInvalid() const; + + bool operator==(const ConnectionId&) const = default; +}; + +uint qHash(const ConnectionId& id, uint seed = 0); + +class ConnectionManager : public QObject +{ + Q_OBJECT + class Private; + +private: + QLocalServer* mLocal = nullptr; + + struct Connection; + std::vector<Connection> mConnections; + +public: + explicit ConnectionManager(QObject* parent = nullptr); + ~ConnectionManager(); + + bool isLocalConnectionsEnabled() const; + void setLocalConnectionsEnabled(bool enabled); + + void replyMessage(ConnectionId id, const QJsonDocument& message); + +signals: + void connectionEstablished(Epistmool::Server::ConnectionId id); + void connectionDropped(Epistmool::Server::ConnectionId id); + void messageRecieved(const QJsonDocument& message, Epistmool::Server::ConnectionId id); +}; + +} // namespace Epistmool::Server |