#include <CacheSyncSource.h>
Public Member Functions | |
CacheSyncSource (const WCHAR *name, AbstractSyncSourceConfig *sc, KeyValueStore *cache=NULL) | |
virtual | ~CacheSyncSource () |
void | setItemStatus (const WCHAR *key, int status, const char *command) |
SyncItem * | getFirstItemKey () |
SyncItem * | getNextItemKey () |
SyncItem * | getFirstItem () |
SyncItem * | getNextItem () |
SyncItem * | getFirstNewItem () |
SyncItem * | getNextNewItem () |
SyncItem * | getFirstUpdatedItem () |
SyncItem * | getNextUpdatedItem () |
SyncItem * | getFirstDeletedItem () |
SyncItem * | getNextDeletedItem () |
void | serverStatusPackageEnded () |
void | clientStatusPackageEnded () |
int | endSync () |
virtual StringBuffer | getItemSignature (StringBuffer &key) |
virtual void * | getItemContent (StringBuffer &key, size_t *size)=0 |
virtual Enumeration * | getAllItemList ()=0 |
virtual int | insertItem (SyncItem &item)=0 |
virtual int | modifyItem (SyncItem &item)=0 |
virtual int | removeItem (SyncItem &item)=0 |
Protected Member Functions | |
int | saveCache () |
int | addItem (SyncItem &item) |
int | updateItem (SyncItem &item) |
int | deleteItem (SyncItem &item) |
int | updateInCache (KeyValuePair &k, const char *action=REPLACE) |
int | insertInCache (KeyValuePair &k) |
int | removeFromCache (KeyValuePair &k) |
Definition at line 66 of file CacheSyncSource.h.
CacheSyncSource::CacheSyncSource | ( | const WCHAR * | name, | |
AbstractSyncSourceConfig * | sc, | |||
KeyValueStore * | cache = NULL | |||
) |
Constructor: create a CacheSyncSource with the specified name
name | the name of the SyncSource | |
sc | configuration for the sync source: the instance must remain valid throughout the lifetime of the sync source because it keeps a reference to it and uses it as its own. A NULL pointer is allowed for unit testing outside of the sync framework; the sync source then references a global config instance to avoid crashes, but modifying that config will not make much sense. The pointer may also be set directly after creating the SyncSource, which is useful when a derived class creates the config in its own constructor. | |
cache | the store for the cache. Released by the CacheSyncSource |
virtual CacheSyncSource::~CacheSyncSource | ( | ) | [virtual] |
int CacheSyncSource::addItem | ( | SyncItem & | item | ) | [protected, virtual] |
Called by the sync engine to add an item that the server has sent. The implementation calls the insertItem method that must be implemented by the user. Also used to update the item
Implements SyncSource.
void CacheSyncSource::clientStatusPackageEnded | ( | ) | [inline, virtual] |
Indicates that all the client status of the current package of the server items that has been processed by the client and are going to be sent to the server. This signal can be useful to update the modification arrays NOT USED at the moment
Reimplemented from SyncSource.
Definition at line 304 of file CacheSyncSource.h.
int CacheSyncSource::deleteItem | ( | SyncItem & | item | ) | [protected, virtual] |
Called by the sync engine to update an item that the source already should have. The item's key is the local key of that item, no data is provided.
item | the item as sent by the server |
Implements SyncSource.
int CacheSyncSource::endSync | ( | ) | [virtual] |
In the first implementatation, in which serverStatusPackageEnded and clientStatusPackageEnded are not yet impelemented, the end sync will udpate the whole cache status persistently.
Reimplemented from SyncSource.
virtual Enumeration* CacheSyncSource::getAllItemList | ( | ) | [pure virtual] |
Get an array list containing all the StringBuffer keys of all items. Used for the sync requiring and exchange of all items and for the sync that need to calculate the modification. It has to return a new allocated Enumeration that is freed by the CacheSyncSource
SyncItem* CacheSyncSource::getFirstDeletedItem | ( | ) | [virtual] |
Return the first SyncItem of updated one. It is used in case of fast sync and retrieve the new data source content.
Implements SyncSource.
SyncItem* CacheSyncSource::getFirstItem | ( | ) | [virtual] |
Return the first SyncItem of all. It is used in case of slow sync and retrieve the entire data source content.
Implements SyncSource.
SyncItem* CacheSyncSource::getFirstItemKey | ( | ) | [inline, virtual] |
Return the key of the first SyncItem of all. It is used in case of refresh sync and retrieve all the keys of the data source.
Implements SyncSource.
Definition at line 229 of file CacheSyncSource.h.
SyncItem* CacheSyncSource::getFirstNewItem | ( | ) | [virtual] |
Return the first SyncItem of new one. It is used in case of fast sync and retrieve the new data source content.
Implements SyncSource.
SyncItem* CacheSyncSource::getFirstUpdatedItem | ( | ) | [virtual] |
Return the first SyncItem of updated one. It is used in case of fast sync and retrieve the new data source content.
Implements SyncSource.
virtual void* CacheSyncSource::getItemContent | ( | StringBuffer & | key, | |
size_t * | size | |||
) | [pure virtual] |
Get the content of an item given the key. It is used to populate the SyncItem before the engine uses it in the usual flow of the sync.
key | the local key of the item | |
size | OUT: the size of the content |
virtual StringBuffer CacheSyncSource::getItemSignature | ( | StringBuffer & | key | ) | [virtual] |
Get the signature of an item given the key. The signature could be a crc computation or a timestamp or whatever can identify uniquely the content of an item. The default implementation uses a crc computation of the value. Overriding implementation could provide something different like the timestamp or other...
key | the key of the item. |
SyncItem* CacheSyncSource::getNextDeletedItem | ( | ) | [virtual] |
Return the next SyncItem of updated one. It is used in case of fast sync and retrieve the new data source content.
Implements SyncSource.
SyncItem* CacheSyncSource::getNextItem | ( | ) | [virtual] |
Return the next SyncItem of all. It is used in case of slow sync and retrieve the entire data source content.
Implements SyncSource.
SyncItem* CacheSyncSource::getNextItemKey | ( | ) | [inline, virtual] |
Return the key of the next SyncItem of all. It is used in case of refresh sync and retrieve all the keys of the data source.
Implements SyncSource.
Definition at line 237 of file CacheSyncSource.h.
SyncItem* CacheSyncSource::getNextNewItem | ( | ) | [virtual] |
Return the next SyncItem of new one. It is used in case of fast sync and retrieve the new data source content.
Implements SyncSource.
SyncItem* CacheSyncSource::getNextUpdatedItem | ( | ) | [virtual] |
Return the next SyncItem of updated one. It is used in case of fast sync and retrieve the new data source content.
Implements SyncSource.
int CacheSyncSource::insertInCache | ( | KeyValuePair & | k | ) | [inline, protected] |
To insert in the cache.
Definition at line 173 of file CacheSyncSource.h.
References updateInCache().
virtual int CacheSyncSource::insertItem | ( | SyncItem & | item | ) | [pure virtual] |
Called by the sync engine to add an item that the server has sent. The sync source is expected to add it to its database, then set the key to the local key assigned to the new item. Alternatively the sync source can match the new item against one of the existing items and return that key.
item | the item as sent by the server |
virtual int CacheSyncSource::modifyItem | ( | SyncItem & | item | ) | [pure virtual] |
Called by the sync engine to update an item that the source already should have. The item's key is the local key of that item.
item | the item as sent by the server |
int CacheSyncSource::removeFromCache | ( | KeyValuePair & | k | ) | [inline, protected] |
virtual int CacheSyncSource::removeItem | ( | SyncItem & | item | ) | [pure virtual] |
Called by the sync engine to update an item that the source already should have. The item's key is the local key of that item, no data is provided.
item | the item as sent by the server |
int CacheSyncSource::saveCache | ( | ) | [protected] |
Save the current cache in what is implemented by KeyValueStore (a file or wathever).
void CacheSyncSource::serverStatusPackageEnded | ( | ) | [inline, virtual] |
Indicates that all the server status of the current package of the client items has been processed by the engine. This signal can be useful to update the modification arrays NOT USED at the moment
Reimplemented from SyncSource.
Definition at line 295 of file CacheSyncSource.h.
void CacheSyncSource::setItemStatus | ( | const WCHAR * | key, | |
int | status, | |||
const char * | command | |||
) | [virtual] |
called by the sync engine with the status returned by the server for a certain item that the client sent to the server. It contains also the proper command associated to the item. It is used to update the current array of cache.
key | - the local key of the item | |
status | - the SyncML status returned by the server | |
command | - the SyncML command associated to the item |
Reimplemented from SyncSource.
int CacheSyncSource::updateInCache | ( | KeyValuePair & | k, | |
const char * | action = REPLACE | |||
) | [protected] |
Used to update the cache adding, replacing or deleting. The KeyValuePair contains the pair UID/signature. It is provided by the proper method who calls this. It udpates the cache that is in memory. The action by default is Replace.
Referenced by insertInCache(), and removeFromCache().
int CacheSyncSource::updateItem | ( | SyncItem & | item | ) | [protected, virtual] |
Called by the sync engine to update an item that the source already should have. The item's key is the local key of that item.
item | the item as sent by the server |
Implements SyncSource.