gnome-power-manager r3204 - in trunk: . data libdevkit-power src
- From: rhughes svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-power-manager r3204 - in trunk: . data libdevkit-power src
- Date: Fri, 30 Jan 2009 16:38:33 +0000 (UTC)
Author: rhughes
Date: Fri Jan 30 16:38:33 2009
New Revision: 3204
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=3204&view=rev
Log:
2009-01-30 Richard Hughes <richard hughsie com>
* libdevkit-power/Makefile.am:
* libdevkit-power/dkp-wakeups-obj.c:
(dkp_wakeups_obj_clear_internal), (dkp_wakeups_obj_copy),
(dkp_wakeups_obj_equal), (dkp_wakeups_obj_print),
(dkp_wakeups_obj_new), (dkp_wakeups_obj_free):
* libdevkit-power/dkp-wakeups-obj.h:
* libdevkit-power/dkp-wakeups.c: (dkp_wakeups_get_total),
(dkp_wakeups_get_data), (dkp_wakeups_total_changed_cb),
(dkp_wakeups_data_changed_cb), (dkp_wakeups_class_init),
(dkp_wakeups_init), (dkp_wakeups_finalize), (dkp_wakeups_new):
* libdevkit-power/dkp-wakeups.h:
Add the new GObject client functions for the wakeup functionality.
* data/gpm-statistics.glade:
* src/gpm-statistics.c: (gpm_stats_add_wakeups_columns),
(gpm_stats_update_info_data), (gpm_stats_add_wakeups_obj),
(gpm_stats_update_wakeups_data), (gpm_stats_set_title),
(gpm_stats_notebook_changed_cb),
(gpm_stats_devices_treeview_clicked_cb),
(gpm_stats_data_changed_cb), (main):
Add processor wakeup support into gnome-power-statistics.
This requires DeviceKit-power from git master.
Added:
trunk/libdevkit-power/dkp-wakeups-obj.c
trunk/libdevkit-power/dkp-wakeups-obj.h
trunk/libdevkit-power/dkp-wakeups.c
trunk/libdevkit-power/dkp-wakeups.h
Modified:
trunk/ChangeLog
trunk/data/gpm-statistics.glade
trunk/libdevkit-power/Makefile.am
trunk/src/gpm-statistics.c
Modified: trunk/data/gpm-statistics.glade
==============================================================================
--- trunk/data/gpm-statistics.glade (original)
+++ trunk/data/gpm-statistics.glade Fri Jan 30 16:38:33 2009
@@ -356,6 +356,73 @@
<property name="tab_fill">False</property>
</packing>
</child>
+ <child>
+ <widget class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="border_width">9</property>
+ <property name="spacing">9</property>
+ <child>
+ <widget class="GtkHBox" id="hbox3">
+ <property name="visible">True</property>
+ <property name="spacing">3</property>
+ <child>
+ <widget class="GtkLabel" id="label8">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Processor wakeups per second:</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label_total_wakeups">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">0</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkScrolledWindow" id="scrolledwindow3">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="shadow_type">GTK_SHADOW_IN</property>
+ <child>
+ <widget class="GtkTreeView" id="treeview_wakeups">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="label7">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Wakeups</property>
+ </widget>
+ <packing>
+ <property name="type">tab</property>
+ <property name="position">3</property>
+ <property name="tab_fill">False</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="position">1</property>
Modified: trunk/libdevkit-power/Makefile.am
==============================================================================
--- trunk/libdevkit-power/Makefile.am (original)
+++ trunk/libdevkit-power/Makefile.am Fri Jan 30 16:38:33 2009
@@ -21,8 +21,12 @@
egg-obj-list.h \
dkp-client.c \
dkp-client.h \
- dkp-device.c \
- dkp-device.h \
+ dkp-device.c \
+ dkp-device.h \
+ dkp-wakeups-obj.c \
+ dkp-wakeups-obj.h \
+ dkp-wakeups.c \
+ dkp-wakeups.h \
dkp-history-obj.h \
dkp-history-obj.c \
dkp-stats-obj.h \
Added: trunk/libdevkit-power/dkp-wakeups-obj.c
==============================================================================
--- (empty file)
+++ trunk/libdevkit-power/dkp-wakeups-obj.c Fri Jan 30 16:38:33 2009
@@ -0,0 +1,104 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 Richard Hughes <richard hughsie com>
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "egg-debug.h"
+#include "dkp-enum.h"
+#include "dkp-wakeups-obj.h"
+
+/**
+ * dkp_wakeups_obj_clear_internal:
+ **/
+static void
+dkp_wakeups_obj_clear_internal (DkpWakeupsObj *obj)
+{
+ obj->id = 0;
+ obj->old = 0;
+ obj->value = 0.0f;
+ obj->is_userspace = FALSE;
+ obj->cmdline = NULL;
+ obj->details = NULL;
+}
+
+/**
+ * dkp_wakeups_obj_copy:
+ **/
+DkpWakeupsObj *
+dkp_wakeups_obj_copy (const DkpWakeupsObj *cobj)
+{
+ DkpWakeupsObj *obj;
+ obj = g_new0 (DkpWakeupsObj, 1);
+ obj->id = cobj->id;
+ obj->value = cobj->value;
+ obj->is_userspace = cobj->is_userspace;
+ return obj;
+}
+
+/**
+ * dkp_wakeups_obj_equal:
+ **/
+gboolean
+dkp_wakeups_obj_equal (const DkpWakeupsObj *obj1, const DkpWakeupsObj *obj2)
+{
+ if (obj1->id == obj2->id)
+ return TRUE;
+ return FALSE;
+}
+
+/**
+ * dkp_wakeups_obj_print:
+ **/
+gboolean
+dkp_wakeups_obj_print (const DkpWakeupsObj *obj)
+{
+ g_print ("userspace:%i id:%i, interrupts:%.1f, cmdline:%s, details:%s\n", obj->is_userspace, obj->id, obj->value, obj->cmdline, obj->details);
+ return TRUE;
+}
+
+/**
+ * dkp_wakeups_obj_new:
+ **/
+DkpWakeupsObj *
+dkp_wakeups_obj_new (void)
+{
+ DkpWakeupsObj *obj;
+ obj = g_new0 (DkpWakeupsObj, 1);
+ dkp_wakeups_obj_clear_internal (obj);
+ return obj;
+}
+
+/**
+ * dkp_wakeups_obj_free:
+ **/
+void
+dkp_wakeups_obj_free (DkpWakeupsObj *obj)
+{
+ if (obj == NULL)
+ return;
+ g_free (obj->cmdline);
+ g_free (obj->details);
+ g_free (obj);
+ return;
+}
+
Added: trunk/libdevkit-power/dkp-wakeups-obj.h
==============================================================================
--- (empty file)
+++ trunk/libdevkit-power/dkp-wakeups-obj.h Fri Jan 30 16:38:33 2009
@@ -0,0 +1,49 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 Richard Hughes <richard hughsie com>
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __DKP_WAKEUPS_OBJ_H__
+#define __DKP_WAKEUPS_OBJ_H__
+
+#include <glib.h>
+#include "dkp-enum.h"
+
+G_BEGIN_DECLS
+
+typedef struct
+{
+ gboolean is_userspace;
+ guint id;
+ guint old;
+ gfloat value;
+ gchar *cmdline;
+ gchar *details;
+} DkpWakeupsObj;
+
+DkpWakeupsObj *dkp_wakeups_obj_new (void);
+void dkp_wakeups_obj_free (DkpWakeupsObj *obj);
+DkpWakeupsObj *dkp_wakeups_obj_copy (const DkpWakeupsObj *cobj);
+gboolean dkp_wakeups_obj_print (const DkpWakeupsObj *obj);
+gboolean dkp_wakeups_obj_equal (const DkpWakeupsObj *obj1,
+ const DkpWakeupsObj *obj2);
+
+G_END_DECLS
+
+#endif /* __DKP_WAKEUPS_OBJ_H__ */
+
Added: trunk/libdevkit-power/dkp-wakeups.c
==============================================================================
--- (empty file)
+++ trunk/libdevkit-power/dkp-wakeups.c Fri Jan 30 16:38:33 2009
@@ -0,0 +1,282 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 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 "dkp-wakeups.h"
+
+static void dkp_wakeups_class_init (DkpWakeupsClass *klass);
+static void dkp_wakeups_init (DkpWakeups *wakeups);
+static void dkp_wakeups_finalize (GObject *object);
+
+#define DKP_WAKEUPS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_TYPE_WAKEUPS, DkpWakeupsPrivate))
+
+struct DkpWakeupsPrivate
+{
+ DBusGConnection *bus;
+ DBusGProxy *proxy;
+};
+
+enum {
+ DKP_WAKEUPS_DATA_CHANGED,
+ DKP_WAKEUPS_TOTAL_CHANGED,
+ DKP_WAKEUPS_LAST_SIGNAL
+};
+
+static guint signals [DKP_WAKEUPS_LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (DkpWakeups, dkp_wakeups, G_TYPE_OBJECT)
+
+/**
+ * dkp_wakeups_get_total:
+ **/
+guint
+dkp_wakeups_get_total (DkpWakeups *wakeups, GError **error)
+{
+ guint total = 0;
+ gboolean ret;
+ GError *error_local = NULL;
+
+ g_return_val_if_fail (DKP_IS_WAKEUPS (wakeups), FALSE);
+ g_return_val_if_fail (wakeups->priv->proxy != NULL, FALSE);
+
+ ret = dbus_g_proxy_call (wakeups->priv->proxy, "GetTotal", &error_local,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &total,
+ G_TYPE_INVALID);
+ if (!ret) {
+ egg_warning ("Couldn't get total: %s", error_local->message);
+ if (error != NULL)
+ *error = g_error_new (1, 0, "%s", error_local->message);
+ g_error_free (error_local);
+ }
+ return total;
+}
+
+/**
+ * dkp_wakeups_get_data:
+ *
+ * Returns an array of %DkpWakeupsObj's
+ **/
+GPtrArray *
+dkp_wakeups_get_data (DkpWakeups *wakeups, GError **error)
+{
+ GError *error_local = NULL;
+ GType g_type_gvalue_array;
+ GPtrArray *gvalue_ptr_array = NULL;
+ GValueArray *gva;
+ GValue *gv;
+ guint i;
+ DkpWakeupsObj *obj;
+ GPtrArray *array = NULL;
+ gboolean ret;
+
+ g_return_val_if_fail (DKP_IS_WAKEUPS (wakeups), FALSE);
+ g_return_val_if_fail (wakeups->priv->proxy != NULL, FALSE);
+
+ g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
+ dbus_g_type_get_struct("GValueArray",
+ G_TYPE_BOOLEAN,
+ G_TYPE_UINT,
+ G_TYPE_DOUBLE,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_INVALID));
+
+ /* get compound data */
+ ret = dbus_g_proxy_call (wakeups->priv->proxy, "GetData", &error_local,
+ G_TYPE_INVALID,
+ g_type_gvalue_array, &gvalue_ptr_array,
+ G_TYPE_INVALID);
+ if (!ret) {
+ egg_debug ("GetData on failed: %s", error_local->message);
+ if (error != NULL)
+ *error = g_error_new (1, 0, "%s", error_local->message);
+ g_error_free (error_local);
+ goto out;
+ }
+
+ /* no data */
+ if (gvalue_ptr_array->len == 0)
+ goto out;
+
+ /* convert */
+ array = g_ptr_array_new ();
+ for (i=0; i<gvalue_ptr_array->len; i++) {
+ gva = (GValueArray *) g_ptr_array_index (gvalue_ptr_array, i);
+ obj = dkp_wakeups_obj_new ();
+
+ /* 0 */
+ gv = g_value_array_get_nth (gva, 0);
+ obj->is_userspace = g_value_get_boolean (gv);
+ g_value_unset (gv);
+
+ /* 1 */
+ gv = g_value_array_get_nth (gva, 1);
+ obj->id = g_value_get_uint (gv);
+ g_value_unset (gv);
+
+ /* 2 */
+ gv = g_value_array_get_nth (gva, 2);
+ obj->value = g_value_get_double (gv);
+ g_value_unset (gv);
+
+ /* 3 */
+ gv = g_value_array_get_nth (gva, 3);
+ obj->cmdline = g_strdup (g_value_get_string (gv));
+ g_value_unset (gv);
+
+ /* 4 */
+ gv = g_value_array_get_nth (gva, 4);
+ obj->details = g_strdup (g_value_get_string (gv));
+ g_value_unset (gv);
+
+ /* add */
+ g_ptr_array_add (array, obj);
+ g_value_array_free (gva);
+ }
+out:
+ if (gvalue_ptr_array != NULL)
+ g_ptr_array_free (gvalue_ptr_array, TRUE);
+ return array;
+}
+
+/**
+ * dkp_wakeups_total_changed_cb:
+ **/
+static void
+dkp_wakeups_total_changed_cb (DBusGProxy *proxy, guint value, DkpWakeups *wakeups)
+{
+ g_signal_emit (wakeups, signals [DKP_WAKEUPS_TOTAL_CHANGED], 0, value);
+}
+
+/**
+ * dkp_wakeups_data_changed_cb:
+ **/
+static void
+dkp_wakeups_data_changed_cb (DBusGProxy *proxy, DkpWakeups *wakeups)
+{
+ g_signal_emit (wakeups, signals [DKP_WAKEUPS_DATA_CHANGED], 0);
+}
+
+/**
+ * dkp_wakeups_class_init:
+ * @klass: The DkpWakeupsClass
+ **/
+static void
+dkp_wakeups_class_init (DkpWakeupsClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = dkp_wakeups_finalize;
+
+ signals [DKP_WAKEUPS_DATA_CHANGED] =
+ g_signal_new ("data-changed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (DkpWakeupsClass, data_changed),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals [DKP_WAKEUPS_TOTAL_CHANGED] =
+ g_signal_new ("total-changed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (DkpWakeupsClass, data_changed),
+ NULL, NULL, g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1, G_TYPE_UINT);
+
+ g_type_class_add_private (klass, sizeof (DkpWakeupsPrivate));
+}
+
+/**
+ * dkp_wakeups_init:
+ * @wakeups: This class instance
+ **/
+static void
+dkp_wakeups_init (DkpWakeups *wakeups)
+{
+ GError *error = NULL;
+
+ wakeups->priv = DKP_WAKEUPS_GET_PRIVATE (wakeups);
+
+ /* get on the bus */
+ wakeups->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (wakeups->priv->bus == NULL) {
+ egg_warning ("Couldn't connect to system bus: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* connect to main interface */
+ wakeups->priv->proxy = dbus_g_proxy_new_for_name (wakeups->priv->bus,
+ "org.freedesktop.DeviceKit.Power",
+ "/org/freedesktop/DeviceKit/Power/Wakeups",
+ "org.freedesktop.DeviceKit.Power.Wakeups");
+ if (wakeups->priv->proxy == NULL) {
+ egg_warning ("Couldn't connect to proxy");
+ goto out;
+ }
+ dbus_g_proxy_add_signal (wakeups->priv->proxy, "TotalChanged", G_TYPE_UINT, G_TYPE_INVALID);
+ dbus_g_proxy_add_signal (wakeups->priv->proxy, "DataChanged", G_TYPE_INVALID);
+
+ /* all callbacks */
+ dbus_g_proxy_connect_signal (wakeups->priv->proxy, "TotalChanged",
+ G_CALLBACK (dkp_wakeups_total_changed_cb), wakeups, NULL);
+ dbus_g_proxy_connect_signal (wakeups->priv->proxy, "DataChanged",
+ G_CALLBACK (dkp_wakeups_data_changed_cb), wakeups, NULL);
+out:
+ return;
+}
+
+/**
+ * dkp_wakeups_finalize:
+ * @object: The object to finalize
+ **/
+static void
+dkp_wakeups_finalize (GObject *object)
+{
+ DkpWakeups *wakeups;
+
+ g_return_if_fail (DKP_IS_WAKEUPS (object));
+
+ wakeups = DKP_WAKEUPS (object);
+ if (wakeups->priv->proxy != NULL)
+ g_object_unref (wakeups->priv->proxy);
+
+ G_OBJECT_CLASS (dkp_wakeups_parent_class)->finalize (object);
+}
+
+/**
+ * dkp_wakeups_new:
+ *
+ * Return value: a new DkpWakeups object.
+ **/
+DkpWakeups *
+dkp_wakeups_new (void)
+{
+ DkpWakeups *wakeups;
+ wakeups = g_object_new (DKP_TYPE_WAKEUPS, NULL);
+ return DKP_WAKEUPS (wakeups);
+}
+
Added: trunk/libdevkit-power/dkp-wakeups.h
==============================================================================
--- (empty file)
+++ trunk/libdevkit-power/dkp-wakeups.h Fri Jan 30 16:38:33 2009
@@ -0,0 +1,67 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 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_WAKEUPS_H
+#define __DKP_WAKEUPS_H
+
+#include <glib-object.h>
+#include <dkp-enum.h>
+#include "dkp-device.h"
+#include "dkp-wakeups-obj.h"
+
+G_BEGIN_DECLS
+
+#define DKP_TYPE_WAKEUPS (dkp_wakeups_get_type ())
+#define DKP_WAKEUPS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_TYPE_WAKEUPS, DkpWakeups))
+#define DKP_WAKEUPS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_TYPE_WAKEUPS, DkpWakeupsClass))
+#define DKP_IS_WAKEUPS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_TYPE_WAKEUPS))
+#define DKP_IS_WAKEUPS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DKP_TYPE_WAKEUPS))
+#define DKP_WAKEUPS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DKP_TYPE_WAKEUPS, DkpWakeupsClass))
+#define DKP_WAKEUPS_ERROR (dkp_wakeups_error_quark ())
+#define DKP_WAKEUPS_TYPE_ERROR (dkp_wakeups_error_get_type ())
+
+typedef struct DkpWakeupsPrivate DkpWakeupsPrivate;
+
+typedef struct
+{
+ GObject parent;
+ DkpWakeupsPrivate *priv;
+} DkpWakeups;
+
+typedef struct
+{
+ GObjectClass parent_class;
+ void (*data_changed) (DkpWakeups *wakeups);
+ void (*total_changed) (DkpWakeups *wakeups,
+ guint value);
+} DkpWakeupsClass;
+
+GType dkp_wakeups_get_type (void) G_GNUC_CONST;
+DkpWakeups *dkp_wakeups_new (void);
+guint dkp_wakeups_get_total (DkpWakeups *wakeups,
+ GError **error);
+GPtrArray *dkp_wakeups_get_data (DkpWakeups *wakeups,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __DKP_WAKEUPS_H */
+
Modified: trunk/src/gpm-statistics.c
==============================================================================
--- trunk/src/gpm-statistics.c (original)
+++ trunk/src/gpm-statistics.c Fri Jan 30 16:38:33 2009
@@ -46,16 +46,19 @@
#include "dkp-history-obj.h"
#include "dkp-stats-obj.h"
#include "dkp-device.h"
+#include "dkp-wakeups.h"
static GladeXML *glade_xml = NULL;
static GtkListStore *list_store_info = NULL;
static GtkListStore *list_store_devices = NULL;
+static GtkListStore *list_store_wakeups = NULL;
gchar *current_device = NULL;
static const gchar *history_type;
static const gchar *stats_type;
static guint history_time;
static GConfClient *gconf_client;
static gfloat sigma_smoothing = 0.0f;
+static DkpWakeups *wakeups = NULL;
enum {
GPM_INFO_COLUMN_TEXT,
@@ -70,6 +73,15 @@
GPM_DEVICES_COLUMN_LAST
};
+enum {
+ GPM_WAKEUPS_COLUMN_ICON,
+ GPM_WAKEUPS_COLUMN_ID,
+ GPM_WAKEUPS_COLUMN_VALUE,
+ GPM_WAKEUPS_COLUMN_CMDLINE,
+ GPM_WAKEUPS_COLUMN_DETAILS,
+ GPM_WAKEUPS_COLUMN_LAST
+};
+
#define GPM_HISTORY_RATE_TEXT _("Rate")
#define GPM_HISTORY_CHARGE_TEXT _("Charge")
#define GPM_HISTORY_TIME_FULL_TEXT _("Time to full")
@@ -158,6 +170,51 @@
}
/**
+ * gpm_stats_add_wakeups_columns:
+ **/
+static void
+gpm_stats_add_wakeups_columns (GtkTreeView *treeview)
+{
+ GtkCellRenderer *renderer;
+ GtkTreeViewColumn *column;
+
+ /* image */
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL);
+ column = gtk_tree_view_column_new_with_attributes (_("Type"), renderer,
+ "icon-name", GPM_WAKEUPS_COLUMN_ICON, NULL);
+ gtk_tree_view_append_column (treeview, column);
+
+ /* column for id */
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (_("ID"), renderer,
+ "markup", GPM_WAKEUPS_COLUMN_ID, NULL);
+ gtk_tree_view_append_column (treeview, column);
+ gtk_tree_view_column_set_expand (column, TRUE);
+
+ /* column for value */
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (_("Wakeups"), renderer,
+ "markup", GPM_WAKEUPS_COLUMN_VALUE, NULL);
+ gtk_tree_view_append_column (treeview, column);
+ gtk_tree_view_column_set_expand (column, TRUE);
+
+ /* column for cmdline */
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (_("Command"), renderer,
+ "markup", GPM_WAKEUPS_COLUMN_CMDLINE, NULL);
+ gtk_tree_view_append_column (treeview, column);
+ gtk_tree_view_column_set_expand (column, TRUE);
+
+ /* column for details */
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes (_("Details"), renderer,
+ "markup", GPM_WAKEUPS_COLUMN_DETAILS, NULL);
+ gtk_tree_view_append_column (treeview, column);
+ gtk_tree_view_column_set_expand (column, TRUE);
+}
+
+/**
* gpm_stats_add_info_data:
**/
static void
@@ -576,6 +633,10 @@
widget = glade_xml_get_widget (glade_xml, "notebook1");
obj = dkp_device_get_object (device);
+ /* show info page */
+ page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 0);
+ gtk_widget_show (page_widget);
+
/* hide history if no support */
page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 1);
if (obj->has_history)
@@ -590,12 +651,136 @@
else
gtk_widget_hide (page_widget);
+ /* hide wakeups page */
+ page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 3);
+ gtk_widget_hide (page_widget);
+
page = gtk_notebook_get_current_page (GTK_NOTEBOOK (widget));
gpm_stats_update_info_data_page (device, page);
return;
}
+/**
+ * gpm_stats_add_wakeups_obj:
+ **/
+static void
+gpm_stats_add_wakeups_obj (const DkpWakeupsObj *obj)
+{
+ const gchar *icon;
+ gchar *value;
+ gchar *cmdline;
+ gchar *id;
+ const gchar *cmdline_ptr;
+ gchar *cmdline_escaped;
+ gchar *details;
+ gchar *found;
+ GtkTreeIter iter;
+
+ if (obj->is_userspace) {
+ icon = "application-x-executable";
+ id = g_strdup_printf ("%i", obj->id);
+ } else {
+ icon = "applications-system";
+ if (obj->id < 0xff0)
+ id = g_strdup_printf ("IRQ%i", obj->id);
+ else
+ id = g_strdup ("IRQx");
+ }
+
+ /* formate value to one decimal place */
+ value = g_strdup_printf ("%.1f", obj->value);
+
+ /* truncate at first space or ':' */
+ cmdline = g_strdup (obj->cmdline);
+ found = strstr (cmdline, ":");
+ if (found != NULL)
+ *found = '\0';
+ found = strstr (cmdline, " ");
+ if (found != NULL)
+ *found = '\0';
+
+ /* remove ./ */
+ found = g_strrstr (cmdline, "/");
+ if (found != NULL)
+ cmdline_ptr = found + 1;
+ else
+ cmdline_ptr = cmdline;
+
+ /* format command line */
+ cmdline_escaped = g_markup_escape_text (cmdline_ptr, -1);
+
+ /* format details */
+ details = g_markup_escape_text (obj->details, -1);
+
+ gtk_list_store_append (list_store_wakeups, &iter);
+ gtk_list_store_set (list_store_wakeups, &iter,
+ GPM_WAKEUPS_COLUMN_ID, id,
+ GPM_WAKEUPS_COLUMN_VALUE, value,
+ GPM_WAKEUPS_COLUMN_CMDLINE, cmdline_escaped,
+ GPM_WAKEUPS_COLUMN_DETAILS, details,
+ GPM_WAKEUPS_COLUMN_ICON, icon, -1);
+ g_free (cmdline);
+ g_free (cmdline_escaped);
+ g_free (details);
+ g_free (value);
+ g_free (id);
+}
+
+/**
+ * gpm_stats_update_wakeups_data:
+ **/
+static void
+gpm_stats_update_wakeups_data (void)
+{
+ GtkWidget *widget;
+ GtkWidget *page_widget;
+ guint total;
+ DkpWakeupsObj *obj;
+ gchar *text;
+ guint i;
+ GError *error = NULL;
+ GPtrArray *array;
+
+ widget = glade_xml_get_widget (glade_xml, "notebook1");
+
+ /* hide other pages */
+ page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 0);
+ gtk_widget_hide (page_widget);
+ page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 1);
+ gtk_widget_hide (page_widget);
+ page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 2);
+ gtk_widget_hide (page_widget);
+
+ /* show wakeups page */
+ page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 3);
+ gtk_widget_show (page_widget);
+
+ /* show total */
+ total = dkp_wakeups_get_total (wakeups, &error);
+ widget = glade_xml_get_widget (glade_xml, "label_total_wakeups");
+ if (error == NULL) {
+ text = g_strdup_printf ("%i", total);
+ gtk_label_set_label (GTK_LABEL(widget), text);
+ g_free (text);
+ } else {
+ gtk_label_set_label (GTK_LABEL(widget), error->message);
+ g_error_free (error);
+ }
+
+ /* get data */
+ gtk_list_store_clear (list_store_wakeups);
+ array = dkp_wakeups_get_data (wakeups, NULL);
+ if (array == NULL)
+ return;
+ for (i=0; i<array->len; i++) {
+ obj = g_ptr_array_index (array, i);
+ gpm_stats_add_wakeups_obj (obj);
+ }
+ g_ptr_array_foreach (array, (GFunc) dkp_wakeups_obj_free, NULL);
+ g_ptr_array_free (array, TRUE);
+}
+
static void
gpm_stats_set_title (GtkWindow *window, gint page_num)
{
@@ -603,7 +788,8 @@
const gchar * const page_titles[] = {
N_("Device Information"),
N_("Device History"),
- N_("Device Profile")
+ N_("Device Profile"),
+ N_("Processor Wakeups")
};
title = g_strdup_printf ("%s - %s", _("Power Statistics"), _(page_titles[page_num]));
@@ -630,6 +816,9 @@
if (current_device == NULL)
return;
+ if (egg_strequal (current_device, "wakeups"))
+ return;
+
device = dkp_device_new ();
dkp_device_set_object_path (device, current_device);
gpm_stats_update_info_data_page (device, page_num);
@@ -685,10 +874,15 @@
/* show transaction_id */
egg_debug ("selected row is: %s", current_device);
- device = dkp_device_new ();
- dkp_device_set_object_path (device, current_device);
- gpm_stats_update_info_data (device);
- g_object_unref (device);
+ /* is special device */
+ if (egg_strequal (current_device, "wakeups")) {
+ gpm_stats_update_wakeups_data ();
+ } else {
+ device = dkp_device_new ();
+ dkp_device_set_object_path (device, current_device);
+ gpm_stats_update_info_data (device);
+ g_object_unref (device);
+ }
} else {
egg_debug ("no row selected");
@@ -747,6 +941,15 @@
}
/**
+ * gpm_stats_data_changed_cb:
+ **/
+static void
+gpm_stats_data_changed_cb (DkpClient *client, gpointer user_data)
+{
+ gpm_stats_update_wakeups_data ();
+}
+
+/**
* gpm_stats_device_added_cb:
**/
static void
@@ -1106,6 +1309,8 @@
list_store_info = gtk_list_store_new (GPM_INFO_COLUMN_LAST, G_TYPE_STRING, G_TYPE_STRING);
list_store_devices = gtk_list_store_new (GPM_DEVICES_COLUMN_LAST, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING);
+ list_store_wakeups = gtk_list_store_new (GPM_WAKEUPS_COLUMN_LAST, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
/* create transaction_id tree view */
widget = glade_xml_get_widget (glade_xml, "treeview_info");
@@ -1128,6 +1333,16 @@
gpm_stats_add_devices_columns (GTK_TREE_VIEW (widget));
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)); /* show */
+ /* create wakeups tree view */
+ widget = glade_xml_get_widget (glade_xml, "treeview_wakeups");
+ gtk_tree_view_set_model (GTK_TREE_VIEW (widget),
+ GTK_TREE_MODEL (list_store_wakeups));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
+
+ /* add columns to the tree view */
+ gpm_stats_add_wakeups_columns (GTK_TREE_VIEW (widget));
+ gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)); /* show */
+
history_type = gconf_client_get_string (gconf_client, GPM_CONF_INFO_HISTORY_TYPE, NULL);
history_time = gconf_client_get_int (gconf_client, GPM_CONF_INFO_HISTORY_TIME, NULL);
if (history_type == NULL)
@@ -1196,6 +1411,9 @@
g_signal_connect (client, "device-removed", G_CALLBACK (gpm_stats_device_removed_cb), NULL);
g_signal_connect (client, "device-changed", G_CALLBACK (gpm_stats_device_changed_cb), NULL);
+ wakeups = dkp_wakeups_new ();
+ g_signal_connect (wakeups, "data-changed", G_CALLBACK (gpm_stats_data_changed_cb), NULL);
+
/* coldplug */
devices = dkp_client_enumerate_devices (client);
if (devices == NULL)
@@ -1211,6 +1429,17 @@
last_device = gconf_client_get_string (gconf_client, GPM_CONF_INFO_LAST_DEVICE, NULL);
+ /* can we get wakeup data? */
+ i = dkp_wakeups_get_total (wakeups, NULL);
+ if (i > 0) {
+ GtkTreeIter iter;
+ gtk_list_store_append (list_store_devices, &iter);
+ gtk_list_store_set (list_store_devices, &iter,
+ GPM_DEVICES_COLUMN_ID, "wakeups",
+ GPM_DEVICES_COLUMN_TEXT, _("Processor"),
+ GPM_DEVICES_COLUMN_ICON, "computer", -1);
+ }
+
/* set the correct focus on the last device */
for (i=0; i < devices->len; i++) {
object_path = (const gchar *) g_ptr_array_index (devices, i);
@@ -1245,6 +1474,7 @@
out:
g_object_unref (gconf_client);
g_object_unref (client);
+ g_object_unref (wakeups);
g_object_unref (glade_xml);
g_object_unref (list_store_info);
unique_out:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]