From 5f40ace47be289c74ad95948c75ed86676158639 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Sat, 6 Dec 2014 02:33:51 +0100 Subject: resource -> synchronizer the resource will be the plugin that interacts with the source and store --- synchronizer/listener.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 synchronizer/listener.h (limited to 'synchronizer/listener.h') diff --git a/synchronizer/listener.h b/synchronizer/listener.h new file mode 100644 index 0000000..dcc3818 --- /dev/null +++ b/synchronizer/listener.h @@ -0,0 +1,63 @@ +#pragma once + +#include +#include +#include +#include + +#include + +class Client +{ +public: + Client() + : socket(nullptr), + hasSentCommand(false) + { + } + + Client(const QString &n, QLocalSocket *s) + : name(n), + socket(s), + hasSentCommand(false) + { + } + + QString name; + QLocalSocket *socket; + QByteArray commandBuffer; + bool hasSentCommand; +}; + +class Listener : public QObject +{ + Q_OBJECT + +public: + Listener(const QString &resourceName, QObject *parent = 0); + ~Listener(); + + void setRevision(unsigned long long revision); + unsigned long long revision() const; + +Q_SIGNALS: + void noClients(); + +public Q_SLOTS: + void closeAllConnections(); + +private Q_SLOTS: + void acceptConnection(); + void clientDropped(); + void checkConnections(); + void readFromSocket(); + +private: + bool processClientBuffer(Client &client); + void sendCurrentRevision(Client &client); + void updateClientsWithRevision(); + QLocalServer *m_server; + QVector m_connections; + unsigned long long m_revision; + flatbuffers::FlatBufferBuilder m_fbb; +}; -- cgit v1.2.3