diff options
author | Aaron Seigo <aseigo@kde.org> | 2014-12-06 02:33:51 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2014-12-06 02:33:51 +0100 |
commit | 5f40ace47be289c74ad95948c75ed86676158639 (patch) | |
tree | b3c50012da8c7404398050a17724342866a9e83e /synchronizer/listener.h | |
parent | 6b8994edba4fcc0663838b90f66fe2ad0f9e134a (diff) | |
download | sink-5f40ace47be289c74ad95948c75ed86676158639.tar.gz sink-5f40ace47be289c74ad95948c75ed86676158639.zip |
resource -> synchronizer
the resource will be the plugin that interacts with the source and store
Diffstat (limited to 'synchronizer/listener.h')
-rw-r--r-- | synchronizer/listener.h | 63 |
1 files changed, 63 insertions, 0 deletions
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 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <QLocalServer> | ||
4 | #include <QLocalSocket> | ||
5 | #include <QList> | ||
6 | #include <QObject> | ||
7 | |||
8 | #include <flatbuffers/flatbuffers.h> | ||
9 | |||
10 | class Client | ||
11 | { | ||
12 | public: | ||
13 | Client() | ||
14 | : socket(nullptr), | ||
15 | hasSentCommand(false) | ||
16 | { | ||
17 | } | ||
18 | |||
19 | Client(const QString &n, QLocalSocket *s) | ||
20 | : name(n), | ||
21 | socket(s), | ||
22 | hasSentCommand(false) | ||
23 | { | ||
24 | } | ||
25 | |||
26 | QString name; | ||
27 | QLocalSocket *socket; | ||
28 | QByteArray commandBuffer; | ||
29 | bool hasSentCommand; | ||
30 | }; | ||
31 | |||
32 | class Listener : public QObject | ||
33 | { | ||
34 | Q_OBJECT | ||
35 | |||
36 | public: | ||
37 | Listener(const QString &resourceName, QObject *parent = 0); | ||
38 | ~Listener(); | ||
39 | |||
40 | void setRevision(unsigned long long revision); | ||
41 | unsigned long long revision() const; | ||
42 | |||
43 | Q_SIGNALS: | ||
44 | void noClients(); | ||
45 | |||
46 | public Q_SLOTS: | ||
47 | void closeAllConnections(); | ||
48 | |||
49 | private Q_SLOTS: | ||
50 | void acceptConnection(); | ||
51 | void clientDropped(); | ||
52 | void checkConnections(); | ||
53 | void readFromSocket(); | ||
54 | |||
55 | private: | ||
56 | bool processClientBuffer(Client &client); | ||
57 | void sendCurrentRevision(Client &client); | ||
58 | void updateClientsWithRevision(); | ||
59 | QLocalServer *m_server; | ||
60 | QVector<Client> m_connections; | ||
61 | unsigned long long m_revision; | ||
62 | flatbuffers::FlatBufferBuilder m_fbb; | ||
63 | }; | ||