summaryrefslogtreecommitdiffstats
path: root/common/listener.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-28 20:49:08 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-28 20:49:08 +0200
commitdd86c15b48f33c120c510327569fb1cc3ffa3d45 (patch)
tree22db98990fbfe189ff40f34befa58ffb08287d9a /common/listener.h
parente22776a57bd12621358ad7cd98dac3261f2a70db (diff)
downloadsink-dd86c15b48f33c120c510327569fb1cc3ffa3d45.tar.gz
sink-dd86c15b48f33c120c510327569fb1cc3ffa3d45.zip
Moved listener to common
So we can use it in tests as well.
Diffstat (limited to 'common/listener.h')
-rw-r--r--common/listener.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/common/listener.h b/common/listener.h
new file mode 100644
index 0000000..560f052
--- /dev/null
+++ b/common/listener.h
@@ -0,0 +1,101 @@
1/*
2 * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#pragma once
21
22#include <QLocalServer>
23#include <QLocalSocket>
24#include <QObject>
25
26#include <flatbuffers/flatbuffers.h>
27
28#include "common/pipeline.h"
29
30namespace Akonadi2
31{
32 class Resource;
33}
34
35class QTimer;
36
37class Client
38{
39public:
40 Client()
41 : socket(nullptr)
42 {
43 }
44
45 Client(const QString &n, QLocalSocket *s)
46 : name(n),
47 socket(s)
48 {
49 }
50
51 QString name;
52 QPointer<QLocalSocket> socket;
53 QByteArray commandBuffer;
54};
55
56class QLockFile;
57
58class Listener : public QObject
59{
60 Q_OBJECT
61
62public:
63 Listener(const QByteArray &resourceName, QObject *parent = 0);
64 ~Listener();
65
66Q_SIGNALS:
67 void noClients();
68
69public Q_SLOTS:
70 void closeAllConnections();
71
72private Q_SLOTS:
73 void acceptConnection();
74 void clientDropped();
75 void checkConnections();
76 void onDataAvailable();
77 void processClientBuffers();
78 void refreshRevision();
79 void quit();
80
81private:
82 void processCommand(int commandId, uint messageId, const QByteArray &commandBuffer, Client &client, const std::function<void()> &callback);
83 bool processClientBuffer(Client &client);
84 void sendCurrentRevision(Client &client);
85 void sendCommandCompleted(QLocalSocket *socket, uint messageId);
86 void updateClientsWithRevision();
87 void loadResource();
88 void readFromSocket(QLocalSocket *socket);
89
90 QLocalServer *m_server;
91 QVector<Client> m_connections;
92 flatbuffers::FlatBufferBuilder m_fbb;
93 const QByteArray m_resourceName;
94 const QByteArray m_resourceInstanceIdentifier;
95 Akonadi2::Resource *m_resource;
96 Akonadi2::Pipeline *m_pipeline;
97 QTimer *m_clientBufferProcessesTimer;
98 QTimer *m_checkConnectionsTimer;
99 int m_messageId;
100 QLockFile *m_lockfile;
101};