2009/10/14 Pramod Dematagoda <[email protected]>: > There is a problem with DKP where the daemon would not be aware of being > on battery or not during a delayed refresh since it would seem that the > backend does not send the daemon a device changed signal during such an > action. > > I have attached the patch that fixes this problem by making the daemon > check whether it is on battery or not manually during a delayed refresh.
I would rather fix the problem rather than work around it. From my analysis: 1. dkp_daemon_refresh_battery_devices_cb() gets called after a short delay 2. this calls dkp_daemon_refresh_battery_devices(), which calls dkp_device_refresh_internal() on each battery device 3. dkp_device_refresh_internal() calls the klass->refresh() method, which for this battery would call dkp_device_supply_refresh() 4. dkp_device_supply_refresh() sets the "update-time" property and refreshes the device. ... 5. dkp_device_perhaps_changed_cb() gets called as "notify::update-time" is triggered 6. dkp_device_perhaps_changed_cb() emits DkpDevice::Changed() and DkpDaemon::DeviceChanged() 7. dkp_daemon_device_changed_cb gets called due to the DkpDevice::Changed signal 8. this updates the "on-battery" and "on-low-battery" properties So, it looks like the problem is step 4. We need to refresh the device, and then set the "update-time" property, else we calculate "on-battery" and "on-low-battery" according to the old data, not the newly refreshed data. This looks like it also affects DkpDeviceCsr, DkpDeviceHid and DkpDeviceSupply, although obviously only the last will be triggered from the idle refresh. I've attached the patch I've just merged for your review, could you try with the latest git and tell me if this also fixes the problem please. Thanks. Richard.
From b69e31ef05a18be74c4ff69ed3a6ce79a0550bc2 Mon Sep 17 00:00:00 2001 From: Richard Hughes <[email protected]> Date: Wed, 14 Oct 2009 10:34:10 +0100 Subject: [PATCH] Ensure we only reset the update-time property when we have done the refresh, not before This should fix the timed callback when the AC changes and and a delayed refresh is triggered. --- src/linux/dkp-device-csr.c | 6 +++--- src/linux/dkp-device-hid.c | 8 ++++---- src/linux/dkp-device-supply.c | 9 +++++++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/linux/dkp-device-csr.c b/src/linux/dkp-device-csr.c index 72c7e78..69582c8 100644 --- a/src/linux/dkp-device-csr.c +++ b/src/linux/dkp-device-csr.c @@ -227,9 +227,6 @@ dkp_device_csr_refresh (DkpDevice *device) gdouble percentage; guint written; - g_get_current_time (&timeval); - g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL); - /* For dual receivers C502, C504 and C505, the mouse is the * second device and uses an addr of 1 in the value and index * fields' high byte */ @@ -270,6 +267,9 @@ dkp_device_csr_refresh (DkpDevice *device) egg_debug ("percentage=%f", percentage); } + /* reset time */ + g_get_current_time (&timeval); + g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL); out: if (handle != NULL) usb_close (handle); diff --git a/src/linux/dkp-device-hid.c b/src/linux/dkp-device-hid.c index c1e1425..c258fef 100644 --- a/src/linux/dkp-device-hid.c +++ b/src/linux/dkp-device-hid.c @@ -385,10 +385,6 @@ dkp_device_hid_refresh (DkpDevice *device) int rd; DkpDeviceHid *hid = DKP_DEVICE_HID (device); - /* reset time */ - g_get_current_time (&timeval); - g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL); - /* read any data */ rd = read (hid->priv->fd, ev, sizeof (ev)); @@ -416,6 +412,10 @@ dkp_device_hid_refresh (DkpDevice *device) /* fix up device states */ dkp_device_hid_fixup_state (device); + + /* reset time */ + g_get_current_time (&timeval); + g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL); out: return ret; } diff --git a/src/linux/dkp-device-supply.c b/src/linux/dkp-device-supply.c index 20bd48e..9573807 100644 --- a/src/linux/dkp-device-supply.c +++ b/src/linux/dkp-device-supply.c @@ -763,8 +763,6 @@ dkp_device_supply_refresh (DkpDevice *device) supply->priv->poll_timer_id = 0; } - g_get_current_time (&timeval); - g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL); g_object_get (device, "type", &type, NULL); switch (type) { case DKP_DEVICE_TYPE_LINE_POWER: @@ -781,6 +779,13 @@ dkp_device_supply_refresh (DkpDevice *device) g_assert_not_reached (); break; } + + /* reset time if we got new data */ + if (ret) { + g_get_current_time (&timeval); + g_object_set (device, "update-time", (guint64) timeval.tv_sec, NULL); + } + return ret; } -- 1.6.5.rc2
_______________________________________________ devkit-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/devkit-devel
