File indexing completed on 2024-05-19 05:26:10
0001 /* 0002 * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License as published by 0006 * the Free Software Foundation; either version 2 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0018 */ 0019 0020 #pragma once 0021 0022 #include "sink_export.h" 0023 #include "facadeinterface.h" 0024 0025 #include <QByteArray> 0026 #include <KAsync/Async> 0027 0028 #include "resourceaccess.h" 0029 #include "domaintypeadaptorfactoryinterface.h" 0030 #include "storage.h" 0031 #include "resourcecontext.h" 0032 0033 namespace Sink { 0034 0035 /** 0036 * Default facade implementation for resources that are implemented in a separate process using the ResourceAccess class. 0037 * 0038 * Ideally a basic resource has no implementation effort for the facades and can simply instanciate default implementations (meaning it only has to implement the factory with all 0039 * supported types). 0040 * A resource has to implement: 0041 * * A facade factory registering all available facades 0042 * * An adaptor factory if it uses special resource buffers (default implementation can be used otherwise) 0043 * * A mapping between resource and buffertype if default can't be used. 0044 * 0045 * Additionally a resource only has to provide a synchronizer plugin to execute the synchronization 0046 */ 0047 template <typename DomainType> 0048 class SINK_EXPORT GenericFacade : public Sink::StoreFacade<DomainType> 0049 { 0050 protected: 0051 SINK_DEBUG_COMPONENT(mResourceContext.resourceInstanceIdentifier) 0052 public: 0053 /** 0054 * Create a new GenericFacade 0055 * 0056 * @param resourceIdentifier is the identifier of the resource instance 0057 * @param adaptorFactory is the adaptor factory used to generate the mappings from domain to resource types and vice versa 0058 */ 0059 GenericFacade(const ResourceContext &context); 0060 virtual ~GenericFacade() Q_DECL_OVERRIDE; 0061 0062 static QByteArray bufferTypeForDomainType(); 0063 KAsync::Job<void> create(const DomainType &domainObject) Q_DECL_OVERRIDE; 0064 KAsync::Job<void> modify(const DomainType &domainObject) Q_DECL_OVERRIDE; 0065 KAsync::Job<void> move(const DomainType &domainObject, const QByteArray &newResource) Q_DECL_OVERRIDE; 0066 KAsync::Job<void> copy(const DomainType &domainObject, const QByteArray &newResource) Q_DECL_OVERRIDE; 0067 KAsync::Job<void> remove(const DomainType &domainObject) Q_DECL_OVERRIDE; 0068 virtual QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> load(const Sink::Query &query, const Log::Context &) Q_DECL_OVERRIDE; 0069 0070 protected: 0071 std::function<void(Sink::ApplicationDomain::ApplicationDomainType &domainObject)> mResultTransformation; 0072 ResourceContext mResourceContext; 0073 Sink::ResourceAccessInterface::Ptr mResourceAccess; 0074 }; 0075 0076 /** 0077 * A default facade implemenation that simply instantiates a generic resource 0078 */ 0079 template<typename DomainType> 0080 class DefaultFacade : public GenericFacade<DomainType> 0081 { 0082 public: 0083 DefaultFacade(const ResourceContext &context) : GenericFacade<DomainType>(context) {} 0084 virtual ~DefaultFacade(){} 0085 }; 0086 0087 }