[tracker/libtracker-miner: 1/3] Add TrackerMiner abstract class, plus TrackerMinerTest impl+app.



commit 0be2636cfafafdee788c1856d5f3eb39dc49c8ad
Author: Carlos Garnacho <carlos lanedo com>
Date:   Thu Jul 30 13:47:27 2009 +0200

    Add TrackerMiner abstract class, plus TrackerMinerTest impl+app.
    
    * tracker-dbus.[ch]: Implements DBus initialization, all this is private to
      TrackerMiner.
    * tracker-miner.[ch]: Base class for miners.
    * tracker-miner-dbus.h: Private header for DBus method declarations.
    * tracker-miner-test.[ch], tracker-main.c: Test app.

 INSTALL                                   |   94 +++++++--
 configure.ac                              |    3 +-
 data/dbus/tracker-miner.xml               |    4 +-
 src/Makefile.am                           |    1 +
 src/libtracker-miner/Makefile.am          |   76 +++++++
 src/libtracker-miner/tracker-dbus.c       |  325 +++++++++++++++++++++++++++++
 src/libtracker-miner/tracker-dbus.h       |   54 +++++
 src/libtracker-miner/tracker-main.c       |   61 ++++++
 src/libtracker-miner/tracker-miner-dbus.h |   38 ++++
 src/libtracker-miner/tracker-miner-test.c |   43 ++++
 src/libtracker-miner/tracker-miner-test.h |   52 +++++
 src/libtracker-miner/tracker-miner.c      |  250 ++++++++++++++++++++++
 src/libtracker-miner/tracker-miner.h      |   67 ++++++
 13 files changed, 1045 insertions(+), 23 deletions(-)
---
diff --git a/INSTALL b/INSTALL
index d3c5b40..8b82ade 100644
--- a/INSTALL
+++ b/INSTALL
@@ -2,15 +2,15 @@ Installation Instructions
 *************************
 
 Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
-2006, 2007 Free Software Foundation, Inc.
+2006, 2007, 2008 Free Software Foundation, Inc.
 
-This file is free documentation; the Free Software Foundation gives
+   This file is free documentation; the Free Software Foundation gives
 unlimited permission to copy, distribute and modify it.
 
 Basic Installation
 ==================
 
-Briefly, the shell commands `./configure; make; make install' should
+   Briefly, the shell commands `./configure; make; make install' should
 configure, build, and install this package.  The following
 more-detailed instructions are generic; see the `README' file for
 instructions specific to this package.
@@ -73,9 +73,9 @@ The simplest way to compile this package is:
 Compilers and Options
 =====================
 
-Some systems require unusual options for compilation or linking that the
-`configure' script does not know about.  Run `./configure --help' for
-details on some of the pertinent environment variables.
+   Some systems require unusual options for compilation or linking that
+the `configure' script does not know about.  Run `./configure --help'
+for details on some of the pertinent environment variables.
 
    You can give `configure' initial values for configuration parameters
 by setting variables in the command line or in the environment.  Here
@@ -88,7 +88,7 @@ is an example:
 Compiling For Multiple Architectures
 ====================================
 
-You can compile the package for more than one kind of computer at the
+   You can compile the package for more than one kind of computer at the
 same time, by placing the object files for each architecture in their
 own directory.  To do this, you can use GNU `make'.  `cd' to the
 directory where you want the object files and executables to go and run
@@ -100,10 +100,24 @@ architecture at a time in the source code directory.  After you have
 installed the package for one architecture, use `make distclean' before
 reconfiguring for another architecture.
 
+   On MacOS X 10.5 and later systems, you can create libraries and
+executables that work on multiple system types--known as "fat" or
+"universal" binaries--by specifying multiple `-arch' options to the
+compiler but only a single `-arch' option to the preprocessor.  Like
+this:
+
+     ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
+                 CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
+                 CPP="gcc -E" CXXCPP="g++ -E"
+
+   This is not guaranteed to produce working output in all cases, you
+may have to build one architecture at a time and combine the results
+using the `lipo' tool if you have problems.
+
 Installation Names
 ==================
 
-By default, `make install' installs the package's commands under
+   By default, `make install' installs the package's commands under
 `/usr/local/bin', include files under `/usr/local/include', etc.  You
 can specify an installation prefix other than `/usr/local' by giving
 `configure' the option `--prefix=PREFIX'.
