diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2011-04-15 18:01:53 +0200 |
---|---|---|
committer | Martin Pitt <martin.pitt@ubuntu.com> | 2011-04-26 11:28:32 +0200 |
commit | f65aa4dbf2721a660300d14fc3a582d3be3c3072 (patch) | |
tree | 3d4c246a46dafbadf91cd34fe54411f22c4451e1 | |
parent | c25079b65240d37e07d7629030994fa5e09bfbf3 (diff) |
Support virtual UPS devices for testing
If a HID device is marked with the UPOWER_FAKE_DEVICE udev property, don't send
ioctl commands to it, but instead read status and percentage from udev
properties as well (UPOWER_FAKE_HID_CHARGING and UPOWER_FAKE_HID_PERCENTAGE).
This allows developers or a test suite to test the behaviour of UPSes without
actually having one.
-rw-r--r-- | src/linux/up-device-hid.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/linux/up-device-hid.c b/src/linux/up-device-hid.c index 60d8557..0172930 100644 --- a/src/linux/up-device-hid.c +++ b/src/linux/up-device-hid.c @@ -306,6 +306,7 @@ up_device_hid_coldplug (UpDevice *device) UpDeviceHid *hid = UP_DEVICE_HID (device); GUdevDevice *native; gboolean ret = FALSE; + gboolean fake_device; const gchar *device_file; const gchar *type; const gchar *vendor; @@ -332,10 +333,14 @@ up_device_hid_coldplug (UpDevice *device) } /* first check that we are an UPS */ - ret = up_device_hid_is_ups (hid); - if (!ret) { - g_debug ("not a HID device: %s", device_file); - goto out; + fake_device = g_udev_device_has_property (native, "UPOWER_FAKE_DEVICE"); + if (!fake_device) + { + ret = up_device_hid_is_ups (hid); + if (!ret) { + g_debug ("not a HID device: %s", device_file); + goto out; + } } /* prefer UPOWER names */ @@ -355,10 +360,21 @@ up_device_hid_coldplug (UpDevice *device) NULL); /* coldplug everything */ - ret = up_device_hid_get_all_data (hid); - if (!ret) { - g_debug ("failed to coldplug: %s", device_file); - goto out; + if (fake_device) + { + ret = TRUE; + if (g_udev_device_get_property_as_boolean (native, "UPOWER_FAKE_HID_CHARGING")) + up_device_hid_set_values (hid, UP_DEVICE_HID_CHARGING, 1); + else + up_device_hid_set_values (hid, UP_DEVICE_HID_DISCHARGING, 1); + up_device_hid_set_values (hid, UP_DEVICE_HID_REMAINING_CAPACITY, + g_udev_device_get_property_as_int (native, "UPOWER_FAKE_HID_PERCENTAGE")); + } else { + ret = up_device_hid_get_all_data (hid); + if (!ret) { + g_debug ("failed to coldplug: %s", device_file); + goto out; + } } /* fix up device states */ |