[gnome-battery-bench] SystemInfo: move sysfs helper to util-sysfs.[hc]
- From: Christian Kellner <gicmo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-battery-bench] SystemInfo: move sysfs helper to util-sysfs.[hc]
- Date: Wed, 5 Jul 2017 14:18:35 +0000 (UTC)
commit b08bedf33050e55e550e9b24f174bdf6b5714053
Author: Christian Kellner <gicmo gnome org>
Date: Tue Jun 6 20:16:27 2017 +0200
SystemInfo: move sysfs helper to util-sysfs.[hc]
src/Makefile.am | 4 ++-
src/power-supply.c | 64 +--------------------------------------------------
src/util-sysfs.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++
src/util-sysfs.h | 15 ++++++++++++
4 files changed, 78 insertions(+), 63 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 072f870..db8c525 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,7 +44,9 @@ client_sources = \
test-runner.c \
test-runner.h \
xinput-wait.c \
- xinput-wait.h
+ xinput-wait.h \
+ util-sysfs.h \
+ util-sysfs.c
gnome_battery_bench_CPPFLAGS = $(AM_CPPFLAGS) $(APPLICATION_CFLAGS)
gnome_battery_bench_LDADD = $(APPLICATION_LIBS)
diff --git a/src/power-supply.c b/src/power-supply.c
index 32c8bdc..21f79fb 100644
--- a/src/power-supply.c
+++ b/src/power-supply.c
@@ -3,10 +3,10 @@
#include <glib.h>
#include <gudev/gudev.h>
-#define _ISOC99_SOURCE //for NAN
-#include <math.h>
#include <limits.h>
+#include "util-sysfs.h"
+
#include "power-supply.h"
typedef struct _GbbPowerSupplyPrivate {
@@ -193,12 +193,6 @@ static GParamSpec *battery_props[PROP_BAT_LAST] = { NULL, };
G_DEFINE_TYPE(GbbBattery, gbb_battery, GBB_TYPE_POWER_SUPPLY);
-
-static char * sysfs_read_string_cached (GUdevDevice *device,
- const char *name);
-static double sysfs_read_double_scaled (GUdevDevice *device,
- const char *name);
-
static void voltage_design_initialize (GbbBattery *battery);
static void energy_design_initialize (GbbBattery *battery);
@@ -329,60 +323,6 @@ gbb_battery_class_init(GbbBatteryClass *klass)
}
-static char *
-sysfs_read_string_cached(GUdevDevice *device, const char *name)
-{
- const char *value;
-
- value = g_udev_device_get_sysfs_attr(device, name);
- if (value == NULL) {
- value = "Unknown";
- }
-
- return g_strdup(value);
-}
-
-static gboolean
-sysfs_read_guint64(GUdevDevice *device, const char *name, guint64 *res)
-{
- g_autofree char *buffer = NULL;
- char filename[PATH_MAX];
- const char *path;
- guint64 value;
- gboolean ok;
- char *end;
-
- path = g_udev_device_get_sysfs_path(device);
-
- g_snprintf(filename, sizeof(filename), "%s/%s", path, name);
- ok = g_file_get_contents(filename, &buffer, NULL, NULL);
- if (!ok) {
- return FALSE;
- }
-
- value = g_ascii_strtoull(buffer, &end, 10);
- if (end == buffer) {
- return FALSE;
- }
-
- *res = value;
- return TRUE;
-}
-
-static double
-sysfs_read_double_scaled(GUdevDevice *device, const char *name)
-{
- guint64 value;
- gboolean ok;
-
- ok = sysfs_read_guint64(device, name, &value);
- if (!ok) {
- return NAN;
- }
-
- return value / 1000000.;
-}
-
static const char *voltage_sources[] = {
"voltage_min_design",
"voltage_max_design",
diff --git a/src/util-sysfs.c b/src/util-sysfs.c
new file mode 100644
index 0000000..d6cbd46
--- /dev/null
+++ b/src/util-sysfs.c
@@ -0,0 +1,58 @@
+#include "util-sysfs.h"
+
+#define _ISOC99_SOURCE //for NAN
+#include <math.h>
+
+char *
+sysfs_read_string_cached(GUdevDevice *device, const char *name)
+{
+ const char *value;
+
+ value = g_udev_device_get_sysfs_attr(device, name);
+ if (value == NULL) {
+ value = "Unknown";
+ }
+
+ return g_strdup(value);
+}
+
+gboolean
+sysfs_read_guint64(GUdevDevice *device, const char *name, guint64 *res)
+{
+ g_autofree char *buffer = NULL;
+ char filename[PATH_MAX];
+ const char *path;
+ guint64 value;
+ gboolean ok;
+ char *end;
+
+ path = g_udev_device_get_sysfs_path(device);
+
+ g_snprintf(filename, sizeof(filename), "%s/%s", path, name);
+ ok = g_file_get_contents(filename, &buffer, NULL, NULL);
+ if (!ok) {
+ return FALSE;
+ }
+
+ value = g_ascii_strtoull(buffer, &end, 10);
+ if (end == buffer) {
+ return FALSE;
+ }
+
+ *res = value;
+ return TRUE;
+}
+
+double
+sysfs_read_double_scaled(GUdevDevice *device, const char *name)
+{
+ guint64 value;
+ gboolean ok;
+
+ ok = sysfs_read_guint64(device, name, &value);
+ if (!ok) {
+ return NAN;
+ }
+
+ return value / 1000000.;
+}
diff --git a/src/util-sysfs.h b/src/util-sysfs.h
new file mode 100644
index 0000000..2b8d673
--- /dev/null
+++ b/src/util-sysfs.h
@@ -0,0 +1,15 @@
+#ifndef __UTIL_SYSFS_H__
+#define __UTIL_SYSFS_H__
+
+#include <glib.h>
+#include <gudev/gudev.h>
+
+char * sysfs_read_string_cached (GUdevDevice *device,
+ const char *name);
+gboolean sysfs_read_guint64 (GUdevDevice *device,
+ const char *name,
+ guint64 *res);
+double sysfs_read_double_scaled (GUdevDevice *device,
+ const char *name);
+
+#endif /* __UTIL_SYSFS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]