Hi, all
I'm working on automatic sync. One of scenario is to track changes of backends 
and do automatic sync.
So we need define APIs for this. See below.

// a listener to listen to changes of backend
class SyncSourceListener {
public:
/** itemAdded is a callback when an item is newly added by backend */
virtual void itemAdded(const string &luid, const string &item, bool raw) {};
/** itemRemoved is a callback when an item is newly removed by backend */
virtual void itemRemoved(const string &luid) {};
/** itemUpdated is a callback when an item is newly updated by backend */
virtual void itemUpdated (const string &luid, const string &item, bool raw) {};
};
class SyncSource {
public:
 ...
 //add listener of the sync source
 void startListener(SyncSourceListener *listener) { throw 
std::runtime_error("don't support listener"); }
};

The example code is:
class MyListener : public SyncSourceListener {
// implement itemAdded, itemRemoved, itemUpdated if wanted
};
Syncsource source;
MyListener listener;
source.setListener(listener);

Some behaviors are specified by Patrick:
- open()/close() are not called
- a source is used either for change notifications or data access
- it only has to support at most one listener
- changes made by SyncEvolution as part of a sync may be reported,
  but don't have to
- the listener instance is owned by the caller
- the source should continue monitoring changes until destructed

For SyncSourceListener, the concern here is that we are not sure whether 
needing this level of detail. For backend tracking used in automatic sync, 
below API is enough:
virtual void itemChanged(); // callback when there is any change in the backend
Anyone has idea or suggestion?

Another thing is that backends don't have opportunity to process its changes 
only if they are integrated with glib main loop. We should have a mechanism to 
support this.
Potential solutions are(rough ideas):

1)       new threads for backends

2)       add APIs in SyncEvolution and syncEvolution call APIs to give 
opportunity to backends to process their changes.
Anyone who has concerns or ideas, please feel free to raise them. Thanks.

Regards,
Yongsheng

_______________________________________________
SyncEvolution mailing list
SyncEvolution@syncevolution.org
http://lists.syncevolution.org/listinfo/syncevolution

Reply via email to