diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-28 16:56:28 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-28 16:56:28 +0100 |
commit | 885f185f55249a2e97e9c7c238f89a5d0d99d1df (patch) | |
tree | 5c597d61d1d2e3d9044443539873c50fea8d9a19 /common/commandprocessor.h | |
parent | 9fe1d50d7ace50f1f7efc66412dff006f20a2062 (diff) | |
download | sink-885f185f55249a2e97e9c7c238f89a5d0d99d1df.tar.gz sink-885f185f55249a2e97e9c7c238f89a5d0d99d1df.zip |
Move the commandprocessor to a separate file.
Diffstat (limited to 'common/commandprocessor.h')
-rw-r--r-- | common/commandprocessor.h | 79 |
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 | |||
29 | class MessageQueue; | ||
30 | |||
31 | namespace Sink { | ||
32 | class Pipeline; | ||
33 | class QueuedCommand; | ||
34 | |||
35 | /** | ||
36 | * Drives the pipeline using the output from all command queues | ||
37 | */ | ||
38 | class 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 | |||
45 | public: | ||
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 | |||
54 | signals: | ||
55 | void error(int errorCode, const QString &errorMessage); | ||
56 | |||
57 | private: | ||
58 | bool messagesToProcessAvailable(); | ||
59 | |||
60 | private 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 | |||
68 | private: | ||
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 | }; | ||