mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-04 21:08:10 +02:00
make get_on_battery and get_low_battery part of the DkpDevice vtable, not direct methods
This commit is contained in:
parent
5f43202a82
commit
c8789936b4
5 changed files with 53 additions and 22 deletions
|
|
@ -330,7 +330,7 @@ dkp_daemon_get_on_battery_local (DkpDaemon *daemon)
|
|||
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_source_get_on_battery (DKP_SOURCE (device), &on_battery);
|
||||
ret = dkp_device_get_on_battery (device, &on_battery);
|
||||
if (ret && on_battery) {
|
||||
result = TRUE;
|
||||
break;
|
||||
|
|
@ -358,7 +358,7 @@ dkp_daemon_get_low_battery_local (DkpDaemon *daemon)
|
|||
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_source_get_low_battery (DKP_SOURCE (device), &low_battery);
|
||||
ret = dkp_device_get_low_battery (device, &low_battery);
|
||||
if (ret && !low_battery) {
|
||||
result = FALSE;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -102,9 +102,30 @@ dkp_device_changed (DkpDevice *device, DevkitDevice *d, gboolean synthesized)
|
|||
/**
|
||||
* dkp_device_get_object_path:
|
||||
**/
|
||||
const char *
|
||||
const gchar *
|
||||
dkp_device_get_object_path (DkpDevice *device)
|
||||
{
|
||||
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
|
||||
return (klass->get_object_path (device));
|
||||
return klass->get_object_path (device);
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_device_get_on_battery:
|
||||
**/
|
||||
gboolean
|
||||
dkp_device_get_on_battery (DkpDevice *device, gboolean *on_battery)
|
||||
{
|
||||
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
|
||||
return klass->get_on_battery (device, on_battery);
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_device_get_low_battery:
|
||||
**/
|
||||
gboolean
|
||||
dkp_device_get_low_battery (DkpDevice *device, gboolean *low_battery)
|
||||
{
|
||||
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
|
||||
return klass->get_low_battery (device, low_battery);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
|
||||
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -46,11 +47,15 @@ typedef struct
|
|||
GObjectClass parent_class;
|
||||
|
||||
/* vtable */
|
||||
gboolean (*changed) (DkpDevice *device,
|
||||
gboolean (*changed) (DkpDevice *device,
|
||||
DevkitDevice *d,
|
||||
gboolean synthesized);
|
||||
void (*removed) (DkpDevice *device);
|
||||
const char *(*get_object_path) (DkpDevice *device);
|
||||
void (*removed) (DkpDevice *device);
|
||||
const gchar *(*get_object_path) (DkpDevice *device);
|
||||
gboolean (*get_on_battery) (DkpDevice *device,
|
||||
gboolean *on_battery);
|
||||
gboolean (*get_low_battery) (DkpDevice *device,
|
||||
gboolean *low_battery);
|
||||
} DkpDeviceClass;
|
||||
|
||||
GType dkp_device_get_type (void);
|
||||
|
|
@ -60,7 +65,11 @@ gboolean dkp_device_changed (DkpDevice *device,
|
|||
DevkitDevice *d,
|
||||
gboolean synthesized);
|
||||
void dkp_device_removed (DkpDevice *device);
|
||||
const char *dkp_device_get_object_path (DkpDevice *device);
|
||||
const gchar *dkp_device_get_object_path (DkpDevice *device);
|
||||
gboolean dkp_device_get_on_battery (DkpDevice *device,
|
||||
gboolean *on_battery);
|
||||
gboolean dkp_device_get_low_battery (DkpDevice *device,
|
||||
gboolean *low_battery);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -105,9 +105,11 @@ static guint signals[LAST_SIGNAL] = { 0 };
|
|||
G_DEFINE_TYPE (DkpSource, dkp_source, DKP_SOURCE_TYPE_DEVICE)
|
||||
#define DKP_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_SOURCE_TYPE_SOURCE, DkpSourcePrivate))
|
||||
|
||||
static const char *dkp_source_get_object_path (DkpDevice *device);
|
||||
static void dkp_source_removed (DkpDevice *device);
|
||||
static gboolean dkp_source_changed (DkpDevice *device, DevkitDevice *d, gboolean synthesized);
|
||||
static const char *dkp_source_get_object_path (DkpDevice *device);
|
||||
static gboolean dkp_source_get_on_battery (DkpDevice *device, gboolean *on_battery);
|
||||
static gboolean dkp_source_get_low_battery (DkpDevice *device, gboolean *low_battery);
|
||||
static void dkp_source_removed (DkpDevice *device);
|
||||
static gboolean dkp_source_changed (DkpDevice *device, DevkitDevice *d, gboolean synthesized);
|
||||
|
||||
/**
|
||||
* dkp_source_error_quark:
|
||||
|
|
@ -241,6 +243,8 @@ dkp_source_class_init (DkpSourceClass *klass)
|
|||
device_class->changed = dkp_source_changed;
|
||||
device_class->removed = dkp_source_removed;
|
||||
device_class->get_object_path = dkp_source_get_object_path;
|
||||
device_class->get_on_battery = dkp_source_get_on_battery;
|
||||
device_class->get_low_battery = dkp_source_get_low_battery;
|
||||
|
||||
g_type_class_add_private (klass, sizeof (DkpSourcePrivate));
|
||||
|
||||
|
|
@ -608,9 +612,11 @@ dkp_source_reset_values (DkpSource *source)
|
|||
/**
|
||||
* dkp_source_get_on_battery:
|
||||
**/
|
||||
gboolean
|
||||
dkp_source_get_on_battery (DkpSource *source, gboolean *on_battery)
|
||||
static gboolean
|
||||
dkp_source_get_on_battery (DkpDevice *device, gboolean *on_battery)
|
||||
{
|
||||
DkpSource *source = DKP_SOURCE (device);
|
||||
|
||||
g_return_val_if_fail (DKP_IS_SOURCE (source), FALSE);
|
||||
g_return_val_if_fail (on_battery != NULL, FALSE);
|
||||
|
||||
|
|
@ -626,17 +632,18 @@ dkp_source_get_on_battery (DkpSource *source, gboolean *on_battery)
|
|||
/**
|
||||
* dkp_source_get_low_battery:
|
||||
**/
|
||||
gboolean
|
||||
dkp_source_get_low_battery (DkpSource *source, gboolean *low_battery)
|
||||
static gboolean
|
||||
dkp_source_get_low_battery (DkpDevice *device, gboolean *low_battery)
|
||||
{
|
||||
gboolean ret;
|
||||
gboolean on_battery;
|
||||
DkpSource *source = DKP_SOURCE (device);
|
||||
|
||||
g_return_val_if_fail (DKP_IS_SOURCE (source), FALSE);
|
||||
g_return_val_if_fail (low_battery != NULL, FALSE);
|
||||
|
||||
/* reuse the common checks */
|
||||
ret = dkp_source_get_on_battery (source, &on_battery);
|
||||
ret = dkp_source_get_on_battery (device, &on_battery);
|
||||
if (!ret)
|
||||
return FALSE;
|
||||
|
||||
|
|
|
|||
|
|
@ -74,12 +74,6 @@ gboolean dkp_source_get_statistics (DkpSource *source,
|
|||
guint timespan,
|
||||
DBusGMethodInvocation *context);
|
||||
|
||||
/* needed for the on_battery and low_battery logic */
|
||||
gboolean dkp_source_get_on_battery (DkpSource *source,
|
||||
gboolean *on_battery);
|
||||
gboolean dkp_source_get_low_battery (DkpSource *source,
|
||||
gboolean *low_battery);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __DKP_SOURCE_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue