summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-08-01 12:07:56 +0100
committerRichard Hughes <richard@hughsie.com>2008-08-01 12:07:56 +0100
commit4f934ad2dfa319c9bdfe0706442833df95cc1129 (patch)
tree02abd7f403330dc6167889bef9f8688ab6cee644 /src
parentcbaa6851d4e5c69a9b797c9379446388a989b4b0 (diff)
convert spaces to tabs, and make sure functions have sensible names
Diffstat (limited to 'src')
-rw-r--r--src/dkp-daemon.c1095
-rw-r--r--src/dkp-daemon.h63
-rw-r--r--src/dkp-device.c49
-rw-r--r--src/dkp-device.h43
-rw-r--r--src/dkp-enum.c164
-rw-r--r--src/dkp-enum.h50
-rw-r--r--src/dkp-source.c1213
-rw-r--r--src/dkp-source.h29
-rw-r--r--src/main.c176
-rw-r--r--src/sysfs-utils.c244
10 files changed, 1624 insertions, 1502 deletions
diff --git a/src/dkp-daemon.c b/src/dkp-daemon.c
index b4da9e6..8e1a0a9 100644
--- a/src/dkp-daemon.c
+++ b/src/dkp-daemon.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
*
@@ -41,33 +41,33 @@
enum
{
- DEVICE_ADDED_SIGNAL,
- DEVICE_REMOVED_SIGNAL,
- DEVICE_CHANGED_SIGNAL,
- ON_BATTERY_CHANGED_SIGNAL,
- LOW_BATTERY_CHANGED_SIGNAL,
- LAST_SIGNAL,
+ DEVICE_ADDED_SIGNAL,
+ DEVICE_REMOVED_SIGNAL,
+ DEVICE_CHANGED_SIGNAL,
+ ON_BATTERY_CHANGED_SIGNAL,
+ LOW_BATTERY_CHANGED_SIGNAL,
+ LAST_SIGNAL,
};
static guint signals[LAST_SIGNAL] = { 0 };
struct DkpDaemonPrivate
{
- DBusGConnection *system_bus_connection;
- DBusGProxy *system_bus_proxy;
- PolKitContext *pk_context;
- PolKitTracker *pk_tracker;
+ DBusGConnection *system_bus_connection;
+ DBusGProxy *system_bus_proxy;
+ PolKitContext *pk_context;
+ PolKitTracker *pk_tracker;
- GHashTable *map_native_path_to_device;
- gboolean on_battery;
- gboolean low_battery;
+ GHashTable *map_native_path_to_device;
+ gboolean on_battery;
+ gboolean low_battery;
- DevkitClient *devkit_client;
+ DevkitClient *devkit_client;
};
-static void dkp_daemon_class_init (DkpDaemonClass *klass);
-static void dkp_daemon_init (DkpDaemon *seat);
-static void dkp_daemon_finalize (GObject *object);
+static void dkp_daemon_class_init (DkpDaemonClass *klass);
+static void dkp_daemon_init (DkpDaemon *seat);
+static void dkp_daemon_finalize (GObject *object);
G_DEFINE_TYPE (DkpDaemon, dkp_daemon, G_TYPE_OBJECT)
@@ -75,391 +75,427 @@ G_DEFINE_TYPE (DkpDaemon, dkp_daemon, G_TYPE_OBJECT)
/*--------------------------------------------------------------------------------------------------------------*/
+/**
+ * dkp_daemon_error_quark:
+ **/
GQuark
dkp_daemon_error_quark (void)
{
- static GQuark ret = 0;
+ static GQuark ret = 0;
- if (ret == 0) {
- ret = g_quark_from_static_string ("dkp_daemon_error");
- }
+ if (ret == 0) {
+ ret = g_quark_from_static_string ("dkp_daemon_error");
+ }
- return ret;
+ return ret;
}
-
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+/**
+ * dkp_daemon_error_get_type:
+ **/
GType
dkp_daemon_error_get_type (void)
{
- static GType etype = 0;
-
- if (etype == 0)
- {
- static const GEnumValue values[] =
- {
- ENUM_ENTRY (DKP_DAEMON_ERROR_GENERAL, "GeneralError"),
- ENUM_ENTRY (DKP_DAEMON_ERROR_NOT_SUPPORTED, "NotSupported"),
- ENUM_ENTRY (DKP_DAEMON_ERROR_NO_SUCH_DEVICE, "NoSuchDevice"),
- { 0, 0, 0 }
- };
- g_assert (DKP_DAEMON_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
- etype = g_enum_register_static ("DkpDaemonError", values);
- }
- return etype;
+ static GType etype = 0;
+
+ if (etype == 0)
+ {
+ static const GEnumValue values[] =
+ {
+ ENUM_ENTRY (DKP_DAEMON_ERROR_GENERAL, "GeneralError"),
+ ENUM_ENTRY (DKP_DAEMON_ERROR_NOT_SUPPORTED, "NotSupported"),
+ ENUM_ENTRY (DKP_DAEMON_ERROR_NO_SUCH_DEVICE, "NoSuchDevice"),
+ { 0, 0, 0 }
+ };
+ g_assert (DKP_DAEMON_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
+ etype = g_enum_register_static ("DkpDaemonError", values);
+ }
+ return etype;
}
-
+/**
+ * dkp_daemon_constructor:
+ **/
static GObject *
-dkp_daemon_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_properties)
+dkp_daemon_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties)
{
- DkpDaemon *daemon;
- DkpDaemonClass *klass;
-
- klass = DKP_DAEMON_CLASS (g_type_class_peek (DKP_SOURCE_TYPE_DAEMON));
+ DkpDaemon *daemon;
+ DkpDaemonClass *klass;
- daemon = DKP_DAEMON (
- G_OBJECT_CLASS (dkp_daemon_parent_class)->constructor (type,
- n_construct_properties,
- construct_properties));
- return G_OBJECT (daemon);
+ klass = DKP_DAEMON_CLASS (g_type_class_peek (DKP_SOURCE_TYPE_DAEMON));
+ daemon = DKP_DAEMON (G_OBJECT_CLASS (dkp_daemon_parent_class)->constructor (type, n_construct_properties, construct_properties));
+ return G_OBJECT (daemon);
}
+/**
+ * dkp_daemon_class_init:
+ **/
static void
dkp_daemon_class_init (DkpDaemonClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->constructor = dkp_daemon_constructor;
- object_class->finalize = dkp_daemon_finalize;
-
- g_type_class_add_private (klass, sizeof (DkpDaemonPrivate));
-
- signals[DEVICE_ADDED_SIGNAL] =
- g_signal_new ("device-added",
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- signals[DEVICE_REMOVED_SIGNAL] =
- g_signal_new ("device-removed",
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- signals[DEVICE_CHANGED_SIGNAL] =
- g_signal_new ("device-changed",
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- signals[ON_BATTERY_CHANGED_SIGNAL] =
- g_signal_new ("on-battery-changed",
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
-
- signals[LOW_BATTERY_CHANGED_SIGNAL] =
- g_signal_new ("low-battery-changed",
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
-
- dbus_g_object_type_install_info (DKP_SOURCE_TYPE_DAEMON, &dbus_glib_dkp_daemon_object_info);
-
- dbus_g_error_domain_register (DKP_DAEMON_ERROR,
- NULL,
- DKP_DAEMON_TYPE_ERROR);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->constructor = dkp_daemon_constructor;
+ object_class->finalize = dkp_daemon_finalize;
+
+ g_type_class_add_private (klass, sizeof (DkpDaemonPrivate));
+
+ signals[DEVICE_ADDED_SIGNAL] =
+ g_signal_new ("device-added",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+
+ signals[DEVICE_REMOVED_SIGNAL] =
+ g_signal_new ("device-removed",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+
+ signals[DEVICE_CHANGED_SIGNAL] =
+ g_signal_new ("device-changed",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+
+ signals[ON_BATTERY_CHANGED_SIGNAL] =
+ g_signal_new ("on-battery-changed",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ signals[LOW_BATTERY_CHANGED_SIGNAL] =
+ g_signal_new ("low-battery-changed",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ dbus_g_object_type_install_info (DKP_SOURCE_TYPE_DAEMON, &dbus_glib_dkp_daemon_object_info);
+
+ dbus_g_error_domain_register (DKP_DAEMON_ERROR, NULL, DKP_DAEMON_TYPE_ERROR);
}
+/**
+ * dkp_daemon_init:
+ **/
static void
dkp_daemon_init (DkpDaemon *daemon)
{
- daemon->priv = DKP_DAEMON_GET_PRIVATE (daemon);
- daemon->priv->on_battery = FALSE;
- daemon->priv->low_battery = FALSE;
- daemon->priv->map_native_path_to_device = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- NULL);
+ daemon->priv = DKP_DAEMON_GET_PRIVATE (daemon);
+ daemon->priv->on_battery = FALSE;
+ daemon->priv->low_battery = FALSE;
+ daemon->priv->map_native_path_to_device = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
}
+/**
+ * dkp_daemon_finalize:
+ **/
static void
dkp_daemon_finalize (GObject *object)
{
- DkpDaemon *daemon;
+ DkpDaemon *daemon;
- g_return_if_fail (object != NULL);
- g_return_if_fail (DKP_IS_DAEMON (object));
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (DKP_IS_DAEMON (object));
- daemon = DKP_DAEMON (object);
+ daemon = DKP_DAEMON (object);
- g_return_if_fail (daemon->priv != NULL);
+ g_return_if_fail (daemon->priv != NULL);
- if (daemon->priv->pk_context != NULL)
- polkit_context_unref (daemon->priv->pk_context);
+ if (daemon->priv->pk_context != NULL)
+ polkit_context_unref (daemon->priv->pk_context);
- if (daemon->priv->pk_tracker != NULL)
- polkit_tracker_unref (daemon->priv->pk_tracker);
+ if (daemon->priv->pk_tracker != NULL)
+ polkit_tracker_unref (daemon->priv->pk_tracker);
- if (daemon->priv->system_bus_proxy != NULL)
- g_object_unref (daemon->priv->system_bus_proxy);
+ if (daemon->priv->system_bus_proxy != NULL)
+ g_object_unref (daemon->priv->system_bus_proxy);
- if (daemon->priv->system_bus_connection != NULL)
- dbus_g_connection_unref (daemon->priv->system_bus_connection);
+ if (daemon->priv->system_bus_connection != NULL)
+ dbus_g_connection_unref (daemon->priv->system_bus_connection);
- if (daemon->priv->devkit_client != NULL) {
- g_object_unref (daemon->priv->devkit_client);
- }
+ if (daemon->priv->devkit_client != NULL)
+ g_object_unref (daemon->priv->devkit_client);
- if (daemon->priv->map_native_path_to_device != NULL) {
- g_hash_table_unref (daemon->priv->map_native_path_to_device);
- }
+ if (daemon->priv->map_native_path_to_device != NULL)
+ g_hash_table_unref (daemon->priv->map_native_path_to_device);
- G_OBJECT_CLASS (dkp_daemon_parent_class)->finalize (object);
+ G_OBJECT_CLASS (dkp_daemon_parent_class)->finalize (object);
}
+/**
+ * pk_io_watch_have_data:
+ **/
static gboolean
pk_io_watch_have_data (GIOChannel *channel, GIOCondition condition, gpointer user_data)
{
- int fd;
- PolKitContext *pk_context = user_data;
- fd = g_io_channel_unix_get_fd (channel);
- polkit_context_io_func (pk_context, fd);
- return TRUE;
+ int fd;
+ PolKitContext *pk_context = user_data;
+ fd = g_io_channel_unix_get_fd (channel);
+ polkit_context_io_func (pk_context, fd);
+ return TRUE;
}
+/**
+ * pk_io_add_watch:
+ **/
static int
pk_io_add_watch (PolKitContext *pk_context, int fd)
{
- guint id = 0;
- GIOChannel *channel;
- channel = g_io_channel_unix_new (fd);
- if (channel == NULL)
- goto out;
- id = g_io_add_watch (channel, G_IO_IN, pk_io_watch_have_data, pk_context);
- if (id == 0) {
- g_io_channel_unref (channel);
- goto out;
- }
- g_io_channel_unref (channel);
+ guint id = 0;
+ GIOChannel *channel;
+ channel = g_io_channel_unix_new (fd);
+ if (channel == NULL)
+ goto out;
+ id = g_io_add_watch (channel, G_IO_IN, pk_io_watch_have_data, pk_context);
+ if (id == 0) {
+ g_io_channel_unref (channel);
+ goto out;
+ }
+ g_io_channel_unref (channel);
out:
- return id;
+ return id;
}
+/**
+ * pk_io_remove_watch:
+ **/
static void
pk_io_remove_watch (PolKitContext *pk_context, int watch_id)
{
- g_source_remove (watch_id);
+ g_source_remove (watch_id);
}
+/**
+ * gpk_daemon_dbus_filter:
+ **/
static DBusHandlerResult
-_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
+gpk_daemon_dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
{
- DkpDaemon *daemon = DKP_DAEMON (user_data);
- const char *interface;
+ DkpDaemon *daemon = DKP_DAEMON (user_data);
+ const char *interface;
- interface = dbus_message_get_interface (message);
+ interface = dbus_message_get_interface (message);
- if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
- /* pass NameOwnerChanged signals from the bus to PolKitTracker */
- polkit_tracker_dbus_func (daemon->priv->pk_tracker, message);
- }
+ if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
+ /* pass NameOwnerChanged signals from the bus to PolKitTracker */
+ polkit_tracker_dbus_func (daemon->priv->pk_tracker, message);
+ }
- if (interface != NULL && g_str_has_prefix (interface, "org.freedesktop.ConsoleKit")) {
- /* pass ConsoleKit signals to PolKitTracker */
- polkit_tracker_dbus_func (daemon->priv->pk_tracker, message);
- }
+ if (interface != NULL && g_str_has_prefix (interface, "org.freedesktop.ConsoleKit")) {
+ /* pass ConsoleKit signals to PolKitTracker */
+ polkit_tracker_dbus_func (daemon->priv->pk_tracker, message);
+ }
- /* other filters might want to process this message too */
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ /* other filters might want to process this message too */
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static void device_add (DkpDaemon *daemon, DevkitDevice *d, gboolean emit_event);
-static void device_remove (DkpDaemon *daemon, DevkitDevice *d);
+static void gpk_daemon_device_add (DkpDaemon *daemon, DevkitDevice *d, gboolean emit_event);
+static void gpk_daemon_device_remove (DkpDaemon *daemon, DevkitDevice *d);
+/**
+ * gpk_daemon_device_changed:
+ **/
static void
-device_changed (DkpDaemon *daemon, DevkitDevice *d, gboolean synthesized)
+gpk_daemon_device_changed (DkpDaemon *daemon, DevkitDevice *d, gboolean synthesized)
{
- DkpDevice *device;
- const char *native_path;
-
- native_path = devkit_device_get_native_path (d);
- device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
- if (device != NULL) {
- if (!dkp_device_changed (device, d, synthesized)) {
- g_print ("changed triggered remove on %s\n", native_path);
- device_remove (daemon, d);
- } else {
- g_print ("changed %s\n", native_path);
- }
- } else {
- g_print ("treating change event as add on %s\n", native_path);
- device_add (daemon, d, TRUE);
- }
+ DkpDevice *device;
+ const char *native_path;
+
+ native_path = devkit_device_get_native_path (d);
+ device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
+ if (device != NULL) {
+ if (!dkp_device_changed (device, d, synthesized)) {
+ g_print ("changed triggered remove on %s\n", native_path);
+ gpk_daemon_device_remove (daemon, d);
+ } else {
+ g_print ("changed %s\n", native_path);
+ }
+ } else {
+ g_print ("treating change event as add on %s\n", native_path);
+ gpk_daemon_device_add (daemon, d, TRUE);
+ }
}
+/**
+ * gpk_daemon_device_went_away_remove_cb:
+ **/
static gboolean
-device_went_away_remove_cb (gpointer key, gpointer value, gpointer user_data)
+gpk_daemon_device_went_away_remove_cb (gpointer key, gpointer value, gpointer user_data)
{
- if (value == user_data) {
- g_print ("removed %s\n", (char *) key);
- return TRUE;
- }
- return FALSE;
+ if (value == user_data) {
+ g_print ("removed %s\n", (char *) key);
+ return TRUE;
+ }
+ return FALSE;
}
+/**
+ * gpk_daemon_device_went_away:
+ **/
static void
-device_went_away (gpointer user_data, GObject *where_the_object_was)
+gpk_daemon_device_went_away (gpointer user_data, GObject *where_the_object_was)
{
- DkpDaemon *daemon = DKP_DAEMON (user_data);
+ DkpDaemon *daemon = DKP_DAEMON (user_data);
- g_hash_table_foreach_remove (daemon->priv->map_native_path_to_device,
- device_went_away_remove_cb,
- where_the_object_was);
+ g_hash_table_foreach_remove (daemon->priv->map_native_path_to_device,
+ gpk_daemon_device_went_away_remove_cb,
+ where_the_object_was);
}
+/**
+ * gpk_daemon_device_add:
+ **/
static void
-device_add (DkpDaemon *daemon, DevkitDevice *d, gboolean emit_event)
+gpk_daemon_device_add (DkpDaemon *daemon, DevkitDevice *d, gboolean emit_event)
{
- DkpDevice *device;
- const char *native_path;
-
- native_path = devkit_device_get_native_path (d);
- device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
- if (device != NULL) {
- /* we already have the device; treat as change event */
- g_print ("treating add event as change event on %s\n", native_path);
- device_changed (daemon, d, FALSE);
- } else {
- device = dkp_device_new (daemon, d);
-
- if (device != NULL) {
- /* only take a weak ref; the device will stay on the bus until
- * it's unreffed. So if we ref it, it'll never go away. Stupid
- * dbus-glib, no cookie for you.
- */
- g_object_weak_ref (G_OBJECT (device), device_went_away, daemon);
- g_hash_table_insert (daemon->priv->map_native_path_to_device,
- g_strdup (native_path),
- device);
- g_print ("added %s\n", native_path);
- if (emit_event) {
- g_signal_emit (daemon, signals[DEVICE_ADDED_SIGNAL], 0,
- dkp_device_get_object_path (device));
- }
- } else {
- g_print ("ignoring add event on %s\n", native_path);
- }
- }
+ DkpDevice *device;
+ const char *native_path;
+
+ native_path = devkit_device_get_native_path (d);
+ device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
+ if (device != NULL) {
+ /* we already have the device; treat as change event */
+ g_print ("treating add event as change event on %s\n", native_path);
+ gpk_daemon_device_changed (daemon, d, FALSE);
+ } else {
+ device = dkp_device_new (daemon, d);
+
+ if (device != NULL) {
+ /* only take a weak ref; the device will stay on the bus until
+ * it's unreffed. So if we ref it, it'll never go away. Stupid
+ * dbus-glib, no cookie for you.
+ */
+ g_object_weak_ref (G_OBJECT (device), gpk_daemon_device_went_away, daemon);
+ g_hash_table_insert (daemon->priv->map_native_path_to_device,
+ g_strdup (native_path),
+ device);
+ g_print ("added %s\n", native_path);
+ if (emit_event) {
+ g_signal_emit (daemon, signals[DEVICE_ADDED_SIGNAL], 0,
+ dkp_device_get_object_path (device));
+ }
+ } else {
+ g_print ("ignoring add event on %s\n", native_path);
+ }
+ }
}
+/**
+ * gpk_daemon_device_remove:
+ **/
static void
-device_remove (DkpDaemon *daemon, DevkitDevice *d)
+gpk_daemon_device_remove (DkpDaemon *daemon, DevkitDevice *d)
{
- DkpDevice *device;
- const char *native_path;
-
- native_path = devkit_device_get_native_path (d);
- device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
- if (device == NULL) {
- g_print ("ignoring remove event on %s\n", native_path);
- } else {
- dkp_device_removed (device);
- g_signal_emit (daemon, signals[DEVICE_REMOVED_SIGNAL], 0,
- dkp_device_get_object_path (device));
- g_object_unref (device);
- }
+ DkpDevice *device;
+ const char *native_path;
+
+ native_path = devkit_device_get_native_path (d);
+ device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path);
+ if (device == NULL) {
+ g_print ("ignoring remove event on %s\n", native_path);
+ } else {
+ dkp_device_removed (device);
+ g_signal_emit (daemon, signals[DEVICE_REMOVED_SIGNAL], 0,
+ dkp_device_get_object_path (device));
+ g_object_unref (device);
+ }
}
//TODO: hook into the devices
//g_signal_emit (daemon, signals[ON_BATTERY_CHANGED_SIGNAL], 0, FALSE);
//g_signal_emit (daemon, signals[LOW_BATTERY_CHANGED_SIGNAL], 0, FALSE);
+/**
+ * gpk_daemon_device_event_signal_handler:
+ **/
static void
-device_event_signal_handler (DevkitClient *client,
- const char *action,
- DevkitDevice *device,
- gpointer user_data)
+gpk_daemon_device_event_signal_handler (DevkitClient *client,
+ const char *action,
+ DevkitDevice *device,
+ gpointer user_data)
{
- DkpDaemon *daemon = DKP_DAEMON (user_data);
-
- if (strcmp (action, "add") == 0) {
- device_add (daemon, device, TRUE);
- } else if (strcmp (action, "remove") == 0) {
- device_remove (daemon, device);
- } else if (strcmp (action, "change") == 0) {
- device_changed (daemon, device, FALSE);
- } else {
- g_warning ("unhandled action '%s' on %s", action, devkit_device_get_native_path (device));
- }
+ DkpDaemon *daemon = DKP_DAEMON (user_data);
+
+ if (strcmp (action, "add") == 0) {
+ gpk_daemon_device_add (daemon, device, TRUE);
+ } else if (strcmp (action, "remove") == 0) {
+ gpk_daemon_device_remove (daemon, device);
+ } else if (strcmp (action, "change") == 0) {
+ gpk_daemon_device_changed (daemon, device, FALSE);
+ } else {
+ g_warning ("unhandled action '%s' on %s", action, devkit_device_get_native_path (device));
+ }
}
+/**
+ * gpk_daemon_register_power_daemon:
+ **/
static gboolean
-register_power_daemon (DkpDaemon *daemon)
+gpk_daemon_register_power_daemon (DkpDaemon *daemon)
{
- DBusConnection *connection;
- DBusError dbus_error;
- GError *error = NULL;
- const char *subsystems[] = {"power_supply", NULL};
-
- daemon->priv->pk_context = polkit_context_new ();
- polkit_context_set_io_watch_functions (daemon->priv->pk_context, pk_io_add_watch, pk_io_remove_watch);
- if (!polkit_context_init (daemon->priv->pk_context, NULL)) {
- g_critical ("cannot initialize libpolkit");
- goto error;
- }
-
- error = NULL;
- daemon->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (daemon->priv->system_bus_connection == NULL) {
- if (error != NULL) {
- g_critical ("error getting system bus: %s", error->message);
- g_error_free (error);
- }
- goto error;
- }
- connection = dbus_g_connection_get_connection (daemon->priv->system_bus_connection);
-
- daemon->priv->pk_tracker = polkit_tracker_new ();
- polkit_tracker_set_system_bus_connection (daemon->priv->pk_tracker, connection);
- polkit_tracker_init (daemon->priv->pk_tracker);
-
- dbus_g_connection_register_g_object (daemon->priv->system_bus_connection, "/",
- G_OBJECT (daemon));
-
- daemon->priv->system_bus_proxy = dbus_g_proxy_new_for_name (daemon->priv->system_bus_connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
-
- /* TODO FIXME: I'm pretty sure dbus-glib blows in a way that
- * we can't say we're interested in all signals from all
- * members on all interfaces for a given service... So we do
- * this..
- */
-
- dbus_error_init (&dbus_error);
-
- /* need to listen to NameOwnerChanged */
+ DBusConnection *connection;
+ DBusError dbus_error;
+ GError *error = NULL;
+ const char *subsystems[] = {"power_supply", NULL};
+
+ daemon->priv->pk_context = polkit_context_new ();
+ polkit_context_set_io_watch_functions (daemon->priv->pk_context, pk_io_add_watch, pk_io_remove_watch);
+ if (!polkit_context_init (daemon->priv->pk_context, NULL)) {
+ g_critical ("cannot initialize libpolkit");
+ goto error;
+ }
+
+ error = NULL;
+ daemon->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (daemon->priv->system_bus_connection == NULL) {
+ if (error != NULL) {
+ g_critical ("error getting system bus: %s", error->message);
+ g_error_free (error);
+ }
+ goto error;
+ }
+ connection = dbus_g_connection_get_connection (daemon->priv->system_bus_connection);
+
+ daemon->priv->pk_tracker = polkit_tracker_new ();
+ polkit_tracker_set_system_bus_connection (daemon->priv->pk_tracker, connection);
+ polkit_tracker_init (daemon->priv->pk_tracker);
+
+ dbus_g_connection_register_g_object (daemon->priv->system_bus_connection, "/",
+ G_OBJECT (daemon));
+
+ daemon->priv->system_bus_proxy = dbus_g_proxy_new_for_name (daemon->priv->system_bus_connection,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS);
+
+ /* TODO FIXME: I'm pretty sure dbus-glib blows in a way that
+ * we can't say we're interested in all signals from all
+ * members on all interfaces for a given service... So we do
+ * this..
+ */
+
+ dbus_error_init (&dbus_error);
+
+ /* need to listen to NameOwnerChanged */
dbus_bus_add_match (connection,
"type='signal'"
",interface='"DBUS_INTERFACE_DBUS"'"
@@ -467,289 +503,300 @@ register_power_daemon (DkpDaemon *daemon)
",member='NameOwnerChanged'",
&dbus_error);
- if (dbus_error_is_set (&dbus_error)) {
- g_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- goto error;
- }
+ if (dbus_error_is_set (&dbus_error)) {
+ g_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
+ dbus_error_free (&dbus_error);
+ goto error;
+ }
- /* need to listen to ConsoleKit signals */
+ /* need to listen to ConsoleKit signals */
dbus_bus_add_match (connection,
"type='signal',sender='org.freedesktop.ConsoleKit'",
&dbus_error);
- if (dbus_error_is_set (&dbus_error)) {
- g_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- goto error;
- }
-
- if (!dbus_connection_add_filter (connection,
- _filter,
- daemon,
- NULL)) {
- g_warning ("Cannot add D-Bus filter: %s: %s", dbus_error.name, dbus_error.message);
- goto error;
- }
-
- /* connect to the DeviceKit daemon */
- daemon->priv->devkit_client = devkit_client_new (subsystems);
- if (!devkit_client_connect (daemon->priv->devkit_client, &error)) {
+ if (dbus_error_is_set (&dbus_error)) {
+ g_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
+ dbus_error_free (&dbus_error);
+ goto error;
+ }
+
+ if (!dbus_connection_add_filter (connection,
+ gpk_daemon_dbus_filter,
+ daemon,
+ NULL)) {
+ g_warning ("Cannot add D-Bus filter: %s: %s", dbus_error.name, dbus_error.message);
+ goto error;
+ }
+
+ /* connect to the DeviceKit daemon */
+ daemon->priv->devkit_client = devkit_client_new (subsystems);
+ if (!devkit_client_connect (daemon->priv->devkit_client, &error)) {
g_warning ("Couldn't open connection to DeviceKit daemon: %s", error->message);
- g_error_free (error);
- goto error;
- }
- g_signal_connect (daemon->priv->devkit_client, "device-event",
- G_CALLBACK (device_event_signal_handler), daemon);
+ g_error_free (error);
+ goto error;
+ }
+ g_signal_connect (daemon->priv->devkit_client, "device-event",
+ G_CALLBACK (gpk_daemon_device_event_signal_handler), daemon);
- return TRUE;
+ return TRUE;
error:
- return FALSE;
+ return FALSE;
}
-
+/**
+ * dkp_daemon_new:
+ **/
DkpDaemon *
dkp_daemon_new (void)
{
- DkpDaemon *daemon;
- GError *error = NULL;
- GList *devices;
- GList *l;
- const char *subsystems[] = {"power_supply", NULL};
-
- daemon = DKP_DAEMON (g_object_new (DKP_SOURCE_TYPE_DAEMON, NULL));
-
- if (!register_power_daemon (DKP_DAEMON (daemon))) {
- g_object_unref (daemon);
- return NULL;
- }
-
-
- devices = devkit_client_enumerate_by_subsystem (daemon->priv->devkit_client,
- subsystems,
- &error);
- if (error != NULL) {
- g_warning ("Cannot enumerate devices: %s", error->message);
- g_error_free (error);
- g_object_unref (daemon);
- return NULL;
- }
- for (l = devices; l != NULL; l = l->next) {
- DevkitDevice *device = l->data;
- device_add (daemon, device, FALSE);
- }
- g_list_foreach (devices, (GFunc) g_object_unref, NULL);
- g_list_free (devices);
-
- return daemon;
+ DkpDaemon *daemon;
+ GError *error = NULL;
+ GList *devices;
+ GList *l;
+ const char *subsystems[] = {"power_supply", NULL};
+
+ daemon = DKP_DAEMON (g_object_new (DKP_SOURCE_TYPE_DAEMON, NULL));
+
+ if (!gpk_daemon_register_power_daemon (DKP_DAEMON (daemon))) {
+ g_object_unref (daemon);
+ return NULL;
+ }
+
+ devices = devkit_client_enumerate_by_subsystem (daemon->priv->devkit_client,
+ subsystems,
+ &error);
+ if (error != NULL) {
+ g_warning ("Cannot enumerate devices: %s", error->message);
+ g_error_free (error);
+ g_object_unref (daemon);
+ return NULL;
+ }
+ for (l = devices; l != NULL; l = l->next) {
+ DevkitDevice *device = l->data;
+ gpk_daemon_device_add (daemon, device, FALSE);
+ }
+ g_list_foreach (devices, (GFunc) g_object_unref, NULL);
+ g_list_free (devices);
+
+ return daemon;
}
+/**
+ * dkp_daemon_local_get_caller_for_context:
+ **/
PolKitCaller *
-dkp_daemon_local_get_caller_for_context (DkpDaemon *daemon,
- DBusGMethodInvocation *context)
+dkp_daemon_local_get_caller_for_context (DkpDaemon *daemon, DBusGMethodInvocation *context)
{
- const char *sender;
- GError *error;
- DBusError dbus_error;
- PolKitCaller *pk_caller;
-
- sender = dbus_g_method_get_sender (context);
- dbus_error_init (&dbus_error);
- pk_caller = polkit_tracker_get_caller_from_dbus_name (daemon->priv->pk_tracker,
- sender,
- &dbus_error);
- if (pk_caller == NULL) {
- error = g_error_new (DKP_DAEMON_ERROR,
- DKP_DAEMON_ERROR_GENERAL,
- "Error getting information about caller: %s: %s",
- dbus_error.name, dbus_error.message);
- dbus_error_free (&dbus_error);
- dbus_g_method_return_error (context, error);
- g_error_free (error);
- return NULL;
- }
-
- return pk_caller;
+ const char *sender;
+ GError *error;
+ DBusError dbus_error;
+ PolKitCaller *pk_caller;
+
+ sender = dbus_g_method_get_sender (context);
+ dbus_error_init (&dbus_error);
+ pk_caller = polkit_tracker_get_caller_from_dbus_name (daemon->priv->pk_tracker,
+ sender,
+ &dbus_error);
+ if (pk_caller == NULL) {
+ error = g_error_new (DKP_DAEMON_ERROR,
+ DKP_DAEMON_ERROR_GENERAL,
+ "Error getting information about caller: %s: %s",
+ dbus_error.name, dbus_error.message);
+ dbus_error_free (&dbus_error);
+ dbus_g_method_return_error (context, error);
+ g_error_free (error);
+ return NULL;
+ }
+
+ return pk_caller;
}
+/**
+ * dkp_daemon_local_check_auth:
+ **/
gboolean
-dkp_daemon_local_check_auth (DkpDaemon *daemon,
- PolKitCaller *pk_caller,
- const char *action_id,
- DBusGMethodInvocation *context)
+dkp_daemon_local_check_auth (DkpDaemon *daemon, PolKitCaller *pk_caller, const char *action_id, DBusGMethodInvocation *context)
{
- gboolean ret;
- GError *error;
- DBusError d_error;
- PolKitAction *pk_action;
- PolKitResult pk_result;
-
- ret = FALSE;
-
- pk_action = polkit_action_new ();
- polkit_action_set_action_id (pk_action, action_id);
- pk_result = polkit_context_is_caller_authorized (daemon->priv->pk_context,
- pk_action,
- pk_caller,
- TRUE,
- NULL);
- if (pk_result == POLKIT_RESULT_YES) {
- ret = TRUE;
- } else {
-
- dbus_error_init (&d_error);
- polkit_dbus_error_generate (pk_action, pk_result, &d_error);
- error = NULL;
- dbus_set_g_error (&error, &d_error);
- dbus_g_method_return_error (context, error);
- g_error_free (error);
- dbus_error_free (&d_error);
- }
- polkit_action_unref (pk_action);
- return ret;
+ gboolean ret;
+ GError *error;
+ DBusError d_error;
+ PolKitAction *pk_action;
+ PolKitResult pk_result;
+
+ ret = FALSE;
+
+ pk_action = polkit_action_new ();
+ polkit_action_set_action_id (pk_action, action_id);
+ pk_result = polkit_context_is_caller_authorized (daemon->priv->pk_context, pk_action, pk_caller, TRUE, NULL);
+ if (pk_result == POLKIT_RESULT_YES) {
+ ret = TRUE;
+ } else {
+ dbus_error_init (&d_error);
+ polkit_dbus_error_generate (pk_action, pk_result, &d_error);
+ error = NULL;
+ dbus_set_g_error (&error, &d_error);
+ dbus_g_method_return_error (context, error);
+ g_error_free (error);
+ dbus_error_free (&d_error);
+ }
+ polkit_action_unref (pk_action);
+ return ret;
}
-
/*--------------------------------------------------------------------------------------------------------------*/
#if 0
+/**
+ * gpk_daemon_throw_error:
+ **/
static gboolean
-throw_error (DBusGMethodInvocation *context, int error_code, const char *format, ...)
+gpk_daemon_throw_error (DBusGMethodInvocation *context, int error_code, const char *format, ...)
{
- GError *error;
- va_list args;
- char *message;
-
- va_start (args, format);
- message = g_strdup_vprintf (format, args);
- va_end (args);
-
- error = g_error_new (DKP_DAEMON_ERROR,
- error_code,
- message);
- dbus_g_method_return_error (context, error);
- g_error_free (error);
- g_free (message);
- return TRUE;
+ GError *error;
+ va_list args;
+ char *message;
+
+ va_start (args, format);
+ message = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ error = g_error_new (DKP_DAEMON_ERROR,
+ error_code,
+ message);
+ dbus_g_method_return_error (context, error);
+ g_error_free (error);
+ g_free (message);
+ return TRUE;
}
#endif
/*--------------------------------------------------------------------------------------------------------------*/
/* exported methods */
+/**
+ * gpk_daemon_enumerate_cb:
+ **/
static void
-enumerate_cb (gpointer key, gpointer value, gpointer user_data)
+gpk_daemon_enumerate_cb (gpointer key, gpointer value, gpointer user_data)
{
- DkpDevice *device = DKP_DEVICE (value);
- GPtrArray *object_paths = user_data;
- g_ptr_array_add (object_paths, g_strdup (dkp_device_get_object_path (device)));
+ DkpDevice *device = DKP_DEVICE (value);
+ GPtrArray *object_paths = user_data;
+ g_ptr_array_add (object_paths, g_strdup (dkp_device_get_object_path (device)));
}
+/**
+ * dkp_daemon_enumerate_devices:
+ **/
gboolean
-dkp_daemon_enumerate_devices (DkpDaemon *daemon,
- DBusGMethodInvocation *context)
+dkp_daemon_enumerate_devices (DkpDaemon *daemon, DBusGMethodInvocation *context)
{
- GPtrArray *object_paths;
- object_paths = g_ptr_array_new ();
- g_hash_table_foreach (daemon->priv->map_native_path_to_device, enumerate_cb, object_paths);
- dbus_g_method_return (context, object_paths);
- g_ptr_array_foreach (object_paths, (GFunc) g_free, NULL);
- g_ptr_array_free (object_paths, TRUE);
- return TRUE;
+ GPtrArray *object_paths;
+ object_paths = g_ptr_array_new ();
+ g_hash_table_foreach (daemon->priv->map_native_path_to_device, gpk_daemon_enumerate_cb, object_paths);
+ dbus_g_method_return (context, object_paths);
+ g_ptr_array_foreach (object_paths, (GFunc) g_free, NULL);
+ g_ptr_array_free (object_paths, TRUE);
+ return TRUE;
}
+/**
+ * dkp_daemon_get_on_battery:
+ **/
gboolean
-dkp_daemon_get_on_battery (DkpDaemon *daemon,
- DBusGMethodInvocation *context)
+dkp_daemon_get_on_battery (DkpDaemon *daemon, DBusGMethodInvocation *context)
{
- /* this is cached as it's expensive to check all sources */
- dbus_g_method_return (context, daemon->priv->on_battery);
- return TRUE;
+ /* this is cached as it's expensive to check all sources */
+ dbus_g_method_return (context, daemon->priv->on_battery);
+ return TRUE;
}
+/**
+ * dkp_daemon_get_low_battery:
+ **/
gboolean
-dkp_daemon_get_low_battery (DkpDaemon *daemon,
- DBusGMethodInvocation *context)
+dkp_daemon_get_low_battery (DkpDaemon *daemon, DBusGMethodInvocation *context)
{
- /* this is cached as it's expensive to check all sources */
- dbus_g_method_return (context, daemon->priv->low_battery);
- return TRUE;
+ /* this is cached as it's expensive to check all sources */
+ dbus_g_method_return (context, daemon->priv->low_battery);
+ return TRUE;
}
+/**
+ * dkp_daemon_suspend:
+ **/
gboolean
dkp_daemon_suspend (DkpDaemon *daemon, DBusGMethodInvocation *context)
{
- gboolean ret;
- GError *error;
- GError *error_local = NULL;
- gchar *argv;
- const gchar *quirks;
- PolKitCaller *pk_caller;
-
- pk_caller = dkp_daemon_local_get_caller_for_context (daemon, context);
- if (pk_caller == NULL)
- goto out;
-
- if (!dkp_daemon_local_check_auth (daemon, pk_caller,
- "org.freedesktop.devicekit.power.suspend",
- context))
- goto out;
-
- /* TODO: where from? */
- quirks = "--quirk-s3-bios --quirk-s3-mode";
-
- argv = g_strdup_printf ("/usr/sbin/pm-suspend %s", quirks);
- ret = g_spawn_command_line_async (argv, &error_local);
- if (!ret) {
- error = g_error_new (DKP_DAEMON_ERROR,
- DKP_DAEMON_ERROR_GENERAL,
- "Cannot spawn: %s", error_local->message);
- g_error_free (error_local);
+ gboolean ret;
+ GError *error;
+ GError *error_local = NULL;
+ gchar *argv;
+ const gchar *quirks;
+ PolKitCaller *pk_caller;
+
+ pk_caller = dkp_daemon_local_get_caller_for_context (daemon, context);
+ if (pk_caller == NULL)
+ goto out;
+
+ if (!dkp_daemon_local_check_auth (daemon, pk_caller, "org.freedesktop.devicekit.power.suspend", context))
+ goto out;
+
+ /* TODO: where from? */
+ quirks = "--quirk-s3-bios --quirk-s3-mode";
+
+ argv = g_strdup_printf ("/usr/sbin/pm-suspend %s", quirks);
+ ret = g_spawn_command_line_async (argv, &error_local);
+ if (!ret) {
+ error = g_error_new (DKP_DAEMON_ERROR,
+ DKP_DAEMON_ERROR_GENERAL,
+ "Cannot spawn: %s", error_local->message);
+ g_error_free (error_local);
dbus_g_method_return_error (context, error);
goto out;
- }
- dbus_g_method_return (context, NULL);
+ }
+ dbus_g_method_return (context, NULL);
out:
- if (pk_caller != NULL)
- polkit_caller_unref (pk_caller);
- return TRUE;
+ if (pk_caller != NULL)
+ polkit_caller_unref (pk_caller);
+ return TRUE;
}
+/**
+ * dkp_daemon_hibernate:
+ **/
gboolean
dkp_daemon_hibernate (DkpDaemon *daemon, DBusGMethodInvocation *context)
{
- gboolean ret;
- GError *error;
- GError *error_local = NULL;
- gchar *argv;
- const gchar *quirks;
- PolKitCaller *pk_caller;
-
- pk_caller = dkp_daemon_local_get_caller_for_context (daemon, context);
- if (pk_caller == NULL)
- goto out;
-
- if (!dkp_daemon_local_check_auth (daemon, pk_caller,
- "org.freedesktop.devicekit.power.hibernate",
- context))
- goto out;
-
- /* TODO: where from? */
- quirks = "--quirk-s3-bios --quirk-s3-mode";
-
- argv = g_strdup_printf ("/usr/sbin/pm-hibernate %s", quirks);
- ret = g_spawn_command_line_async (argv, &error_local);
- if (!ret) {
- error = g_error_new (DKP_DAEMON_ERROR,
- DKP_DAEMON_ERROR_GENERAL,
- "Cannot spawn: %s", error_local->message);
- g_error_free (error_local);
+ gboolean ret;
+ GError *error;
+ GError *error_local = NULL;
+ gchar *argv;
+ const gchar *quirks;
+ PolKitCaller *pk_caller;
+
+ pk_caller = dkp_daemon_local_get_caller_for_context (daemon, context);
+ if (pk_caller == NULL)
+ goto out;
+
+ if (!dkp_daemon_local_check_auth (daemon, pk_caller, "org.freedesktop.devicekit.power.hibernate", context))
+ goto out;
+
+ /* TODO: where from? */
+ quirks = "--quirk-s3-bios --quirk-s3-mode";
+
+ argv = g_strdup_printf ("/usr/sbin/pm-hibernate %s", quirks);
+ ret = g_spawn_command_line_async (argv, &error_local);
+ if (!ret) {
+ error = g_error_new (DKP_DAEMON_ERROR,
+ DKP_DAEMON_ERROR_GENERAL,
+ "Cannot spawn: %s", error_local->message);
+ g_error_free (error_local);
dbus_g_method_return_error (context, error);
goto out;
- }
- dbus_g_method_return (context, NULL);
+ }
+ dbus_g_method_return (context, NULL);
out:
- if (pk_caller != NULL)
- polkit_caller_unref (pk_caller);
- return TRUE;
+ if (pk_caller != NULL)
+ polkit_caller_unref (pk_caller);
+ return TRUE;
}
diff --git a/src/dkp-daemon.h b/src/dkp-daemon.h
index ad019e1..36afdf9 100644
--- a/src/dkp-daemon.h
+++ b/src/dkp-daemon.h
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
*
@@ -27,10 +27,10 @@
G_BEGIN_DECLS
-#define DKP_SOURCE_TYPE_DAEMON (dkp_daemon_get_type ())
-#define DKP_DAEMON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_DAEMON, DkpDaemon))
-#define DKP_DAEMON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_DAEMON, DkpDaemonClass))
-#define DKP_IS_DAEMON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_DAEMON))
+#define DKP_SOURCE_TYPE_DAEMON (dkp_daemon_get_type ())
+#define DKP_DAEMON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_DAEMON, DkpDaemon))
+#define DKP_DAEMON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_DAEMON, DkpDaemonClass))
+#define DKP_IS_DAEMON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_DAEMON))
#define DKP_IS_DAEMON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DKP_SOURCE_TYPE_DAEMON))
#define DKP_DAEMON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DKP_SOURCE_TYPE_DAEMON, DkpDaemonClass))
@@ -38,21 +38,21 @@ typedef struct DkpDaemonPrivate DkpDaemonPrivate;
typedef struct
{
- GObject parent;
- DkpDaemonPrivate *priv;
+ GObject parent;
+ DkpDaemonPrivate *priv;
} DkpDaemon;
typedef struct
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
} DkpDaemonClass;
typedef enum
{
- DKP_DAEMON_ERROR_GENERAL,
- DKP_DAEMON_ERROR_NOT_SUPPORTED,
- DKP_DAEMON_ERROR_NO_SUCH_DEVICE,
- DKP_DAEMON_NUM_ERRORS
+ DKP_DAEMON_ERROR_GENERAL,
+ DKP_DAEMON_ERROR_NOT_SUPPORTED,
+ DKP_DAEMON_ERROR_NO_SUCH_DEVICE,
+ DKP_DAEMON_NUM_ERRORS
} DkpDaemonError;
#define DKP_DAEMON_ERROR dkp_daemon_error_quark ()
@@ -60,32 +60,31 @@ typedef enum
GType dkp_daemon_error_get_type (void);
#define DKP_DAEMON_TYPE_ERROR (dkp_daemon_error_get_type ())
-GQuark dkp_daemon_error_quark (void);
-GType dkp_daemon_get_type (void);
-DkpDaemon *dkp_daemon_new (void);
+GQuark dkp_daemon_error_quark (void);
+GType dkp_daemon_get_type (void);
+DkpDaemon *dkp_daemon_new (void);
/* local methods */
-PolKitCaller *dkp_daemon_local_get_caller_for_context (DkpDaemon *daemon,
- DBusGMethodInvocation *context);
+PolKitCaller *dkp_daemon_local_get_caller_for_context (DkpDaemon *daemon,
+ DBusGMethodInvocation *context);
-gboolean dkp_daemon_local_check_auth (DkpDaemon *daemon,
- PolKitCaller *pk_caller,
- const char *action_id,
- DBusGMethodInvocation *context);
+gboolean dkp_daemon_local_check_auth (DkpDaemon *daemon,
+ PolKitCaller *pk_caller,
+ const char *action_id,
+ DBusGMethodInvocation *context);
/* exported methods */
-
-gboolean dkp_daemon_enumerate_devices (DkpDaemon *daemon,
- DBusGMethodInvocation *context);
-gboolean dkp_daemon_get_on_battery (DkpDaemon *daemon,
- DBusGMethodInvocation *context);
-gboolean dkp_daemon_get_low_battery (DkpDaemon *daemon,
- DBusGMethodInvocation *context);
-gboolean dkp_daemon_suspend (DkpDaemon *daemon,
- DBusGMethodInvocation *context);
-gboolean dkp_daemon_hibernate (DkpDaemon *daemon,
- DBusGMethodInvocation *context);
+gboolean dkp_daemon_enumerate_devices (DkpDaemon *daemon,
+ DBusGMethodInvocation *context);
+gboolean dkp_daemon_get_on_battery (DkpDaemon *daemon,
+ DBusGMethodInvocation *context);
+gboolean dkp_daemon_get_low_battery (DkpDaemon *daemon,
+ DBusGMethodInvocation *context);
+gboolean dkp_daemon_suspend (DkpDaemon *daemon,
+ DBusGMethodInvocation *context);
+gboolean dkp_daemon_hibernate (DkpDaemon *daemon,
+ DBusGMethodInvocation *context);
G_END_DECLS
diff --git a/src/dkp-device.c b/src/dkp-device.c
index 660a48e..02ac719 100644
--- a/src/dkp-device.c
+++ b/src/dkp-device.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
*
@@ -38,55 +38,72 @@
#include "dkp-source.h"
static void dkp_device_class_init (DkpDeviceClass *klass);
-static void dkp_device_init (DkpDevice *seat);
+static void dkp_device_init (DkpDevice *seat);
G_DEFINE_TYPE (DkpDevice, dkp_device, G_TYPE_OBJECT)
#define DKP_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_SOURCE_TYPE_DEVICE, DkpDevicePrivate))
+/**
+ * dkp_device_class_init:
+ **/
static void
dkp_device_class_init (DkpDeviceClass *klass)
{
}
+/**
+ * dkp_device_init:
+ **/
static void
dkp_device_init (DkpDevice *device)
{
}
+/**
+ * dkp_device_removed:
+ **/
void
dkp_device_removed (DkpDevice *device)
{
- DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
- klass->removed (device);
+ DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
+ klass->removed (device);
}
+/**
+ * dkp_device_new:
+ **/
DkpDevice *
dkp_device_new (DkpDaemon *daemon, DevkitDevice *d)
{
- const char *subsys;
- DkpDevice *device;
+ const char *subsys;
+ DkpDevice *device;
- device = NULL;
+ device = NULL;
- subsys = devkit_device_get_subsystem (d);
- if (strcmp (subsys, "power_supply") == 0) {
- device = DKP_DEVICE (dkp_source_new (daemon, d));
- }
+ subsys = devkit_device_get_subsystem (d);
+ if (strcmp (subsys, "power_supply") == 0)
+ device = DKP_DEVICE (dkp_source_new (daemon, d));
- return device;
+ return device;
}
+/**
+ * dkp_device_changed:
+ **/
gboolean
dkp_device_changed (DkpDevice *device, DevkitDevice *d, gboolean synthesized)
{
- DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
- return (klass->changed (device, d, synthesized));
+ DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
+ return (klass->changed (device, d, synthesized));
}
+/**
+ * dkp_device_get_object_path:
+ **/
const char *
dkp_device_get_object_path (DkpDevice *device)
{
- DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
- return (klass->get_object_path (device));
+ DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
+ return (klass->get_object_path (device));
}
diff --git a/src/dkp-device.h b/src/dkp-device.h
index 2d72a81..dcccff8 100644
--- a/src/dkp-device.h
+++ b/src/dkp-device.h
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
*
@@ -29,39 +29,38 @@
G_BEGIN_DECLS
-#define DKP_SOURCE_TYPE_DEVICE (dkp_device_get_type ())
-#define DKP_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_DEVICE, DkpDevice))
-#define DKP_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_DEVICE, DkpDeviceClass))
-#define DKP_IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_DEVICE))
+#define DKP_SOURCE_TYPE_DEVICE (dkp_device_get_type ())
+#define DKP_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_DEVICE, DkpDevice))
+#define DKP_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_DEVICE, DkpDeviceClass))
+#define DKP_IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_DEVICE))
#define DKP_IS_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DKP_SOURCE_TYPE_DEVICE))
#define DKP_DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DKP_SOURCE_TYPE_DEVICE, DkpDeviceClass))
typedef struct
{
- GObject parent;
+ GObject parent;
} DkpDevice;
typedef struct
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
- /* vtable */
- gboolean (*changed) (DkpDevice *device,
- DevkitDevice *d,
- gboolean synthesized);
- void (*removed) (DkpDevice *device);
- const char *(*get_object_path) (DkpDevice *device);
+ /* vtable */
+ gboolean (*changed) (DkpDevice *device,
+ DevkitDevice *d,
+ gboolean synthesized);
+ void (*removed) (DkpDevice *device);
+ const char *(*get_object_path) (DkpDevice *device);
} DkpDeviceClass;
-GType dkp_device_get_type (void);
-DkpDevice *dkp_device_new (DkpDaemon *daemon,
- DevkitDevice *d);
-gboolean dkp_device_changed (DkpDevice *device,
- DevkitDevice *d,
- gboolean synthesized);
-void dkp_device_removed (DkpDevice *device);
-
-const char *dkp_device_get_object_path (DkpDevice *device);
+GType dkp_device_get_type (void);
+DkpDevice *dkp_device_new (DkpDaemon *daemon,
+ DevkitDevice *d);
+gboolean dkp_device_changed (DkpDevice *device,
+ DevkitDevice *d,
+ gboolean synthesized);
+void dkp_device_removed (DkpDevice *device);
+const char *dkp_device_get_object_path (DkpDevice *device);
G_END_DECLS
diff --git a/src/dkp-enum.c b/src/dkp-enum.c
index bac43eb..e6aa4a2 100644
--- a/src/dkp-enum.c
+++ b/src/dkp-enum.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
@@ -23,96 +23,108 @@
#include <strings.h>
#include "dkp-enum.h"
+/**
+ * dkp_source_type_to_text:
+ **/
const char *
dkp_source_type_to_text (DkpSourceType type_enum)
{
- const char *type = NULL;
- switch (type_enum) {
- case DKP_SOURCE_TYPE_LINE_POWER:
- type = "line-power";
- break;
- case DKP_SOURCE_TYPE_BATTERY:
- type = "battery";
- break;
- case DKP_SOURCE_TYPE_UPS:
- type = "ups";
- break;
- case DKP_SOURCE_TYPE_MOUSE:
- type = "mouse";
- break;
- case DKP_SOURCE_TYPE_KEYBOARD:
- type = "keyboard";
- break;
- case DKP_SOURCE_TYPE_PDA:
- type = "pda";
- break;
- case DKP_SOURCE_TYPE_PHONE:
- type = "phone";
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- return type;
+ const char *type = NULL;
+ switch (type_enum) {
+ case DKP_SOURCE_TYPE_LINE_POWER:
+ type = "line-power";
+ break;
+ case DKP_SOURCE_TYPE_BATTERY:
+ type = "battery";
+ break;
+ case DKP_SOURCE_TYPE_UPS:
+ type = "ups";
+ break;
+ case DKP_SOURCE_TYPE_MOUSE:
+ type = "mouse";
+ break;
+ case DKP_SOURCE_TYPE_KEYBOARD:
+ type = "keyboard";
+ break;
+ case DKP_SOURCE_TYPE_PDA:
+ type = "pda";
+ break;
+ case DKP_SOURCE_TYPE_PHONE:
+ type = "phone";
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ return type;
}
+/**
+ * dkp_source_state_to_text:
+ **/
const char *
dkp_source_state_to_text (DkpSourceState state_enum)
{
- const char *state = NULL;
- switch (state_enum) {
- case DKP_SOURCE_STATE_CHARGING:
- state = "charging";
- break;
- case DKP_SOURCE_STATE_DISCHARGING:
- state = "discharging";
- break;
- case DKP_SOURCE_STATE_EMPTY:
- state = "empty";
- break;
- case DKP_SOURCE_STATE_FULLY_CHARGED:
- state = "fully-charged";
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- return state;
+ const char *state = NULL;
+ switch (state_enum) {
+ case DKP_SOURCE_STATE_CHARGING:
+ state = "charging";
+ break;
+ case DKP_SOURCE_STATE_DISCHARGING:
+ state = "discharging";
+ break;
+ case DKP_SOURCE_STATE_EMPTY:
+ state = "empty";
+ break;
+ case DKP_SOURCE_STATE_FULLY_CHARGED:
+ state = "fully-charged";
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ return state;
}
+/**
+ * dkp_source_technology_to_text:
+ **/
const char *
dkp_source_technology_to_text (DkpSourceTechnology technology_enum)
{
- const char *technology = NULL;
- switch (technology_enum) {
- case DKP_SOURCE_TECHNOLGY_LITHIUM_ION:
- technology = "lithium-ion";
- break;
- case DKP_SOURCE_TECHNOLGY_LITHIUM_POLYMER:
- technology = "lithium-polymer";
- break;
- case DKP_SOURCE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE:
- technology = "lithium-iron-phosphate";
- break;
- case DKP_SOURCE_TECHNOLGY_LEAD_ACID:
- technology = "lead-acid";
- break;
- case DKP_SOURCE_TECHNOLGY_NICKEL_CADMIUM:
- technology = "nickel-cadmium";
- break;
- case DKP_SOURCE_TECHNOLGY_NICKEL_METAL_HYDRIDE:
- technology = "nickel-metal-hydride";
- break;
- case DKP_SOURCE_TECHNOLGY_UNKNOWN:
- technology = "unknown";
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- return technology;
+ const char *technology = NULL;
+ switch (technology_enum) {
+ case DKP_SOURCE_TECHNOLGY_LITHIUM_ION:
+ technology = "lithium-ion";
+ break;
+ case DKP_SOURCE_TECHNOLGY_LITHIUM_POLYMER:
+ technology = "lithium-polymer";
+ break;
+ case DKP_SOURCE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE:
+ technology = "lithium-iron-phosphate";
+ break;
+ case DKP_SOURCE_TECHNOLGY_LEAD_ACID:
+ technology = "lead-acid";
+ break;
+ case DKP_SOURCE_TECHNOLGY_NICKEL_CADMIUM:
+ technology = "nickel-cadmium";
+ break;
+ case DKP_SOURCE_TECHNOLGY_NICKEL_METAL_HYDRIDE:
+ technology = "nickel-metal-hydride";
+ break;
+ case DKP_SOURCE_TECHNOLGY_UNKNOWN:
+ technology = "unknown";
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ return technology;
}
+/**
+ * dkp_acpi_to_source_technology:
+ **/
DkpSourceTechnology
dkp_acpi_to_source_technology (const char *type)
{
diff --git a/src/dkp-enum.h b/src/dkp-enum.h
index 31c8755..1cd7b97 100644
--- a/src/dkp-enum.h
+++ b/src/dkp-enum.h
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
@@ -27,38 +27,38 @@
G_BEGIN_DECLS
typedef enum {
- DKP_SOURCE_TYPE_LINE_POWER,
- DKP_SOURCE_TYPE_BATTERY,
- DKP_SOURCE_TYPE_UPS,
- DKP_SOURCE_TYPE_MOUSE,
- DKP_SOURCE_TYPE_KEYBOARD,
- DKP_SOURCE_TYPE_PDA,
- DKP_SOURCE_TYPE_PHONE,
- DKP_SOURCE_TYPE_UNKNOWN
+ DKP_SOURCE_TYPE_LINE_POWER,
+ DKP_SOURCE_TYPE_BATTERY,
+ DKP_SOURCE_TYPE_UPS,
+ DKP_SOURCE_TYPE_MOUSE,
+ DKP_SOURCE_TYPE_KEYBOARD,
+ DKP_SOURCE_TYPE_PDA,
+ DKP_SOURCE_TYPE_PHONE,
+ DKP_SOURCE_TYPE_UNKNOWN
} DkpSourceType;
typedef enum {
- DKP_SOURCE_STATE_CHARGING,
- DKP_SOURCE_STATE_DISCHARGING,
- DKP_SOURCE_STATE_EMPTY,
- DKP_SOURCE_STATE_FULLY_CHARGED,
- DKP_SOURCE_STATE_UNKNOWN
+ DKP_SOURCE_STATE_CHARGING,
+ DKP_SOURCE_STATE_DISCHARGING,
+ DKP_SOURCE_STATE_EMPTY,
+ DKP_SOURCE_STATE_FULLY_CHARGED,
+ DKP_SOURCE_STATE_UNKNOWN
} DkpSourceState;
typedef enum {
- DKP_SOURCE_TECHNOLGY_LITHIUM_ION,
- DKP_SOURCE_TECHNOLGY_LITHIUM_POLYMER,
- DKP_SOURCE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE,
- DKP_SOURCE_TECHNOLGY_LEAD_ACID,
- DKP_SOURCE_TECHNOLGY_NICKEL_CADMIUM,
- DKP_SOURCE_TECHNOLGY_NICKEL_METAL_HYDRIDE,
- DKP_SOURCE_TECHNOLGY_UNKNOWN
+ DKP_SOURCE_TECHNOLGY_LITHIUM_ION,
+ DKP_SOURCE_TECHNOLGY_LITHIUM_POLYMER,
+ DKP_SOURCE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE,
+ DKP_SOURCE_TECHNOLGY_LEAD_ACID,
+ DKP_SOURCE_TECHNOLGY_NICKEL_CADMIUM,
+ DKP_SOURCE_TECHNOLGY_NICKEL_METAL_HYDRIDE,
+ DKP_SOURCE_TECHNOLGY_UNKNOWN
} DkpSourceTechnology;
-const char *dkp_source_type_to_text (DkpSourceType type_enum);
-const char *dkp_source_state_to_text (DkpSourceState state_enum);
-const char *dkp_source_technology_to_text (DkpSourceTechnology technology_enum);
-DkpSourceTechnology dkp_acpi_to_source_technology (const char *type);
+const char *dkp_source_type_to_text (DkpSourceType type_enum);
+const char *dkp_source_state_to_text (DkpSourceState state_enum);
+const char *dkp_source_technology_to_text (DkpSourceTechnology technology_enum);
+DkpSourceTechnology dkp_acpi_to_source_technology (const char *type);
G_END_DECLS
diff --git a/src/dkp-source.c b/src/dkp-source.c
index ebee66f..002f725 100644
--- a/src/dkp-source.c
+++ b/src/dkp-source.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
@@ -47,81 +47,80 @@
struct DkpSourcePrivate
{
- DBusGConnection *system_bus_connection;
- DBusGProxy *system_bus_proxy;
- DkpDaemon *daemon;
- DevkitDevice *d;
-
- char *object_path;
- char *native_path;
-
- guint poll_timer_id;
-
- char *vendor;
- char *model;
- char *serial;
- GTimeVal update_time;
- DkpSourceType type;
- gboolean has_coldplug_values;
-
- gboolean power_supply;
- gboolean line_power_online;
- gboolean battery_is_present;
- gboolean battery_is_rechargeable;
- DkpSourceState battery_state;
- DkpSourceTechnology battery_technology;
-
- double battery_capacity;
- double battery_energy;
- double battery_energy_empty;
- double battery_energy_full;
- double battery_energy_full_design;
- double battery_energy_rate;
- gint64 battery_time_to_empty;
- gint64 battery_time_to_full;
- double battery_percentage;
-
- double battery_energy_old;
- GTimeVal battery_energy_old_timespec;
+ DBusGConnection *system_bus_connection;
+ DBusGProxy *system_bus_proxy;
+ DkpDaemon *daemon;
+ DevkitDevice *d;
+
+ gchar *object_path;
+ gchar *native_path;
+
+ guint poll_timer_id;
+
+ gchar *vendor;
+ gchar *model;
+ gchar *serial;
+ GTimeVal update_time;
+ DkpSourceType type;
+ gboolean has_coldplug_values;
+
+ gboolean power_supply;
+ gboolean line_power_online;
+ gboolean battery_is_present;
+ gboolean battery_is_rechargeable;
+ DkpSourceState battery_state;
+ DkpSourceTechnology battery_technology;
+
+ gdouble battery_capacity;
+ gdouble battery_energy;
+ gdouble battery_energy_empty;
+ gdouble battery_energy_full;
+ gdouble battery_energy_full_design;
+ gdouble battery_energy_rate;
+ gint64 battery_time_to_empty;
+ gint64 battery_time_to_full;
+ gdouble battery_percentage;
+
+ gdouble battery_energy_old;
+ GTimeVal battery_energy_old_timespec;
};
-static void dkp_source_class_init (DkpSourceClass *klass);
-static void dkp_source_init (DkpSource *source);
-static void dkp_source_finalize (GObject *object);
-static void dkp_source_reset_values(DkpSource *source);
-
-static gboolean update (DkpSource *source);
+static void dkp_source_class_init (DkpSourceClass *klass);
+static void dkp_source_init (DkpSource *source);
+static void dkp_source_finalize (GObject *object);
+static void dkp_source_reset_values (DkpSource *source);
+static gboolean dkp_source_update (DkpSource *source);
enum
{
- PROP_0,
- PROP_NATIVE_PATH,
- PROP_VENDOR,
- PROP_MODEL,
- PROP_SERIAL,
- PROP_UPDATE_TIME,
- PROP_TYPE,
- PROP_LINE_POWER_ONLINE,
- PROP_POWER_SUPPLY,
- PROP_BATTERY_CAPACITY,
- PROP_BATTERY_IS_PRESENT,
- PROP_BATTERY_IS_RECHARGEABLE,
- PROP_BATTERY_STATE,
- PROP_BATTERY_ENERGY,
- PROP_BATTERY_ENERGY_EMPTY,
- PROP_BATTERY_ENERGY_FULL,
- PROP_BATTERY_ENERGY_FULL_DESIGN,
- PROP_BATTERY_ENERGY_RATE,
- PROP_BATTERY_TIME_TO_EMPTY,
- PROP_BATTERY_TIME_TO_FULL,
- PROP_BATTERY_PERCENTAGE,
- PROP_BATTERY_TECHNOLOGY,
+ PROP_0,
+ PROP_NATIVE_PATH,
+ PROP_VENDOR,
+ PROP_MODEL,
+ PROP_SERIAL,
+ PROP_UPDATE_TIME,
+ PROP_TYPE,
+ PROP_LINE_POWER_ONLINE,
+ PROP_POWER_SUPPLY,
+ PROP_BATTERY_CAPACITY,
+ PROP_BATTERY_IS_PRESENT,
+ PROP_BATTERY_IS_RECHARGEABLE,
+ PROP_BATTERY_STATE,
+ PROP_BATTERY_ENERGY,
+ PROP_BATTERY_ENERGY_EMPTY,
+ PROP_BATTERY_ENERGY_FULL,
+ PROP_BATTERY_ENERGY_FULL_DESIGN,
+ PROP_BATTERY_ENERGY_RATE,
+ PROP_BATTERY_TIME_TO_EMPTY,
+ PROP_BATTERY_TIME_TO_FULL,
+ PROP_BATTERY_PERCENTAGE,
+ PROP_BATTERY_TECHNOLOGY,
};
enum
{
- CHANGED_SIGNAL,
- LAST_SIGNAL,
+ CHANGED_SIGNAL,
+ LAST_SIGNAL,
};
static guint signals[LAST_SIGNAL] = { 0 };
@@ -130,440 +129,472 @@ G_DEFINE_TYPE (DkpSource, dkp_source, DKP_SOURCE_TYPE_DEVICE)
#define DKP_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_SOURCE_TYPE_SOURCE, DkpSourcePrivate))
static const char *dkp_source_get_object_path (DkpDevice *device);
-static void dkp_source_removed (DkpDevice *device);
-static gboolean dkp_source_changed (DkpDevice *device,
- DevkitDevice *d,
- gboolean synthesized);
+static void dkp_source_removed (DkpDevice *device);
+static gboolean dkp_source_changed (DkpDevice *device, DevkitDevice *d, gboolean synthesized);
+/**
+ * dkp_source_get_property:
+ **/
static void
-get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+dkp_source_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
- DkpSource *source = DKP_SOURCE (object);
-
- switch (prop_id) {
- case PROP_NATIVE_PATH:
- g_value_set_string (value, source->priv->native_path);
- break;
- case PROP_VENDOR:
- g_value_set_string (value, source->priv->vendor);
- break;
- case PROP_MODEL:
- g_value_set_string (value, source->priv->model);
- break;
- case PROP_SERIAL:
- g_value_set_string (value, source->priv->serial);
- break;
- case PROP_UPDATE_TIME:
- g_value_set_uint64 (value, source->priv->update_time.tv_sec);
- break;
- case PROP_TYPE:
- g_value_set_string (value, dkp_source_type_to_text (source->priv->type));
- break;
-
- case PROP_POWER_SUPPLY:
- g_value_set_boolean (value, source->priv->power_supply);
- break;
-
- case PROP_LINE_POWER_ONLINE:
- g_value_set_boolean (value, source->priv->line_power_online);
- break;
-
- case PROP_BATTERY_IS_PRESENT:
- g_value_set_boolean (value, source->priv->battery_is_present);
- break;
- case PROP_BATTERY_IS_RECHARGEABLE:
- g_value_set_boolean (value, source->priv->battery_is_rechargeable);
- break;
- case PROP_BATTERY_STATE:
- g_value_set_string (value, dkp_source_state_to_text (source->priv->battery_state));
- break;
- case PROP_BATTERY_CAPACITY:
- g_value_set_double (value, source->priv->battery_capacity);
- break;
- case PROP_BATTERY_ENERGY:
- g_value_set_double (value, source->priv->battery_energy);
- break;
- case PROP_BATTERY_ENERGY_EMPTY:
- g_value_set_double (value, source->priv->battery_energy_empty);
- break;
- case PROP_BATTERY_ENERGY_FULL:
- g_value_set_double (value, source->priv->battery_energy_full);
- break;
- case PROP_BATTERY_ENERGY_FULL_DESIGN:
- g_value_set_double (value, source->priv->battery_energy_full_design);
- break;
- case PROP_BATTERY_ENERGY_RATE:
- g_value_set_double (value, source->priv->battery_energy_rate);
- break;
- case PROP_BATTERY_TIME_TO_EMPTY:
- g_value_set_int64 (value, source->priv->battery_time_to_empty);
- break;
- case PROP_BATTERY_TIME_TO_FULL:
- g_value_set_int64 (value, source->priv->battery_time_to_full);
- break;
- case PROP_BATTERY_PERCENTAGE:
- g_value_set_double (value, source->priv->battery_percentage);
- break;
-
- case PROP_BATTERY_TECHNOLOGY:
- g_value_set_string (value, dkp_source_technology_to_text (source->priv->battery_technology));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ DkpSource *source = DKP_SOURCE (object);
+
+ switch (prop_id) {
+ case PROP_NATIVE_PATH:
+ g_value_set_string (value, source->priv->native_path);
+ break;
+ case PROP_VENDOR:
+ g_value_set_string (value, source->priv->vendor);
+ break;
+ case PROP_MODEL:
+ g_value_set_string (value, source->priv->model);
+ break;
+ case PROP_SERIAL:
+ g_value_set_string (value, source->priv->serial);
+ break;
+ case PROP_UPDATE_TIME:
+ g_value_set_uint64 (value, source->priv->update_time.tv_sec);
+ break;
+ case PROP_TYPE:
+ g_value_set_string (value, dkp_source_type_to_text (source->priv->type));
+ break;
+
+ case PROP_POWER_SUPPLY:
+ g_value_set_boolean (value, source->priv->power_supply);
+ break;
+
+ case PROP_LINE_POWER_ONLINE:
+ g_value_set_boolean (value, source->priv->line_power_online);
+ break;
+
+ case PROP_BATTERY_IS_PRESENT:
+ g_value_set_boolean (value, source->priv->battery_is_present);
+ break;
+ case PROP_BATTERY_IS_RECHARGEABLE:
+ g_value_set_boolean (value, source->priv->battery_is_rechargeable);
+ break;
+ case PROP_BATTERY_STATE:
+ g_value_set_string (value, dkp_source_state_to_text (source->priv->battery_state));
+ break;
+ case PROP_BATTERY_CAPACITY:
+ g_value_set_double (value, source->priv->battery_capacity);
+ break;
+ case PROP_BATTERY_ENERGY:
+ g_value_set_double (value, source->priv->battery_energy);
+ break;
+ case PROP_BATTERY_ENERGY_EMPTY:
+ g_value_set_double (value, source->priv->battery_energy_empty);
+ break;
+ case PROP_BATTERY_ENERGY_FULL:
+ g_value_set_double (value, source->priv->battery_energy_full);
+ break;
+ case PROP_BATTERY_ENERGY_FULL_DESIGN:
+ g_value_set_double (value, source->priv->battery_energy_full_design);
+ break;
+ case PROP_BATTERY_ENERGY_RATE:
+ g_value_set_double (value, source->priv->battery_energy_rate);
+ break;
+ case PROP_BATTERY_TIME_TO_EMPTY:
+ g_value_set_int64 (value, source->priv->battery_time_to_empty);
+ break;
+ case PROP_BATTERY_TIME_TO_FULL:
+ g_value_set_int64 (value, source->priv->battery_time_to_full);
+ break;
+ case PROP_BATTERY_PERCENTAGE:
+ g_value_set_double (value, source->priv->battery_percentage);
+ break;
+
+ case PROP_BATTERY_TECHNOLOGY:
+ g_value_set_string (value, dkp_source_technology_to_text (source->priv->battery_technology));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
-
-
+/**
+ * dkp_source_class_init:
+ **/
static void
dkp_source_class_init (DkpSourceClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- DkpDeviceClass *device_class = DKP_DEVICE_CLASS (klass);
-
- object_class->finalize = dkp_source_finalize;
- object_class->get_property = get_property;
- device_class->changed = dkp_source_changed;
- device_class->removed = dkp_source_removed;
- device_class->get_object_path = dkp_source_get_object_path;
-
- g_type_class_add_private (klass, sizeof (DkpSourcePrivate));
-
- signals[CHANGED_SIGNAL] =
- g_signal_new ("changed",
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- dbus_g_object_type_install_info (DKP_SOURCE_TYPE_SOURCE, &dbus_glib_dkp_source_object_info);
-
- g_object_class_install_property (
- object_class,
- PROP_NATIVE_PATH,
- g_param_spec_string ("native-path", NULL, NULL, NULL, G_PARAM_READABLE));
-
- g_object_class_install_property (
- object_class,
- PROP_VENDOR,
- g_param_spec_string ("vendor", NULL, NULL, NULL, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_MODEL,
- g_param_spec_string ("model", NULL, NULL, NULL, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_SERIAL,
- g_param_spec_string ("serial", NULL, NULL, NULL, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_UPDATE_TIME,
- g_param_spec_uint64 ("update-time", NULL, NULL, 0, G_MAXUINT64, 0, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_TYPE,
- g_param_spec_string ("type", NULL, NULL, NULL, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_IS_PRESENT,
- g_param_spec_boolean ("power-supply", NULL, NULL, FALSE, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_LINE_POWER_ONLINE,
- g_param_spec_boolean ("line-power-online", NULL, NULL, FALSE, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_ENERGY,
- g_param_spec_double ("battery-energy", NULL, NULL, 0, G_MAXDOUBLE, 0, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_IS_PRESENT,
- g_param_spec_boolean ("battery-is-present", NULL, NULL, FALSE, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_IS_RECHARGEABLE,
- g_param_spec_boolean ("battery-is-rechargeable", NULL, NULL, FALSE, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_STATE,
- g_param_spec_string ("battery-state", NULL, NULL, NULL, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_CAPACITY,
- g_param_spec_double ("battery-capacity", NULL, NULL, 0, G_MAXDOUBLE, 0, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_ENERGY_EMPTY,
- g_param_spec_double ("battery-energy-empty", NULL, NULL, 0, G_MAXDOUBLE, 0, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_ENERGY_FULL,
- g_param_spec_double ("battery-energy-full", NULL, NULL, 0, G_MAXDOUBLE, 0, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_ENERGY_FULL_DESIGN,
- g_param_spec_double ("battery-energy-full-design", NULL, NULL, 0, G_MAXDOUBLE, 0, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_ENERGY_RATE,
- g_param_spec_double ("battery-energy-rate", NULL, NULL, -G_MAXDOUBLE, G_MAXDOUBLE, 0, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_TIME_TO_EMPTY,
- g_param_spec_int64 ("battery-time-to-empty", NULL, NULL, -1, G_MAXINT64, -1, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_TIME_TO_FULL,
- g_param_spec_int64 ("battery-time-to-full", NULL, NULL, -1, G_MAXINT64, -1, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_PERCENTAGE,
- g_param_spec_double ("battery-percentage", NULL, NULL, -1, 100, -1, G_PARAM_READABLE));
- g_object_class_install_property (
- object_class,
- PROP_BATTERY_TECHNOLOGY,
- g_param_spec_string ("battery-technology", NULL, NULL, NULL, G_PARAM_READABLE));
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ DkpDeviceClass *device_class = DKP_DEVICE_CLASS (klass);
+
+ object_class->finalize = dkp_source_finalize;
+ object_class->get_property = dkp_source_get_property;
+ device_class->changed = dkp_source_changed;
+ device_class->removed = dkp_source_removed;
+ device_class->get_object_path = dkp_source_get_object_path;
+
+ g_type_class_add_private (klass, sizeof (DkpSourcePrivate));
+
+ signals[CHANGED_SIGNAL] =
+ g_signal_new ("changed",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ dbus_g_object_type_install_info (DKP_SOURCE_TYPE_SOURCE, &dbus_glib_dkp_source_object_info);
+
+ g_object_class_install_property (
+ object_class,
+ PROP_NATIVE_PATH,
+ g_param_spec_string ("native-path", NULL, NULL, NULL, G_PARAM_READABLE));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_VENDOR,
+ g_param_spec_string ("vendor", NULL, NULL, NULL, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_MODEL,
+ g_param_spec_string ("model", NULL, NULL, NULL, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_SERIAL,
+ g_param_spec_string ("serial", NULL, NULL, NULL, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_UPDATE_TIME,
+ g_param_spec_uint64 ("update-time", NULL, NULL, 0, G_MAXUINT64, 0, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_TYPE,
+ g_param_spec_string ("type", NULL, NULL, NULL, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_IS_PRESENT,
+ g_param_spec_boolean ("power-supply", NULL, NULL, FALSE, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_LINE_POWER_ONLINE,
+ g_param_spec_boolean ("line-power-online", NULL, NULL, FALSE, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_ENERGY,
+ g_param_spec_double ("battery-energy", NULL, NULL, 0, G_MAXDOUBLE, 0, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_IS_PRESENT,
+ g_param_spec_boolean ("battery-is-present", NULL, NULL, FALSE, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_IS_RECHARGEABLE,
+ g_param_spec_boolean ("battery-is-rechargeable", NULL, NULL, FALSE, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_STATE,
+ g_param_spec_string ("battery-state", NULL, NULL, NULL, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_CAPACITY,
+ g_param_spec_double ("battery-capacity", NULL, NULL, 0, G_MAXDOUBLE, 0, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_ENERGY_EMPTY,
+ g_param_spec_double ("battery-energy-empty", NULL, NULL, 0, G_MAXDOUBLE, 0, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_ENERGY_FULL,
+ g_param_spec_double ("battery-energy-full", NULL, NULL, 0, G_MAXDOUBLE, 0, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_ENERGY_FULL_DESIGN,
+ g_param_spec_double ("battery-energy-full-design", NULL, NULL, 0, G_MAXDOUBLE, 0, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_ENERGY_RATE,
+ g_param_spec_double ("battery-energy-rate", NULL, NULL, -G_MAXDOUBLE, G_MAXDOUBLE, 0, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_TIME_TO_EMPTY,
+ g_param_spec_int64 ("battery-time-to-empty", NULL, NULL, -1, G_MAXINT64, -1, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_TIME_TO_FULL,
+ g_param_spec_int64 ("battery-time-to-full", NULL, NULL, -1, G_MAXINT64, -1, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_PERCENTAGE,
+ g_param_spec_double ("battery-percentage", NULL, NULL, -1, 100, -1, G_PARAM_READABLE));
+ g_object_class_install_property (
+ object_class,
+ PROP_BATTERY_TECHNOLOGY,
+ g_param_spec_string ("battery-technology", NULL, NULL, NULL, G_PARAM_READABLE));
}
+/**
+ * dkp_source_init:
+ **/
static void
dkp_source_init (DkpSource *source)
{
- source->priv = DKP_SOURCE_GET_PRIVATE (source);
- dkp_source_reset_values (source);
+ source->priv = DKP_SOURCE_GET_PRIVATE (source);
+ dkp_source_reset_values (source);
}
+/**
+ * dkp_source_finalize:
+ **/
static void
dkp_source_finalize (GObject *object)
{
- DkpSource *source;
+ DkpSource *source;
- g_return_if_fail (object != NULL);
- g_return_if_fail (DKP_IS_SOURCE (object));
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (DKP_IS_SOURCE (object));
- source = DKP_SOURCE (object);
- g_return_if_fail (source->priv != NULL);
+ source = DKP_SOURCE (object);
+ g_return_if_fail (source->priv != NULL);
- g_object_unref (source->priv->d);
- g_object_unref (source->priv->daemon);
+ g_object_unref (source->priv->d);
+ g_object_unref (source->priv->daemon);
- g_free (source->priv->native_path);
+ g_free (source->priv->native_path);
- g_free (source->priv->vendor);
- g_free (source->priv->model);
- g_free (source->priv->serial);
+ g_free (source->priv->vendor);
+ g_free (source->priv->model);
+ g_free (source->priv->serial);
- if (source->priv->poll_timer_id > 0)
- g_source_remove (source->priv->poll_timer_id);
+ if (source->priv->poll_timer_id > 0)
+ g_source_remove (source->priv->poll_timer_id);
- G_OBJECT_CLASS (dkp_source_parent_class)->finalize (object);
+ G_OBJECT_CLASS (dkp_source_parent_class)->finalize (object);
}
+/**
+ * dkp_source_compute_object_path_from_basename:
+ **/
static char *
-compute_object_path_from_basename (const char *native_path_basename)
+dkp_source_compute_object_path_from_basename (const char *native_path_basename)
{
- char *basename;
- char *object_path;
- unsigned int n;
-
- /* TODO: need to be more thorough with making proper object
- * names that won't make D-Bus crash. This is just to cope
- * with dm-0...
- */
- basename = g_path_get_basename (native_path_basename);
- for (n = 0; basename[n] != '\0'; n++)
- if (basename[n] == '-')
- basename[n] = '_';
- object_path = g_build_filename ("/sources/", basename, NULL);
- g_free (basename);
-
- return object_path;
+ char *basename;
+ char *object_path;
+ unsigned int n;
+
+ /* TODO: need to be more thorough with making proper object
+ * names that won't make D-Bus crash. This is just to cope
+ * with dm-0...
+ */
+ basename = g_path_get_basename (native_path_basename);
+ for (n = 0; basename[n] != '\0'; n++)
+ if (basename[n] == '-')
+ basename[n] = '_';
+ object_path = g_build_filename ("/sources/", basename, NULL);
+ g_free (basename);
+
+ return object_path;
}
+/**
+ * dkp_source_compute_object_path:
+ **/
static char *
-compute_object_path (const char *native_path)
+dkp_source_compute_object_path (const char *native_path)
{
- char *basename;
- char *object_path;
+ char *basename;
+ char *object_path;
- basename = g_path_get_basename (native_path);
- object_path = compute_object_path_from_basename (basename);
- g_free (basename);
- return object_path;
+ basename = g_path_get_basename (native_path);
+ object_path = dkp_source_compute_object_path_from_basename (basename);
+ g_free (basename);
+ return object_path;
}
+/**
+ * dkp_source_register_power_source:
+ **/
static gboolean
-register_power_source (DkpSource *source)
+dkp_source_register_power_source (DkpSource *source)
{
- DBusConnection *connection;
- GError *error = NULL;
-
- source->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (source->priv->system_bus_connection == NULL) {
- if (error != NULL) {
- g_critical ("error getting system bus: %s", error->message);
- g_error_free (error);
- }
- goto error;
- }
- connection = dbus_g_connection_get_connection (source->priv->system_bus_connection);
+ DBusConnection *connection;
+ GError *error = NULL;
+
+ source->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (source->priv->system_bus_connection == NULL) {
+ if (error != NULL) {
+ g_critical ("error getting system bus: %s", error->message);
+ g_error_free (error);
+ }
+ goto error;
+ }
+ connection = dbus_g_connection_get_connection (source->priv->system_bus_connection);
- source->priv->object_path = compute_object_path (source->priv->native_path);
+ source->priv->object_path = dkp_source_compute_object_path (source->priv->native_path);
- dbus_g_connection_register_g_object (source->priv->system_bus_connection,
- source->priv->object_path,
- G_OBJECT (source));
+ dbus_g_connection_register_g_object (source->priv->system_bus_connection,
+ source->priv->object_path, G_OBJECT (source));
- source->priv->system_bus_proxy = dbus_g_proxy_new_for_name (source->priv->system_bus_connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
+ source->priv->system_bus_proxy = dbus_g_proxy_new_for_name (source->priv->system_bus_connection,
+ DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
- return TRUE;
+ return TRUE;
error:
- return FALSE;
+ return FALSE;
}
+/**
+ * dkp_source_new:
+ **/
DkpSource *
dkp_source_new (DkpDaemon *daemon, DevkitDevice *d)
{
- DkpSource *source;
- const char *native_path;
-
- source = NULL;
- native_path = devkit_device_get_native_path (d);
-
- source = DKP_SOURCE (g_object_new (DKP_SOURCE_TYPE_SOURCE, NULL));
- source->priv->d = g_object_ref (d);
- source->priv->daemon = g_object_ref (daemon);
- source->priv->native_path = g_strdup (native_path);
-
- if (sysfs_file_exists (native_path, "online")) {
- source->priv->type = DKP_SOURCE_TYPE_LINE_POWER;
- } else {
- /* this is correct, UPS and CSR are not in the kernel */
- source->priv->type = DKP_SOURCE_TYPE_BATTERY;
- }
-
- if (!update (source)) {
- g_object_unref (source);
- source = NULL;
- goto out;
- }
-
- if (! register_power_source (DKP_SOURCE (source))) {
- g_object_unref (source);
- source = NULL;
- goto out;
- }
+ DkpSource *source;
+ const char *native_path;
+
+ source = NULL;
+ native_path = devkit_device_get_native_path (d);
+
+ source = DKP_SOURCE (g_object_new (DKP_SOURCE_TYPE_SOURCE, NULL));
+ source->priv->d = g_object_ref (d);
+ source->priv->daemon = g_object_ref (daemon);
+ source->priv->native_path = g_strdup (native_path);
+
+ if (sysfs_file_exists (native_path, "online")) {
+ source->priv->type = DKP_SOURCE_TYPE_LINE_POWER;
+ } else {
+ /* this is correct, UPS and CSR are not in the kernel */
+ source->priv->type = DKP_SOURCE_TYPE_BATTERY;
+ }
+
+ if (!dkp_source_update (source)) {
+ g_object_unref (source);
+ source = NULL;
+ goto out;
+ }
+
+ if (!dkp_source_register_power_source (DKP_SOURCE (source))) {
+ g_object_unref (source);
+ source = NULL;
+ goto out;
+ }
out:
- return source;
+ return source;
}
+/**
+ * dkp_source_emit_changed:
+ **/
static void
-emit_changed (DkpSource *source)
+dkp_source_emit_changed (DkpSource *source)
{
- g_print ("emitting changed on %s\n", source->priv->native_path);
- g_signal_emit_by_name (source->priv->daemon,
- "device-changed",
- source->priv->object_path,
- NULL);
- g_signal_emit (source, signals[CHANGED_SIGNAL], 0);
+ g_print ("emitting changed on %s\n", source->priv->native_path);
+ g_signal_emit_by_name (source->priv->daemon,
+ "device-changed",
+ source->priv->object_path,
+ NULL);
+ g_signal_emit (source, signals[CHANGED_SIGNAL], 0);
}
+/**
+ * dkp_source_changed:
+ **/
static gboolean
dkp_source_changed (DkpDevice *device, DevkitDevice *d, gboolean synthesized)
{
- DkpSource *source = DKP_SOURCE (device);
- gboolean keep_source;
+ DkpSource *source = DKP_SOURCE (device);
+ gboolean keep_source;
- g_object_unref (source->priv->d);
- source->priv->d = g_object_ref (d);
+ g_object_unref (source->priv->d);
+ source->priv->d = g_object_ref (d);
- keep_source = update (source);
+ keep_source = dkp_source_update (source);
- /* this 'change' event might prompt us to remove the source */
- if (!keep_source)
- goto out;
+ /* this 'change' event might prompt us to remove the source */
+ if (!keep_source)
+ goto out;
- /* no, it's good .. keep it */
- emit_changed (source);
+ /* no, it's good .. keep it */
+ dkp_source_emit_changed (source);
out:
- return keep_source;
+ return keep_source;
}
+/**
+ * dkp_source_removed:
+ **/
void
dkp_source_removed (DkpDevice *device)
{
}
+/**
+ * dkp_source_get_object_path:
+ **/
static const char *
dkp_source_get_object_path (DkpDevice *device)
{
- DkpSource *source = DKP_SOURCE (device);
- return source->priv->object_path;
+ DkpSource *source = DKP_SOURCE (device);
+ return source->priv->object_path;
}
-/*--------------------------------------------------------------------------------------------------------------*/
-
+/**
+ * dkp_source_update_line_power:
+ **/
static gboolean
-update_line_power (DkpSource *source)
+dkp_source_update_line_power (DkpSource *source)
{
- source->priv->line_power_online = sysfs_get_int (source->priv->native_path, "online");
- return TRUE;
+ source->priv->line_power_online = sysfs_get_int (source->priv->native_path, "online");
+ return TRUE;
}
+/**
+ * dkp_source_reset_values:
+ **/
static void
dkp_source_reset_values (DkpSource *source)
{
- source->priv->battery_energy = -1;
- source->priv->battery_energy_old = -1;
- source->priv->battery_energy_full = -1;
- source->priv->battery_energy_full_design = -1;
- source->priv->battery_energy_rate = -1;
- source->priv->battery_percentage = -1;
- source->priv->battery_capacity = -1;
- source->priv->battery_time_to_empty = -1;
- source->priv->battery_time_to_full = -1;
- source->priv->battery_state = DKP_SOURCE_STATE_UNKNOWN;
- source->priv->battery_technology = DKP_SOURCE_TECHNOLGY_UNKNOWN;
- source->priv->vendor = NULL;
- source->priv->model = NULL;
- source->priv->serial = NULL;
- source->priv->line_power_online = FALSE;
- source->priv->battery_is_present = FALSE;
- source->priv->power_supply = FALSE;
- source->priv->battery_is_rechargeable = FALSE;
- source->priv->has_coldplug_values = FALSE;
- source->priv->battery_energy_old_timespec.tv_sec = 0;
+ source->priv->battery_energy = -1;
+ source->priv->battery_energy_old = -1;
+ source->priv->battery_energy_full = -1;
+ source->priv->battery_energy_full_design = -1;
+ source->priv->battery_energy_rate = -1;
+ source->priv->battery_percentage = -1;
+ source->priv->battery_capacity = -1;
+ source->priv->battery_time_to_empty = -1;
+ source->priv->battery_time_to_full = -1;
+ source->priv->battery_state = DKP_SOURCE_STATE_UNKNOWN;
+ source->priv->battery_technology = DKP_SOURCE_TECHNOLGY_UNKNOWN;
+ source->priv->vendor = NULL;
+ source->priv->model = NULL;
+ source->priv->serial = NULL;
+ source->priv->line_power_online = FALSE;
+ source->priv->battery_is_present = FALSE;
+ source->priv->power_supply = FALSE;
+ source->priv->battery_is_rechargeable = FALSE;
+ source->priv->has_coldplug_values = FALSE;
+ source->priv->battery_energy_old_timespec.tv_sec = 0;
}
+/**
+ * dkp_source_get_id:
+ **/
gchar *
dkp_source_get_id (DkpSource *source)
{
GString *string;
gchar *id = NULL;
- /* only valid for devices supplying the system */
- if (!source->priv->power_supply)
- return id;
+ /* only valid for devices supplying the system */
+ if (!source->priv->power_supply)
+ return id;
- /* only valid for batteries */
- if (source->priv->type != DKP_SOURCE_TYPE_BATTERY)
- return id;
+ /* only valid for batteries */
+ if (source->priv->type != DKP_SOURCE_TYPE_BATTERY)
+ return id;
- /* we don't have an ID if we are not present */
- if (!source->priv->battery_is_present)
- return id;
+ /* we don't have an ID if we are not present */
+ if (!source->priv->battery_is_present)
+ return id;
string = g_string_new ("");
@@ -597,118 +628,124 @@ dkp_source_get_id (DkpSource *source)
return id;
}
+/**
+ * dkp_source_calculate_battery_rate:
+ **/
static void
-calculate_battery_rate (DkpSource *source)
+dkp_source_calculate_battery_rate (DkpSource *source)
{
- guint time;
- gdouble energy;
- GTimeVal now;
+ guint time;
+ gdouble energy;
+ GTimeVal now;
- if (source->priv->battery_energy < 0)
- return;
+ if (source->priv->battery_energy < 0)
+ return;
- if (source->priv->battery_energy_old < 0)
- return;
+ if (source->priv->battery_energy_old < 0)
+ return;
- if (source->priv->battery_energy_old == source->priv->battery_energy)
- return;
+ if (source->priv->battery_energy_old == source->priv->battery_energy)
+ return;
- /* get the time difference */
- g_get_current_time (&now);
- time = now.tv_sec - source->priv->battery_energy_old_timespec.tv_sec;
+ /* get the time difference */
+ g_get_current_time (&now);
+ time = now.tv_sec - source->priv->battery_energy_old_timespec.tv_sec;
- if (time == 0)
- return;
+ if (time == 0)
+ return;
- /* get the difference in charge */
- energy = source->priv->battery_energy_old - source->priv->battery_energy;
- if (energy < 0.1)
- return;
+ /* get the difference in charge */
+ energy = source->priv->battery_energy_old - source->priv->battery_energy;
+ if (energy < 0.1)
+ return;
- /* probably okay */
- source->priv->battery_energy_rate = energy * 3600 / time;
+ /* probably okay */
+ source->priv->battery_energy_rate = energy * 3600 / time;
}
+/**
+ * dkp_source_update_battery:
+ **/
static gboolean
-update_battery (DkpSource *source)
+dkp_source_update_battery (DkpSource *source)
{
- char *status;
- gboolean is_charging;
- gboolean is_discharging;
- DkpSourceState battery_state;
-
- /* are we present? */
- source->priv->battery_is_present = sysfs_get_bool (source->priv->native_path, "present");
- if (!source->priv->battery_is_present) {
- g_free (source->priv->vendor);
- g_free (source->priv->model);
- g_free (source->priv->serial);
- dkp_source_reset_values (source);
- return TRUE;
- }
-
- /* initial values */
- if (!source->priv->has_coldplug_values) {
- char *technology_native;
-
- /* when we add via sysfs power_supply class then we know this is true */
- source->priv->power_supply = TRUE;
-
- /* the ACPI spec is bad at defining battery type constants */
- technology_native = g_strstrip (sysfs_get_string (source->priv->native_path, "technology"));
- source->priv->battery_technology = dkp_acpi_to_source_technology (technology_native);
- g_free (technology_native);
-
- source->priv->vendor = g_strstrip (sysfs_get_string (source->priv->native_path, "manufacturer"));
- source->priv->model = g_strstrip (sysfs_get_string (source->priv->native_path, "model_name"));
- source->priv->serial = g_strstrip (sysfs_get_string (source->priv->native_path, "serial_number"));
-
- /* assume true for laptops */
- source->priv->battery_is_rechargeable = TRUE;
-
- /* these don't change at runtime */
- source->priv->battery_energy_full =
- sysfs_get_double (source->priv->native_path, "energy_full") / 1000000.0;
- source->priv->battery_energy_full_design =
- sysfs_get_double (source->priv->native_path, "energy_full_design") / 1000000.0;
-
- /* the last full cannot be bigger than the design */
- if (source->priv->battery_energy_full > source->priv->battery_energy_full_design)
- source->priv->battery_energy_full = source->priv->battery_energy_full_design;
-
- /* calculate how broken our battery is */
- source->priv->battery_capacity = source->priv->battery_energy_full_design /
- source->priv->battery_energy_full * 100.0f;
- if (source->priv->battery_capacity < 0)
- source->priv->battery_capacity = 0;
- if (source->priv->battery_capacity > 100.0)
- source->priv->battery_capacity = 100.0;
-
- /* we only coldplug once, as these values will never change */
- source->priv->has_coldplug_values = TRUE;
- }
-
- status = g_strstrip (sysfs_get_string (source->priv->native_path, "status"));
- is_charging = strcasecmp (status, "charging") == 0;
- is_discharging = strcasecmp (status, "discharging") == 0;
-
- /* really broken battery, assume charging */
- if (is_charging && is_discharging)
- is_discharging = FALSE;
-
- /* get the currect charge */
- source->priv->battery_energy =
- sysfs_get_double (source->priv->native_path, "energy_avg") / 1000000.0;
- if (source->priv->battery_energy == 0)
- source->priv->battery_energy =
- sysfs_get_double (source->priv->native_path, "energy_now") / 1000000.0;
-
- /* some batteries don't update last_full attribute */
- if (source->priv->battery_energy > source->priv->battery_energy_full)
- source->priv->battery_energy_full = source->priv->battery_energy;
-
- source->priv->battery_energy_rate =
- fabs (sysfs_get_double (source->priv->native_path, "current_now") / 1000000.0);
+ char *status;
+ gboolean is_charging;
+ gboolean is_discharging;
+ DkpSourceState battery_state;
+
+ /* are we present? */
+ source->priv->battery_is_present = sysfs_get_bool (source->priv->native_path, "present");
+ if (!source->priv->battery_is_present) {
+ g_free (source->priv->vendor);
+ g_free (source->priv->model);
+ g_free (source->priv->serial);
+ dkp_source_reset_values (source);
+ return TRUE;
+ }
+
+ /* initial values */
+ if (!source->priv->has_coldplug_values) {
+ char *technology_native;
+
+ /* when we add via sysfs power_supply class then we know this is true */
+ source->priv->power_supply = TRUE;
+
+ /* the ACPI spec is bad at defining battery type constants */
+ technology_native = g_strstrip (sysfs_get_string (source->priv->native_path, "technology"));
+ source->priv->battery_technology = dkp_acpi_to_source_technology (technology_native);
+ g_free (technology_native);
+
+ source->priv->vendor = g_strstrip (sysfs_get_string (source->priv->native_path, "manufacturer"));
+ source->priv->model = g_strstrip (sysfs_get_string (source->priv->native_path, "model_name"));
+ source->priv->serial = g_strstrip (sysfs_get_string (source->priv->native_path, "serial_number"));
+
+ /* assume true for laptops */
+ source->priv->battery_is_rechargeable = TRUE;
+
+ /* these don't change at runtime */
+ source->priv->battery_energy_full =
+ sysfs_get_double (source->priv->native_path, "energy_full") / 1000000.0;
+ source->priv->battery_energy_full_design =
+ sysfs_get_double (source->priv->native_path, "energy_full_design") / 1000000.0;
+
+ /* the last full cannot be bigger than the design */
+ if (source->priv->battery_energy_full > source->priv->battery_energy_full_design)
+ source->priv->battery_energy_full = source->priv->battery_energy_full_design;
+
+ /* calculate how broken our battery is */
+ source->priv->battery_capacity = source->priv->battery_energy_full_design /
+ source->priv->battery_energy_full * 100.0f;
+ if (source->priv->battery_capacity < 0)
+ source->priv->battery_capacity = 0;
+ if (source->priv->battery_capacity > 100.0)
+ source->priv->battery_capacity = 100.0;
+
+ /* we only coldplug once, as these values will never change */
+ source->priv->has_coldplug_values = TRUE;
+ }
+
+ status = g_strstrip (sysfs_get_string (source->priv->native_path, "status"));
+ is_charging = strcasecmp (status, "charging") == 0;
+ is_discharging = strcasecmp (status, "discharging") == 0;
+
+ /* really broken battery, assume charging */
+ if (is_charging && is_discharging)
+ is_discharging = FALSE;
+
+ /* get the currect charge */
+ source->priv->battery_energy =
+ sysfs_get_double (source->priv->native_path, "energy_avg") / 1000000.0;
+ if (source->priv->battery_energy == 0)
+ source->priv->battery_energy =
+ sysfs_get_double (source->priv->native_path, "energy_now") / 1000000.0;
+
+ /* some batteries don't update last_full attribute */
+ if (source->priv->battery_energy > source->priv->battery_energy_full)
+ source->priv->battery_energy_full = source->priv->battery_energy;
+
+ source->priv->battery_energy_rate =
+ fabs (sysfs_get_double (source->priv->native_path, "current_now") / 1000000.0);
/* ACPI gives out the special 'Ones' value for rate when it's unable
* to calculate the true rate. We should set the rate zero, and wait
@@ -720,29 +757,29 @@ update_battery (DkpSource *source)
if (source->priv->battery_energy_rate > 100*1000)
source->priv->battery_energy_rate = -1;
- /* the hardware reporting failed -- try to calculate this */
- if (source->priv->battery_energy_rate < 0) {
- calculate_battery_rate (source);
- }
-
- /* charging has a negative rate */
- if (source->priv->battery_energy_rate > 0 && is_charging)
- source->priv->battery_energy_rate *= -1.0;
-
- /* get a precise percentage */
- source->priv->battery_percentage = 100.0 * source->priv->battery_energy / source->priv->battery_energy_full;
- if (source->priv->battery_percentage < 0)
- source->priv->battery_percentage = 0;
- if (source->priv->battery_percentage > 100.0)
- source->priv->battery_percentage = 100.0;
-
- /* calculate a quick and dirty time remaining value */
- source->priv->battery_time_to_empty = -1;
- source->priv->battery_time_to_full = -1;
+ /* the hardware reporting failed -- try to calculate this */
+ if (source->priv->battery_energy_rate < 0) {
+ dkp_source_calculate_battery_rate (source);
+ }
+
+ /* charging has a negative rate */
+ if (source->priv->battery_energy_rate > 0 && is_charging)
+ source->priv->battery_energy_rate *= -1.0;
+
+ /* get a precise percentage */
+ source->priv->battery_percentage = 100.0 * source->priv->battery_energy / source->priv->battery_energy_full;
+ if (source->priv->battery_percentage < 0)
+ source->priv->battery_percentage = 0;
+ if (source->priv->battery_percentage > 100.0)
+ source->priv->battery_percentage = 100.0;
+
+ /* calculate a quick and dirty time remaining value */
+ source->priv->battery_time_to_empty = -1;
+ source->priv->battery_time_to_full = -1;
if (source->priv->battery_energy_rate > 0) {
if (is_discharging) {
source->priv->battery_time_to_empty = 3600 * (source->priv->battery_energy /
- source->priv->battery_energy_rate);
+ source->priv->battery_energy_rate);
} else if (is_charging) {
source->priv->battery_time_to_full = 3600 *
((source->priv->battery_energy_full - source->priv->battery_energy) /
@@ -756,83 +793,89 @@ update_battery (DkpSource *source)
if (source->priv->battery_time_to_full > (100 * 60 * 60))
source->priv->battery_time_to_full = -1;
- /* get the state */
- if (is_charging)
- battery_state = DKP_SOURCE_STATE_CHARGING;
- else if (is_discharging)
- battery_state = DKP_SOURCE_STATE_DISCHARGING;
- else if (source->priv->battery_percentage > DK_POWER_MIN_CHARGED_PERCENTAGE)
- battery_state = DKP_SOURCE_STATE_FULLY_CHARGED;
- else
- battery_state = DKP_SOURCE_STATE_EMPTY;
-
- /* set the old status */
- source->priv->battery_energy_old = source->priv->battery_energy;
- g_get_current_time (&source->priv->battery_energy_old_timespec);
-
- /* we changed state */
- if (source->priv->battery_state != battery_state) {
- source->priv->battery_energy_old = -1;
- source->priv->battery_state = battery_state;
- }
-
- g_free (status);
- return TRUE;
+ /* get the state */
+ if (is_charging)
+ battery_state = DKP_SOURCE_STATE_CHARGING;
+ else if (is_discharging)
+ battery_state = DKP_SOURCE_STATE_DISCHARGING;
+ else if (source->priv->battery_percentage > DK_POWER_MIN_CHARGED_PERCENTAGE)
+ battery_state = DKP_SOURCE_STATE_FULLY_CHARGED;
+ else
+ battery_state = DKP_SOURCE_STATE_EMPTY;
+
+ /* set the old status */
+ source->priv->battery_energy_old = source->priv->battery_energy;
+ g_get_current_time (&source->priv->battery_energy_old_timespec);
+
+ /* we changed state */
+ if (source->priv->battery_state != battery_state) {
+ source->priv->battery_energy_old = -1;
+ source->priv->battery_state = battery_state;
+ }
+
+ g_free (status);
+ return TRUE;
}
+/**
+ * dkp_source_poll_battery:
+ **/
static gboolean
-_poll_battery (DkpSource *source)
+dkp_source_poll_battery (DkpSource *source)
{
- g_warning ("No updates on source %s for 30 seconds; forcing update", source->priv->native_path);
- source->priv->poll_timer_id = 0;
- update (source);
- emit_changed (source);
- return FALSE;
+ g_warning ("No updates on source %s for 30 seconds; forcing update", source->priv->native_path);
+ source->priv->poll_timer_id = 0;
+ dkp_source_update (source);
+ dkp_source_emit_changed (source);
+ return FALSE;
}
+/**
+ * dkp_source_update:
+ **/
static gboolean
-update (DkpSource *source)
+dkp_source_update (DkpSource *source)
{
- gboolean ret;
+ gboolean ret;
- if (source->priv->poll_timer_id > 0) {
- g_source_remove (source->priv->poll_timer_id);
- source->priv->poll_timer_id = 0;
- }
+ if (source->priv->poll_timer_id > 0) {
+ g_source_remove (source->priv->poll_timer_id);
+ source->priv->poll_timer_id = 0;
+ }
- g_get_current_time (&(source->priv->update_time));
+ g_get_current_time (&(source->priv->update_time));
- switch (source->priv->type) {
- case DKP_SOURCE_TYPE_LINE_POWER:
- ret = update_line_power (source);
- break;
- case DKP_SOURCE_TYPE_BATTERY:
+ switch (source->priv->type) {
+ case DKP_SOURCE_TYPE_LINE_POWER:
+ ret = dkp_source_update_line_power (source);
+ break;
+ case DKP_SOURCE_TYPE_BATTERY:
- ret = update_battery (source);
+ ret = dkp_source_update_battery (source);
- /* Seems that we don't get change uevents from the
- * kernel on some BIOS types; set up a timer to poll
- *
- * TODO: perhaps only do this if we do not get frequent updates.
- */
- source->priv->poll_timer_id = g_timeout_add_seconds (30, (GSourceFunc) _poll_battery, source);
+ /* Seems that we don't get change uevents from the
+ * kernel on some BIOS types; set up a timer to poll
+ *
+ * TODO: perhaps only do this if we do not get frequent updates.
+ */
+ source->priv->poll_timer_id = g_timeout_add_seconds (30, (GSourceFunc) dkp_source_poll_battery, source);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
- return ret;
+ return ret;
}
-/*--------------------------------------------------------------------------------------------------------------*/
-
+/**
+ * dkp_source_refresh:
+ **/
gboolean
-dkp_source_refresh (DkpSource *power_source,
- DBusGMethodInvocation *context)
+dkp_source_refresh (DkpSource *power_source, DBusGMethodInvocation *context)
{
- update (power_source);
- dbus_g_method_return (context);
- return TRUE;
+ dkp_source_update (power_source);
+ dbus_g_method_return (context);
+ return TRUE;
}
diff --git a/src/dkp-source.h b/src/dkp-source.h
index 19ab3fb..04c5dca 100644
--- a/src/dkp-source.h
+++ b/src/dkp-source.h
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
*
@@ -30,10 +30,10 @@
G_BEGIN_DECLS
-#define DKP_SOURCE_TYPE_SOURCE (dkp_source_get_type ())
-#define DKP_SOURCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_SOURCE, DkpSource))
-#define DKP_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_SOURCE, DkpSourceClass))
-#define DKP_IS_SOURCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_SOURCE))
+#define DKP_SOURCE_TYPE_SOURCE (dkp_source_get_type ())
+#define DKP_SOURCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_SOURCE, DkpSource))
+#define DKP_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_SOURCE, DkpSourceClass))
+#define DKP_IS_SOURCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_SOURCE))
#define DKP_IS_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DKP_SOURCE_TYPE_SOURCE))
#define DKP_SOURCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DKP_SOURCE_TYPE_SOURCE, DkpSourceClass))
@@ -41,24 +41,23 @@ typedef struct DkpSourcePrivate DkpSourcePrivate;
typedef struct
{
- DkpDevice parent;
- DkpSourcePrivate *priv;
+ DkpDevice parent;
+ DkpSourcePrivate *priv;
} DkpSource;
typedef struct
{
- DkpDeviceClass parent_class;
+ DkpDeviceClass parent_class;
} DkpSourceClass;
-GType dkp_source_get_type (void);
-DkpSource *dkp_source_new (DkpDaemon *daemon,
- DevkitDevice *d);
+GType dkp_source_get_type (void);
+DkpSource *dkp_source_new (DkpDaemon *daemon,
+ DevkitDevice *d);
/* exported methods */
-
-gboolean dkp_source_refresh (DkpSource *power_source,
- DBusGMethodInvocation *context);
-gchar *dkp_source_get_id (DkpSource *power_source);
+gboolean dkp_source_refresh (DkpSource *power_source,
+ DBusGMethodInvocation *context);
+gchar *dkp_source_get_id (DkpSource *power_source);
G_END_DECLS
diff --git a/src/main.c b/src/main.c
index c140c37..3f50629 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2007 David Zeuthen <david@fubar.dk>
*
@@ -42,116 +42,122 @@
#define NAME_TO_CLAIM "org.freedesktop.DeviceKit.Power"
+/**
+ * main_acquire_name_on_proxy:
+ **/
static gboolean
-acquire_name_on_proxy (DBusGProxy *bus_proxy)
+main_acquire_name_on_proxy (DBusGProxy *bus_proxy)
{
- GError *error;
- guint result;
- gboolean res;
- gboolean ret;
+ GError *error;
+ guint result;
+ gboolean res;
+ gboolean ret;
- ret = FALSE;
+ ret = FALSE;
- if (bus_proxy == NULL) {
- goto out;
- }
+ if (bus_proxy == NULL) {
+ goto out;
+ }
- error = NULL;
+ error = NULL;
res = dbus_g_proxy_call (bus_proxy,
- "RequestName",
- &error,
- G_TYPE_STRING, NAME_TO_CLAIM,
- G_TYPE_UINT, 0,
- G_TYPE_INVALID,
- G_TYPE_UINT, &result,
- G_TYPE_INVALID);
- if (! res) {
- if (error != NULL) {
- g_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
- g_error_free (error);
- } else {
- g_warning ("Failed to acquire %s", NAME_TO_CLAIM);
- }
- goto out;
+ "RequestName",
+ &error,
+ G_TYPE_STRING, NAME_TO_CLAIM,
+ G_TYPE_UINT, 0,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &result,
+ G_TYPE_INVALID);
+ if (!res) {
+ if (error != NULL) {
+ g_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
+ g_error_free (error);
+ } else {
+ g_warning ("Failed to acquire %s", NAME_TO_CLAIM);
+ }
+ goto out;
}
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- if (error != NULL) {
- g_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
- g_error_free (error);
- } else {
- g_warning ("Failed to acquire %s", NAME_TO_CLAIM);
- }
- goto out;
- }
+ if (error != NULL) {
+ g_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
+ g_error_free (error);
+ } else {
+ g_warning ("Failed to acquire %s", NAME_TO_CLAIM);
+ }
+ goto out;
+ }
- ret = TRUE;
+ ret = TRUE;
out:
- return ret;
+ return ret;
}
+/**
+ * main:
+ **/
int
main (int argc, char **argv)
{
- GError *error;
- GMainLoop *loop;
- DkpDaemon *power_daemon;
- GOptionContext *context;
- DBusGProxy *bus_proxy;
- DBusGConnection *bus;
- int ret;
- static GOptionEntry entries [] = {
- { NULL }
- };
-
- ret = 1;
-
- g_type_init ();
-
- context = g_option_context_new ("DeviceKit Power Daemon");
- g_option_context_add_main_entries (context, entries, NULL);
- g_option_context_parse (context, &argc, &argv, NULL);
- g_option_context_free (context);
-
- error = NULL;
- bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (bus == NULL) {
- g_warning ("Couldn't connect to system bus: %s", error->message);
- g_error_free (error);
- goto out;
- }
+ GError *error;
+ GMainLoop *loop;
+ DkpDaemon *power_daemon;
+ GOptionContext *context;
+ DBusGProxy *bus_proxy;
+ DBusGConnection *bus;
+ int ret;
+ static GOptionEntry entries [] = {
+ { NULL }
+ };
+
+ ret = 1;
+
+ g_type_init ();
+
+ context = g_option_context_new ("DeviceKit Power Daemon");
+ g_option_context_add_main_entries (context, entries, NULL);
+ g_option_context_parse (context, &argc, &argv, NULL);
+ g_option_context_free (context);
+
+ error = NULL;
+ bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (bus == NULL) {
+ g_warning ("Couldn't connect to system bus: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
bus_proxy = dbus_g_proxy_new_for_name (bus,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
- if (bus_proxy == NULL) {
- g_warning ("Could not construct bus_proxy object; bailing out");
- goto out;
- }
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS);
+ if (bus_proxy == NULL) {
+ g_warning ("Could not construct bus_proxy object; bailing out");
+ goto out;
+ }
- if (!acquire_name_on_proxy (bus_proxy) ) {
- g_warning ("Could not acquire name; bailing out");
- goto out;
- }
+ if (!main_acquire_name_on_proxy (bus_proxy) ) {
+ g_warning ("Could not acquire name; bailing out");
+ goto out;
+ }
- g_debug ("Starting devkit-power-daemon version %s", VERSION);
+ g_debug ("Starting devkit-power-daemon version %s", VERSION);
- power_daemon = dkp_daemon_new ();
+ power_daemon = dkp_daemon_new ();
- if (power_daemon == NULL) {
- goto out;
- }
+ if (power_daemon == NULL) {
+ goto out;
+ }
- loop = g_main_loop_new (NULL, FALSE);
+ loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (loop);
+ g_main_loop_run (loop);
- g_object_unref (power_daemon);
- g_main_loop_unref (loop);
- ret = 0;
+ g_object_unref (power_daemon);
+ g_main_loop_unref (loop);
+ ret = 0;
out:
- return ret;
+ return ret;
}
diff --git a/src/sysfs-utils.c b/src/sysfs-utils.c
index 93aa2a3..8a594f5 100644
--- a/src/sysfs-utils.c
+++ b/src/sysfs-utils.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
*
@@ -44,178 +44,178 @@
double
sysfs_get_double (const char *dir, const char *attribute)
{
- double result;
- char *contents;
- char *filename;
+ double result;
+ char *contents;
+ char *filename;
- result = 0.0;
- filename = g_build_filename (dir, attribute, NULL);
- if (g_file_get_contents (filename, &contents, NULL, NULL)) {
- result = atof (contents);
- g_free (contents);
- }
- g_free (filename);
+ result = 0.0;
+ filename = g_build_filename (dir, attribute, NULL);
+ if (g_file_get_contents (filename, &contents, NULL, NULL)) {
+ result = atof (contents);
+ g_free (contents);
+ }
+ g_free (filename);
- return result;
+ return result;
}
gboolean
sysfs_file_contains (const char *dir, const char *attribute, const char *string)
{
- gboolean result;
- char *filename;
- char *s;
+ gboolean result;
+ char *filename;
+ char *s;
- result = FALSE;
+ result = FALSE;
- filename = g_build_filename (dir, attribute, NULL);
- if (g_file_get_contents (filename, &s, NULL, NULL)) {
- result = (strstr(s, string) != NULL);
- g_free (s);
- }
- g_free (filename);
+ filename = g_build_filename (dir, attribute, NULL);
+ if (g_file_get_contents (filename, &s, NULL, NULL)) {
+ result = (strstr(s, string) != NULL);
+ g_free (s);
+ }
+ g_free (filename);
- return result;
+ return result;
}
char *
sysfs_get_string (const char *dir, const char *attribute)
{
- char *result;
- char *filename;
+ char *result;
+ char *filename;
- result = NULL;
- filename = g_build_filename (dir, attribute, NULL);
- if (!g_file_get_contents (filename, &result, NULL, NULL)) {
- result = g_strdup ("");
- }
- g_free (filename);
+ result = NULL;
+ filename = g_build_filename (dir, attribute, NULL);
+ if (!g_file_get_contents (filename, &result, NULL, NULL)) {
+ result = g_strdup ("");
+ }
+ g_free (filename);
- return result;
+ return result;
}
int
sysfs_get_int (const char *dir, const char *attribute)
{
- int result;
- char *contents;
- char *filename;
-
- result = 0;
- filename = g_build_filename (dir, attribute, NULL);
- if (g_file_get_contents (filename, &contents, NULL, NULL)) {
- result = atoi (contents);
- g_free (contents);
- }
- g_free (filename);
-
- return result;
+ int result;
+ char *contents;
+ char *filename;
+
+ result = 0;
+ filename = g_build_filename (dir, attribute, NULL);
+ if (g_file_get_contents (filename, &contents, NULL, NULL)) {
+ result = atoi (contents);
+ g_free (contents);
+ }
+ g_free (filename);
+
+ return result;
}
gboolean
sysfs_get_bool (const char *dir, const char *attribute)
{
- gboolean result = FALSE;
- char *contents;
- char *filename;
-
- result = 0;
- filename = g_build_filename (dir, attribute, NULL);
- if (g_file_get_contents (filename, &contents, NULL, NULL)) {
- if (strcmp (contents, "1"))
- result = TRUE;
- g_free (contents);
- }
- g_free (filename);
-
- return result;
+ gboolean result = FALSE;
+ char *contents;
+ char *filename;
+
+ result = 0;
+ filename = g_build_filename (dir, attribute, NULL);
+ if (g_file_get_contents (filename, &contents, NULL, NULL)) {
+ if (strcmp (contents, "1"))
+ result = TRUE;
+ g_free (contents);
+ }
+ g_free (filename);
+
+ return result;
}
guint64
sysfs_get_uint64 (const char *dir, const char *attribute)
{
- guint64 result;
- char *contents;
- char *filename;
+ guint64 result;
+ char *contents;
+ char *filename;
- result = 0;
- filename = g_build_filename (dir, attribute, NULL);
- if (g_file_get_contents (filename, &contents, NULL, NULL)) {
- result = atoll (contents);
- g_free (contents);
- }
- g_free (filename);
+ result = 0;
+ filename = g_build_filename (dir, attribute, NULL);
+ if (g_file_get_contents (filename, &contents, NULL, NULL)) {
+ result = atoll (contents);
+ g_free (contents);
+ }
+ g_free (filename);
- return result;
+ return result;
}
gboolean
sysfs_file_exists (const char *dir, const char *attribute)
{
- gboolean result;
- char *filename;
+ gboolean result;
+ char *filename;
- result = FALSE;
- filename = g_build_filename (dir, attribute, NULL);
- if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
- result = TRUE;
- }
- g_free (filename);
+ result = FALSE;
+ filename = g_build_filename (dir, attribute, NULL);
+ if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
+ result = TRUE;
+ }
+ g_free (filename);
- return result;
+ return result;
}
char *
_dupv8 (const char *s)
{
- const char *end_valid;
-
- if (!g_utf8_validate (s,
- -1,
- &end_valid)) {
- g_warning ("The string '%s' is not valid UTF-8. Invalid characters begins at '%s'", s, end_valid);
- return g_strndup (s, end_valid - s);
- } else {
- return g_strdup (s);
- }
+ const char *end_valid;
+
+ if (!g_utf8_validate (s,
+ -1,
+ &end_valid)) {
+ g_warning ("The string '%s' is not valid UTF-8. Invalid characters begins at '%s'", s, end_valid);
+ return g_strndup (s, end_valid - s);
+ } else {
+ return g_strdup (s);
+ }
}
char *
sysfs_resolve_link (const char *dir, const char *attribute)
{
- char *full_path;
- char link_path[PATH_MAX];
- char resolved_path[PATH_MAX];
- ssize_t num;
- gboolean found_it;
-
- found_it = FALSE;
-
- full_path = g_build_filename (dir, attribute, NULL);
-
- //g_warning ("attribute='%s'", attribute);
- //g_warning ("full_path='%s'", full_path);
- num = readlink (full_path, link_path, sizeof (link_path) - 1);
- if (num != -1) {
- char *absolute_path;
-
- link_path[num] = '\0';
-
- //g_warning ("link_path='%s'", link_path);
- absolute_path = g_build_filename (dir, link_path, NULL);
- //g_warning ("absolute_path='%s'", absolute_path);
- if (realpath (absolute_path, resolved_path) != NULL) {
- //g_warning ("resolved_path='%s'", resolved_path);
- found_it = TRUE;
- }
- g_free (absolute_path);
- }
- g_free (full_path);
-
- if (found_it)
- return g_strdup (resolved_path);
- else
- return NULL;
+ char *full_path;
+ char link_path[PATH_MAX];
+ char resolved_path[PATH_MAX];
+ ssize_t num;
+ gboolean found_it;
+
+ found_it = FALSE;
+
+ full_path = g_build_filename (dir, attribute, NULL);
+
+ //g_warning ("attribute='%s'", attribute);
+ //g_warning ("full_path='%s'", full_path);
+ num = readlink (full_path, link_path, sizeof (link_path) - 1);
+ if (num != -1) {
+ char *absolute_path;
+
+ link_path[num] = '\0';
+
+ //g_warning ("link_path='%s'", link_path);
+ absolute_path = g_build_filename (dir, link_path, NULL);
+ //g_warning ("absolute_path='%s'", absolute_path);
+ if (realpath (absolute_path, resolved_path) != NULL) {
+ //g_warning ("resolved_path='%s'", resolved_path);
+ found_it = TRUE;
+ }
+ g_free (absolute_path);
+ }
+ g_free (full_path);
+
+ if (found_it)
+ return g_strdup (resolved_path);
+ else
+ return NULL;
}