|
From: <svn...@op...> - 2009-11-08 16:11:48
|
Author: dgollub Date: Sun Nov 8 17:11:26 2009 New Revision: 5950 URL: http://www.opensync.org/changeset/5950 Log: Marshal/demarhasl the objtype sink also on the plugin initialize phase to get information if plugins provide a get_changes or read function, which are optional and have impact on conflict-handling (e.g. read() and ignore resolution-hanlder) if they aren't available. Modified: trunk/opensync/client/opensync_client.c trunk/opensync/client/opensync_client_internals.h trunk/opensync/client/opensync_client_proxy.c trunk/opensync/client/opensync_client_proxy_internals.h trunk/opensync/ipc/opensync_serializer.c trunk/opensync/ipc/opensync_serializer_internals.h trunk/tests/client-tests/check_proxy.c Modified: trunk/opensync/client/opensync_client.c ============================================================================== --- trunk/opensync/client/opensync_client.c Fri Nov 6 22:34:10 2009 (r5949) +++ trunk/opensync/client/opensync_client.c Sun Nov 8 17:11:26 2009 (r5950) @@ -861,6 +861,10 @@ if (!reply) goto error_finalize; + /* Marshal available ObjType sinks */ + if (!osync_marshal_objtype_sinks(reply, client, FALSE, error)) + goto error_free_message; + if (!osync_queue_send_message(client->outgoing, NULL, reply, error)) goto error_free_message; @@ -957,12 +961,8 @@ OSyncMessage *reply = NULL; OSyncPluginConfig *config = NULL; OSyncList *res = NULL; - unsigned int avail = 0; - OSyncObjTypeSink *sink = NULL; unsigned int num_res = 0; OSyncPluginResource *resource = NULL; - OSyncList *objtypesinks = NULL; - OSyncList *list; config = osync_plugin_info_get_config(client->plugin_info); res = osync_plugin_config_get_resources(config); @@ -984,29 +984,9 @@ if (osync_error_is_set(error)) goto error_free_message; - objtypesinks = osync_plugin_info_get_objtype_sinks(client->plugin_info); - list = objtypesinks; - while(list) { - sink = (OSyncObjTypeSink*)list->data; - if (osync_objtype_sink_is_available(sink)) { - avail++; - } - list = list->next; - } - - if (!osync_message_write_uint(reply, avail, error)) + /* Marshal available ObjType sinks */ + if (!osync_marshal_objtype_sinks(reply, client, TRUE, error)) goto error_free_message; - - list = objtypesinks; - while(list) { - sink = (OSyncObjTypeSink*)list->data; - if (osync_objtype_sink_is_available(sink)) { - if (!osync_marshal_objtype_sink(reply, sink, error)) - goto error_free_message; - } - list = list->next; - } - osync_list_free(objtypesinks); if (!_osync_client_handle_capabilities_message(client, reply, error)) goto error_free_message; @@ -1033,7 +1013,6 @@ return TRUE; error_free_message: - osync_list_free(objtypesinks); osync_message_unref(reply); error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); @@ -2060,3 +2039,9 @@ osync_trace(TRACE_EXIT, "%s", __func__); } + +OSyncPluginInfo *osync_client_get_plugin_info(OSyncClient *client) +{ + osync_return_val_if_fail(client, NULL); + return client->plugin_info; +} Modified: trunk/opensync/client/opensync_client_internals.h ============================================================================== --- trunk/opensync/client/opensync_client_internals.h Fri Nov 6 22:34:10 2009 (r5949) +++ trunk/opensync/client/opensync_client_internals.h Sun Nov 8 17:11:26 2009 (r5950) @@ -31,4 +31,6 @@ osync_bool osync_client_setup_pipes(OSyncClient *client, const char *pipe_path, OSyncError **error); osync_bool osync_client_connect_pipes(OSyncClient *client, OSyncError **error); +OSyncPluginInfo *osync_client_get_plugin_info(OSyncClient *client); + #endif /*OPENSYNC_CLIENT_INTERNALS_H_*/ Modified: trunk/opensync/client/opensync_client_proxy.c ============================================================================== --- trunk/opensync/client/opensync_client_proxy.c Fri Nov 6 22:34:10 2009 (r5949) +++ trunk/opensync/client/opensync_client_proxy.c Sun Nov 8 17:11:26 2009 (r5950) @@ -258,6 +258,10 @@ osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, message, user_data); if (osync_message_get_cmd(message) == OSYNC_MESSAGE_REPLY) { + + if (!osync_demarshal_objtype_sinks(message, proxy, &locerror)) + goto error; + ctx->init_callback(proxy, ctx->init_callback_data, NULL); } else if (osync_message_get_cmd(message) == OSYNC_MESSAGE_ERRORREPLY) { @@ -431,9 +435,7 @@ OSyncClientProxy *proxy = ctx->proxy; OSyncError *error = NULL; OSyncError *locerror = NULL; - unsigned int num_sinks = 0; unsigned int i = 0; - OSyncObjTypeSink *sink = NULL; OSyncMember *member = osync_client_proxy_get_member(proxy); unsigned int num_res = 0; OSyncPluginConfig *config = NULL; @@ -445,22 +447,12 @@ osync_message_read_int(message, &proxy->has_main_sink, &locerror); - osync_message_read_uint(message, &num_sinks, &locerror); if (osync_error_is_set(&locerror)) goto error; - osync_trace(TRACE_INTERNAL, "main sink?: %i, num objs?: %i", proxy->has_main_sink, num_sinks); - - for (i = 0; i < num_sinks; i++) { - if (!osync_demarshal_objtype_sink(message, &sink, &locerror)) - goto error; - - proxy->objtypes = g_list_append(proxy->objtypes, sink); - - if (proxy->member) - osync_member_add_objtype_sink(proxy->member, sink); - } + if (!osync_demarshal_objtype_sinks(message, proxy, &locerror)) + goto error; if (!_osync_client_proxy_read_discover_message(proxy, message, &locerror)) goto error; @@ -1286,6 +1278,15 @@ return TRUE; } +void osync_client_proxy_add_objtype_sink(OSyncClientProxy *proxy, OSyncObjTypeSink *sink) +{ + osync_return_if_fail(proxy); + osync_return_if_fail(sink); + + osync_objtype_sink_ref(sink); + proxy->objtypes = g_list_append(proxy->objtypes, sink); +} + osync_bool osync_client_proxy_initialize(OSyncClientProxy *proxy, initialize_cb callback, void *userdata, const char *formatdir, const char *plugindir, const char *plugin, const char *groupname, const char *configdir, OSyncPluginConfig *config, OSyncError **error) { callContext *ctx = NULL; @@ -1343,8 +1344,7 @@ sink = osync_client_proxy_find_objtype_sink(proxy, objtype); /* TODO: In discovery phase *sink COULD be NULL. Review if this is correct behavior. */ if (sink) { - osync_objtype_sink_ref(sink); - proxy->objtypes = g_list_append(proxy->objtypes, sink); + osync_client_proxy_add_objtype_sink(proxy, sink); } } } Modified: trunk/opensync/client/opensync_client_proxy_internals.h ============================================================================== --- trunk/opensync/client/opensync_client_proxy_internals.h Fri Nov 6 22:34:10 2009 (r5949) +++ trunk/opensync/client/opensync_client_proxy_internals.h Sun Nov 8 17:11:26 2009 (r5950) @@ -76,5 +76,7 @@ osync_bool osync_client_proxy_sync_done(OSyncClientProxy *proxy, sync_done_cb callback, void *userdata, const char *objtype, OSyncError **error); +void osync_client_proxy_add_objtype_sink(OSyncClientProxy *proxy, OSyncObjTypeSink *sink); + #endif /* OSYNC_CLIENT_PROXY_INTERNALS_H_ */ Modified: trunk/opensync/ipc/opensync_serializer.c ============================================================================== --- trunk/opensync/ipc/opensync_serializer.c Fri Nov 6 22:34:10 2009 (r5949) +++ trunk/opensync/ipc/opensync_serializer.c Sun Nov 8 17:11:26 2009 (r5950) @@ -30,6 +30,11 @@ #include "opensync-plugin.h" #include "plugin/opensync_objtype_sink_internals.h" +#include "client/opensync_client_internals.h" +#include "client/opensync_client_proxy_internals.h" + +#include "opensync-group.h" + #include "opensync_serializer.h" #include "opensync_serializer_internals.h" @@ -487,6 +492,82 @@ return FALSE; } +osync_bool osync_marshal_objtype_sinks(OSyncMessage *reply, OSyncClient *client, osync_bool only_available, OSyncError **error) +{ + + unsigned int avail = 0; + OSyncPluginInfo *plugin_info = osync_client_get_plugin_info(client); + OSyncList *list, *objtypesinks = osync_plugin_info_get_objtype_sinks(plugin_info); + OSyncObjTypeSink *sink; + + list = objtypesinks; + while(list) { + sink = (OSyncObjTypeSink*)list->data; + if (!only_available || osync_objtype_sink_is_available(sink)) { + avail++; + } + list = list->next; + } + + if (!osync_message_write_uint(reply, avail, error)) + goto error; + + list = objtypesinks; + while(list) { + sink = (OSyncObjTypeSink*)list->data; + if (!only_available || osync_objtype_sink_is_available(sink)) { + if (!osync_marshal_objtype_sink(reply, sink, error)) + goto error; + } + list = list->next; + } + osync_list_free(objtypesinks); + + return TRUE; + +error: + osync_list_free(objtypesinks); + return FALSE; +} + +osync_bool osync_demarshal_objtype_sinks(OSyncMessage *message, OSyncClientProxy *proxy, OSyncError **error) +{ + OSyncObjTypeSink *sink, *proxy_sink, *member_sink; + unsigned int i, num_sinks; + OSyncMember *member; + + if (!osync_message_read_uint(message, &num_sinks, error)) + goto error; + + osync_trace(TRACE_INTERNAL, "num objs?: %u", num_sinks); + + for (i = 0; i < num_sinks; i++) { + if (!osync_demarshal_objtype_sink(message, &sink, error)) + goto error; + + /* Update the sink if there already exists one */ + if ((proxy_sink = osync_client_proxy_find_objtype_sink(proxy, osync_objtype_sink_get_name(sink)))) { + osync_bool func_read = osync_objtype_sink_get_function_read(sink); + osync_bool func_getchanges = osync_objtype_sink_get_function_getchanges(sink); + + osync_objtype_sink_set_function_read(proxy_sink, func_read); + osync_objtype_sink_set_function_getchanges(proxy_sink, func_getchanges); + } else { + osync_client_proxy_add_objtype_sink(proxy, sink); + } + + if ((member = osync_client_proxy_get_member(proxy)) && + !(member_sink = osync_member_find_objtype_sink(member, osync_objtype_sink_get_name(sink)))) { + osync_member_add_objtype_sink(member, sink); + } + } + + return TRUE; + +error: + return FALSE; +} + osync_bool osync_marshal_error(OSyncMessage *message, OSyncError *marshal_error, OSyncError **error) { osync_assert(message); Modified: trunk/opensync/ipc/opensync_serializer_internals.h ============================================================================== --- trunk/opensync/ipc/opensync_serializer_internals.h Fri Nov 6 22:34:10 2009 (r5949) +++ trunk/opensync/ipc/opensync_serializer_internals.h Sun Nov 8 17:11:26 2009 (r5950) @@ -50,6 +50,9 @@ osync_bool osync_marshal_pluginresource(OSyncMessage *message, OSyncPluginResource *res, OSyncError **error); osync_bool osync_demarshal_pluginresource(OSyncMessage *message, OSyncPluginResource **res, OSyncError **error); +osync_bool osync_marshal_objtype_sinks(OSyncMessage *reply, OSyncClient *client, osync_bool only_available, OSyncError **error); +osync_bool osync_demarshal_objtype_sinks(OSyncMessage *message, OSyncClientProxy *proxy, OSyncError **error); + /*@}*/ #endif /* _OPENSYNC_SERIALIZER_INTERNALS_H_ */ Modified: trunk/tests/client-tests/check_proxy.c ============================================================================== --- trunk/tests/client-tests/check_proxy.c Fri Nov 6 22:34:10 2009 (r5949) +++ trunk/tests/client-tests/check_proxy.c Sun Nov 8 17:11:26 2009 (r5950) @@ -170,7 +170,12 @@ while (init_replies != 1) { g_usleep(100); } +/* TODO: create a mock-sync testcase which doesn't report any objtypes wihtout an initial discover call. + * e.g. empty OSyncPluingconfig + fail_unless(osync_client_proxy_num_objtypes(proxy) == 0, NULL); + + */ fail_unless(osync_client_proxy_discover(proxy, discover_callback, GINT_TO_POINTER(1), &error), NULL); fail_unless(error == NULL, NULL); |