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/util/ArrayElement.h"
00044 #include "spds/constants.h"
00045 #include "spds/SyncItem.h"
00046 #include "spds/AbstractSyncSourceConfig.h"
00047 #include "spds/SyncSourceReport.h"
00048 #include "spds/SyncSource.h"
00049 #include "syncml/core/TagNames.h"
00050 #include "base/util/Enumeration.h"
00051 #include "base/util/KeyValueStore.h"
00052 #include "base/util/KeyValuePair.h"
00053 #include "event/FireEvent.h"
00054
00055 BEGIN_NAMESPACE
00056
00086 class CacheSyncSource : public SyncSource {
00087
00088 private:
00089
00101 KeyValueStore* cache;
00102
00103
00104 protected:
00105
00109 Enumeration* newKeys;
00110
00114 Enumeration* updatedKeys;
00115
00119 Enumeration* deletedKeys;
00120
00125 Enumeration* allKeys;
00126
00127
00134 virtual SyncItem* fillSyncItem(StringBuffer* key, const bool fillData = true);
00135
00144 virtual void getKeyAndSignature(SyncItem& item, KeyValuePair& kvp);
00145
00146
00156 virtual bool fillItemModifications();
00157
00158
00163 virtual int saveCache();
00164
00174 int addItem(SyncItem& item);
00175
00183 int updateItem(SyncItem& item);
00184
00193 int deleteItem(SyncItem& item);
00194
00202 int updateInCache(KeyValuePair& k, const char* action = REPLACE);
00203
00207 int insertInCache(KeyValuePair& k) {
00208 return updateInCache(k, ADD);
00209 }
00210
00214 int removeFromCache(KeyValuePair& k) {
00215 return updateInCache(k, DEL);
00216 }
00217
00221 int clearCache() {
00222 return (cache->removeAllProperties() || saveCache());
00223 }
00224
00232 StringBuffer readCachePropertyValue(const char* prop);
00233
00234 public:
00235
00254 CacheSyncSource(const WCHAR* name, AbstractSyncSourceConfig* sc,
00255 KeyValueStore* cache = NULL);
00256
00257
00258 virtual ~CacheSyncSource();
00259
00271 virtual void setItemStatus(const WCHAR* wkey, int status, const char* command);
00272
00278 virtual SyncItem* getFirstItem();
00279
00285 SyncItem* getNextItem();
00286
00291 virtual SyncItem* getFirstNewItem();
00292
00297 SyncItem* getNextNewItem();
00298
00303 SyncItem* getFirstUpdatedItem();
00304
00309 SyncItem* getNextUpdatedItem();
00310
00315 SyncItem* getFirstDeletedItem();
00316
00321 SyncItem* getNextDeletedItem();
00322
00329 void serverStatusPackageEnded() {};
00330
00338 void clientStatusPackageEnded() {};
00339
00343 virtual int beginSync();
00344
00350 virtual int endSync();
00351
00362 virtual StringBuffer getItemSignature(StringBuffer& key);
00363
00371 virtual void* getItemContent(StringBuffer& key, size_t* size) = 0;
00372
00373
00386 virtual Enumeration* getAllItemList() = 0;
00387
00398 virtual int insertItem(SyncItem& item) = 0;
00399
00407 virtual int modifyItem(SyncItem& item) = 0;
00408
00417 virtual int removeItem(SyncItem& item) = 0;
00418
00429 virtual bool isErrorCode(int code);
00430
00437 virtual void fireClientTotalNumber(int number);
00438 };
00439
00440 END_NAMESPACE
00441
00444 #endif