From: <svn...@op...> - 2009-08-01 15:24:04
|
Author: bellmich Date: Sat Aug 1 17:23:46 2009 New Revision: 1224 URL: http://libsyncml.opensync.org/changeset/1224 Log: - renamed SmlDataSyncMapItem into SmlMapItem - integrated SmlMapItem into DS API - fixed synchronous map handling (now asynchron) - fixed tests to support asynchronous map handling Added: trunk/libsyncml/data_sync_api/sml_map_item.c trunk/libsyncml/data_sync_api/sml_map_item.h trunk/libsyncml/data_sync_api/sml_map_item_internals.h Deleted: trunk/libsyncml/data_sync_api/sml_data_sync_map_item.c trunk/libsyncml/data_sync_api/sml_data_sync_map_item.h Modified: trunk/libsyncml/CMakeLists.txt trunk/libsyncml/data_sync_api/callbacks.h trunk/libsyncml/data_sync_api/data_sync.c trunk/libsyncml/data_sync_api/data_sync_callbacks.c trunk/libsyncml/data_sync_api/data_sync_callbacks.h trunk/libsyncml/data_sync_api/standard.h trunk/libsyncml/objects/sml_ds_server.c trunk/libsyncml/objects/sml_ds_server.h trunk/libsyncml/objects/sml_ds_server_internals.h trunk/libsyncml/parser/sml_xml_assm.c trunk/libsyncml/parser/sml_xml_parse.c trunk/libsyncml/sml_command.c trunk/libsyncml/sml_elements.c trunk/libsyncml/sml_elements.h trunk/libsyncml/sml_elements_internals.h trunk/libsyncml/sml_session.c trunk/tests/CMakeLists.txt trunk/tests/check_data_sync_api_map_item.c trunk/tests/check_ds.c trunk/tests/check_sync.c Modified: trunk/libsyncml/CMakeLists.txt ============================================================================== --- trunk/libsyncml/CMakeLists.txt Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/CMakeLists.txt Sat Aug 1 17:23:46 2009 (r1224) @@ -24,7 +24,7 @@ data_sync_api/data_sync_client.c data_sync_api/data_sync_server.c data_sync_api/sml_location.c - data_sync_api/sml_data_sync_map_item.c + data_sync_api/sml_map_item.c data_sync_api/transport_http_client.c data_sync_api/transport_http_server.c data_sync_api/transport_obex_client.c @@ -79,7 +79,7 @@ INSTALL( FILES data_sync_api/sml_location.h - data_sync_api/sml_data_sync_map_item.h + data_sync_api/sml_map_item.h data_sync_api/defines.h data_sync_api/standard.h data_sync_api/callbacks.h Modified: trunk/libsyncml/data_sync_api/callbacks.h ============================================================================== --- trunk/libsyncml/data_sync_api/callbacks.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/data_sync_api/callbacks.h Sat Aug 1 17:23:46 2009 (r1224) @@ -31,6 +31,7 @@ #include <libsyncml/data_sync_api/defines.h> #include <libsyncml/data_sync_api/standard.h> #include <libsyncml/dev_inf_api/sml_dev_inf.h> +#include <libsyncml/data_sync_api/sml_map_item.h> #include <glib.h> @@ -69,8 +70,7 @@ typedef gboolean (* SmlDataSyncMappingCallback) ( SmlDataSyncObject *dsObject, const gchar *source, - const gchar *orig, - const gchar *newuid, + SmlMapItem *item, void *userdata, GError **error); typedef gchar *(* SmlDataSyncGetAnchorCallback) ( Modified: trunk/libsyncml/data_sync_api/data_sync.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/data_sync_api/data_sync.c Sat Aug 1 17:23:46 2009 (r1224) @@ -764,8 +764,7 @@ gboolean smlDataSyncAddMapping (SmlDataSyncObject *dsObject, const gchar *source, - const gchar *remoteID, - const gchar *localID, + SmlMapItem *item, GError **error) { smlTrace(TRACE_ENTRY, "%s(%s)", __func__, VA_STRING(source)); @@ -774,8 +773,7 @@ CHECK_ERROR_REF smlAssert(dsObject); smlAssert(source); - smlAssert(remoteID); - smlAssert(localID); + smlAssert(item); /* A map can only be created if a sync from a server was * received. So it makes no sense to cache the mapping. @@ -786,7 +784,7 @@ datastore = smlDataSyncGetDatastoreFromSource(dsObject, source, error); if (!datastore) goto error; - if (!smlDsSessionQueueMap(datastore->session, remoteID, localID, error)) + if (!smlDsSessionQueueMap(datastore->session, item, error)) goto error; smlTrace(TRACE_EXIT, "%s - TRUE", __func__); Modified: trunk/libsyncml/data_sync_api/data_sync_callbacks.c ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_callbacks.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/data_sync_api/data_sync_callbacks.c Sat Aug 1 17:23:46 2009 (r1224) @@ -632,11 +632,10 @@ void smlDataSyncMappingCallback( SmlDsSession *dsession, - SmlLocation *orig, - SmlLocation *newuid, + SmlMapItem *item, void *userdata) { - smlTrace(TRACE_ENTRY, "%s(%p, %s, %s, %p)", __func__, dsession, VA_STRING(sml_location_get_uri(orig)), VA_STRING(sml_location_get_uri(newuid)), userdata); + smlTrace(TRACE_ENTRY, "%s(%p, %s, %s, %p)", __func__, dsession, item, userdata); GError *error = NULL; SmlDataSyncDatastore *datastore = userdata; @@ -647,9 +646,9 @@ /* perform callback */ if (!datastore->dsObject->mappingCallback( - datastore->dsObject, datastore->sourceUri, - sml_location_get_uri(orig), - sml_location_get_uri(newuid), + datastore->dsObject, + datastore->sourceUri, + item, datastore->dsObject->mappingUserdata, &error)) goto error; Modified: trunk/libsyncml/data_sync_api/data_sync_callbacks.h ============================================================================== --- trunk/libsyncml/data_sync_api/data_sync_callbacks.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/data_sync_api/data_sync_callbacks.h Sat Aug 1 17:23:46 2009 (r1224) @@ -90,8 +90,7 @@ void smlDataSyncMappingCallback( SmlDsSession *dsession, - SmlLocation *orig, - SmlLocation *newuid, + SmlMapItem *item, void *userdata); /* ********************************* */ Added: trunk/libsyncml/data_sync_api/sml_map_item.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_map_item.c Sat Aug 1 17:23:46 2009 (r1224) @@ -0,0 +1,300 @@ +/* sml_map_item.c + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include "sml_map_item_internals.h" +#include "../sml_error_internals.h" +#include <string.h> + +G_DEFINE_TYPE (SmlMapItem, sml_map_item, G_TYPE_OBJECT) + +enum +{ + PROP_0, + PROP_REMOTE, + PROP_LOCAL +}; + +struct _SmlMapItemPrivate +{ + SmlLocation* remote; + SmlLocation* local; +}; + +static void +sml_map_item_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_REMOTE: + g_value_set_object (value, SML_MAP_ITEM (object)->priv->remote); + break; + case PROP_LOCAL: + g_value_set_object (value, SML_MAP_ITEM (object)->priv->local); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_map_item_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + switch (property_id) { + case PROP_REMOTE: + if (SML_MAP_ITEM (object)->priv->remote) + g_object_unref (SML_MAP_ITEM (object)->priv->remote); + SML_MAP_ITEM (object)->priv->remote = SML_LOCATION (value); + g_object_ref(SML_MAP_ITEM (object)->priv->remote); + break; + case PROP_LOCAL: + if (SML_MAP_ITEM (object)->priv->local) + g_object_unref (SML_MAP_ITEM (object)->priv->local); + SML_MAP_ITEM (object)->priv->local = SML_LOCATION (value); + g_object_ref(SML_MAP_ITEM (object)->priv->local); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +sml_map_item_finalize (GObject *object) +{ + SmlMapItem *self = (SmlMapItem *) object; + g_object_unref(self->priv->remote); + g_object_unref(self->priv->local); + /* all pointers must be NULL */ + self->priv->remote = NULL; + self->priv->local = NULL; + G_OBJECT_CLASS (sml_map_item_parent_class)->finalize (object); +} + +static void +sml_map_item_class_init (SmlMapItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (SmlMapItemPrivate)); + + object_class->get_property = sml_map_item_get_property; + object_class->set_property = sml_map_item_set_property; + object_class->finalize = sml_map_item_finalize; + + /** + * SmlMapItem:remote: + * + * The remote property. + */ + g_object_class_install_property (object_class, + PROP_REMOTE, + g_param_spec_object ("remote", + "remote", + "remote", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + /** + * SmlMapItem:local: + * + * The local property. + */ + g_object_class_install_property (object_class, + PROP_LOCAL, + g_param_spec_object ("local", + "local", + "local", + G_TYPE_OBJECT, + G_PARAM_READWRITE)); + +} + +static void +sml_map_item_init (SmlMapItem *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + SML_TYPE_MAP_ITEM, + SmlMapItemPrivate); +} + +/** + * sml_map_item_new: + * + * Creates a new instance of #SmlMapItem. + * + * Return value: the newly created #SmlMapItem instance + */ +SmlMapItem* +sml_map_item_new (void) +{ + return g_object_new (SML_TYPE_MAP_ITEM, NULL); +} + +/** + * sml_map_item_get_remote: + * @self: A #SmlMapItem + * + * Gets the remote property. + * + * Return value: + */ +SmlLocation* +sml_map_item_get_remote (SmlMapItem *self) +{ + g_return_val_if_fail (SML_IS_MAP_ITEM (self), NULL); + return self->priv->remote; +} + +/** + * sml_map_item_get_remote_uri: + * @self: A #SmlMapItem + * + * Gets the remote URI property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_map_item_get_remote_uri (SmlMapItem *self) +{ + g_return_val_if_fail (SML_IS_MAP_ITEM (self), NULL); + if (!self->priv->remote) + return NULL; + return sml_location_get_uri(self->priv->remote); +} + +/** + * sml_map_item_set_remote: + * @self: A #SmlMapItem + * @remote: + * + * Sets the remote property. + */ +gboolean +sml_map_item_set_remote (SmlMapItem *self, + SmlLocation* remote, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlMapItem object."); + sml_return_val_error_if_fail (SML_IS_LOCATION (remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(remote)) > 0, FALSE, error, SML_ERROR_GENERIC, "The remote URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote parent URI must not be set."); + + if (self->priv->remote) + g_object_unref (self->priv->remote); + self->priv->remote = remote; + g_object_ref (remote); + return TRUE; +} + +/** + * sml_map_item_get_local: + * @self: A #SmlMapItem + * + * Gets the local property. + * + * Return value: + */ +SmlLocation* +sml_map_item_get_local (SmlMapItem *self) +{ + g_return_val_if_fail (SML_IS_MAP_ITEM (self), NULL); + return self->priv->local; +} + +/** + * sml_map_item_get_local_uri: + * @self: A #SmlMapItem + * + * Gets the local URI property. + * + * Return value: + */ +G_CONST_RETURN gchar* +sml_map_item_get_local_uri (SmlMapItem *self) +{ + g_return_val_if_fail (SML_IS_MAP_ITEM (self), NULL); + if (!self->priv->local) + return NULL; + return sml_location_get_uri(self->priv->local); +} + +/** + * sml_map_item_set_local: + * @self: A #SmlMapItem + * @local: + * + * Sets the local property. + */ +gboolean +sml_map_item_set_local (SmlMapItem *self, + SmlLocation* local, + GError **error) +{ + CHECK_ERROR_REF + sml_return_val_error_if_fail (SML_IS_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlMapItem object."); + sml_return_val_error_if_fail (SML_IS_LOCATION (local), FALSE, error, SML_ERROR_GENERIC, "There must be a local SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(local), FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(local)) > 0, FALSE, error, SML_ERROR_GENERIC, "The local URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local parent URI must not be set."); + + if (self->priv->local) + g_object_unref (self->priv->local); + self->priv->local = local; + g_object_ref (local); + return TRUE; +} + +/** + * sml_map_item_is_compliant: + * @self: A #SmlMapItem + * + * Checks the compliance with the OMA specifications for mappings. + */ +gboolean +sml_map_item_is_compliant (SmlMapItem *self, + GError **error) +{ + sml_return_val_error_if_fail (SML_IS_MAP_ITEM (self), FALSE, error, SML_ERROR_GENERIC, "There must be a SmlMapItem object."); + + SmlLocation *remote = self->priv->remote; + sml_return_val_error_if_fail (remote, FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (SML_IS_LOCATION (remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(remote), FALSE, error, SML_ERROR_GENERIC, "There must be a remote URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(remote)) > 0, FALSE, error, SML_ERROR_GENERIC, "The remote URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(remote) == NULL, FALSE, error, SML_ERROR_GENERIC, "The remote parent URI must not be set."); + + SmlLocation *local = self->priv->local; + sml_return_val_error_if_fail (local, FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (SML_IS_LOCATION (local), FALSE, error, SML_ERROR_GENERIC, "There must be a local SmlLocation object."); + sml_return_val_error_if_fail (sml_location_get_uri(local), FALSE, error, SML_ERROR_GENERIC, "There must be a local URI."); + sml_return_val_error_if_fail (strlen(sml_location_get_uri(local)) > 0, FALSE, error, SML_ERROR_GENERIC, "The local URI cannot be the empty string."); + sml_return_val_error_if_fail (sml_location_get_name(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local name must not be set."); + sml_return_val_error_if_fail (sml_location_get_parent_uri(local) == NULL, FALSE, error, SML_ERROR_GENERIC, "The local parent URI must not be set."); + + return TRUE; +} Added: trunk/libsyncml/data_sync_api/sml_map_item.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_map_item.h Sat Aug 1 17:23:46 2009 (r1224) @@ -0,0 +1,64 @@ +/* sml_map_item.h + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __SML_MAP_ITEM_H__ +#define __SML_MAP_ITEM_H__ + +#include <glib-object.h> +#include <libsyncml/data_sync_api/sml_location.h> + +G_BEGIN_DECLS + +#define SML_TYPE_MAP_ITEM (sml_map_item_get_type()) +#define SML_MAP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SML_TYPE_MAP_ITEM, SmlMapItem)) +#define SML_MAP_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SML_TYPE_MAP_ITEM, SmlMapItemClass)) +#define SML_IS_MAP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SML_TYPE_MAP_ITEM)) +#define SML_IS_MAP_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SML_TYPE_MAP_ITEM)) +#define SML_MAP_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SML_TYPE_MAP_ITEM, SmlMapItemClass)) + +typedef struct _SmlMapItem SmlMapItem; +typedef struct _SmlMapItemClass SmlMapItemClass; +typedef struct _SmlMapItemPrivate SmlMapItemPrivate; + +struct _SmlMapItem +{ + GObject parent; + + /*< private >*/ + SmlMapItemPrivate *priv; +}; + +struct _SmlMapItemClass +{ + GObjectClass parent_class; + +}; + +GType sml_map_item_get_type (void); +SmlMapItem* sml_map_item_new (void); +G_CONST_RETURN gchar* sml_map_item_get_local_uri (SmlMapItem *self); +gboolean sml_map_item_set_local (SmlMapItem *self, SmlLocation* local, GError **error); +G_CONST_RETURN gchar* sml_map_item_get_remote_uri (SmlMapItem *self); +gboolean sml_map_item_set_remote (SmlMapItem *self, SmlLocation* remote, GError **error); +gboolean sml_map_item_is_compliant (SmlMapItem *self, GError **error); + +G_END_DECLS + +#endif /* __SML_MAP_ITEM_H__ */ Added: trunk/libsyncml/data_sync_api/sml_map_item_internals.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libsyncml/data_sync_api/sml_map_item_internals.h Sat Aug 1 17:23:46 2009 (r1224) @@ -0,0 +1,34 @@ +/* sml_map_item_internals.h + * + * Copyright (C) 2009 Michael Bell <mic...@op...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef __SML_MAP_ITEM_INTERNALS_H__ +#define __SML_MAP_ITEM_INTERNALS_H__ + +#include <glib-object.h> +#include <libsyncml/data_sync_api/sml_map_item.h> + +G_BEGIN_DECLS + +SmlLocation* sml_map_item_get_local (SmlMapItem *self); +SmlLocation* sml_map_item_get_remote (SmlMapItem *self); + +G_END_DECLS + +#endif /* __SML_MAP_ITEM_INTERNALS_H__ */ Modified: trunk/libsyncml/data_sync_api/standard.h ============================================================================== --- trunk/libsyncml/data_sync_api/standard.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/data_sync_api/standard.h Sat Aug 1 17:23:46 2009 (r1224) @@ -35,6 +35,7 @@ #include <libsyncml/data_sync_api/defines.h> #include <libsyncml/data_sync_api/sml_location.h> +#include <libsyncml/data_sync_api/sml_map_item.h> #ifdef __cplusplus extern "C" @@ -68,8 +69,7 @@ gboolean smlDataSyncSendChanges (SmlDataSyncObject *dsObject, GError **error); gboolean smlDataSyncAddMapping (SmlDataSyncObject *dsObject, const gchar *source, - const gchar *remoteID, - const gchar *localID, + SmlMapItem *item, GError **error); /** Modified: trunk/libsyncml/objects/sml_ds_server.c ============================================================================== --- trunk/libsyncml/objects/sml_ds_server.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/objects/sml_ds_server.c Sat Aug 1 17:23:46 2009 (r1224) @@ -33,17 +33,17 @@ { smlTrace(TRACE_ENTRY, "%s(%p, %s, %i)", __func__, dsession, VA_STRING(uid), type); - g_mutex_lock(dsession->pendingMapsLock); + g_mutex_lock(dsession->pendingChangesLock); GList *c = NULL; - for (c = dsession->pendingMaps; c; c = c->next) { + for (c = dsession->pendingChanges; c; c = c->next) { SmlWriteContext *ctx = c->data; if (!strcmp(uid, ctx->uid) && ctx->type == type) { - g_mutex_unlock(dsession->pendingMapsLock); + g_mutex_unlock(dsession->pendingChangesLock); smlTrace(TRACE_EXIT, "%s: %p", __func__, ctx); return ctx; } } - g_mutex_unlock(dsession->pendingMapsLock); + g_mutex_unlock(dsession->pendingChangesLock); smlTrace(TRACE_EXIT_ERROR, "%s: Not found", __func__); return NULL; @@ -59,9 +59,6 @@ if (ctx->uid) smlSafeCFree(&(ctx->uid)); - if (ctx->newuid) - smlSafeCFree(&(ctx->newuid)); - smlSafeFree((gpointer *)&ctx); smlTrace(TRACE_EXIT, "%s", __func__); @@ -76,37 +73,13 @@ return; } - smlTrace(TRACE_INTERNAL, "%s: Dispatching: uid %s, Type %i, newuid %s, result %i", __func__, VA_STRING(ctx->uid), ctx->type, VA_STRING(ctx->newuid), smlStatusGetCode(ctx->status)); + smlTrace(TRACE_INTERNAL, "%s: Dispatching: uid %s, Type %i, result %i", __func__, VA_STRING(ctx->uid), ctx->type, smlStatusGetCode(ctx->status)); - if (ctx->type == SML_CHANGE_ADD && - smlStatusGetClass(ctx->status) == SML_ERRORCLASS_SUCCESS && - !dsession->recvMappingCallback && - !ctx->newuid && - dsession->server->servertype == SML_DS_SERVER) - { - smlTrace(TRACE_EXIT, "%s: No mapitem yet", __func__); - return; - } - ctx->callback(dsession, ctx->status, ctx->userdata); - g_mutex_lock(dsession->pendingMapsLock); - dsession->pendingMaps = g_list_remove(dsession->pendingMaps, ctx); - g_mutex_unlock(dsession->pendingMapsLock); - - if (ctx->type == SML_CHANGE_ADD && - smlStatusGetClass(ctx->status) == SML_ERRORCLASS_SUCCESS && - dsession->recvEventCallback && - !dsession->pendingMaps) - { - /* FIXME: I'm sure that this event is buggy. - * FIXME: What is the semantic of this event? - * Now there are no more MapItems ... - * do some fancy callback. Some applications will love it ;) - */ - dsession->recvEventCallback(dsession, SML_DS_EVENT_COMMITEDCHANGES, dsession->recvEventCallbackUserdata); - smlTrace(TRACE_INTERNAL, "%s: recvEventCallback commited changes callback", __func__); - } + g_mutex_lock(dsession->pendingChangesLock); + dsession->pendingChanges = g_list_remove(dsession->pendingChanges, ctx); + g_mutex_unlock(dsession->pendingChangesLock); _write_context_free(ctx); @@ -138,12 +111,6 @@ dsession->sentSyncCallback = NULL; dsession->sentSyncCallbackUserdata = NULL; - // Now there are no more MapItems ... do some fancy callback. Some applications will love it ;) - if (dsession->recvEventCallback && !dsession->pendingMaps) { - dsession->recvEventCallback(dsession, SML_DS_EVENT_COMMITEDCHANGES, dsession->recvEventCallbackUserdata); - smlTrace(TRACE_INTERNAL, "%s: recvEventCallback commited changes callback", __func__); - } - smlTrace(TRACE_EXIT, "%s", __func__); } @@ -432,7 +399,7 @@ dsession->location = server->location; g_object_ref(dsession->location); - dsession->pendingMapsLock = g_mutex_new(); + dsession->pendingChangesLock = g_mutex_new(); smlTrace(TRACE_EXIT, "%s: %p", __func__, dsession); return dsession; @@ -481,25 +448,31 @@ dsession->recvChanges = g_list_delete_link(dsession->recvChanges, dsession->recvChanges); } + while (dsession->recvMap) { + SmlCommand *cmd = dsession->recvMap->data; + smlCommandUnref(cmd); + dsession->recvMap = g_list_delete_link(dsession->recvMap, dsession->recvMap); + } + if (dsession->syncCommand) smlCommandUnref(dsession->syncCommand); - if (!g_mutex_trylock(dsession->pendingMapsLock)) { + if (!g_mutex_trylock(dsession->pendingChangesLock)) { smlTrace(TRACE_ERROR, "%s: somebody still uses this object", __func__); - g_mutex_lock(dsession->pendingMapsLock); + g_mutex_lock(dsession->pendingChangesLock); } - while (dsession->pendingMaps) { - SmlWriteContext *ctx = dsession->pendingMaps->data; + while (dsession->pendingChanges) { + SmlWriteContext *ctx = dsession->pendingChanges->data; _write_context_free(ctx); - dsession->pendingMaps = g_list_delete_link(dsession->pendingMaps, dsession->pendingMaps); + dsession->pendingChanges = g_list_delete_link(dsession->pendingChanges, dsession->pendingChanges); } - g_mutex_unlock(dsession->pendingMapsLock); - g_mutex_free(dsession->pendingMapsLock); + g_mutex_unlock(dsession->pendingChangesLock); + g_mutex_free(dsession->pendingChangesLock); while (dsession->mapItems) { SmlMapItem *item = dsession->mapItems->data; - smlMapItemUnref(item); + g_object_unref(item); dsession->mapItems = g_list_delete_link(dsession->mapItems, dsession->mapItems); } @@ -600,11 +573,6 @@ if (!dsession->recvChanges) { /* There are no changes. */ - /* ... do some fancy callback. Some applications will love it ;) */ - if (dsession->recvEventCallback) { - dsession->recvEventCallback(dsession, SML_DS_EVENT_GOTCHANGES, dsession->recvEventCallbackUserdata); - smlTrace(TRACE_INTERNAL, "%s: recvEventCallback no changes in recvSync callback", __func__); - } /* unlock the final event at the manager * * If this is called from a test case then the datastore @@ -617,7 +585,7 @@ } smlTrace(TRACE_INTERNAL, "%s: final handling done", __func__); } - } else if (dsession->recvChanges && dsession->changesCallback) { + } else if (dsession->recvChanges && dsession->recvChangeCallback) { smlTrace(TRACE_INTERNAL, "%s: Dispatching changes", __func__); while (dsession->recvChanges) { @@ -662,12 +630,12 @@ if (!smlItemStealData(item, &data, &size, &error)) goto error; - if (!dsession->changesCallback(dsession, + 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->changesCallbackUserdata, &error)) + dsession->recvChangeCallbackUserdata, &error)) goto error; } @@ -690,11 +658,6 @@ dsession->recvChanges = g_list_delete_link(dsession->recvChanges, dsession->recvChanges); } - // Now there are no more changes... do some fancy callback. Some applications will love it ;) - if (dsession->recvEventCallback) { - dsession->recvEventCallback(dsession, SML_DS_EVENT_GOTCHANGES, dsession->recvEventCallbackUserdata); - smlTrace(TRACE_INTERNAL, "%s: recvEventCallback all changes sent in recvChanges callback", __func__); - } /* unlock the final event at the manager * * If this is called from a test case then the datastore @@ -707,9 +670,43 @@ } else smlTrace(TRACE_INTERNAL, "%s - no manager so should be a test", __func__); + } else if (dsession->recvMap && dsession->recvMappingCallback) { + while (dsession->recvMap) { + SmlCommand *cmd = dsession->recvMap->data; + + smlTrace(TRACE_INTERNAL, "%s: answering map command with cmdRef %i and msgRef %i", + __func__, + smlCommandGetID(cmd), + smlCommandGetMessageID(cmd)); + + /* handle the mapping */ + gsize i; + for (i = 0; i < smlCommandGetNumMappings(cmd); i++) { + SmlMapItem *item = smlCommandGetNthMapping(cmd, i); + + dsession->recvMappingCallback( + dsession, + item, + dsession->recvMappingCallbackUserdata); + } + + /* send the reply */ + reply = smlCommandNewReply(cmd, SML_NO_ERROR, &error); + if (!reply) + goto error; + + if (!smlSessionSendReply(dsession->session, reply, &error)) + goto error; + + smlStatusUnref(reply); + + /* cleanup the command */ + smlCommandUnref(cmd); + dsession->recvMap = g_list_delete_link(dsession->recvMap, dsession->recvMap); + } } else { - smlTrace(TRACE_INTERNAL, "%s: recvChanges: %p changesCallback: %p", __func__, dsession->recvChanges, dsession->changesCallback); + smlTrace(TRACE_INTERNAL, "%s: no actions/callbacks to be done", __func__); } smlTrace(TRACE_EXIT, "%s()", __func__); @@ -729,7 +726,8 @@ { if ((dsession->alertCommand && dsession->recvAlertCallback) || \ (dsession->recvSync && dsession->recvSyncCallback) || \ - (dsession->recvChanges && dsession->changesCallback)) + (dsession->recvChanges && dsession->recvChangeCallback) || \ + (dsession->recvMap && dsession->recvMappingCallback)) return TRUE; return FALSE; } @@ -901,6 +899,7 @@ smlTrace(TRACE_EXIT, "%s", __func__); } +/* FIXME: this is synchronous behaviour !? */ void smlDsSessionRecvMap(SmlSession *session, SmlCommand *cmd, void *userdata) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, session, cmd, userdata); @@ -909,44 +908,13 @@ g_mutex_lock(dsession->lock); - SmlStatus *reply = smlCommandNewReply(cmd, SML_NO_ERROR, &error); - if (!reply) - goto error; - - if (!smlSessionSendReply(session, reply, &error)) - goto error; - - smlStatusUnref(reply); - - gsize i; - for (i = 0; i < smlCommandGetNumMappings(cmd); i++) { - SmlMapItem *item = smlCommandGetNthMapping(cmd, i); - - if (dsession->recvMappingCallback) { - dsession->recvMappingCallback( - dsession, - smlMapItemGetTarget(item), - smlMapItemGetSource(item), - dsession->recvMappingCallbackUserdata); - } else { - SmlWriteContext *ctx = _write_context_find(dsession, sml_location_get_uri(smlMapItemGetTarget(item)), SML_CHANGE_ADD); - if (ctx) { - ctx->newuid = g_strdup(sml_location_get_uri(smlMapItemGetSource(item))); - _write_context_dispatch(dsession, ctx); - } else { - smlTrace(TRACE_ERROR, "%s: Unknown map ... %s => %s", - __func__, - VA_STRING(sml_location_get_uri(smlMapItemGetTarget(item))), - VA_STRING(sml_location_get_uri(smlMapItemGetSource(item)))); - } - } - } + dsession->recvMap = g_list_append(dsession->recvMap, cmd); + smlCommandRef(cmd); g_mutex_unlock(dsession->lock); smlTrace(TRACE_EXIT, "%s", __func__); return; - error: g_mutex_unlock(dsession->lock); smlSessionDispatchEvent(session, SML_SESSION_EVENT_ERROR, NULL, NULL, NULL, error); @@ -1048,14 +1016,14 @@ * @param error A pointer to a error struct * @returns TRUE if the call was successful, FALSE otherwise */ -void smlDsSessionGetChanges(SmlDsSession *dsession, SmlDsSessionChangesCb chgCallback, void *userdata) +void smlDsSessionGetChanges(SmlDsSession *dsession, SmlDsSessionChangeCb chgCallback, void *userdata) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, dsession, chgCallback, userdata); smlAssert(dsession); smlAssert(chgCallback); - dsession->changesCallback = chgCallback; - dsession->changesCallbackUserdata = userdata; + dsession->recvChangeCallback = chgCallback; + dsession->recvChangeCallbackUserdata = userdata; smlDsSessionDispatch(dsession); @@ -1076,21 +1044,6 @@ smlTrace(TRACE_EXIT, "%s", __func__); } -void smlDsSessionGetEvent(SmlDsSession *dsession, SmlDsSessionEventCb eventCallback, void *userdata) -{ - smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, dsession, eventCallback, userdata); - smlAssert(dsession); - smlAssert(eventCallback); - - dsession->recvEventCallback = eventCallback; - dsession->recvEventCallbackUserdata = userdata; - - smlDsSessionDispatch(dsession); - - smlTrace(TRACE_EXIT, "%s", __func__); -} - - /** @brief Start the sync command to send to the other side * * This function will start the sync command with which the changes will be sent to the other side. @@ -1145,7 +1098,7 @@ const gchar *data, gsize size, const gchar *contenttype, - SmlDsSessionWriteCb callback, + SmlDsSessionChangeStatusCb callback, void *userdata, GError **error) { @@ -1176,9 +1129,9 @@ ctx->type = type; ctx->session = dsession; - g_mutex_lock(dsession->pendingMapsLock); - dsession->pendingMaps = g_list_append(dsession->pendingMaps, ctx); - g_mutex_unlock(dsession->pendingMapsLock); + g_mutex_lock(dsession->pendingChangesLock); + dsession->pendingChanges = g_list_append(dsession->pendingChanges, ctx); + g_mutex_unlock(dsession->pendingChangesLock); if (!smlSessionSendCommand(dsession->session, cmd, dsession->syncCommand, _change_reply, ctx, error)) goto error; @@ -1234,19 +1187,15 @@ gboolean smlDsSessionQueueMap (SmlDsSession *dsession, - const gchar *uid, - const gchar *newuid, + SmlMapItem *item, GError **error) { - smlTrace(TRACE_ENTRY, "%s(%p, %s, %s, %p)", __func__, dsession, VA_STRING(uid), VA_STRING(newuid), error); + smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, dsession, item, error); smlAssert(dsession); CHECK_ERROR_REF - SmlMapItem *item = smlMapItemNew(uid, newuid, error); - if (!item) - goto error; - dsession->mapItems = g_list_append(dsession->mapItems, item); + g_object_ref(item); smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; @@ -1287,9 +1236,8 @@ SmlMapItem *item = dsession->mapItems->data; if (!smlCommandAddMapItem(cmd, item, error)) goto error; - smlMapItemUnref(item); - dsession->mapItems = g_list_remove(dsession->mapItems, item); + g_object_unref(item); } if (!smlSessionSendCommand(dsession->session, cmd, NULL, callback, userdata, error)) Modified: trunk/libsyncml/objects/sml_ds_server.h ============================================================================== --- trunk/libsyncml/objects/sml_ds_server.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/objects/sml_ds_server.h Sat Aug 1 17:23:46 2009 (r1224) @@ -31,21 +31,16 @@ #define _SML_DS_SERVER_H_ #include "../sml_notification.h" +#include <libsyncml/data_sync_api/sml_map_item.h> typedef struct SmlDsServer SmlDsServer; typedef struct SmlDsSession SmlDsSession; -typedef enum { - SML_DS_EVENT_GOTCHANGES = 0, - SML_DS_EVENT_COMMITEDCHANGES = 1 -} SmlDsEvent; - 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 void (* SmlDsSessionEventCb) (SmlDsSession *dsession, SmlDsEvent event, void *userdata); -typedef gboolean (* SmlDsSessionChangesCb) (SmlDsSession *dsession, SmlChangeType type, const gchar *uid, gchar *data, gsize size, const gchar *contenttype, void *userdata, GError **error); -typedef void (* SmlDsSessionWriteCb) (SmlDsSession *dsession, SmlStatus *status, 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); SmlDsServer* smlDsServerNew (const gchar *type, SmlLocation *location, GError **error); SmlDsServer* smlDsClientNew (const gchar *type, SmlLocation *location, SmlLocation *target, GError **error); @@ -66,13 +61,12 @@ gboolean smlDsSessionCheck (SmlDsSession *dsession); void smlDsSessionGetAlert (SmlDsSession *dsession, SmlDsSessionAlertCb callback, void *userdata); gboolean smlDsSessionSendAlert (SmlDsSession *dsession, SmlAlertType type, const gchar *last, const gchar *next, SmlStatusReplyCb callback, void *userdata, GError **error); -void smlDsSessionGetChanges (SmlDsSession *dsession, SmlDsSessionChangesCb chgCallback, void *userdata); +void smlDsSessionGetChanges (SmlDsSession *dsession, SmlDsSessionChangeCb chgCallback, void *userdata); void smlDsSessionGetSync (SmlDsSession *dsession, SmlDsSessionSyncCb chgCallback, void *userdata); -void smlDsSessionGetEvent (SmlDsSession *dsession, SmlDsSessionEventCb eventCallback, 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, SmlDsSessionWriteCb 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 smlDsSessionCloseSync (SmlDsSession *dsession, GError **error); -gboolean smlDsSessionQueueMap (SmlDsSession *dsession, const gchar *uid, const gchar *newuid, GError **error); +gboolean smlDsSessionQueueMap (SmlDsSession *dsession, SmlMapItem *item, GError **error); gboolean smlDsSessionCloseMap (SmlDsSession *dsession, SmlStatusReplyCb callback, void *userdata, GError **error); const gchar* smlDsSessionGetLocation (SmlDsSession *dsession); const gchar* smlDsSessionGetContentType (SmlDsSession *dsession); Modified: trunk/libsyncml/objects/sml_ds_server_internals.h ============================================================================== --- trunk/libsyncml/objects/sml_ds_server_internals.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/objects/sml_ds_server_internals.h Sat Aug 1 17:23:46 2009 (r1224) @@ -32,12 +32,11 @@ #include "sml_ds_server.h" -typedef void (* SmlDsSessionMapCb) (SmlDsSession *dsession, SmlLocation *orig, SmlLocation *mapped, void *userdata); +typedef void (* SmlDsSessionMapCb) (SmlDsSession *dsession, SmlMapItem *item, void *userdata); typedef struct SmlWriteContext { - SmlDsSessionWriteCb callback; + SmlDsSessionChangeStatusCb callback; gchar *uid; - gchar *newuid; SmlStatus *status; void *userdata; SmlChangeType type; @@ -65,8 +64,8 @@ /** Callback that will receive the sync command */ SmlDsSessionSyncCb recvSyncCallback; void *recvSyncCallbackUserdata; - SmlDsSessionChangesCb changesCallback; - void *changesCallbackUserdata; + SmlDsSessionChangeCb recvChangeCallback; + void *recvChangeCallbackUserdata; /** List of received sync commands. We need a list here * since sync commands might get split due to size limitations * and the answer to a sync command might arrive after several @@ -81,20 +80,17 @@ SmlStatusReplyCb sentSyncCallback; void *sentSyncCallbackUserdata; - /** Callback that will information about the Ds Session events */ - SmlDsSessionEventCb recvEventCallback; - void *recvEventCallbackUserdata; - /** The temporary storage for the sync command to send */ SmlCommand *syncCommand; - GList *pendingMaps; - GMutex *pendingMapsLock; + GList *pendingChanges; + GMutex *pendingChangesLock; GList *mapItems; /** Callback that signals mappings */ SmlDsSessionMapCb recvMappingCallback; void *recvMappingCallbackUserdata; + GList *recvMap; GMutex *write_lock; GMutex *lock; Modified: trunk/libsyncml/parser/sml_xml_assm.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_assm.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/parser/sml_xml_assm.c Sat Aug 1 17:23:46 2009 (r1224) @@ -25,6 +25,7 @@ #include <libsyncml/sml_session_internals.h> #include "libsyncml/sml_error_internals.h" +#include "libsyncml/data_sync_api/sml_map_item_internals.h" #include "sml_xml_assm_internals.h" #include <string.h> @@ -757,13 +758,13 @@ if (!_smlXmlAssemblerStartNode(assm, SML_ELEMENT_MAPITEM, error)) goto error; - if (item->source) { - if (!smlLocationAssemble(item->source, assm, SML_ELEMENT_SOURCE, error)) + if (sml_map_item_get_remote(item)) { + if (!smlLocationAssemble(sml_map_item_get_remote(item), assm, SML_ELEMENT_SOURCE, error)) goto error; } - if (item->target) { - if (!smlLocationAssemble(item->target, assm, SML_ELEMENT_TARGET, error)) + if (sml_map_item_get_local(item)) { + if (!smlLocationAssemble(sml_map_item_get_local(item), assm, SML_ELEMENT_TARGET, error)) goto error; } Modified: trunk/libsyncml/parser/sml_xml_parse.c ============================================================================== --- trunk/libsyncml/parser/sml_xml_parse.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/parser/sml_xml_parse.c Sat Aug 1 17:23:46 2009 (r1224) @@ -1464,10 +1464,11 @@ CHECK_ERROR_REF smlAssert(parser); - SmlMapItem *item = smlTryMalloc0(sizeof(SmlMapItem), error); - if (!item) + SmlMapItem *item = sml_map_item_new(); + if (!item) { + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Out of memory."); goto error; - item->refCount = 1; + } while (1) { if (!_smlXmlParserStep(parser)) { @@ -1486,11 +1487,23 @@ } if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_SOURCE)) { - if (!_smlLocationParse(&item->source, parser, error)) + SmlLocation *loc = NULL; + if (!_smlLocationParse(&loc, parser, error)) + goto error_free_item; + if (!sml_map_item_set_remote(item, loc, error)) { + g_object_unref(loc); goto error_free_item; + } + g_object_unref(loc); } else if (!strcmp((char *)xmlTextReaderConstName(parser->reader), SML_ELEMENT_TARGET)) { - if (!_smlLocationParse(&item->target, parser, error)) + SmlLocation *loc = NULL; + if (!_smlLocationParse(&loc, parser, error)) + goto error_free_item; + if (!sml_map_item_set_local(item, loc, error)) { + g_object_unref(loc); goto error_free_item; + } + g_object_unref(loc); } else { g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "wrong initial node %s", xmlTextReaderConstName(parser->reader)); goto error_free_item; @@ -1501,7 +1514,7 @@ return item; error_free_item: - smlMapItemUnref(item); + g_object_unref(item); error: smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return NULL; Modified: trunk/libsyncml/sml_command.c ============================================================================== --- trunk/libsyncml/sml_command.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/sml_command.c Sat Aug 1 17:23:46 2009 (r1224) @@ -422,7 +422,7 @@ case SML_COMMAND_TYPE_MAP: while (cmd->private.map.items) { SmlMapItem *item = cmd->private.map.items->data; - smlMapItemUnref(item); + g_object_unref(item); cmd->private.map.items = g_list_delete_link(cmd->private.map.items, cmd->private.map.items); } break; @@ -953,7 +953,7 @@ smlAssert(map->type == SML_COMMAND_TYPE_MAP); smlAssert(item); - smlMapItemRef(item); + g_object_ref(item); map->private.map.items = g_list_append(map->private.map.items, item); smlTrace(TRACE_EXIT, "%s", __func__); Modified: trunk/libsyncml/sml_elements.c ============================================================================== --- trunk/libsyncml/sml_elements.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/sml_elements.c Sat Aug 1 17:23:46 2009 (r1224) @@ -851,89 +851,3 @@ return chal->type; } -SmlMapItem* -smlMapItemNew (const gchar *uid, - const gchar *newuid, - GError **error) -{ - smlTrace(TRACE_ENTRY, "%s(%s, %s, %p)", __func__, VA_STRING(uid), VA_STRING(newuid), error); - CHECK_ERROR_REF - smlAssert(uid); - smlAssert(newuid); - - SmlMapItem *item = smlTryMalloc0(sizeof(SmlMapItem), error); - if (!item) - goto error; - item->refCount = 1; - - item->source = sml_location_new_with_options(newuid, NULL, error); - if (!item->source) - goto error; - - item->target = sml_location_new_with_options(uid, NULL, error); - if (!item->target) - goto error; - - smlTrace(TRACE_EXIT, "%s: %p", __func__, item); - return item; - -error: - if (item) { - if (item->source) - g_object_unref(item->source); - smlSafeFree((gpointer *)&item); - } - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); - return NULL; -} - -SmlMapItem* -smlMapItemRef (SmlMapItem *item) -{ - smlTrace(TRACE_ENTRY, "%s(%p)", __func__, item); - smlAssert(item); - - g_atomic_int_inc(&(item->refCount)); - - smlTrace(TRACE_EXIT, "%s: New refcount: %i", __func__, item->refCount); - return item; -} - -void -smlMapItemUnref (SmlMapItem *item) -{ - smlTrace(TRACE_ENTRY, "%s(%p)", __func__, item); - smlAssert(item); - - if (g_atomic_int_dec_and_test(&(item->refCount))) { - smlTrace(TRACE_INTERNAL, "%s: Refcount == 0!", __func__); - - if (item->source) - { - g_object_unref(item->source); - item->source = NULL; - } - - if (item->target) - { - g_object_unref(item->target); - item->target = NULL; - } - - smlSafeFree((gpointer *)&item); - } - - smlTrace(TRACE_EXIT, "%s", __func__); -} - -SmlLocation* -smlMapItemGetSource (SmlMapItem *item) -{ - return item->source; -} - -SmlLocation* -smlMapItemGetTarget (SmlMapItem *item) -{ - return item->target; -} Modified: trunk/libsyncml/sml_elements.h ============================================================================== --- trunk/libsyncml/sml_elements.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/sml_elements.h Sat Aug 1 17:23:46 2009 (r1224) @@ -39,7 +39,6 @@ typedef struct SmlItem SmlItem; typedef struct SmlHeader SmlHeader; typedef struct SmlChal SmlChal; -typedef struct SmlMapItem SmlMapItem; SmlCred* smlCredNewFromString (const gchar *type, const gchar *format, const gchar *data, GError **error); SmlCred* smlCredNewAuth (SmlAuthType type, const gchar *username, const gchar *password, GError **error); @@ -101,12 +100,6 @@ const gchar* smlChalGetNonce (SmlChal *chal); /* Base 64 only */ SmlAuthType smlChalGetType (SmlChal *chal); -SmlMapItem* smlMapItemNew (const gchar *uid, const gchar *newuid, GError **error); -SmlMapItem* smlMapItemRef (SmlMapItem *item); -void smlMapItemUnref (SmlMapItem *item); -SmlLocation* smlMapItemGetSource (SmlMapItem *item); -SmlLocation* smlMapItemGetTarget (SmlMapItem *item); - #endif //_SML_ELEMENTS_H_ /*@}*/ Modified: trunk/libsyncml/sml_elements_internals.h ============================================================================== --- trunk/libsyncml/sml_elements_internals.h Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/sml_elements_internals.h Sat Aug 1 17:23:46 2009 (r1224) @@ -57,12 +57,6 @@ gboolean raw; }; -struct SmlMapItem { - gint refCount; - SmlLocation *source; - SmlLocation *target; -}; - struct SmlHeader { gsize sessionID; SmlProtocolVersion version; Modified: trunk/libsyncml/sml_session.c ============================================================================== --- trunk/libsyncml/sml_session.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/libsyncml/sml_session.c Sat Aug 1 17:23:46 2009 (r1224) @@ -1017,7 +1017,7 @@ } else { - smlTrace(TRACE_INTERNAL, "%s: dispatch status", __func__); + smlTrace(TRACE_INTERNAL, "%s: dispatch status - %d", __func__, smlQueueLengthPrio(session->command_queue)); smlQueueDispatchPrio(session->command_queue); } smlTrace(TRACE_EXIT, "%s - done", __func__); @@ -2188,7 +2188,7 @@ sesscmd->type = SML_SESSION_FLUSH; sesscmd->final = TRUE; sesscmd->end = TRUE; - smlTrace(TRACE_INTERNAL, "%s: sending command %p", sesscmd); + smlTrace(TRACE_INTERNAL, "%s: sending command %p", __func__, sesscmd); smlQueueSend(session->command_queue, sesscmd); } else { Modified: trunk/tests/CMakeLists.txt ============================================================================== --- trunk/tests/CMakeLists.txt Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/tests/CMakeLists.txt Sat Aug 1 17:23:46 2009 (r1224) @@ -89,26 +89,26 @@ SML_ADD_TESTCASE( location_references ) SML_END_TEST() - SML_START_TEST( "data_sync_map_item" data_sync_api_map_item check_data_sync_api_map_item.c ${TEST_TARGET_LIBRARIES} ) - SML_ADD_TESTCASE( data_sync_map_item_new ) - SML_ADD_TESTCASE( data_sync_map_item_set_local ) - SML_ADD_TESTCASE( data_sync_map_item_set_local_not_null ) - SML_ADD_TESTCASE( data_sync_map_item_set_local_no_name ) - SML_ADD_TESTCASE( data_sync_map_item_set_local_no_parent ) - SML_ADD_TESTCASE( data_sync_map_item_set_local_missing_uri ) - SML_ADD_TESTCASE( data_sync_map_item_get_local ) - SML_ADD_TESTCASE( data_sync_map_item_set_remote ) - SML_ADD_TESTCASE( data_sync_map_item_set_remote_not_null ) - SML_ADD_TESTCASE( data_sync_map_item_set_remote_no_name ) - SML_ADD_TESTCASE( data_sync_map_item_set_remote_no_parent ) - SML_ADD_TESTCASE( data_sync_map_item_set_remote_missing_uri ) - SML_ADD_TESTCASE( data_sync_map_item_get_remote ) - SML_ADD_TESTCASE( data_sync_map_item_compliance ) - SML_ADD_TESTCASE( data_sync_map_item_compliance_missing_local ) - SML_ADD_TESTCASE( data_sync_map_item_compliance_missing_remote ) - SML_ADD_TESTCASE( data_sync_map_item_compliance_wrong_local ) - SML_ADD_TESTCASE( data_sync_map_item_compliance_wrong_remote ) - SML_ADD_TESTCASE( data_sync_map_item_references ) + SML_START_TEST( "map_item" data_sync_api_map_item check_data_sync_api_map_item.c ${TEST_TARGET_LIBRARIES} ) + SML_ADD_TESTCASE( map_item_new ) + SML_ADD_TESTCASE( map_item_set_local ) + SML_ADD_TESTCASE( map_item_set_local_not_null ) + SML_ADD_TESTCASE( map_item_set_local_no_name ) + SML_ADD_TESTCASE( map_item_set_local_no_parent ) + SML_ADD_TESTCASE( map_item_set_local_missing_uri ) + SML_ADD_TESTCASE( map_item_get_local ) + SML_ADD_TESTCASE( map_item_set_remote ) + SML_ADD_TESTCASE( map_item_set_remote_not_null ) + SML_ADD_TESTCASE( map_item_set_remote_no_name ) + SML_ADD_TESTCASE( map_item_set_remote_no_parent ) + SML_ADD_TESTCASE( map_item_set_remote_missing_uri ) + SML_ADD_TESTCASE( map_item_get_remote ) + SML_ADD_TESTCASE( map_item_compliance ) + SML_ADD_TESTCASE( map_item_compliance_missing_local ) + SML_ADD_TESTCASE( map_item_compliance_missing_remote ) + SML_ADD_TESTCASE( map_item_compliance_wrong_local ) + SML_ADD_TESTCASE( map_item_compliance_wrong_remote ) + SML_ADD_TESTCASE( map_item_references ) SML_END_TEST() SML_START_TEST( "XML fix broken Item Data" xml-fix-broken-item-data check_xml_fix_broken_item_data.c ${TEST_TARGET_LIBRARIES} ) Modified: trunk/tests/check_data_sync_api_map_item.c ============================================================================== --- trunk/tests/check_data_sync_api_map_item.c Fri Jul 31 13:32:17 2009 (r1223) +++ trunk/tests/check_data_sync_api_map_item.c Sat Aug 1 17:23:46 2009 (r1224) @@ -20,18 +20,18 @@ #include "tests/support.h" -#include <libsyncml/data_sync_api/sml_data_sync_map_item.h> +#include <libsyncml/data_sync_api/sml_map_item.h> -START_TEST (data_sync_map_item_new) +START_TEST (map_item_new) { setup_testbed(NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); g_object_unref(item); } END_TEST -START_TEST (data_sync_map_item_set_local) +START_TEST (map_item_set_local) { setup_testbed(NULL); @@ -41,10 +41,10 @@ sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(sml_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); g_object_unref(location); @@ -52,16 +52,16 @@ } END_TEST -START_TEST (data_sync_map_item_set_local_not_null) +START_TEST (map_item_set_local_not_null) { setup_testbed(NULL); GError *error = NULL; - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_local(item, NULL, &error), "The local URI must be enforced."); + sml_fail_unless(!sml_map_item_set_local(item, NULL, &error), "The local URI must be enforced."); sml_fail_unless(error != NULL, NULL); g_error_free(error); @@ -69,7 +69,7 @@ } END_TEST -START_TEST (data_sync_map_item_set_local_no_name) +START_TEST (map_item_set_local_no_name) { setup_testbed(NULL); @@ -81,10 +81,10 @@ sml_fail_unless(sml_location_set_name(location, "my 1234", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must not have a name."); + sml_fail_unless(!sml_map_item_set_local(item, location, &error), "The location must not have a name."); sml_fail_unless(error != NULL, NULL); g_error_free(error); @@ -93,7 +93,7 @@ } END_TEST -START_TEST (data_sync_map_item_set_local_no_parent) +START_TEST (map_item_set_local_no_parent) { setup_testbed(NULL); @@ -105,10 +105,10 @@ sml_fail_unless(sml_location_set_parent_uri(location, "56", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must not have a parent URI."); + sml_fail_unless(!sml_map_item_set_local(item, location, &error), "The location must not have a parent URI."); sml_fail_unless(error != NULL, NULL); g_error_free(error); @@ -117,7 +117,7 @@ } END_TEST -START_TEST (data_sync_map_item_set_local_missing_uri) +START_TEST (map_item_set_local_missing_uri) { setup_testbed(NULL); @@ -125,10 +125,10 @@ SmlLocation *location = sml_location_new(); sml_fail_unless(location != NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_local(item, location, &error), "The location must have an URI."); + sml_fail_unless(!sml_map_item_set_local(item, location, &error), "The location must have an URI."); sml_fail_unless(error != NULL, NULL); g_error_free(error); @@ -137,7 +137,7 @@ } END_TEST -START_TEST (data_sync_map_item_get_local) +START_TEST (map_item_get_local) { setup_testbed(NULL); @@ -147,23 +147,23 @@ sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) == NULL, "The local URI is not set until now."); + sml_fail_unless(sml_map_item_get_local_uri(item) == NULL, "The local URI is not set until now."); - sml_fail_unless(sml_data_sync_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(sml_map_item_set_local(item, location, &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - sml_fail_unless(sml_data_sync_map_item_get_local_uri(item) != NULL, "The local URI must be set now."); - sml_fail_unless(strcmp(sml_data_sync_map_item_get_local_uri(item), "1234") == 0, "The local URI must be 1234."); + sml_fail_unless(sml_map_item_get_local_uri(item) != NULL, "The local URI must be set now."); + sml_fail_unless(strcmp(sml_map_item_get_local_uri(item), "1234") == 0, "The local URI must be 1234."); g_object_unref(location); g_object_unref(item); } END_TEST -START_TEST (data_sync_map_item_set_remote) +START_TEST (map_item_set_remote) { setup_testbed(NULL); @@ -173,10 +173,10 @@ sml_fail_unless(sml_location_set_uri(location, "1234", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(sml_data_sync_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); + sml_fail_unless(sml_map_item_set_remote(item, location, &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); g_object_unref(location); @@ -184,16 +184,16 @@ } END_TEST -START_TEST (data_sync_map_item_set_remote_not_null) +START_TEST (map_item_set_remote_not_null) { setup_testbed(NULL); GError *error = NULL; - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_remote(item, NULL, &error), "The remote URI must be enforced."); + sml_fail_unless(!sml_map_item_set_remote(item, NULL, &error), "The remote URI must be enforced."); sml_fail_unless(error != NULL, NULL); g_error_free(error); @@ -201,7 +201,7 @@ } END_TEST -START_TEST (data_sync_map_item_set_remote_no_name) +START_TEST (map_item_set_remote_no_name) { setup_testbed(NULL); @@ -213,10 +213,10 @@ sml_fail_unless(sml_location_set_name(location, "my 1234", &error), "%s", error?error->message:"No GError set."); sml_fail_unless(error == NULL, NULL); - SmlDataSyncMapItem *item = sml_data_sync_map_item_new(); + SmlMapItem *item = sml_map_item_new(); sml_fail_unless(item != NULL, NULL); - sml_fail_unless(!sml_data_sync_map_item_set_remote(item, location, &error), "The locatio... [truncated message content] |