From: <svn...@op...> - 2009-03-30 08:29:57
|
Author: bricks Date: Mon Mar 30 10:29:50 2009 New Revision: 5460 URL: http://www.opensync.org/changeset/5460 Log: ported tomboy-sync to latest api changes plugin needs an additional review Modified: plugins/tomboy-sync/src/tomboy_sync.c plugins/tomboy-sync/src/tomboy_sync.h plugins/tomboy-sync/src/tomboy_sync_dbus.c plugins/tomboy-sync/src/tomboy_sync_dbus.h plugins/tomboy-sync/src/tomboy_sync_file.c plugins/tomboy-sync/src/tomboy_sync_file.h Modified: plugins/tomboy-sync/src/tomboy_sync.c ============================================================================== --- plugins/tomboy-sync/src/tomboy_sync.c Mon Mar 30 07:00:46 2009 (r5459) +++ plugins/tomboy-sync/src/tomboy_sync.c Mon Mar 30 10:29:50 2009 (r5460) @@ -1,6 +1,6 @@ /* * tomboy-sync - A plugin for the opensync framework - * Copyright (C) 2008 Bjoern Ricks <bjo...@go...> + * Copyright (C) 2008-2009 Bjoern Ricks <bjo...@go...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -33,12 +33,27 @@ if (dir->sink) osync_objtype_sink_unref(dir->sink); - if (dir->hashtable) - osync_hashtable_unref(dir->hashtable); - g_free(dir); } +osync_bool osync_tomboysync_compare_anchor(OSyncAnchor *anchor, OSyncContext *ctx, const char *new_anchor, OSyncError **error) { + + osync_bool anchormatch; + + if ( !osync_anchor_compare(anchor, new_anchor, &anchormatch, error) ) { + /* anchor couldn't be compared */ + goto error; + } + if ( !anchormatch ) { + /* request slow sync */ + osync_context_report_slowsync(ctx); + } + return TRUE; + +error: + return FALSE; +} + /* * validates a uuid and returns true if the uuid has the right format */ @@ -149,14 +164,15 @@ } } } - int i, numobjs = osync_plugin_info_num_objtypes(info); - for (i = 0; i < numobjs; i++) { + OSyncList *objtypes = osync_plugin_info_get_objtype_sinks(info); + OSyncList *o = NULL; + for (o = objtypes; o; o = o->next) { OSyncTomboyDir *dir = osync_try_malloc0(sizeof(OSyncTomboyDir), error); if (!dir) { goto error; } dir->env = tomboyenv; - dir->sink = osync_plugin_info_nth_objtype(info, i); + dir->sink = (OSyncObjTypeSink*)o->data; osync_assert(dir->sink); const char *objtype = osync_objtype_sink_get_name(dir->sink); @@ -183,72 +199,42 @@ } /* All sinks have the same functions of course */ - OSyncObjTypeSinkFunctions functions; - memset(&functions, 0, sizeof(functions)); #ifdef ENABLE_DBUS if ( usedbus ) { osync_trace(TRACE_INTERNAL, "using dbus for sync."); - functions.get_changes = osync_tomboysync_dbus_get_changes; - functions.commit = osync_tomboysync_dbus_commit_change; - functions.read = osync_tomboysync_dbus_read; - functions.write = osync_tomboysync_dbus_write; - functions.sync_done = osync_tomboysync_dbus_sync_done; + osync_objtype_sink_set_connect_func(dir->sink, osync_tomboysync_dbus_connect); + osync_objtype_sink_set_get_changes_func(dir->sink, osync_tomboysync_dbus_get_changes); + osync_objtype_sink_set_commit_func(dir->sink, osync_tomboysync_dbus_commit_change); + osync_objtype_sink_set_read_func(dir->sink, osync_tomboysync_dbus_read); + osync_objtype_sink_set_sync_done_func(dir->sink, osync_tomboysync_dbus_sync_done); } else { #endif /* ENABLE_DBUS */ osync_trace(TRACE_INTERNAL, "using file for sync."); - functions.get_changes = osync_tomboysync_file_get_changes; - functions.commit = osync_tomboysync_file_commit_change; - functions.read = osync_tomboysync_file_read; - functions.write = osync_tomboysync_file_write; - functions.sync_done = osync_tomboysync_file_sync_done; + osync_objtype_sink_set_connect_func(dir->sink, osync_tomboysync_file_connect); + osync_objtype_sink_set_get_changes_func(dir->sink, osync_tomboysync_file_get_changes); + osync_objtype_sink_set_commit_func(dir->sink, osync_tomboysync_file_commit_change); + osync_objtype_sink_set_read_func(dir->sink, osync_tomboysync_file_read); + osync_objtype_sink_set_sync_done_func(dir->sink, osync_tomboysync_file_sync_done); #ifdef ENABLE_DBUS } #endif /* ENABLE_DBUS */ /* We pass the OSyncTomboyDir object to the sink, so we dont have to look it up * again once the functions are called */ - osync_objtype_sink_set_functions(dir->sink, functions, dir); + osync_objtype_sink_set_userdata(dir->sink, dir); - osync_trace(TRACE_INTERNAL, "The configdir: %s", osync_plugin_info_get_configdir(info)); - char *tablepath = g_strdup_printf("%s/hashtable.db", osync_plugin_info_get_configdir(info)); - dir->hashtable = osync_hashtable_new(tablepath, objtype, error); - g_free(tablepath); + /* Request Hashtable */ + osync_objtype_sink_enable_hashtable(dir->sink, TRUE); - if (!dir->hashtable) - goto error; - - if (!osync_hashtable_load(dir->hashtable, error)) - goto error; - - char *path_field = g_strdup_printf("path_%s", osync_objtype_sink_get_name(dir->sink)); - OSyncAnchor *anchor = osync_objtype_sink_get_anchor(dir->sink); - osync_bool anchormatch; + /* Enable Anchors */ + osync_objtype_sink_enable_anchor(dir->sink, TRUE); - if ( !osync_anchor_compare(anchor, tomboyenv->homedir_path, &anchormatch, error) ) { - /* anchor couldn't be compared */ - goto error; - } - if ( !anchormatch ) { - /* request slow sync */ - osync_objtype_sink_set_slowsync(dir->sink, TRUE); - } - g_free(path_field); - -#ifdef ENABLE_DBUS - if (usedbus) { - if (!osync_tomboysync_dbus_initalize(tomboyenv,error)) { + if ( !usedbus ) { + if (!osync_tomboysync_file_initalize(tomboyenv, error)) { goto error; } } - else { -#endif /* ENABLE_DBUS */ - if (!osync_tomboysync_file_initalize(tomboyenv, error)) { - goto error; - } -#ifdef ENABLE_DBUS - } -#endif /* ENABLE_DBUS */ } osync_trace(TRACE_EXIT, "%s: %p", __func__); @@ -294,8 +280,7 @@ osync_plugin_info_set_version(info, version); osync_version_unref(version); - /* we can set here the capabilities, but for the file-sync - * plugin they are static and shipped with opensync */ + /* set here the capabilities in the future */ osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; Modified: plugins/tomboy-sync/src/tomboy_sync.h ============================================================================== --- plugins/tomboy-sync/src/tomboy_sync.h Mon Mar 30 07:00:46 2009 (r5459) +++ plugins/tomboy-sync/src/tomboy_sync.h Mon Mar 30 10:29:50 2009 (r5460) @@ -1,6 +1,6 @@ /* * tomboy-sync - A plugin for the opensync framework - * Copyright (C) 2008 Bjoern Ricks <bjo...@go...> + * Copyright (C) 2008-2009 Bjoern Ricks <bjo...@go...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -53,7 +53,6 @@ typedef struct OSyncTomboyDir { OSyncObjFormat *objformat; // GDir *dir; - OSyncHashTable *hashtable; OSyncObjTypeSink *sink; OSyncTomboyEnv *env; } OSyncTomboyDir; Modified: plugins/tomboy-sync/src/tomboy_sync_dbus.c ============================================================================== --- plugins/tomboy-sync/src/tomboy_sync_dbus.c Mon Mar 30 07:00:46 2009 (r5459) +++ plugins/tomboy-sync/src/tomboy_sync_dbus.c Mon Mar 30 10:29:50 2009 (r5460) @@ -1,6 +1,6 @@ /* * tomboy-sync - A plugin for the opensync framework - * Copyright (C) 2008 Bjoern Ricks <bjo...@go...> + * Copyright (C) 2008-2009 Bjoern Ricks <bjo...@go...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -43,6 +43,7 @@ OSyncError *error = NULL; OSyncData *odata = NULL; OSyncObjFormat *tomboynoteformat = NULL; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); GError *gerror = NULL; char **name_list; char **name_list_ptr; @@ -53,7 +54,7 @@ if ( slow_sync ) { osync_trace(TRACE_INTERNAL, "Slow sync requested"); /* prepare hashtable for slowsync (flush entries) */ - if (!osync_hashtable_slowsync(dir->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)); osync_error_unref(&error); @@ -118,10 +119,10 @@ osync_change_set_hash(change, hash); g_free(hash); - OSyncChangeType type = osync_hashtable_get_changetype(dir->hashtable, change); + OSyncChangeType type = osync_hashtable_get_changetype(hashtable, change); osync_change_set_changetype(change, type); /* if change is modified (other hashvalue then in the hashtable) write the new value to the hashtable */ - osync_hashtable_update_change(dir->hashtable, change); + osync_hashtable_update_change(hashtable, change); if (type == OSYNC_CHANGE_TYPE_UNMODIFIED) { g_free(uuid); @@ -150,7 +151,7 @@ g_strfreev(name_list); /* get all items which weren't changed in osync_tomboysync_file_report_dir. These items have to be deleted */ - OSyncList *u, *uids = osync_hashtable_get_deleted(dir->hashtable); + OSyncList *u, *uids = osync_hashtable_get_deleted(hashtable); for (u = uids; u; u = u->next) { OSyncChange *change = osync_change_new(&error); if (!change) { @@ -177,7 +178,7 @@ osync_context_report_change(ctx, change); - osync_hashtable_update_change(dir->hashtable, change); + osync_hashtable_update_change(hashtable, change); osync_change_unref(change); } @@ -193,6 +194,7 @@ OSyncTomboyDir *dir = (OSyncTomboyDir*)userdata; //OSyncTomboyEnv *tomboyenv = dir->env; OSyncData *odata = NULL; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); int size; char *hash = NULL; @@ -210,7 +212,7 @@ hash = osync_tomboysync_generate_hash(buffer, size); osync_change_set_hash(change, hash); } - osync_hashtable_update_change(dir->hashtable, change); + osync_hashtable_update_change(hashtable, change); osync_context_report_success(ctx); g_free(hash); osync_trace(TRACE_EXIT, "%s", __func__); @@ -229,9 +231,6 @@ goto error; } - if (!osync_hashtable_save(dir->hashtable, &error)) - goto error; - osync_context_report_success(ctx); g_object_unref(dir->env->proxy); @@ -412,23 +411,46 @@ osync_bool osync_tomboysync_dbus_initalize(OSyncTomboyEnv *tomboyenv, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, tomboyenv, error); - osync_assert(tomboyenv); + + return TRUE; +error: + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; +} + +void osync_tomboysync_dbus_connect(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *data) { + + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, sink, info, ctx, data); + + OSyncError *error = NULL; + OSyncTomboyDir *dir = (OSyncTomboyDir*)data; + OSyncTomboyEnv *tomboyenv = dir->env; GError *gerror = NULL; g_type_init(); tomboyenv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &gerror); if (tomboyenv->connection == NULL) { - osync_error_set(error, OSYNC_ERROR_NO_CONNECTION, "Could not connect to dbus. Error \"%s\".", gerror->message); + osync_error_set(&error, OSYNC_ERROR_NO_CONNECTION, "Could not connect to dbus. Error \"%s\".", gerror->message); g_error_free(gerror); goto error; } tomboyenv->proxy = dbus_g_proxy_new_for_name(tomboyenv->connection, TOMBOY_DBUS_NAME, TOMBOY_DBUS_PATH, TOMBOY_DBUS_INTERFACE); - return TRUE; + + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(dir->sink); + + if (!osync_tomboysync_compare_anchor(anchor, ctx, tomboyenv->homedir_path, &error) ) { + goto error; + } + + osync_context_report_success(ctx); + osync_trace(TRACE_EXIT, "%s", __func__); + return; error: - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); - return FALSE; + osync_context_report_osyncerror(ctx, error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); + osync_error_unref(&error); } #endif /* ENABLE_DBUS */ Modified: plugins/tomboy-sync/src/tomboy_sync_dbus.h ============================================================================== --- plugins/tomboy-sync/src/tomboy_sync_dbus.h Mon Mar 30 07:00:46 2009 (r5459) +++ plugins/tomboy-sync/src/tomboy_sync_dbus.h Mon Mar 30 10:29:50 2009 (r5460) @@ -1,6 +1,6 @@ /* * tomboy-sync - A plugin for the opensync framework - * Copyright (C) 2008 Bjoern Ricks <bjo...@go...> + * Copyright (C) 2008-2009 Bjoern Ricks <bjo...@go...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -35,6 +35,8 @@ osync_bool osync_tomboysync_dbus_initalize(OSyncTomboyEnv *tomboyenv, OSyncError **error); +void osync_tomboysync_dbus_connect(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *data); + #endif /* ENABLE_DBUS */ #endif /* TOMBOY_SYNC_DBUS_H_ */ Modified: plugins/tomboy-sync/src/tomboy_sync_file.c ============================================================================== --- plugins/tomboy-sync/src/tomboy_sync_file.c Mon Mar 30 07:00:46 2009 (r5459) +++ plugins/tomboy-sync/src/tomboy_sync_file.c Mon Mar 30 10:29:50 2009 (r5460) @@ -1,6 +1,6 @@ /* * tomboy-sync - A plugin for the opensync framework - * Copyright (C) 2008 Bjoern Ricks <bjo...@go...> + * Copyright (C) 2008-2009 Bjoern Ricks <bjo...@go...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -40,6 +40,7 @@ const char *homedir = tomboyenv->homedir_path; path = g_build_filename(homedir,".tomboy", NULL); osync_trace(TRACE_INTERNAL, "path %s", path); + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(directory->sink); dir = g_dir_open(path, 0, &gerror); if (!dir) { @@ -96,10 +97,10 @@ osync_change_set_hash(change, hash); g_free(hash); - OSyncChangeType type = osync_hashtable_get_changetype(directory->hashtable, change); + OSyncChangeType type = osync_hashtable_get_changetype(hashtable, change); osync_change_set_changetype(change, type); /* if change is modified (other hashvalue then in the hashtable) write the new value to the hashtable */ - osync_hashtable_update_change(directory->hashtable, change); + osync_hashtable_update_change(hashtable, change); if (type == OSYNC_CHANGE_TYPE_UNMODIFIED) { g_free(filename); @@ -149,12 +150,13 @@ OSyncTomboyDir *dir = (OSyncTomboyDir*)userdata; OSyncFormatEnv *formatenv = osync_plugin_info_get_format_env(info); OSyncError *error = NULL; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); /* is slowsync necessary */ if ( slow_sync ) { osync_trace(TRACE_INTERNAL, "Slow sync requested"); /* prepare hashtable for slowsync (flush entries) */ - if (!osync_hashtable_slowsync(dir->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)); @@ -169,7 +171,7 @@ osync_tomboysync_file_report_dir(dir, info, NULL, ctx); /* get all items which weren't changed in osync_tomboysync_file_report_dir. These items have to be deleted */ - OSyncList *u, *uids = osync_hashtable_get_deleted(dir->hashtable); + OSyncList *u, *uids = osync_hashtable_get_deleted(hashtable); for (u = uids; u; u = u->next) { OSyncChange *change = osync_change_new(&error); if (!change) { @@ -198,7 +200,7 @@ osync_context_report_change(ctx, change); - osync_hashtable_update_change(dir->hashtable, change); + osync_hashtable_update_change(hashtable, change); osync_change_unref(change); } @@ -217,6 +219,7 @@ OSyncTomboyDir *dir = (OSyncTomboyDir*)userdata; OSyncTomboyEnv *tomboyenv = dir->env; + OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); char *filename = NULL; char* tomboydir = NULL; @@ -241,7 +244,7 @@ g_free(filename); g_free(tomboydir); - osync_hashtable_update_change(dir->hashtable, change); + osync_hashtable_update_change(hashtable, change); g_free(hash); osync_context_report_success(ctx); @@ -264,9 +267,6 @@ goto error; } - if (!osync_hashtable_save(dir->hashtable, &error)) - goto error; - osync_context_report_success(ctx); osync_trace(TRACE_EXIT, "%s", __func__); @@ -409,7 +409,26 @@ osync_error_unref(&error); return FALSE; } - +void osync_tomboysync_file_connect(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *data) { + osync_trace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, sink, info, ctx, data); + + OSyncError *error = NULL; + OSyncTomboyDir *dir = (OSyncTomboyDir*)data; + OSyncTomboyEnv *tomboyenv = dir->env; + OSyncAnchor *anchor = osync_objtype_sink_get_anchor(dir->sink); + + if (!osync_tomboysync_compare_anchor(anchor, ctx, tomboyenv->homedir_path, &error) ) { + goto error; + } + + osync_context_report_success(ctx); + osync_trace(TRACE_EXIT, "%s", __func__); + return; +error: + osync_context_report_osyncerror(ctx, error); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); + osync_error_unref(&error); +} osync_bool osync_tomboysync_file_initalize(OSyncTomboyEnv *tomboyenv, OSyncError **error) { osync_assert(tomboyenv); osync_assert(tomboyenv->homedir_path); Modified: plugins/tomboy-sync/src/tomboy_sync_file.h ============================================================================== --- plugins/tomboy-sync/src/tomboy_sync_file.h Mon Mar 30 07:00:46 2009 (r5459) +++ plugins/tomboy-sync/src/tomboy_sync_file.h Mon Mar 30 10:29:50 2009 (r5460) @@ -1,6 +1,6 @@ /* * tomboy-sync - A plugin for the opensync framework - * Copyright (C) 2008 Bjoern Ricks <bjo...@go...> + * Copyright (C) 2008-2009 Bjoern Ricks <bjo...@go...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -35,4 +35,6 @@ osync_bool osync_tomboysync_file_initalize(OSyncTomboyEnv *tomboyenv, OSyncError **error); +void osync_tomboysync_file_connect(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx, void *data); + #endif /* TOMBOY_SYNC_FILE_H_ */ |