From: <svn...@op...> - 2009-03-28 14:18:33
|
Author: dgollub Date: Sat Mar 28 15:18:21 2009 New Revision: 5376 URL: http://www.opensync.org/changeset/5376 Log: Blind hashtable API port. More port of plugin sink functions and anchor is required. Modified: plugins/gnokii-sync/src/gnokii_calendar.c plugins/gnokii-sync/src/gnokii_contact.c plugins/gnokii-sync/src/gnokii_sync.c plugins/gnokii-sync/src/gnokii_sync.h Modified: plugins/gnokii-sync/src/gnokii_calendar.c ============================================================================== --- plugins/gnokii-sync/src/gnokii_calendar.c Sat Mar 28 15:03:04 2009 (r5375) +++ plugins/gnokii-sync/src/gnokii_calendar.c Sat Mar 28 15:18:21 2009 (r5376) @@ -343,6 +343,7 @@ OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); gn_data *caldata = (gn_data *) malloc(sizeof(gn_data)); @@ -357,8 +358,7 @@ // check for slowsync and prepare the "event" hashtable if needed if (osync_objtype_sink_get_slowsync(sink)) { osync_trace(TRACE_INTERNAL, "slow sync"); - assert(sinkenv->hashtable); - if (!osync_hashtable_slowsync(sinkenv->hashtable, &error)) { + if (!osync_hashtable_slowsync(hashtable, &error)) { osync_context_report_osyncerror(ctx, error); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); return; @@ -383,13 +383,13 @@ osync_change_set_hash(change, hash); g_free(hash); - OSyncChangeType type = osync_hashtable_get_changetype(sinkenv->hashtable, change); + OSyncChangeType type = osync_hashtable_get_changetype(hashtable, change); osync_change_set_changetype(change, type); /* Once hash and uid is set to change object - report it! Otherwise the hashtable will declare it as deleted. */ - //osync_hashtable_report(sinkenv->hashtable, change); - osync_hashtable_update_change(sinkenv->hashtable, change); + //osync_hashtable_report(hashtable, change); + osync_hashtable_update_change(hashtable, change); if (type == OSYNC_CHANGE_TYPE_UNMODIFIED) { /* Nothing to do. */ @@ -421,8 +421,8 @@ osync_trace(TRACE_INTERNAL, "number of calendar notes: %i", i - 1); - assert(sinkenv->hashtable); - OSyncList *u, *uids = osync_hashtable_get_deleted(sinkenv->hashtable); + assert(hashtable); + OSyncList *u, *uids = osync_hashtable_get_deleted(hashtable); for (u = uids; u; u = u->next) { OSyncChange *change = osync_change_new(&error); if (!change) { @@ -448,7 +448,7 @@ osync_change_set_data(change, odata); osync_data_unref(odata); - osync_hashtable_update_change(sinkenv->hashtable, change); + osync_hashtable_update_change(hashtable, change); osync_context_report_change(ctx, change); @@ -476,6 +476,7 @@ OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); gnokii_sinkenv *sinkenv = osync_objtype_sink_get_userdata(sink); gnokii_environment *env = (gnokii_environment *) plugindata; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); // Get changed calendar note OSyncData *data = osync_change_get_data(change); @@ -529,7 +530,7 @@ /////////// WORKAROUND for "dirty" modify /////////// osync_change_set_changetype(change, OSYNC_CHANGE_TYPE_DELETED); - osync_hashtable_update_change(sinkenv->hashtable, change); + osync_hashtable_update_change(hashtable, change); // update the old UID with the followed UID for the hashtable // - is needed for new memory location @@ -545,7 +546,7 @@ osync_change_set_hash(change, hash); g_free(hash); - //osync_hashtable_update_change(sinkenv->hashtable, change); + //osync_hashtable_update_change(hashtable, change); /* osync_trace(TRACE_INTERNAL, "New CHANGE: %p UID: %s (%s) changetype: %i", @@ -565,7 +566,7 @@ osync_context_report_success(ctx); // update hashtable - osync_hashtable_update_change(sinkenv->hashtable, change); + osync_hashtable_update_change(hashtable, change); osync_trace(TRACE_EXIT, "%s", __func__); return; Modified: plugins/gnokii-sync/src/gnokii_contact.c ============================================================================== --- plugins/gnokii-sync/src/gnokii_contact.c Sat Mar 28 15:03:04 2009 (r5375) +++ plugins/gnokii-sync/src/gnokii_contact.c Sat Mar 28 15:18:21 2009 (r5376) @@ -391,6 +391,7 @@ gn_data *data = osync_try_malloc0(sizeof(gn_data), &error); OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); gnokii_sinkenv *sinkenv = osync_objtype_sink_get_userdata(sink); gnokii_environment *env = (gnokii_environment *) plugindata; @@ -400,7 +401,7 @@ // check for slowsync and prepare the "contact" hashtable if needed if (osync_objtype_sink_get_slowsync(sink)) { osync_trace(TRACE_INTERNAL, "slow sync"); - if (!osync_hashtable_slowsync(sinkenv->hashtable, &error)) { + if (!osync_hashtable_slowsync(hashtable, &error)) { osync_context_report_osyncerror(ctx, error); osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); return; @@ -468,12 +469,12 @@ g_free(hash); /* Once UID and HASH got set - report it! */ - //osync_hashtable_report(sinkenv->hashtable, change); + //osync_hashtable_report(hashtable, change); - OSyncChangeType type = osync_hashtable_get_changetype(sinkenv->hashtable, change); + OSyncChangeType type = osync_hashtable_get_changetype(hashtable, change); osync_change_set_changetype(change, type); - osync_hashtable_update_change(sinkenv->hashtable, change); + osync_hashtable_update_change(hashtable, change); if (type == OSYNC_CHANGE_TYPE_UNMODIFIED) { /* Nothing to do. */ @@ -506,7 +507,7 @@ g_free(data); - 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) { @@ -534,7 +535,7 @@ osync_context_report_change(ctx, change); - osync_hashtable_update_change(sinkenv->hashtable, change); + osync_hashtable_update_change(hashtable, change); osync_change_unref(change); } @@ -561,6 +562,7 @@ OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); gnokii_sinkenv *sinkenv = osync_objtype_sink_get_userdata(sink); gnokii_environment *env = (gnokii_environment *) plugindata; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); // Get changed contact note osync_data_get_data(osync_change_get_data(change), &buf, NULL); @@ -618,7 +620,7 @@ osync_context_report_success(ctx); // update hashtable - osync_hashtable_update_change(sinkenv->hashtable, change); + osync_hashtable_update_change(hashtable, change); osync_trace(TRACE_EXIT, "%s", __func__); Modified: plugins/gnokii-sync/src/gnokii_sync.c ============================================================================== --- plugins/gnokii-sync/src/gnokii_sync.c Sat Mar 28 15:03:04 2009 (r5375) +++ plugins/gnokii-sync/src/gnokii_sync.c Sat Mar 28 15:18:21 2009 (r5376) @@ -32,11 +32,6 @@ while (env->sinks) { gnokii_sinkenv *sinkenv = env->sinks->data; - // close the hashtable - if (sinkenv->hashtable) { - osync_hashtable_unref(sinkenv->hashtable); - } - osync_objtype_sink_unref(sinkenv->sink); g_free(sinkenv); @@ -93,10 +88,6 @@ OSyncObjTypeSink *sink = osync_plugin_info_get_sink(info); gnokii_sinkenv *sinkenv = osync_objtype_sink_get_userdata(sink); - // commit changes to persistent hahstable - if (!osync_hashtable_save(sinkenv->hashtable, &error)) - goto error; - // answer the call osync_context_report_success(ctx); @@ -180,11 +171,6 @@ gnokii_sinkenv *contact_sinkenv = NULL; gnokii_sinkenv *event_sinkenv = NULL; OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); - char *tablepath = g_strdup_printf("%s/hashtable.db", osync_plugin_info_get_configdir(info)); - if (!tablepath) { - osync_error_set(error, OSYNC_ERROR_IO_ERROR, "No memory left for Plugin initialization"); - goto error; - } /* create gnokii_environment which stores config and statemachine for libgnokii */ env = osync_try_malloc0(sizeof(gnokii_environment), error); @@ -247,12 +233,9 @@ env->sinks = g_list_append(env->sinks, contact_sinkenv); - contact_sinkenv->hashtable = osync_hashtable_new(tablepath, "contact", error); - if (!contact_sinkenv->hashtable) - goto error; + /* Request an hashtable from the framework. */ + osync_objtype_sink_enable_hashtable(contact_sinkenv->sink, TRUE); - if (!osync_hashtable_load(contact_sinkenv->hashtable, error)) - goto error; } else { osync_trace(TRACE_INTERNAL, "Contact sink is disable by configuration."); } @@ -283,13 +266,8 @@ goto error; } - event_sinkenv->hashtable = osync_hashtable_new(tablepath, "event", error); - - if (!event_sinkenv->hashtable) - goto error; - - if (!osync_hashtable_load(event_sinkenv->hashtable, error)) - goto error; + /* Request an hashtable from the framework. */ + osync_objtype_sink_enable_hashtable(event_sinkenv->sink, TRUE); env->sinks = g_list_append(env->sinks, event_sinkenv); } else { @@ -297,9 +275,6 @@ } /* end of event sink */ - /* Free Hashtable path */ - g_free(tablepath); - osync_trace(TRACE_EXIT, "%s: %p", __func__, env); return (void *)env; Modified: plugins/gnokii-sync/src/gnokii_sync.h ============================================================================== --- plugins/gnokii-sync/src/gnokii_sync.h Sat Mar 28 15:03:04 2009 (r5375) +++ plugins/gnokii-sync/src/gnokii_sync.h Sat Mar 28 15:18:21 2009 (r5376) @@ -50,7 +50,6 @@ typedef struct { OSyncObjFormat *objformat; OSyncObjTypeSink *sink; - OSyncHashTable *hashtable; } gnokii_sinkenv; #endif /* GNOKII_SYNC_H */ |