From: <svn...@op...> - 2009-03-28 02:13:14
|
Author: dgollub Date: Sat Mar 28 03:13:10 2009 New Revision: 5369 URL: http://www.opensync.org/changeset/5369 Log: Prepare new hashtable interface to request a OSyncHashTable. Similar to the OSyncAnchor request implementation. refs #1082 Modified: trunk/opensync.sym trunk/opensync/client/opensync_client.c trunk/opensync/plugin/opensync_objtype_sink.c trunk/opensync/plugin/opensync_objtype_sink.h trunk/opensync/plugin/opensync_objtype_sink_internals.h trunk/opensync/plugin/opensync_objtype_sink_private.h Modified: trunk/opensync.sym ============================================================================== --- trunk/opensync.sym Sat Mar 28 03:04:57 2009 (r5368) +++ trunk/opensync.sym Sat Mar 28 03:13:10 2009 (r5369) @@ -382,10 +382,12 @@ osync_objtype_sink_connect_done osync_objtype_sink_disconnect osync_objtype_sink_enable_anchor +osync_objtype_sink_enable_hashtable osync_objtype_sink_find_objformat_sink osync_objtype_sink_get_anchor osync_objtype_sink_get_changes osync_objtype_sink_get_getchanges +osync_objtype_sink_get_hashtable osync_objtype_sink_get_name osync_objtype_sink_get_objformat_sinks osync_objtype_sink_get_preferred_format Modified: trunk/opensync/client/opensync_client.c ============================================================================== --- trunk/opensync/client/opensync_client.c Sat Mar 28 03:04:57 2009 (r5368) +++ trunk/opensync/client/opensync_client.c Sat Mar 28 03:13:10 2009 (r5369) @@ -702,6 +702,11 @@ if (!osync_objtype_sink_load_anchor(sink, client->plugin_info, error)) { goto error_finalize; } + + if (!osync_objtype_sink_load_hashtable(sink, client->plugin_info, error)) { + goto error_finalize; + } + } main_sink = osync_plugin_info_get_main_sink(client->plugin_info); Modified: trunk/opensync/plugin/opensync_objtype_sink.c ============================================================================== --- trunk/opensync/plugin/opensync_objtype_sink.c Sat Mar 28 03:04:57 2009 (r5368) +++ trunk/opensync/plugin/opensync_objtype_sink.c Sat Mar 28 03:13:10 2009 (r5369) @@ -23,8 +23,10 @@ #include "opensync-context.h" #include "opensync-format.h" +#include "opensync-helper.h" #include "opensync/helper/opensync_anchor_internals.h" +#include "opensync/helper/opensync_hashtable_internals.h" #include "opensync_plugin_info.h" /* due to osync_plugin_info_get_configdir() */ @@ -80,7 +82,10 @@ if (sink->anchor) osync_anchor_unref(sink->anchor); - + + if (sink->hashtable) + osync_hashtable_unref(sink->hashtable); + if (sink->preferred_format) osync_free(sink->preferred_format); @@ -118,6 +123,33 @@ sink->anchor = osync_anchor_ref(anchor); } +void osync_objtype_sink_enable_hashtable(OSyncObjTypeSink *sink, osync_bool enable) +{ + osync_return_if_fail(sink); + sink->hashtable_requested = enable; +} + +osync_bool osync_objtype_sink_has_hashtable(OSyncObjTypeSink *sink) +{ + osync_return_val_if_fail(sink, FALSE); + return sink->hashtable_requested; +} + +OSyncHashTable *osync_objtype_sink_get_hashtable(OSyncObjTypeSink *sink) +{ + osync_return_val_if_fail(sink, NULL); + return sink->hashtable; +} + +void osync_objtype_sink_set_hashtable(OSyncObjTypeSink *sink, OSyncHashTable *hashtable) +{ + osync_return_if_fail(sink); + if (sink->hashtable) + osync_hashtable_unref(sink->hashtable); + + sink->hashtable = osync_hashtable_ref(hashtable); +} + const char *osync_objtype_sink_get_name(OSyncObjTypeSink *sink) { osync_assert(sink); @@ -745,3 +777,32 @@ return FALSE; } +osync_bool osync_objtype_sink_load_hashtable(OSyncObjTypeSink *sink, OSyncPluginInfo *plugin_info, OSyncError **error) +{ + char *hashtablepath; + + osync_assert(sink); + + if (!osync_objtype_sink_has_hashtable(sink)) + return TRUE; + + /* FIXME: Get rid of file lcoation! + * Later with fruther OSyncDB modifications this should be file-hiarchy indepdendent. + * And The first arg should just consists of the Member ID + */ + hashtablepath = osync_strdup_printf("%s%chashtable.db", + osync_plugin_info_get_configdir(plugin_info), + G_DIR_SEPARATOR); + + sink->hashtable = osync_hashtable_new(hashtablepath, sink->objtype, error); + if (!sink->hashtable) + goto error; + + osync_free(hashtablepath); + + return TRUE; +error: + osync_free(hashtablepath); + return FALSE; +} + Modified: trunk/opensync/plugin/opensync_objtype_sink.h ============================================================================== --- trunk/opensync/plugin/opensync_objtype_sink.h Sat Mar 28 03:04:57 2009 (r5368) +++ trunk/opensync/plugin/opensync_objtype_sink.h Sat Mar 28 03:13:10 2009 (r5369) @@ -113,11 +113,37 @@ * or not. * * @param sink Pointer to the sink - * @returns the name of the object type of the specified sink + * @returns Pointer to the requested OSyncAnchor, or NULL if no anchor is requested * */ OSYNC_EXPORT OSyncAnchor *osync_objtype_sink_get_anchor(OSyncObjTypeSink *sink); +/** @brief Request a hashtable for this Sink + * + * If for this sink a hashtable is required, this needs to be requested by this + * function. If hashtable gets enabled/requested inside the plugin, the framework + * will take care about preparing the hashtable. The created hashtable can be accessed + * by using the function osync_objtype_sink_get_hashtable() + * + * By default no hashtable is requested/enabled. + * + * @param sink Pointer to the sink + * @param enable Flag to enable, disbable hashtable. + * + */ +OSYNC_EXPORT void osync_objtype_sink_enable_hashtable(OSyncObjTypeSink *sink, osync_bool enable); + +/** @brief Get the pointer to the sink OSyncHashTable + * + * This Hashtable is sink specific and can store persistent hash values of changes. + * Designed to help to determine the change type of an entry. + * + * @param sink Pointer to the sink + * @returns the name of the object type of the specified sink + * + */ +OSYNC_EXPORT OSyncHashTable *osync_objtype_sink_get_hashtable(OSyncObjTypeSink *sink); + /** @brief Return the name of the object type of a sink * Modified: trunk/opensync/plugin/opensync_objtype_sink_internals.h ============================================================================== --- trunk/opensync/plugin/opensync_objtype_sink_internals.h Sat Mar 28 03:04:57 2009 (r5368) +++ trunk/opensync/plugin/opensync_objtype_sink_internals.h Sat Mar 28 03:13:10 2009 (r5369) @@ -51,6 +51,36 @@ */ void osync_objtype_sink_set_anchor(OSyncObjTypeSink *sink, OSyncAnchor *anchor); +/** @brief Check if sink has a hashtable request. + * + * @param sink Pointer to the sink + * @returns TRUE if the sink has a hashtable request, FALSE otherwise + */ +osync_bool osync_objtype_sink_has_hashtable(OSyncObjTypeSink *sink); + +/** @brief Set the OSyncHashTable for this sink + * + * This Hashtable is sink specific and can store persistent hash values of changes. + * + * @param sink Pointer to the sink + * @param hashtable Pointer to the Hashtable object + * + */ +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 Modified: trunk/opensync/plugin/opensync_objtype_sink_private.h ============================================================================== --- trunk/opensync/plugin/opensync_objtype_sink_private.h Sat Mar 28 03:04:57 2009 (r5368) +++ trunk/opensync/plugin/opensync_objtype_sink_private.h Sat Mar 28 03:13:10 2009 (r5369) @@ -81,6 +81,12 @@ /** Flag if anchor is requested by plugin */ osync_bool anchor_requested; + /** The sink hashtable if requested by the plugin */ + OSyncHashTable *hashtable; + + /** Flag if hashtable is requested by plugin */ + osync_bool hashtable_requested; + /** The preferred step or target format for the conversion path of this sink */ char *preferred_format; /** The format which can be synchronized by this sink */ |