From: <svn...@op...> - 2009-05-14 19:25:52
|
Author: Graham Cobb Date: Thu May 14 21:25:40 2009 New Revision: 5643 URL: http://www.opensync.org/changeset/5643 Log: gpe-sync: Bug #1082 - hashtable changes Modified: plugins/gpe/ChangeLog plugins/gpe/src/calendar.c plugins/gpe/src/contacts.c plugins/gpe/src/gpe_sync.c plugins/gpe/src/gpe_sync.h plugins/gpe/src/todo.c plugins/gpe/src/utils.c Modified: plugins/gpe/ChangeLog ============================================================================== --- plugins/gpe/ChangeLog Thu May 14 21:04:43 2009 (r5642) +++ plugins/gpe/ChangeLog Thu May 14 21:25:40 2009 (r5643) @@ -1,5 +1,12 @@ 2009-05-14 Graham Cobb <g+...@co...> + * src/gpe_sync.h: Bug #1082: Hashtable changes: remove hashtable + pointer from sink_environment + + * src/gpe_sync.c (sync_done): Bug #1082: Hashtable changes: do not save anchors + + * src/utils.c, src/todo.c, src/calendar.c, src/contacts.c: Bug #1082: Hashtable changes + * src/calendar.c (gpe_calendar_setup): Bug #1086: Drop OSyncObjTypeSinkFunctions and use new osync_objtype_sink_set_*_func() calls Modified: plugins/gpe/src/calendar.c ============================================================================== --- plugins/gpe/src/calendar.c Thu May 14 21:04:43 2009 (r5642) +++ plugins/gpe/src/calendar.c Thu May 14 21:25:40 2009 (r5643) @@ -31,6 +31,7 @@ { osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p, %p, %p)", __func__, sink, info, ctx, change, userdata); + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); sink_environment *sinkenv = (sink_environment *)userdata; gpe_environment *env = sinkenv->gpe_env; gchar *response = NULL; @@ -42,6 +43,8 @@ gpe_assert(sinkenv == &env->calendar_sink); // Check userdata is being passed correctly + gpe_assert(hashtable); + if (!gpe_assert(env->configured && env->discovered)) { osync_trace(TRACE_ERROR, "GPE plugin not initialised: configured = %d, discovered = %d", env->configured, env->discovered ); osync_context_report_error (ctx, OSYNC_ERROR_GENERIC, "GPE plugin not initialised: configured = %d, discovered = %d", env->configured, env->discovered); @@ -89,7 +92,7 @@ osync_change_set_uid (change, g_strdup (buf)); } osync_change_set_hash (change, modified); - osync_hashtable_update_change (sinkenv->hashtable, change); + osync_hashtable_update_change (hashtable, change); osync_context_report_success(ctx); } else { @@ -122,9 +125,12 @@ OSyncError *error = NULL; sink_environment *sinkenv = (sink_environment *)userdata; gpe_environment *env = sinkenv->gpe_env; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); gpe_assert(sinkenv == &env->calendar_sink); // Check userdata is being passed correctly + gpe_assert(hashtable); + if (!gpe_assert(env->configured && env->discovered)) { osync_trace(TRACE_ERROR, "GPE plugin not initialised: configured = %d, discovered = %d", env->configured, env->discovered ); osync_context_report_error (ctx, OSYNC_ERROR_GENERIC, "GPE plugin not initialised: configured = %d, discovered = %d", env->configured, env->discovered); @@ -133,7 +139,7 @@ if (slowsync) { osync_trace(TRACE_INTERNAL, "Slow sync requested"); - if (!osync_hashtable_slowsync(sinkenv->hashtable, &error)) { + if (!osync_hashtable_slowsync(hashtable, &error)) { osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); osync_context_report_osyncerror(ctx, error); return; @@ -228,14 +234,6 @@ gpe_assert(sinkenv == &env->calendar_sink); // Check sinkenv is being passed correctly - char *tablepath = g_strdup_printf("%s/hashtable.db", osync_plugin_info_get_configdir(info)); - // Note: caller responsible for freeing hashtable on any error - sinkenv->hashtable = osync_hashtable_new(tablepath, "event", error); - g_free(tablepath); - if (!sinkenv->hashtable) goto error; - - if (!osync_hashtable_load(sinkenv->hashtable, error)) goto error; - // Find sink sinkenv->sink = osync_plugin_info_find_objtype(info, "event"); if (!sinkenv->sink) { @@ -243,6 +241,9 @@ goto exit; // No event sink configured. Not an error. } + /* Request a hashtable from the framework. */ + osync_objtype_sink_enable_hashtable(sinkenv->sink, TRUE); + osync_objtype_sink_set_get_changes_func(sinkenv->sink, gpe_calendar_get_changes); osync_objtype_sink_set_commit_func(sinkenv->sink, gpe_calendar_commit_change); osync_objtype_sink_set_userdata(sinkenv->sink, sinkenv); Modified: plugins/gpe/src/contacts.c ============================================================================== --- plugins/gpe/src/contacts.c Thu May 14 21:04:43 2009 (r5642) +++ plugins/gpe/src/contacts.c Thu May 14 21:25:40 2009 (r5643) @@ -31,6 +31,7 @@ { osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p, %p, %p)", __func__, sink, info, ctx, change, userdata); + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); sink_environment *sinkenv = (sink_environment *)userdata; gpe_environment *env = sinkenv->gpe_env; gchar *response = NULL; @@ -89,7 +90,7 @@ osync_change_set_uid (change, g_strdup (buf)); } osync_change_set_hash (change, modified); - osync_hashtable_update_change (sinkenv->hashtable, change); + osync_hashtable_update_change (hashtable, change); osync_context_report_success(ctx); } else { @@ -122,6 +123,7 @@ OSyncError *error = NULL; sink_environment *sinkenv = (sink_environment *)userdata; gpe_environment *env = sinkenv->gpe_env; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); gpe_assert(sinkenv == &env->contact_sink); // Check userdata is being passed correctly @@ -133,7 +135,7 @@ if (slowsync) { osync_trace(TRACE_INTERNAL, "Slow sync requested"); - if (!osync_hashtable_slowsync(sinkenv->hashtable, &error)) { + if (!osync_hashtable_slowsync(hashtable, &error)) { osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); osync_context_report_osyncerror(ctx, error); return; @@ -224,14 +226,6 @@ osync_bool gpe_contacts_setup(sink_environment *sinkenv, gpe_environment *env, OSyncPluginInfo *info, OSyncError **error) { osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p, %p)", __func__, sinkenv, env, info, error); - - char *tablepath = g_strdup_printf("%s/hashtable.db", osync_plugin_info_get_configdir(info)); - // Note: caller responsible for freeing hashtable on any error - sinkenv->hashtable = osync_hashtable_new(tablepath, "contact", error); - g_free(tablepath); - if (!sinkenv->hashtable) goto error; - - if (!osync_hashtable_load(sinkenv->hashtable, error)) goto error; // Find sink sinkenv->sink = osync_plugin_info_find_objtype(info, "contact"); Modified: plugins/gpe/src/gpe_sync.c ============================================================================== --- plugins/gpe/src/gpe_sync.c Thu May 14 21:04:43 2009 (r5642) +++ plugins/gpe/src/gpe_sync.c Thu May 14 21:25:40 2009 (r5643) @@ -441,14 +441,6 @@ //If we use anchors we have to update it now. - // Save hashtables - if (!osync_hashtable_save(env->contact_sink.hashtable, &error)) - goto error; - if (!osync_hashtable_save(env->todo_sink.hashtable, &error)) - goto error; - if (!osync_hashtable_save(env->calendar_sink.hashtable, &error)) - goto error; - //Answer the call osync_context_report_success(ctx); osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); @@ -463,8 +455,6 @@ static void free_sink(sink_environment *sinkenv) { sinkenv->sink = NULL; - if (sinkenv->hashtable) osync_hashtable_unref(sinkenv->hashtable); - sinkenv->hashtable = NULL; } Modified: plugins/gpe/src/gpe_sync.h ============================================================================== --- plugins/gpe/src/gpe_sync.h Thu May 14 21:04:43 2009 (r5642) +++ plugins/gpe/src/gpe_sync.h Thu May 14 21:25:40 2009 (r5643) @@ -40,7 +40,6 @@ typedef struct sink_environment { OSyncObjTypeSink *sink; OSyncObjFormat *objformat; - OSyncHashTable *hashtable; struct gpe_environment *gpe_env; } sink_environment; Modified: plugins/gpe/src/todo.c ============================================================================== --- plugins/gpe/src/todo.c Thu May 14 21:04:43 2009 (r5642) +++ plugins/gpe/src/todo.c Thu May 14 21:25:40 2009 (r5643) @@ -31,6 +31,7 @@ { osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p, %p, %p)", __func__, sink, info, ctx, change, userdata); + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); sink_environment *sinkenv = (sink_environment *)userdata; gpe_environment *env = sinkenv->gpe_env; gchar *response = NULL; @@ -42,6 +43,8 @@ gpe_assert(sinkenv == &env->todo_sink); // Check userdata is being passed correctly + gpe_assert(hashtable); + if (!gpe_assert(env->configured && env->discovered)) { osync_trace(TRACE_ERROR, "GPE plugin not initialised: configured = %d, discovered = %d", env->configured, env->discovered ); osync_context_report_error (ctx, OSYNC_ERROR_GENERIC, "GPE plugin not initialised: configured = %d, discovered = %d", env->configured, env->discovered); @@ -89,7 +92,7 @@ osync_change_set_uid (change, g_strdup(buf)); } osync_change_set_hash (change, modified); - osync_hashtable_update_change (sinkenv->hashtable, change); + osync_hashtable_update_change (hashtable, change); osync_context_report_success(ctx); } else { @@ -123,9 +126,12 @@ OSyncError *error = NULL; sink_environment *sinkenv = (sink_environment *)userdata; gpe_environment *env = sinkenv->gpe_env; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); gpe_assert(sinkenv == &env->todo_sink); // Check userdata is being passed correctly + gpe_assert(hashtable); + if (!gpe_assert(env->configured && env->discovered)) { osync_trace(TRACE_ERROR, "GPE plugin not initialised: configured = %d, discovered = %d", env->configured, env->discovered ); osync_context_report_error (ctx, OSYNC_ERROR_GENERIC, "GPE plugin not initialised: configured = %d, discovered = %d", env->configured, env->discovered); @@ -134,7 +140,7 @@ if (slowsync) { osync_trace(TRACE_INTERNAL, "Slow sync requested"); - if (!osync_hashtable_slowsync(sinkenv->hashtable, &error)) { + if (!osync_hashtable_slowsync(hashtable, &error)) { osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); osync_context_report_osyncerror(ctx, error); return; @@ -225,14 +231,6 @@ { osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p, %p, %p)", __func__, sinkenv, env, info, error); - char *tablepath = g_strdup_printf("%s/hashtable.db", osync_plugin_info_get_configdir(info)); - // Note: caller responsible for freeing hashtable on any error - sinkenv->hashtable = osync_hashtable_new(tablepath, "todo", error); - g_free(tablepath); - if (!sinkenv->hashtable) goto error; - - if (!osync_hashtable_load(sinkenv->hashtable, error)) goto error; - // Find sink sinkenv->sink = osync_plugin_info_find_objtype(info, "todo"); if (!sinkenv->sink) { @@ -240,6 +238,9 @@ goto exit; // No todo sink configured. Not an error. } + /* Request a hashtable from the framework. */ + osync_objtype_sink_enable_hashtable(sinkenv->sink, TRUE); + osync_objtype_sink_set_get_changes_func(sinkenv->sink, gpe_todo_get_changes); osync_objtype_sink_set_commit_func(sinkenv->sink, gpe_todo_commit_change); osync_objtype_sink_set_userdata(sinkenv->sink, sinkenv); Modified: plugins/gpe/src/utils.c ============================================================================== --- plugins/gpe/src/utils.c Thu May 14 21:04:43 2009 (r5642) +++ plugins/gpe/src/utils.c Thu May 14 21:25:40 2009 (r5643) @@ -82,6 +82,7 @@ osync_trace(TRACE_SENSITIVE, "GPE-SYNC %s: reporting item type = %s, uid = %s, hash = %s, string = %s", __func__, type, uid, hash, string); OSyncError *error = NULL; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sinkenv->sink); OSyncData *data = osync_data_new(string, strlen(string)+1, sinkenv->objformat, &error); if (!data) { @@ -109,9 +110,9 @@ osync_change_set_hash (change, hash); osync_change_set_data (change, data); - OSyncChangeType changetype = osync_hashtable_get_changetype(sinkenv->hashtable, change); + OSyncChangeType changetype = osync_hashtable_get_changetype(hashtable, change); osync_change_set_changetype(change, changetype); - osync_hashtable_update_change (sinkenv->hashtable, change); + osync_hashtable_update_change (hashtable, change); if (changetype != OSYNC_CHANGE_TYPE_UNMODIFIED) { osync_context_report_change (ctx, change); @@ -135,10 +136,11 @@ osync_trace(TRACE_ENTRY, "GPE-SYNC %s(%p, %p)", __func__, sinkenv, ctx); OSyncError *error = NULL; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sinkenv->sink); //check for deleted entries ... via hashtable int i; - OSyncList *u, *uids = osync_hashtable_get_deleted(sinkenv->hashtable); + OSyncList *u, *uids = osync_hashtable_get_deleted(hashtable); for (u = uids; u; u = u->next) { OSyncChange *change = osync_change_new(&error); if (!change) { @@ -166,7 +168,7 @@ osync_context_report_change(ctx, change); - osync_hashtable_update_change(sinkenv->hashtable, change); + osync_hashtable_update_change(hashtable, change); osync_change_unref(change); } @@ -174,3 +176,4 @@ osync_trace(TRACE_EXIT, "GPE-SYNC %s", __func__); } + |