mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-01-30 11:40:23 +01:00
Allow the daemon to get the global online state for all devices
Signed-off-by: Richard Hughes <richard@hughsie.com>
This commit is contained in:
parent
7cba688292
commit
a65e5761d9
4 changed files with 82 additions and 2 deletions
|
|
@ -89,6 +89,7 @@ static void dkp_daemon_init (DkpDaemon *seat);
|
|||
static void dkp_daemon_finalize (GObject *object);
|
||||
static gboolean dkp_daemon_get_on_battery_local (DkpDaemon *daemon);
|
||||
static gboolean dkp_daemon_get_low_battery_local (DkpDaemon *daemon);
|
||||
static gboolean dkp_daemon_get_on_ac_local (DkpDaemon *daemon);
|
||||
|
||||
G_DEFINE_TYPE (DkpDaemon, dkp_daemon, G_TYPE_OBJECT)
|
||||
|
||||
|
|
@ -418,6 +419,34 @@ dkp_daemon_get_low_battery_local (DkpDaemon *daemon)
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_daemon_get_on_ac_local:
|
||||
*
|
||||
* As soon as _any_ ac supply goes online, this is true
|
||||
**/
|
||||
static gboolean
|
||||
dkp_daemon_get_on_ac_local (DkpDaemon *daemon)
|
||||
{
|
||||
guint i;
|
||||
gboolean ret;
|
||||
gboolean result = FALSE;
|
||||
gboolean online;
|
||||
DkpDevice *device;
|
||||
const GPtrArray *array;
|
||||
|
||||
/* ask each device */
|
||||
array = dkp_device_list_get_array (daemon->priv->list);
|
||||
for (i=0; i<array->len; i++) {
|
||||
device = (DkpDevice *) g_ptr_array_index (array, i);
|
||||
ret = dkp_device_get_online (device, &online);
|
||||
if (ret && online) {
|
||||
result = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* gpk_daemon_device_changed:
|
||||
**/
|
||||
|
|
@ -438,7 +467,7 @@ gpk_daemon_device_changed (DkpDaemon *daemon, DevkitDevice *d, gboolean synthesi
|
|||
}
|
||||
|
||||
/* second, check if the on_battery and low_battery state has changed */
|
||||
ret = dkp_daemon_get_on_battery_local (daemon);
|
||||
ret = (dkp_daemon_get_on_battery_local (daemon) && !dkp_daemon_get_on_ac_local (daemon));
|
||||
if (ret != daemon->priv->on_battery) {
|
||||
daemon->priv->on_battery = ret;
|
||||
egg_debug ("now on_battery = %s", ret ? "yes" : "no");
|
||||
|
|
@ -842,7 +871,8 @@ dkp_daemon_new (void)
|
|||
g_list_foreach (devices, (GFunc) g_object_unref, NULL);
|
||||
g_list_free (devices);
|
||||
|
||||
daemon->priv->on_battery = dkp_daemon_get_on_battery_local (daemon);
|
||||
daemon->priv->on_battery = (dkp_daemon_get_on_battery_local (daemon) &&
|
||||
!dkp_daemon_get_on_ac_local (daemon));
|
||||
daemon->priv->low_battery = dkp_daemon_get_low_battery_local (daemon);
|
||||
|
||||
return daemon;
|
||||
|
|
|
|||
|
|
@ -396,6 +396,25 @@ dkp_device_get_low_battery (DkpDevice *device, gboolean *low_battery)
|
|||
return klass->get_low_battery (device, low_battery);
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_device_get_online:
|
||||
*
|
||||
* Note: Only implement for system devices, i.e. devices supplying the system
|
||||
**/
|
||||
gboolean
|
||||
dkp_device_get_online (DkpDevice *device, gboolean *online)
|
||||
{
|
||||
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
|
||||
|
||||
g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
|
||||
|
||||
/* no support */
|
||||
if (klass->get_online == NULL)
|
||||
return FALSE;
|
||||
|
||||
return klass->get_online (device, online);
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_device_get_id:
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ typedef struct
|
|||
gboolean *on_battery);
|
||||
gboolean (*get_low_battery) (DkpDevice *device,
|
||||
gboolean *low_battery);
|
||||
gboolean (*get_online) (DkpDevice *device,
|
||||
gboolean *online);
|
||||
} DkpDeviceClass;
|
||||
|
||||
typedef enum
|
||||
|
|
@ -85,6 +87,8 @@ gboolean dkp_device_get_on_battery (DkpDevice *device,
|
|||
gboolean *on_battery);
|
||||
gboolean dkp_device_get_low_battery (DkpDevice *device,
|
||||
gboolean *low_battery);
|
||||
gboolean dkp_device_get_online (DkpDevice *device,
|
||||
gboolean *online);
|
||||
void dkp_device_emit_changed (DkpDevice *device);
|
||||
|
||||
/* exported methods */
|
||||
|
|
|
|||
|
|
@ -177,6 +177,32 @@ dkp_supply_get_low_battery (DkpDevice *device, gboolean *low_battery)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_supply_get_online:
|
||||
**/
|
||||
static gboolean
|
||||
dkp_supply_get_online (DkpDevice *device, gboolean *online)
|
||||
{
|
||||
DkpSupply *supply = DKP_SUPPLY (device);
|
||||
DkpDeviceType type;
|
||||
gboolean online_tmp;
|
||||
|
||||
g_return_val_if_fail (DKP_IS_SUPPLY (supply), FALSE);
|
||||
g_return_val_if_fail (online != NULL, FALSE);
|
||||
|
||||
g_object_get (device,
|
||||
"type", &type,
|
||||
"online", &online_tmp,
|
||||
NULL);
|
||||
|
||||
if (type != DKP_DEVICE_TYPE_LINE_POWER)
|
||||
return FALSE;
|
||||
|
||||
*online = online_tmp;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_supply_calculate_rate:
|
||||
**/
|
||||
|
|
@ -599,6 +625,7 @@ dkp_supply_class_init (DkpSupplyClass *klass)
|
|||
object_class->finalize = dkp_supply_finalize;
|
||||
device_class->get_on_battery = dkp_supply_get_on_battery;
|
||||
device_class->get_low_battery = dkp_supply_get_low_battery;
|
||||
device_class->get_online = dkp_supply_get_online;
|
||||
device_class->coldplug = dkp_supply_coldplug;
|
||||
device_class->refresh = dkp_supply_refresh;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue