summaryrefslogtreecommitdiff
path: root/libdevkit-power
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2009-01-23 17:14:02 +0000
committerRichard Hughes <richard@hughsie.com>2009-01-23 17:14:02 +0000
commit39df99ae208e0f5c38e041de7c6050c1f77ceace (patch)
treef6adabdaea82e2729d64ba6cb56cc67bdd5c769f /libdevkit-power
parent44b2ad6bc2e64365c92f401229804949c2a748a6 (diff)
trivial: add a fixme
Diffstat (limited to 'libdevkit-power')
-rw-r--r--libdevkit-power/Makefile.am4
-rw-r--r--libdevkit-power/dkp-client-device.c495
-rw-r--r--libdevkit-power/dkp-client-device.h76
-rw-r--r--libdevkit-power/dkp-client.c140
-rw-r--r--libdevkit-power/dkp-client.h27
-rw-r--r--libdevkit-power/dkp-object.c1
6 files changed, 121 insertions, 622 deletions
diff --git a/libdevkit-power/Makefile.am b/libdevkit-power/Makefile.am
index 93ca66f..bc5ceea 100644
--- a/libdevkit-power/Makefile.am
+++ b/libdevkit-power/Makefile.am
@@ -21,8 +21,8 @@ libdevkit_power_la_SOURCES = \
egg-obj-list.h \
dkp-client.c \
dkp-client.h \
- dkp-client-device.c \
- dkp-client-device.h \
+ dkp-device.c \
+ dkp-device.h \
dkp-history-obj.h \
dkp-history-obj.c \
dkp-stats-obj.h \
diff --git a/libdevkit-power/dkp-client-device.c b/libdevkit-power/dkp-client-device.c
deleted file mode 100644
index dc25fc5..0000000
--- a/libdevkit-power/dkp-client-device.c
+++ /dev/null
@@ -1,495 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-
-#include "egg-debug.h"
-#include "egg-obj-list.h"
-
-#include "dkp-client-device.h"
-#include "dkp-object.h"
-#include "dkp-stats-obj.h"
-#include "dkp-history-obj.h"
-
-static void dkp_client_device_class_init (DkpClientDeviceClass *klass);
-static void dkp_client_device_init (DkpClientDevice *device);
-static void dkp_client_device_finalize (GObject *object);
-
-#define DKP_CLIENT_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_TYPE_CLIENT_DEVICE, DkpClientDevicePrivate))
-
-struct DkpClientDevicePrivate
-{
- gchar *object_path;
- DkpObject *obj;
- DBusGConnection *bus;
- DBusGProxy *proxy_device;
- DBusGProxy *proxy_props;
-};
-
-enum {
- DKP_CLIENT_DEVICE_CHANGED,
- DKP_CLIENT_DEVICE_LAST_SIGNAL
-};
-
-static guint signals [DKP_CLIENT_DEVICE_LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE (DkpClientDevice, dkp_client_device, G_TYPE_OBJECT)
-
-/**
- * dkp_client_device_get_device_properties:
- **/
-static GHashTable *
-dkp_client_device_get_device_properties (DkpClientDevice *device)
-{
- gboolean ret;
- GError *error = NULL;
- GHashTable *hash_table = NULL;
-
- ret = dbus_g_proxy_call (device->priv->proxy_props, "GetAll", &error,
- G_TYPE_STRING, "org.freedesktop.DeviceKit.Power.Device",
- G_TYPE_INVALID,
- dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
- &hash_table,
- G_TYPE_INVALID);
- if (!ret) {
- egg_debug ("Couldn't call GetAll() to get properties for %s: %s", device->priv->object_path, error->message);
- g_error_free (error);
- goto out;
- }
-out:
- return hash_table;
-}
-
-/**
- * dkp_client_device_refresh_internal:
- **/
-static gboolean
-dkp_client_device_refresh_internal (DkpClientDevice *device)
-{
- GHashTable *hash;
-
- /* get all the properties */
- hash = dkp_client_device_get_device_properties (device);
- if (hash == NULL) {
- egg_warning ("Cannot get device properties for %s", device->priv->object_path);
- return FALSE;
- }
- dkp_object_set_from_map (device->priv->obj, hash);
- g_hash_table_unref (hash);
- return TRUE;
-}
-
-/**
- * dkp_client_device_changed_cb:
- **/
-static void
-dkp_client_device_changed_cb (DBusGProxy *proxy, DkpClientDevice *device)
-{
- g_return_if_fail (DKP_IS_CLIENT_DEVICE (device));
- dkp_client_device_refresh_internal (device);
- g_signal_emit (device, signals [DKP_CLIENT_DEVICE_CHANGED], 0, device->priv->obj);
-}
-
-/**
- * dkp_client_device_set_object_path:
- **/
-gboolean
-dkp_client_device_set_object_path (DkpClientDevice *device, const gchar *object_path)
-{
- GError *error = NULL;
- gboolean ret = FALSE;
- DBusGProxy *proxy_device;
- DBusGProxy *proxy_props;
-
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
-
- if (device->priv->object_path != NULL)
- return FALSE;
- if (object_path == NULL)
- return FALSE;
-
- /* connect to the bus */
- device->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (device->priv->bus == NULL) {
- egg_warning ("Couldn't connect to system bus: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- /* connect to the correct path for properties */
- proxy_props = dbus_g_proxy_new_for_name (device->priv->bus, "org.freedesktop.DeviceKit.Power",
- object_path, "org.freedesktop.DBus.Properties");
- if (proxy_props == NULL) {
- egg_warning ("Couldn't connect to proxy");
- goto out;
- }
-
- /* connect to the correct path for all the other methods */
- proxy_device = dbus_g_proxy_new_for_name (device->priv->bus, "org.freedesktop.DeviceKit.Power",
- object_path, "org.freedesktop.DeviceKit.Power.Device");
- if (proxy_device == NULL) {
- egg_warning ("Couldn't connect to proxy");
- goto out;
- }
-
- /* listen to Changed */
- dbus_g_proxy_add_signal (proxy_device, "Changed", G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (proxy_device, "Changed",
- G_CALLBACK (dkp_client_device_changed_cb), device, NULL);
-
- /* yay */
- egg_debug ("using object_path: %s", object_path);
- device->priv->proxy_device = proxy_device;
- device->priv->proxy_props = proxy_props;
- device->priv->object_path = g_strdup (object_path);
-
- /* coldplug */
- ret = dkp_client_device_refresh_internal (device);
- if (!ret)
- egg_warning ("cannot refresh");
-out:
- return ret;
-}
-
-/**
- * dkp_client_device_get_object_path:
- **/
-const gchar *
-dkp_client_device_get_object_path (const DkpClientDevice *device)
-{
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), NULL);
- return device->priv->object_path;
-}
-
-/**
- * dkp_client_device_get_object:
- **/
-const DkpObject *
-dkp_client_device_get_object (const DkpClientDevice *device)
-{
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), NULL);
- return device->priv->obj;
-}
-
-/**
- * dkp_client_device_print_history:
- **/
-static gboolean
-dkp_client_device_print_history (const DkpClientDevice *device, const gchar *type)
-{
- guint i;
- EggObjList *array;
- DkpHistoryObj *obj;
- gboolean ret = FALSE;
-
- /* get a fair chunk of data */
- array = dkp_client_device_get_history (device, type, 120, 10);
- if (array == NULL)
- goto out;
-
- /* pretty print */
- g_print (" History (%s):\n", type);
- for (i=0; i<array->len; i++) {
- obj = (DkpHistoryObj *) egg_obj_list_index (array, i);
- g_print (" %i\t%.3f\t%s\n", obj->time, obj->value, dkp_device_state_to_text (obj->state));
- }
- g_object_unref (array);
- ret = TRUE;
-out:
- return ret;
-}
-
-/**
- * dkp_client_device_print:
- **/
-gboolean
-dkp_client_device_print (const DkpClientDevice *device)
-{
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
-
- /* print to screen */
- dkp_object_print (device->priv->obj);
-
- /* if we can, get history */
- dkp_client_device_print_history (device, "charge");
- dkp_client_device_print_history (device, "rate");
-
- return TRUE;
-}
-
-/**
- * dkp_client_device_refresh:
- **/
-gboolean
-dkp_client_device_refresh (DkpClientDevice *device)
-{
- GError *error = NULL;
- gboolean ret;
-
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
- g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
-
- /* just refresh the device */
- ret = dbus_g_proxy_call (device->priv->proxy_device, "Refresh", &error,
- G_TYPE_INVALID, G_TYPE_INVALID);
- if (!ret) {
- egg_debug ("Refresh() on %s failed: %s", device->priv->object_path, error->message);
- g_error_free (error);
- goto out;
- }
-out:
- return ret;
-}
-
-/**
- * dkp_client_device_get_history:
- *
- * Returns an array of %DkpHistoryObj's
- **/
-EggObjList *
-dkp_client_device_get_history (const DkpClientDevice *device, const gchar *type, guint timespec, guint resolution)
-{
- GError *error = NULL;
- GType g_type_gvalue_array;
- GPtrArray *gvalue_ptr_array = NULL;
- GValueArray *gva;
- GValue *gv;
- guint i;
- DkpHistoryObj *obj;
- EggObjList *array = NULL;
- gboolean ret;
-
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
- g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
-
- g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
- dbus_g_type_get_struct("GValueArray",
- G_TYPE_UINT,
- G_TYPE_DOUBLE,
- G_TYPE_STRING,
- G_TYPE_INVALID));
-
- /* get compound data */
- ret = dbus_g_proxy_call (device->priv->proxy_device, "GetHistory", &error,
- G_TYPE_STRING, type,
- G_TYPE_UINT, timespec,
- G_TYPE_UINT, resolution,
- G_TYPE_INVALID,
- g_type_gvalue_array, &gvalue_ptr_array,
- G_TYPE_INVALID);
- if (!ret) {
- egg_debug ("GetHistory(%s,%i) on %s failed: %s", type, timespec,
- device->priv->object_path, error->message);
- g_error_free (error);
- goto out;
- }
-
- /* no data */
- if (gvalue_ptr_array->len == 0)
- goto out;
-
- /* convert */
- array = egg_obj_list_new ();
- egg_obj_list_set_copy (array, (EggObjListCopyFunc) dkp_history_obj_copy);
- egg_obj_list_set_free (array, (EggObjListFreeFunc) dkp_history_obj_free);
-
- for (i=0; i<gvalue_ptr_array->len; i++) {
- gva = (GValueArray *) g_ptr_array_index (gvalue_ptr_array, i);
- obj = dkp_history_obj_new ();
- /* 0 */
- gv = g_value_array_get_nth (gva, 0);
- obj->time = g_value_get_uint (gv);
- g_value_unset (gv);
- /* 1 */
- gv = g_value_array_get_nth (gva, 1);
- obj->value = g_value_get_double (gv);
- g_value_unset (gv);
- /* 2 */
- gv = g_value_array_get_nth (gva, 2);
- obj->state = dkp_device_state_from_text (g_value_get_string (gv));
- g_value_unset (gv);
- egg_obj_list_add (array, obj);
- dkp_history_obj_free (obj);
- g_value_array_free (gva);
- }
-
-out:
- if (gvalue_ptr_array != NULL)
- g_ptr_array_free (gvalue_ptr_array, TRUE);
- return array;
-}
-
-/**
- * dkp_client_device_get_statistics:
- *
- * Returns an array of %DkpStatsObj's
- **/
-EggObjList *
-dkp_client_device_get_statistics (const DkpClientDevice *device, const gchar *type)
-{
- GError *error = NULL;
- GType g_type_gvalue_array;
- GPtrArray *gvalue_ptr_array = NULL;
- GValueArray *gva;
- GValue *gv;
- guint i;
- DkpStatsObj *obj;
- EggObjList *array = NULL;
- gboolean ret;
-
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
- g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
-
- g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
- dbus_g_type_get_struct("GValueArray",
- G_TYPE_DOUBLE,
- G_TYPE_DOUBLE,
- G_TYPE_INVALID));
-
- /* get compound data */
- ret = dbus_g_proxy_call (device->priv->proxy_device, "GetStatistics", &error,
- G_TYPE_STRING, type,
- G_TYPE_INVALID,
- g_type_gvalue_array, &gvalue_ptr_array,
- G_TYPE_INVALID);
- if (!ret) {
- egg_debug ("GetStatistics(%s) on %s failed: %s", type,
- device->priv->object_path, error->message);
- g_error_free (error);
- goto out;
- }
-
- /* no data */
- if (gvalue_ptr_array->len == 0)
- goto out;
-
- /* convert */
- array = egg_obj_list_new ();
- egg_obj_list_set_copy (array, (EggObjListCopyFunc) dkp_stats_obj_copy);
- egg_obj_list_set_free (array, (EggObjListFreeFunc) dkp_stats_obj_free);
- egg_obj_list_set_to_string (array, (EggObjListToStringFunc) dkp_stats_obj_to_string);
- egg_obj_list_set_from_string (array, (EggObjListFromStringFunc) dkp_stats_obj_from_string);
-
- for (i=0; i<gvalue_ptr_array->len; i++) {
- gva = (GValueArray *) g_ptr_array_index (gvalue_ptr_array, i);
- obj = dkp_stats_obj_new ();
- /* 0 */
- gv = g_value_array_get_nth (gva, 0);
- obj->value = g_value_get_double (gv);
- g_value_unset (gv);
- /* 1 */
- gv = g_value_array_get_nth (gva, 1);
- obj->accuracy = g_value_get_double (gv);
- g_value_unset (gv);
- /* 2 */
- egg_obj_list_add (array, obj);
- dkp_stats_obj_free (obj);
- g_value_array_free (gva);
- }
-out:
- if (gvalue_ptr_array != NULL)
- g_ptr_array_free (gvalue_ptr_array, TRUE);
- return array;
-}
-
-/**
- * dkp_client_device_class_init:
- * @klass: The DkpClientDeviceClass
- **/
-static void
-dkp_client_device_class_init (DkpClientDeviceClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = dkp_client_device_finalize;
-
- /**
- * PkClient::changed:
- * @device: the #DkpClientDevice instance that emitted the signal
- * @obj: the #DkpObject that has changed
- *
- * The ::changed signal is emitted when the device data has changed.
- **/
- signals [DKP_CLIENT_DEVICE_CHANGED] =
- g_signal_new ("changed",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (DkpClientDeviceClass, changed),
- NULL, NULL, g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
-
- g_type_class_add_private (klass, sizeof (DkpClientDevicePrivate));
-}
-
-/**
- * dkp_client_device_init:
- * @client_device: This class instance
- **/
-static void
-dkp_client_device_init (DkpClientDevice *device)
-{
- device->priv = DKP_CLIENT_DEVICE_GET_PRIVATE (device);
- device->priv->object_path = NULL;
- device->priv->proxy_device = NULL;
- device->priv->proxy_props = NULL;
- device->priv->obj = dkp_object_new ();
-}
-
-/**
- * dkp_client_device_finalize:
- * @object: The object to finalize
- **/
-static void
-dkp_client_device_finalize (GObject *object)
-{
- DkpClientDevice *device;
-
- g_return_if_fail (DKP_IS_CLIENT_DEVICE (object));
-
- device = DKP_CLIENT_DEVICE (object);
-
- g_free (device->priv->object_path);
- dkp_object_free (device->priv->obj);
- if (device->priv->proxy_device != NULL)
- g_object_unref (device->priv->proxy_device);
- if (device->priv->proxy_props != NULL)
- g_object_unref (device->priv->proxy_props);
- dbus_g_connection_unref (device->priv->bus);
-
- G_OBJECT_CLASS (dkp_client_device_parent_class)->finalize (object);
-}
-
-/**
- * dkp_client_device_new:
- *
- * Return value: a new DkpClientDevice object.
- **/
-DkpClientDevice *
-dkp_client_device_new (void)
-{
- DkpClientDevice *device;
- device = g_object_new (DKP_TYPE_CLIENT_DEVICE, NULL);
- return DKP_CLIENT_DEVICE (device);
-}
-
diff --git a/libdevkit-power/dkp-client-device.h b/libdevkit-power/dkp-client-device.h
deleted file mode 100644
index a0d88d2..0000000
--- a/libdevkit-power/dkp-client-device.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __DKP_CLIENT_DEVICE_H
-#define __DKP_CLIENT_DEVICE_H
-
-#include <glib-object.h>
-#include <dkp-enum.h>
-#include <dkp-object.h>
-#include "egg-obj-list.h"
-
-G_BEGIN_DECLS
-
-#define DKP_TYPE_CLIENT_DEVICE (dkp_client_device_get_type ())
-#define DKP_CLIENT_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_TYPE_CLIENT_DEVICE, DkpClientDevice))
-#define DKP_CLIENT_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_TYPE_CLIENT_DEVICE, DkpClientDeviceClass))
-#define DKP_IS_CLIENT_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_TYPE_CLIENT_DEVICE))
-#define DKP_IS_CLIENT_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DKP_TYPE_CLIENT_DEVICE))
-#define DKP_CLIENT_DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DKP_TYPE_CLIENT_DEVICE, DkpClientDeviceClass))
-#define DKP_CLIENT_DEVICE_ERROR (dkp_client_device_error_quark ())
-#define DKP_CLIENT_DEVICE_TYPE_ERROR (dkp_client_device_error_get_type ())
-
-typedef struct DkpClientDevicePrivate DkpClientDevicePrivate;
-
-typedef struct
-{
- GObject parent;
- DkpClientDevicePrivate *priv;
-} DkpClientDevice;
-
-typedef struct
-{
- GObjectClass parent_class;
- void (*changed) (DkpClientDevice *device,
- const DkpObject *obj);
-} DkpClientDeviceClass;
-
-GType dkp_client_device_get_type (void) G_GNUC_CONST;
-DkpClientDevice *dkp_client_device_new (void);
-
-const DkpObject *dkp_client_device_get_object (const DkpClientDevice *device);
-const gchar *dkp_client_device_get_object_path (const DkpClientDevice *device);
-gboolean dkp_client_device_set_object_path (DkpClientDevice *device,
- const gchar *object_path);
-
-gboolean dkp_client_device_print (const DkpClientDevice *device);
-gboolean dkp_client_device_refresh (DkpClientDevice *device);
-EggObjList *dkp_client_device_get_history (const DkpClientDevice *device,
- const gchar *type,
- guint timespec,
- guint resolution);
-EggObjList *dkp_client_device_get_statistics (const DkpClientDevice *device,
- const gchar *type);
-
-G_END_DECLS
-
-#endif /* __DKP_CLIENT_DEVICE_H */
-
diff --git a/libdevkit-power/dkp-client.c b/libdevkit-power/dkp-client.c
index bfb17eb..91d4a09 100644
--- a/libdevkit-power/dkp-client.c
+++ b/libdevkit-power/dkp-client.c
@@ -28,7 +28,7 @@
#include "egg-debug.h"
#include "dkp-client.h"
-#include "dkp-client-device.h"
+#include "dkp-device.h"
static void dkp_client_class_init (DkpClientClass *klass);
static void dkp_client_init (DkpClient *client);
@@ -44,19 +44,19 @@ struct DkpClientPrivate
GHashTable *hash;
GPtrArray *array;
- gboolean have_properties;
+ gboolean have_properties;
- char *daemon_version;
- gboolean can_suspend;
- gboolean can_hibernate;
- gboolean on_battery;
- gboolean on_low_battery;
+ gchar *daemon_version;
+ gboolean can_suspend;
+ gboolean can_hibernate;
+ gboolean on_battery;
+ gboolean on_low_battery;
};
enum {
- DKP_CLIENT_DEVICE_ADDED,
- DKP_CLIENT_DEVICE_CHANGED,
- DKP_CLIENT_DEVICE_REMOVED,
+ DKP_DEVICE_ADDED,
+ DKP_DEVICE_CHANGED,
+ DKP_DEVICE_REMOVED,
DKP_CLIENT_CHANGED,
DKP_CLIENT_LAST_SIGNAL
};
@@ -68,19 +68,41 @@ G_DEFINE_TYPE (DkpClient, dkp_client, G_TYPE_OBJECT)
/**
* dkp_client_get_device:
**/
-static DkpClientDevice *
+static DkpDevice *
dkp_client_get_device (DkpClient *client, const gchar *object_path)
{
- DkpClientDevice *device;
+ DkpDevice *device;
device = g_hash_table_lookup (client->priv->hash, object_path);
return device;
}
/**
* dkp_client_enumerate_devices:
+ *
+ * Return a list of devices, which need to be unref'd, and the array needs
+ * to be freed
**/
GPtrArray *
-dkp_client_enumerate_devices (DkpClient *client, GError **error)
+dkp_client_enumerate_devices (DkpClient *client)
+{
+ guint i;
+ GPtrArray *array;
+ DkpDevice *device;
+
+ array = g_ptr_array_new ();
+ for (i=0; i<client->priv->array->len; i++) {
+ device = g_ptr_array_index (client->priv->array, i);
+ g_object_ref (device);
+ g_ptr_array_add (array, device);
+ }
+ return array;
+}
+
+/**
+ * dkp_client_enumerate_devices_private:
+ **/
+static GPtrArray *
+dkp_client_enumerate_devices_private (DkpClient *client, GError **error)
{
gboolean ret;
GError *error_local = NULL;
@@ -102,6 +124,52 @@ dkp_client_enumerate_devices (DkpClient *client, GError **error)
}
/**
+ * dkp_client_suspend:
+ **/
+gboolean
+dkp_client_suspend (DkpClient *client, GError **error)
+{
+ gboolean ret;
+ GError *error_local = NULL;
+
+ g_return_val_if_fail (DKP_IS_CLIENT (client), FALSE);
+ g_return_val_if_fail (client->priv->proxy != NULL, FALSE);
+
+ ret = dbus_g_proxy_call (client->priv->proxy, "Suspend", &error_local,
+ G_TYPE_INVALID, G_TYPE_INVALID);
+ if (!ret) {
+ egg_warning ("Couldn't suspend: %s", error_local->message);
+ if (error != NULL)
+ *error = g_error_new (1, 0, "%s", error_local->message);
+ g_error_free (error_local);
+ }
+ return ret;
+}
+
+/**
+ * dkp_client_hibernate:
+ **/
+gboolean
+dkp_client_hibernate (DkpClient *client, GError **error)
+{
+ gboolean ret;
+ GError *error_local = NULL;
+
+ g_return_val_if_fail (DKP_IS_CLIENT (client), FALSE);
+ g_return_val_if_fail (client->priv->proxy != NULL, FALSE);
+
+ ret = dbus_g_proxy_call (client->priv->proxy, "Hibernate", &error_local,
+ G_TYPE_INVALID, G_TYPE_INVALID);
+ if (!ret) {
+ egg_warning ("Couldn't hibernate: %s", error_local->message);
+ if (error != NULL)
+ *error = g_error_new (1, 0, "%s", error_local->message);
+ g_error_free (error_local);
+ }
+ return ret;
+}
+
+/**
* dkp_client_ensure_properties:
**/
static void
@@ -231,14 +299,14 @@ dkp_client_on_low_battery (DkpClient *client)
/**
* dkp_client_add:
**/
-static DkpClientDevice *
+static DkpDevice *
dkp_client_add (DkpClient *client, const gchar *object_path)
{
- DkpClientDevice *device;
+ DkpDevice *device;
/* create new device */
- device = dkp_client_device_new ();
- dkp_client_device_set_object_path (device, object_path);
+ device = dkp_device_new ();
+ dkp_device_set_object_path (device, object_path);
g_ptr_array_add (client->priv->array, device);
g_hash_table_insert (client->priv->hash, g_strdup (object_path), device);
@@ -249,7 +317,7 @@ dkp_client_add (DkpClient *client, const gchar *object_path)
* dkp_client_remove:
**/
static gboolean
-dkp_client_remove (DkpClient *client, DkpClientDevice *device)
+dkp_client_remove (DkpClient *client, DkpDevice *device)
{
/* deallocate it */
g_object_unref (device);
@@ -263,37 +331,37 @@ dkp_client_remove (DkpClient *client, DkpClientDevice *device)
* dkp_client_added_cb:
**/
static void
-dkp_client_device_added_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
+dkp_device_added_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
{
- DkpClientDevice *device;
+ DkpDevice *device;
/* create new device */
device = dkp_client_add (client, object_path);
- g_signal_emit (client, signals [DKP_CLIENT_DEVICE_ADDED], 0, device);
+ g_signal_emit (client, signals [DKP_DEVICE_ADDED], 0, device);
}
/**
* dkp_client_changed_cb:
**/
static void
-dkp_client_device_changed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
+dkp_device_changed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
{
- DkpClientDevice *device;
+ DkpDevice *device;
device = dkp_client_get_device (client, object_path);
if (device != NULL)
- g_signal_emit (client, signals [DKP_CLIENT_DEVICE_CHANGED], 0, device);
+ g_signal_emit (client, signals [DKP_DEVICE_CHANGED], 0, device);
}
/**
* dkp_client_removed_cb:
**/
static void
-dkp_client_device_removed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
+dkp_device_removed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
{
- DkpClientDevice *device;
+ DkpDevice *device;
device = dkp_client_get_device (client, object_path);
if (device != NULL)
- g_signal_emit (client, signals [DKP_CLIENT_DEVICE_REMOVED], 0, device);
+ g_signal_emit (client, signals [DKP_DEVICE_REMOVED], 0, device);
dkp_client_remove (client, device);
}
@@ -317,19 +385,19 @@ dkp_client_class_init (DkpClientClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = dkp_client_finalize;
- signals [DKP_CLIENT_DEVICE_ADDED] =
+ signals [DKP_DEVICE_ADDED] =
g_signal_new ("device-added",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DkpClientClass, device_added),
NULL, NULL, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
- signals [DKP_CLIENT_DEVICE_REMOVED] =
+ signals [DKP_DEVICE_REMOVED] =
g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DkpClientClass, device_removed),
NULL, NULL, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
- signals [DKP_CLIENT_DEVICE_CHANGED] =
+ signals [DKP_DEVICE_CHANGED] =
g_signal_new ("device-changed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DkpClientClass, device_changed),
@@ -395,16 +463,16 @@ dkp_client_init (DkpClient *client)
/* all callbacks */
dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceAdded",
- G_CALLBACK (dkp_client_device_added_cb), client, NULL);
+ G_CALLBACK (dkp_device_added_cb), client, NULL);
dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceRemoved",
- G_CALLBACK (dkp_client_device_removed_cb), client, NULL);
+ G_CALLBACK (dkp_device_removed_cb), client, NULL);
dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceChanged",
- G_CALLBACK (dkp_client_device_changed_cb), client, NULL);
+ G_CALLBACK (dkp_device_changed_cb), client, NULL);
dbus_g_proxy_connect_signal (client->priv->proxy, "Changed",
G_CALLBACK (dkp_client_changed_cb), client, NULL);
/* coldplug */
- devices = dkp_client_enumerate_devices (client, NULL);
+ devices = dkp_client_enumerate_devices_private (client, NULL);
if (devices == NULL)
goto out;
for (i=0; i<devices->len; i++) {
@@ -423,7 +491,7 @@ static void
dkp_client_finalize (GObject *object)
{
DkpClient *client;
- DkpClientDevice *device;
+ DkpDevice *device;
guint i;
g_return_if_fail (DKP_IS_CLIENT (object));
@@ -432,7 +500,7 @@ dkp_client_finalize (GObject *object)
/* free any devices */
for (i=0; i<client->priv->array->len; i++) {
- device = (DkpClientDevice *) g_ptr_array_index (client->priv->array, i);
+ device = (DkpDevice *) g_ptr_array_index (client->priv->array, i);
dkp_client_remove (client, device);
}
diff --git a/libdevkit-power/dkp-client.h b/libdevkit-power/dkp-client.h
index 2582109..9422f05 100644
--- a/libdevkit-power/dkp-client.h
+++ b/libdevkit-power/dkp-client.h
@@ -24,7 +24,7 @@
#include <glib-object.h>
#include <dkp-enum.h>
-#include "dkp-client-device.h"
+#include "dkp-device.h"
G_BEGIN_DECLS
@@ -49,25 +49,26 @@ typedef struct
{
GObjectClass parent_class;
void (*device_added) (DkpClient *client,
- const DkpClientDevice *device);
+ const DkpDevice *device);
void (*device_changed) (DkpClient *client,
- const DkpClientDevice *device);
+ const DkpDevice *device);
void (*device_removed) (DkpClient *client,
- const DkpClientDevice *device);
- void (*changed) (DkpClient *client,
- gboolean on_battery);
+ const DkpDevice *device);
+ void (*changed) (DkpClient *client);
} DkpClientClass;
GType dkp_client_get_type (void) G_GNUC_CONST;
DkpClient *dkp_client_new (void);
-GPtrArray *dkp_client_enumerate_devices (DkpClient *client,
+GPtrArray *dkp_client_enumerate_devices (DkpClient *client);
+gboolean dkp_client_suspend (DkpClient *client,
GError **error);
-
-const gchar *dkp_client_get_daemon_version (DkpClient *client);
-gboolean dkp_client_can_hibernate (DkpClient *client);
-gboolean dkp_client_can_suspend (DkpClient *client);
-gboolean dkp_client_on_battery (DkpClient *client);
-gboolean dkp_client_on_low_battery (DkpClient *client);
+gboolean dkp_client_hibernate (DkpClient *client,
+ GError **error);
+const gchar *dkp_client_get_daemon_version (DkpClient *client);
+gboolean dkp_client_can_hibernate (DkpClient *client);
+gboolean dkp_client_can_suspend (DkpClient *client);
+gboolean dkp_client_on_battery (DkpClient *client);
+gboolean dkp_client_on_low_battery (DkpClient *client);
G_END_DECLS
diff --git a/libdevkit-power/dkp-object.c b/libdevkit-power/dkp-object.c
index 931bc52..12158e2 100644
--- a/libdevkit-power/dkp-object.c
+++ b/libdevkit-power/dkp-object.c
@@ -510,6 +510,7 @@ dkp_object_get_id (DkpObject *obj)
g_string_append_c (string, '-');
}
if (obj->energy_full_design > 0) {
+ /* FIXME: this may not be stable if we are using voltage_now */
g_string_append_printf (string, "%i", (guint) obj->energy_full_design);
g_string_append_c (string, '-');
}