summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2023-06-30 17:36:00 +0200
committerBastien Nocera <hadess@hadess.net>2023-07-03 16:10:13 +0200
commit5ddc7c8bc5cd89b078dcf953e457db690a16ade8 (patch)
tree0ce9a486db7b8153dffff8f55e9e8ccbae9cdf39
parent570d6cdf271fae19343b85d7d585e3eed23a99c0 (diff)
linux: Set the "disconnected" property on events
When a sibling device has its "wireless_status" attribute changing, change the "disconnected" property appropriately.
-rw-r--r--src/linux/up-device-supply.c51
1 files changed, 46 insertions, 5 deletions
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c
index edf6548..888f48b 100644
--- a/src/linux/up-device-supply.c
+++ b/src/linux/up-device-supply.c
@@ -320,8 +320,8 @@ up_device_supply_refresh_device (UpDeviceSupply *supply,
}
static void
-up_device_supply_sibling_discovered (UpDevice *device,
- GObject *sibling)
+up_device_supply_sibling_discovered_guess_type (UpDevice *device,
+ GObject *sibling)
{
GUdevDevice *input;
UpDeviceKind cur_type, new_type;
@@ -364,9 +364,6 @@ up_device_supply_sibling_discovered (UpDevice *device,
* - microphone */
};
- if (!G_UDEV_IS_DEVICE (sibling))
- return;
-
input = G_UDEV_DEVICE (sibling);
/* Do not process if we already have a "good" guess for the device type. */
@@ -456,6 +453,50 @@ up_device_supply_sibling_discovered (UpDevice *device,
}
}
+static void
+up_device_supply_sibling_discovered_handle_wireless_status (UpDevice *device,
+ GObject *obj)
+{
+ const char *status;
+ GUdevDevice *sibling = G_UDEV_DEVICE (obj);
+
+ status = g_udev_device_get_sysfs_attr_uncached (sibling, "wireless_status");
+ if (!status)
+ return;
+
+ if (!g_str_equal (status, "connected") &&
+ !g_str_equal (status, "disconnected")) {
+ g_warning ("Unhandled wireless_status value '%s' on %s",
+ status, g_udev_device_get_sysfs_path (sibling));
+ return;
+ }
+
+ g_debug ("Detected wireless_status '%s' on %s",
+ status, g_udev_device_get_sysfs_path (sibling));
+
+ g_object_set (G_OBJECT (device),
+ "disconnected", g_str_equal (status, "disconnected"),
+ NULL);
+}
+
+static void
+up_device_supply_sibling_discovered (UpDevice *device,
+ GObject *sibling)
+{
+ GUdevDevice *native;
+
+ if (!G_UDEV_IS_DEVICE (sibling))
+ return;
+
+ native = G_UDEV_DEVICE (up_device_get_native (device));
+ g_message ("up_device_supply_sibling_discovered (device: %s, sibling: %s)",
+ g_udev_device_get_sysfs_path (native),
+ g_udev_device_get_sysfs_path (G_UDEV_DEVICE (sibling)));
+
+ up_device_supply_sibling_discovered_guess_type (device, sibling);
+ up_device_supply_sibling_discovered_handle_wireless_status (device, sibling);
+}
+
static UpDeviceKind
up_device_supply_guess_type (GUdevDevice *native,
const char *native_path)