File indexing completed on 2024-05-12 05:26:27
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 "sinktest_export.h" 0023 #include <KAsync/Async> 0024 0025 #include <common/domainadaptor.h> 0026 #include <common/resultprovider.h> 0027 #include <common/resourceaccess.h> 0028 #include <common/facade.h> 0029 #include <common/genericresource.h> 0030 #include <common/commands.h> 0031 0032 // Replace with something different 0033 #include "event_generated.h" 0034 #include "mail_generated.h" 0035 #include "createentity_generated.h" 0036 0037 class SINKTEST_EXPORT TestEventAdaptorFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Event> 0038 { 0039 public: 0040 TestEventAdaptorFactory() : DomainTypeAdaptorFactory() 0041 { 0042 } 0043 0044 virtual ~TestEventAdaptorFactory(){}; 0045 }; 0046 0047 class SINKTEST_EXPORT TestMailAdaptorFactory : public DomainTypeAdaptorFactory<Sink::ApplicationDomain::Mail> 0048 { 0049 public: 0050 TestMailAdaptorFactory() : DomainTypeAdaptorFactory() 0051 { 0052 } 0053 0054 virtual ~TestMailAdaptorFactory(){}; 0055 }; 0056 0057 class SINKTEST_EXPORT TestResourceAccess : public Sink::ResourceAccessInterface 0058 { 0059 Q_OBJECT 0060 public: 0061 virtual ~TestResourceAccess(){}; 0062 KAsync::Job<void> sendCommand(int commandId) Q_DECL_OVERRIDE 0063 { 0064 return KAsync::null<void>(); 0065 } 0066 KAsync::Job<void> sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE 0067 { 0068 return KAsync::null<void>(); 0069 } 0070 KAsync::Job<void> synchronizeResource(const Sink::QueryBase &) Q_DECL_OVERRIDE 0071 { 0072 return KAsync::null<void>(); 0073 } 0074 0075 void revisionUpdate(qint64 rev) 0076 { 0077 emit revisionChanged(rev); 0078 } 0079 0080 public slots: 0081 void open() Q_DECL_OVERRIDE 0082 { 0083 } 0084 void close() Q_DECL_OVERRIDE 0085 { 0086 } 0087 }; 0088 0089 class SINKTEST_EXPORT TestResourceFacade : public Sink::GenericFacade<Sink::ApplicationDomain::Event> 0090 { 0091 public: 0092 TestResourceFacade(const Sink::ResourceContext &resourceContext) 0093 : Sink::GenericFacade<Sink::ApplicationDomain::Event>(resourceContext) 0094 { 0095 } 0096 virtual ~TestResourceFacade() 0097 { 0098 } 0099 }; 0100 0101 class SINKTEST_EXPORT TestMailResourceFacade : public Sink::GenericFacade<Sink::ApplicationDomain::Mail> 0102 { 0103 public: 0104 TestMailResourceFacade(const Sink::ResourceContext &resourceContext) 0105 : Sink::GenericFacade<Sink::ApplicationDomain::Mail>(resourceContext) 0106 { 0107 } 0108 virtual ~TestMailResourceFacade() 0109 { 0110 } 0111 }; 0112 0113 class SINKTEST_EXPORT TestResource : public Sink::GenericResource 0114 { 0115 public: 0116 TestResource(const Sink::ResourceContext &resourceContext, QSharedPointer<Sink::Pipeline> pipeline) : Sink::GenericResource(resourceContext, pipeline) 0117 { 0118 } 0119 }; 0120 0121 template <typename DomainType> 0122 QByteArray createCommand(const DomainType &domainObject, DomainTypeAdaptorFactoryInterface &domainTypeAdaptorFactory) 0123 { 0124 flatbuffers::FlatBufferBuilder entityFbb; 0125 domainTypeAdaptorFactory.createBuffer(domainObject, entityFbb); 0126 flatbuffers::FlatBufferBuilder fbb; 0127 auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName<DomainType>().toStdString().data()); 0128 auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); 0129 Sink::Commands::CreateEntityBuilder builder(fbb); 0130 builder.add_domainType(type); 0131 builder.add_delta(delta); 0132 auto location = builder.Finish(); 0133 Sink::Commands::FinishCreateEntityBuffer(fbb, location); 0134 return QByteArray(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); 0135 }