File indexing completed on 2024-05-12 05:26:03

0001 /*
0002  * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
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 
0024 #include <KAsync/Async>
0025 #include "notification.h"
0026 
0027 namespace Sink {
0028 class FacadeFactory;
0029 class AdaptorFactoryRegistry;
0030 struct ResourceContext;
0031 class QueryBase;
0032 
0033 /**
0034  * Resource interface
0035  */
0036 class SINK_EXPORT Resource : public QObject
0037 {
0038     Q_OBJECT
0039 public:
0040     Resource();
0041     virtual ~Resource();
0042 
0043     virtual void processCommand(int commandId, const QByteArray &data);
0044 
0045     /**
0046      * Set the lowest revision that is still referenced by external clients.
0047      */
0048     virtual void setLowerBoundRevision(qint64 revision);
0049 
0050     virtual void setSecret(const QString &s);
0051     virtual bool checkForUpgrade();
0052 
0053 signals:
0054     void revisionUpdated(qint64);
0055     void notify(Notification);
0056 
0057 private:
0058     class Private;
0059     Private *const d;
0060 };
0061 
0062 /**
0063  * Factory interface for resource to implement.
0064  */
0065 class SINK_EXPORT ResourceFactory : public QObject
0066 {
0067     Q_OBJECT
0068 public:
0069     static ResourceFactory *load(const QByteArray &resourceName);
0070 
0071     ResourceFactory(QObject *parent, const QByteArrayList &capabilities);
0072     virtual ~ResourceFactory();
0073 
0074     virtual Resource *createResource(const ResourceContext &context) = 0;
0075     virtual void registerFacades(const QByteArray &resourceName, FacadeFactory &factory) = 0;
0076     virtual void registerAdaptorFactories(const QByteArray &resourceName, AdaptorFactoryRegistry &registry) {};
0077     virtual void removeDataFromDisk(const QByteArray &instanceIdentifier) = 0;
0078     QByteArrayList capabilities() const;
0079 
0080 private:
0081     class Private;
0082     Private *const d;
0083 };
0084 
0085 } // namespace Sink
0086 
0087 Q_DECLARE_INTERFACE(Sink::ResourceFactory, "sink.resourcefactory")