[evolution-data-server/openismus-work-master: 3/12] Adding ESourceRevisionGuards
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/openismus-work-master: 3/12] Adding ESourceRevisionGuards
- Date: Fri, 25 Jan 2013 10:05:18 +0000 (UTC)
commit 8ce6b797cd0d147d348b9fcb7cedb20060bca8dc
Author: Tristan Van Berkom <tristanvb openismus com>
Date: Thu Jan 24 16:07:27 2013 +0900
Adding ESourceRevisionGuards
The ESourceRevisionGuards extension configures whether an ESource backend
should check revisions on object modifications and produce an
E_CLIENT_ERROR_OUT_OF_SYNC error upon revision conflicts.
libedataserver/Makefile.am | 2 +
libedataserver/e-source-revision-guards.c | 208 +++++++++++++++++++++++++++++
libedataserver/e-source-revision-guards.h | 94 +++++++++++++
libedataserver/libedataserver.h | 1 +
4 files changed, 305 insertions(+), 0 deletions(-)
---
diff --git a/libedataserver/Makefile.am b/libedataserver/Makefile.am
index fd3627f..8bdb82d 100644
--- a/libedataserver/Makefile.am
+++ b/libedataserver/Makefile.am
@@ -84,6 +84,7 @@ libedataserver_1_2_la_SOURCES = \
e-source-refresh.c \
e-source-registry.c \
e-source-resource.c \
+ e-source-revision-guards.c \
e-source-security.c \
e-source-selectable.c \
e-source-smime.c \
@@ -157,6 +158,7 @@ libedataserverinclude_HEADERS = \
e-source-refresh.h \
e-source-registry.h \
e-source-resource.h \
+ e-source-revision-guards.h \
e-source-security.h \
e-source-selectable.h \
e-source-smime.h \
diff --git a/libedataserver/e-source-revision-guards.c b/libedataserver/e-source-revision-guards.c
new file mode 100644
index 0000000..b4b831e
--- /dev/null
+++ b/libedataserver/e-source-revision-guards.c
@@ -0,0 +1,208 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* e-source-revision-guards.c - Revision Guard Configuration.
+ *
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Authors: Tristan Van Berkom <tristanvb openismus com>
+ */
+
+/**
+ * SECTION: e-source-revision-guards
+ * @include: libedataserver/libedataserver.h
+ * @short_description: #ESource extension to configure revision guards
+ *
+ * The #ESourceRevisionGuards extension configures whether revisions
+ * should be checked on modified objects. If a modified object has
+ * a conflicting revision with an existing object, then an
+ * %E_CLIENT_ERROR_OUT_OF_SYNC error should be produced for that object
+ * and the modification should be discarded.
+ *
+ * Access the extension as follows:
+ *
+ * |[
+ * #include <libedataserver/libedataserver.h>
+ *
+ * ESourceRevisionGuards *extension;
+ *
+ * extension = e_source_get_extension (source, E_SOURCE_EXTENSION_REVISION_GUARDS);
+ * ]|
+ **/
+
+#include <libedataserver/e-data-server-util.h>
+
+#include "e-source-revision-guards.h"
+
+#define E_SOURCE_ABC_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), E_TYPE_SOURCE_REVISION_GUARDS, \
+ ESourceRevisionGuardsPrivate))
+
+struct _ESourceRevisionGuardsPrivate {
+ GMutex property_lock;
+ gboolean enabled;
+};
+
+enum {
+ PROP_0,
+ PROP_ENABLED
+};
+
+G_DEFINE_TYPE (
+ ESourceRevisionGuards,
+ e_source_revision_guards,
+ E_TYPE_SOURCE_EXTENSION)
+
+static void
+source_revision_guards_finalize (GObject *object)
+{
+ ESourceRevisionGuardsPrivate *priv;
+
+ priv = E_SOURCE_ABC_GET_PRIVATE (object);
+
+ g_mutex_clear (&priv->property_lock);
+
+ G_OBJECT_CLASS (e_source_revision_guards_parent_class)->finalize (object);
+}
+
+static void
+source_revision_guards_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ ESourceRevisionGuards *extension = E_SOURCE_REVISION_GUARDS (object);
+
+ switch (property_id) {
+ case PROP_ENABLED:
+ e_source_revision_guards_set_enabled (extension, g_value_get_boolean (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_revision_guards_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ ESourceRevisionGuards *extension = E_SOURCE_REVISION_GUARDS (object);
+
+ switch (property_id) {
+ case PROP_ENABLED:
+ g_value_set_boolean (value, e_source_revision_guards_get_enabled (extension));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+e_source_revision_guards_class_init (ESourceRevisionGuardsClass *class)
+{
+ GObjectClass *object_class;
+ ESourceExtensionClass *extension_class;
+
+ extension_class = E_SOURCE_EXTENSION_CLASS (class);
+ extension_class->name = E_SOURCE_EXTENSION_REVISION_GUARDS;
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->finalize = source_revision_guards_finalize;
+ object_class->get_property = source_revision_guards_get_property;
+ object_class->set_property = source_revision_guards_set_property;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_ENABLED,
+ g_param_spec_boolean (
+ "enabled",
+ "Enabled",
+ "Whether to enable or disable the revision guards",
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ E_SOURCE_PARAM_SETTING));
+
+ g_type_class_add_private (class, sizeof (ESourceRevisionGuardsPrivate));
+}
+
+static void
+e_source_revision_guards_init (ESourceRevisionGuards *extension)
+{
+ extension->priv = E_SOURCE_ABC_GET_PRIVATE (extension);
+ extension->priv->enabled = FALSE;
+
+ g_mutex_init (&extension->priv->property_lock);
+}
+
+/**
+ * e_source_revision_guards_set_enabled:
+ * @extension: An #ESourceRevisionGuards
+ * @enabled: Whether to enable or disable the revision guards.
+ *
+ * Enables or disables the revision guards for a given #ESource.
+ *
+ * Revision guards are disabled by default.
+ *
+ * Since: 3.8
+ */
+void
+e_source_revision_guards_set_enabled (ESourceRevisionGuards *extension,
+ gboolean enabled)
+{
+ g_return_if_fail (E_IS_SOURCE_REVISION_GUARDS (extension));
+
+ g_mutex_lock (&extension->priv->property_lock);
+
+ if (extension->priv->enabled == enabled) {
+ g_mutex_unlock (&extension->priv->property_lock);
+ return;
+ }
+
+ extension->priv->enabled = enabled;
+
+ g_mutex_unlock (&extension->priv->property_lock);
+
+ g_object_notify (G_OBJECT (extension), "enabled");
+}
+
+
+/**
+ * e_source_revision_guards_get_enabled:
+ * @extension: An #ESourceRevisionGuards
+ *
+ * Checks whether revision guards for the given #ESource are enabled.
+ *
+ * Returns: %TRUE if the revision guards are enabled.
+ *
+ * Since: 3.8
+ */
+gboolean
+e_source_revision_guards_get_enabled (ESourceRevisionGuards *extension)
+{
+ gboolean enabled;
+
+ g_return_val_if_fail (E_IS_SOURCE_REVISION_GUARDS (extension), FALSE);
+
+ g_mutex_lock (&extension->priv->property_lock);
+ enabled = extension->priv->enabled;
+ g_mutex_unlock (&extension->priv->property_lock);
+
+ return enabled;
+}
diff --git a/libedataserver/e-source-revision-guards.h b/libedataserver/e-source-revision-guards.h
new file mode 100644
index 0000000..fadf318
--- /dev/null
+++ b/libedataserver/e-source-revision-guards.h
@@ -0,0 +1,94 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/* e-source-revision-guards.h - Revision Guard Configuration.
+ *
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU Lesser General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Authors: Tristan Van Berkom <tristanvb openismus com>
+ */
+
+#if !defined (__LIBEDATASERVER_H_INSIDE__) && !defined (LIBEDATASERVER_COMPILATION)
+#error "Only <libedataserver/libedataserver.h> should be included directly."
+#endif
+
+#ifndef E_SOURCE_REVISION_GUARDS_H
+#define E_SOURCE_REVISION_GUARDS_H
+
+#include <libedataserver/e-source-extension.h>
+
+/* Standard GObject macros */
+#define E_TYPE_SOURCE_REVISION_GUARDS \
+ (e_source_revision_guards_get_type ())
+#define E_SOURCE_REVISION_GUARDS(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_SOURCE_REVISION_GUARDS, ESourceRevisionGuards))
+#define E_SOURCE_REVISION_GUARDS_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), E_TYPE_SOURCE_REVISION_GUARDS, ESourceRevisionGuardsClass))
+#define E_IS_SOURCE_REVISION_GUARDS(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), E_TYPE_SOURCE_REVISION_GUARDS))
+#define E_IS_SOURCE_REVISION_GUARDS_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), E_TYPE_SOURCE_REVISION_GUARDS))
+#define E_SOURCE_REVISION_GUARDS_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), E_TYPE_SOURCE_REVISION_GUARDS, ESourceRevisionGuardsClass))
+
+/**
+ * E_SOURCE_EXTENSION_REVISION_GUARDS:
+ *
+ * Pass this extension name to e_source_get_extension() to access
+ * #ESourceRevisionGuards. This is also used as a group name in key files.
+ *
+ * Since: 3.8
+ **/
+#define E_SOURCE_EXTENSION_REVISION_GUARDS "Revision Guards"
+
+G_BEGIN_DECLS
+
+typedef struct _ESourceRevisionGuards ESourceRevisionGuards;
+typedef struct _ESourceRevisionGuardsClass ESourceRevisionGuardsClass;
+typedef struct _ESourceRevisionGuardsPrivate ESourceRevisionGuardsPrivate;
+
+/**
+ * ESourceRevisionGuards:
+ *
+ * Contains only private data that should be read and manipulated using the
+ * functions below.
+ *
+ * Since: 3.8
+ **/
+struct _ESourceRevisionGuards {
+ ESourceExtension parent;
+ ESourceRevisionGuardsPrivate *priv;
+};
+
+struct _ESourceRevisionGuardsClass {
+ ESourceExtensionClass parent_class;
+};
+
+GType e_source_revision_guards_get_type (void);
+
+void e_source_revision_guards_set_enabled (ESourceRevisionGuards *extension,
+ gboolean enabled);
+gboolean e_source_revision_guards_get_enabled (ESourceRevisionGuards *extension);
+
+
+G_END_DECLS
+
+#endif /* E_SOURCE_REVISION_GUARDS_H */
diff --git a/libedataserver/libedataserver.h b/libedataserver/libedataserver.h
index 1bf689c..fab63a3 100644
--- a/libedataserver/libedataserver.h
+++ b/libedataserver/libedataserver.h
@@ -61,6 +61,7 @@
#include <libedataserver/e-source-refresh.h>
#include <libedataserver/e-source-registry.h>
#include <libedataserver/e-source-resource.h>
+#include <libedataserver/e-source-revision-guards.h>
#include <libedataserver/e-source-security.h>
#include <libedataserver/e-source-selectable.h>
#include <libedataserver/e-source-smime.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]