[tracker] Add initial tracker-writeback implementation.



commit b3a6a1b93e99f6f72d8c3a87f9bc31ead03b9807
Author: Carlos Garnacho <carlos lanedo com>
Date:   Tue Nov 10 17:48:53 2009 +0100

    Add initial tracker-writeback implementation.
    
    It does close to nothing at the moment, but functionality will be added over
    time.

 configure.ac                                       |    1 +
 data/dbus/Makefile.am                              |    3 +-
 data/dbus/tracker-writeback.xml                    |   12 +
 src/Makefile.am                                    |    3 +-
 src/tracker-writeback/Makefile.am                  |   59 ++++++
 src/tracker-writeback/tracker-main.c               |   42 ++++
 src/tracker-writeback/tracker-writeback-dbus.h     |   39 ++++
 .../tracker-writeback-dispatcher.c                 |  217 ++++++++++++++++++++
 .../tracker-writeback-dispatcher.h                 |   55 +++++
 src/tracker-writeback/tracker-writeback-module.c   |  155 ++++++++++++++
 src/tracker-writeback/tracker-writeback-module.h   |   59 ++++++
 src/tracker-writeback/tracker-writeback.c          |   20 ++
 src/tracker-writeback/tracker-writeback.h          |   48 +++++
 13 files changed, 711 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8cd2046..f1dbab9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1479,6 +1479,7 @@ AC_CONFIG_FILES([
 	src/tracker-search-tool/tracker-search-tool.desktop.in
 	src/tracker-explorer/Makefile
 	src/tracker-utils/Makefile
+        src/tracker-writeback/Makefile
 	src/plugins/Makefile
 	src/plugins/evolution/Makefile
 	src/plugins/kmail/Makefile
diff --git a/data/dbus/Makefile.am b/data/dbus/Makefile.am
index b759f69..8522516 100644
--- a/data/dbus/Makefile.am
+++ b/data/dbus/Makefile.am
@@ -8,7 +8,8 @@ config_DATA =							\
 	tracker-miner.xml					\
 	tracker-resources.xml					\
 	tracker-resources-class.xml				\
-	tracker-statistics.xml
+	tracker-statistics.xml					\
+	tracker-writeback.xml
 
 # Services
 servicedir = $(DBUS_SERVICES_DIR)
diff --git a/data/dbus/tracker-writeback.xml b/data/dbus/tracker-writeback.xml
new file mode 100644
index 0000000..f1466f6
--- /dev/null
+++ b/data/dbus/tracker-writeback.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<node name="/">
+  <interface name="org.freedesktop.Tracker1.Writeback">
+    <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="tracker_writeback_dbus"/>
+
+    <method name="UpdateMetadata">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="s" name="uri" direction="in" />
+    </method>
+  </interface>
+</node>
diff --git a/src/Makefile.am b/src/Makefile.am
index 69b27ad..f7d2409 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,7 +14,8 @@ SUBDIRS = 					\
 	tracker-control				\
 	tracker-utils				\
 	tracker-extract				\
-	tracker-miner-fs
+	tracker-miner-fs			\
+	tracker-writeback
 
 if HAVE_TRACKER_PREFERENCES
 SUBDIRS += tracker-preferences
diff --git a/src/tracker-writeback/Makefile.am b/src/tracker-writeback/Makefile.am
new file mode 100644
index 0000000..60988c9
--- /dev/null
+++ b/src/tracker-writeback/Makefile.am
@@ -0,0 +1,59 @@
+include $(top_srcdir)/Makefile.decl
+
+module_flags = -module -avoid-version -no-undefined
+modulesdir = $(libdir)/tracker-$(TRACKER_API_VERSION)/writeback-modules
+
+INCLUDES = 								\
+	-DLOCALEDIR=\""$(localedir)"\" 					\
+	-DMODULESDIR=\"$(modulesdir)\"					\
+	-DG_LOG_DOMAIN=\"Tracker\"					\
+	-DTRACKER_COMPILATION						\
+	-DWRITEBACK_MODULES_DIR=\""$(modulesdir)"\"			\
+	-I$(top_srcdir)/src 						\
+	$(WARN_CFLAGS)							\
+	$(GLIB2_CFLAGS)							\
+	$(GCOV_CFLAGS)							\
+	$(GMODULE_CFLAGS) 						\
+	$(DBUS_CFLAGS)
+
+#modules_LTLIBRARIES = 							\
+#	libwriteback-dummy.la
+
+# dummy
+#libwriteback_dummy_la_SOURCES = tracker-writeback-dummy.c
+#libwriteback_dummy_la_LDFLAGS = $(module_flags)
+#libwriteback_dummy_la_LIBADD = $(GLIB2_LIBS) $(GCOV_LIBS)
+
+#
+# Binaries
+#
+libexec_PROGRAMS = tracker-writeback
+
+tracker_writeback_SOURCES = 						\
+	$(dbus_sources)							\
+	tracker-writeback-dispatcher.c					\
+	tracker-writeback-dispatcher.h					\
+	tracker-writeback-module.c					\
+	tracker-writeback-module.h					\
+	tracker-writeback.c						\
+	tracker-writeback.h						\
+	tracker-main.c
+
+tracker_writeback_LDADD = 						\
+	$(top_builddir)/src/libtracker-common/libtracker-common.la	\
+	$(DBUS_LIBS)							\
+	$(GMODULE_LIBS)							\
+	$(GTHREAD_LIBS)							\
+	$(GCOV_LIBS)							\
+	$(GLIB2_LIBS)
+
+dbus_sources = 								\
+	tracker-writeback-glue.h
+
+%-glue.h: $(top_srcdir)/data/dbus/%.xml
+	$(AM_V_GEN)$(DBUSBINDINGTOOL) --mode=glib-server --output=$@ --prefix=$(subst -,_,$*) $^
+
+BUILT_SOURCES = 							\
+	$(dbus_sources)
+
+CLEANFILES = $(BUILT_SOURCES)
diff --git a/src/tracker-writeback/tracker-main.c b/src/tracker-writeback/tracker-main.c
new file mode 100644
index 0000000..e84833c
--- /dev/null
+++ b/src/tracker-writeback/tracker-main.c
@@ -0,0 +1,42 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 "config.h"
+#include "tracker-writeback-dispatcher.h"
+#include <stdlib.h>
+
+int
+main (int   argc,
+      char *argv[])
+{
+        TrackerWritebackDispatcher *dispatcher;
+        GMainLoop *loop;
+
+        g_type_init ();
+
+        loop = g_main_loop_new (NULL, FALSE);
+        dispatcher = tracker_writeback_dispatcher_new ();
+
+        g_main_loop_run (loop);
+
+        g_object_unref (dispatcher);
+
+        return EXIT_SUCCESS;
+}
diff --git a/src/tracker-writeback/tracker-writeback-dbus.h b/src/tracker-writeback/tracker-writeback-dbus.h
new file mode 100644
index 0000000..e22faff
--- /dev/null
+++ b/src/tracker-writeback/tracker-writeback-dbus.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 __TRACKER_WRITEBACK_DBUS_H__
+#define __TRACKER_WRITEBACK_DBUS_H__
+
+G_BEGIN_DECLS
+
+#include "tracker-writeback-dispatcher.h"
+
+#define TRACKER_WRITEBACK_DBUS_INTERFACE "org.freedesktop.Tracker1.Writeback"
+#define TRACKER_WRITEBACK_DBUS_NAME      "org.freedesktop.Tracker1.Writeback"
+#define TRACKER_WRITEBACK_DBUS_PATH      "/org/freedesktop/Tracker1/Writeback"
+
+void tracker_writeback_dbus_update_metadata  (TrackerWritebackDispatcher  *dispatcher,
+                                              const gchar                 *uri,
+                                              DBusGMethodInvocation       *context,
+                                              GError                     **error);
+
+G_END_DECLS
+
+#endif /* __TRACKER_WRITEBACK_DBUS_H__ */
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.c b/src/tracker-writeback/tracker-writeback-dispatcher.c
new file mode 100644
index 0000000..667fe19
--- /dev/null
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.c
@@ -0,0 +1,217 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 "tracker-writeback-dispatcher.h"
+#include "tracker-writeback-dbus.h"
+#include "tracker-writeback-glue.h"
+#include "tracker-writeback-module.h"
+#include <libtracker-common/tracker-dbus.h>
+
+typedef struct {
+	DBusGConnection *connection;
+	DBusGProxy *gproxy;
+} DBusData;
+
+typedef struct {
+        GHashTable *modules;
+        DBusData *dbus_data;
+} TrackerWritebackDispatcherPrivate;
+
+#define TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcherPrivate))
+
+static void tracker_writeback_dispatcher_finalize    (GObject *object);
+static void tracker_writeback_dispatcher_constructed (GObject *object);
+
+
+G_DEFINE_TYPE (TrackerWritebackDispatcher, tracker_writeback_dispatcher, G_TYPE_OBJECT)
+
+
+static void
+tracker_writeback_dispatcher_class_init (TrackerWritebackDispatcherClass *klass)
+{
+        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+        object_class->finalize = tracker_writeback_dispatcher_finalize;
+        object_class->constructed = tracker_writeback_dispatcher_constructed;
+
+	g_type_class_add_private (object_class, sizeof (TrackerWritebackDispatcherPrivate));
+}
+
+static gboolean
+dbus_register_service (DBusGProxy  *proxy,
+                       const gchar *name)
+{
+	GError *error = NULL;
+	guint	result;
+
+	g_message ("Registering D-Bus service '%s'...", name);
+
+	if (!org_freedesktop_DBus_request_name (proxy,
+						name,
+						DBUS_NAME_FLAG_DO_NOT_QUEUE,
+						&result, &error)) {
+		g_critical ("Could not acquire name:'%s', %s",
+			    name,
+			    error ? error->message : "no error given");
+		g_error_free (error);
+
+		return FALSE;
+	}
+
+	if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+		g_critical ("D-Bus service name:'%s' is already taken, "
+			    "perhaps the application is already running?",
+			    name);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static gboolean
+dbus_register_object (GObject		    *object,
+		      DBusGConnection	    *connection,
+		      DBusGProxy	    *proxy,
+		      const DBusGObjectInfo *info,
+		      const gchar	    *path)
+{
+	g_message ("Registering D-Bus object...");
+	g_message ("  Path:'%s'", path);
+	g_message ("  Object Type:'%s'", G_OBJECT_TYPE_NAME (object));
+
+	dbus_g_object_type_install_info (G_OBJECT_TYPE (object), info);
+	dbus_g_connection_register_g_object (connection, path, object);
+
+	return TRUE;
+}
+
+static DBusData *
+dbus_data_create (GObject *object)
+{
+	DBusData *data;
+	DBusGConnection *connection;
+	DBusGProxy *gproxy;
+	GError *error = NULL;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+	if (!connection) {
+		g_critical ("Could not connect to the D-Bus session bus, %s",
+			    error ? error->message : "no error given.");
+		g_error_free (error);
+		return NULL;
+	}
+
+	gproxy = dbus_g_proxy_new_for_name (connection,
+					    DBUS_SERVICE_DBUS,
+					    DBUS_PATH_DBUS,
+					    DBUS_INTERFACE_DBUS);
+
+	if (!dbus_register_service (gproxy,
+                                    TRACKER_WRITEBACK_DBUS_NAME)) {
+		g_object_unref (gproxy);
+		return NULL;
+	}
+
+	if (!dbus_register_object (object,
+				   connection, gproxy,
+				   &dbus_glib_tracker_writeback_object_info,
+				   TRACKER_WRITEBACK_DBUS_PATH)) {
+		g_object_unref (gproxy);
+		return NULL;
+	}
+
+	/* Now we're successfully connected and registered, create the data */
+	data = g_slice_new0 (DBusData);
+	data->connection = dbus_g_connection_ref (connection);
+	data->gproxy = g_object_ref (gproxy);
+
+	return data;
+}
+
+static void
+tracker_writeback_dispatcher_init (TrackerWritebackDispatcher *dispatcher)
+{
+        TrackerWritebackDispatcherPrivate *priv;
+
+        priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (dispatcher);
+
+        priv->dbus_data = dbus_data_create (G_OBJECT (dispatcher));
+        priv->modules = g_hash_table_new_full (g_str_hash,
+                                               g_str_equal,
+                                               (GDestroyNotify) g_free,
+                                               NULL);
+}
+
+static void
+tracker_writeback_dispatcher_finalize (GObject *object)
+{
+        G_OBJECT_CLASS (tracker_writeback_dispatcher_parent_class)->finalize (object);
+}
+
+static void
+tracker_writeback_dispatcher_constructed (GObject *object)
+{
+        GList *modules;
+        TrackerWritebackDispatcherPrivate *priv;
+
+        priv = TRACKER_WRITEBACK_DISPATCHER_GET_PRIVATE (object);
+        modules = tracker_writeback_modules_list ();
+
+        while (modules) {
+                TrackerWritebackModule *module;
+                const gchar *path;
+
+                path = modules->data;
+                module = tracker_writeback_module_get (path);
+
+                g_hash_table_insert (priv->modules, g_strdup (path), module);
+
+                modules = modules->next;
+        }
+}
+
+TrackerWritebackDispatcher *
+tracker_writeback_dispatcher_new ()
+{
+        return g_object_new (TRACKER_TYPE_WRITEBACK_DISPATCHER, NULL);
+}
+
+void
+tracker_writeback_dbus_update_metadata (TrackerWritebackDispatcher  *dispatcher,
+                                        const gchar                 *uri,
+                                        DBusGMethodInvocation       *context,
+                                        GError                     **error)
+{
+	guint request_id;
+
+	request_id = tracker_dbus_get_next_request_id ();
+
+	tracker_dbus_async_return_if_fail (dispatcher != NULL, context);
+	tracker_dbus_async_return_if_fail (uri != NULL, context);
+
+	tracker_dbus_request_new (request_id, "%s for '%s'",
+				  __PRETTY_FUNCTION__,
+                                  uri);
+
+	dbus_g_method_return (context);
+
+	tracker_dbus_request_success (request_id);
+}
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.h b/src/tracker-writeback/tracker-writeback-dispatcher.h
new file mode 100644
index 0000000..f34ba9d
--- /dev/null
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.h
@@ -0,0 +1,55 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 __TRACKER_WRITEBACK_DISPATCHER_H__
+#define __TRACKER_WRITEBACK_DISPATCHER_H__
+
+
+#include <glib-object.h>
+#include <gio/gio.h>
+#include <libtracker-client/tracker.h>
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_WRITEBACK_DISPATCHER         (tracker_writeback_dispatcher_get_type())
+#define TRACKER_WRITEBACK_DISPATCHER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcher))
+#define TRACKER_WRITEBACK_DISPATCHER_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcherClass))
+#define TRACKER_IS_WRITEBACK_DISPATCHER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER))
+#define TRACKER_IS_WRITEBACK_DISPATCHER_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c),  TRACKER_TYPE_WRITEBACK_DISPATCHER))
+#define TRACKER_WRITEBACK_DISPATCHER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_WRITEBACK_DISPATCHER, TrackerWritebackDispatcherClass))
+
+typedef struct TrackerWritebackDispatcher TrackerWritebackDispatcher;
+typedef struct TrackerWritebackDispatcherClass TrackerWritebackDispatcherClass;
+
+struct TrackerWritebackDispatcher {
+        GObject parent_instance;
+};
+
+struct TrackerWritebackDispatcherClass {
+        GObjectClass parent_class;
+};
+
+GType          tracker_writeback_dispatcher_get_type (void) G_GNUC_CONST;
+
+TrackerWritebackDispatcher * tracker_writeback_dispatcher_new (void);
+
+G_END_DECLS
+
+#endif /* __TRACKER_WRITEBACK_DISPATCHER_H__ */
diff --git a/src/tracker-writeback/tracker-writeback-module.c b/src/tracker-writeback/tracker-writeback-module.c
new file mode 100644
index 0000000..ecd8bbc
--- /dev/null
+++ b/src/tracker-writeback/tracker-writeback-module.c
@@ -0,0 +1,155 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 <gmodule.h>
+#include "tracker-writeback-module.h"
+
+
+static gboolean tracker_writeback_module_load   (GTypeModule *module);
+static void     tracker_writeback_module_unload (GTypeModule *module);
+
+
+G_DEFINE_TYPE (TrackerWritebackModule, tracker_writeback_module, G_TYPE_TYPE_MODULE)
+
+static void
+tracker_writeback_module_class_init (TrackerWritebackModuleClass *klass)
+{
+  GTypeModuleClass *module_class = G_TYPE_MODULE_CLASS (klass);
+
+  module_class->load = tracker_writeback_module_load;
+  module_class->unload = tracker_writeback_module_unload;
+}
+
+static void
+tracker_writeback_module_init (TrackerWritebackModule *module)
+{
+}
+
+static gboolean
+tracker_writeback_module_load (GTypeModule *module)
+{
+	TrackerWritebackModule *writeback_module;
+	gchar *path;
+
+	writeback_module = TRACKER_WRITEBACK_MODULE (module);
+
+	path = g_build_filename (WRITEBACK_MODULES_DIR, writeback_module->name, NULL);
+	writeback_module->module = g_module_open (path, G_MODULE_BIND_LOCAL);
+	g_free (path);
+
+	if (G_UNLIKELY (!writeback_module->module)) {
+		g_warning ("Could not load writeback module '%s': %s\n",
+			   writeback_module->name,
+			   g_module_error ());
+
+		return FALSE;
+	}
+
+	g_module_make_resident (writeback_module->module);
+
+	if (!g_module_symbol (writeback_module->module, "writeback_module_initialize",
+			      (gpointer *) &writeback_module->initialize) ||
+	    !g_module_symbol (writeback_module->module, "writeback_module_shutdown",
+			      (gpointer *) &writeback_module->shutdown)) {
+		g_warning ("Could not load module symbols for '%s': %s",
+			   writeback_module->name,
+			   g_module_error ());
+
+		return FALSE;
+	}
+
+	writeback_module->initialize (module);
+
+	return TRUE;
+}
+
+static void
+tracker_writeback_module_unload (GTypeModule *module)
+{
+	TrackerWritebackModule *writeback_module;
+
+	writeback_module = TRACKER_WRITEBACK_MODULE (module);
+	writeback_module->shutdown ();
+
+	g_module_close (writeback_module->module);
+	writeback_module->module = NULL;
+
+	writeback_module->initialize = NULL;
+	writeback_module->shutdown = NULL;
+}
+
+TrackerWritebackModule *
+tracker_writeback_module_get (const gchar *name)
+{
+	static GHashTable *modules;
+	TrackerWritebackModule *module;
+
+	g_return_val_if_fail (name != NULL, NULL);
+
+	if (G_UNLIKELY (!modules)) {
+		modules = g_hash_table_new (g_str_hash, g_str_equal);
+	}
+
+	module = g_hash_table_lookup (modules, name);
+
+	if (G_UNLIKELY (!module)) {
+		module = g_object_new (TRACKER_TYPE_WRITEBACK_MODULE, NULL);
+		g_type_module_set_name (G_TYPE_MODULE (module), name);
+		module->name = g_strdup (name);
+
+		g_hash_table_insert (modules, module->name, module);
+	}
+
+	if (!g_type_module_use (G_TYPE_MODULE (module))) {
+		return NULL;
+	}
+
+	return module;
+}
+
+GList *
+tracker_writeback_modules_list (void)
+{
+        GError *error = NULL;
+        const gchar *name;
+        GList *list = NULL;
+        GDir *dir;
+
+        dir = g_dir_open (WRITEBACK_MODULES_DIR, 0, &error);
+
+        if (error) {
+                g_critical ("Could not get writeback modules list: %s", error->message);
+                g_error_free (error);
+                return NULL;
+        }
+
+        while ((name = g_dir_read_name (dir)) != NULL) {
+                if (!g_str_has_suffix (name, G_MODULE_SUFFIX)) {
+                        continue;
+                }
+
+                list = g_list_prepend (list, g_strdup (name));
+        }
+
+        g_dir_close (dir);
+
+        return list;
+}
diff --git a/src/tracker-writeback/tracker-writeback-module.h b/src/tracker-writeback/tracker-writeback-module.h
new file mode 100644
index 0000000..5e23349
--- /dev/null
+++ b/src/tracker-writeback/tracker-writeback-module.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 __TRACKER_WRITEBACK_MODULE_H__
+#define __TRACKER_WRITEBACK_MODULE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_WRITEBACK_MODULE    (tracker_writeback_module_get_type ())
+#define TRACKER_WRITEBACK_MODULE(module) (G_TYPE_CHECK_INSTANCE_CAST ((module), TRACKER_TYPE_WRITEBACK_MODULE, TrackerWritebackModule))
+
+typedef struct TrackerWritebackModule TrackerWritebackModule;
+typedef struct TrackerWritebackModuleClass TrackerWritebackModuleClass;
+
+struct TrackerWritebackModule {
+	GTypeModule parent_instance;
+
+	GModule *module;
+	gchar *name;
+
+        void (* initialize) (GTypeModule *module);
+        void (* shutdown)   (void);
+};
+
+struct TrackerWritebackModuleClass {
+	GTypeModuleClass parent_class;
+};
+
+
+GType                     tracker_writeback_module_get_type               (void) G_GNUC_CONST;
+
+TrackerWritebackModule *  tracker_writeback_module_get                    (const gchar *name);
+GList *                   tracker_writeback_modules_list                  (void);
+
+
+G_END_DECLS
+
+#endif /* __TRACKER_WRITEBACK_MODULE_H__ */
diff --git a/src/tracker-writeback/tracker-writeback.c b/src/tracker-writeback/tracker-writeback.c
new file mode 100644
index 0000000..a4b274b
--- /dev/null
+++ b/src/tracker-writeback/tracker-writeback.c
@@ -0,0 +1,20 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
diff --git a/src/tracker-writeback/tracker-writeback.h b/src/tracker-writeback/tracker-writeback.h
new file mode 100644
index 0000000..9f27e41
--- /dev/null
+++ b/src/tracker-writeback/tracker-writeback.h
@@ -0,0 +1,48 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 __TRACKER_WRITEBACK_H__
+#define __TRACKER_WRITEBACK_H__
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_WRITEBACK         (tracker_writeback_get_type())
+#define TRACKER_WRITEBACK(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_WRITEBAK, TrackerWriteback))
+#define TRACKER_WRITEBACK_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_WRITEBACK, TrackerWritebackClass))
+#define TRACKER_IS_WRITEBACK(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_WRITEBACK))
+#define TRACKER_IS_WRITEBACK_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c),  TRACKER_TYPE_WRITEBACK))
+#define TRACKER_WRITEBACK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_WRITEBACK, TrackerWritebackClass))
+
+typedef struct TrackerWriteback TrackerWriteback;
+typedef struct TrackerWritebackClass TrackerWritebackClass;
+
+struct TrackerWriteback {
+        GObject parent_instance;
+};
+
+struct TrackerWritebackClass {
+        GObjectClass parent_class;
+};
+
+GType          tracker_writeback_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __TRACKER_WRITEBACK_H__ */



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