mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-15 18:08:11 +02:00
device: Flag refresh reason
The reason of a refresh may be interesting to special case certain situation (e.g. discontinuity of charge after wakeup, polling again after an event). As such, add an enum parameter that signals the reason for the refresh.
This commit is contained in:
parent
5836099ad7
commit
7f7839bdde
11 changed files with 44 additions and 33 deletions
|
|
@ -97,7 +97,7 @@ up_backend_refresh_devices (gpointer user_data)
|
|||
|
||||
for (i = 0; i < array->len; i++) {
|
||||
device = UP_DEVICE (g_ptr_array_index (array, i));
|
||||
up_device_refresh_internal (device);
|
||||
up_device_refresh_internal (device, UP_REFRESH_POLL);
|
||||
}
|
||||
|
||||
g_ptr_array_unref (array);
|
||||
|
|
@ -164,7 +164,7 @@ up_backend_acpi_devd_notify (UpBackend *backend, const gchar *system, const gcha
|
|||
goto out;
|
||||
}
|
||||
|
||||
up_device_refresh_internal (UP_DEVICE (object));
|
||||
up_device_refresh_internal (UP_DEVICE (object), UP_REFRESH_EVENT);
|
||||
|
||||
if (object != NULL)
|
||||
g_object_unref (object);
|
||||
|
|
@ -258,7 +258,7 @@ up_backend_coldplug (UpBackend *backend, UpDaemon *daemon)
|
|||
if (object != NULL) {
|
||||
device = UP_DEVICE (object);
|
||||
g_warning ("treating add event as change event on %s", up_device_get_object_path (device));
|
||||
up_device_refresh_internal (device);
|
||||
up_device_refresh_internal (device, UP_REFRESH_EVENT);
|
||||
} else {
|
||||
up_backend_create_new_device (backend, native);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@
|
|||
|
||||
G_DEFINE_TYPE (UpDeviceSupply, up_device_supply, UP_TYPE_DEVICE)
|
||||
|
||||
static gboolean up_device_supply_refresh (UpDevice *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);
|
||||
|
|
@ -387,7 +387,7 @@ out:
|
|||
* Return %TRUE on success, %FALSE if we failed to refresh or no data
|
||||
**/
|
||||
static gboolean
|
||||
up_device_supply_refresh (UpDevice *device)
|
||||
up_device_supply_refresh (UpDevice *device, UpRefreshReason reason)
|
||||
{
|
||||
GObject *object;
|
||||
UpDeviceKind type;
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ up_backend_device_changed (UpBackend *backend, GUdevDevice *native, const char *
|
|||
|
||||
/* need to refresh device */
|
||||
device = UP_DEVICE (object);
|
||||
ret = up_device_refresh_internal (device);
|
||||
ret = up_device_refresh_internal (device, UP_REFRESH_EVENT);
|
||||
if (!ret) {
|
||||
g_debug ("no changes on %s", up_device_get_object_path (device));
|
||||
goto out;
|
||||
|
|
@ -751,7 +751,7 @@ up_backend_prepare_for_sleep (GDBusConnection *connection,
|
|||
|
||||
for (i = 0; i < array->len; i++) {
|
||||
UpDevice *device = UP_DEVICE (g_ptr_array_index (array, i));
|
||||
up_device_refresh_internal (device);
|
||||
up_device_refresh_internal (device, UP_REFRESH_RESUME);
|
||||
}
|
||||
|
||||
g_ptr_array_unref (array);
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ struct UpDeviceHidPrivate
|
|||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (UpDeviceHid, up_device_hid, UP_TYPE_DEVICE)
|
||||
|
||||
static gboolean up_device_hid_refresh (UpDevice *device);
|
||||
static gboolean up_device_hid_refresh (UpDevice *device, UpRefreshReason reason);
|
||||
|
||||
/**
|
||||
* up_device_hid_is_ups:
|
||||
|
|
@ -131,7 +131,7 @@ up_device_hid_poll (UpDeviceHid *hid)
|
|||
UpDevice *device = UP_DEVICE (hid);
|
||||
|
||||
g_debug ("Polling: %s", up_device_get_object_path (device));
|
||||
up_device_hid_refresh (device);
|
||||
up_device_hid_refresh (device, UP_REFRESH_POLL);
|
||||
|
||||
/* always continue polling */
|
||||
return TRUE;
|
||||
|
|
@ -386,7 +386,7 @@ out:
|
|||
* Return %TRUE on success, %FALSE if we failed to refresh or no data
|
||||
**/
|
||||
static gboolean
|
||||
up_device_hid_refresh (UpDevice *device)
|
||||
up_device_hid_refresh (UpDevice *device, UpRefreshReason reason)
|
||||
{
|
||||
gboolean set = FALSE;
|
||||
gboolean ret = FALSE;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ struct UpDeviceIdevicePrivate
|
|||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (UpDeviceIdevice, up_device_idevice, UP_TYPE_DEVICE)
|
||||
|
||||
static gboolean up_device_idevice_refresh (UpDevice *device);
|
||||
static gboolean up_device_idevice_refresh (UpDevice *device, UpRefreshReason reason);
|
||||
|
||||
/**
|
||||
* up_device_idevice_poll_cb:
|
||||
|
|
@ -58,7 +58,7 @@ up_device_idevice_poll_cb (UpDeviceIdevice *idevice)
|
|||
UpDevice *device = UP_DEVICE (idevice);
|
||||
|
||||
g_debug ("Polling: %s", up_device_get_object_path (device));
|
||||
up_device_idevice_refresh (device);
|
||||
up_device_idevice_refresh (device, UP_REFRESH_POLL);
|
||||
|
||||
/* always continue polling */
|
||||
return TRUE;
|
||||
|
|
@ -175,7 +175,7 @@ up_device_idevice_start_poll_cb (UpDeviceIdevice *idevice)
|
|||
|
||||
/* coldplug */
|
||||
idevice->priv->client = client;
|
||||
if (up_device_idevice_refresh (device) == FALSE) {
|
||||
if (up_device_idevice_refresh (device, UP_REFRESH_INIT) == FALSE) {
|
||||
idevice->priv->client = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
|
@ -283,7 +283,7 @@ up_device_idevice_coldplug (UpDevice *device)
|
|||
* Return %TRUE on success, %FALSE if we failed to refresh or no data
|
||||
**/
|
||||
static gboolean
|
||||
up_device_idevice_refresh (UpDevice *device)
|
||||
up_device_idevice_refresh (UpDevice *device, UpRefreshReason reason)
|
||||
{
|
||||
UpDeviceIdevice *idevice = UP_DEVICE_IDEVICE (device);
|
||||
lockdownd_client_t client = NULL;
|
||||
|
|
|
|||
|
|
@ -69,7 +69,8 @@ struct UpDeviceSupplyPrivate
|
|||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (UpDeviceSupply, up_device_supply, UP_TYPE_DEVICE)
|
||||
|
||||
static gboolean up_device_supply_refresh (UpDevice *device);
|
||||
static gboolean up_device_supply_refresh (UpDevice *device,
|
||||
UpRefreshReason reason);
|
||||
static void up_device_supply_setup_unknown_poll (UpDevice *device,
|
||||
UpDeviceState state);
|
||||
static UpDeviceKind up_device_supply_guess_type (GUdevDevice *native,
|
||||
|
|
@ -1041,7 +1042,7 @@ up_device_supply_poll_unknown_battery (UpDevice *device)
|
|||
up_device_get_object_path (device), UP_DAEMON_UNKNOWN_TIMEOUT);
|
||||
|
||||
supply->priv->poll_timer_id = 0;
|
||||
up_device_supply_refresh (device);
|
||||
up_device_supply_refresh (device, UP_REFRESH_POLL);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -1172,7 +1173,7 @@ up_device_supply_coldplug (UpDevice *device)
|
|||
up_daemon_start_poll (G_OBJECT (device), (GSourceFunc) up_device_supply_refresh);
|
||||
|
||||
/* coldplug values */
|
||||
up_device_supply_refresh (device);
|
||||
up_device_supply_refresh (device, UP_REFRESH_INIT);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -1221,7 +1222,7 @@ up_device_supply_disable_unknown_poll (UpDevice *device)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
up_device_supply_refresh (UpDevice *device)
|
||||
up_device_supply_refresh (UpDevice *device, UpRefreshReason reason)
|
||||
{
|
||||
gboolean updated;
|
||||
UpDeviceSupply *supply = UP_DEVICE_SUPPLY (device);
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ struct UpDeviceWupPrivate
|
|||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (UpDeviceWup, up_device_wup, UP_TYPE_DEVICE)
|
||||
|
||||
static gboolean up_device_wup_refresh (UpDevice *device);
|
||||
static gboolean up_device_wup_refresh (UpDevice *device, UpRefreshReason reason);
|
||||
|
||||
/**
|
||||
* up_device_wup_poll_cb:
|
||||
|
|
@ -82,7 +82,7 @@ up_device_wup_poll_cb (UpDeviceWup *wup)
|
|||
UpDevice *device = UP_DEVICE (wup);
|
||||
|
||||
g_debug ("Polling: %s", up_device_get_object_path (device));
|
||||
up_device_wup_refresh (device);
|
||||
up_device_wup_refresh (device, UP_REFRESH_POLL);
|
||||
|
||||
/* always continue polling */
|
||||
return TRUE;
|
||||
|
|
@ -372,7 +372,7 @@ up_device_wup_coldplug (UpDevice *device)
|
|||
|
||||
/* coldplug */
|
||||
g_debug ("coldplug");
|
||||
ret = up_device_wup_refresh (device);
|
||||
ret = up_device_wup_refresh (device, UP_REFRESH_INIT);
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -383,7 +383,7 @@ out:
|
|||
* Return %TRUE on success, %FALSE if we failed to refresh or no data
|
||||
**/
|
||||
static gboolean
|
||||
up_device_wup_refresh (UpDevice *device)
|
||||
up_device_wup_refresh (UpDevice *device, UpRefreshReason reason)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
gchar *data = NULL;
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ static void up_backend_update_lid_status(UpDaemon*);
|
|||
|
||||
static gboolean up_apm_device_get_on_battery (UpDevice *device, gboolean *on_battery);
|
||||
static gboolean up_apm_device_get_online (UpDevice *device, gboolean *online);
|
||||
static gboolean up_apm_device_refresh (UpDevice *device);
|
||||
static gboolean up_apm_device_refresh (UpDevice *device, UpRefreshReason reason);
|
||||
|
||||
struct UpBackendPrivate
|
||||
{
|
||||
|
|
@ -411,14 +411,14 @@ up_backend_apm_powerchange_event_cb(gpointer object)
|
|||
|
||||
g_return_val_if_fail (UP_IS_BACKEND (object), FALSE);
|
||||
backend = UP_BACKEND (object);
|
||||
up_apm_device_refresh(backend->priv->ac);
|
||||
up_apm_device_refresh(backend->priv->battery);
|
||||
up_device_refresh_internal (backend->priv->ac, UP_REFRESH_EVENT);
|
||||
up_device_refresh_internal (backend->priv->battery, UP_REFRESH_EVENT);
|
||||
/* return false to not endless loop */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
up_apm_device_refresh(UpDevice* device)
|
||||
up_apm_device_refresh(UpDevice* device, UpRefreshReason reason)
|
||||
{
|
||||
UpDeviceKind type;
|
||||
gboolean ret;
|
||||
|
|
|
|||
|
|
@ -377,7 +377,7 @@ up_daemon_refresh_battery_devices (UpDaemon *daemon)
|
|||
NULL);
|
||||
if (type == UP_DEVICE_KIND_BATTERY &&
|
||||
power_supply)
|
||||
up_device_refresh_internal (device);
|
||||
up_device_refresh_internal (device, UP_REFRESH_CHANGES);
|
||||
}
|
||||
g_ptr_array_unref (array);
|
||||
|
||||
|
|
|
|||
|
|
@ -420,7 +420,7 @@ up_device_refresh (UpExportedDevice *skeleton,
|
|||
GDBusMethodInvocation *invocation,
|
||||
UpDevice *device)
|
||||
{
|
||||
up_device_refresh_internal (device);
|
||||
up_device_refresh_internal (device, UP_REFRESH_POLL);
|
||||
up_exported_device_complete_refresh (skeleton, invocation);
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -459,7 +459,7 @@ up_device_initable_init (GInitable *initable,
|
|||
}
|
||||
|
||||
/* force a refresh, although failure isn't fatal */
|
||||
ret = up_device_refresh_internal (device);
|
||||
ret = up_device_refresh_internal (device, UP_REFRESH_INIT);
|
||||
if (!ret) {
|
||||
g_debug ("failed to refresh %s", native_path);
|
||||
|
||||
|
|
@ -623,7 +623,7 @@ out:
|
|||
* notify::update-time this should be mostly done.
|
||||
**/
|
||||
gboolean
|
||||
up_device_refresh_internal (UpDevice *device)
|
||||
up_device_refresh_internal (UpDevice *device, UpRefreshReason reason)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
UpDeviceClass *klass = UP_DEVICE_GET_CLASS (device);
|
||||
|
|
@ -636,7 +636,7 @@ up_device_refresh_internal (UpDevice *device)
|
|||
goto out;
|
||||
|
||||
/* do the refresh */
|
||||
ret = klass->refresh (device);
|
||||
ret = klass->refresh (device, reason);
|
||||
if (!ret) {
|
||||
g_debug ("no changes");
|
||||
goto out;
|
||||
|
|
|
|||
|
|
@ -42,13 +42,22 @@ typedef struct
|
|||
UpDevicePrivate *priv;
|
||||
} UpDevice;
|
||||
|
||||
typedef enum {
|
||||
UP_REFRESH_INIT,
|
||||
UP_REFRESH_POLL,
|
||||
UP_REFRESH_RESUME,
|
||||
UP_REFRESH_EVENT,
|
||||
UP_REFRESH_CHANGES,
|
||||
} UpRefreshReason;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UpExportedDeviceSkeletonClass parent_class;
|
||||
|
||||
/* vtable */
|
||||
gboolean (*coldplug) (UpDevice *device);
|
||||
gboolean (*refresh) (UpDevice *device);
|
||||
gboolean (*refresh) (UpDevice *device,
|
||||
UpRefreshReason reason);
|
||||
const gchar *(*get_id) (UpDevice *device);
|
||||
gboolean (*get_on_battery) (UpDevice *device,
|
||||
gboolean *on_battery);
|
||||
|
|
@ -67,7 +76,8 @@ gboolean up_device_get_on_battery (UpDevice *device,
|
|||
gboolean *on_battery);
|
||||
gboolean up_device_get_online (UpDevice *device,
|
||||
gboolean *online);
|
||||
gboolean up_device_refresh_internal (UpDevice *device);
|
||||
gboolean up_device_refresh_internal (UpDevice *device,
|
||||
UpRefreshReason reason);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue