summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-07-24 17:52:51 +0100
committerRichard Hughes <richard@hughsie.com>2008-07-24 17:52:51 +0100
commitf1c5630274195d4c613b95a49200ac48c3130f11 (patch)
treef766826d4e2096f2fcd2de444062a7e6eb06d098
parent8a04a2c3eda34f049a0d2190070c9c9e19ee46ec (diff)
downloadupower-f1c5630274195d4c613b95a49200ac48c3130f11.tar.gz
split out the enumerated stuff into devkit-power-enum.[c|h] as they'll be more soon
-rw-r--r--src/Makefile.am1
-rw-r--r--src/devkit-power-enum.c56
-rw-r--r--src/devkit-power-enum.h45
-rw-r--r--src/devkit-power-source.c24
4 files changed, 112 insertions, 14 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 1db6572..192b154 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -41,6 +41,7 @@ devkit_power_daemon_SOURCES = \
devkit-power-daemon.h devkit-power-daemon.c \
devkit-power-device.h devkit-power-device.c \
devkit-power-source.h devkit-power-source.c \
+ devkit-power-enum.h devkit-power-enum.c \
sysfs-utils.h sysfs-utils.c \
main.c \
$(BUILT_SOURCES)
diff --git a/src/devkit-power-enum.c b/src/devkit-power-enum.c
new file mode 100644
index 0000000..6368f97
--- /dev/null
+++ b/src/devkit-power-enum.c
@@ -0,0 +1,56 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 David Zeuthen <david@fubar.dk>
+ * Copyright (C) 2008 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 "devkit-power-enum.h"
+
+const char *
+devkit_power_convert_type_to_text (DevkitPowerType type_enum)
+{
+ const char *type = NULL;
+ switch (type_enum) {
+ case DEVKIT_POWER_TYPE_LINE_POWER:
+ type = "line-power";
+ break;
+ case DEVKIT_POWER_TYPE_BATTERY:
+ type = "battery";
+ break;
+ case DEVKIT_POWER_TYPE_UPS:
+ type = "ups";
+ break;
+ case DEVKIT_POWER_TYPE_MOUSE:
+ type = "mouse";
+ break;
+ case DEVKIT_POWER_TYPE_KEYBOARD:
+ type = "keyboard";
+ break;
+ case DEVKIT_POWER_TYPE_PDA:
+ type = "pda";
+ break;
+ case DEVKIT_POWER_TYPE_PHONE:
+ type = "phone";
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ return type;
+}
diff --git a/src/devkit-power-enum.h b/src/devkit-power-enum.h
new file mode 100644
index 0000000..9d7c1dc
--- /dev/null
+++ b/src/devkit-power-enum.h
@@ -0,0 +1,45 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 David Zeuthen <david@fubar.dk>
+ * Copyright (C) 2008 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 __DEVKIT_POWER_ENUM_H__
+#define __DEVKIT_POWER_ENUM_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+ DEVKIT_POWER_TYPE_LINE_POWER,
+ DEVKIT_POWER_TYPE_BATTERY,
+ DEVKIT_POWER_TYPE_UPS,
+ DEVKIT_POWER_TYPE_MOUSE,
+ DEVKIT_POWER_TYPE_KEYBOARD,
+ DEVKIT_POWER_TYPE_PDA,
+ DEVKIT_POWER_TYPE_PHONE,
+ DEVKIT_POWER_TYPE_UNKNOWN
+} DevkitPowerType;
+
+const char *devkit_power_convert_type_to_text (DevkitPowerType type_enum);
+
+G_END_DECLS
+
+#endif /* __DEVKIT_POWER_ENUM_H__ */
+
diff --git a/src/devkit-power-source.c b/src/devkit-power-source.c
index e90082c..7589851 100644
--- a/src/devkit-power-source.c
+++ b/src/devkit-power-source.c
@@ -35,17 +35,13 @@
#include <polkit-dbus/polkit-dbus.h>
#include "sysfs-utils.h"
+#include "devkit-power-enum.h"
#include "devkit-power-source.h"
#include "devkit-power-marshal.h"
/*--------------------------------------------------------------------------------------------------------------*/
#include "devkit-power-source-glue.h"
-typedef enum {
- DEVKIT_POWER_SOURCE_TYPE_LINE_POWER,
- DEVKIT_POWER_SOURCE_TYPE_BATTERY,
-} DevkitPowerSourceType;
-
struct DevkitPowerSourcePrivate
{
DBusGConnection *system_bus_connection;
@@ -62,7 +58,7 @@ struct DevkitPowerSourcePrivate
char *model;
char *serial;
GTimeVal update_time;
- DevkitPowerSourceType type;
+ DevkitPowerType type;
gboolean line_power_online;
@@ -146,8 +142,7 @@ get_property (GObject *object,
g_value_set_uint64 (value, source->priv->update_time.tv_sec);
break;
case PROP_TYPE:
- g_value_set_string (value, source->priv->type == DEVKIT_POWER_SOURCE_TYPE_LINE_POWER
- ? "line-power" : "battery");
+ g_value_set_string (value, devkit_power_convert_type_to_text (source->priv->type));
break;
case PROP_LINE_POWER_ONLINE:
@@ -398,9 +393,10 @@ devkit_power_source_new (DevkitPowerDaemon *daemon, DevkitDevice *d)
source->priv->native_path = g_strdup (native_path);
if (sysfs_file_exists (native_path, "online")) {
- source->priv->type = DEVKIT_POWER_SOURCE_TYPE_LINE_POWER;
+ source->priv->type = DEVKIT_POWER_TYPE_LINE_POWER;
} else {
- source->priv->type = DEVKIT_POWER_SOURCE_TYPE_BATTERY;
+ /* this is correct, UPS and CSR are not in the kernel */
+ source->priv->type = DEVKIT_POWER_TYPE_BATTERY;
}
if (!update (source)) {
@@ -549,17 +545,17 @@ update (DevkitPowerSource *source)
g_get_current_time (&(source->priv->update_time));
switch (source->priv->type) {
- case DEVKIT_POWER_SOURCE_TYPE_LINE_POWER:
+ case DEVKIT_POWER_TYPE_LINE_POWER:
ret = update_line_power (source);
break;
- case DEVKIT_POWER_SOURCE_TYPE_BATTERY:
+ case DEVKIT_POWER_TYPE_BATTERY:
ret = update_battery (source);
/* Seems that we don't get change uevents from the
- * kernel; set up a timer to poll
+ * kernel on some BIOS types; set up a timer to poll
*
- * TODO: perhaps only do this if running on battery.
+ * 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);