From: <svn...@op...> - 2009-08-07 17:45:51
|
Author: bellmich Date: Fri Aug 7 19:45:42 2009 New Revision: 1237 URL: http://libsyncml.opensync.org/changeset/1237 Log: - adapted to reduced SmlLocation API - removed useless smlCommandNewPartialChange - removed no longer needed Disable/EnableChanges feature - integrated SmlChangeItem API Modified: trunk/libsyncml/sml_command.c trunk/libsyncml/sml_command.h Modified: trunk/libsyncml/sml_command.c ============================================================================== --- trunk/libsyncml/sml_command.c Fri Aug 7 19:42:46 2009 (r1236) +++ trunk/libsyncml/sml_command.c Fri Aug 7 19:45:42 2009 (r1237) @@ -25,6 +25,7 @@ #include "sml_support.h" #include "parser/sml_xml_assm.h" +#include <libsyncml/data_sync_api/sml_change_item_internals.h> SmlCommandType smlCommandTypeFromString (const gchar *name, @@ -413,8 +414,8 @@ guint i; for (i = 0; i < g_list_length(cmd->private.change.items); i++) { - SmlItem *item = g_list_nth_data(cmd->private.change.items, i); - smlItemUnref(item); + SmlChangeItem *item = g_list_nth_data(cmd->private.change.items, i); + g_object_unref(item); } g_list_free(cmd->private.change.items); } @@ -445,18 +446,14 @@ } SmlCommand* -smlCommandNewChange (SmlChangeType type, - const gchar *uid, - const gchar *data, - gsize size, - const gchar *contenttype, +smlCommandNewChange (SmlChangeItem *item, GError **error) { - smlTrace(TRACE_ENTRY, "%s(%i, %s, %p, %i, %s, %p)", __func__, type, VA_STRING(uid), data, size, VA_STRING(contenttype), error); + smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, item, error); CHECK_ERROR_REF SmlCommand *cmd = NULL; - switch (type) { + switch (sml_change_item_get_action(item)) { case SML_CHANGE_ADD: cmd = smlCommandNew(SML_COMMAND_TYPE_ADD, error); break; @@ -472,23 +469,12 @@ if (!cmd) goto error; - SmlItem *item = smlItemNewForData(data, size, error); - if (!item) - goto error; cmd->private.change.items = g_list_append(NULL, item); if (!cmd->private.change.items) { - smlItemUnref(item); goto error; } - - SmlLocation *loc = sml_location_new(); - if (!loc) { - g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); - goto error; - } - if (!sml_location_set_uri(loc, uid, error)) - goto error; + g_object_ref(item); /* The usage of target and source depends on the role of the * local peer. We cannot determine if the local peer is an @@ -496,96 +482,9 @@ * smlDsSessionQueueChange. So the correct usage of target * and source must be ensured by the XML assembler. */ - smlItemSetSource(item, loc); - if (type != SML_CHANGE_ADD) { - /* If this is an Add command then nobody knows - * which ID the remote peer will be use for this item. - */ - g_object_ref(loc); - smlItemSetTarget(item, loc); - } - g_object_unref(loc); - - if (!smlItemSetContentType(item, contenttype, error)) - goto error; - - smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd); - return cmd; - -error: - if (cmd) - smlCommandUnref(cmd); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); - return NULL; -} - -/** Send a fragmented change. You can use this command to fragment a very large change into several - * objects. - * @param complete_size The overall size of the object. must be the sum over all partial_sizes - * @param partial_size The size of this part. - */ -SmlCommand* -smlCommandNewPartialChange (SmlChangeType type, - const gchar *uid, - const gchar *data, - gsize complete_size, - gsize partial_size, - const gchar *contenttype, - GError **error) -{ - smlTrace(TRACE_ENTRY, "%s(%i, %s, %p, %i, %i, %s, %p)", __func__, type, VA_STRING(uid), data, complete_size, partial_size, VA_STRING(contenttype), error); - CHECK_ERROR_REF - SmlCommand *cmd = NULL; - - switch (type) { - case SML_CHANGE_ADD: - cmd = smlCommandNew(SML_COMMAND_TYPE_ADD, error); - break; - case SML_CHANGE_REPLACE: - cmd = smlCommandNew(SML_COMMAND_TYPE_REPLACE, error); - break; - case SML_CHANGE_DELETE: - cmd = smlCommandNew(SML_COMMAND_TYPE_DELETE, error); - break; - default: - g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Unknown changetype"); - } - if (!cmd) - goto error; - cmd->size = complete_size; - - SmlItem *item = smlItemNewForData(data, partial_size, error); - if (!item) - goto error; - cmd->private.change.items = g_list_append(NULL, item); - if (!cmd->private.change.items) - { - smlItemUnref(item); - goto error; - } - - SmlLocation *loc = sml_location_new(); - if (!loc) { - g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot create new SmlLocation object - out of memory."); - goto error; - } - if (!sml_location_set_uri(loc, uid, error)) - goto error; - - if (type != SML_CHANGE_ADD) { - smlItemSetTarget(item, loc); - } else { - smlItemSetSource(item, loc); - } - g_object_unref(loc); - - smlItemSetMoreData(item, TRUE); - if (!smlItemSetContentType(item, contenttype, error)) - goto error; smlTrace(TRACE_EXIT, "%s: %p", __func__, cmd); return cmd; - error: if (cmd) smlCommandUnref(cmd); @@ -777,14 +676,11 @@ } if (version == SML_DEVINF_VERSION_10) { - if (!sml_location_set_uri(source, "./devinf10", error)) - goto error; + sml_location_set_uri(source, "./devinf10"); } else if (version == SML_DEVINF_VERSION_12) { - if (!sml_location_set_uri(source, "./devinf12", error)) - goto error; + sml_location_set_uri(source, "./devinf12"); } else { - if (!sml_location_set_uri(source, "./devinf11", error)) - goto error; + sml_location_set_uri(source, "./devinf11"); } SmlCommand *result = smlCommandNewResult(cmd, source, data, size, SML_ELEMENT_DEVINF_XML, error); @@ -829,14 +725,11 @@ } if (version == SML_DEVINF_VERSION_10) { - if (!sml_location_set_uri(source, "./devinf10", error)) - goto error; + sml_location_set_uri(source, "./devinf10"); } else if (version == SML_DEVINF_VERSION_12) { - if (!sml_location_set_uri(source, "./devinf12", error)) - goto error; + sml_location_set_uri(source, "./devinf12"); } else { - if (!sml_location_set_uri(source, "./devinf11", error)) - goto error; + sml_location_set_uri(source, "./devinf11"); } if (!source) @@ -887,14 +780,11 @@ } if (version == SML_DEVINF_VERSION_10) { - if (!sml_location_set_uri(target, "./devinf10", error)) - goto error; + sml_location_set_uri(target, "./devinf10"); } else if (version == SML_DEVINF_VERSION_12) { - if (!sml_location_set_uri(target, "./devinf12", error)) - goto error; + sml_location_set_uri(target, "./devinf12"); } else { - if (!sml_location_set_uri(target, "./devinf11", error)) - goto error; + sml_location_set_uri(target, "./devinf11"); } if (!target) @@ -1113,38 +1003,6 @@ return cmd->private.alert.anchor; } -void -smlCommandDisableChanges (SmlCommand *cmd) -{ - smlAssert(cmd); - - if (cmd->private.change.items) - { - guint i; - for (i=0; i < g_list_length(cmd->private.change.items); i++) - { - SmlItem *item = g_list_nth_data(cmd->private.change.items, i); - smlItemSetDisable(item, TRUE); - } - } -} - -void -smlCommandEnableChanges (SmlCommand *cmd) -{ - smlAssert(cmd); - - if (cmd->private.change.items) - { - guint i; - for (i=0; i < g_list_length(cmd->private.change.items); i++) - { - SmlItem *item = g_list_nth_data(cmd->private.change.items, i); - smlItemSetDisable(item, FALSE); - } - } -} - /* NumberOfChanges in sync command */ gsize smlCommandGetNumberOfChanges (SmlCommand *cmd) @@ -1160,7 +1018,7 @@ return g_list_length(cmd->private.change.items); } -SmlItem* +SmlChangeItem* smlCommandGetNthChange (SmlCommand *cmd, gsize n) { @@ -1185,44 +1043,34 @@ } gsize -smlCommandGetNthItemSize (SmlCommand *orig_cmd, +smlCommandGetNthItemSize (SmlCommand *cmd, gsize n, GError **error) { - smlAssert(orig_cmd); - - char *data = NULL; - gsize size = 0; + smlAssert(cmd); - SmlItem *orig_item = g_list_nth_data(orig_cmd->private.change.items, n); - if (!smlItemGetData(orig_item, &data, &size, error)) - goto error; - return size; -error: - return 0; + SmlChangeItem *item = g_list_nth_data(cmd->private.change.items, n); + if (!sml_change_item_get_data(item)) + return 0; + return strlen(sml_change_item_get_data(item)); } SmlCommand* smlCommandGetFragment (SmlCommand *orig_cmd, gsize start, gsize space, - gsize complete_size, GError **error) { smlAssert(orig_cmd); - gchar *data = NULL; - gsize size = 0; - SmlItem *frag_item = NULL; + SmlChangeItem *frag_item = NULL; SmlCommand *frag_cmd = NULL; - SmlItem *orig_item = g_list_nth_data(orig_cmd->private.change.items, 0); - if (!smlItemGetData(orig_item, &data, &size, error)) - goto error; + SmlChangeItem *orig_item = g_list_nth_data(orig_cmd->private.change.items, 0); /* create item fragment */ - frag_item = smlItemGetFragment(orig_item, start, space, error); + frag_item = sml_change_item_get_fragment(orig_item, start, space, error); if (!frag_item) goto error; @@ -1244,14 +1092,14 @@ * command. */ if (start == 0) - frag_cmd->size = complete_size; + frag_cmd->size = strlen(sml_change_item_get_data(orig_item)); return frag_cmd; error: if (frag_cmd) smlCommandUnref(frag_cmd); if (frag_item) - smlItemUnref(frag_item); + g_object_unref(frag_item); return NULL; } @@ -1271,7 +1119,7 @@ smlAssert(target); while(1) { - SmlItem *item = g_list_nth_data(source->private.change.items, start); + SmlChangeItem *item = g_list_nth_data(source->private.change.items, start); if (!item) return; target->private.change.items = g_list_append(target->private.change.items, item); @@ -1283,7 +1131,7 @@ smlCommandFreeFirstChange (SmlCommand *cmd) { smlAssert(cmd); - SmlItem *first = smlCommandGetNthChange(cmd, 0); + SmlChangeItem *first = smlCommandGetNthChange(cmd, 0); cmd->private.change.items = g_list_remove(cmd->private.change.items, first); - smlItemUnref(first); + g_object_unref(first); } Modified: trunk/libsyncml/sml_command.h ============================================================================== --- trunk/libsyncml/sml_command.h Fri Aug 7 19:42:46 2009 (r1236) +++ trunk/libsyncml/sml_command.h Fri Aug 7 19:45:42 2009 (r1237) @@ -32,6 +32,7 @@ #include <libsyncml/syncml.h> #include <libsyncml/dev_inf_api/sml_dev_inf.h> +#include <libsyncml/data_sync_api/sml_change_item.h> #include "sml_elements.h" typedef struct SmlCommand SmlCommand; @@ -61,8 +62,7 @@ SmlCommand* smlCommandNewAlert (SmlAlertType type, SmlLocation *target, SmlLocation *source, const gchar *next, const gchar *last, const gchar *contenttype, GError **error); SmlCommand* smlCommandNewSync (SmlLocation *target, SmlLocation *source, gsize num_changes, GError **error); -SmlCommand* smlCommandNewChange (SmlChangeType type, const gchar *uid, const gchar *data, gsize size, const gchar *contenttype, GError **error); -SmlCommand* smlCommandNewPartialChange (SmlChangeType type, const gchar *uid, const gchar *data, gsize complete_size, gsize partial_size, const gchar *contenttype, GError **error); +SmlCommand* smlCommandNewChange (SmlChangeItem *item, GError **error); SmlCommand* smlCommandNewResult (SmlCommand *cmd, SmlLocation *source, gchar *data, gsize size, const gchar *contenttype, GError **error); SmlCommand* smlCommandNewPut (SmlLocation *target, SmlLocation *source, const gchar *data, gsize size, const gchar *contenttype, GError **error); SmlCommand* smlCommandNewGet (SmlLocation *target, const gchar *contenttype, GError **error); @@ -96,20 +96,18 @@ G_CONST_RETURN gchar *smlCommandTypeToString(SmlCommandType type, GError **error); -void smlCommandDisableChanges (SmlCommand *cmd); -void smlCommandEnableChanges (SmlCommand *cmd); -gsize smlCommandGetNumberOfChanges (SmlCommand *cmd); /* NumberOfChanges in sync command */ -gsize smlCommandGetNumChanges (SmlCommand *cmd); /* number of items in change command */ -SmlItem* smlCommandGetNthChange (SmlCommand *cmd, gsize n); -gsize smlCommandGetNumMappings (SmlCommand *cmd); /* number of items in change command */ -SmlMapItem* smlCommandGetNthMapping (SmlCommand *cmd, gsize n); +gsize smlCommandGetNumberOfChanges (SmlCommand *cmd); /* NumberOfChanges in sync command */ +gsize smlCommandGetNumChanges (SmlCommand *cmd); /* number of items in change command */ +SmlChangeItem* smlCommandGetNthChange (SmlCommand *cmd, gsize n); +gsize smlCommandGetNumMappings (SmlCommand *cmd); /* number of items in change command */ +SmlMapItem* smlCommandGetNthMapping (SmlCommand *cmd, gsize n); SmlStatus* smlCommandResultsGetStatus (SmlCommand *cmd); void smlCommandTransferItems (SmlCommand *source, SmlCommand *target, gsize start); void smlCommandFreeFirstChange (SmlCommand *cmd); gsize smlCommandGetNthItemSize (SmlCommand *orig_cmd, gsize n, GError **error); -SmlCommand* smlCommandGetFragment (SmlCommand *orig_cmd, gsize start, gsize space, gsize complete_size, GError **error); +SmlCommand* smlCommandGetFragment (SmlCommand *orig_cmd, gsize start, gsize space, GError **error); #endif //_SML_COMMAND_H_ |