summaryrefslogtreecommitdiffstats
path: root/common/synchronizer.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/synchronizer.h')
-rw-r--r--common/synchronizer.h31
1 files changed, 14 insertions, 17 deletions
diff --git a/common/synchronizer.h b/common/synchronizer.h
index 5f60128..f3319f6 100644
--- a/common/synchronizer.h
+++ b/common/synchronizer.h
@@ -37,31 +37,28 @@ class RemoteIdMap;
37class SINK_EXPORT Synchronizer 37class SINK_EXPORT Synchronizer
38{ 38{
39public: 39public:
40 Synchronizer(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier); 40 Synchronizer(const Sink::ResourceContext &resourceContext);
41 virtual ~Synchronizer(); 41 virtual ~Synchronizer();
42 42
43 void setup(const std::function<void(int commandId, const QByteArray &data)> &enqueueCommandCallback, MessageQueue &messageQueue); 43 void setup(const std::function<void(int commandId, const QByteArray &data)> &enqueueCommandCallback, MessageQueue &messageQueue);
44 KAsync::Job<void> synchronize(); 44 KAsync::Job<void> synchronize();
45 45
46 //Read only access to main storage 46 //Read only access to main storage
47 EntityStore &store(); 47 Storage::EntityStore &store();
48 48
49 //Read/Write access to sync storage 49 //Read/Write access to sync storage
50 RemoteIdMap &syncStore(); 50 RemoteIdMap &syncStore();
51 51
52 void commit(); 52 void commit();
53 Sink::Storage::Transaction &transaction(); 53 Sink::Storage::DataStore::Transaction &syncTransaction();
54 Sink::Storage::Transaction &syncTransaction();
55 54
56protected: 55protected:
57 ///Calls the callback to enqueue the command 56 ///Calls the callback to enqueue the command
58 void enqueueCommand(int commandId, const QByteArray &data); 57 void enqueueCommand(int commandId, const QByteArray &data);
59 58
60 static void createEntity(const QByteArray &localId, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, 59 void createEntity(const QByteArray &localId, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject);
61 DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function<void(const QByteArray &)> callback); 60 void modifyEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject);
62 static void modifyEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, 61 void deleteEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType);
63 DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function<void(const QByteArray &)> callback);
64 static void deleteEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, std::function<void(const QByteArray &)> callback);
65 62
66 /** 63 /**
67 * A synchronous algorithm to remove entities that are no longer existing. 64 * A synchronous algorithm to remove entities that are no longer existing.
@@ -74,7 +71,8 @@ protected:
74 * All functions are called synchronously, and both @param entryGenerator and @param exists need to be synchronous. 71 * All functions are called synchronously, and both @param entryGenerator and @param exists need to be synchronous.
75 */ 72 */
76 void scanForRemovals(const QByteArray &bufferType, 73 void scanForRemovals(const QByteArray &bufferType,
77 const std::function<void(const std::function<void(const QByteArray &key)> &callback)> &entryGenerator, std::function<bool(const QByteArray &remoteId)> exists); 74 const std::function<void(const std::function<void(const QByteArray &sinkId)> &callback)> &entryGenerator, std::function<bool(const QByteArray &remoteId)> exists);
75 void scanForRemovals(const QByteArray &bufferType, std::function<bool(const QByteArray &remoteId)> exists);
78 76
79 /** 77 /**
80 * An algorithm to create or modify the entity. 78 * An algorithm to create or modify the entity.
@@ -96,14 +94,13 @@ protected:
96 virtual KAsync::Job<void> synchronizeWithSource() = 0; 94 virtual KAsync::Job<void> synchronizeWithSource() = 0;
97 95
98private: 96private:
97 void modifyIfChanged(Storage::EntityStore &store, const QByteArray &bufferType, const QByteArray &sinkId, const Sink::ApplicationDomain::ApplicationDomainType &entity);
98
99 Sink::ResourceContext mResourceContext;
100 Sink::Storage::EntityStore::Ptr mEntityStore;
99 QSharedPointer<RemoteIdMap> mSyncStore; 101 QSharedPointer<RemoteIdMap> mSyncStore;
100 QSharedPointer<EntityStore> mEntityStore; 102 Sink::Storage::DataStore mSyncStorage;
101 Sink::Storage mStorage; 103 Sink::Storage::DataStore::Transaction mSyncTransaction;
102 Sink::Storage mSyncStorage;
103 QByteArray mResourceType;
104 QByteArray mResourceInstanceIdentifier;
105 Sink::Storage::Transaction mTransaction;
106 Sink::Storage::Transaction mSyncTransaction;
107 std::function<void(int commandId, const QByteArray &data)> mEnqueue; 104 std::function<void(int commandId, const QByteArray &data)> mEnqueue;
108 MessageQueue *mMessageQueue; 105 MessageQueue *mMessageQueue;
109 bool mSyncInProgress; 106 bool mSyncInProgress;