summaryrefslogtreecommitdiffstats
path: root/common/commandprocessor.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-28 16:56:28 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-11-28 16:56:28 +0100
commit885f185f55249a2e97e9c7c238f89a5d0d99d1df (patch)
tree5c597d61d1d2e3d9044443539873c50fea8d9a19 /common/commandprocessor.h
parent9fe1d50d7ace50f1f7efc66412dff006f20a2062 (diff)
downloadsink-885f185f55249a2e97e9c7c238f89a5d0d99d1df.tar.gz
sink-885f185f55249a2e97e9c7c238f89a5d0d99d1df.zip
Move the commandprocessor to a separate file.
Diffstat (limited to 'common/commandprocessor.h')
-rw-r--r--common/commandprocessor.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/common/commandprocessor.h b/common/commandprocessor.h
new file mode 100644
index 0000000..51d845e
--- /dev/null
+++ b/common/commandprocessor.h
@@ -0,0 +1,79 @@
1/*
2 * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) version 3, or any
8 * later version accepted by the membership of KDE e.V. (or its
9 * successor approved by the membership of KDE e.V.), which shall
10 * act as a proxy defined in Section 6 of version 3 of the license.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20#pragma once
21
22#include "sink_export.h"
23
24#include <QObject>
25#include <Async/Async>
26#include <functional>
27#include "log.h"
28
29class MessageQueue;
30
31namespace Sink {
32 class Pipeline;
33 class QueuedCommand;
34
35/**
36 * Drives the pipeline using the output from all command queues
37 */
38class CommandProcessor : public QObject
39{
40 Q_OBJECT
41 typedef std::function<KAsync::Job<void>(void const *, size_t)> InspectionFunction;
42 typedef std::function<KAsync::Job<void>(void const *, size_t)> FlushFunction;
43 SINK_DEBUG_AREA("commandprocessor")
44
45public:
46 CommandProcessor(Sink::Pipeline *pipeline, QList<MessageQueue *> commandQueues);
47
48 void setOldestUsedRevision(qint64 revision);
49
50 void setInspectionCommand(const InspectionFunction &f);
51
52 void setFlushCommand(const FlushFunction &f);
53
54signals:
55 void error(int errorCode, const QString &errorMessage);
56
57private:
58 bool messagesToProcessAvailable();
59
60private slots:
61 void process();
62 KAsync::Job<qint64> processQueuedCommand(const Sink::QueuedCommand *queuedCommand);
63 KAsync::Job<qint64> processQueuedCommand(const QByteArray &data);
64 // Process all messages of this queue
65 KAsync::Job<void> processQueue(MessageQueue *queue);
66 KAsync::Job<void> processPipeline();
67
68private:
69 Sink::Pipeline *mPipeline;
70 // Ordered by priority
71 QList<MessageQueue *> mCommandQueues;
72 bool mProcessingLock;
73 // The lowest revision we no longer need
74 qint64 mLowerBoundRevision;
75 InspectionFunction mInspect;
76 FlushFunction mFlush;
77};
78
79};