@@ -126,7 +140,7 @@ option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
 Optional Features
 =================
 
-Some packages pay attention to `--enable-FEATURE' options to
+   Some packages pay attention to `--enable-FEATURE' options to
 `configure', where FEATURE indicates an optional part of the package.
 They may also pay attention to `--with-PACKAGE' options, where PACKAGE
 is something like `gnu-as' or `x' (for the X Window System).  The
@@ -138,14 +152,36 @@ find the X include and library files automatically, but if it doesn't,
 you can use the `configure' options `--x-includes=DIR' and
 `--x-libraries=DIR' to specify their locations.
 
+Particular systems
+==================
+
+   On HP-UX, the default C compiler is not ANSI C compatible.  If GNU
+CC is not installed, it is recommended to use the following options in
+order to use an ANSI C compiler:
+
+     ./configure CC="cc -Ae"
+
+and if that doesn't work, install pre-built binaries of GCC for HP-UX.
+
+   On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
+parse its `<wchar.h>' header file.  The option `-nodtk' can be used as
+a workaround.  If GNU CC is not installed, it is therefore recommended
+to try
+
+     ./configure CC="cc"
+
+and if that doesn't work, try
+
+     ./configure CC="cc -nodtk"
+
 Specifying the System Type
 ==========================
 
-There may be some features `configure' cannot figure out automatically,
-but needs to determine by the type of machine the package will run on.
-Usually, assuming the package is built to be run on the _same_
-architectures, `configure' can figure that out, but if it prints a
-message saying it cannot guess the machine type, give it the
+   There may be some features `configure' cannot figure out
+automatically, but needs to determine by the type of machine the package
+will run on.  Usually, assuming the package is built to be run on the
+_same_ architectures, `configure' can figure that out, but if it prints
+a message saying it cannot guess the machine type, give it the
 `--build=TYPE' option.  TYPE can either be a short name for the system
 type, such as `sun4', or a canonical name which has the form:
 
@@ -171,9 +207,9 @@ eventually be run) with `--host=TYPE'.
 Sharing Defaults
 ================
 
-If you want to set default values for `configure' scripts to share, you
-can create a site shell script called `config.site' that gives default
-values for variables like `CC', `cache_file', and `prefix'.
+   If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
 `configure' looks for `PREFIX/share/config.site' if it exists, then
 `PREFIX/etc/config.site' if it exists.  Or, you can set the
 `CONFIG_SITE' environment variable to the location of the site script.
@@ -182,7 +218,7 @@ A warning: not all `configure' scripts look for a site script.
 Defining Variables
 ==================
 
-Variables not defined in a site shell script can be set in the
+   Variables not defined in a site shell script can be set in the
 environment passed to `configure'.  However, some packages may run
 configure again during the build, and the customized values of these
 variables may be lost.  In order to avoid this problem, you should set
@@ -201,11 +237,19 @@ an Autoconf bug.  Until the bug is fixed you can use this workaround:
 `configure' Invocation
 ======================
 
-`configure' recognizes the following options to control how it operates.
+   `configure' recognizes the following options to control how it
+operates.
 
 `--help'
 `-h'
-     Print a summary of the options to `configure', and exit.
+     Print a summary of all of the options to `configure', and exit.
+
+`--help=short'
+`--help=recursive'
+     Print a summary of the options unique to this package's
+     `configure', and exit.  The `short' variant lists options used
+     only in the top level, while the `recursive' variant lists options
+     also present in any nested packages.
 
 `--version'
 `-V'
@@ -232,6 +276,16 @@ an Autoconf bug.  Until the bug is fixed you can use this workaround:
      Look for the package's source code in directory DIR.  Usually
      `configure' can determine that directory automatically.
 
