[gnome-battery-bench] Power supply: make battery_discover generic



commit 5f7d876faada3611c82b848bcc0610910f200057
Author: Christian Kellner <gicmo gnome org>
Date:   Fri Mar 17 18:23:36 2017 +0100

    Power supply: make battery_discover generic
    
    That is, also return GbbMains, and rename it to
    gbb_power_supply_discover.

 src/power-supply.c |   79 +++++++++++++++++++++++++++++-----------------------
 src/power-supply.h |    4 ++-
 2 files changed, 47 insertions(+), 36 deletions(-)
---
diff --git a/src/power-supply.c b/src/power-supply.c
index 9f3d863..c4f34af 100644
--- a/src/power-supply.c
+++ b/src/power-supply.c
@@ -100,6 +100,50 @@ gbb_power_supply_init(GbbPowerSupply *ps)
 {
 
 }
+
+GList *
+gbb_power_supply_discover()
+{
+    GUdevClient *client;
+    GList *devices;
+    GList *l;
+    GList *supplies = NULL;
+
+    client = g_udev_client_new(NULL);
+
+    devices = g_udev_client_query_by_subsystem(client, "power_supply");
+
+    for (l = devices; l != NULL; l = l->next) {
+        GUdevDevice *device = l->data;
+        const gchar *dev_type;
+
+        dev_type = g_udev_device_get_sysfs_attr(device,
+                                                "type");
+        if (dev_type == NULL) {
+            continue;
+        }
+
+        if (g_str_equal(dev_type, "Battery")) {
+            GObject *bat = g_object_new(GBB_TYPE_BATTERY,
+                                        "udev-device", device,
+                                        NULL);
+            supplies = g_list_prepend(supplies, bat);
+        } else if (g_str_equal(dev_type, "Mains")) {
+            GObject *msn = g_object_new(GBB_TYPE_MAINS,
+                                        "udev-device", device,
+                                        NULL);
+            supplies = g_list_prepend(supplies, msn);
+        } else {
+            g_warning("Unknown power supply type '%s'. Skipping.",
+                      dev_type);
+        }
+    }
+
+    g_list_free_full(devices, (GDestroyNotify) g_object_unref);
+    g_object_unref(client);
+
+    return supplies;
+}
 /* ************************************************************************** */
 
 struct _GbbBattery {
@@ -391,41 +435,6 @@ energy_design_initialize(GbbBattery *bat)
     }
 }
 
-GList *
-gbb_battery_discover()
-{
-    GUdevClient *client;
-    GList *devices;
-    GList *l;
-    GList *supplies = NULL;
-
-    client = g_udev_client_new(NULL);
-
-    devices = g_udev_client_query_by_subsystem(client, "power_supply");
-
-    for (l = devices; l != NULL; l = l->next) {
-        GUdevDevice *device = l->data;
-        const gchar *dev_type;
-
-        dev_type = g_udev_device_get_sysfs_attr(device,
-                                                "type");
-        if (dev_type == NULL) {
-            continue;
-        }
-
-        g_print("Type: %s\n", dev_type);
-        if (g_str_equal(dev_type, "Battery")) {
-            GObject *bat = g_object_new(GBB_TYPE_BATTERY,
-                                        "udev-device", device,
-                                        NULL);
-            supplies = g_list_prepend(supplies, bat);
-        }
-    }
-
-    g_list_free_full(devices, (GDestroyNotify) g_object_unref);
-    return supplies;
-}
-
 double
 gbb_battery_poll(GbbBattery *bat)
 {
diff --git a/src/power-supply.h b/src/power-supply.h
index 579a95f..2123b39 100644
--- a/src/power-supply.h
+++ b/src/power-supply.h
@@ -15,12 +15,14 @@ struct _GbbPowerSupplyClass
   gpointer padding[13];
 };
 
+GList *     gbb_power_supply_discover    (void);
+
 /* ************************************************************************** */
 
 #define GBB_TYPE_BATTERY gbb_battery_get_type()
 G_DECLARE_FINAL_TYPE(GbbBattery, gbb_battery, GBB, BATTERY, GbbPowerSupply)
 
-GList *     gbb_battery_discover    (void);
+
 double      gbb_battery_poll        (GbbBattery *);
 
 /* ************************************************************************** */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]