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 MEDIASOURCESYNC_H_
00037 #define MEDIASOURCESYNC_H_
00038
00039 #include "base/fscapi.h"
00040 #include "spds/constants.h"
00041 #include "spds/SyncItem.h"
00042 #include "spds/SyncMap.h"
00043 #include "spds/SyncStatus.h"
00044 #include "base/util/ItemContainer.h"
00045 #include "spds/FileData.h"
00046 #include "client/CacheSyncSource.h"
00047 #include "client/FileSyncSource.h"
00048 #include "http/HttpUploader.h"
00049
00050 BEGIN_NAMESPACE
00051
00052 #define MEDIA_CACHE_FILE_NAME "funambol_cache.dat"
00053 #define MEDIA_LUID_MAP_FILE_NAME "funambol_luid.dat"
00054
00055 #define CACHE_PROPERTY_URL "_SERVER_URL_"
00056 #define CACHE_PROPERTY_USERNAME "_USERNAME_"
00057 #define CACHE_PROPERTY_SWV "_CLIENT_SWV_"
00058
00059 #define CONFIG_PROPS_EXT "_params.ini" // config props file will be "<sourcename>_params.ini"
00060 #define PROPERTY_NEXT_LUID "nextLUID"
00061
00062
00069 class MediaSyncSourceParams
00070 {
00071 private:
00072 StringBuffer url;
00073 StringBuffer username;
00074 StringBuffer password;
00075 StringBuffer swv;
00076 StringBuffer deviceID;
00077 StringBuffer userAgent;
00084 int nextLUID;
00085
00091 unsigned int filterBySize;
00092
00098 unsigned long filterByDate;
00099
00100 public:
00101 MediaSyncSourceParams() {
00102 nextLUID = 0;
00103 filterBySize = 0;
00104 filterByDate = 0;
00105 }
00106 ~MediaSyncSourceParams() {};
00107
00108 const StringBuffer& getUrl() { return url; }
00109 const StringBuffer& getUsername() { return username; }
00110 const StringBuffer& getPassword() { return password; }
00111 const StringBuffer& getSwv() { return swv; }
00112 const StringBuffer& getDeviceID() { return deviceID; }
00113 const StringBuffer& getUserAgent() { return userAgent; }
00114 const int getNextLUID() { return nextLUID; }
00115 const unsigned int getFilterBySize() { return filterBySize; }
00116 const unsigned long getFilterByDate() { return filterByDate; }
00117
00118 void setUrl (const StringBuffer& v) { url = v; }
00119 void setUsername (const StringBuffer& v) { username = v; }
00120 void setPassword (const StringBuffer& v) { password = v; }
00121 void setSwv (const StringBuffer& v) { swv = v; }
00122 void setDeviceID (const StringBuffer& v) { deviceID = v; }
00123 void setUserAgent (const StringBuffer& v) { userAgent = v; }
00124 void setNextLUID (const int v) { nextLUID = v; }
00125 void setFilterBySize (const unsigned int v) { filterBySize = v; }
00126 void setFilterByDate (const unsigned long v) { filterByDate = v; }
00127 };
00128
00129
00130
00141 class MediaSyncSource : public FileSyncSource
00142 {
00143
00144 public:
00145 MediaSyncSource(const WCHAR* wname,
00146 AbstractSyncSourceConfig* sc,
00147 const StringBuffer& aDir,
00148 MediaSyncSourceParams mediaParams);
00149
00150 ~MediaSyncSource();
00151
00157 int beginSync();
00158
00160 int insertItem(SyncItem& item);
00161
00163 int modifyItem(SyncItem& item);
00164
00166 int removeItem(SyncItem& item);
00167
00176 StringBuffer getItemSignature(StringBuffer& key);
00177
00185 virtual void fireClientTotalNumber(int number);
00186
00193 void setItemStatus(const WCHAR* wkey, int status, const char* command);
00194
00205 int endSync();
00206
00217 virtual bool isErrorCode(int code);
00218
00219
00220 protected:
00221
00223 MediaSyncSourceParams params;
00224
00226 StringBuffer filterDateString;
00227
00234 ArrayList LUIDsToSend;
00235
00243 KeyValueStore* LUIDMap;
00244
00251 virtual SyncItem* fillSyncItem(StringBuffer* key, const bool fillData = true);
00252
00263 virtual void getKeyAndSignature(SyncItem& item, KeyValuePair& kvp);
00264
00265
00274 SyncItem* getFirstItem();
00275
00285 virtual SyncItem* getFirstNewItem();
00286
00287
00301 virtual bool filterOutgoingItem(const StringBuffer& fullName, struct stat& st);
00302
00315 virtual bool dynamicFilterItem(const StringBuffer& fileName);
00316
00326 void dynamicFilterItems(Enumeration* itemKeys);
00327
00334 virtual int saveCache();
00335
00336
00341 StringBuffer getLUIDFromPath(const StringBuffer& path);
00342
00352 StringBuffer getPathFromLUID(const StringBuffer& luid);
00353
00360 void setSourceError(const int errorCode);
00361
00366 virtual HttpUploader* getHttpUploader() {
00367 return new HttpUploader();
00368 }
00369
00370 private:
00371
00378 KeyValueStore* configParams;
00379
00387 bool checkCacheValidity();
00388
00394 bool verifyNextLUIDValue();
00395
00403 bool refreshLUIDMap();
00404
00405
00410 const int readNextLUID();
00411
00418 void saveNextLUID(const int nextLUID);
00419
00420 };
00421
00422 END_NAMESPACE
00423
00424 #endif