+`--prefix=DIR'
+     Use DIR as the installation prefix.  *Note Installation Names::
+     for more details, including other options available for fine-tuning
+     the installation locations.
+
+`--no-create'
+`-n'
+     Run the configure checks, but stop before creating any output
+     files.
+
 `configure' also accepts some other, not widely useful, options.  Run
 `configure --help' for more details.
 
diff --git a/configure.ac b/configure.ac
index 83d5d43..65f291a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1431,6 +1431,7 @@ AC_CONFIG_FILES([
 	src/libtracker-db/Makefile
 	src/libtracker-gtk/Makefile
 	src/libtracker/Makefile
+        src/libtracker-miner/Makefile
 	src/Makefile
 	src/rasqal/Makefile
 	src/tracker-applet/Makefile
@@ -1514,7 +1515,7 @@ Plugins:
 	Evolution plugin    (data-push):	$have_evolution_plugin
 	KMail plugin        (data-push):	$enable_kmail_push_module
 
-Warning:2
+Warning:
 
         You must make sure SQLite is compiled with --enable-threadsafe
 
diff --git a/data/dbus/tracker-miner.xml b/data/dbus/tracker-miner.xml
index a44183d..7d6f64a 100644
--- a/data/dbus/tracker-miner.xml
+++ b/data/dbus/tracker-miner.xml
@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <node name="/">
-  <interface name="org.freedesktop.Tracker.Miner.FS">
+  <interface name="org.freedesktop.Tracker.Miner">
     <method name="Pause">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
     </method>
-    <method name="Continue">
+    <method name="Resume">
       <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
     </method>
   </interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index c6651b7..1c96b86 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,6 +8,7 @@ SUBDIRS = 					\
 	libtracker-db				\
 	libtracker-data				\
 	libtracker				\
+	libtracker-miner			\
 	tracker-fts				\
 	plugins					\
 	tracker-store				\
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
new file mode 100644
index 0000000..d79a6fe
--- /dev/null
+++ b/src/libtracker-miner/Makefile.am
@@ -0,0 +1,76 @@
+include $(top_srcdir)/Makefile.decl
+
+INCLUDES =						\
+	-DSHAREDIR=\""$(datadir)"\"			\
+	-DG_LOG_DOMAIN=\"Tracker\"			\
+	-DTRACKER_COMPILATION				\
+	-DI_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE	\
+	-I$(top_srcdir)/src				\
+	$(WARN_CFLAGS)					\
+	$(GLIB2_CFLAGS)					\
+	$(GCOV_CFLAGS)					\
+	$(GDKPIXBUF_CFLAGS)				\
+	$(GIO_CFLAGS)					\
+	$(PANGO_CFLAGS)					\
+	$(HAL_CFLAGS)					\
+	$(DEVKIT_POWER_CFLAGS)				\
+	$(DBUS_CFLAGS)					\
+	$(UNAC_CFLAGS)
+
+libtracker_minerdir = $(libdir)/tracker-$(TRACKER_API_VERSION)
+libtracker_minerincludedir=$(includedir)/tracker-$(TRACKER_API_VERSION)/libtracker-miner/
+libtracker_miner_LTLIBRARIES = libtracker-miner.la
+
+libtracker_miner_la_SOURCES = 				\
+	tracker-dbus.c 					\
+	tracker-dbus.h 					\
+	tracker-miner-dbus.h				\
+	tracker-miner.c 				\
+	tracker-miner.h
+
+libtracker_minerinclude_HEADERS = \
+	tracker-miner.h
+
+libtracker_miner_la_LDFLAGS = \
+	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
+
+libtracker_miner_la_LIBADD = 				\
+	$(top_builddir)/src/libstemmer/libstemmer.la	\
+	$(top_builddir)/src/libtracker/libtrackerclient- TRACKER_API_VERSION@.la \
+	$(HAL_LIBS)					\
+	$(DEVKIT_POWER_LIBS)				\
+	$(DBUS_LIBS)					\
+	$(UNAC_LIBS)					\
+	$(PANGO_LIBS)					\
+	$(GIO_LIBS)					\
+	$(GCOV_LIBS)					\
+	$(GLIB2_LIBS)					\
+	$(GDKPIXBUF_LIBS)
+
+dbus_sources = tracker-miner-glue.h
+
+%-glue.h: $(top_srcdir)/data/dbus/%.xml
+	$(DBUSBINDINGTOOL) --mode=glib-server --output=$@ --prefix=$(subst -,_,$*) $^
+
+BUILT_SOURCES = $(dbus_sources)
+
+CLEANFILES = $(BUILT_SOURCES)
+
+libexec_PROGRAMS = tracker-miner-test
+
+tracker_miner_test_SOURCES = 	\
+	tracker-miner-test.c 	\
+	tracker-miner-test.h 	\
+	tracker-main.c
+
+tracker_miner_test_LDADD = 				\
+	libtracker-miner.la			 	\
+	$(DBUS_LIBS)					\
+	$(GMODULE_LIBS)					\
+	$(GTHREAD_LIBS)					\
+	$(GIO_LIBS)					\
+	$(GCOV_LIBS)					\
+	$(GLIB2_LIBS)					\
+	$(RAPTOR_LIBS)					\
+	-lz						\
+	-lm
diff --git a/src/libtracker-miner/tracker-dbus.c b/src/libtracker-miner/tracker-dbus.c
new file mode 100644
index 0000000..c6f4e44
--- /dev/null
+++ b/src/libtracker-miner/tracker-dbus.c
@@ -0,0 +1,325 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, 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 <string.h>
+#include "config.h"
+#include "tracker-dbus.h"
+#include "tracker-miner-dbus.h"
+#include "tracker-miner-glue.h"
+
+typedef struct {
+	DBusGConnection *connection;
+	DBusGProxy      *gproxy;
+	GHashTable      *name_monitors;
+} TrackerDBusData;
+
+#if 0
+typedef struct {
+	TrackerDBusNameMonitorFunc func;
+	gpointer user_data;
+	GDestroyNotify destroy_func;
+} TrackerDBusNameMonitor;
+#endif
+
+static GQuark dbus_data = 0;
+
+static gboolean
+dbus_register_service (DBusGProxy  *proxy,
+		       const gchar *name)
+{
+	GError *error = NULL;
+	guint	result;
+
+	g_message ("Registering DBus service...\n"
+		   "  Name:'%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 ("DBus service name:'%s' is already taken, "
+			    "perhaps the application is already running?",
+			    name);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+#if 0
+static void
+name_owner_changed_cb (DBusGProxy *proxy,
+		       gchar	  *name,
+		       gchar	  *old_owner,
+		       gchar	  *new_owner,
+		       gpointer    user_data)
+{
+	TrackerDBusNameMonitor *name_monitor;
+
+	name_monitor = g_hash_table_lookup (name_monitors, name);
+
+	if (name_monitor) {
+		gboolean available;
+
+		available = (new_owner && *new_owner);
+		(name_monitor->func) (name, available, name_monitor->user_data);
+	}
+}
+#endif
+
+static gboolean
+dbus_register_object (GObject		    *object,
+		      DBusGConnection	    *connection,
+		      DBusGProxy	    *proxy,
+		      const DBusGObjectInfo *info,
+		      const gchar	    *path)
+{
+	g_message ("Registering DBus 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);
+
+#if 0
+	dbus_g_proxy_add_signal (proxy, "NameOwnerChanged",
+				 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
+				 G_TYPE_INVALID);
+
+	dbus_g_proxy_connect_signal (proxy, "NameOwnerChanged",
+				     G_CALLBACK (name_owner_changed_cb),
+				     object, NULL);
+#endif
+	return TRUE;
+}
+
+#if 0
+static TrackerDBusNameMonitor *
+name_monitor_new (TrackerDBusNameMonitorFunc func,
+		  gpointer                   user_data,
+		  GDestroyNotify             destroy_func)
+{
+	TrackerDBusNameMonitor *name_monitor;
+
+	name_monitor = g_slice_new (TrackerDBusNameMonitor);
+	name_monitor->func = func;
+	name_monitor->user_data = user_data;
+	name_monitor->destroy_func = destroy_func;
+
+	return name_monitor;
+}
+
+static void
+name_monitor_free (TrackerDBusNameMonitor *name_monitor)
+{
+	if (name_monitor->user_data && name_monitor->destroy_func) {
+		(name_monitor->destroy_func) (name_monitor->user_data);
+	}
+
+	g_slice_free (TrackerDBusNameMonitor, name_monitor);
+}
+#endif
+
+static void
+dbus_data_destroy (TrackerDBusData *data)
+{
+	if (data->gproxy) {
+		g_object_unref (data->gproxy);
+	}
+
+	if (data->connection) {
+		dbus_g_connection_unref (data->connection);
+	}
+
+	if (data->name_monitors) {
+		g_hash_table_destroy (data->name_monitors);
+	}
+
+	g_slice_free (TrackerDBusData, data);
+}
+
+static TrackerDBusData *
+dbus_data_create (TrackerMiner *miner,
+		  const gchar  *name)
+{
+	TrackerDBusData *data;
+	DBusGConnection *connection;
+	DBusGProxy *gproxy;
+	GError *error = NULL;
+	gchar *full_name, *full_path;
+
+	connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+	if (!connection) {
+		g_critical ("Could not connect to the DBus 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);
+
+	/* Register the service name for the miner */
+	full_name = g_strconcat ("org.freedesktop.Tracker.Miner.", name, NULL);
+
+	if (!dbus_register_service (gproxy, full_name)) {
+		g_object_unref (gproxy);
+		g_free (full_name);
+		return NULL;
+	}
+
+	g_free (full_name);
+
+	full_path = g_strconcat ("/org/freedesktop/Tracker/Miner/", name, NULL);
+
+	if (!dbus_register_object (G_OBJECT (miner),
+				   connection, gproxy,
+				   &dbus_glib_tracker_miner_object_info,
+				   full_path)) {
+		g_object_unref (gproxy);
+		g_free (full_path);
+		return NULL;
+	}
+
+	g_free (full_path);
+
+	/* Now we're successfully connected and registered, create the data */
+	data = g_slice_new0 (TrackerDBusData);
+	data->connection = dbus_g_connection_ref (connection);
+	data->gproxy = g_object_ref (gproxy);
+
+#if 0
+	data->name_monitors = g_hash_table_new_full (g_str_hash,
+						     g_str_equal,
+						     (GDestroyNotify) g_free,
+						     (GDestroyNotify) name_monitor_free);
+#endif
+	return data;
+}
+
+gboolean
+tracker_dbus_init (TrackerMiner *miner)
+{
+	TrackerDBusData *data;
+
+	g_return_val_if_fail (TRACKER_IS_MINER (miner), FALSE);
+
+	if (G_UNLIKELY (dbus_data == 0)) {
+		dbus_data = g_quark_from_static_string ("tracker-miner-dbus-data");
+	}
+
+	data = g_object_get_qdata (G_OBJECT (miner), dbus_data);
+
+	if (G_LIKELY (!data)) {
+		const gchar *name;
+
+		name = tracker_miner_get_name (miner);
+		data = dbus_data_create (miner, name);
+	}
+
+	if (G_UNLIKELY (!data)) {
+		return FALSE;
+	}
+
+	g_object_set_qdata_full (G_OBJECT (miner), dbus_data, data,
+				 (GDestroyNotify) dbus_data_destroy);
+
+	return TRUE;
+}
+
+void
+tracker_dbus_shutdown (TrackerMiner *miner)
+{
+	if (dbus_data == 0) {
+		return;
+	}
+
+	g_object_set_qdata (G_OBJECT (miner), dbus_data, NULL);
+}
+
+#if 0
+gboolean
+tracker_dbus_register_object (GObject               *object,
+			      const DBusGObjectInfo *info,
+			      const gchar	    *path)
+{
+	if (!connection || !gproxy) {
+		g_critical ("DBus support must be initialized before registering objects!");
+		return FALSE;
+	}
+
+	return dbus_register_object (object,
+				     connection,
+				     gproxy,
+				     info,
+				     path);
+}
+
+void
+tracker_dbus_add_name_monitor (const gchar                *name,
+			       TrackerDBusNameMonitorFunc  func,
+			       gpointer                    user_data,
+			       GDestroyNotify              destroy_func)
+{
+	g_return_if_fail (name != NULL);
+	g_return_if_fail (func != NULL);
+
+	if (!name_monitors) {
+		g_critical ("DBus support must be initialized before adding name monitors!");
+		return;
+	}
+
+	if (g_hash_table_lookup (name_monitors, name) != NULL) {
+		g_critical ("There is already a name monitor for such name");
+		return;
+	}
+
+	g_hash_table_insert (name_monitors,
+			     g_strdup (name),
+			     name_monitor_new (func, user_data, destroy_func));
+}
+
+void
+tracker_dbus_remove_name_monitor (const gchar *name)
+{
+	g_return_if_fail (name != NULL);
+
+	if (!name_monitors) {
+		g_critical ("DBus support must be initialized before removing name monitors!");
+		return;
+	}
+
+	g_hash_table_remove (name_monitors, name);
+}
+#endif
diff --git a/src/libtracker-miner/tracker-dbus.h b/src/libtracker-miner/tracker-dbus.h
new file mode 100644
index 0000000..b1508d5
--- /dev/null
+++ b/src/libtracker-miner/tracker-dbus.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, 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_DBUS_H__
+#define __TRACKER_DBUS_H__
+
+#include <glib.h>
+#include <dbus/dbus-glib-bindings.h>
+#include "tracker-miner.h"
+
+G_BEGIN_DECLS
+
+#if 0
+typedef void (* TrackerDBusNameMonitorFunc) (const gchar *name,
+					     gboolean     available,
+					     gpointer     user_data);
+#endif
+
+gboolean    tracker_dbus_init		   (TrackerMiner *miner);
+void	    tracker_dbus_shutdown	   (TrackerMiner *miner);
+
+#if 0
+gboolean    tracker_dbus_register_object   (GObject               *object,
+					    const DBusGObjectInfo *info,
+					    const gchar	          *path);
+
+void        tracker_dbus_add_name_monitor     (const gchar                *name,
+					       TrackerDBusNameMonitorFunc  func,
+					       gpointer                    user_data,
+					       GDestroyNotify              destroy_func);
+void        tracker_dbus_remove_name_monitor  (const gchar                *name);
+#endif
+
+G_END_DECLS
+
+#endif /* __TRACKER_DBUS_H__ */
diff --git a/src/libtracker-miner/tracker-main.c b/src/libtracker-miner/tracker-main.c
new file mode 100644
index 0000000..f60ad92
--- /dev/null
+++ b/src/libtracker-miner/tracker-main.c
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009, 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 <stdlib.h>
+#include "tracker-miner-test.h"
+
+static void
+on_miner_terminated (TrackerMiner *miner,
+		     gpointer      user_data)
+{
+        GMainLoop *main_loop = user_data;
+
+        g_main_loop_quit (main_loop);
+}
+
+static gboolean
+on_miner_start (TrackerMiner *miner)
+{
+	g_message ("Starting miner");
+	tracker_miner_start (miner);
+
+	return FALSE;
+}
+
+int
+main (int argc, char *argv[])
+{
+        TrackerMiner *miner;
+        GMainLoop *main_loop;
+
+        g_type_init ();
+
+        main_loop = g_main_loop_new (NULL, FALSE);
+
+        miner = tracker_miner_test_new ("test");
+        g_signal_connect (miner, "terminated",
+                          G_CALLBACK (on_miner_terminated), main_loop);
+
+	g_timeout_add_seconds (1, (GSourceFunc) on_miner_start, miner);
+
+        g_main_loop_run (main_loop);
+
+        return EXIT_SUCCESS;
+}
diff --git a/src/libtracker-miner/tracker-miner-dbus.h b/src/libtracker-miner/tracker-miner-dbus.h
new file mode 100644
index 0000000..b2967f0
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-dbus.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, 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_MINER_DBUS_H__
+#define __TRACKER_MINER_DBUS_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+void tracker_miner_pause  (TrackerMiner           *miner,
+                           DBusGMethodInvocation  *context,
+                           GError                **error);
+void tracker_miner_resume (TrackerMiner           *miner,
+                           DBusGMethodInvocation  *context,
+                           GError                **error);
+
+G_END_DECLS
+
+#endif /* __TRACKER_MINER_DBUS_H__ */
diff --git a/src/libtracker-miner/tracker-miner-test.c b/src/libtracker-miner/tracker-miner-test.c
new file mode 100644
index 0000000..da9518d
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-test.c
@@ -0,0 +1,43 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2009, 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-miner-test.h"
+
+G_DEFINE_TYPE (TrackerMinerTest, tracker_miner_test, TRACKER_TYPE_MINER)
+
+static void
+tracker_miner_test_class_init (TrackerMinerTestClass *klass)
+{
+
+}
+
+static void
+tracker_miner_test_init (TrackerMinerTest *miner)
+{
+
+}
+
+TrackerMiner *
+tracker_miner_test_new (const gchar *name)
+{
+        return g_object_new (TRACKER_TYPE_MINER_TEST,
+			     "name", name,
+			     NULL);
+}
diff --git a/src/libtracker-miner/tracker-miner-test.h b/src/libtracker-miner/tracker-miner-test.h
new file mode 100644
index 0000000..a36676c
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner-test.h
@@ -0,0 +1,52 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, 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_MINER_TEST_H__
+#define __TRACKER_MINER_TEST_H__
+
+#include <libtracker-miner/tracker-miner-crawler.h>
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_MINER_TEST         (tracker_miner_test_get_type())
+#define TRACKER_MINER_TEST(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_MINER_TEST, TrackerMinerTest))
+#define TRACKER_MINER_TEST_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c),    TRACKER_TYPE_MINER_TEST, TrackerMinerTestClass))
+#define TRACKER_IS_MINER_TEST(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_MINER_TEST))
+#define TRACKER_IS_MINER_TEST_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c),    TRACKER_TYPE_MINER_TEST))
+#define TRACKER_MINER_TEST_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o),  TRACKER_TYPE_MINER_TEST, TrackerMinerTestClass))
+
+typedef struct TrackerMinerTest TrackerMinerTest;
+typedef struct TrackerMinerTestClass TrackerMinerTestClass;
+
+struct TrackerMinerTest {
+        TrackerMiner parent_instance;
+};
+
+struct TrackerMinerTestClass {
+        TrackerMinerClass parent_class;
+};
+
+GType          tracker_miner_test_get_type (void) G_GNUC_CONST;
+TrackerMiner * tracker_miner_test_new (const gchar *name);
+
+G_END_DECLS
+
+#endif /* __TRACKER_MINER_TEST_H__ */
diff --git a/src/libtracker-miner/tracker-miner.c b/src/libtracker-miner/tracker-miner.c
new file mode 100644
index 0000000..e97b1e4
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner.c
@@ -0,0 +1,250 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, 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 "tracker-miner.h"
+#include "tracker-dbus.h"
+#include "tracker-miner-dbus.h"
+#include <libtracker/tracker.h>
+
+#define TRACKER_MINER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER, TrackerMinerPrivate))
+
+typedef struct TrackerMinerPrivate TrackerMinerPrivate;
+
+struct TrackerMinerPrivate {
+	gchar *name;
+	TrackerClient *client;
+};
+
+enum {
+	PROP_0,
+	PROP_NAME
+};
+
+enum {
+	STARTED,
+	STOPPED,
+	PAUSED,
+	RESUMED,
+	TERMINATED,
+	LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+static void tracker_miner_finalize     (GObject             *object);
+
+static void tracker_miner_get_property (GObject             *object,
+					guint                param_id,
+					GValue              *value,
+					GParamSpec          *pspec);
+static void tracker_miner_set_property (GObject             *object,
+					guint                param_id,
+					const GValue        *value,
+					GParamSpec          *pspec);
+static void tracker_miner_constructed  (GObject             *object);
+
+G_DEFINE_ABSTRACT_TYPE (TrackerMiner, tracker_miner, G_TYPE_OBJECT)
+
+static void
+tracker_miner_class_init (TrackerMinerClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	object_class->finalize = tracker_miner_finalize;
+	object_class->set_property = tracker_miner_set_property;
+	object_class->get_property = tracker_miner_get_property;
+	object_class->constructed = tracker_miner_constructed;
+
+	signals[STARTED] =
+		g_signal_new ("started",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (TrackerMinerClass, started),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE, 0);
+	signals[STOPPED] =
+		g_signal_new ("stopped",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (TrackerMinerClass, stopped),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE, 0);
+	signals[PAUSED] =
+		g_signal_new ("paused",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (TrackerMinerClass, paused),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE, 0);
+	signals[RESUMED] =
+		g_signal_new ("resumed",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (TrackerMinerClass, resumed),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE, 0);
+	signals[TERMINATED] =
+		g_signal_new ("terminated",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (TrackerMinerClass, terminated),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE, 0);
+
+	g_object_class_install_property (object_class,
+					 PROP_NAME,
+					 g_param_spec_string ("name",
+							      "Miner name",
+							      "Miner name",
+							      NULL,
+							      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+	g_type_class_add_private (object_class, sizeof (TrackerMinerPrivate));
+}
+
+static void
+tracker_miner_init (TrackerMiner *miner)
+{
+	TrackerMinerPrivate *priv;
+
+	miner->_priv = priv = TRACKER_MINER_GET_PRIVATE (miner);
+
+	priv->client = tracker_connect (TRUE, -1);
+}
+
+static void
+tracker_miner_finalize (GObject *object)
+{
+	TrackerMiner *miner = TRACKER_MINER (object);
+	TrackerMinerPrivate *priv = miner->_priv;
+
+	if (priv->client) {
+		tracker_disconnect (priv->client);
+	}
+
+	G_OBJECT_CLASS (tracker_miner_parent_class)->finalize (object);
+}
+
+static void
+tracker_miner_get_property (GObject    *object,
+			    guint       prop_id,
+			    GValue     *value,
+			    GParamSpec *pspec)
+{
+	TrackerMiner *miner = TRACKER_MINER (object);
+	TrackerMinerPrivate *priv = miner->_priv;
+
+	switch (prop_id) {
+	case PROP_NAME:
+		g_value_set_string (value, priv->name);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+tracker_miner_set_property (GObject      *object,
+			    guint         prop_id,
+			    const GValue *value,
+			    GParamSpec   *pspec)
+{
+	TrackerMiner *miner = TRACKER_MINER (object);
+	TrackerMinerPrivate *priv = miner->_priv;
+
+	switch (prop_id) {
+	case PROP_NAME:
+		if (priv->name) {
+			g_free (priv->name);
+		}
+
+		priv->name = g_value_dup_string (value);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static gboolean
+terminate_miner_cb (TrackerMiner *miner)
+{
+	g_signal_emit (miner, signals[TERMINATED], 0);
+	return TRUE;
+}
+
+static void
+tracker_miner_constructed (GObject *object)
+{
+	TrackerMiner *miner = TRACKER_MINER (object);
+	TrackerMinerPrivate *priv = miner->_priv;
+
+	if (!priv->name) {
+		g_critical ("Miner should have been given a name, bailing out");
+		g_assert_not_reached ();
+	}
+
+	if (!tracker_dbus_init (miner)) {
+		g_critical ("Could not register object to DBus");
+		g_idle_add ((GSourceFunc) terminate_miner_cb, miner);
+	}
+}
+
+G_CONST_RETURN gchar *
+tracker_miner_get_name (TrackerMiner *miner)
+{
+	TrackerMinerPrivate *priv;
+
+	g_return_val_if_fail (TRACKER_IS_MINER (miner), NULL);
+
+	priv = miner->_priv;
+	return priv->name;
+}
+
+void
+tracker_miner_start (TrackerMiner *miner)
+{
+	g_return_if_fail (TRACKER_IS_MINER (miner));
+
+	g_signal_emit (miner, signals[STARTED], 0);
+}
+
+/* DBus methods */
+void
+tracker_miner_pause (TrackerMiner           *miner,
+		     DBusGMethodInvocation  *context,
+		     GError                **error)
+{
+}
+
+void
+tracker_miner_resume (TrackerMiner           *miner,
+		      DBusGMethodInvocation  *context,
+		      GError                **error)
+{
+}
diff --git a/src/libtracker-miner/tracker-miner.h b/src/libtracker-miner/tracker-miner.h
new file mode 100644
index 0000000..b87488b
--- /dev/null
+++ b/src/libtracker-miner/tracker-miner.h
@@ -0,0 +1,67 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, 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_MINER_H__
+#define __TRACKER_MINER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_MINER	   (tracker_miner_get_type())
+#define TRACKER_MINER(o)	   (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_MINER, TrackerMiner))
+#define TRACKER_MINER_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c),    TRACKER_TYPE_MINER, TrackerMinerClass))
+#define TRACKER_IS_MINER(o)	   (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_MINER))
+#define TRACKER_IS_MINER_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c),    TRACKER_TYPE_MINER))
+#define TRACKER_MINER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o),  TRACKER_TYPE_MINER, TrackerMinerClass))
+
+typedef struct TrackerMiner TrackerMiner;
+typedef struct TrackerMinerClass TrackerMinerClass;
+
+struct TrackerMiner {
+        GObject parent_instance;
+        gpointer _priv;
+};
+
+struct TrackerMinerClass {
+        GObjectClass parent_class;
+
+        /* signals */
+        void (* started) (TrackerMiner *miner);
+        void (* stopped) (TrackerMiner *miner);
+
+        void (* paused)  (TrackerMiner *miner);
+        void (* resumed) (TrackerMiner *miner);
+
+	void (* terminated) (TrackerMiner *miner);
+};
+
+
+GType    tracker_miner_get_type    (void) G_GNUC_CONST;
+
+G_CONST_RETURN gchar * tracker_miner_get_name (TrackerMiner *miner);
+
+void                   tracker_miner_start    (TrackerMiner *miner);
+
+
+G_END_DECLS
+
+#endif /* __TRACKER_MINER_H__ */



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