File indexing completed on 2024-05-12 05:25:59

0001 /*
0002  * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) version 3, or any
0008  * later version accepted by the membership of KDE e.V. (or its
0009  * successor approved by the membership of KDE e.V.), which shall
0010  * act as a proxy defined in Section 6 of version 3 of the license.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0019  */
0020 #pragma once
0021 
0022 #include "sink_export.h"
0023 #include "resource.h"
0024 #include "resourcecontext.h"
0025 
0026 namespace Sink {
0027 class Pipeline;
0028 class Preprocessor;
0029 class Synchronizer;
0030 class Inspector;
0031 class CommandProcessor;
0032 
0033 /**
0034  * Generic Resource implementation.
0035  */
0036 class SINK_EXPORT GenericResource : public Resource
0037 {
0038     Q_OBJECT
0039 public:
0040     GenericResource(const Sink::ResourceContext &context, const QSharedPointer<Pipeline> &pipeline = QSharedPointer<Pipeline>());
0041     virtual ~GenericResource() Q_DECL_OVERRIDE;
0042 
0043     virtual void processCommand(int commandId, const QByteArray &data) Q_DECL_OVERRIDE;
0044     virtual void setLowerBoundRevision(qint64 revision) Q_DECL_OVERRIDE;
0045 
0046     int error() const;
0047 
0048     static void removeFromDisk(const QByteArray &instanceIdentifier);
0049     static qint64 diskUsage(const QByteArray &instanceIdentifier);
0050 
0051     virtual void setSecret(const QString &s) Q_DECL_OVERRIDE;
0052     virtual bool checkForUpgrade() Q_DECL_OVERRIDE;
0053 
0054     //TODO Remove this API, it's only used in tests
0055     KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query);
0056     //TODO Remove this API, it's only used in tests
0057     KAsync::Job<void> processAllMessages();
0058 
0059 private slots:
0060     void updateLowerBoundRevision();
0061 
0062 protected:
0063     void setupPreprocessors(const QByteArray &type, const QVector<Sink::Preprocessor *> &preprocessors);
0064     void setupSynchronizer(const QSharedPointer<Synchronizer> &synchronizer);
0065     void setupInspector(const QSharedPointer<Inspector> &inspector);
0066 
0067     ResourceContext mResourceContext;
0068 
0069 private:
0070     void onProcessorError(int errorCode, const QString &errorMessage);
0071 
0072     QSharedPointer<Pipeline> mPipeline;
0073     QSharedPointer<CommandProcessor> mProcessor;
0074     QSharedPointer<Synchronizer> mSynchronizer;
0075     QSharedPointer<Inspector> mInspector;
0076     int mError;
0077     qint64 mClientLowerBoundRevision;
0078 };
0079 
0080 }