From: <dg...@su...> - 2009-01-07 21:17:00
|
Author: mkoller Date: Wed Jan 7 22:16:33 2009 New Revision: 5050 URL: http://www.opensync.org/changeset/5050 Log: change to new anchor API Modified: plugins/kdepim/src/datasource.cpp plugins/kdepim/src/kdepim_sync.cpp Modified: plugins/kdepim/src/datasource.cpp ============================================================================== --- plugins/kdepim/src/datasource.cpp Wed Jan 7 14:54:09 2009 (r5049) +++ plugins/kdepim/src/datasource.cpp Wed Jan 7 22:16:33 2009 (r5050) @@ -19,50 +19,50 @@ static void connect_wrapper(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) { - osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __PRETTY_FUNCTION__, userdata, info, ctx); - OSyncDataSource *obj = (OSyncDataSource *)osync_objtype_sink_get_userdata(osync_plugin_info_get_sink(info)); - obj->connect(info, ctx); - osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __PRETTY_FUNCTION__, userdata, info, ctx); + OSyncDataSource *obj = (OSyncDataSource *)osync_objtype_sink_get_userdata(osync_plugin_info_get_sink(info)); + obj->connect(info, ctx); + osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); } //-------------------------------------------------------------------------------- static void disconnect_wrapper(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) { - osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __PRETTY_FUNCTION__, userdata, info, ctx); - OSyncDataSource *obj = (OSyncDataSource *)osync_objtype_sink_get_userdata(osync_plugin_info_get_sink(info)); - obj->disconnect(info, ctx); - osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __PRETTY_FUNCTION__, userdata, info, ctx); + OSyncDataSource *obj = (OSyncDataSource *)osync_objtype_sink_get_userdata(osync_plugin_info_get_sink(info)); + obj->disconnect(info, ctx); + osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); } //-------------------------------------------------------------------------------- static void get_changes_wrapper(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) { - osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __PRETTY_FUNCTION__, userdata, info, ctx); - OSyncDataSource *obj = (OSyncDataSource *)osync_objtype_sink_get_userdata(osync_plugin_info_get_sink(info)); - obj->get_changes(info, ctx); - osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __PRETTY_FUNCTION__, userdata, info, ctx); + OSyncDataSource *obj = (OSyncDataSource *)osync_objtype_sink_get_userdata(osync_plugin_info_get_sink(info)); + obj->get_changes(info, ctx); + osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); } //-------------------------------------------------------------------------------- static void commit_wrapper(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx, OSyncChange *chg) { - osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __PRETTY_FUNCTION__, userdata, info, ctx, chg); - OSyncDataSource *obj = (OSyncDataSource *)osync_objtype_sink_get_userdata(osync_plugin_info_get_sink(info)); - obj->commit(info, ctx, chg); - osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __PRETTY_FUNCTION__, userdata, info, ctx, chg); + OSyncDataSource *obj = (OSyncDataSource *)osync_objtype_sink_get_userdata(osync_plugin_info_get_sink(info)); + obj->commit(info, ctx, chg); + osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); } //-------------------------------------------------------------------------------- static void sync_done_wrapper(void *userdata, OSyncPluginInfo *info, OSyncContext *ctx) { - osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __PRETTY_FUNCTION__, userdata, info, ctx); - OSyncDataSource *obj = (OSyncDataSource *)osync_objtype_sink_get_userdata(osync_plugin_info_get_sink(info)); - obj->sync_done(info, ctx); - osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __PRETTY_FUNCTION__, userdata, info, ctx); + OSyncDataSource *obj = (OSyncDataSource *)osync_objtype_sink_get_userdata(osync_plugin_info_get_sink(info)); + obj->sync_done(info, ctx); + osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); } } // extern "C" @@ -72,97 +72,123 @@ bool OSyncDataSource::initialize(OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncError **error) { - osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, plugin, info); + osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, plugin, info); - OSyncObjTypeSink *sink = osync_plugin_info_find_objtype(info, objtype); + OSyncObjTypeSink *sink = osync_plugin_info_find_objtype(info, objtype); - if (sink == NULL) { - // this objtype is not enabled, but this is not an error - osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); - return true; - } - - OSyncObjTypeSinkFunctions functions; - memset(&functions, 0, sizeof(functions)); - functions.connect = connect_wrapper; - functions.disconnect = disconnect_wrapper; - functions.get_changes = get_changes_wrapper; - functions.commit = commit_wrapper; - functions.sync_done = sync_done_wrapper; - - osync_objtype_sink_set_functions(sink, functions, this); - - const char *configdir = osync_plugin_info_get_configdir(info); - QString tablepath = QString("%1/hashtable.db").arg(configdir); - hashtable = osync_hashtable_new(QFile::encodeName(tablepath), objtype, error); - if ( !hashtable ) { - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(error)); - return false; - } - if ( !osync_hashtable_load(hashtable, error) ) - { - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(error)); - return false; - } - - // NOTE: advanced options are per plugin; currently we read the FilterCategory - // for each Resource (later this could be separated by Resource via a different name, etc.) - // read advanced options - OSyncPluginConfig *config = osync_plugin_info_get_config(info); - if ( config ) - { - OSyncList *entry = osync_plugin_config_get_advancedoptions(config); - for (; entry; entry = entry->next) - { - OSyncPluginAdvancedOption *option = static_cast<OSyncPluginAdvancedOption*>(entry->data); - - if ( strcmp(osync_plugin_advancedoption_get_name(option), "FilterCategory") == 0 ) - categories.append(QString::fromUtf8(osync_plugin_advancedoption_get_value(option))); - } - } + if ( !sink ) + { + // this objtype is not enabled, but this is not an error + osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); + return true; + } + + OSyncObjTypeSinkFunctions functions; + memset(&functions, 0, sizeof(functions)); + functions.connect = connect_wrapper; + functions.disconnect = disconnect_wrapper; + functions.get_changes = get_changes_wrapper; + functions.commit = commit_wrapper; + functions.sync_done = sync_done_wrapper; + + osync_objtype_sink_set_functions(sink, functions, this); + + // Request an anchor from the framework. + osync_objtype_sink_enable_anchor(sink, TRUE); + + const char *configdir = osync_plugin_info_get_configdir(info); + QString tablepath = QString("%1/hashtable.db").arg(configdir); + hashtable = osync_hashtable_new(QFile::encodeName(tablepath), objtype, error); + if ( !hashtable ) { + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(error)); + return false; + } + if ( !osync_hashtable_load(hashtable, error) ) + { + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(error)); + return false; + } + + // NOTE: advanced options are per plugin; currently we read the FilterCategory + // for each Resource (later this could be separated by Resource via a different name, etc.) + // read advanced options + OSyncPluginConfig *config = osync_plugin_info_get_config(info); + if ( config ) + { + OSyncList *entry = osync_plugin_config_get_advancedoptions(config); + for (; entry; entry = entry->next) + { + OSyncPluginAdvancedOption *option = static_cast<OSyncPluginAdvancedOption*>(entry->data); + + if ( strcmp(osync_plugin_advancedoption_get_name(option), "FilterCategory") == 0 ) + categories.append(QString::fromUtf8(osync_plugin_advancedoption_get_value(option))); + } + } - osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); - return true; + osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); + return true; } //-------------------------------------------------------------------------------- void OSyncDataSource::connect(OSyncPluginInfo *info, OSyncContext *ctx) { - osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, info, ctx); + osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, info, ctx); - //Detection mechanismn if this is the first sync - QString anchorpath = QString("%1/anchor.db").arg(osync_plugin_info_get_configdir(info)); - if (!osync_anchor_compare(anchorpath, objtype, "true")) { - osync_trace(TRACE_INTERNAL, "Setting slow-sync for %s", objtype); - OSyncObjTypeSink *sink = osync_plugin_info_find_objtype(info, objtype); - osync_objtype_sink_set_slowsync(sink, TRUE); - } - osync_context_report_success(ctx); + // Detection mechanismn if this is the first sync + OSyncError *error = NULL; + osync_bool anchormatch = FALSE; + + OSyncObjTypeSink *sink = osync_plugin_info_find_objtype(info, objtype); + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(sink); + + if ( !osync_anchor_compare(anchor, "true", &anchormatch, &error) ) + { + osync_context_report_osyncerror(ctx, error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(&error)); + osync_error_unref(&error); + return; + } + + if ( !anchormatch ) + { + osync_trace(TRACE_INTERNAL, "Setting slow-sync for %s", objtype); + osync_objtype_sink_set_slowsync(sink, TRUE); + } + osync_context_report_success(ctx); - osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); + osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); } //-------------------------------------------------------------------------------- void OSyncDataSource::sync_done(OSyncPluginInfo *info, OSyncContext *ctx) { - osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, info, ctx); + osync_trace(TRACE_ENTRY, "%s(%p, %p)", __PRETTY_FUNCTION__, info, ctx); - //Detection mechanismn if this is the first sync - QString anchorpath = QString("%1/anchor.db").arg(osync_plugin_info_get_configdir(info)); - osync_anchor_update(anchorpath, objtype, "true"); - osync_context_report_success(ctx); - - OSyncError *error = NULL; - if ( hashtable && !osync_hashtable_save(hashtable, &error) ) - { - osync_context_report_osyncerror(ctx, error); - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(&error)); - osync_error_unref(&error); - } + // Detection mechanismn if this is the first sync + OSyncError *error = NULL; - osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); + OSyncObjTypeSink *sink = osync_plugin_info_find_objtype(info, objtype); + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(sink); + + if ( !osync_anchor_update(anchor, "true", &error) ) + { + osync_context_report_osyncerror(ctx, error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(&error)); + osync_error_unref(&error); + return; + } + osync_context_report_success(ctx); + + if ( hashtable && !osync_hashtable_save(hashtable, &error) ) + { + osync_context_report_osyncerror(ctx, error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(&error)); + osync_error_unref(&error); + } + + osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); } //-------------------------------------------------------------------------------- @@ -170,125 +196,125 @@ bool OSyncDataSource::report_change(OSyncPluginInfo *info, OSyncContext *ctx, QString uid, QString data, QString hash, OSyncObjFormat *objformat) { - osync_trace(TRACE_ENTRY, "%s(%p, %p, %s, (data), (hash), %p)", __PRETTY_FUNCTION__, + osync_trace(TRACE_ENTRY, "%s(%p, %p, %s, (data), (hash), %p)", __PRETTY_FUNCTION__, info, ctx, static_cast<const char*>(uid.utf8()), objformat); - OSyncError *error = NULL; + OSyncError *error = NULL; - OSyncChange *change = osync_change_new(&error); - if (!change) - { - osync_context_report_osyncerror(ctx, error); - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(&error)); - osync_error_unref(&error); - return false; - } - - // Use the hash table to check if the object needs to be reported - osync_change_set_uid(change, uid.utf8()); - osync_change_set_hash(change, hash.utf8()); - - OSyncChangeType changetype = osync_hashtable_get_changetype(hashtable, change); - osync_change_set_changetype(change, changetype); - - // Update change in hashtable ... otherwise it gets deleted! - osync_hashtable_update_change(hashtable, change); - - if ( changetype != OSYNC_CHANGE_TYPE_UNMODIFIED ) - { - char *data_str = strdup((const char *)data.utf8()); - - osync_trace(TRACE_SENSITIVE,"Data:\n%s", data_str); - - OSyncData *odata = osync_data_new(data_str, strlen(data_str), objformat, &error); - if (!odata) - { - osync_context_report_osyncerror(ctx, error); - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(&error)); - osync_error_unref(&error); - osync_change_unref(change); - return false; - } - - osync_data_set_objtype(odata, objtype); - - osync_change_set_data(change, odata); - osync_data_unref(odata); - - osync_context_report_change(ctx, change); - osync_change_unref(change); - } + OSyncChange *change = osync_change_new(&error); + if (!change) + { + osync_context_report_osyncerror(ctx, error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(&error)); + osync_error_unref(&error); + return false; + } + + // Use the hash table to check if the object needs to be reported + osync_change_set_uid(change, uid.utf8()); + osync_change_set_hash(change, hash.utf8()); + + OSyncChangeType changetype = osync_hashtable_get_changetype(hashtable, change); + osync_change_set_changetype(change, changetype); + + // Update change in hashtable ... otherwise it gets deleted! + osync_hashtable_update_change(hashtable, change); + + if ( changetype != OSYNC_CHANGE_TYPE_UNMODIFIED ) + { + char *data_str = strdup((const char *)data.utf8()); + + osync_trace(TRACE_SENSITIVE,"Data:\n%s", data_str); + + OSyncData *odata = osync_data_new(data_str, strlen(data_str), objformat, &error); + if (!odata) + { + osync_context_report_osyncerror(ctx, error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(&error)); + osync_error_unref(&error); + osync_change_unref(change); + return false; + } + + osync_data_set_objtype(odata, objtype); + + osync_change_set_data(change, odata); + osync_data_unref(odata); + + osync_context_report_change(ctx, change); + osync_change_unref(change); + } - osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); - return true; + osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); + return true; } //-------------------------------------------------------------------------------- bool OSyncDataSource::report_deleted(OSyncPluginInfo *info, OSyncContext *ctx, OSyncObjFormat *objformat) { - osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __PRETTY_FUNCTION__, info, ctx, objformat); + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __PRETTY_FUNCTION__, info, ctx, objformat); - OSyncError *error = NULL; - OSyncList *u, *uids = osync_hashtable_get_deleted(hashtable); - OSyncChange *change = NULL; - - for (u=uids; u; u = u->next) { - char *uid = (char *) u->data; - osync_trace(TRACE_INTERNAL, "going to delete entry with uid: %s", uid); - - change = osync_change_new(&error); - if (!change) - goto error; - - osync_change_set_changetype(change, OSYNC_CHANGE_TYPE_DELETED); - osync_change_set_uid(change, uid); - - OSyncData *data = osync_data_new(NULL, 0, objformat, &error); - if (!data) - goto error_free_change; - - osync_data_set_objtype(data, objtype); - osync_change_set_data(change, data); - osync_data_unref(data); - - osync_context_report_change(ctx, change); - osync_hashtable_update_change(hashtable, change); - - osync_change_unref(change); - } - osync_list_free(uids); - osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); - return true; + OSyncError *error = NULL; + OSyncList *u, *uids = osync_hashtable_get_deleted(hashtable); + OSyncChange *change = NULL; + + for (u=uids; u; u = u->next) { + char *uid = (char *) u->data; + osync_trace(TRACE_INTERNAL, "going to delete entry with uid: %s", uid); + + change = osync_change_new(&error); + if (!change) + goto error; + + osync_change_set_changetype(change, OSYNC_CHANGE_TYPE_DELETED); + osync_change_set_uid(change, uid); + + OSyncData *data = osync_data_new(NULL, 0, objformat, &error); + if (!data) + goto error_free_change; + + osync_data_set_objtype(data, objtype); + osync_change_set_data(change, data); + osync_data_unref(data); + + osync_context_report_change(ctx, change); + osync_hashtable_update_change(hashtable, change); + + osync_change_unref(change); + } + osync_list_free(uids); + osync_trace(TRACE_EXIT, "%s", __PRETTY_FUNCTION__); + return true; error_free_change: - osync_change_unref(change); + osync_change_unref(change); error: - osync_context_report_osyncerror(ctx, error); - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(&error)); - osync_error_unref(&error); - return false; + osync_context_report_osyncerror(ctx, error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __PRETTY_FUNCTION__, osync_error_print(&error)); + osync_error_unref(&error); + return false; } //-------------------------------------------------------------------------------- OSyncDataSource::~OSyncDataSource() { - if (hashtable) - osync_hashtable_unref(hashtable); + if (hashtable) + osync_hashtable_unref(hashtable); } //-------------------------------------------------------------------------------- bool OSyncDataSource::has_category(const QStringList &list) const { - if ( categories.isEmpty() ) return true; // no filter defined -> match all + if ( categories.isEmpty() ) return true; // no filter defined -> match all - for (QStringList::const_iterator it = list.begin(); it != list.end(); ++it ) { - if ( categories.contains(*it) ) return true; - } - return false; // not found + for (QStringList::const_iterator it = list.begin(); it != list.end(); ++it ) { + if ( categories.contains(*it) ) return true; + } + return false; // not found } //-------------------------------------------------------------------------------- Modified: plugins/kdepim/src/kdepim_sync.cpp ============================================================================== --- plugins/kdepim/src/kdepim_sync.cpp Wed Jan 7 14:54:09 2009 (r5049) +++ plugins/kdepim/src/kdepim_sync.cpp Wed Jan 7 22:16:33 2009 (r5050) @@ -144,7 +144,7 @@ /* Here we actually tell opensync which sinks are available. For this plugin, we * go through and enable all the sinks */ -osync_bool kde_discover(void *userdata, OSyncPluginInfo *info, OSyncError **error) +osync_bool kde_discover(OSyncPluginInfo *info, void *userdata, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, userdata, info, error); |