|
From: <svn...@op...> - 2009-11-04 16:07:51
|
Author: dgollub Date: Wed Nov 4 17:07:07 2009 New Revision: 5923 URL: http://www.opensync.org/changeset/5923 Log: Introduce osync_context_report_uid_update() to report mapping changes for async protocolos (e.g. syncml, ...). This context function is useable inside the sync_done() phase. The interface it self is currently NOP. Mapping table update still needs to be implemented. See #1161 Added: trunk/opensync/plugin/opensync_context_internals.h - copied, changed from r5920, trunk/opensync/plugin/opensync_context.h Modified: trunk/opensync.sym trunk/opensync/client/opensync_client.c trunk/opensync/client/opensync_client_proxy.c trunk/opensync/client/opensync_client_proxy_internals.h trunk/opensync/client/opensync_client_proxy_private.h trunk/opensync/engine/opensync_engine.c trunk/opensync/plugin/opensync_context.c trunk/opensync/plugin/opensync_context.h trunk/opensync/plugin/opensync_context_private.h Modified: trunk/opensync.sym ============================================================================== --- trunk/opensync.sym Tue Nov 3 20:28:17 2009 (r5922) +++ trunk/opensync.sym Wed Nov 4 17:07:07 2009 (r5923) @@ -72,6 +72,7 @@ osync_context_report_osyncwarning osync_context_report_slowsync osync_context_report_success +osync_context_report_uid_update osync_context_set_callback osync_context_set_changes_callback osync_context_set_slowsync_callback Modified: trunk/opensync/client/opensync_client.c ============================================================================== --- trunk/opensync/client/opensync_client.c Tue Nov 3 20:28:17 2009 (r5922) +++ trunk/opensync/client/opensync_client.c Wed Nov 4 17:07:07 2009 (r5923) @@ -25,6 +25,7 @@ #include "plugin/opensync_plugin_internals.h" #include "plugin/opensync_objtype_sink_internals.h" #include "plugin/opensync_plugin_info_internals.h" +#include "plugin/opensync_context_internals.h" #include "opensync-helper.h" #include "helper/opensync_hashtable_internals.h" @@ -395,6 +396,56 @@ return; } +static void _osync_client_uid_update_callback(const char *olduid, const char *newuid, OSyncObjTypeSink *sink, void *data) +{ + callContext *baton = NULL; + OSyncError *locerror = NULL; + OSyncClient *client = NULL; + OSyncMessage *message = NULL; + const char *objtype = NULL; + + client = data; + osync_trace(TRACE_ENTRY, "%s(%p, %s, %s, %p, %p)", __func__, __NULLSTR(olduid), __NULLSTR(newuid), sink, data); + + objtype = osync_objtype_sink_get_name(sink); + + /* We don't expect main-sink here */ + osync_assert(objtype); + + message = osync_message_new(OSYNC_MESSAGE_MAPPING_CHANGED, 0, &locerror); + if (!message) + goto error; + + /** objtype */ + if (!osync_message_write_string(message, objtype, &locerror)) + goto error_free_message; + + /** olduid */ + if (!osync_message_write_string(message, olduid, &locerror)) + goto error_free_message; + + /** newuid */ + if (!osync_message_write_string(message, newuid, &locerror)) + goto error_free_message; + + if (!osync_queue_send_message(client->outgoing, NULL, message, &locerror)) + goto error_free_message; + + osync_message_unref(message); + + osync_trace(TRACE_EXIT, "%s", __func__); + return; + + error_free_message: + osync_message_unref(message); + error: + _free_baton(baton); + osync_client_error_shutdown(client, locerror); + osync_error_unref(&locerror); + osync_trace(TRACE_EXIT, "%s", __func__); + return; +} + static void _osync_client_ignored_conflict_callback(OSyncChange *change, void *data) { callContext *baton = NULL; @@ -1449,6 +1500,8 @@ if (!context) goto error; + osync_context_set_uid_update_callback(context, _osync_client_uid_update_callback, sink, client); + osync_plugin_info_set_sink(client->plugin_info, sink); osync_objtype_sink_sync_done(sink, client->plugin_info, context); Modified: trunk/opensync/client/opensync_client_proxy.c ============================================================================== --- trunk/opensync/client/opensync_client_proxy.c Tue Nov 3 20:28:17 2009 (r5922) +++ trunk/opensync/client/opensync_client_proxy.c Wed Nov 4 17:07:07 2009 (r5923) @@ -827,6 +827,7 @@ OSyncClientProxy *proxy = user_data; OSyncError *error = NULL; OSyncChange *change = NULL; + char *objtype = NULL, *olduid = NULL, *newuid = NULL; osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, message, user_data); @@ -850,13 +851,52 @@ osync_change_unref(change); break; + case OSYNC_MESSAGE_MAPPING_CHANGED: + + osync_assert(proxy->uid_update_callback); + + if (proxy->error) { + osync_trace(TRACE_INTERNAL, "WARNING: Proxy error taintend! Ignoring incoming changes!"); + break; + } + + if (!osync_message_read_string(message, &objtype, &error)) + goto error; + + if (!osync_message_read_string(message, &olduid, &error)) + goto error; + + if (!osync_message_read_string(message, &newuid, &error)) + goto error; + + proxy->uid_update_callback(proxy, proxy->uid_update_callback_data, objtype, olduid, newuid); + + osync_free(objtype); + osync_free(olduid); + osync_free(newuid); + + objtype = NULL; + olduid = NULL; + newuid = NULL; + + break; + default: break; } osync_trace(TRACE_EXIT, "%s", __func__); return; - error: +error: + if (objtype) + osync_free(objtype); + + if (olduid) + osync_free(olduid); + + if (newuid) + osync_free(newuid); + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); osync_error_unref(&error); } @@ -946,6 +986,14 @@ proxy->change_callback_data = userdata; } +void osync_client_proxy_set_uid_update_callback(OSyncClientProxy *proxy, uid_update_cb cb, void *userdata) +{ + osync_assert(proxy); + + proxy->uid_update_callback = cb; + proxy->uid_update_callback_data = userdata; +} + OSyncMember *osync_client_proxy_get_member(OSyncClientProxy *proxy) { osync_assert(proxy); Modified: trunk/opensync/client/opensync_client_proxy_internals.h ============================================================================== --- trunk/opensync/client/opensync_client_proxy_internals.h Tue Nov 3 20:28:17 2009 (r5922) +++ trunk/opensync/client/opensync_client_proxy_internals.h Wed Nov 4 17:07:07 2009 (r5923) @@ -32,6 +32,7 @@ typedef void (* read_cb) (OSyncClientProxy *proxy, void *userdata, OSyncError *error); typedef void (* get_changes_cb) (OSyncClientProxy *proxy, void *userdata, OSyncError *error); typedef void (* change_cb) (OSyncClientProxy *proxy, void *userdata, OSyncChange *change); +typedef void (* uid_update_cb) (OSyncClientProxy *proxy, void *userdata, const char *objtype, const char *olduid, const char *newuid); typedef void (* commit_change_cb) (OSyncClientProxy *proxy, void *userdata, const char *uid, OSyncError *error); typedef void (* committed_all_cb) (OSyncClientProxy *proxy, void *userdata, OSyncError *error); typedef void (* sync_done_cb) (OSyncClientProxy *proxy, void *userdata, OSyncError *error); @@ -42,6 +43,7 @@ void osync_client_proxy_set_context(OSyncClientProxy *proxy, GMainContext *ctx); void osync_client_proxy_set_change_callback(OSyncClientProxy *proxy, change_cb cb, void *userdata); +void osync_client_proxy_set_uid_update_callback(OSyncClientProxy *proxy, uid_update_cb cb, void *userdata); OSyncMember *osync_client_proxy_get_member(OSyncClientProxy *proxy); OSYNC_TEST_EXPORT osync_bool osync_client_proxy_spawn(OSyncClientProxy *proxy, OSyncStartType type, const char *path, const char* external_command, OSyncError **error); Modified: trunk/opensync/client/opensync_client_proxy_private.h ============================================================================== --- trunk/opensync/client/opensync_client_proxy_private.h Tue Nov 3 20:28:17 2009 (r5922) +++ trunk/opensync/client/opensync_client_proxy_private.h Wed Nov 4 17:07:07 2009 (r5923) @@ -72,6 +72,9 @@ change_cb change_callback; void *change_callback_data; + uid_update_cb uid_update_callback; + void *uid_update_callback_data; + /** Proxy specific error struct */ OSyncError *error; }; Modified: trunk/opensync/engine/opensync_engine.c ============================================================================== --- trunk/opensync/engine/opensync_engine.c Tue Nov 3 20:28:17 2009 (r5922) +++ trunk/opensync/engine/opensync_engine.c Wed Nov 4 17:07:07 2009 (r5923) @@ -172,6 +172,11 @@ osync_converter_path_unref(converter_path); } +static void _osync_engine_receive_uid_update(OSyncClientProxy *proxy, void *userdata, const char *objtype, const char *olduid, const char *newuid) +{ + printf("OBJTYPE: %s OLDUID: %s NEWUID: %s\n", objtype, olduid, newuid); +} + static void _osync_engine_receive_change(OSyncClientProxy *proxy, void *userdata, OSyncChange *change) { OSyncEngine *engine = userdata; @@ -788,6 +793,7 @@ osync_client_proxy_set_context(proxy, engine->context); osync_client_proxy_set_change_callback(proxy, _osync_engine_receive_change, engine); + osync_client_proxy_set_uid_update_callback(proxy, _osync_engine_receive_uid_update, engine); if (osync_plugin_get_start_type(plugin) == OSYNC_START_TYPE_EXTERNAL) { Modified: trunk/opensync/plugin/opensync_context.c ============================================================================== --- trunk/opensync/plugin/opensync_context.c Tue Nov 3 20:28:17 2009 (r5922) +++ trunk/opensync/plugin/opensync_context.c Wed Nov 4 17:07:07 2009 (r5923) @@ -24,6 +24,7 @@ #include "opensync-data.h" #include "opensync_context.h" +#include "opensync_context_internals.h" #include "opensync_context_private.h" OSyncContext *osync_context_new(OSyncError **error) @@ -81,6 +82,14 @@ context->warning_function = warning; } +void osync_context_set_uid_update_callback(OSyncContext *context, OSyncContextUidUpdateFn uid_update_func, OSyncObjTypeSink *sink, void *userdata) +{ + osync_assert(context); + context->uid_update_function = uid_update_func; + context->uid_update_sink = sink; + context->uid_update_data = userdata; +} + void osync_context_report_osyncerror(OSyncContext *context, OSyncError *error) { osync_trace(TRACE_ENTRY, "%s(%p, %p:(%s))", __func__, context, error, osync_error_print(&error)); @@ -168,3 +177,16 @@ osync_trace(TRACE_EXIT, "%s", __func__); } +void osync_context_report_uid_update(OSyncContext *context, const char *olduid, const char *newuid) +{ + osync_trace(TRACE_ENTRY, "%s(%p, %s, %s)", __func__, context, __NULLSTR(olduid), __NULLSTR(newuid)); + + osync_return_if_fail(context); + osync_return_if_fail(olduid); + osync_return_if_fail(newuid); + + context->uid_update_function(olduid, newuid, context->uid_update_sink, context->uid_update_data); + + osync_trace(TRACE_EXIT, "%s", __func__); +} + Modified: trunk/opensync/plugin/opensync_context.h ============================================================================== --- trunk/opensync/plugin/opensync_context.h Tue Nov 3 20:28:17 2009 (r5922) +++ trunk/opensync/plugin/opensync_context.h Wed Nov 4 17:07:07 2009 (r5923) @@ -51,6 +51,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); +OSYNC_EXPORT void osync_context_report_uid_update(OSyncContext *ctx, const char *olduid, const char *newuid); /*@}*/ Copied and modified: trunk/opensync/plugin/opensync_context_internals.h (from r5920, trunk/opensync/plugin/opensync_context.h) ============================================================================== --- trunk/opensync/plugin/opensync_context.h Tue Nov 3 19:20:53 2009 (r5920, copy source) +++ trunk/opensync/plugin/opensync_context_internals.h Wed Nov 4 17:07:07 2009 (r5923) @@ -1,6 +1,7 @@ /* * libopensync - A synchronization framework * Copyright (C) 2004-2005 Armin Bauer <arm...@op...> + * Copyright (C) 2009 Daniel Gollub <go...@b1...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,42 +19,21 @@ * */ -#ifndef _OPENSYNC_CONTEXT_H -#define _OPENSYNC_CONTEXT_H - -OPENSYNC_BEGIN_DECLS +#ifndef _OPENSYNC_CONTEXT_INTERNALS_H +#define _OPENSYNC_CONTEXT_INTERNALS_H /** * @defgroup OSyncContextAPI OpenSync Context - * @ingroup OSyncPlugin - * Public part of OpenSync Context + * @ingroup OSyncPluginInternals + * Internal part of OpenSync Context */ /*@{*/ -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); -OSYNC_EXPORT void osync_context_unref(OSyncContext *context); - -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, ...); -OSYNC_EXPORT void osync_context_report_success(OSyncContext *context); -OSYNC_EXPORT void osync_context_report_osyncerror(OSyncContext *context, OSyncError *error); - -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); +typedef void (* OSyncContextUidUpdateFn) (const char *olduid, const char *newuid, OSyncObjTypeSink *sink, void *); -/*@}*/ +OSYNC_TEST_EXPORT void osync_context_set_uid_update_callback(OSyncContext *context, OSyncContextUidUpdateFn uid_update_func, OSyncObjTypeSink *sink, void *userdata); -OPENSYNC_END_DECLS +/*@}*/ -#endif //_OPENSYNC_CONTEXT_H +#endif /* _OPENSYNC_CONTEXT_INTERNALS_H */ Modified: trunk/opensync/plugin/opensync_context_private.h ============================================================================== --- trunk/opensync/plugin/opensync_context_private.h Tue Nov 3 20:28:17 2009 (r5922) +++ trunk/opensync/plugin/opensync_context_private.h Wed Nov 4 17:07:07 2009 (r5923) @@ -35,6 +35,12 @@ OSyncContextChangeFn changes_function; OSyncContextSlowSyncFn slowsync_function; void *slowsync_data; + + /* uid_update callback */ + OSyncContextUidUpdateFn uid_update_function; + OSyncObjTypeSink *uid_update_sink; + void *uid_update_data; + void *plugindata; int ref_count; }; |