#include <FileSyncSource.h>
Public Member Functions | |
FileSyncSource (const EvolutionSyncSourceParams ¶ms, const string &dataformat) | |
Protected Member Functions | |
virtual void | open () |
virtual void | close () |
virtual Databases | getDatabases () |
virtual SyncItem * | createItem (const string &uid) |
virtual string | fileSuffix () const |
virtual const char * | getMimeType () const |
virtual const char * | getMimeVersion () const |
virtual const char * | getSupportedTypes () const |
virtual void | logItem (const string &uid, const string &info, bool debug=false) |
virtual void | logItem (const SyncItem &item, const string &info, bool debug=false) |
virtual void | listAllItems (RevisionMap_t &revisions) |
virtual InsertItemResult | insertItem (const string &uid, const SyncItem &item) |
virtual void | deleteItem (const string &uid) |
Change tracking is done via the file systems modification time stamp: editing a file treats it as modified and then sends it to the server in the next sync. Removing and adding files also works.
The local unique identifier for each item is its name in the directory. New files are created using a running count which initialized based on the initial content of the directory to "highest existing number + 1" and incremented to avoid collisions.
Although this sync source itself does not care about the content of each item/file, the server needs to know what each item sent to it contains and what items the source is able to receive. Therefore the "type" property for this source must contain a data format specified, including a version for it. Here are some examples:
Definition at line 53 of file FileSyncSource.h.
FileSyncSource::FileSyncSource | ( | const EvolutionSyncSourceParams & | params, | |
const string & | dataformat | |||
) |
void FileSyncSource::close | ( | ) | [protected, virtual] |
closes the data source so that it can be reopened
Just as open() it should not affect the state of the database unless some previous action requires it.
Implements TrackingSyncSource.
Definition at line 115 of file FileSyncSource.cpp.
References EvolutionSyncSource::sleepSinceModification().
SyncItem * FileSyncSource::createItem | ( | const string & | uid | ) | [protected, virtual] |
Extract information for the item identified by UID and store it in a new SyncItem. The caller must free that item. May throw exceptions.
uid | identifies the item |
Implements TrackingSyncSource.
Definition at line 151 of file FileSyncSource.cpp.
References getMimeType(), and EvolutionSyncSource::throwError().
void FileSyncSource::deleteItem | ( | const string & | uid | ) | [protected, virtual] |
removes and item
Implements TrackingSyncSource.
Definition at line 233 of file FileSyncSource.cpp.
References EvolutionSyncSource::throwError().
string FileSyncSource::fileSuffix | ( | ) | const [protected, virtual] |
file suffix for database files
Implements TrackingSyncSource.
Definition at line 60 of file FileSyncSource.cpp.
FileSyncSource::Databases FileSyncSource::getDatabases | ( | ) | [protected, virtual] |
returns a list of all know sources for the kind of items supported by this sync source
Implements TrackingSyncSource.
Definition at line 127 of file FileSyncSource.cpp.
const char * FileSyncSource::getMimeType | ( | ) | const [protected, virtual] |
Returns the preferred mime type of the items handled by the sync source. Example: "text/x-vcard"
Implements TrackingSyncSource.
Definition at line 70 of file FileSyncSource.cpp.
Referenced by createItem().
const char * FileSyncSource::getMimeVersion | ( | ) | const [protected, virtual] |
Returns the version of the mime type used by client. Example: "2.1"
Implements TrackingSyncSource.
Definition at line 75 of file FileSyncSource.cpp.
const char * FileSyncSource::getSupportedTypes | ( | ) | const [protected, virtual] |
A string representing the source types (with versions) supported by the SyncSource. The string must be formatted as a sequence of "type:version" separated by commas ','. For example: "text/x-vcard:2.1,text/vcard:3.0". The version can be left empty, for example: "text/x-s4j-sifc:". Supported types will be sent as part of the DevInf.
Implements TrackingSyncSource.
Definition at line 80 of file FileSyncSource.cpp.
TrackingSyncSource::InsertItemResult FileSyncSource::insertItem | ( | const string & | uid, | |
const SyncItem & | item | |||
) | [protected, virtual] |
Create or modify an item.
The sync source should be flexible: if the UID is non-empty, it shall modify the item referenced by the UID. If the UID is empty, the normal operation is to add it. But if the item already exists (e.g., a calendar event which was imported by the user manually), then the existing item should be updated also in the second case.
Passing a UID of an item which does not exist is an error. This error should be reported instead of covering it up by (re)creating the item.
Errors are signalled by throwing an exception. Returning empty strings in the result is an error which triggers an "item could not be stored" error.
uid | identifies the item to be modified, empty for creating | |
item | contains the new content of the item and its MIME type |
Implements TrackingSyncSource.
Definition at line 177 of file FileSyncSource.cpp.
References EvolutionSyncSource::throwError().
void FileSyncSource::listAllItems | ( | RevisionMap_t & | revisions | ) | [protected, virtual] |
Definition at line 136 of file FileSyncSource.cpp.
void FileSyncSource::logItem | ( | const SyncItem & | item, | |
const string & | info, | |||
bool | debug = false | |||
) | [protected, virtual] |
Implements TrackingSyncSource.
Definition at line 278 of file FileSyncSource.cpp.
References logItem(), and EvolutionSyncSource::logItemUtil().
void FileSyncSource::logItem | ( | const string & | uid, | |
const string & | info, | |||
bool | debug = false | |||
) | [protected, virtual] |
log a one-line info about an item
Implements TrackingSyncSource.
Definition at line 242 of file FileSyncSource.cpp.
References EvolutionSyncSource::logItemUtil().
Referenced by logItem().
void FileSyncSource::open | ( | ) | [protected, virtual] |
Actually opens the data source specified in the constructor, will throw the normal exceptions if that fails. Should not modify the state of the sync source: that can be deferred until the server is also ready and beginSync() is called.
Implements TrackingSyncSource.
Definition at line 86 of file FileSyncSource.cpp.
References EvolutionSyncSourceConfig::getDatabaseID(), isDir(), mkdir_p(), and EvolutionSyncSource::throwError().