[tracker] Split TrackerHal into TrackerStorage and TrackerPower
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] Split TrackerHal into TrackerStorage and TrackerPower
- Date: Wed, 13 May 2009 08:28:24 -0400 (EDT)
commit 1e545925fd18405450924c2f03820a585d43e022
Author: Jürg Billeter <j bitron ch>
Date: Wed May 13 14:25:21 2009 +0200
Split TrackerHal into TrackerStorage and TrackerPower
Split TrackerHal into TrackerStorage and TrackerPower to better split
the functionalities for future work. This is needed for future patches
to add DeviceKit support. Based on patch by Richard Hughes.
---
.../libtracker-common-sections.txt | 51 ++-
src/libtracker-common/Makefile.am | 6 +-
src/libtracker-common/tracker-albumart.c | 8 +-
src/libtracker-common/tracker-albumart.h | 6 +-
src/libtracker-common/tracker-common.h | 3 +-
src/libtracker-common/tracker-hal.h | 82 ---
src/libtracker-common/tracker-power-hal.c | 577 +++++++++++++++++++
src/libtracker-common/tracker-power.h | 65 +++
.../{tracker-hal.c => tracker-storage-hal.c} | 601 +++++---------------
src/libtracker-common/tracker-storage.h | 78 +++
src/tracker-extract/tracker-main.c | 6 +-
src/tracker-extract/tracker-main.h | 4 +-
src/tracker-indexer/tracker-indexer.c | 54 +-
src/trackerd/tracker-main.c | 60 +-
src/trackerd/tracker-processor.c | 24 +-
src/trackerd/tracker-processor.h | 4 +-
src/trackerd/tracker-status.c | 26 +-
src/trackerd/tracker-status.h | 4 +-
18 files changed, 990 insertions(+), 669 deletions(-)
diff --git a/docs/reference/libtracker-common/libtracker-common-sections.txt b/docs/reference/libtracker-common/libtracker-common-sections.txt
index 87e8f77..0d36e2a 100644
--- a/docs/reference/libtracker-common/libtracker-common-sections.txt
+++ b/docs/reference/libtracker-common/libtracker-common-sections.txt
@@ -186,25 +186,42 @@ tracker_string_to_string_list
tracker_string_to_uint
</SECTION>
-<INCLUDE>libtracker-common/tracker-hal.h</INCLUDE>
+<INCLUDE>libtracker-common/tracker-power.h</INCLUDE>
<SECTION>
-<FILE>tracker-hal</FILE>
-<TITLE>HAL</TITLE>
-TrackerHal
-tracker_hal_new
-tracker_hal_get_battery_exists
-tracker_hal_get_battery_in_use
-tracker_hal_get_mounted_directory_roots
-tracker_hal_get_removable_device_roots
+<FILE>tracker-power</FILE>
+<TITLE>Power</TITLE>
+TrackerPower
+tracker_power_new
+tracker_power_get_battery_exists
+tracker_power_get_battery_in_use
<SUBSECTION Standard>
-TrackerHalClass
-TRACKER_HAL
-TRACKER_IS_HAL
-TRACKER_TYPE_HAL
-tracker_hal_get_type
-TRACKER_HAL_CLASS
-TRACKER_IS_HAL_CLASS
-TRACKER_HAL_GET_CLASS
+TrackerPowerClass
+TRACKER_POWER
+TRACKER_IS_POWER
+TRACKER_TYPE_POWER
+tracker_power_get_type
+TRACKER_POWER_CLASS
+TRACKER_IS_POWER_CLASS
+TRACKER_POWER_GET_CLASS
+</SECTION>
+
+<INCLUDE>libtracker-common/tracker-storage.h</INCLUDE>
+<SECTION>
+<FILE>tracker-storage</FILE>
+<TITLE>Storage</TITLE>
+TrackerStorage
+tracker_storage_new
+tracker_storage_get_mounted_directory_roots
+tracker_storage_get_removable_device_roots
+<SUBSECTION Standard>
+TrackerStorageClass
+TRACKER_STORAGE
+TRACKER_IS_STORAGE
+TRACKER_TYPE_STORAGE
+tracker_storage_get_type
+TRACKER_STORAGE_CLASS
+TRACKER_IS_STORAGE_CLASS
+TRACKER_STORAGE_GET_CLASS
</SECTION>
<INCLUDE>libtracker-common/tracker-ioprio.h</INCLUDE>
diff --git a/src/libtracker-common/Makefile.am b/src/libtracker-common/Makefile.am
index 57820f8..caf9c7e 100644
--- a/src/libtracker-common/Makefile.am
+++ b/src/libtracker-common/Makefile.am
@@ -27,9 +27,11 @@ endif
if HAVE_HAL
hal_sources = \
- tracker-hal.c
+ tracker-power-hal.c \
+ tracker-storage-hal.c
hal_headers = \
- tracker-hal.h
+ tracker-power.h \
+ tracker-storage.h
endif
libtracker_common_la_SOURCES = \
diff --git a/src/libtracker-common/tracker-albumart.c b/src/libtracker-common/tracker-albumart.c
index 669c722..fbd2d0b 100644
--- a/src/libtracker-common/tracker-albumart.c
+++ b/src/libtracker-common/tracker-albumart.c
@@ -55,7 +55,7 @@
#define THUMBNAILER_INTERFACE "org.freedesktop.thumbnailer.Generic"
typedef struct {
- TrackerHal *hal;
+ TrackerStorage *hal;
gchar *art_path;
gchar *local_uri;
} GetFileInfo;
@@ -304,7 +304,7 @@ tracker_albumart_strip_invalid_entities (const gchar *original)
}
void
-tracker_albumart_copy_to_local (TrackerHal *hal,
+tracker_albumart_copy_to_local (TrackerStorage *hal,
const gchar *filename,
const gchar *local_uri)
{
@@ -321,7 +321,7 @@ tracker_albumart_copy_to_local (TrackerHal *hal,
#ifdef HAVE_HAL
g_return_if_fail (hal != NULL);
- removable_roots = tracker_hal_get_removable_device_roots (hal);
+ removable_roots = tracker_storage_get_removable_device_roots (hal);
#else
removable_roots = g_list_append (removable_roots, "/media");
removable_roots = g_list_append (removable_roots, "/mnt");
@@ -722,7 +722,7 @@ tracker_albumart_get_path (const gchar *a,
}
void
-tracker_albumart_request_download (TrackerHal *hal,
+tracker_albumart_request_download (TrackerStorage *hal,
const gchar *album,
const gchar *artist,
const gchar *local_uri,
diff --git a/src/libtracker-common/tracker-albumart.h b/src/libtracker-common/tracker-albumart.h
index 390e727..9a3c3fd 100644
--- a/src/libtracker-common/tracker-albumart.h
+++ b/src/libtracker-common/tracker-albumart.h
@@ -30,7 +30,7 @@ G_BEGIN_DECLS
#error "only <libtracker-common/tracker-common.h> must be included directly."
#endif
-#include "tracker-hal.h"
+#include "tracker-storage.h"
gboolean tracker_albumart_heuristic (const gchar *artist_,
const gchar *album_,
@@ -39,7 +39,7 @@ gboolean tracker_albumart_heuristic (const gchar *artist_,
const gchar *local_uri,
gboolean *copied);
gchar * tracker_albumart_strip_invalid_entities (const gchar *original);
-void tracker_albumart_copy_to_local (TrackerHal *hal,
+void tracker_albumart_copy_to_local (TrackerStorage *storage,
const gchar *filename,
const gchar *local_uri);
void tracker_albumart_get_path (const gchar *a,
@@ -48,7 +48,7 @@ void tracker_albumart_get_path (const gchar *a,
const gchar *uri,
gchar **path,
gchar **local);
-void tracker_albumart_request_download (TrackerHal *hal,
+void tracker_albumart_request_download (TrackerStorage *storage,
const gchar *album,
const gchar *artist,
const gchar *local_uri,
diff --git a/src/libtracker-common/tracker-common.h b/src/libtracker-common/tracker-common.h
index 53711b9..59ac595 100644
--- a/src/libtracker-common/tracker-common.h
+++ b/src/libtracker-common/tracker-common.h
@@ -35,13 +35,14 @@ G_BEGIN_DECLS
#include "tracker-class.h"
#include "tracker-config.h"
#include "tracker-file-utils.h"
-#include "tracker-hal.h"
#include "tracker-language.h"
#include "tracker-module-config.h"
#include "tracker-namespace.h"
#include "tracker-ontology.h"
#include "tracker-parser.h"
+#include "tracker-power.h"
#include "tracker-property.h"
+#include "tracker-storage.h"
#include "tracker-type-utils.h"
#include "tracker-utils.h"
diff --git a/src/libtracker-common/tracker-hal.h b/src/libtracker-common/tracker-hal.h
deleted file mode 100644
index 21ea607..0000000
--- a/src/libtracker-common/tracker-hal.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/* -*- 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 (urho konttori nokia com)
- *
- * 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 __LIBTRACKER_HAL_H__
-#define __LIBTRACKER_HAL_H__
-
-#include <glib-object.h>
-#include <gio/gio.h>
-
-G_BEGIN_DECLS
-
-#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
-#error "only <libtracker-common/tracker-common.h> must be included directly."
-#endif
-
-#define TRACKER_TYPE_HAL (tracker_hal_get_type ())
-#define TRACKER_HAL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_HAL, TrackerHal))
-#define TRACKER_HAL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_HAL, TrackerHalClass))
-#define TRACKER_IS_HAL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_HAL))
-#define TRACKER_IS_HAL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_HAL))
-#define TRACKER_HAL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_HAL, TrackerHalClass))
-
-typedef struct _TrackerHal TrackerHal;
-typedef struct _TrackerHalClass TrackerHalClass;
-
-struct _TrackerHal {
- GObject parent;
-};
-
-struct _TrackerHalClass {
- GObjectClass parent_class;
-};
-
-#ifdef HAVE_HAL
-
-GType tracker_hal_get_type (void) G_GNUC_CONST;
-
-TrackerHal * tracker_hal_new (void);
-
-gboolean tracker_hal_get_battery_in_use (TrackerHal *hal);
-gboolean tracker_hal_get_battery_exists (TrackerHal *hal);
-gdouble tracker_hal_get_battery_percentage (TrackerHal *hal);
-
-GList * tracker_hal_get_mounted_directory_roots (TrackerHal *hal);
-GList * tracker_hal_get_removable_device_roots (TrackerHal *hal);
-GList * tracker_hal_get_removable_device_udis (TrackerHal *hal);
-
-const gchar *tracker_hal_udi_get_mount_point (TrackerHal *hal,
- const gchar *udi);
-gboolean tracker_hal_udi_get_is_mounted (TrackerHal *hal,
- const gchar *udi);
-gboolean tracker_hal_uri_is_on_removable_device (TrackerHal *hal,
- const gchar *uri,
- gchar **mount_point,
- gboolean *available);
-
-const gchar* tracker_hal_get_volume_udi_for_file (TrackerHal *hal,
- GFile *file);
-
-#endif /* HAVE_HAL */
-
-G_END_DECLS
-
-#endif /* __LIBTRACKER_HAL_H__ */
diff --git a/src/libtracker-common/tracker-power-hal.c b/src/libtracker-common/tracker-power-hal.c
new file mode 100644
index 0000000..42b9caf
--- /dev/null
+++ b/src/libtracker-common/tracker-power-hal.c
@@ -0,0 +1,577 @@
+/* -*- 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 (urho konttori nokia com)
+ *
+ * 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"
+
+#ifdef HAVE_HAL
+
+#include <string.h>
+
+#include <libhal.h>
+
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "tracker-log.h"
+#include "tracker-power.h"
+#include "tracker-utils.h"
+#include "tracker-marshal.h"
+
+#define CAPABILITY_AC_ADAPTER "ac_adapter"
+#define CAPABILITY_BATTERY "battery"
+
+#define PROP_AC_ADAPTER_ON "ac_adapter.present"
+#define PROP_BATT_PERCENTAGE "battery.charge_level.percentage"
+
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_POWER, TrackerPowerPriv))
+
+typedef struct {
+ LibHalContext *context;
+ DBusConnection *connection;
+
+ GHashTable *batteries;
+
+ gchar *ac_adapter_udi;
+ gboolean battery_in_use;
+ gdouble battery_percentage;
+} TrackerPowerPriv;
+
+static void tracker_power_finalize (GObject *object);
+static void hal_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static gboolean hal_setup_ac_adapters (TrackerPower *power);
+static gboolean hal_setup_batteries (TrackerPower *power);
+
+static void hal_battery_modify (TrackerPower *power,
+ const gchar *udi);
+static void hal_battery_remove (TrackerPower *power,
+ const gchar *udi);
+
+static void hal_device_added_cb (LibHalContext *context,
+ const gchar *udi);
+static void hal_device_removed_cb (LibHalContext *context,
+ const gchar *udi);
+static void hal_device_property_modified_cb (LibHalContext *context,
+ const char *udi,
+ const char *key,
+ dbus_bool_t is_removed,
+ dbus_bool_t is_added);
+
+enum {
+ PROP_0,
+ PROP_BATTERY_IN_USE,
+ PROP_BATTERY_EXISTS,
+ PROP_BATTERY_PERCENTAGE
+};
+
+G_DEFINE_TYPE (TrackerPower, tracker_power, G_TYPE_OBJECT);
+
+static void
+tracker_power_class_init (TrackerPowerClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = tracker_power_finalize;
+ object_class->get_property = hal_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_BATTERY_IN_USE,
+ g_param_spec_boolean ("battery-in-use",
+ "Battery in use",
+ "Whether the battery is being used",
+ FALSE,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_BATTERY_EXISTS,
+ g_param_spec_boolean ("battery-exists",
+ "Battery exists",
+ "There is a battery on this machine",
+ FALSE,
+ G_PARAM_READABLE));
+ g_object_class_install_property (object_class,
+ PROP_BATTERY_PERCENTAGE,
+ g_param_spec_double ("battery-percentage",
+ "Battery percentage",
+ "Battery percentage",
+ 0.0, 1.0, 0.0,
+ G_PARAM_READABLE));
+
+ g_type_class_add_private (object_class, sizeof (TrackerPowerPriv));
+}
+
+static void
+tracker_power_init (TrackerPower *power)
+{
+ TrackerPowerPriv *priv;
+ DBusError error;
+
+ g_message ("Initializing HAL Power...");
+
+ priv = GET_PRIV (power);
+
+ priv->batteries = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ NULL);
+
+ dbus_error_init (&error);
+
+ priv->connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (dbus_error_is_set (&error)) {
+ g_critical ("Could not get the system DBus connection, %s",
+ error.message);
+ dbus_error_free (&error);
+ return;
+ }
+
+ dbus_connection_set_exit_on_disconnect (priv->connection, FALSE);
+ dbus_connection_setup_with_g_main (priv->connection, NULL);
+
+ priv->context = libhal_ctx_new ();
+
+ if (!priv->context) {
+ g_critical ("Could not create HAL context");
+ return;
+ }
+
+ libhal_ctx_set_user_data (priv->context, power);
+ libhal_ctx_set_dbus_connection (priv->context, priv->connection);
+
+ if (!libhal_ctx_init (priv->context, &error)) {
+ if (dbus_error_is_set (&error)) {
+ g_critical ("Could not initialize the HAL context, %s",
+ error.message);
+ dbus_error_free (&error);
+ } else {
+ g_critical ("Could not initialize the HAL context, "
+ "no error, is hald running?");
+ }
+
+ libhal_ctx_free (priv->context);
+ priv->context = NULL;
+ return;
+ }
+
+
+ /* Volume and property notification callbacks */
+ g_message ("HAL monitors set for devices added/removed/mounted/umounted...");
+ libhal_ctx_set_device_added (priv->context, hal_device_added_cb);
+ libhal_ctx_set_device_removed (priv->context, hal_device_removed_cb);
+ libhal_ctx_set_device_property_modified (priv->context, hal_device_property_modified_cb);
+
+ /* Get all AC adapters info and set them up */
+ if (!hal_setup_ac_adapters (power)) {
+ return;
+ }
+
+ /* Get all battery devices and set them up */
+ if (!hal_setup_batteries (power)) {
+ return;
+ }
+}
+
+static void
+tracker_power_finalize (GObject *object)
+{
+ TrackerPowerPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ if (priv->batteries) {
+ g_hash_table_unref (priv->batteries);
+ }
+
+ g_free (priv->ac_adapter_udi);
+
+ if (priv->context) {
+ libhal_ctx_shutdown (priv->context, NULL);
+ libhal_ctx_set_user_data (priv->context, NULL);
+ libhal_ctx_free (priv->context);
+ }
+
+ if (priv->connection) {
+ dbus_connection_unref (priv->connection);
+ }
+
+ (G_OBJECT_CLASS (tracker_power_parent_class)->finalize) (object);
+}
+
+static void
+hal_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerPowerPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ switch (param_id) {
+ case PROP_BATTERY_IN_USE:
+ g_value_set_boolean (value, priv->battery_in_use);
+ break;
+ case PROP_BATTERY_EXISTS:
+ g_value_set_boolean (value, priv->ac_adapter_udi != NULL);
+ break;
+ case PROP_BATTERY_PERCENTAGE:
+ g_value_set_double (value, priv->battery_percentage);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+static gboolean
+hal_setup_ac_adapters (TrackerPower *power)
+{
+ TrackerPowerPriv *priv;
+ DBusError error;
+ gchar **devices, **p;
+ gint num;
+
+ priv = GET_PRIV (power);
+
+ dbus_error_init (&error);
+
+ devices = libhal_find_device_by_capability (priv->context,
+ CAPABILITY_AC_ADAPTER,
+ &num,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ g_critical ("Could not get AC adapter capable devices, %s",
+ error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ g_message ("HAL found %d AC adapter capable devices", num);
+
+ if (!devices || !devices[0]) {
+ libhal_free_string_array (devices);
+
+ priv->battery_in_use = FALSE;
+ g_object_notify (G_OBJECT (power), "battery-in-use");
+
+ priv->ac_adapter_udi = NULL;
+ g_object_notify (G_OBJECT (power), "battery-exists");
+
+ return TRUE;
+ }
+
+ for (p = devices; *p; p++) {
+ if (!priv->ac_adapter_udi) {
+ /* For now just use the first one we find */
+ priv->ac_adapter_udi = g_strdup (*p);
+ g_object_notify (G_OBJECT (power), "battery-exists");
+
+ g_message (" Device '%s' (default)", *p);
+ } else {
+ g_message (" Device '%s'", *p);
+ }
+ }
+
+ libhal_free_string_array (devices);
+
+ /* Make sure we watch changes to the battery use */
+ libhal_device_add_property_watch (priv->context,
+ priv->ac_adapter_udi,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ g_critical ("Could not add device:'%s' to property watch, %s",
+ priv->ac_adapter_udi, error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ /* Get current state, are we using the battery now? */
+ priv->battery_in_use = !libhal_device_get_property_bool (priv->context,
+ priv->ac_adapter_udi,
+ PROP_AC_ADAPTER_ON,
+ NULL);
+
+ g_message ("HAL reports system is currently powered by %s",
+ priv->battery_in_use ? "battery" : "AC adapter");
+
+ g_object_notify (G_OBJECT (power), "battery-in-use");
+
+ return TRUE;
+}
+
+static gboolean
+hal_setup_batteries (TrackerPower *power)
+{
+ TrackerPowerPriv *priv;
+ DBusError error;
+ gchar **devices, **p;
+ gint num;
+
+ priv = GET_PRIV (power);
+
+ dbus_error_init (&error);
+
+ devices = libhal_find_device_by_capability (priv->context,
+ CAPABILITY_BATTERY,
+ &num,
+ &error);
+
+ if (dbus_error_is_set (&error)) {
+ g_critical ("Could not get Battery HAL info, %s",
+ error.message);
+ dbus_error_free (&error);
+ return FALSE;
+ }
+
+ g_message ("HAL found %d batteries", num);
+
+ if (!devices || !devices[0]) {
+ libhal_free_string_array (devices);
+ return TRUE;
+ }
+
+ for (p = devices; *p; p++) {
+ g_message (" Device '%s'", *p);
+
+ hal_battery_modify (power, *p);
+ libhal_device_add_property_watch (priv->context, *p, &error);
+
+ if (dbus_error_is_set (&error)) {
+ g_critical ("Could not add device:'%s' to property watch, %s",
+ *p, error.message);
+ dbus_error_free (&error);
+ }
+ }
+
+ libhal_free_string_array (devices);
+
+ return TRUE;
+}
+
+static void
+hal_battery_notify (TrackerPower *power)
+{
+ TrackerPowerPriv *priv;
+ GList *values, *v;
+ gint percentage, n_values;
+
+ priv = GET_PRIV (power);
+ percentage = n_values = 0;
+
+ values = g_hash_table_get_values (priv->batteries);
+
+ for (v = values; v; v = v->next) {
+ percentage += GPOINTER_TO_INT (v->data);
+ n_values++;
+ }
+
+ if (n_values > 0) {
+ priv->battery_percentage = (gdouble) percentage / n_values;
+ priv->battery_percentage /= 100;
+ } else {
+ priv->battery_percentage = 0;
+ }
+
+ g_list_free (values);
+
+ g_object_notify (G_OBJECT (power), "battery-percentage");
+}
+
+static void
+hal_battery_modify (TrackerPower *power,
+ const gchar *udi)
+{
+ TrackerPowerPriv *priv;
+ gint percentage;
+
+ priv = GET_PRIV (power);
+ percentage = libhal_device_get_property_int (priv->context, udi,
+ PROP_BATT_PERCENTAGE,
+ NULL);
+
+ g_hash_table_insert (priv->batteries,
+ g_strdup (udi),
+ GINT_TO_POINTER (percentage));
+
+ hal_battery_notify (power);
+}
+
+static void
+hal_battery_remove (TrackerPower *power,
+ const gchar *udi)
+{
+ TrackerPowerPriv *priv;
+
+ priv = GET_PRIV (power);
+
+ g_hash_table_remove (priv->batteries, udi);
+ hal_battery_notify (power);
+}
+
+static void
+hal_device_added_cb (LibHalContext *context,
+ const gchar *udi)
+{
+ TrackerPower *power;
+
+ power = libhal_ctx_get_user_data (context);
+
+ if (libhal_device_query_capability (context, udi, CAPABILITY_BATTERY, NULL)) {
+ hal_battery_modify (power, udi);
+ }
+}
+
+static void
+hal_device_removed_cb (LibHalContext *context,
+ const gchar *udi)
+{
+ TrackerPower *power;
+ TrackerPowerPriv *priv;
+
+ power = (TrackerPower*) libhal_ctx_get_user_data (context);
+ priv = GET_PRIV (power);
+
+ if (g_hash_table_lookup (priv->batteries, udi)) {
+ hal_battery_remove (power, udi);
+ }
+}
+
+static void
+hal_device_property_modified_cb (LibHalContext *context,
+ const char *udi,
+ const char *key,
+ dbus_bool_t is_removed,
+ dbus_bool_t is_added)
+{
+ TrackerPower *power;
+ TrackerPowerPriv *priv;
+ DBusError error;
+
+ power = (TrackerPower*) libhal_ctx_get_user_data (context);
+ priv = GET_PRIV (power);
+
+ dbus_error_init (&error);
+
+ if (priv->ac_adapter_udi && strcmp (priv->ac_adapter_udi, udi) == 0) {
+ /* Property change is on the AC adapter */
+ priv->battery_in_use = !libhal_device_get_property_bool (priv->context,
+ priv->ac_adapter_udi,
+ PROP_AC_ADAPTER_ON,
+ &error);
+ g_message ("HAL reports system is now powered by %s",
+ priv->battery_in_use ? "battery" : "AC adapter");
+
+ g_object_notify (G_OBJECT (power), "battery-in-use");
+
+ if (dbus_error_is_set (&error)) {
+ g_critical ("Could not get device property:'%s' for udi:'%s', %s",
+ udi, PROP_AC_ADAPTER_ON, error.message);
+ dbus_error_free (&error);
+ return;
+ }
+ } else if (g_hash_table_lookup (priv->batteries, udi)) {
+ /* Property change is on any battery */
+ if (strcmp (key, PROP_BATT_PERCENTAGE) == 0) {
+ hal_battery_modify (power, udi);
+ }
+ }
+}
+
+/**
+ * tracker_power_new:
+ *
+ * Creates a new instance of #TrackerPower.
+ *
+ * Returns: The newly created #TrackerPower.
+ **/
+TrackerPower *
+tracker_power_new ()
+{
+ return g_object_new (TRACKER_TYPE_POWER, NULL);
+}
+
+/**
+ * tracker_power_get_battery_in_use:
+ * @power: A #TrackerPower.
+ *
+ * Returns whether the computer battery (if any) is currently in use.
+ *
+ * Returns: #TRUE if the computer is running on battery power.
+ **/
+gboolean
+tracker_power_get_battery_in_use (TrackerPower *power)
+{
+ TrackerPowerPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_POWER (power), TRUE);
+
+ priv = GET_PRIV (power);
+
+ return priv->battery_in_use;
+}
+
+/**
+ * tracker_power_get_battery_exists:
+ * @power: A #TrackerPower
+ *
+ * Returns whether the computer has batteries.
+ *
+ * Returns: #TRUE if the computer has batteries available.
+ **/
+gboolean
+tracker_power_get_battery_exists (TrackerPower *power)
+{
+ TrackerPowerPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_POWER (power), TRUE);
+
+ priv = GET_PRIV (power);
+
+ return priv->ac_adapter_udi != NULL;
+}
+
+/**
+ * tracker_power_get_battery_percentage:
+ * @power: A #TrackerPower
+ *
+ * Returns the battery percentage left on the
+ * computer, or #0.0 if no batteries are present.
+ *
+ * Returns: The battery percentage left.
+ **/
+gdouble
+tracker_power_get_battery_percentage (TrackerPower *power)
+{
+ TrackerPowerPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_POWER (power), 0.0);
+
+ priv = GET_PRIV (power);
+
+ return priv->battery_percentage;
+}
+
+#endif /* HAVE_HAL */
diff --git a/src/libtracker-common/tracker-power.h b/src/libtracker-common/tracker-power.h
new file mode 100644
index 0000000..daa85aa
--- /dev/null
+++ b/src/libtracker-common/tracker-power.h
@@ -0,0 +1,65 @@
+/* -*- 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 (urho konttori nokia com)
+ *
+ * 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 __LIBTRACKER_POWER_H__
+#define __LIBTRACKER_POWER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-common/tracker-common.h> must be included directly."
+#endif
+
+#define TRACKER_TYPE_POWER (tracker_power_get_type ())
+#define TRACKER_POWER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_POWER, TrackerPower))
+#define TRACKER_POWER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_POWER, TrackerPowerClass))
+#define TRACKER_IS_POWER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_POWER))
+#define TRACKER_IS_POWER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_POWER))
+#define TRACKER_POWER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_POWER, TrackerPowerClass))
+
+typedef struct _TrackerPower TrackerPower;
+typedef struct _TrackerPowerClass TrackerPowerClass;
+
+struct _TrackerPower {
+ GObject parent;
+};
+
+struct _TrackerPowerClass {
+ GObjectClass parent_class;
+};
+
+#ifdef HAVE_HAL
+
+GType tracker_power_get_type (void) G_GNUC_CONST;
+
+TrackerPower * tracker_power_new (void);
+
+gboolean tracker_power_get_battery_in_use (TrackerPower *power);
+gboolean tracker_power_get_battery_exists (TrackerPower *power);
+gdouble tracker_power_get_battery_percentage (TrackerPower *power);
+
+#endif /* HAVE_HAL */
+
+G_END_DECLS
+
+#endif /* __LIBTRACKER_POWER_H__ */
diff --git a/src/libtracker-common/tracker-hal.c b/src/libtracker-common/tracker-storage-hal.c
similarity index 60%
rename from src/libtracker-common/tracker-hal.c
rename to src/libtracker-common/tracker-storage-hal.c
index f8a35d9..18c5177 100644
--- a/src/libtracker-common/tracker-hal.c
+++ b/src/libtracker-common/tracker-storage-hal.c
@@ -32,19 +32,15 @@
#include <dbus/dbus-glib-lowlevel.h>
#include "tracker-log.h"
-#include "tracker-hal.h"
+#include "tracker-storage.h"
#include "tracker-utils.h"
#include "tracker-marshal.h"
-#define CAPABILITY_AC_ADAPTER "ac_adapter"
-#define CAPABILITY_BATTERY "battery"
#define CAPABILITY_VOLUME "volume"
-#define PROP_AC_ADAPTER_ON "ac_adapter.present"
-#define PROP_BATT_PERCENTAGE "battery.charge_level.percentage"
#define PROP_IS_MOUNTED "volume.is_mounted"
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_HAL, TrackerHalPriv))
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_STORAGE, TrackerStoragePriv))
typedef struct {
LibHalContext *context;
@@ -53,33 +49,21 @@ typedef struct {
GHashTable *all_devices;
GHashTable *mounted_devices;
GHashTable *removable_devices;
- GHashTable *batteries;
-
- gchar *ac_adapter_udi;
- gboolean battery_in_use;
- gdouble battery_percentage;
-} TrackerHalPriv;
+} TrackerStoragePriv;
typedef struct {
LibHalContext *context;
GList *roots;
} GetRoots;
-static void tracker_hal_finalize (GObject *object);
+static void tracker_storage_finalize (GObject *object);
static void hal_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
-static gboolean hal_setup_devices (TrackerHal *hal);
-static gboolean hal_setup_ac_adapters (TrackerHal *hal);
-static gboolean hal_setup_batteries (TrackerHal *hal);
-
-static void hal_battery_modify (TrackerHal *hal,
- const gchar *udi);
-static void hal_battery_remove (TrackerHal *hal,
- const gchar *udi);
+static gboolean hal_setup_devices (TrackerStorage *hal);
-static gboolean hal_device_add (TrackerHal *hal,
+static gboolean hal_device_add (TrackerStorage *hal,
LibHalVolume *volume);
static void hal_device_added_cb (LibHalContext *context,
const gchar *udi);
@@ -93,9 +77,6 @@ static void hal_device_property_modified_cb (LibHalContext *context,
enum {
PROP_0,
- PROP_BATTERY_IN_USE,
- PROP_BATTERY_EXISTS,
- PROP_BATTERY_PERCENTAGE
};
enum {
@@ -106,16 +87,16 @@ enum {
static guint signals[LAST_SIGNAL] = {0};
-G_DEFINE_TYPE (TrackerHal, tracker_hal, G_TYPE_OBJECT);
+G_DEFINE_TYPE (TrackerStorage, tracker_storage, G_TYPE_OBJECT);
static void
-tracker_hal_class_init (TrackerHalClass *klass)
+tracker_storage_class_init (TrackerStorageClass *klass)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = tracker_hal_finalize;
+ object_class->finalize = tracker_storage_finalize;
object_class->get_property = hal_get_property;
signals[MOUNT_POINT_ADDED] =
@@ -142,41 +123,18 @@ tracker_hal_class_init (TrackerHalClass *klass)
G_TYPE_STRING,
G_TYPE_STRING);
- g_object_class_install_property (object_class,
- PROP_BATTERY_IN_USE,
- g_param_spec_boolean ("battery-in-use",
- "Battery in use",
- "Whether the battery is being used",
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_BATTERY_EXISTS,
- g_param_spec_boolean ("battery-exists",
- "Battery exists",
- "There is a battery on this machine",
- FALSE,
- G_PARAM_READABLE));
- g_object_class_install_property (object_class,
- PROP_BATTERY_PERCENTAGE,
- g_param_spec_double ("battery-percentage",
- "Battery percentage",
- "Battery percentage",
- 0.0, 1.0, 0.0,
- G_PARAM_READABLE));
-
- g_type_class_add_private (object_class, sizeof (TrackerHalPriv));
+ g_type_class_add_private (object_class, sizeof (TrackerStoragePriv));
}
static void
-tracker_hal_init (TrackerHal *hal)
+tracker_storage_init (TrackerStorage *storage)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
DBusError error;
- g_message ("Initializing HAL...");
+ g_message ("Initializing HAL Storage...");
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
priv->all_devices = g_hash_table_new_full (g_str_hash,
g_str_equal,
@@ -192,10 +150,6 @@ tracker_hal_init (TrackerHal *hal)
g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
- priv->batteries = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- NULL);
dbus_error_init (&error);
@@ -217,7 +171,7 @@ tracker_hal_init (TrackerHal *hal)
return;
}
- libhal_ctx_set_user_data (priv->context, hal);
+ libhal_ctx_set_user_data (priv->context, storage);
libhal_ctx_set_dbus_connection (priv->context, priv->connection);
if (!libhal_ctx_init (priv->context, &error)) {
@@ -243,25 +197,15 @@ tracker_hal_init (TrackerHal *hal)
libhal_ctx_set_device_property_modified (priv->context, hal_device_property_modified_cb);
/* Get all devices which are mountable and set them up */
- if (!hal_setup_devices (hal)) {
- return;
- }
-
- /* Get all AC adapters info and set them up */
- if (!hal_setup_ac_adapters (hal)) {
- return;
- }
-
- /* Get all battery devices and set them up */
- if (!hal_setup_batteries (hal)) {
+ if (!hal_setup_devices (storage)) {
return;
}
}
static void
-tracker_hal_finalize (GObject *object)
+tracker_storage_finalize (GObject *object)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
priv = GET_PRIV (object);
@@ -277,12 +221,6 @@ tracker_hal_finalize (GObject *object)
g_hash_table_unref (priv->all_devices);
}
- if (priv->batteries) {
- g_hash_table_unref (priv->batteries);
- }
-
- g_free (priv->ac_adapter_udi);
-
if (priv->context) {
libhal_ctx_shutdown (priv->context, NULL);
libhal_ctx_set_user_data (priv->context, NULL);
@@ -293,7 +231,7 @@ tracker_hal_finalize (GObject *object)
dbus_connection_unref (priv->connection);
}
- (G_OBJECT_CLASS (tracker_hal_parent_class)->finalize) (object);
+ (G_OBJECT_CLASS (tracker_storage_parent_class)->finalize) (object);
}
static void
@@ -302,20 +240,11 @@ hal_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
priv = GET_PRIV (object);
switch (param_id) {
- case PROP_BATTERY_IN_USE:
- g_value_set_boolean (value, priv->battery_in_use);
- break;
- case PROP_BATTERY_EXISTS:
- g_value_set_boolean (value, priv->ac_adapter_udi != NULL);
- break;
- case PROP_BATTERY_PERCENTAGE:
- g_value_set_double (value, priv->battery_percentage);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -323,14 +252,14 @@ hal_get_property (GObject *object,
}
static gboolean
-hal_setup_devices (TrackerHal *hal)
+hal_setup_devices (TrackerStorage *storage)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
DBusError error;
gchar **devices, **p;
gint num;
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
dbus_error_init (&error);
@@ -374,7 +303,7 @@ hal_setup_devices (TrackerHal *hal)
g_debug (" Label : %s",
libhal_volume_get_label (volume));
- hal_device_add (hal, volume);
+ hal_device_add (storage, volume);
libhal_volume_free (volume);
}
@@ -383,142 +312,15 @@ hal_setup_devices (TrackerHal *hal)
return TRUE;
}
-static gboolean
-hal_setup_ac_adapters (TrackerHal *hal)
-{
- TrackerHalPriv *priv;
- DBusError error;
- gchar **devices, **p;
- gint num;
-
- priv = GET_PRIV (hal);
-
- dbus_error_init (&error);
-
- devices = libhal_find_device_by_capability (priv->context,
- CAPABILITY_AC_ADAPTER,
- &num,
- &error);
-
- if (dbus_error_is_set (&error)) {
- g_critical ("Could not get AC adapter capable devices, %s",
- error.message);
- dbus_error_free (&error);
- return FALSE;
- }
-
- g_message ("HAL found %d AC adapter capable devices", num);
-
- if (!devices || !devices[0]) {
- libhal_free_string_array (devices);
-
- priv->battery_in_use = FALSE;
- g_object_notify (G_OBJECT (hal), "battery-in-use");
-
- priv->ac_adapter_udi = NULL;
- g_object_notify (G_OBJECT (hal), "battery-exists");
-
- return TRUE;
- }
-
- for (p = devices; *p; p++) {
- if (!priv->ac_adapter_udi) {
- /* For now just use the first one we find */
- priv->ac_adapter_udi = g_strdup (*p);
- g_object_notify (G_OBJECT (hal), "battery-exists");
-
- g_message (" Device '%s' (default)", *p);
- } else {
- g_message (" Device '%s'", *p);
- }
- }
-
- libhal_free_string_array (devices);
-
- /* Make sure we watch changes to the battery use */
- libhal_device_add_property_watch (priv->context,
- priv->ac_adapter_udi,
- &error);
-
- if (dbus_error_is_set (&error)) {
- g_critical ("Could not add device:'%s' to property watch, %s",
- priv->ac_adapter_udi, error.message);
- dbus_error_free (&error);
- return FALSE;
- }
-
- /* Get current state, are we using the battery now? */
- priv->battery_in_use = !libhal_device_get_property_bool (priv->context,
- priv->ac_adapter_udi,
- PROP_AC_ADAPTER_ON,
- NULL);
-
- g_message ("HAL reports system is currently powered by %s",
- priv->battery_in_use ? "battery" : "AC adapter");
-
- g_object_notify (G_OBJECT (hal), "battery-in-use");
-
- return TRUE;
-}
-
-static gboolean
-hal_setup_batteries (TrackerHal *hal)
-{
- TrackerHalPriv *priv;
- DBusError error;
- gchar **devices, **p;
- gint num;
-
- priv = GET_PRIV (hal);
-
- dbus_error_init (&error);
-
- devices = libhal_find_device_by_capability (priv->context,
- CAPABILITY_BATTERY,
- &num,
- &error);
-
- if (dbus_error_is_set (&error)) {
- g_critical ("Could not get Battery HAL info, %s",
- error.message);
- dbus_error_free (&error);
- return FALSE;
- }
-
- g_message ("HAL found %d batteries", num);
-
- if (!devices || !devices[0]) {
- libhal_free_string_array (devices);
- return TRUE;
- }
-
- for (p = devices; *p; p++) {
- g_message (" Device '%s'", *p);
-
- hal_battery_modify (hal, *p);
- libhal_device_add_property_watch (priv->context, *p, &error);
-
- if (dbus_error_is_set (&error)) {
- g_critical ("Could not add device:'%s' to property watch, %s",
- *p, error.message);
- dbus_error_free (&error);
- }
- }
-
- libhal_free_string_array (devices);
-
- return TRUE;
-}
-
static void
-hal_mount_point_add (TrackerHal *hal,
- const gchar *udi,
- const gchar *mount_point,
- gboolean removable_device)
+hal_mount_point_add (TrackerStorage *storage,
+ const gchar *udi,
+ const gchar *mount_point,
+ gboolean removable_device)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
g_message ("HAL device:'%s' with mount point:'%s', removable:%s now being tracked",
(const gchar*) g_hash_table_lookup (priv->all_devices, udi),
@@ -535,17 +337,17 @@ hal_mount_point_add (TrackerHal *hal,
g_strdup (mount_point));
}
- g_signal_emit (hal, signals[MOUNT_POINT_ADDED], 0, udi, mount_point, NULL);
+ g_signal_emit (storage, signals[MOUNT_POINT_ADDED], 0, udi, mount_point, NULL);
}
static void
-hal_mount_point_remove (TrackerHal *hal,
- const gchar *udi)
+hal_mount_point_remove (TrackerStorage *storage,
+ const gchar *udi)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
const gchar *mount_point;
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
mount_point = g_hash_table_lookup (priv->mounted_devices, udi);
@@ -559,7 +361,7 @@ hal_mount_point_remove (TrackerHal *hal,
udi,
g_hash_table_remove (priv->removable_devices, udi) ? "yes" : "no");
- g_signal_emit (hal, signals[MOUNT_POINT_REMOVED], 0, udi, mount_point, NULL);
+ g_signal_emit (storage, signals[MOUNT_POINT_REMOVED], 0, udi, mount_point, NULL);
g_hash_table_remove (priv->mounted_devices, udi);
g_hash_table_remove (priv->removable_devices, udi);
@@ -605,10 +407,10 @@ hal_drive_type_to_string (LibHalDriveType type)
}
static gboolean
-hal_device_is_removable (TrackerHal *hal,
- const gchar *device_file)
+hal_device_is_removable (TrackerStorage *storage,
+ const gchar *device_file)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
LibHalDrive *drive;
gboolean removable;
@@ -616,7 +418,7 @@ hal_device_is_removable (TrackerHal *hal,
return FALSE;
}
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
drive = libhal_drive_from_device_file (priv->context, device_file);
if (!drive) {
@@ -630,10 +432,10 @@ hal_device_is_removable (TrackerHal *hal,
}
static gboolean
-hal_device_should_be_tracked (TrackerHal *hal,
- const gchar *device_file)
+hal_device_should_be_tracked (TrackerStorage *storage,
+ const gchar *device_file)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
LibHalDrive *drive;
LibHalDriveType drive_type;
gboolean eligible;
@@ -642,7 +444,7 @@ hal_device_should_be_tracked (TrackerHal *hal,
return FALSE;
}
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
drive = libhal_drive_from_device_file (priv->context, device_file);
if (!drive) {
@@ -696,77 +498,17 @@ hal_device_should_be_tracked (TrackerHal *hal,
return eligible;
}
-static void
-hal_battery_notify (TrackerHal *hal)
-{
- TrackerHalPriv *priv;
- GList *values, *v;
- gint percentage, n_values;
-
- priv = GET_PRIV (hal);
- percentage = n_values = 0;
-
- values = g_hash_table_get_values (priv->batteries);
-
- for (v = values; v; v = v->next) {
- percentage += GPOINTER_TO_INT (v->data);
- n_values++;
- }
-
- if (n_values > 0) {
- priv->battery_percentage = (gdouble) percentage / n_values;
- priv->battery_percentage /= 100;
- } else {
- priv->battery_percentage = 0;
- }
-
- g_list_free (values);
-
- g_object_notify (G_OBJECT (hal), "battery-percentage");
-}
-
-static void
-hal_battery_modify (TrackerHal *hal,
- const gchar *udi)
-{
- TrackerHalPriv *priv;
- gint percentage;
-
- priv = GET_PRIV (hal);
- percentage = libhal_device_get_property_int (priv->context, udi,
- PROP_BATT_PERCENTAGE,
- NULL);
-
- g_hash_table_insert (priv->batteries,
- g_strdup (udi),
- GINT_TO_POINTER (percentage));
-
- hal_battery_notify (hal);
-}
-
-static void
-hal_battery_remove (TrackerHal *hal,
- const gchar *udi)
-{
- TrackerHalPriv *priv;
-
- priv = GET_PRIV (hal);
-
- g_hash_table_remove (priv->batteries, udi);
- hal_battery_notify (hal);
-}
-
static gboolean
-hal_device_add (TrackerHal *hal,
- LibHalVolume *volume)
+hal_device_add (TrackerStorage *storage,
+ LibHalVolume *volume)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
DBusError error;
const gchar *udi;
const gchar *mount_point;
const gchar *device_file;
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
dbus_error_init (&error);
@@ -779,7 +521,7 @@ hal_device_add (TrackerHal *hal,
}
/* If there is no mount point, then there is nothing to track */
- if (!hal_device_should_be_tracked (hal, device_file)) {
+ if (!hal_device_should_be_tracked (storage, device_file)) {
return TRUE;
}
@@ -800,10 +542,10 @@ hal_device_add (TrackerHal *hal,
g_strdup (device_file));
if (mount_point) {
- hal_mount_point_add (hal,
+ hal_mount_point_add (storage,
udi,
mount_point,
- hal_device_is_removable (hal, device_file));
+ hal_device_is_removable (storage, device_file));
}
return TRUE;
@@ -813,14 +555,12 @@ static void
hal_device_added_cb (LibHalContext *context,
const gchar *udi)
{
- TrackerHal *hal;
- LibHalVolume *volume;
+ TrackerStorage *storage;
+ LibHalVolume *volume;
- hal = libhal_ctx_get_user_data (context);
+ storage = libhal_ctx_get_user_data (context);
- if (libhal_device_query_capability (context, udi, CAPABILITY_BATTERY, NULL)) {
- hal_battery_modify (hal, udi);
- } else if (libhal_device_query_capability (context, udi, CAPABILITY_VOLUME, NULL)) {
+ if (libhal_device_query_capability (context, udi, CAPABILITY_VOLUME, NULL)) {
volume = libhal_volume_from_udi (context, udi);
if (!volume) {
@@ -843,7 +583,7 @@ hal_device_added_cb (LibHalContext *context,
g_message (" Label : %s",
libhal_volume_get_label (volume));
- hal_device_add (hal, volume);
+ hal_device_add (storage, volume);
libhal_volume_free (volume);
}
}
@@ -852,17 +592,15 @@ static void
hal_device_removed_cb (LibHalContext *context,
const gchar *udi)
{
- TrackerHal *hal;
- TrackerHalPriv *priv;
- const gchar *device_file;
- const gchar *mount_point;
+ TrackerStorage *storage;
+ TrackerStoragePriv *priv;
+ const gchar *device_file;
+ const gchar *mount_point;
- hal = (TrackerHal*) libhal_ctx_get_user_data (context);
- priv = GET_PRIV (hal);
+ storage = (TrackerStorage*) libhal_ctx_get_user_data (context);
+ priv = GET_PRIV (storage);
- if (g_hash_table_lookup (priv->batteries, udi)) {
- hal_battery_remove (hal, udi);
- } else if (g_hash_table_lookup (priv->all_devices, udi)) {
+ if (g_hash_table_lookup (priv->all_devices, udi)) {
device_file = g_hash_table_lookup (priv->all_devices, udi);
if (!device_file) {
@@ -881,7 +619,7 @@ hal_device_removed_cb (LibHalContext *context,
g_hash_table_remove (priv->all_devices, udi);
- hal_mount_point_remove (hal, udi);
+ hal_mount_point_remove (storage, udi);
}
}
@@ -892,38 +630,16 @@ hal_device_property_modified_cb (LibHalContext *context,
dbus_bool_t is_removed,
dbus_bool_t is_added)
{
- TrackerHal *hal;
- TrackerHalPriv *priv;
- DBusError error;
+ TrackerStorage *storage;
+ TrackerStoragePriv *priv;
+ DBusError error;
- hal = (TrackerHal*) libhal_ctx_get_user_data (context);
- priv = GET_PRIV (hal);
+ storage = (TrackerStorage*) libhal_ctx_get_user_data (context);
+ priv = GET_PRIV (storage);
dbus_error_init (&error);
- if (priv->ac_adapter_udi && strcmp (priv->ac_adapter_udi, udi) == 0) {
- /* Property change is on the AC adapter */
- priv->battery_in_use = !libhal_device_get_property_bool (priv->context,
- priv->ac_adapter_udi,
- PROP_AC_ADAPTER_ON,
- &error);
- g_message ("HAL reports system is now powered by %s",
- priv->battery_in_use ? "battery" : "AC adapter");
-
- g_object_notify (G_OBJECT (hal), "battery-in-use");
-
- if (dbus_error_is_set (&error)) {
- g_critical ("Could not get device property:'%s' for udi:'%s', %s",
- udi, PROP_AC_ADAPTER_ON, error.message);
- dbus_error_free (&error);
- return;
- }
- } else if (g_hash_table_lookup (priv->batteries, udi)) {
- /* Property change is on any battery */
- if (strcmp (key, PROP_BATT_PERCENTAGE) == 0) {
- hal_battery_modify (hal, udi);
- }
- } else if (g_hash_table_lookup (priv->all_devices, udi)) {
+ if (g_hash_table_lookup (priv->all_devices, udi)) {
const gchar *device_file;
gboolean is_mounted;
@@ -951,7 +667,7 @@ hal_device_property_modified_cb (LibHalContext *context,
g_message ("HAL device:'%s' with udi:'%s' is now unmounted (due to error)",
device_file,
udi);
- hal_mount_point_remove (hal, udi);
+ hal_mount_point_remove (storage, udi);
return;
}
@@ -966,10 +682,10 @@ hal_device_property_modified_cb (LibHalContext *context,
device_file,
udi);
- hal_mount_point_add (hal,
+ hal_mount_point_add (storage,
udi,
mount_point,
- hal_device_is_removable (hal, device_file));
+ hal_device_is_removable (storage, device_file));
libhal_volume_free (volume);
} else {
@@ -977,83 +693,22 @@ hal_device_property_modified_cb (LibHalContext *context,
device_file,
udi);
- hal_mount_point_remove (hal, udi);
+ hal_mount_point_remove (storage, udi);
}
}
}
/**
- * tracker_hal_new:
- *
- * Creates a new instance of #TrackerHal.
- *
- * Returns: The newly created #TrackerHal.
- **/
-TrackerHal *
-tracker_hal_new ()
-{
- return g_object_new (TRACKER_TYPE_HAL, NULL);
-}
-
-/**
- * tracker_hal_get_battery_in_use:
- * @hal: A #TrackerHal.
- *
- * Returns whether the computer battery (if any) is currently in use.
- *
- * Returns: #TRUE if the computer is running on battery power.
- **/
-gboolean
-tracker_hal_get_battery_in_use (TrackerHal *hal)
-{
- TrackerHalPriv *priv;
-
- g_return_val_if_fail (TRACKER_IS_HAL (hal), TRUE);
-
- priv = GET_PRIV (hal);
-
- return priv->battery_in_use;
-}
-
-/**
- * tracker_hal_get_battery_exists:
- * @hal: A #TrackerHal
+ * tracker_storage_new:
*
- * Returns whether the computer has batteries.
+ * Creates a new instance of #TrackerStorage.
*
- * Returns: #TRUE if the computer has batteries available.
+ * Returns: The newly created #TrackerStorage.
**/
-gboolean
-tracker_hal_get_battery_exists (TrackerHal *hal)
+TrackerStorage *
+tracker_storage_new ()
{
- TrackerHalPriv *priv;
-
- g_return_val_if_fail (TRACKER_IS_HAL (hal), TRUE);
-
- priv = GET_PRIV (hal);
-
- return priv->ac_adapter_udi != NULL;
-}
-
-/**
- * tracker_hal_get_battery_percentage:
- * @hal: A #TrackerHal
- *
- * Returns the battery percentage left on the
- * computer, or #0.0 if no batteries are present.
- *
- * Returns: The battery percentage left.
- **/
-gdouble
-tracker_hal_get_battery_percentage (TrackerHal *hal)
-{
- TrackerHalPriv *priv;
-
- g_return_val_if_fail (TRACKER_IS_HAL (hal), 0.0);
-
- priv = GET_PRIV (hal);
-
- return priv->battery_percentage;
+ return g_object_new (TRACKER_TYPE_STORAGE, NULL);
}
static void
@@ -1089,8 +744,8 @@ hal_get_mount_point_by_udi_foreach (gpointer key,
}
/**
- * tracker_hal_get_mounted_directory_roots:
- * @hal: A #TrackerHal
+ * tracker_storage_get_mounted_directory_roots:
+ * @storage: A #TrackerStorage
*
* Returns a #Glist of strings containing the root directories for mounted devices.
* Each element must be freed using g_free() and the list itself using g_list_free().
@@ -1098,14 +753,14 @@ hal_get_mount_point_by_udi_foreach (gpointer key,
* Returns: The list of root directories.
**/
GList *
-tracker_hal_get_mounted_directory_roots (TrackerHal *hal)
+tracker_storage_get_mounted_directory_roots (TrackerStorage *storage)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
GetRoots gr;
- g_return_val_if_fail (TRACKER_IS_HAL (hal), NULL);
+ g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL);
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
gr.context = priv->context;
gr.roots = NULL;
@@ -1118,8 +773,8 @@ tracker_hal_get_mounted_directory_roots (TrackerHal *hal)
}
/**
- * tracker_hal_get_removable_device_roots:
- * @hal: A #TrackerHal
+ * tracker_storage_get_removable_device_roots:
+ * @storage: A #TrackerStorage
*
* Returns a #GList of strings containing the root directories for removable devices.
* Each element must be freed using g_free() and the list itself through g_list_free().
@@ -1127,14 +782,14 @@ tracker_hal_get_mounted_directory_roots (TrackerHal *hal)
* Returns: The list of root directories.
**/
GList *
-tracker_hal_get_removable_device_roots (TrackerHal *hal)
+tracker_storage_get_removable_device_roots (TrackerStorage *storage)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
GetRoots gr;
- g_return_val_if_fail (TRACKER_IS_HAL (hal), NULL);
+ g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL);
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
gr.context = priv->context;
gr.roots = NULL;
@@ -1147,8 +802,8 @@ tracker_hal_get_removable_device_roots (TrackerHal *hal)
}
/**
- * tracker_hal_path_is_on_removable_device:
- * @hal: A #TrackerHal
+ * tracker_storage_path_is_on_removable_device:
+ * @storage: A #TrackerStorage
* @uri: a uri
* @mount_mount: if @uri is on a removable device, the mount point will
* be filled in here. You must free the returned result
@@ -1160,19 +815,19 @@ tracker_hal_get_removable_device_roots (TrackerHal *hal)
* Returns: TRUE if @uri on a known removable device, FALSE otherwise
**/
gboolean
-tracker_hal_uri_is_on_removable_device (TrackerHal *hal,
- const gchar *uri,
- gchar **mount_point,
- gboolean *available)
+tracker_storage_uri_is_on_removable_device (TrackerStorage *storage,
+ const gchar *uri,
+ gchar **mount_point,
+ gboolean *available)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
GHashTableIter iter;
gboolean found = FALSE;
gpointer key, value;
gchar *path;
GFile *file;
- g_return_val_if_fail (TRACKER_IS_HAL (hal), FALSE);
+ g_return_val_if_fail (TRACKER_IS_STORAGE (storage), FALSE);
file = g_file_new_for_uri (uri);
path = g_file_get_path (file);
@@ -1182,7 +837,7 @@ tracker_hal_uri_is_on_removable_device (TrackerHal *hal,
return FALSE;
}
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
g_hash_table_iter_init (&iter, priv->removable_devices);
@@ -1215,8 +870,8 @@ tracker_hal_uri_is_on_removable_device (TrackerHal *hal,
/**
- * tracker_hal_get_removable_device_udis:
- * @hal: A #TrackerHal
+ * tracker_storage_get_removable_device_udis:
+ * @storage: A #TrackerStorage
*
* Returns a #GList of strings containing the UDI for removable devices.
* Each element is owned by the #GHashTable internally, the list
@@ -1225,58 +880,58 @@ tracker_hal_uri_is_on_removable_device (TrackerHal *hal,
* Returns: The list of UDIs.
**/
GList *
-tracker_hal_get_removable_device_udis (TrackerHal *hal)
+tracker_storage_get_removable_device_udis (TrackerStorage *storage)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
- g_return_val_if_fail (TRACKER_IS_HAL (hal), NULL);
+ g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL);
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
return g_hash_table_get_keys (priv->removable_devices);
}
/**
- * tracker_hal_udi_get_mount_point:
- * @hal: A #TrackerHal
+ * tracker_storage_udi_get_mount_point:
+ * @storage: A #TrackerStorage
* @udi: A string pointer to the UDI for the device.
*
* Returns: The mount point for @udi, this should not be freed.
**/
const gchar *
-tracker_hal_udi_get_mount_point (TrackerHal *hal,
- const gchar *udi)
+tracker_storage_udi_get_mount_point (TrackerStorage *storage,
+ const gchar *udi)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
- g_return_val_if_fail (TRACKER_IS_HAL (hal), NULL);
+ g_return_val_if_fail (TRACKER_IS_STORAGE (storage), NULL);
g_return_val_if_fail (udi != NULL, NULL);
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
return g_hash_table_lookup (priv->removable_devices, udi);
}
/**
- * tracker_hal_udi_get_mount_point:
- * @hal: A #TrackerHal
+ * tracker_storage_udi_get_mount_point:
+ * @storage: A #TrackerStorage
* @udi: A #gboolean
*
* Returns: The %TRUE if @udi is mounted or %FALSE if it isn't.
**/
gboolean
-tracker_hal_udi_get_is_mounted (TrackerHal *hal,
- const gchar *udi)
+tracker_storage_udi_get_is_mounted (TrackerStorage *storage,
+ const gchar *udi)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
LibHalVolume *volume;
const gchar *mount_point;
gboolean is_mounted;
- g_return_val_if_fail (TRACKER_IS_HAL (hal), FALSE);
+ g_return_val_if_fail (TRACKER_IS_STORAGE (storage), FALSE);
g_return_val_if_fail (udi != NULL, FALSE);
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
volume = libhal_volume_from_udi (priv->context, udi);
if (!volume) {
@@ -1298,8 +953,8 @@ tracker_hal_udi_get_is_mounted (TrackerHal *hal,
/**
- * tracker_hal_get_volume_udi_for_file:
- * @hal: A #TrackerHal
+ * tracker_storage_get_volume_udi_for_file:
+ * @storage: A #TrackerStorage
* @file: a file
*
* Returns the UDI of the removable device for @file
@@ -1307,17 +962,17 @@ tracker_hal_udi_get_is_mounted (TrackerHal *hal,
* Returns: Returns the UDI of the removable device for @file
**/
const gchar *
-tracker_hal_get_volume_udi_for_file (TrackerHal *hal,
- GFile *file)
+tracker_storage_get_volume_udi_for_file (TrackerStorage *storage,
+ GFile *file)
{
- TrackerHalPriv *priv;
+ TrackerStoragePriv *priv;
GHashTableIter iter;
gboolean found = FALSE;
gpointer key, value;
gchar *path;
const gchar *udi;
- g_return_val_if_fail (TRACKER_IS_HAL (hal), FALSE);
+ g_return_val_if_fail (TRACKER_IS_STORAGE (storage), FALSE);
path = g_file_get_path (file);
@@ -1325,7 +980,7 @@ tracker_hal_get_volume_udi_for_file (TrackerHal *hal,
return NULL;
}
- priv = GET_PRIV (hal);
+ priv = GET_PRIV (storage);
g_hash_table_iter_init (&iter, priv->removable_devices);
diff --git a/src/libtracker-common/tracker-storage.h b/src/libtracker-common/tracker-storage.h
new file mode 100644
index 0000000..7f6f067
--- /dev/null
+++ b/src/libtracker-common/tracker-storage.h
@@ -0,0 +1,78 @@
+/* -*- 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 (urho konttori nokia com)
+ *
+ * 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 __LIBTRACKER_STORAGE_H__
+#define __LIBTRACKER_STORAGE_H__
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-common/tracker-common.h> must be included directly."
+#endif
+
+#define TRACKER_TYPE_STORAGE (tracker_storage_get_type ())
+#define TRACKER_STORAGE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_STORAGE, TrackerStorage))
+#define TRACKER_STORAGE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_STORAGE, TrackerStorageClass))
+#define TRACKER_IS_STORAGE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_STORAGE))
+#define TRACKER_IS_STORAGE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_STORAGE))
+#define TRACKER_STORAGE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_STORAGE, TrackerStorageClass))
+
+typedef struct _TrackerStorage TrackerStorage;
+typedef struct _TrackerStorageClass TrackerStorageClass;
+
+struct _TrackerStorage {
+ GObject parent;
+};
+
+struct _TrackerStorageClass {
+ GObjectClass parent_class;
+};
+
+#ifdef HAVE_HAL
+
+GType tracker_storage_get_type (void) G_GNUC_CONST;
+
+TrackerStorage * tracker_storage_new (void);
+
+GList * tracker_storage_get_mounted_directory_roots (TrackerStorage *storage);
+GList * tracker_storage_get_removable_device_roots (TrackerStorage *storage);
+GList * tracker_storage_get_removable_device_udis (TrackerStorage *storage);
+
+const gchar *tracker_storage_udi_get_mount_point (TrackerStorage *storage,
+ const gchar *udi);
+gboolean tracker_storage_udi_get_is_mounted (TrackerStorage *storage,
+ const gchar *udi);
+gboolean tracker_storage_uri_is_on_removable_device (TrackerStorage *storage,
+ const gchar *uri,
+ gchar **mount_point,
+ gboolean *available);
+
+const gchar* tracker_storage_get_volume_udi_for_file (TrackerStorage *storage,
+ GFile *file);
+
+#endif /* HAVE_HAL */
+
+G_END_DECLS
+
+#endif /* __LIBTRACKER_STORAGE_H__ */
diff --git a/src/tracker-extract/tracker-main.c b/src/tracker-extract/tracker-main.c
index 9458fa3..b01b1c9 100644
--- a/src/tracker-extract/tracker-main.c
+++ b/src/tracker-extract/tracker-main.c
@@ -68,7 +68,7 @@
static GMainLoop *main_loop;
static guint quit_timeout_id = 0;
-static TrackerHal *hal;
+static TrackerStorage *hal;
static gboolean version;
gboolean debug_mode = FALSE;
@@ -130,12 +130,12 @@ tracker_main_quit_timeout_reset (void)
NULL);
}
-TrackerHal *
+TrackerStorage *
tracker_main_get_hal (void)
{
if (!hal) {
#ifdef HAVE_HAL
- hal = tracker_hal_new ();
+ hal = tracker_storage_new ();
#else
hal = NULL;
#endif
diff --git a/src/tracker-extract/tracker-main.h b/src/tracker-extract/tracker-main.h
index 867b146..8032ff1 100644
--- a/src/tracker-extract/tracker-main.h
+++ b/src/tracker-extract/tracker-main.h
@@ -24,7 +24,7 @@
#include <glib.h>
-#include <libtracker-common/tracker-hal.h>
+#include <libtracker-common/tracker-storage.h>
#include <libtracker-common/tracker-statement-list.h>
G_BEGIN_DECLS
@@ -47,7 +47,7 @@ TrackerExtractData *tracker_get_extract_data (void);
* avoid creating new HAL objects constantly, we initialize it once
* and it is available using this API.
*/
-TrackerHal * tracker_main_get_hal (void);
+TrackerStorage * tracker_main_get_hal (void);
/* This is used to not shutdown after the default of 30 seconds if we
* get more work to do.
diff --git a/src/tracker-indexer/tracker-indexer.c b/src/tracker-indexer/tracker-indexer.c
index afc1b6d..16a627f 100644
--- a/src/tracker-indexer/tracker-indexer.c
+++ b/src/tracker-indexer/tracker-indexer.c
@@ -61,7 +61,8 @@
#include <libtracker-common/tracker-config.h>
#include <libtracker-common/tracker-dbus.h>
#include <libtracker-common/tracker-file-utils.h>
-#include <libtracker-common/tracker-hal.h>
+#include <libtracker-common/tracker-power.h>
+#include <libtracker-common/tracker-storage.h>
#include <libtracker-common/tracker-language.h>
#include <libtracker-common/tracker-parser.h>
#include <libtracker-common/tracker-ontology.h>
@@ -136,7 +137,8 @@ struct TrackerIndexerPrivate {
TrackerConfig *config;
TrackerLanguage *language;
- TrackerHal *hal;
+ TrackerPower *hal_power;
+ TrackerStorage *hal_storage;
GTimer *timer;
@@ -483,7 +485,7 @@ set_up_throttle (TrackerIndexer *indexer)
*/
throttle = tracker_config_get_throttle (indexer->private->config);
- if (tracker_hal_get_battery_in_use (indexer->private->hal)) {
+ if (tracker_power_get_battery_in_use (indexer->private->hal_power)) {
g_message ("We are running on battery");
if (throttle == THROTTLE_DEFAULT) {
@@ -612,11 +614,12 @@ tracker_indexer_finalize (GObject *object)
}
#ifdef HAVE_HAL
- g_signal_handlers_disconnect_by_func (priv->hal,
+ g_signal_handlers_disconnect_by_func (priv->hal_power,
notify_battery_in_use_cb,
TRACKER_INDEXER (object));
- g_object_unref (priv->hal);
+ g_object_unref (priv->hal_power);
+ g_object_unref (priv->hal_storage);
#endif /* HAVE_HAL */
g_object_unref (priv->language);
@@ -968,9 +971,10 @@ tracker_indexer_init (TrackerIndexer *indexer)
priv->config = tracker_config_new ();
#ifdef HAVE_HAL
- priv->hal = tracker_hal_new ();
+ priv->hal_power = tracker_power_new ();
+ priv->hal_storage = tracker_storage_new ();
- g_signal_connect (priv->hal, "notify::battery-in-use",
+ g_signal_connect (priv->hal_power, "notify::battery-in-use",
G_CALLBACK (notify_battery_in_use_cb),
indexer);
@@ -1120,8 +1124,8 @@ item_add_to_datasource (TrackerIndexer *indexer,
file = tracker_module_file_get_file (module_file);
#ifdef HAVE_HAL
- removable_device_udi = tracker_hal_get_volume_udi_for_file (indexer->private->hal,
- file);
+ removable_device_udi = tracker_storage_get_volume_udi_for_file (indexer->private->hal_storage,
+ file);
#else
removable_device_udi = NULL;
#endif
@@ -1220,10 +1224,10 @@ item_add_or_update (TrackerIndexer *indexer,
generate_item_thumbnail (indexer, uri);
#ifdef HAVE_HAL
- if (tracker_hal_uri_is_on_removable_device (indexer->private->hal,
- uri,
- &mount_point,
- NULL)) {
+ if (tracker_storage_uri_is_on_removable_device (indexer->private->hal_storage,
+ uri,
+ &mount_point,
+ NULL)) {
tracker_removable_device_add_metadata (indexer,
mount_point,
@@ -1330,14 +1334,14 @@ item_move (TrackerIndexer *indexer,
update_file_uri_recursively (source_uri, uri);
#ifdef HAVE_HAL
- if (tracker_hal_uri_is_on_removable_device (indexer->private->hal,
- source_uri,
- &mount_point,
- NULL) ) {
- if (tracker_hal_uri_is_on_removable_device (indexer->private->hal,
- uri,
- NULL,
- NULL) ) {
+ if (tracker_storage_uri_is_on_removable_device (indexer->private->hal_storage,
+ source_uri,
+ &mount_point,
+ NULL) ) {
+ if (tracker_storage_uri_is_on_removable_device (indexer->private->hal_storage,
+ uri,
+ NULL,
+ NULL) ) {
tracker_removable_device_add_move (indexer,
mount_point,
@@ -1436,10 +1440,10 @@ item_remove (TrackerIndexer *indexer,
}*/
#ifdef HAVE_HAL
- if (tracker_hal_uri_is_on_removable_device (indexer->private->hal,
- uri,
- &mount_point,
- NULL)) {
+ if (tracker_storage_uri_is_on_removable_device (indexer->private->hal_storage,
+ uri,
+ &mount_point,
+ NULL)) {
tracker_removable_device_add_removal (indexer, mount_point, uri);
}
diff --git a/src/trackerd/tracker-main.c b/src/trackerd/tracker-main.c
index 5b986b7..ea6d20f 100644
--- a/src/trackerd/tracker-main.c
+++ b/src/trackerd/tracker-main.c
@@ -44,7 +44,8 @@
#include <libtracker-common/tracker-config.h>
#include <libtracker-common/tracker-file-utils.h>
-#include <libtracker-common/tracker-hal.h>
+#include <libtracker-common/tracker-power.h>
+#include <libtracker-common/tracker-storage.h>
#include <libtracker-common/tracker-ioprio.h>
#include <libtracker-common/tracker-language.h>
#include <libtracker-common/tracker-log.h>
@@ -226,7 +227,7 @@ get_lock_file (void)
static TrackerRunningLevel
check_runtime_level (TrackerConfig *config,
- TrackerHal *hal)
+ TrackerPower *hal)
{
TrackerRunningLevel runlevel;
gchar *lock_file;
@@ -275,8 +276,8 @@ check_runtime_level (TrackerConfig *config,
runlevel = TRACKER_RUNNING_MAIN_INSTANCE;
#ifdef HAVE_HAL
- if (!tracker_hal_get_battery_exists (hal) ||
- !tracker_hal_get_battery_in_use (hal)) {
+ if (!tracker_power_get_battery_exists (hal) ||
+ !tracker_power_get_battery_in_use (hal)) {
return TRACKER_RUNNING_MAIN_INSTANCE;
}
@@ -329,10 +330,10 @@ mount_point_set_cb (DBusGProxy *proxy,
}
static void
-mount_point_added_cb (TrackerHal *hal,
- const gchar *udi,
- const gchar *mount_point,
- gpointer user_data)
+mount_point_added_cb (TrackerStorage *hal,
+ const gchar *udi,
+ const gchar *mount_point,
+ gpointer user_data)
{
TrackerMainPrivate *private;
@@ -377,10 +378,10 @@ mount_point_set_and_signal_cb (DBusGProxy *proxy,
}
static void
-mount_point_removed_cb (TrackerHal *hal,
- const gchar *udi,
- const gchar *mount_point,
- gpointer user_data)
+mount_point_removed_cb (TrackerStorage *hal,
+ const gchar *udi,
+ const gchar *mount_point,
+ gpointer user_data)
{
TrackerMainPrivate *private;
@@ -749,7 +750,7 @@ set_up_mount_points_cb (DBusGProxy *proxy,
GError *error,
gpointer user_data)
{
- TrackerHal *hal;
+ TrackerStorage *hal;
GList *roots, *l;
if (error) {
@@ -762,7 +763,7 @@ set_up_mount_points_cb (DBusGProxy *proxy,
g_message ("Indexer is being notified about ALL UDIs");
hal = user_data;
- roots = tracker_hal_get_removable_device_udis (hal);
+ roots = tracker_storage_get_removable_device_udis (hal);
for (l = roots; l; l = l->next) {
gchar *udi;
@@ -770,8 +771,8 @@ set_up_mount_points_cb (DBusGProxy *proxy,
gboolean is_mounted;
udi = l->data;
- mount_point = tracker_hal_udi_get_mount_point (hal, udi);
- is_mounted = tracker_hal_udi_get_is_mounted (hal, udi);
+ mount_point = tracker_storage_udi_get_mount_point (hal, udi);
+ is_mounted = tracker_storage_udi_get_is_mounted (hal, udi);
g_message (" %s", udi);
@@ -787,7 +788,7 @@ set_up_mount_points_cb (DBusGProxy *proxy,
}
static void
-set_up_mount_points (TrackerHal *hal)
+set_up_mount_points (TrackerStorage *hal)
{
g_message ("Indexer is being notified to disable all volumes");
org_freedesktop_Tracker_Indexer_volume_disable_all_async (tracker_dbus_indexer_get_proxy (),
@@ -823,7 +824,8 @@ main (gint argc, gchar *argv[])
TrackerMainPrivate *private;
TrackerConfig *config;
TrackerLanguage *language;
- TrackerHal *hal;
+ TrackerPower *hal_power;
+ TrackerStorage *hal_storage;
TrackerRunningLevel runtime_level;
TrackerDBManagerFlags flags = 0;
gboolean is_first_time_index;
@@ -948,17 +950,18 @@ main (gint argc, gchar *argv[])
tracker_nfs_lock_init (tracker_config_get_nfs_locking (config));
#ifdef HAVE_HAL
- hal = tracker_hal_new ();
+ hal_power = tracker_power_new ();
+ hal_storage = tracker_storage_new ();
- g_signal_connect (hal, "mount-point-added",
+ g_signal_connect (hal_storage, "mount-point-added",
G_CALLBACK (mount_point_added_cb),
NULL);
- g_signal_connect (hal, "mount-point-removed",
+ g_signal_connect (hal_storage, "mount-point-removed",
G_CALLBACK (mount_point_removed_cb),
NULL);
#endif /* HAVE_HAL */
- tracker_status_init (config, hal);
+ tracker_status_init (config, hal_power);
tracker_module_config_init ();
@@ -985,7 +988,7 @@ main (gint argc, gchar *argv[])
/*
* Check instances running
*/
- runtime_level = check_runtime_level (config, hal);
+ runtime_level = check_runtime_level (config, hal_power);
switch (runtime_level) {
case TRACKER_RUNNING_NON_ALLOWED:
@@ -1014,10 +1017,10 @@ main (gint argc, gchar *argv[])
* we have to have already initialised the databases if we
* are going to do that.
*/
- set_up_mount_points (hal);
+ set_up_mount_points (hal_storage);
#endif /* HAVE_HAL */
- private->processor = tracker_processor_new (config, hal);
+ private->processor = tracker_processor_new (config, hal_storage);
/* Make Tracker available for introspection */
if (!tracker_dbus_register_objects (config,
@@ -1102,14 +1105,15 @@ main (gint argc, gchar *argv[])
tracker_log_shutdown ();
#ifdef HAVE_HAL
- g_signal_handlers_disconnect_by_func (hal,
+ g_signal_handlers_disconnect_by_func (hal_storage,
mount_point_added_cb,
NULL);
- g_signal_handlers_disconnect_by_func (hal,
+ g_signal_handlers_disconnect_by_func (hal_storage,
mount_point_removed_cb,
NULL);
- g_object_unref (hal);
+ g_object_unref (hal_power);
+ g_object_unref (hal_storage);
#endif /* HAVE_HAL */
g_object_unref (language);
diff --git a/src/trackerd/tracker-processor.c b/src/trackerd/tracker-processor.c
index f503ffd..750a23d 100644
--- a/src/trackerd/tracker-processor.c
+++ b/src/trackerd/tracker-processor.c
@@ -24,7 +24,7 @@
#include <libtracker-common/tracker-dbus.h>
#include <libtracker-common/tracker-file-utils.h>
-#include <libtracker-common/tracker-hal.h>
+#include <libtracker-common/tracker-storage.h>
#include <libtracker-common/tracker-module-config.h>
#include <libtracker-common/tracker-utils.h>
@@ -56,7 +56,7 @@ typedef enum {
struct TrackerProcessorPrivate {
TrackerConfig *config;
- TrackerHal *hal;
+ TrackerStorage *hal;
TrackerMonitor *monitor;
DBusGProxy *indexer_proxy;
@@ -163,11 +163,11 @@ static void crawler_finished_cb (TrackerCrawler *crawler,
gpointer user_data);
#ifdef HAVE_HAL
-static void mount_point_added_cb (TrackerHal *hal,
+static void mount_point_added_cb (TrackerStorage *hal,
const gchar *volume_uuid,
const gchar *mount_point,
gpointer user_data);
-static void mount_point_removed_cb (TrackerHal *hal,
+static void mount_point_removed_cb (TrackerStorage *hal,
const gchar *volume_uuid,
const gchar *mount_point,
gpointer user_data);
@@ -358,8 +358,8 @@ get_remote_roots (TrackerProcessor *processor,
GList *l2;
#ifdef HAVE_HAL
- l1 = tracker_hal_get_mounted_directory_roots (processor->private->hal);
- l2 = tracker_hal_get_removable_device_roots (processor->private->hal);
+ l1 = tracker_storage_get_mounted_directory_roots (processor->private->hal);
+ l2 = tracker_storage_get_removable_device_roots (processor->private->hal);
#else /* HAVE_HAL */
l1 = NULL;
l2 = NULL;
@@ -1502,7 +1502,7 @@ crawler_finished_cb (TrackerCrawler *crawler,
#ifdef HAVE_HAL
static void
-mount_point_added_cb (TrackerHal *hal,
+mount_point_added_cb (TrackerStorage *hal,
const gchar *udi,
const gchar *mount_point,
gpointer user_data)
@@ -1550,7 +1550,7 @@ mount_point_added_cb (TrackerHal *hal,
}
static void
-mount_point_removed_cb (TrackerHal *hal,
+mount_point_removed_cb (TrackerStorage *hal,
const gchar *udi,
const gchar *mount_point,
gpointer user_data)
@@ -1597,8 +1597,8 @@ mount_point_removed_cb (TrackerHal *hal,
#endif /* HAVE_HAL */
TrackerProcessor *
-tracker_processor_new (TrackerConfig *config,
- TrackerHal *hal)
+tracker_processor_new (TrackerConfig *config,
+ TrackerStorage *hal)
{
TrackerProcessor *processor;
TrackerProcessorPrivate *priv;
@@ -1609,7 +1609,7 @@ tracker_processor_new (TrackerConfig *config,
g_return_val_if_fail (TRACKER_IS_CONFIG (config), NULL);
#ifdef HAVE_HAL
- g_return_val_if_fail (TRACKER_IS_HAL (hal), NULL);
+ g_return_val_if_fail (TRACKER_IS_STORAGE (hal), NULL);
#endif /* HAVE_HAL */
tracker_status_set_and_signal (TRACKER_STATUS_INITIALIZING);
@@ -1624,7 +1624,7 @@ tracker_processor_new (TrackerConfig *config,
/* Set up hal */
priv->hal = g_object_ref (hal);
- priv->removable_devices = tracker_hal_get_removable_device_roots (priv->hal);
+ priv->removable_devices = tracker_storage_get_removable_device_roots (priv->hal);
priv->removable_devices_current = priv->removable_devices;
priv->removable_devices_completed = NULL;
diff --git a/src/trackerd/tracker-processor.h b/src/trackerd/tracker-processor.h
index d90af73..45900bd 100644
--- a/src/trackerd/tracker-processor.h
+++ b/src/trackerd/tracker-processor.h
@@ -25,7 +25,7 @@
#include <gio/gio.h>
#include <libtracker-common/tracker-config.h>
-#include <libtracker-common/tracker-hal.h>
+#include <libtracker-common/tracker-storage.h>
G_BEGIN_DECLS
@@ -54,7 +54,7 @@ struct TrackerProcessorClass {
GType tracker_processor_get_type (void) G_GNUC_CONST;
TrackerProcessor *tracker_processor_new (TrackerConfig *config,
- TrackerHal *hal);
+ TrackerStorage *hal);
void tracker_processor_start (TrackerProcessor *processor);
void tracker_processor_stop (TrackerProcessor *processor);
diff --git a/src/trackerd/tracker-status.c b/src/trackerd/tracker-status.c
index fc6e2e7..5eaf4f9 100644
--- a/src/trackerd/tracker-status.c
+++ b/src/trackerd/tracker-status.c
@@ -50,7 +50,7 @@ typedef struct {
gint cpu_priority;
TrackerConfig *config;
- TrackerHal *hal;
+ TrackerPower *hal;
DBusGProxy *indexer_proxy;
@@ -370,6 +370,14 @@ disk_space_check_stop (void)
}
}
+static void
+low_disk_space_limit_cb (GObject *gobject,
+ GParamSpec *arg1,
+ gpointer user_data)
+{
+ disk_space_check_cb (NULL);
+}
+
#ifdef HAVE_HAL
static void
@@ -387,7 +395,7 @@ set_up_throttle (gboolean debugging)
*/
throttle = tracker_config_get_throttle (private->config);
- if (tracker_hal_get_battery_in_use (private->hal)) {
+ if (tracker_power_get_battery_in_use (private->hal)) {
if (debugging) {
g_message ("We are running on battery");
}
@@ -431,14 +439,6 @@ set_up_throttle (gboolean debugging)
}
static void
-low_disk_space_limit_cb (GObject *gobject,
- GParamSpec *arg1,
- gpointer user_data)
-{
- disk_space_check_cb (NULL);
-}
-
-static void
battery_in_use_cb (GObject *gobject,
GParamSpec *arg1,
gpointer user_data)
@@ -458,8 +458,8 @@ battery_percentage_cb (GObject *object,
private = g_static_private_get (&private_key);
g_return_if_fail (private != NULL);
- percentage = tracker_hal_get_battery_percentage (private->hal);
- battery_in_use = tracker_hal_get_battery_in_use (private->hal);
+ percentage = tracker_power_get_battery_percentage (private->hal);
+ battery_in_use = tracker_power_get_battery_in_use (private->hal);
g_message ("Battery percentage is now %.0f%%",
percentage * 100);
@@ -483,7 +483,7 @@ battery_percentage_cb (GObject *object,
gboolean
tracker_status_init (TrackerConfig *config,
- TrackerHal *hal)
+ TrackerPower *hal)
{
GType type;
DBusGProxy *proxy;
diff --git a/src/trackerd/tracker-status.h b/src/trackerd/tracker-status.h
index cd05634..8c86fb7 100644
--- a/src/trackerd/tracker-status.h
+++ b/src/trackerd/tracker-status.h
@@ -25,7 +25,7 @@
#include <glib-object.h>
#include <libtracker-common/tracker-config.h>
-#include <libtracker-common/tracker-hal.h>
+#include <libtracker-common/tracker-power.h>
G_BEGIN_DECLS
@@ -44,7 +44,7 @@ typedef enum {
gboolean tracker_status_init (TrackerConfig *config,
- TrackerHal *hal);
+ TrackerPower *hal);
void tracker_status_shutdown (void);
gboolean tracker_status_is_initialized (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]