Commit 5f7d876f authored by Christian Kellner's avatar Christian Kellner
Browse files

Power supply: make battery_discover generic

That is, also return GbbMains, and rename it to
gbb_power_supply_discover.
parent 7f0b3bac
......@@ -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)
{
......
......@@ -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 *);
/* ************************************************************************** */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment