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
00279 SyncItem* getFirstItemKey() { return NULL; };
00280
00287 SyncItem* getNextItemKey() { return NULL; };
00288
00294 virtual SyncItem* getFirstItem();
00295
00301 SyncItem* getNextItem();
00302
00307 virtual SyncItem* getFirstNewItem();
00308
00313 SyncItem* getNextNewItem();
00314
00319 SyncItem* getFirstUpdatedItem();
00320
00325 SyncItem* getNextUpdatedItem();
00326
00331 SyncItem* getFirstDeletedItem();
00332
00337 SyncItem* getNextDeletedItem();
00338
00345 void serverStatusPackageEnded() {};
00346
00354 void clientStatusPackageEnded() {};
00355
00359 virtual int beginSync();
00360
00366 virtual int endSync();
00367
00378 virtual StringBuffer getItemSignature(StringBuffer& key);
00379
00387 virtual void* getItemContent(StringBuffer& key, size_t* size) = 0;
00388
00389
00402 virtual Enumeration* getAllItemList() = 0;
00403
00414 virtual int insertItem(SyncItem& item) = 0;
00415
00423 virtual int modifyItem(SyncItem& item) = 0;
00424
00433 virtual int removeItem(SyncItem& item) = 0;
00434
00445 virtual bool isErrorCode(int code);
00446
00453 virtual void fireClientTotalNumber(int number);
00454 };
00455
00456 END_NAMESPACE
00457
00460 #endif