From: <svn...@op...> - 2009-08-07 17:55:11
|
Author: bellmich Date: Fri Aug 7 19:54:58 2009 New Revision: 1245 URL: http://libsyncml.opensync.org/changeset/1245 Log: - adapted to reduced SmlLocation API - integrated SmlChangeItem API - disabled find function of write context because the function is never used Modified: trunk/libsyncml/objects/sml_ds_server.c trunk/libsyncml/objects/sml_ds_server.h trunk/libsyncml/objects/sml_ds_server_internals.h Modified: trunk/libsyncml/objects/sml_ds_server.c ============================================================================== --- trunk/libsyncml/objects/sml_ds_server.c Fri Aug 7 19:53:35 2009 (r1244) +++ trunk/libsyncml/objects/sml_ds_server.c Fri Aug 7 19:54:58 2009 (r1245) @@ -29,6 +29,7 @@ #include <libsyncml/sml_command.h> #include <libsyncml/sml_elements.h> +/* static SmlWriteContext *_write_context_find(SmlDsSession *dsession, const gchar *uid, SmlChangeType type) { smlTrace(TRACE_ENTRY, "%s(%p, %s, %i)", __func__, dsession, VA_STRING(uid), type); @@ -37,7 +38,10 @@ GList *c = NULL; for (c = dsession->pendingChanges; c; c = c->next) { SmlWriteContext *ctx = c->data; - if (!strcmp(uid, ctx->uid) && ctx->type == type) { + SmlLocation *loc = sml_change_item_get_location(ctx->item); + const char *uri = sml_location_get_full_uri(loc); + if (!strcmp(uid, uri) && + sml_change_item_get_action(ctx->item) == type) { g_mutex_unlock(dsession->pendingChangesLock); smlTrace(TRACE_EXIT, "%s: %p", __func__, ctx); return ctx; @@ -48,6 +52,7 @@ smlTrace(TRACE_EXIT_ERROR, "%s: Not found", __func__); return NULL; } +*/ static void _write_context_free(SmlWriteContext *ctx) { @@ -56,8 +61,8 @@ if (ctx->status) smlStatusUnref(ctx->status); - if (ctx->uid) - smlSafeCFree(&(ctx->uid)); + if (ctx->item) + g_object_unref(ctx->item); smlSafeFree((gpointer *)&ctx); @@ -73,8 +78,6 @@ return; } - smlTrace(TRACE_INTERNAL, "%s: Dispatching: uid %s, Type %i, result %i", __func__, VA_STRING(ctx->uid), ctx->type, smlStatusGetCode(ctx->status)); - ctx->callback(dsession, ctx->status, ctx->userdata); g_mutex_lock(dsession->pendingChangesLock); @@ -609,33 +612,17 @@ gsize i; for (i=0; i < smlCommandGetNumChanges(cmd); i++) { - SmlItem *item = smlCommandGetNthChange(cmd, i); + SmlChangeItem *item = smlCommandGetNthChange(cmd, i); if (!item) { g_set_error(&error, SML_ERROR, SML_ERROR_GENERIC, "Item %i of the command's item list is NULL.", i); goto error; } - /* We'd rather use the target of the change since it already the mapped - * uid (if we are a client for example). If it is not given we use the - * source uri. This has then to be translated by the sync engine of course */ - if ((!smlItemGetSource(item) && !smlItemGetTarget(item))) { - g_set_error(&error, SML_ERROR, SML_ERROR_GENERIC, - "Cannot determine UID because source an target are missing on item %i.", i); - goto error; - } - - char *data = NULL; - gsize size = 0; - if (!smlItemStealData(item, &data, &size, &error)) - goto error; - if (!dsession->recvChangeCallback(dsession, - smlCommandGetChangeType(cmd), - smlItemGetTarget(item) ? sml_location_get_uri(smlItemGetTarget(item)) : sml_location_get_uri(smlItemGetSource(item)), - data, size, - smlItemGetContentType(item), - dsession->recvChangeCallbackUserdata, &error)) + item, + dsession->recvChangeCallbackUserdata, + &error)) goto error; } @@ -658,17 +645,17 @@ dsession->recvChanges = g_list_delete_link(dsession->recvChanges, dsession->recvChanges); } - /* unlock the final event at the manager - * - * If this is called from a test case then the datastore - * is sometimes not registered at a SmlManager. - */ - if (dsession->server->manager) - { - dsession->finalLock = FALSE; - smlManagerSessionFinalLockUnref(dsession->server->manager, dsession->session); - } - else + /* unlock the final event at the manager + * + * If this is called from a test case then the datastore + * is sometimes not registered at a SmlManager. + */ + if (dsession->server->manager) + { + dsession->finalLock = FALSE; + smlManagerSessionFinalLockUnref(dsession->server->manager, dsession->session); + } + else smlTrace(TRACE_INTERNAL, "%s - no manager so should be a test", __func__); } else if (dsession->recvMap && dsession->recvMappingCallback) { while (dsession->recvMap) { @@ -904,7 +891,6 @@ { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, session, cmd, userdata); SmlDsSession *dsession = userdata; - GError *error = NULL; g_mutex_lock(dsession->lock); @@ -915,11 +901,6 @@ smlTrace(TRACE_EXIT, "%s", __func__); return; -error: - g_mutex_unlock(dsession->lock); - smlSessionDispatchEvent(session, SML_SESSION_EVENT_ERROR, NULL, NULL, NULL, error); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, error->message); - g_error_free(error); } /** @brief Gets a already received alert @@ -1093,16 +1074,12 @@ //Send a change to the remote side gboolean smlDsSessionQueueChange (SmlDsSession *dsession, - SmlChangeType type, - const gchar *uid, - const gchar *data, - gsize size, - const gchar *contenttype, + SmlChangeItem *item, SmlDsSessionChangeStatusCb callback, void *userdata, GError **error) { - smlTrace(TRACE_ENTRY, "%s(%p, %i, %s, %p, %i, %s, %p, %p, %p)", __func__, dsession, type, VA_STRING(uid), data, size, VA_STRING(contenttype), callback, userdata, error); + smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p, %p)", __func__, dsession, item, callback, userdata, error); smlAssert(dsession); CHECK_ERROR_REF @@ -1115,7 +1092,7 @@ goto error; } - cmd = smlCommandNewChange(type, uid, data, size, contenttype, error); + cmd = smlCommandNewChange(item, error); if (!cmd) goto error; @@ -1125,8 +1102,8 @@ ctx->callback = callback; ctx->userdata = userdata; - ctx->uid = g_strdup(uid); - ctx->type = type; + ctx->item = item; + g_object_ref(item); ctx->session = dsession; g_mutex_lock(dsession->pendingChangesLock); @@ -1143,7 +1120,7 @@ return TRUE; error: if (ctx) { - smlSafeCFree(&(ctx->uid)); + g_object_unref(ctx->item); smlSafeFree((gpointer *)&ctx); } if (cmd) @@ -1199,9 +1176,6 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; -error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); - return FALSE; } /** @brief Closes the map command Modified: trunk/libsyncml/objects/sml_ds_server.h ============================================================================== --- trunk/libsyncml/objects/sml_ds_server.h Fri Aug 7 19:53:35 2009 (r1244) +++ trunk/libsyncml/objects/sml_ds_server.h Fri Aug 7 19:54:58 2009 (r1245) @@ -36,11 +36,12 @@ typedef struct SmlDsServer SmlDsServer; typedef struct SmlDsSession SmlDsSession; -typedef void (* SmlDsSessionConnectCb) (SmlDsSession *dsession, void *userdata); -typedef gboolean (* SmlDsSessionAlertCb) (SmlDsSession *dsession, SmlAlertType type, const gchar *last, const gchar *next, void *userdata); -typedef void (* SmlDsSessionSyncCb) (SmlDsSession *dsession, gsize numchanges, void *userdata); -typedef gboolean (* SmlDsSessionChangeCb) (SmlDsSession *dsession, SmlChangeType type, const gchar *uid, gchar *data, gsize size, const gchar *contenttype, void *userdata, GError **error); -typedef void (* SmlDsSessionChangeStatusCb) (SmlDsSession *dsession, SmlStatus *status, void *userdata); +typedef void (* SmlDsSessionConnectCb) (SmlDsSession *dsession, void *userdata); +typedef gboolean (* SmlDsSessionAlertCb) (SmlDsSession *dsession, SmlAlertType type, const gchar *last, const gchar *next, void *userdata); +typedef void (* SmlDsSessionSyncCb) (SmlDsSession *dsession, gsize numchanges, void *userdata); +typedef gboolean (* SmlDsSessionChangeCb) (SmlDsSession *dsession, SmlChangeItem *item, void *userdata, GError **error); +typedef void (* SmlDsSessionChangeStatusCb) (SmlDsSession *dsession, SmlStatus *status, void *userdata); +typedef void (* SmlDsSessionMapCb) (SmlDsSession *dsession, SmlMapItem *item, void *userdata); SmlDsServer* smlDsServerNew (const gchar *type, SmlLocation *location, GError **error); SmlDsServer* smlDsClientNew (const gchar *type, SmlLocation *location, SmlLocation *target, GError **error); @@ -64,8 +65,9 @@ void smlDsSessionGetChanges (SmlDsSession *dsession, SmlDsSessionChangeCb chgCallback, void *userdata); void smlDsSessionGetSync (SmlDsSession *dsession, SmlDsSessionSyncCb chgCallback, void *userdata); gboolean smlDsSessionSendSync (SmlDsSession *dsession, gsize num_changes, SmlStatusReplyCb callback, void *userdata, GError **error); -gboolean smlDsSessionQueueChange (SmlDsSession *dsession, SmlChangeType type, const gchar *uid, const gchar *data, gsize size, const gchar *contenttype, SmlDsSessionChangeStatusCb callback, void *userdata, GError **error); +gboolean smlDsSessionQueueChange (SmlDsSession *dsession, SmlChangeItem *item, SmlDsSessionChangeStatusCb callback, void *userdata, GError **error); gboolean smlDsSessionCloseSync (SmlDsSession *dsession, GError **error); +void smlDsSessionGetMapping (SmlDsSession *dsession, SmlDsSessionMapCb mapCallback, void *userdata); gboolean smlDsSessionQueueMap (SmlDsSession *dsession, SmlMapItem *item, GError **error); gboolean smlDsSessionCloseMap (SmlDsSession *dsession, SmlStatusReplyCb callback, void *userdata, GError **error); const gchar* smlDsSessionGetLocation (SmlDsSession *dsession); Modified: trunk/libsyncml/objects/sml_ds_server_internals.h ============================================================================== --- trunk/libsyncml/objects/sml_ds_server_internals.h Fri Aug 7 19:53:35 2009 (r1244) +++ trunk/libsyncml/objects/sml_ds_server_internals.h Fri Aug 7 19:54:58 2009 (r1245) @@ -32,14 +32,11 @@ #include "sml_ds_server.h" -typedef void (* SmlDsSessionMapCb) (SmlDsSession *dsession, SmlMapItem *item, void *userdata); - typedef struct SmlWriteContext { SmlDsSessionChangeStatusCb callback; - gchar *uid; + SmlChangeItem *item; SmlStatus *status; void *userdata; - SmlChangeType type; SmlDsSession *session; } SmlWriteContext; @@ -121,7 +118,5 @@ SmlDsSession* smlDsSessionNew (SmlDsServer *server, SmlSession *session, GError **error); void smlDsSessionFree (SmlDsSession *dsession); -void smlDsSessionGetMapping (SmlDsSession *dsession, SmlDsSessionMapCb mapCallback, void *userdata); - #endif //_SML_DS_SERVER_INTERNALS_H_ /*@}*/ |