00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef INCL_CACHE_SYNC_SOURCE
00037 #define INCL_CACHE_SYNC_SOURCE
00038
00042 #include "base/fscapi.h"
00043 #include "base/ErrorHandler.h"
00044 #include "base/util/ArrayElement.h"
00045 #include "filter/SourceFilter.h"
00046 #include "spds/constants.h"
00047 #include "spds/SyncItem.h"
00048 #include "spds/SyncStatus.h"
00049 #include "spds/AbstractSyncSourceConfig.h"
00050 #include "spds/SyncSourceReport.h"
00051 #include "spds/SyncSource.h"
00052 #include "syncml/core/TagNames.h"
00053 #include "base/util/Enumeration.h"
00054 #include "base/util/KeyValueStore.h"
00055 #include "base/util/KeyValuePair.h"
00056
00057 BEGIN_NAMESPACE
00058
00059 #define CACHE_FILE_NAME "cache_items.dat"
00060
00066 class CacheSyncSource : public SyncSource {
00067
00068 private:
00069
00081 KeyValueStore* cache;
00082
00086 Enumeration* newKeys;
00090 Enumeration* updatedKeys;
00094 Enumeration* deletedKeys;
00095
00100 Enumeration* allKeys;
00101
00106 SyncItem* fillSyncItem(StringBuffer* key);
00107
00117 bool fillItemModifications();
00118
00127 void getKeyAndSignature(SyncItem& item, KeyValuePair& kvp);
00128
00129 protected:
00130
00134 int saveCache();
00135
00141 int addItem(SyncItem& item);
00142
00150 int updateItem(SyncItem& item);
00151
00159 int deleteItem(SyncItem& item);
00160
00168 int updateInCache(KeyValuePair& k, const char* action = REPLACE);
00169
00173 int insertInCache(KeyValuePair& k) {
00174 return updateInCache(k, ADD);
00175 }
00176
00180 int removeFromCache(KeyValuePair& k) {
00181 return updateInCache(k, DEL);
00182 }
00183
00184 public:
00185
00204 CacheSyncSource(const WCHAR* name, AbstractSyncSourceConfig* sc,
00205 KeyValueStore* cache = NULL);
00206
00207
00208 virtual ~CacheSyncSource();
00209
00221 void setItemStatus(const WCHAR* key, int status, const char* command);
00222
00229 SyncItem* getFirstItemKey() { return NULL; };
00230
00237 SyncItem* getNextItemKey() { return NULL; };
00238
00244 SyncItem* getFirstItem();
00245
00251 SyncItem* getNextItem();
00252
00257 SyncItem* getFirstNewItem();
00258
00263 SyncItem* getNextNewItem();
00264
00269 SyncItem* getFirstUpdatedItem();
00270
00275 SyncItem* getNextUpdatedItem();
00276
00281 SyncItem* getFirstDeletedItem();
00282
00287 SyncItem* getNextDeletedItem();
00288
00295 void serverStatusPackageEnded() {};
00296
00304 void clientStatusPackageEnded() {};
00305
00311 int endSync();
00312
00323 virtual StringBuffer getItemSignature(StringBuffer& key);
00324
00332 virtual void* getItemContent(StringBuffer& key, size_t* size) = 0;
00333
00334
00342 virtual Enumeration* getAllItemList() = 0;
00343
00354 virtual int insertItem(SyncItem& item) = 0;
00355
00363 virtual int modifyItem(SyncItem& item) = 0;
00364
00372 virtual int removeItem(SyncItem& item) = 0;
00373
00374
00375 };
00376
00377 END_NAMESPACE
00378
00381 #endif