From: <svn...@op...> - 2009-03-30 02:35:05
|
Author: dgollub Date: Mon Mar 30 04:34:56 2009 New Revision: 5444 URL: http://www.opensync.org/changeset/5444 Log: Dropped osync_objtype_sink_set_slowsync. Replacment is osync_context_report_slowsync(OSyncContext*) Reporting a slow-sync is only allowed/handled inside the connect() function context. Call this context report function before osync_context_report_success()! For further information see #1085 Furhter changes: * fixing typedef typo in public API * dropped wrong and unused test instrumentation in mock-sync ("LATE-SLOW-SYNC", is about getting not setting slow-sync) * ported example plugins * ported osyncplugin tool * some cleanups inside OSyncClient fixes #1085 Modified: trunk/docs/examples/plugins/src/plugin.c trunk/docs/examples/plugins/src/simple_plugin.c trunk/opensync.sym trunk/opensync/client/opensync_client.c trunk/opensync/plugin/opensync_context.c trunk/opensync/plugin/opensync_context.h trunk/opensync/plugin/opensync_context_private.h trunk/opensync/plugin/opensync_objtype_sink.c trunk/opensync/plugin/opensync_objtype_sink.h trunk/opensync/plugin/opensync_objtype_sink_internals.h trunk/tests/mock-plugin/mock_sync.c trunk/tools/osyncplugin.c Modified: trunk/docs/examples/plugins/src/plugin.c ============================================================================== --- trunk/docs/examples/plugins/src/plugin.c Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/docs/examples/plugins/src/plugin.c Mon Mar 30 04:34:56 2009 (r5444) @@ -47,7 +47,7 @@ } if (!anchormatch) { /* request slow sync */ - osync_objtype_sink_set_slowsync(sink, TRUE); + osync_context_report_slowsync(ctx); } osync_context_report_success(ctx); Modified: trunk/docs/examples/plugins/src/simple_plugin.c ============================================================================== --- trunk/docs/examples/plugins/src/simple_plugin.c Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/docs/examples/plugins/src/simple_plugin.c Mon Mar 30 04:34:56 2009 (r5444) @@ -43,7 +43,7 @@ if (!anchormatch) { /* request slow sync */ - osync_objtype_sink_set_slowsync(sink, TRUE); + osync_context_report_slowsync(ctx); } osync_context_report_success(ctx); Modified: trunk/opensync.sym ============================================================================== --- trunk/opensync.sym Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/opensync.sym Mon Mar 30 04:34:56 2009 (r5444) @@ -45,9 +45,11 @@ osync_context_report_error osync_context_report_osyncerror osync_context_report_osyncwarning +osync_context_report_slowsync osync_context_report_success osync_context_set_callback osync_context_set_changes_callback +osync_context_set_slowsync_callback osync_context_set_warning_callback osync_context_unref osync_converter_detect @@ -412,7 +414,6 @@ osync_objtype_sink_set_read osync_objtype_sink_set_read_func osync_objtype_sink_set_read_timeout -osync_objtype_sink_set_slowsync osync_objtype_sink_set_sync_done_func osync_objtype_sink_set_syncdone_timeout osync_objtype_sink_set_userdata Modified: trunk/opensync/client/opensync_client.c ============================================================================== --- trunk/opensync/client/opensync_client.c Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/opensync/client/opensync_client.c Mon Mar 30 04:34:56 2009 (r5444) @@ -75,7 +75,7 @@ baton->change = change; if (baton->change) osync_change_ref(baton->change); - + osync_context_set_callback(context, callback, baton); return context; @@ -96,6 +96,13 @@ osync_free(baton); } +static void _osync_client_slowsync_callback(void *data) +{ + OSyncObjTypeSink *sink = (OSyncObjTypeSink *) data; + osync_objtype_sink_set_slowsync(sink, TRUE); +} + + static void _osync_client_connect_callback(void *data, OSyncError *error) { OSyncError *locerror = NULL; @@ -104,7 +111,7 @@ OSyncClient *client = NULL; char *objtype = NULL; OSyncObjTypeSink *sink = NULL; - int slowsync = 0; + osync_bool slowsync = FALSE; OSyncMessage *reply = NULL; baton = data; @@ -982,6 +989,8 @@ if (!context) goto error; + osync_context_set_slowsync_callback(context, _osync_client_slowsync_callback, sink); + osync_plugin_info_set_sink(client->plugin_info, sink); osync_objtype_sink_connect(sink, client->plugin_info, context); @@ -1152,13 +1161,6 @@ osync_message_unref(reply); } else { - /* set slowsync (again) if the slow-sync got requested during the connect() call - of a member - and not during frontend/engine itself (e.g. anchor mismatch). */ - if (slowsync) - osync_objtype_sink_set_slowsync(sink, TRUE); - else - osync_objtype_sink_set_slowsync(sink, FALSE); - context = _create_context(client, message, _osync_client_get_changes_callback, NULL, error); if (!context) goto error; @@ -1166,7 +1168,7 @@ osync_plugin_info_set_sink(client->plugin_info, sink); - osync_objtype_sink_get_changes(sink, client->plugin_info, context); + osync_objtype_sink_get_changes(sink, client->plugin_info, slowsync, context); osync_context_unref(context); } Modified: trunk/opensync/plugin/opensync_context.c ============================================================================== --- trunk/opensync/plugin/opensync_context.c Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/opensync/plugin/opensync_context.c Mon Mar 30 04:34:56 2009 (r5444) @@ -68,6 +68,13 @@ context->changes_function = changes; } +void osync_context_set_slowsync_callback(OSyncContext *context, OSyncContextSlowSyncFn slowsync_func, void *userdata) +{ + osync_assert(context); + context->slowsync_function = slowsync_func; + context->slowsync_data = userdata; +} + void osync_context_set_warning_callback(OSyncContext *context, OSyncContextCallbackFn warning) { osync_assert(context); @@ -150,3 +157,14 @@ osync_trace(TRACE_EXIT, "%s", __func__); } + +void osync_context_report_slowsync(OSyncContext *context) +{ + osync_trace(TRACE_ENTRY, "%s(%p)", __func__, context); + osync_assert(context); + + context->slowsync_function(context->slowsync_data); + + osync_trace(TRACE_EXIT, "%s", __func__); +} + Modified: trunk/opensync/plugin/opensync_context.h ============================================================================== --- trunk/opensync/plugin/opensync_context.h Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/opensync/plugin/opensync_context.h Mon Mar 30 04:34:56 2009 (r5444) @@ -33,6 +33,7 @@ typedef void (* OSyncContextCallbackFn)(void *, OSyncError *); typedef void (* OSyncContextChangeFn) (OSyncChange *, void *); +typedef void (* OSyncContextSlowSyncFn) (void *); OSYNC_EXPORT OSyncContext *osync_context_new(OSyncError **error); OSYNC_EXPORT OSyncContext *osync_context_ref(OSyncContext *context); @@ -40,6 +41,7 @@ OSYNC_EXPORT void osync_context_set_callback(OSyncContext *context, OSyncContextCallbackFn callback, void *userdata); OSYNC_EXPORT void osync_context_set_changes_callback(OSyncContext *context, OSyncContextChangeFn changes); +OSYNC_EXPORT void osync_context_set_slowsync_callback(OSyncContext *context, OSyncContextSlowSyncFn slowsync_func, void *userdata); OSYNC_EXPORT void osync_context_set_warning_callback(OSyncContext *context, OSyncContextCallbackFn warning); OSYNC_EXPORT void osync_context_report_error(OSyncContext *context, OSyncErrorType type, const char *format, ...); @@ -48,6 +50,7 @@ OSYNC_EXPORT void osync_context_report_osyncwarning(OSyncContext *context, OSyncError *error); OSYNC_EXPORT void osync_context_report_change(OSyncContext *context, OSyncChange *change); +OSYNC_EXPORT void osync_context_report_slowsync(OSyncContext *contextr); /*@}*/ Modified: trunk/opensync/plugin/opensync_context_private.h ============================================================================== --- trunk/opensync/plugin/opensync_context_private.h Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/opensync/plugin/opensync_context_private.h Mon Mar 30 04:34:56 2009 (r5444) @@ -33,6 +33,8 @@ OSyncContextCallbackFn warning_function; void *callback_data; OSyncContextChangeFn changes_function; + OSyncContextSlowSyncFn slowsync_function; + void *slowsync_data; void *plugindata; int ref_count; }; Modified: trunk/opensync/plugin/opensync_objtype_sink.c ============================================================================== --- trunk/opensync/plugin/opensync_objtype_sink.c Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/opensync/plugin/opensync_objtype_sink.c Mon Mar 30 04:34:56 2009 (r5444) @@ -268,7 +268,7 @@ sink->userdata = userdata; } -void osync_objtype_sink_get_changes(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx) +void osync_objtype_sink_get_changes(OSyncObjTypeSink *sink, OSyncPluginInfo *info, osync_bool slow_sync, OSyncContext *ctx) { OSyncObjTypeSinkFunctions functions; osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, sink, info, ctx); @@ -283,7 +283,7 @@ } else if (!functions.get_changes) { osync_context_report_success(ctx); } else { - functions.get_changes(sink, info, ctx, osync_objtype_sink_get_slowsync(sink), osync_objtype_sink_get_userdata(sink)); + functions.get_changes(sink, info, ctx, slow_sync, osync_objtype_sink_get_userdata(sink)); } osync_trace(TRACE_EXIT, "%s", __func__); @@ -319,7 +319,7 @@ osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, sink, info, ctx); osync_assert(sink); osync_assert(ctx); - + functions = sink->functions; if (!functions.connect) { osync_context_report_success(ctx); @@ -847,7 +847,7 @@ sink->functions.sync_done = sync_done_func; } -void osync_objtype_sink_set_disconnect_func(OSyncObjTypeSink *sink, OSyncSinkConnectFn disconnect_func) +void osync_objtype_sink_set_disconnect_func(OSyncObjTypeSink *sink, OSyncSinkDisconnectFn disconnect_func) { osync_return_if_fail(sink); sink->functions.disconnect = disconnect_func; Modified: trunk/opensync/plugin/opensync_objtype_sink.h ============================================================================== --- trunk/opensync/plugin/opensync_objtype_sink.h Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/opensync/plugin/opensync_objtype_sink.h Mon Mar 30 04:34:56 2009 (r5444) @@ -301,32 +301,17 @@ */ OSYNC_EXPORT void osync_objtype_sink_set_read(OSyncObjTypeSink *sink, osync_bool read); -/** @brief Sets the slow-sync state of a sink - * - * When slow-sync is requested, OpenSync synchronizes all entries rather than - * just the changes. - * - * Slow-sync should be requested if you know that your device's memory has - * been erased. If it is appropriate for your device, you can use OpenSync's - * anchor system to determine if you should request slow-sync. - * - * @param sink Pointer to the sink - * @param slowsync TRUE to request slow-sync, FALSE for normal sync - * - */ -OSYNC_EXPORT void osync_objtype_sink_set_slowsync(OSyncObjTypeSink *sink, osync_bool slowsync); - - /** @brief Queries a sink for the changed objects since the last sync * * Calls the get_changes function on a sink * * @param sink Pointer to the sink * @param info Pointer to the plugin info object + * @param slow_sync Bool to request a Slow Sync if set TRUE * @param ctx The sync context * */ -OSYNC_EXPORT void osync_objtype_sink_get_changes(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext *ctx); +OSYNC_EXPORT void osync_objtype_sink_get_changes(OSyncObjTypeSink *sink, OSyncPluginInfo *info, osync_bool slow_sync, OSyncContext *ctx); /** @brief Reads a single object by its uid * @@ -532,7 +517,7 @@ OSYNC_EXPORT void osync_objtype_sink_set_connect_done_func(OSyncObjTypeSink *sink, OSyncSinkConnectDoneFn connect_done_func); -OSYNC_EXPORT void osync_objtype_sink_set_disconnect_func(OSyncObjTypeSink *sink, OSyncSinkConnectFn disconnect_func); +OSYNC_EXPORT void osync_objtype_sink_set_disconnect_func(OSyncObjTypeSink *sink, OSyncSinkDisconnectFn disconnect_func); /*@}*/ Modified: trunk/opensync/plugin/opensync_objtype_sink_internals.h ============================================================================== --- trunk/opensync/plugin/opensync_objtype_sink_internals.h Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/opensync/plugin/opensync_objtype_sink_internals.h Mon Mar 30 04:34:56 2009 (r5444) @@ -287,6 +287,21 @@ */ osync_bool osync_objtype_sink_get_slowsync(OSyncObjTypeSink *sink); +/** @brief Sets the slow-sync state of a sink + * + * When slow-sync is requested, OpenSync synchronizes all entries rather than + * just the changes. + * + * Slow-sync should be requested if you know that your device's memory has + * been erased. If it is appropriate for your device, you can use OpenSync's + * anchor system to determine if you should request slow-sync. + * + * @param sink Pointer to the sink + * @param slowsync TRUE to request slow-sync, FALSE for normal sync + * + */ +void osync_objtype_sink_set_slowsync(OSyncObjTypeSink *sink, osync_bool slowsync); + /** @brief Returns the number of object formats in the sink * * @param sink Pointer to the sink Modified: trunk/tests/mock-plugin/mock_sync.c ============================================================================== --- trunk/tests/mock-plugin/mock_sync.c Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/tests/mock-plugin/mock_sync.c Mon Mar 30 04:34:56 2009 (r5444) @@ -71,7 +71,7 @@ } if (mock_get_error(info->memberid, "CONNECT_SLOWSYNC")) - osync_objtype_sink_set_slowsync(sink, TRUE); + osync_context_report_slowsync(ctx); /* Skip Objtype related stuff like hashtable and anchor */ if (mock_get_error(info->memberid, "MAINSINK_CONNECT")) @@ -90,7 +90,7 @@ osync_assert_msg(osync_anchor_compare(anchor, dir->path, &anchor_compare_match, NULL), "Not expected to fail"); if (!anchor_compare_match) - osync_objtype_sink_set_slowsync(sink, TRUE); + osync_context_report_slowsync(ctx); osync_assert(g_file_test(dir->path, G_FILE_TEST_IS_DIR)); @@ -115,9 +115,6 @@ if (mock_get_error(info->memberid, "CONNECT_DONE_TIMEOUT")) return; - if (mock_get_error(info->memberid, "LATE_SLOW_SYNC")) - osync_objtype_sink_set_slowsync(sink, TRUE); - /* Validate connect_done() call before get_changes(), * and after connect(). */ Modified: trunk/tools/osyncplugin.c ============================================================================== --- trunk/tools/osyncplugin.c Mon Mar 30 00:50:49 2009 (r5443) +++ trunk/tools/osyncplugin.c Mon Mar 30 04:34:56 2009 (r5444) @@ -41,7 +41,8 @@ char *configfile = NULL; char *configdir = NULL; char *syncgroup = NULL; -osync_bool pluginlist= FALSE; +osync_bool pluginlist = FALSE; +osync_bool connect_requested_slowsync = FALSE; GList *sinks = NULL; GList *cmdlist = NULL; GList *changesList = NULL; @@ -568,16 +569,19 @@ static osync_bool get_changes_sink(Command *cmd, OSyncObjTypeSink *sink, SyncType type, OSyncError **error) { OSyncContext *context = NULL; + osync_bool slowsync = FALSE; + assert(sink); switch (type) { case SYNCTYPE_NORMAL: + slowsync = connect_requested_slowsync; break; case SYNCTYPE_FORCE_FASTSYNC: - osync_objtype_sink_set_slowsync(sink, FALSE); + slowsync = FALSE; break; case SYNCTYPE_FORCE_SLOWSYNC: - osync_objtype_sink_set_slowsync(sink, TRUE); + slowsync = TRUE; break; } @@ -590,7 +594,7 @@ osync_plugin_info_set_sink(plugin_info, sink); - osync_objtype_sink_get_changes(sink, plugin_info, context); + osync_objtype_sink_get_changes(sink, plugin_info, slowsync, context); osync_context_unref(context); @@ -644,6 +648,20 @@ return FALSE; } +static void _osyncplugin_ctx_callback_slowsync(void *user_data) +{ + + OSyncObjTypeSink *sink = (OSyncObjTypeSink *) user_data; + + printf("SlowSync got requested by CONNECT function"); + if (osync_objtype_sink_get_name(sink)) + printf(" for ObjType: \"%s\"", osync_objtype_sink_get_name(sink)); + + connect_requested_slowsync = TRUE; + + printf(".\n"); +} + static void _osyncplugin_ctx_callback_connect(void *user_data, OSyncError *error) { OSyncError *locerror = NULL; @@ -660,16 +678,6 @@ goto error; } - /* - if (osync_objtype_sink_get_slowsync(sink)) { - printf("SlowSync got requested by CONNECT function"); - if (osync_objtype_sink_get_name(sink)) - printf(" for ObjType: \"%s\"", osync_objtype_sink_get_name(sink)); - - printf(".\n"); - } - */ - g_mutex_lock(cmd->mutex); g_cond_signal(cmd->cond); cmd->done = TRUE; @@ -693,9 +701,13 @@ cmd->sink = sink; osync_context_set_callback(context, _osyncplugin_ctx_callback_connect, cmd); + osync_context_set_slowsync_callback(context, _osyncplugin_ctx_callback_slowsync, sink); osync_plugin_info_set_sink(plugin_info, sink); + /* Reset slow-sync state */ + connect_requested_slowsync = FALSE; + osync_objtype_sink_connect(sink, plugin_info, context); osync_context_unref(context); |