diff options
author | Benjamin Berg <bberg@redhat.com> | 2022-06-07 15:54:44 +0200 |
---|---|---|
committer | Benjamin Berg <bberg@redhat.com> | 2022-06-07 16:07:03 +0200 |
commit | 68d4f3702d27a331ba95938862c46e5567dc58f4 (patch) | |
tree | 47e549730b7dc06cec3a245cd909797cde4f8884 | |
parent | 1587b37707c5797e5d0d78fdb9f99fb724e16afc (diff) | |
download | upower-68d4f3702d27a331ba95938862c46e5567dc58f4.tar.gz |
Move battery type decoding into common file
-rw-r--r-- | src/freebsd/up-device-supply.c | 32 | ||||
-rw-r--r-- | src/linux/up-device-hid.c | 18 | ||||
-rw-r--r-- | src/linux/up-device-supply.c | 28 | ||||
-rw-r--r-- | src/up-common.c | 23 | ||||
-rw-r--r-- | src/up-common.h | 3 |
5 files changed, 31 insertions, 73 deletions
diff --git a/src/freebsd/up-device-supply.c b/src/freebsd/up-device-supply.c index bd11533..8e3b7a3 100644 --- a/src/freebsd/up-device-supply.c +++ b/src/freebsd/up-device-supply.c @@ -44,7 +44,7 @@ #include "up-acpi-native.h" #include "up-util.h" -#include "up-types.h" +#include "up-common.h" #include "up-device-supply.h" #define UP_ACPIDEV "/dev/acpi" @@ -52,7 +52,6 @@ G_DEFINE_TYPE (UpDeviceSupply, up_device_supply, UP_TYPE_DEVICE) static gboolean up_device_supply_refresh (UpDevice *device, UpRefreshReason reason); -static UpDeviceTechnology up_device_supply_convert_device_technology (const gchar *type); static gboolean up_device_supply_acline_coldplug (UpDevice *device); static gboolean up_device_supply_battery_coldplug (UpDevice *device, UpAcpiNative *native); static gboolean up_device_supply_acline_set_properties (UpDevice *device); @@ -61,33 +60,6 @@ static gboolean up_device_supply_get_on_battery (UpDevice *device, gboolean *on static gboolean up_device_supply_get_online (UpDevice *device, gboolean *online); /** - * up_device_supply_convert_device_technology: - * - * This is taken from linux/up-device-supply.c. - **/ -static UpDeviceTechnology -up_device_supply_convert_device_technology (const gchar *type) -{ - if (type == NULL) - return UP_DEVICE_TECHNOLOGY_UNKNOWN; - if (g_ascii_strcasecmp (type, "li-ion") == 0 || - g_ascii_strcasecmp (type, "lion") == 0) - return UP_DEVICE_TECHNOLOGY_LITHIUM_ION; - if (g_ascii_strcasecmp (type, "pb") == 0 || - g_ascii_strcasecmp (type, "pbac") == 0) - return UP_DEVICE_TECHNOLOGY_LEAD_ACID; - if (g_ascii_strcasecmp (type, "lip") == 0 || - g_ascii_strcasecmp (type, "lipo") == 0 || - g_ascii_strcasecmp (type, "li-poly") == 0) - return UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER; - if (g_ascii_strcasecmp (type, "nimh") == 0) - return UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE; - if (g_ascii_strcasecmp (type, "lifo") == 0) - return UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE; - return UP_DEVICE_TECHNOLOGY_UNKNOWN; -} - -/** * up_device_supply_reset_values: **/ static void @@ -209,7 +181,7 @@ up_device_supply_battery_set_properties (UpDevice *device, UpAcpiNative *native) vendor = up_make_safe_string (g_strdup (battif.bif.oeminfo)); model = up_make_safe_string (g_strdup (battif.bif.model)); serial = up_make_safe_string (g_strdup (battif.bif.serial)); - technology = up_device_supply_convert_device_technology (battif.bif.type); + technology = up_convert_device_technology (battif.bif.type); g_object_set (device, "vendor", vendor, diff --git a/src/linux/up-device-hid.c b/src/linux/up-device-hid.c index 1e88596..9237262 100644 --- a/src/linux/up-device-hid.c +++ b/src/linux/up-device-hid.c @@ -45,7 +45,7 @@ #include <sys/ioctl.h> #include <unistd.h> -#include "up-types.h" +#include "up-common.h" #include "up-device-hid.h" #include "up-constants.h" @@ -144,20 +144,6 @@ up_device_hid_get_string (UpDeviceHid *hid, int sindex) } /** - * up_device_hid_convert_device_technology: - **/ -static UpDeviceTechnology -up_device_hid_convert_device_technology (const gchar *type) -{ - if (type == NULL) - return UP_DEVICE_TECHNOLOGY_UNKNOWN; - if (g_ascii_strcasecmp (type, "pb") == 0 || - g_ascii_strcasecmp (type, "pbac") == 0) - return UP_DEVICE_TECHNOLOGY_LEAD_ACID; - return UP_DEVICE_TECHNOLOGY_UNKNOWN; -} - -/** * up_device_hid_set_values: **/ static gboolean @@ -190,7 +176,7 @@ up_device_hid_set_values (UpDeviceHid *hid, guint32 code, gint32 value) break; case UP_DEVICE_HID_CHEMISTRY: type = up_device_hid_get_string (hid, value); - g_object_set (device, "technology", up_device_hid_convert_device_technology (type), NULL); + g_object_set (device, "technology", up_convert_device_technology (type), NULL); break; case UP_DEVICE_HID_RECHARGEABLE: g_object_set (device, "is-rechargeable", (value != 0), NULL); diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c index 8488040..85783ca 100644 --- a/src/linux/up-device-supply.c +++ b/src/linux/up-device-supply.c @@ -292,32 +292,6 @@ up_device_supply_calculate_rate (UpDeviceSupply *supply, gdouble energy) } /** - * up_device_supply_convert_device_technology: - **/ -static UpDeviceTechnology -up_device_supply_convert_device_technology (const gchar *type) -{ - if (type == NULL) - return UP_DEVICE_TECHNOLOGY_UNKNOWN; - /* every case combination of Li-Ion is commonly used.. */ - if (g_ascii_strcasecmp (type, "li-ion") == 0 || - g_ascii_strcasecmp (type, "lion") == 0) - return UP_DEVICE_TECHNOLOGY_LITHIUM_ION; - if (g_ascii_strcasecmp (type, "pb") == 0 || - g_ascii_strcasecmp (type, "pbac") == 0) - return UP_DEVICE_TECHNOLOGY_LEAD_ACID; - if (g_ascii_strcasecmp (type, "lip") == 0 || - g_ascii_strcasecmp (type, "lipo") == 0 || - g_ascii_strcasecmp (type, "li-poly") == 0) - return UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER; - if (g_ascii_strcasecmp (type, "nimh") == 0) - return UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE; - if (g_ascii_strcasecmp (type, "life") == 0) - return UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE; - return UP_DEVICE_TECHNOLOGY_UNKNOWN; -} - -/** * up_device_supply_get_string: **/ static gchar * @@ -563,7 +537,7 @@ up_device_supply_refresh_battery (UpDeviceSupply *supply, /* the ACPI spec is bad at defining battery type constants */ technology_native = up_device_supply_get_string (native, "technology"); - g_object_set (device, "technology", up_device_supply_convert_device_technology (technology_native), NULL); + g_object_set (device, "technology", up_convert_device_technology (technology_native), NULL); /* get values which may be blank */ manufacturer = up_device_supply_get_string (native, "manufacturer"); diff --git a/src/up-common.c b/src/up-common.c index 9b4f118..9753036 100644 --- a/src/up-common.c +++ b/src/up-common.c @@ -51,3 +51,26 @@ up_make_safe_string (char *text) return text; } + +UpDeviceTechnology +up_convert_device_technology (const gchar *type) +{ + if (type == NULL) + return UP_DEVICE_TECHNOLOGY_UNKNOWN; + /* every case combination of Li-Ion is commonly used.. */ + if (g_ascii_strcasecmp (type, "li-ion") == 0 || + g_ascii_strcasecmp (type, "lion") == 0) + return UP_DEVICE_TECHNOLOGY_LITHIUM_ION; + if (g_ascii_strcasecmp (type, "pb") == 0 || + g_ascii_strcasecmp (type, "pbac") == 0) + return UP_DEVICE_TECHNOLOGY_LEAD_ACID; + if (g_ascii_strcasecmp (type, "lip") == 0 || + g_ascii_strcasecmp (type, "lipo") == 0 || + g_ascii_strcasecmp (type, "li-poly") == 0) + return UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER; + if (g_ascii_strcasecmp (type, "nimh") == 0) + return UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE; + if (g_ascii_strcasecmp (type, "life") == 0) + return UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE; + return UP_DEVICE_TECHNOLOGY_UNKNOWN; +} diff --git a/src/up-common.h b/src/up-common.h index 15a258a..6cde622 100644 --- a/src/up-common.h +++ b/src/up-common.h @@ -20,4 +20,7 @@ #pragma once +#include "up-types.h" + char *up_make_safe_string (char *text); +UpDeviceTechnology up_convert_device_technology (const gchar *type); |