#include <MediaSyncSource.h>
Public Member Functions | |
MediaSyncSource (const WCHAR *wname, AbstractSyncSourceConfig *sc, const StringBuffer &aDir, MediaSyncSourceParams mediaParams) | |
int | beginSync () |
Overrides FileSyncSource::beginSync(). | |
int | insertItem (SyncItem &item) |
Overrides FileSyncSource::insertItem - implemented empty. | |
int | modifyItem (SyncItem &item) |
Overrides FileSyncSource::modifyItem - implemented empty. | |
int | removeItem (SyncItem &item) |
Overrides FileSyncSource::removeItem - implemented empty. | |
StringBuffer | getItemSignature (StringBuffer &key) |
Overrides CacheSyncSource::getItemSignature(). | |
virtual void | fireClientTotalNumber (int number) |
Overwrite the way to send the total number of items to the client. | |
void | setItemStatus (const WCHAR *wkey, int status, const char *command) |
Overrides CacheSyncSource::setItemStatus(). | |
Protected Member Functions | |
virtual SyncItem * | fillSyncItem (StringBuffer *key, const bool fillData=true) |
Overrides CacheSyncSource::fillSyncItem(). | |
virtual void | getKeyAndSignature (SyncItem &item, KeyValuePair &kvp) |
Overrides CacheSyncSource::getKeyAndSignature(). | |
SyncItem * | getFirstItem () |
Overrides CacheSyncSource::getFirstItem(). | |
virtual SyncItem * | getFirstNewItem () |
Overrides CacheSyncSource::getFirstNewItem(). | |
virtual bool | filterOutgoingItem (const StringBuffer &fullName, struct stat &st) |
Used to filter outgoing items (overrides FileSyncSource::filterOutgoingItem) Filters the cache files (*.dat). | |
virtual bool | dynamicFilterItem (const StringBuffer &fileName) |
Filters a specific item (dynamic filtering). | |
void | dynamicFilterItems (Enumeration *itemKeys) |
Used to filter dynamically outgoing items. | |
virtual int | saveCache () |
Overrides CacheSyncSource::saveCache(). | |
StringBuffer | getLUIDFromPath (const StringBuffer &path) |
Utility method to retrieve the LUID of an item, given its path. | |
StringBuffer | getPathFromLUID (const StringBuffer &luid) |
Utility method to retrieve the full path of an item, given its LUID. | |
void | setSourceError (const int errorCode) |
Used to set errors in the MediaSyncSource. | |
Protected Attributes | |
MediaSyncSourceParams | params |
Contains parameters used by this class. | |
StringBuffer | filterDateString |
UTC string of the params::filterByDate (just for debugging). | |
Private Member Functions | |
bool | checkCacheValidity () |
Read the URL, username and client sw version from the cache. | |
bool | verifyNextLUIDValue () |
Utility method: scans the LUIDMap and check if there's a LUID >= than the passed one. | |
bool | refreshLUIDMap () |
Utility method: scans and compress the LUIDMap PropertyFile, removing all entries that have no correspondence in the cache. | |
const int | readNextLUID () |
Reads the nextLUID value from the KeyValueStore, under config folder. | |
void | saveNextLUID (const int nextLUID) |
Stores the nextLUID value in the KeyValueStore, under config folder. | |
Private Attributes | |
KeyValueStore * | LUIDMap |
Map of: Full items Path <-> Items LUID The LUID is an incremental number, different for every new item. | |
KeyValueStore * | configParams |
Used to store KeyValuePairs containing config parameters used by this class. |
Differences from FileSyncSource are:
int MediaSyncSource::beginSync | ( | ) |
Overrides FileSyncSource::beginSync().
Checks if the pictures cache is still valid, before starting a sync. If not, the cache is cleared.
bool MediaSyncSource::checkCacheValidity | ( | ) | [private] |
Read the URL, username and client sw version from the cache.
If wrong (different from the passed ones) or missing, the current cache is not valid (true is returned). This method is called by MediaSyncSource::beginSync().
virtual bool MediaSyncSource::dynamicFilterItem | ( | const StringBuffer & | fileName | ) | [protected, virtual] |
Filters a specific item (dynamic filtering).
This is called AFTER the cache is created, so this is the place to set a custom filter that may change or be disabled over time. Can be reimplemented by derived classes to specify different filterings. Current filters: 1. files with size > filterBySize 2. if the filterByDate is set, files with modification date < filterByDate
fileName | the full name of the file to be checked |
void MediaSyncSource::dynamicFilterItems | ( | Enumeration * | itemKeys | ) | [protected] |
Used to filter dynamically outgoing items.
Calls dynamicFilterItem() for all items in the passed array. This method is called from getFirstItem and getFirstNewItem, just before firing the total number of client's items.
itemKeys | the Enumeration of items to be sent (newKeys for a fast sync, allKeys for a slow sync), to apply the filter |
virtual SyncItem* MediaSyncSource::fillSyncItem | ( | StringBuffer * | key, | |
const bool | fillData = true | |||
) | [protected, virtual] |
Overrides CacheSyncSource::fillSyncItem().
The SyncItem key set is the LUID of this item. It is used by the method getXXXItem to complete the SyncItem.
Reimplemented from FileSyncSource.
virtual bool MediaSyncSource::filterOutgoingItem | ( | const StringBuffer & | fullName, | |
struct stat & | st | |||
) | [protected, virtual] |
Used to filter outgoing items (overrides FileSyncSource::filterOutgoingItem) Filters the cache files (*.dat).
NOTE: this is only STATIC filtering. Meaning that these filters CANNOT be changed/disabled anytime by the Client, otherwise a change in the filter may result in the Client to send deleted items for files fitered out. See dynamicFilterItem() for dynamic filtering.
fullName | the full path + name of the file to check | |
st | reference to struct stat for current file |
Reimplemented from FileSyncSource.
virtual void MediaSyncSource::fireClientTotalNumber | ( | int | number | ) | [virtual] |
Overwrite the way to send the total number of items to the client.
This is because the MediaSyncSource has to remove some fake items in the cache file (see fillItemModifications()), it was called by CacheSyncSource. It should not be overloaded... of items that will be updated
SyncItem* MediaSyncSource::getFirstItem | ( | ) | [protected] |
Overrides CacheSyncSource::getFirstItem().
Return the first SyncItem of ALL. It is used in case of slow sync and retrieve the entire data source content.
Compared to te CacheSyncSource implementation:
virtual SyncItem* MediaSyncSource::getFirstNewItem | ( | ) | [protected, virtual] |
Overrides CacheSyncSource::getFirstNewItem().
Return the first SyncItem of NEW. It is used in case of fast sync and retrieve the new data source content.
Compared to te CacheSyncSource implementation:
StringBuffer MediaSyncSource::getItemSignature | ( | StringBuffer & | key | ) |
Overrides CacheSyncSource::getItemSignature().
Gets the signature of an item given its full path. The signature is the timestamp of last modification time.
key | the key of the item (its full path and name) |
virtual void MediaSyncSource::getKeyAndSignature | ( | SyncItem & | item, | |
KeyValuePair & | kvp | |||
) | [protected, virtual] |
Overrides CacheSyncSource::getKeyAndSignature().
Utility method that populates the keyValuePair with the couple key/signature starting from the SyncItem. The SyncItem key set is the LUID of this item. Used in the addItem and updateItem
item | - IN: the SyncItem | |
kvp | - OUT: the KeyValuePair to be populate |
StringBuffer MediaSyncSource::getLUIDFromPath | ( | const StringBuffer & | path | ) | [protected] |
Utility method to retrieve the LUID of an item, given its path.
This is called for outgoing items: we send a LUID as key to the Server.
StringBuffer MediaSyncSource::getPathFromLUID | ( | const StringBuffer & | luid | ) | [protected] |
Utility method to retrieve the full path of an item, given its LUID.
This is called for incoming items and when receiving item's status: we need the full path to update the cache. Note: returns a NULL StringBuffer if LUID not found in the LUIDMap.
luid | the item's LUID |
const int MediaSyncSource::readNextLUID | ( | ) | [private] |
Reads the nextLUID value from the KeyValueStore, under config folder.
bool MediaSyncSource::refreshLUIDMap | ( | ) | [private] |
Utility method: scans and compress the LUIDMap PropertyFile, removing all entries that have no correspondence in the cache.
This method is called before saving the LUIDMap file at the end of sync to avoid the propertyfile growing indefinitely.
virtual int MediaSyncSource::saveCache | ( | ) | [protected, virtual] |
Overrides CacheSyncSource::saveCache().
Saves the cache and the LUID_Map into the persistent store. Adds the special properties (url, username, swv) to the cache file. Set the files attribute to hidden (TODO).
void MediaSyncSource::saveNextLUID | ( | const int | nextLUID | ) | [private] |
Stores the nextLUID value in the KeyValueStore, under config folder.
This method is called in case a new item is found locally, and so a new LUID is generated for it.
nextLUID | the updated value of nextLUID. |
void MediaSyncSource::setItemStatus | ( | const WCHAR * | wkey, | |
int | status, | |||
const char * | command | |||
) |
Overrides CacheSyncSource::setItemStatus().
The key received from Server is the item's LUID. We need to retrieve the item's path from the LUID (full path is the key fro the cache).
void MediaSyncSource::setSourceError | ( | const int | errorCode | ) | [protected] |
Used to set errors in the MediaSyncSource.
Will set the source state (error state), the source's last error code and source's last error message.
errorCode | the error code |
bool MediaSyncSource::verifyNextLUIDValue | ( | ) | [private] |
Utility method: scans the LUIDMap and check if there's a LUID >= than the passed one.
If so, updates the params::nextLUID value and returns true. This method is called just once in the constructor.
KeyValueStore* MediaSyncSource::configParams [private] |
Used to store KeyValuePairs containing config parameters used by this class.
It is saved under the system config folder, with name "<sourcename>_params.ini". Actually tho only parameter used is 'nextLUID', which is an incremental number used as the item's key when sending items to the Server (to be sure the key is unique).
KeyValueStore* MediaSyncSource::LUIDMap [private] |
Map of: Full items Path <-> Items LUID The LUID is an incremental number, different for every new item.
It's used as the SyncItem's key when sending the items to the Server, to make sure we never send 2 items with the same key. The map is stored as a PropertyFile in the 'dir' folder.