diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-28 02:09:58 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-28 02:09:58 +0200 |
commit | b441386c4e138d19bbd79d578e0a2ff1b3f54a93 (patch) | |
tree | 1110b6ec00ce29a8bcd7f6db0717f4a483f50587 /common/genericresource.h | |
parent | afb29c153daff23e491a350784ce6af5db5e28af (diff) | |
download | sink-b441386c4e138d19bbd79d578e0a2ff1b3f54a93.tar.gz sink-b441386c4e138d19bbd79d578e0a2ff1b3f54a93.zip |
Moved the classes to individual files
Diffstat (limited to 'common/genericresource.h')
-rw-r--r-- | common/genericresource.h | 141 |
1 files changed, 0 insertions, 141 deletions
diff --git a/common/genericresource.h b/common/genericresource.h index 45d5d3a..4ed408d 100644 --- a/common/genericresource.h +++ b/common/genericresource.h | |||
@@ -82,147 +82,6 @@ private: | |||
82 | int mError; | 82 | int mError; |
83 | QTimer mCommitQueueTimer; | 83 | QTimer mCommitQueueTimer; |
84 | qint64 mClientLowerBoundRevision; | 84 | qint64 mClientLowerBoundRevision; |
85 | QHash<QByteArray, DomainTypeAdaptorFactoryInterface::Ptr> mAdaptorFactories; | ||
86 | }; | 85 | }; |
87 | 86 | ||
88 | class SINK_EXPORT SyncStore | ||
89 | { | ||
90 | public: | ||
91 | SyncStore(Sink::Storage::Transaction &); | ||
92 | |||
93 | /** | ||
94 | * Records a localId to remoteId mapping | ||
95 | */ | ||
96 | void recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId); | ||
97 | void removeRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId); | ||
98 | void updateRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId); | ||
99 | |||
100 | /** | ||
101 | * Tries to find a local id for the remote id, and creates a new local id otherwise. | ||
102 | * | ||
103 | * The new local id is recorded in the local to remote id mapping. | ||
104 | */ | ||
105 | QByteArray resolveRemoteId(const QByteArray &type, const QByteArray &remoteId); | ||
106 | |||
107 | /** | ||
108 | * Tries to find a remote id for a local id. | ||
109 | * | ||
110 | * This can fail if the entity hasn't been written back to the server yet. | ||
111 | */ | ||
112 | QByteArray resolveLocalId(const QByteArray &bufferType, const QByteArray &localId); | ||
113 | |||
114 | private: | ||
115 | Sink::Storage::Transaction &mTransaction; | ||
116 | }; | ||
117 | |||
118 | class SINK_EXPORT EntityStore | ||
119 | { | ||
120 | public: | ||
121 | EntityStore(const QByteArray &resourceType, const QByteArray &mResourceInstanceIdentifier, Sink::Storage::Transaction &transaction); | ||
122 | |||
123 | template<typename T> | ||
124 | T read(const QByteArray &identifier) const; | ||
125 | |||
126 | static QSharedPointer<Sink::ApplicationDomain::BufferAdaptor> getLatest(const Sink::Storage::NamedDatabase &db, const QByteArray &uid, DomainTypeAdaptorFactoryInterface &adaptorFactory); | ||
127 | private: | ||
128 | QByteArray mResourceType; | ||
129 | QByteArray mResourceInstanceIdentifier; | ||
130 | Sink::Storage::Transaction &mTransaction; | ||
131 | }; | ||
132 | |||
133 | /** | ||
134 | * Synchronize and add what we don't already have to local queue | ||
135 | */ | ||
136 | class SINK_EXPORT Synchronizer | ||
137 | { | ||
138 | public: | ||
139 | Synchronizer(const QByteArray &resourceType, const QByteArray &resourceInstanceIdentifier); | ||
140 | |||
141 | void setup(const std::function<void(int commandId, const QByteArray &data)> &enqueueCommandCallback); | ||
142 | KAsync::Job<void> synchronize(); | ||
143 | |||
144 | protected: | ||
145 | ///Calls the callback to enqueue the command | ||
146 | void enqueueCommand(int commandId, const QByteArray &data); | ||
147 | |||
148 | static void createEntity(const QByteArray &localId, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, | ||
149 | DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function<void(const QByteArray &)> callback); | ||
150 | static void modifyEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, const Sink::ApplicationDomain::ApplicationDomainType &domainObject, | ||
151 | DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function<void(const QByteArray &)> callback); | ||
152 | static void deleteEntity(const QByteArray &localId, qint64 revision, const QByteArray &bufferType, std::function<void(const QByteArray &)> callback); | ||
153 | |||
154 | /** | ||
155 | * A synchronous algorithm to remove entities that are no longer existing. | ||
156 | * | ||
157 | * A list of entities is generated by @param entryGenerator. | ||
158 | * The entiry Generator typically iterates over an index to produce all existing entries. | ||
159 | * This algorithm calls @param exists for every entity of type @param type, with its remoteId. For every entity where @param exists returns false, | ||
160 | * an entity delete command is enqueued. | ||
161 | * | ||
162 | * All functions are called synchronously, and both @param entryGenerator and @param exists need to be synchronous. | ||
163 | */ | ||
164 | void scanForRemovals(const QByteArray &bufferType, | ||
165 | const std::function<void(const std::function<void(const QByteArray &key)> &callback)> &entryGenerator, std::function<bool(const QByteArray &remoteId)> exists); | ||
166 | |||
167 | /** | ||
168 | * An algorithm to create or modify the entity. | ||
169 | * | ||
170 | * Depending on whether the entity is locally available, or has changed. | ||
171 | */ | ||
172 | void createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity); | ||
173 | |||
174 | //Read only access to main storage | ||
175 | EntityStore &store(); | ||
176 | |||
177 | //Read/Write access to sync storage | ||
178 | SyncStore &syncStore(); | ||
179 | |||
180 | virtual KAsync::Job<void> synchronizeWithSource() = 0; | ||
181 | |||
182 | private: | ||
183 | QSharedPointer<SyncStore> mSyncStore; | ||
184 | QSharedPointer<EntityStore> mEntityStore; | ||
185 | Sink::Storage mStorage; | ||
186 | Sink::Storage mSyncStorage; | ||
187 | QByteArray mResourceType; | ||
188 | QByteArray mResourceInstanceIdentifier; | ||
189 | Sink::Storage::Transaction mTransaction; | ||
190 | Sink::Storage::Transaction mSyncTransaction; | ||
191 | std::function<void(int commandId, const QByteArray &data)> mEnqueue; | ||
192 | }; | ||
193 | |||
194 | /** | ||
195 | * Replay changes to the source | ||
196 | */ | ||
197 | class SINK_EXPORT SourceWriteBack : public ChangeReplay | ||
198 | { | ||
199 | public: | ||
200 | SourceWriteBack(const QByteArray &resourceType,const QByteArray &resourceInstanceIdentifier); | ||
201 | |||
202 | protected: | ||
203 | ///Base implementation calls the replay$Type calls | ||
204 | virtual KAsync::Job<void> replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; | ||
205 | |||
206 | protected: | ||
207 | ///Implement to write back changes to the server | ||
208 | virtual KAsync::Job<QByteArray> replay(const Sink::ApplicationDomain::Mail &, Sink::Operation, const QByteArray &oldRemoteId); | ||
209 | virtual KAsync::Job<QByteArray> replay(const Sink::ApplicationDomain::Folder &, Sink::Operation, const QByteArray &oldRemoteId); | ||
210 | |||
211 | //Read only access to main storage | ||
212 | EntityStore &store(); | ||
213 | |||
214 | //Read/Write access to sync storage | ||
215 | SyncStore &syncStore(); | ||
216 | |||
217 | private: | ||
218 | Sink::Storage mSyncStorage; | ||
219 | QSharedPointer<SyncStore> mSyncStore; | ||
220 | QSharedPointer<EntityStore> mEntityStore; | ||
221 | Sink::Storage::Transaction mTransaction; | ||
222 | Sink::Storage::Transaction mSyncTransaction; | ||
223 | QByteArray mResourceType; | ||
224 | QByteArray mResourceInstanceIdentifier; | ||
225 | }; | ||
226 | |||
227 | |||
228 | } | 87 | } |