From: <svn...@op...> - 2009-03-28 13:19:13
|
Author: dgollub Date: Sat Mar 28 14:19:04 2009 New Revision: 5371 URL: http://www.opensync.org/changeset/5371 Log: Dropped following interfaces: osync_hashtable_new osync_hashtable_ref osync_hashtable_unref osync_hashtable_load osync_hashtable_save This affects all plugins using hashtables! Short Porting instruction: - Drop osync_hashtable_{un,}ref() calls (no replacement required) - Drop osync_hashtable_new() (no replacement required) - Drop calls like osync_plugin_info_get_configdir() if they were used to create a hashtable path (obsolete now) - Drop calls of osync_hashtable_save() (no replacement required) - Call osync_objtype_sink_enable_hashtable(OSyncObjTypeSink *sink, TRUE); in plugin init function for each ObjTypeSink - Hashtable will be initilaized and loaded by the Engine right after the plugin init function. Don't expect to get a HashTable pointer in the init function! - You can get an valid OSyncHashTable pointer by calling inside Plugin Sink Functions (e.g. connect, get_changes, commit, sync_done, ...): OSyncHashTable *hashtable = osync_objtype_sink_get_hashtable(sink); - Hashtable get stored after the sync_done() plugin call. No call by plugin required. refs #1082 refs #1083 Modified: trunk/opensync.sym trunk/opensync/client/opensync_client.c trunk/opensync/helper/opensync_hashtable.h trunk/opensync/helper/opensync_hashtable_internals.h trunk/opensync/plugin/opensync_objtype_sink.c trunk/opensync/plugin/opensync_objtype_sink.h trunk/opensync/plugin/opensync_objtype_sink_internals.h Modified: trunk/opensync.sym ============================================================================== --- trunk/opensync.sym Sat Mar 28 07:00:59 2009 (r5370) +++ trunk/opensync.sym Sat Mar 28 14:19:04 2009 (r5371) @@ -197,13 +197,8 @@ osync_hashtable_get_changetype osync_hashtable_get_deleted osync_hashtable_get_hash -osync_hashtable_load -osync_hashtable_new osync_hashtable_num_entries -osync_hashtable_ref -osync_hashtable_save osync_hashtable_slowsync -osync_hashtable_unref osync_hashtable_update_change osync_list_alloc osync_list_append @@ -396,6 +391,7 @@ osync_objtype_sink_is_available osync_objtype_sink_is_enabled osync_objtype_sink_load_anchor +osync_objtype_sink_load_hashtable osync_objtype_sink_new osync_objtype_sink_nth_objformat_sink osync_objtype_sink_num_objformat_sinks Modified: trunk/opensync/client/opensync_client.c ============================================================================== --- trunk/opensync/client/opensync_client.c Sat Mar 28 07:00:59 2009 (r5370) +++ trunk/opensync/client/opensync_client.c Sat Mar 28 14:19:04 2009 (r5371) @@ -27,6 +27,9 @@ #include "plugin/opensync_objtype_sink_internals.h" #include "plugin/opensync_plugin_info_internals.h" +#include "opensync-helper.h" +#include "helper/opensync_hashtable_internals.h" + #include "opensync-ipc.h" #include "ipc/opensync_serializer_internals.h" #include "ipc/opensync_message_internals.h" @@ -1326,6 +1329,7 @@ OSyncMessage *reply = NULL; OSyncObjTypeSink *sink = NULL; OSyncContext *context = NULL; + OSyncHashTable *hashtable = NULL; osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, client, message, error); @@ -1363,6 +1367,15 @@ osync_objtype_sink_sync_done(sink, client->plugin_info, context); osync_context_unref(context); + + /* Check if Hashtable is used */ + if ((hashtable = osync_objtype_sink_get_hashtable(sink))) { + + /* Save Hashtable */ + if (!osync_hashtable_save(hashtable, error)) + goto error; + } + } osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; Modified: trunk/opensync/helper/opensync_hashtable.h ============================================================================== --- trunk/opensync/helper/opensync_hashtable.h Sat Mar 28 07:00:59 2009 (r5370) +++ trunk/opensync/helper/opensync_hashtable.h Sat Mar 28 14:19:04 2009 (r5371) @@ -84,60 +84,6 @@ */ /*@{*/ -/** @brief Creates a hashtable access object - * - * Hashtables can be used to detect what has been changed since - * the last sync. - * - * @param path the full path and file name of the hashtable .db file to load from or create - * @param objtype the object type of the hashtable - * @param error Pointer to an error struct - * @returns A new hashtable, or NULL if an error occurred. - * - */ -OSYNC_EXPORT OSyncHashTable *osync_hashtable_new(const char *path, const char *objtype, OSyncError **error); - -/** @brief Increase the reference count of a hashtable object. - * - * @param table The hashtable to increase the reference count - * @returns Pointer to increased hashtable object - */ -OSYNC_EXPORT OSyncHashTable *osync_hashtable_ref(OSyncHashTable *table); - -/** @brief Decrease the reference count of a hastable object. - * - * The object will be freed if the reference count reaches zero. - * - * @param table The hashtable to decrease the reference count - * - */ -OSYNC_EXPORT void osync_hashtable_unref(OSyncHashTable *table); - - -/** @brief Loads the data in a hashtable from disk - * - * This function must be called to load the hashtable before attempting - * to use it (eg. in your plugin objtype sink initialization code). - * - * @param table The hashtable to load from - * @param error Pointer to an error struct - * @returns TRUE on success or FALSE if an error occurred. - * - */ -OSYNC_EXPORT osync_bool osync_hashtable_load(OSyncHashTable *table, OSyncError **error); - -/** @brief Saves the data in a hashtable to disk - * - * Call this function in your syncdone() plugin sink function. - * - * @param table The hashtable to save - * @param error Pointer to an error struct - * @returns TRUE on success or FALSE if an error occurred. - * - */ -OSYNC_EXPORT osync_bool osync_hashtable_save(OSyncHashTable *table, OSyncError **error); - - /** @brief Prepares the hashtable for a slowsync and flush the entire hashtable * * This function should be called to prepare the hashtable for a slowsync. Modified: trunk/opensync/helper/opensync_hashtable_internals.h ============================================================================== --- trunk/opensync/helper/opensync_hashtable_internals.h Sat Mar 28 07:00:59 2009 (r5370) +++ trunk/opensync/helper/opensync_hashtable_internals.h Sat Mar 28 14:19:04 2009 (r5371) @@ -45,4 +45,57 @@ GString *query; }; +/** @brief Creates a hashtable access object + * + * Hashtables can be used to detect what has been changed since + * the last sync. + * + * @param path the full path and file name of the hashtable .db file to load from or create + * @param objtype the object type of the hashtable + * @param error Pointer to an error struct + * @returns A new hashtable, or NULL if an error occurred. + * + */ +OSYNC_TEST_EXPORT OSyncHashTable *osync_hashtable_new(const char *path, const char *objtype, OSyncError **error); + +/** @brief Increase the reference count of a hashtable object. + * + * @param table The hashtable to increase the reference count + * @returns Pointer to increased hashtable object + */ +OSYNC_TEST_EXPORT OSyncHashTable *osync_hashtable_ref(OSyncHashTable *table); + +/** @brief Decrease the reference count of a hastable object. + * + * The object will be freed if the reference count reaches zero. + * + * @param table The hashtable to decrease the reference count + * + */ +OSYNC_TEST_EXPORT void osync_hashtable_unref(OSyncHashTable *table); + +/** @brief Loads the hashtable + * + * This function must be called to load the hashtable before attempting + * to use it (eg. in your plugin objtype sink initialization code). + * + * @param table The hashtable to load from + * @param error Pointer to an error struct + * @returns TRUE on success or FALSE if an error occurred. + * + */ +OSYNC_TEST_EXPORT osync_bool osync_hashtable_load(OSyncHashTable *table, OSyncError **error); + +/** @brief Saves the data in a hashtable + * + * Call this function in your syncdone() plugin sink function. + * + * @param table The hashtable to save + * @param error Pointer to an error struct + * @returns TRUE on success or FALSE if an error occurred. + * + */ +OSYNC_TEST_EXPORT osync_bool osync_hashtable_save(OSyncHashTable *table, OSyncError **error); + #endif /*_OPENSYNC_HASHTABLE_INTERNALS_H_*/ + Modified: trunk/opensync/plugin/opensync_objtype_sink.c ============================================================================== --- trunk/opensync/plugin/opensync_objtype_sink.c Sat Mar 28 07:00:59 2009 (r5370) +++ trunk/opensync/plugin/opensync_objtype_sink.c Sat Mar 28 14:19:04 2009 (r5371) @@ -785,6 +785,9 @@ if (!osync_objtype_sink_has_hashtable(sink)) return TRUE; + + if (sink->hashtable) + osync_hashtable_unref(sink->hashtable); /* FIXME: Get rid of file lcoation! * Later with fruther OSyncDB modifications this should be file-hiarchy indepdendent. @@ -798,9 +801,15 @@ if (!sink->hashtable) goto error; + if (!osync_hashtable_load(sink->hashtable, error)) + goto error_free_hashtable; + osync_free(hashtablepath); return TRUE; + +error_free_hashtable: + osync_hashtable_unref(sink->hashtable); error: osync_free(hashtablepath); return FALSE; Modified: trunk/opensync/plugin/opensync_objtype_sink.h ============================================================================== --- trunk/opensync/plugin/opensync_objtype_sink.h Sat Mar 28 07:00:59 2009 (r5370) +++ trunk/opensync/plugin/opensync_objtype_sink.h Sat Mar 28 14:19:04 2009 (r5371) @@ -538,6 +538,19 @@ */ OSYNC_EXPORT osync_bool osync_objtype_sink_load_anchor(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncError **error); +/*! @brief Load the Hashtable for a specific Sink if requested + * + * Load (i.e. connects) to the Hashtable. If no Hashtable is requested for this sink + * this functions just returns TRUE. + * + * @param sink Pointer to the sink + * @param info Pointer to the plugin info object + * @param error Pointer to error struct, get set on any error + * @returns TRUE on success, FALSE on any error + * + */ +OSYNC_EXPORT osync_bool osync_objtype_sink_load_hashtable(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncError **error); + /*@}*/ #endif /* _OPENSYNC_OBJTYPE_SINK_H_ */ Modified: trunk/opensync/plugin/opensync_objtype_sink_internals.h ============================================================================== --- trunk/opensync/plugin/opensync_objtype_sink_internals.h Sat Mar 28 07:00:59 2009 (r5370) +++ trunk/opensync/plugin/opensync_objtype_sink_internals.h Sat Mar 28 14:19:04 2009 (r5371) @@ -68,19 +68,6 @@ */ void osync_objtype_sink_set_hashtable(OSyncObjTypeSink *sink, OSyncHashTable *hashtable); -/*! @brief Load the Hashtable for a specific Sink if requested - * - * Load (i.e. connects) to the Hashtable. If no Hashtable is requested for this sink - * this functions just returns TRUE. - * - * @param sink Pointer to the sink - * @param info Pointer to the plugin info object - * @param error Pointer to error struct, get set on any error - * @returns TRUE on success, FALSE on any error - * - */ -osync_bool osync_objtype_sink_load_hashtable(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncError **error); - /** @brief Checks if sink has a read single entries function (read) * * @param sink Pointer to the sink |