[tracker/libtracker-miner] Add initial version of tracker-miner-fs using libtracker-miner.
- From: Carlos Garnacho <carlosg src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker/libtracker-miner] Add initial version of tracker-miner-fs using libtracker-miner.
- Date: Wed, 19 Aug 2009 08:38:45 +0000 (UTC)
commit 6bb9bbdd607b5ab144da24b6a3a7c58c4db7d9c4
Author: Carlos Garnacho <carlos lanedo com>
Date: Tue Aug 18 18:12:43 2009 +0200
Add initial version of tracker-miner-fs using libtracker-miner.
The binary is compiled ATM in src/tracker-miner-fs/tracker-miner-fs-new,
and just contains the applications miner, more code will be moved over
later.
src/tracker-miner-fs/Makefile.am | 32 ++-
src/tracker-miner-fs/tracker-miner-applications.c | 375 +++++++++++++++++++++
src/tracker-miner-fs/tracker-miner-applications.h | 52 +++
src/tracker-miner-fs/tracker-miner-main.c | 354 +++++++++++++++++++
4 files changed, 812 insertions(+), 1 deletions(-)
---
diff --git a/src/tracker-miner-fs/Makefile.am b/src/tracker-miner-fs/Makefile.am
index 7113d1c..9cf9d5b 100644
--- a/src/tracker-miner-fs/Makefile.am
+++ b/src/tracker-miner-fs/Makefile.am
@@ -38,7 +38,7 @@ libtracker_moduleinclude_HEADERS = \
libtracker_module_la_LIBADD = $(GCOV_LIBS)
-libexec_PROGRAMS = tracker-miner-fs
+libexec_PROGRAMS = tracker-miner-fs tracker-miner-fs-new
tracker_miner_fs_SOURCES = \
tracker-albumart.c \
@@ -83,6 +83,36 @@ tracker_miner_fs_LDADD = \
-lz \
-lm
+tracker_miner_fs_new_SOURCES = \
+ tracker-config.c \
+ tracker-config.h \
+ tracker-miner-applications.c \
+ tracker-miner-applications.h \
+ tracker-miner-main.c
+
+tracker_miner_fs_new_LDADD = \
+ $(plugin_libs) \
+ libtracker-module.la \
+ $(top_builddir)/src/libtracker-data/libtracker-data.la \
+ $(top_builddir)/src/libtracker-db/libtracker-db.la \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(top_builddir)/src/libtracker/libtrackerclient- TRACKER_API_VERSION@.la \
+ $(top_builddir)/src/libstemmer/libstemmer.la \
+ $(top_builddir)/src/libinotify/libinotify.la \
+ $(top_builddir)/src/libtracker-miner/libtracker-miner.la \
+ $(tracker_store_win_libs) \
+ $(DBUS_LIBS) \
+ $(GDKPIXBUF_LIBS) \
+ $(GMODULE_LIBS) \
+ $(GTHREAD_LIBS) \
+ $(PANGO_LIBS) \
+ $(GIO_LIBS) \
+ $(GCOV_LIBS) \
+ $(GLIB2_LIBS) \
+ $(RAPTOR_LIBS) \
+ -lz \
+ -lm
+
tracker-marshal.h: tracker-marshal.list
$(GLIB_GENMARSHAL) $< --prefix=tracker_marshal --header > $@
diff --git a/src/tracker-miner-fs/tracker-miner-applications.c b/src/tracker-miner-fs/tracker-miner-applications.c
new file mode 100644
index 0000000..f83e4d2
--- /dev/null
+++ b/src/tracker-miner-fs/tracker-miner-applications.c
@@ -0,0 +1,375 @@
+/* -*- 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 <libtracker-common/tracker-utils.h>
+#include <libtracker-common/tracker-ontology.h>
+#include "tracker-miner-applications.h"
+
+#define TRACKER_MINER_APPLICATIONS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER_APPLICATIONS, TrackerMinerApplicationsPrivate))
+
+typedef struct _TrackerMinerApplicationsPrivate TrackerMinerApplicationsPrivate;
+
+struct _TrackerMinerApplicationsPrivate {
+ gboolean foo;
+};
+
+#define RDF_TYPE TRACKER_RDF_PREFIX "type"
+#define NFO_PREFIX TRACKER_NFO_PREFIX
+#define NIE_PREFIX TRACKER_NIE_PREFIX
+#define MAEMO_PREFIX TRACKER_MAEMO_PREFIX
+
+#define GROUP_DESKTOP_ENTRY "Desktop Entry"
+
+#define APPLICATION_DATASOURCE_URN "urn:nepomuk:datasource:84f20000-1241-11de-8c30-0800200c9a66"
+#define APPLET_DATASOURCE_URN "urn:nepomuk:datasource:192bd060-1f9a-11de-8c30-0800200c9a66"
+#define SOFTWARE_CATEGORY_URN_PREFIX "urn:software-category:"
+#define THEME_ICON_URN_PREFIX "urn:theme-icon:"
+
+static void tracker_miner_applications_finalize (GObject *object);
+
+static gboolean tracker_miner_applications_check_file (TrackerMinerProcess *miner,
+ GFile *file);
+static gboolean tracker_miner_applications_check_directory (TrackerMinerProcess *miner,
+ GFile *file);
+static gboolean tracker_miner_applications_process_file (TrackerMinerProcess *miner,
+ GFile *file,
+ TrackerSparqlBuilder *sparql);
+static gboolean tracker_miner_applications_monitor_directory (TrackerMinerProcess *miner,
+ GFile *file);
+
+G_DEFINE_TYPE (TrackerMinerApplications, tracker_miner_applications, TRACKER_TYPE_MINER_PROCESS)
+
+
+static void
+tracker_miner_applications_class_init (TrackerMinerApplicationsClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ TrackerMinerProcessClass *miner_process_class = TRACKER_MINER_PROCESS_CLASS (klass);
+
+ object_class->finalize = tracker_miner_applications_finalize;
+
+ miner_process_class->check_file = tracker_miner_applications_check_file;
+ miner_process_class->check_directory = tracker_miner_applications_check_directory;
+ miner_process_class->monitor_directory = tracker_miner_applications_monitor_directory;
+ miner_process_class->process_file = tracker_miner_applications_process_file;
+
+ g_type_class_add_private (object_class, sizeof (TrackerMinerApplicationsPrivate));
+}
+
+static void
+tracker_miner_applications_init (TrackerMinerApplications *miner)
+{
+}
+
+static void
+tracker_miner_applications_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (tracker_miner_applications_parent_class)->finalize (object);
+}
+
+static void
+insert_data_from_desktop_file (TrackerSparqlBuilder *sparql,
+ const gchar *subject,
+ const gchar *metadata_key,
+ GKeyFile *desktop_file,
+ const gchar *key,
+ gboolean use_locale)
+{
+ gchar *str;
+
+ if (use_locale) {
+ str = g_key_file_get_locale_string (desktop_file, GROUP_DESKTOP_ENTRY, key, NULL, NULL);
+ } else {
+ str = g_key_file_get_string (desktop_file, GROUP_DESKTOP_ENTRY, key, NULL);
+ }
+
+ if (str) {
+ tracker_sparql_builder_subject_iri (sparql, subject);
+ tracker_sparql_builder_predicate_iri (sparql, metadata_key);
+ tracker_sparql_builder_object_string (sparql, str);
+ g_free (str);
+ }
+}
+
+static gboolean
+tracker_miner_applications_check_file (TrackerMinerProcess *miner,
+ GFile *file)
+{
+ gboolean retval = FALSE;
+ gchar *basename;
+
+ basename = g_file_get_basename (file);
+
+ /* Check we're dealing with a desktop file */
+ if (g_str_has_suffix (basename, ".desktop") ||
+ g_str_has_suffix (basename, ".directory")) {
+ retval = TRUE;
+ }
+
+ g_free (basename);
+
+ return retval;
+}
+
+static gboolean
+tracker_miner_applications_check_directory (TrackerMinerProcess *miner,
+ GFile *file)
+{
+ /* We want to inspect all the passed dirs and their children */
+ return TRUE;
+}
+
+static gboolean
+tracker_miner_applications_monitor_directory (TrackerMinerProcess *miner,
+ GFile *file)
+{
+ /* We want to monitor all the passed dirs and their children */
+ return TRUE;
+}
+
+static gboolean
+tracker_miner_applications_process_file (TrackerMinerProcess *miner,
+ GFile *file,
+ TrackerSparqlBuilder *sparql)
+{
+ GKeyFile *key_file;
+ gchar *path, *type, *filename, *name = NULL, *uri = NULL;
+ GFileInfo *file_info;
+ GStrv cats = NULL;
+ gsize cats_len;
+
+ path = g_file_get_path (file);
+ key_file = g_key_file_new ();
+
+ if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, NULL)) {
+ g_debug ("Couldn't load desktop file:'%s'", path);
+ g_key_file_free (key_file);
+ g_free (path);
+ return FALSE;
+ }
+
+ if (g_key_file_get_boolean (key_file, GROUP_DESKTOP_ENTRY, "Hidden", NULL)) {
+ g_debug ("Desktop file is 'hidden', not gathering metadata for it");
+ g_key_file_free (key_file);
+ g_free (path);
+ return FALSE;
+ }
+
+ type = g_key_file_get_string (key_file, GROUP_DESKTOP_ENTRY, "Type", NULL);
+
+ if (!type) {
+ g_key_file_free (key_file);
+ g_free (type);
+ g_free (path);
+ return FALSE;
+ }
+
+ cats = g_key_file_get_locale_string_list (key_file, GROUP_DESKTOP_ENTRY, "Categories", NULL, &cats_len, NULL);
+
+ if (!cats)
+ cats = g_key_file_get_string_list (key_file, GROUP_DESKTOP_ENTRY, "Categories", &cats_len, NULL);
+
+ name = g_key_file_get_locale_string (key_file, GROUP_DESKTOP_ENTRY, "Name", NULL, NULL);
+
+ if (!name)
+ g_key_file_get_string (key_file, GROUP_DESKTOP_ENTRY, "Name", NULL);
+
+ if (name && g_ascii_strcasecmp (type, "Directory") == 0) {
+ gchar *canonical_uri = tracker_uri_printf_escaped (SOFTWARE_CATEGORY_URN_PREFIX "%s", name);
+ gchar *icon = g_key_file_get_string (key_file, GROUP_DESKTOP_ENTRY, "Icon", NULL);
+
+ tracker_sparql_builder_insert_open (sparql);
+
+ if (icon) {
+ gchar *icon_uri = g_strdup_printf (THEME_ICON_URN_PREFIX "%s", icon);
+
+ tracker_sparql_builder_subject_iri (sparql, icon_uri);
+ tracker_sparql_builder_predicate (sparql, "a");
+ tracker_sparql_builder_object (sparql, "nfo:Image");
+
+ tracker_sparql_builder_subject_iri (sparql, canonical_uri);
+ tracker_sparql_builder_predicate (sparql, "nfo:softwareCategoryIcon");
+ tracker_sparql_builder_object_iri (sparql, icon_uri);
+
+ g_free (icon_uri);
+ g_free (icon);
+ }
+
+ uri = canonical_uri;
+
+ tracker_sparql_builder_subject_iri (sparql, uri);
+
+ tracker_sparql_builder_predicate (sparql, "a");
+ tracker_sparql_builder_object (sparql, "nfo:SoftwareCategory");
+
+ tracker_sparql_builder_predicate (sparql, "nie:title");
+ tracker_sparql_builder_object_string (sparql, name);
+
+ } else if (name && g_ascii_strcasecmp (type, "Application") == 0) {
+
+ uri = g_file_get_uri (file);
+ tracker_sparql_builder_insert_open (sparql);
+
+ tracker_sparql_builder_subject_iri (sparql, APPLICATION_DATASOURCE_URN);
+ tracker_sparql_builder_predicate (sparql, "a");
+ tracker_sparql_builder_object (sparql, "nie:DataSource");
+
+ tracker_sparql_builder_subject_iri (sparql, uri);
+
+ tracker_sparql_builder_predicate (sparql, "a");
+ tracker_sparql_builder_object (sparql, "nfo:SoftwareApplication");
+
+ tracker_sparql_builder_predicate (sparql, "nie:dataSource");
+ tracker_sparql_builder_object_iri (sparql, APPLICATION_DATASOURCE_URN);
+
+ /* This matches SomeApplet as Type= */
+ } else if (name && g_str_has_suffix (type, "Applet")) {
+
+ /* The URI of the InformationElement should be a UUID URN */
+ uri = g_file_get_uri (file);
+ tracker_sparql_builder_insert_open (sparql);
+
+ tracker_sparql_builder_subject_iri (sparql, APPLET_DATASOURCE_URN);
+ tracker_sparql_builder_predicate (sparql, "a");
+ tracker_sparql_builder_object (sparql, "nie:DataSource");
+
+ /* TODO This is atm specific for Maemo */
+ tracker_sparql_builder_subject_iri (sparql, uri);
+
+ tracker_sparql_builder_predicate (sparql, "a");
+ tracker_sparql_builder_object (sparql, "nfo:SoftwareApplet");
+
+ tracker_sparql_builder_predicate (sparql, "nie:dataSource");
+ tracker_sparql_builder_object_iri (sparql, APPLET_DATASOURCE_URN);
+ }
+
+ if (sparql && uri) {
+ gchar *icon;
+ gchar *desktop_file_uri;
+
+ tracker_sparql_builder_predicate (sparql, "a");
+ tracker_sparql_builder_object (sparql, "nfo:Executable");
+ tracker_sparql_builder_object (sparql, "nfo:FileDataObject");
+
+ tracker_sparql_builder_predicate (sparql, "nie:title");
+ tracker_sparql_builder_object_string (sparql, name);
+
+ insert_data_from_desktop_file (sparql, uri, NIE_PREFIX "comment", key_file, "Comment", TRUE);
+ insert_data_from_desktop_file (sparql, uri, NFO_PREFIX "softwareCmdLine", key_file, "Exec", TRUE);
+
+ icon = g_key_file_get_string (key_file, GROUP_DESKTOP_ENTRY, "Icon", NULL);
+
+ if (icon) {
+ gchar *icon_uri = g_strdup_printf (THEME_ICON_URN_PREFIX "%s", icon);
+
+ tracker_sparql_builder_subject_iri (sparql, icon_uri);
+ tracker_sparql_builder_predicate (sparql, "a");
+ tracker_sparql_builder_object (sparql, "nfo:Image");
+
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ tracker_sparql_builder_predicate (sparql, "nfo:softwareIcon");
+ tracker_sparql_builder_object_iri (sparql, icon_uri);
+
+ g_free (icon_uri);
+ g_free (icon);
+ }
+
+ if (cats) {
+ gsize i;
+
+ for (i = 0 ; cats[i] && i < cats_len ; i++) {
+ gchar *cat_uri = tracker_uri_printf_escaped (SOFTWARE_CATEGORY_URN_PREFIX "%s", cats[i]);
+
+ /* There are also .desktop
+ * files that describe these categories, but we can handle
+ * preemptively creating them if we visit a app .desktop
+ * file that mentions one that we don't yet know about */
+
+ tracker_sparql_builder_subject_iri (sparql, cat_uri);
+ tracker_sparql_builder_predicate (sparql, "a");
+ tracker_sparql_builder_object (sparql, "nfo:SoftwareCategory");
+
+ tracker_sparql_builder_predicate (sparql, "nie:title");
+ tracker_sparql_builder_object_string (sparql, cats[i]);
+
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ tracker_sparql_builder_predicate (sparql, "nfo:belongsToContainer");
+ tracker_sparql_builder_object_iri (sparql, cat_uri);
+
+ g_free (cat_uri);
+ }
+ }
+
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ tracker_sparql_builder_predicate (sparql, "nie:dataSource");
+ tracker_sparql_builder_object_iri (sparql, APPLICATION_DATASOURCE_URN);
+
+ filename = g_filename_display_basename (path);
+ tracker_sparql_builder_predicate (sparql, "nfo:fileName");
+ tracker_sparql_builder_object_string (sparql, filename);
+ g_free (filename);
+
+ desktop_file_uri = g_file_get_uri (file);
+ tracker_sparql_builder_subject_iri (sparql, desktop_file_uri);
+ tracker_sparql_builder_predicate (sparql, "a");
+ tracker_sparql_builder_object (sparql, "nfo:FileDataObject");
+
+ tracker_sparql_builder_subject_iri (sparql, uri);
+ tracker_sparql_builder_predicate (sparql, "nie:isStoredAs");
+ tracker_sparql_builder_object_iri (sparql, desktop_file_uri);
+ g_free (desktop_file_uri);
+
+ }
+
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_TIME_MODIFIED,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, NULL);
+
+ if (file_info) {
+ guint64 time;
+
+ time = g_file_info_get_attribute_uint64 (file_info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ tracker_sparql_builder_predicate (sparql, "nfo:fileLastModified");
+ tracker_sparql_builder_object_date (sparql, &time);
+
+ g_object_unref (file_info);
+ }
+
+
+ if (cats)
+ g_strfreev (cats);
+
+ g_free (uri);
+ g_key_file_free (key_file);
+ g_free (type);
+ g_free (path);
+ g_free (name);
+
+ return TRUE;
+}
+
+TrackerMiner *
+tracker_miner_applications_new (void)
+{
+ return g_object_new (TRACKER_TYPE_MINER_APPLICATIONS,
+ "name", "Applications",
+ NULL);
+}
diff --git a/src/tracker-miner-fs/tracker-miner-applications.h b/src/tracker-miner-fs/tracker-miner-applications.h
new file mode 100644
index 0000000..8c674ab
--- /dev/null
+++ b/src/tracker-miner-fs/tracker-miner-applications.h
@@ -0,0 +1,52 @@
+/* -*- 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_MINER_APPLICATIONS_H__
+#define __TRACKER_MINER_APPLICATIONS_H__
+
+#include <libtracker-miner/tracker-miner-process.h>
+
+G_BEGIN_DECLS
+
+#define TRACKER_TYPE_MINER_APPLICATIONS (tracker_miner_applications_get_type())
+#define TRACKER_MINER_APPLICATIONS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_MINER_APPLICATIONS, TrackerMinerApplications))
+#define TRACKER_MINER_APPLICATIONS_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_MINER_APPLICATIONS, TrackerMinerApplicationsClass))
+#define TRACKER_IS_APPLICATIONS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_MINER_APPLICATIONS))
+#define TRACKER_IS_APPLICATIONS_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TRACKER_TYPE_MINER_APPLICATIONS))
+#define TRACKER_MINER_APPLICATIONS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_MINER_APPLICATIONS, TrackerMinerApplicationsClass))
+
+typedef struct _TrackerMinerApplications TrackerMinerApplications;
+typedef struct _TrackerMinerApplicationsClass TrackerMinerApplicationsClass;
+
+struct _TrackerMinerApplications {
+ TrackerMinerProcess parent_instance;
+};
+
+struct _TrackerMinerApplicationsClass {
+ TrackerMinerProcessClass parent_class;
+};
+
+GType tracker_miner_applications_get_type (void) G_GNUC_CONST;
+
+TrackerMiner * tracker_miner_applications_new (void);
+
+G_END_DECLS
+
+#endif /* __TRACKER_MINER_APPLICATIONS_H__ */
diff --git a/src/tracker-miner-fs/tracker-miner-main.c b/src/tracker-miner-fs/tracker-miner-main.c
new file mode 100644
index 0000000..2285183
--- /dev/null
+++ b/src/tracker-miner-fs/tracker-miner-main.c
@@ -0,0 +1,354 @@
+/* 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 "config.h"
+
+#include <string.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <signal.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+#if defined(__linux__)
+#include <linux/sched.h>
+#endif
+#include <sched.h>
+
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+
+#include <libtracker-common/tracker-ioprio.h>
+#include <libtracker-common/tracker-log.h>
+#include <libtracker-common/tracker-ontology.h>
+#include <libtracker-common/tracker-file-utils.h>
+#include <libtracker-common/tracker-thumbnailer.h>
+#include <libtracker-common/tracker-storage.h>
+
+#include <libtracker-db/tracker-db-manager.h>
+#include <libtracker-db/tracker-db-dbus.h>
+
+#include <libtracker-data/tracker-turtle.h>
+
+#include "tracker-albumart.h"
+#include "tracker-dbus.h"
+#include "tracker-config.h"
+#include "tracker-indexer.h"
+#include "tracker-marshal.h"
+#include "tracker-miner-applications.h"
+
+#define ABOUT \
+ "Tracker " PACKAGE_VERSION "\n"
+
+#define LICENSE \
+ "This program is free software and comes without any warranty.\n" \
+ "It is licensed under version 2 or later of the General Public " \
+ "License which can be viewed at:\n" \
+ "\n" \
+ " http://www.gnu.org/licenses/gpl.txt\n"
+
+static GMainLoop *main_loop;
+
+static gboolean version;
+static gint verbosity = -1;
+static gint initial_sleep = -1;
+static gboolean process_all;
+static gchar **modules;
+
+static GOptionEntry entries[] = {
+ { "version", 'V', 0,
+ G_OPTION_ARG_NONE, &version,
+ N_("Displays version information"),
+ NULL },
+ { "verbosity", 'v', 0,
+ G_OPTION_ARG_INT, &verbosity,
+ N_("Logging, 0 = errors only, "
+ "1 = minimal, 2 = detailed and 3 = debug (default = config)"),
+ NULL },
+ { "initial-sleep", 's', 0,
+ G_OPTION_ARG_INT, &initial_sleep,
+ N_("Initial sleep time in seconds, "
+ "0->1000 (default = config)"),
+ NULL },
+ { "process-all", 'p', 0,
+ G_OPTION_ARG_NONE, &process_all,
+ N_("Index data from all enabled modules"),
+ NULL },
+
+ { NULL }
+};
+
+static void
+sanity_check_option_values (TrackerConfig *config)
+{
+ g_message ("General options:");
+ g_message (" Verbosity ............................ %d",
+ tracker_config_get_verbosity (config));
+ g_message (" Initial Sleep ........................ %d",
+ tracker_config_get_initial_sleep (config));
+
+ g_message ("Indexer options:");
+ g_message (" Throttle level ....................... %d",
+ tracker_config_get_throttle (config));
+ g_message (" Thumbnail indexing enabled ........... %s",
+ tracker_config_get_enable_thumbnails (config) ? "yes" : "no");
+ g_message (" Disable indexing on battery .......... %s (initially = %s)",
+ tracker_config_get_disable_indexing_on_battery (config) ? "yes" : "no",
+ tracker_config_get_disable_indexing_on_battery_init (config) ? "yes" : "no");
+
+ if (tracker_config_get_low_disk_space_limit (config) == -1) {
+ g_message (" Low disk space limit ................. Disabled");
+ } else {
+ g_message (" Low disk space limit ................. %d%%",
+ tracker_config_get_low_disk_space_limit (config));
+ }
+}
+
+static void
+signal_handler (int signo)
+{
+ static gboolean in_loop = FALSE;
+
+ /* Die if we get re-entrant signals handler calls */
+ if (in_loop) {
+ _exit (EXIT_FAILURE);
+ }
+
+ switch (signo) {
+ case SIGTERM:
+ case SIGINT:
+ in_loop = TRUE;
+ g_main_loop_quit (main_loop);
+
+ default:
+ if (g_strsignal (signo)) {
+ g_print ("\n");
+ g_print ("Received signal:%d->'%s'\n",
+ signo,
+ g_strsignal (signo));
+ }
+ break;
+ }
+}
+
+static void
+initialize_signal_handler (void)
+{
+#ifndef G_OS_WIN32
+ struct sigaction act;
+ sigset_t empty_mask;
+
+ sigemptyset (&empty_mask);
+ act.sa_handler = signal_handler;
+ act.sa_mask = empty_mask;
+ act.sa_flags = 0;
+
+ sigaction (SIGTERM, &act, NULL);
+ sigaction (SIGINT, &act, NULL);
+ sigaction (SIGHUP, &act, NULL);
+#endif /* G_OS_WIN32 */
+}
+
+
+
+static void
+initialize_priority (void)
+{
+ /* Set disk IO priority and scheduling */
+ tracker_ioprio_init ();
+
+ /* Set process priority:
+ * The nice() function uses attribute "warn_unused_result" and
+ * so complains if we do not check its returned value. But it
+ * seems that since glibc 2.2.4, nice() can return -1 on a
+ * successful call so we have to check value of errno too.
+ * Stupid...
+ */
+ g_message ("Setting process priority");
+
+ if (nice (19) == -1) {
+ const gchar *str = g_strerror (errno);
+
+ g_message ("Couldn't set nice value to 19, %s",
+ str ? str : "no error given");
+ }
+}
+
+static void
+indexer_finished_cb (TrackerIndexer *indexer,
+ gdouble seconds_elapsed,
+ guint items_processed,
+ guint items_indexed,
+ gboolean interrupted,
+ gpointer user_data)
+{
+ g_message ("Finished indexing sent items");
+
+ if (interrupted) {
+ g_message ("Indexer was told to shutdown");
+ g_main_loop_quit (main_loop);
+ return;
+ }
+}
+
+static void
+daemon_availability_changed_cb (const gchar *name,
+ gboolean available,
+ gpointer user_data)
+{
+ if (!available) {
+ tracker_indexer_stop (TRACKER_INDEXER (user_data));
+ }
+}
+
+int
+main (gint argc, gchar *argv[])
+{
+ TrackerConfig *config;
+ TrackerMiner *miner_applications;
+ TrackerStorage *storage;
+ GOptionContext *context;
+ GError *error = NULL;
+ gchar *log_filename = NULL;
+
+ g_type_init ();
+
+ if (!g_thread_supported ()) {
+ g_thread_init (NULL);
+ }
+
+ setlocale (LC_ALL, "");
+
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ /* Set timezone info */
+ tzset ();
+
+ /* Translators: this messagge will apper immediately after the
+ * usage string - Usage: COMMAND <THIS_MESSAGE>
+ */
+ context = g_option_context_new (_("- start the tracker indexer"));
+
+ g_option_context_add_main_entries (context, entries, NULL);
+ g_option_context_parse (context, &argc, &argv, &error);
+ g_option_context_free (context);
+
+ if (version) {
+ g_print ("\n" ABOUT "\n" LICENSE "\n");
+ return EXIT_SUCCESS;
+ }
+
+ g_print ("Initializing tracker-miner-fs...\n");
+
+ initialize_signal_handler ();
+
+ /* Check XDG spec locations XDG_DATA_HOME _MUST_ be writable. */
+ if (!tracker_env_check_xdg_dirs ()) {
+ return EXIT_FAILURE;
+ }
+
+ /* This makes sure we don't steal all the system's resources */
+ initialize_priority ();
+
+ /* Initialize logging */
+ config = tracker_config_new ();
+
+ if (verbosity > -1) {
+ tracker_config_set_verbosity (config, verbosity);
+ }
+
+ if (initial_sleep > -1) {
+ tracker_config_set_initial_sleep (config, initial_sleep);
+ }
+
+ /* Make sure we initialize DBus, this shows we are started
+ * successfully when called upon from the daemon.
+ */
+#if 0
+ if (!tracker_dbus_init ()) {
+ return EXIT_FAILURE;
+ }
+#endif
+
+ tracker_log_init (tracker_config_get_verbosity (config),
+ &log_filename);
+ g_print ("Starting log:\n File:'%s'\n", log_filename);
+ g_free (log_filename);
+
+ sanity_check_option_values (config);
+
+ /* Set IO priority */
+ tracker_ioprio_init ();
+
+ /* nice() uses attribute "warn_unused_result" and so complains
+ * if we do not check its returned value. But it seems that
+ * since glibc 2.2.4, nice() can return -1 on a successful
+ * call so we have to check value of errno too. Stupid...
+ */
+ if (nice (19) == -1 && errno) {
+ const gchar *str;
+
+ str = g_strerror (errno);
+ g_message ("Couldn't set nice value to 19, %s",
+ str ? str : "no error given");
+ }
+
+#ifdef HAVE_HAL
+ storage = tracker_storage_new ();
+#else
+ storage = NULL;
+#endif
+
+ miner_applications = tracker_miner_applications_new ();
+
+ tracker_miner_process_add_directory (TRACKER_MINER_PROCESS (miner_applications),
+ "/usr/share/applications/",
+ FALSE);
+
+ /* Create the indexer and run the main loop */
+ g_signal_connect (miner_applications, "finished",
+ G_CALLBACK (indexer_finished_cb),
+ NULL);
+
+ tracker_miner_start (miner_applications);
+
+ g_message ("Starting...");
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (main_loop);
+
+ g_message ("Shutdown started");
+
+ g_main_loop_unref (main_loop);
+ g_object_unref (miner_applications);
+ g_object_unref (config);
+
+ if (storage) {
+ g_object_unref (storage);
+ }
+
+ tracker_log_shutdown ();
+
+ g_print ("\nOK\n\n");
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]