[libsocialweb] contacts: add SwCacheable interface



commit 6bd9ae5416620b3e76dd67eec51216537e197b83
Author: Alban Crequy <alban crequy collabora co uk>
Date:   Thu Mar 24 11:19:59 2011 +0000

    contacts: add SwCacheable interface

 libsocialweb/Makefile.am    |    2 +
 libsocialweb/sw-cacheable.c |   62 +++++++++++++++++++++++++++++++++++++++++++
 libsocialweb/sw-cacheable.h |   59 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 123 insertions(+), 0 deletions(-)
---
diff --git a/libsocialweb/Makefile.am b/libsocialweb/Makefile.am
index 284543a..fa7d88b 100644
--- a/libsocialweb/Makefile.am
+++ b/libsocialweb/Makefile.am
@@ -20,6 +20,7 @@ libsocialweb_la_LIBADD = $(DBUS_GLIB_LIBS) $(SOUP_LIBS) $(SOUP_GNOME_LIBS) \
 
 libsocialweb_la_SOURCES = sw-types.h \
 		       sw-debug.c sw-debug.h \
+		       sw-cacheable.c sw-cacheable.h \
 		       sw-core.c sw-core.h \
 		       sw-contact.c sw-contact.h \
 		       sw-contact-view.c sw-contact-view.h \
@@ -39,6 +40,7 @@ libsocialweb_la_SOURCES = sw-types.h \
 		       sw-enum-types.h sw-enum-types.c
 
 public_headers = \
+	sw-cacheable.h \
 	sw-core.h \
 	sw-types.h \
 	sw-service.h \
diff --git a/libsocialweb/sw-cacheable.c b/libsocialweb/sw-cacheable.c
new file mode 100644
index 0000000..5765f2f
--- /dev/null
+++ b/libsocialweb/sw-cacheable.c
@@ -0,0 +1,62 @@
+/*
+ * libsocialweb - social data store
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU Lesser 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 St - Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "sw-cacheable.h"
+
+G_DEFINE_INTERFACE (SwCacheable, sw_cacheable, G_TYPE_OBJECT)
+
+static void
+sw_cacheable_default_init (SwCacheableInterface *iface)
+{
+}   
+
+const gchar *
+sw_cacheable_get_id (SwCacheable *self)
+{
+  SwCacheableInterface *iface = SW_CACHEABLE_GET_IFACE (self);
+  g_return_val_if_fail (iface, NULL);
+
+  return iface->get_id (self);
+}
+
+gboolean
+sw_cacheable_is_ready (SwCacheable *self)
+{
+  SwCacheableInterface *iface = SW_CACHEABLE_GET_IFACE (self);
+  g_return_val_if_fail (iface, FALSE);
+
+  return iface->is_ready (self);
+}
+
+void
+sw_cacheable_save_into_cache (SwCacheable *self, GKeyFile *keys)
+{
+  SwCacheableInterface *iface = SW_CACHEABLE_GET_IFACE (self);
+  const gchar *group;
+  g_return_if_fail (iface);
+
+  group = sw_cacheable_get_id (self);
+  if (group == NULL)
+    return;
+
+  /* Skip items that are not ready. Their properties will not be intact */
+  if (!sw_cacheable_is_ready (self))
+    return;
+
+  return iface->save_into_cache (self, keys, group);
+}
diff --git a/libsocialweb/sw-cacheable.h b/libsocialweb/sw-cacheable.h
new file mode 100644
index 0000000..6fd77da
--- /dev/null
+++ b/libsocialweb/sw-cacheable.h
@@ -0,0 +1,59 @@
+/*
+ * libsocialweb - social data store
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU Lesser 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 St - Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#ifndef _SW_CACHEABLE
+#define _SW_CACHEABLE
+
+#include <glib-object.h>
+#include <libsocialweb/sw-types.h>
+#include <libsocialweb/sw-item.h>
+#include <libsocialweb/sw-set.h>
+#include <libsocialweb/sw-enum-types.h>
+
+G_BEGIN_DECLS
+
+#define SW_TYPE_CACHEABLE            (sw_cacheable_get_type ())
+#define SW_CACHEABLE(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+    SW_TYPE_CACHEABLE, SwCacheable))
+#define SW_IS_CACHEABLE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+    SW_TYPE_CACHEABLE))
+#define SW_CACHEABLE_GET_IFACE(obj)  (G_TYPE_INSTANCE_GET_INTERFACE ((obj), \
+    SW_TYPE_CACHEABLE, SwCacheableInterface))
+
+typedef struct _SwCacheable SwCacheable;
+typedef struct _SwCacheableInterface SwCacheableInterface;
+struct _SwCacheableInterface {
+  GTypeInterface parent_iface;
+  const gchar * (*get_id) (SwCacheable *self);
+  gboolean (*is_ready) (SwCacheable *self);
+  void (*save_into_cache) (SwCacheable *self, GKeyFile *keys,
+                           const gchar *group);
+};
+
+GType sw_cacheable_get_type (void);
+
+const gchar *sw_cacheable_get_id (SwCacheable *self);
+gboolean sw_cacheable_is_ready (SwCacheable *self);
+void sw_cacheable_save_into_cache (SwCacheable *self, GKeyFile *keys);
+
+
+G_END_DECLS
+
+#endif /* _SW_CACHEABLE */
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]