1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
5
* Licensed under the GNU General Public License Version 2
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
* @short_description: Client object for accessing information about UPower devices
26
* A helper GObject to use for accessing UPower devices, and to be notified
36
#include <glib-object.h>
39
#include "up-device.h"
40
#include "up-device-glue.h"
41
#include "up-stats-item.h"
42
#include "up-history-item.h"
44
static void up_device_class_init (UpDeviceClass *klass);
45
static void up_device_init (UpDevice *device);
46
static void up_device_finalize (GObject *object);
48
#define UP_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_DEVICE, UpDevicePrivate))
53
* Private #PkDevice data
55
struct _UpDevicePrivate
57
UpDeviceGlue *proxy_device;
59
/* For use when a UpDevice isn't backed by a D-Bus object
60
* by the UPower daemon */
61
GHashTable *offline_props;
84
PROP_ENERGY_FULL_DESIGN,
97
G_DEFINE_TYPE (UpDevice, up_device, G_TYPE_OBJECT)
100
* up_device_changed_cb:
103
up_device_changed_cb (UpDeviceGlue *proxy, GParamSpec *pspec, UpDevice *device)
105
if (g_strcmp0 (pspec->name, "type") == 0)
106
g_object_notify (G_OBJECT (device), "kind");
108
g_object_notify (G_OBJECT (device), pspec->name);
112
* up_device_set_object_path_sync:
113
* @device: a #UpDevice instance.
114
* @object_path: The UPower object path.
115
* @cancellable: a #GCancellable or %NULL
116
* @error: a #GError, or %NULL.
118
* Sets the object path of the object and fills up initial properties.
120
* Return value: #TRUE for success, else #FALSE and @error is used
125
up_device_set_object_path_sync (UpDevice *device, const gchar *object_path, GCancellable *cancellable, GError **error)
127
UpDeviceGlue *proxy_device;
130
g_return_val_if_fail (UP_IS_DEVICE (device), FALSE);
131
g_return_val_if_fail (object_path != NULL, FALSE);
133
if (device->priv->proxy_device != NULL)
137
if (!g_variant_is_object_path (object_path)) {
139
g_set_error (error, 1, 0,
140
"Object path invalid: %s", object_path);
144
g_clear_pointer (&device->priv->offline_props, g_hash_table_unref);
146
/* connect to the correct path for all the other methods */
147
proxy_device = up_device_glue_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
148
G_DBUS_PROXY_FLAGS_NONE,
149
"org.freedesktop.UPower",
153
if (proxy_device == NULL)
156
/* listen to Changed */
157
g_signal_connect (proxy_device, "notify",
158
G_CALLBACK (up_device_changed_cb), device);
161
device->priv->proxy_device = proxy_device;
167
* up_device_get_object_path:
168
* @device: a #UpDevice instance.
170
* Gets the object path for the device.
172
* Return value: the object path, or %NULL
177
up_device_get_object_path (UpDevice *device)
179
g_return_val_if_fail (UP_IS_DEVICE (device), NULL);
180
return g_dbus_proxy_get_object_path (G_DBUS_PROXY (device->priv->proxy_device));
184
* up_device_to_text_history:
187
up_device_to_text_history (UpDevice *device, GString *string, const gchar *type)
193
/* get a fair chunk of data */
194
array = up_device_get_history_sync (device, type, 120, 10, NULL, NULL);
199
g_string_append_printf (string, " History (%s):\n", type);
200
for (i=0; i<array->len; i++) {
201
item = (UpHistoryItem *) g_ptr_array_index (array, i);
202
g_string_append_printf (string, " %i\t%.3f\t%s\n",
203
up_history_item_get_time (item),
204
up_history_item_get_value (item),
205
up_device_state_to_string (up_history_item_get_state (item)));
207
g_ptr_array_unref (array);
211
* up_device_bool_to_string:
214
up_device_bool_to_string (gboolean ret)
216
return ret ? "yes" : "no";
220
* up_device_to_text_time_to_string:
223
up_device_to_text_time_to_string (gint seconds)
225
gfloat value = seconds;
228
return g_strdup ("unknown");
230
return g_strdup_printf ("%.0f seconds", value);
233
return g_strdup_printf ("%.1f minutes", value);
236
return g_strdup_printf ("%.1f hours", value);
238
return g_strdup_printf ("%.1f days", value);
243
* @device: a #UpDevice instance.
245
* Converts the device to a string description.
247
* Return value: text representation of #UpDevice
252
up_device_to_text (UpDevice *device)
259
UpDevicePrivate *priv;
266
g_return_val_if_fail (UP_IS_DEVICE (device), NULL);
267
g_return_val_if_fail (device->priv->proxy_device != NULL, NULL);
271
is_display = (g_strcmp0 ("/org/freedesktop/UPower/devices/DisplayDevice", up_device_get_object_path (device)) == 0);
273
/* get a human readable time */
274
t = (time_t) up_device_glue_get_update_time (priv->proxy_device);
275
time_tm = localtime (&t);
276
strftime (time_buf, sizeof time_buf, "%c", time_tm);
278
string = g_string_new ("");
280
g_string_append_printf (string, " native-path: %s\n", up_device_glue_get_native_path (priv->proxy_device));
281
vendor = up_device_glue_get_vendor (priv->proxy_device);
282
if (vendor != NULL && vendor[0] != '\0')
283
g_string_append_printf (string, " vendor: %s\n", vendor);
284
model = up_device_glue_get_model (priv->proxy_device);
285
if (model != NULL && model[0] != '\0')
286
g_string_append_printf (string, " model: %s\n", model);
287
serial = up_device_glue_get_serial (priv->proxy_device);
288
if (serial != NULL && serial[0] != '\0')
289
g_string_append_printf (string, " serial: %s\n", serial);
290
g_string_append_printf (string, " power supply: %s\n", up_device_bool_to_string (up_device_glue_get_power_supply (priv->proxy_device)));
291
g_string_append_printf (string, " updated: %s (%d seconds ago)\n", time_buf, (int) (time (NULL) - up_device_glue_get_update_time (priv->proxy_device)));
292
g_string_append_printf (string, " has history: %s\n", up_device_bool_to_string (up_device_glue_get_has_history (priv->proxy_device)));
293
g_string_append_printf (string, " has statistics: %s\n", up_device_bool_to_string (up_device_glue_get_has_statistics (priv->proxy_device)));
295
kind = up_device_glue_get_type_ (priv->proxy_device);
296
g_string_append_printf (string, " %s\n", up_device_kind_to_string (kind));
298
if (kind == UP_DEVICE_KIND_BATTERY ||
299
kind == UP_DEVICE_KIND_MOUSE ||
300
kind == UP_DEVICE_KIND_KEYBOARD ||
301
kind == UP_DEVICE_KIND_UPS)
302
g_string_append_printf (string, " present: %s\n", up_device_bool_to_string (up_device_glue_get_is_present (priv->proxy_device)));
303
if ((kind == UP_DEVICE_KIND_PHONE ||
304
kind == UP_DEVICE_KIND_BATTERY ||
305
kind == UP_DEVICE_KIND_MOUSE ||
306
kind == UP_DEVICE_KIND_KEYBOARD) &&
308
g_string_append_printf (string, " rechargeable: %s\n", up_device_bool_to_string (up_device_glue_get_is_rechargeable (priv->proxy_device)));
309
if (kind == UP_DEVICE_KIND_BATTERY ||
310
kind == UP_DEVICE_KIND_MOUSE ||
311
kind == UP_DEVICE_KIND_KEYBOARD ||
312
kind == UP_DEVICE_KIND_UPS)
313
g_string_append_printf (string, " state: %s\n", up_device_state_to_string (up_device_glue_get_state (priv->proxy_device)));
314
g_string_append_printf (string, " warning-level: %s\n", up_device_level_to_string (up_device_glue_get_warning_level (priv->proxy_device)));
315
if (kind == UP_DEVICE_KIND_BATTERY) {
316
g_string_append_printf (string, " energy: %g Wh\n", up_device_glue_get_energy (priv->proxy_device));
318
g_string_append_printf (string, " energy-empty: %g Wh\n", up_device_glue_get_energy_empty (priv->proxy_device));
319
g_string_append_printf (string, " energy-full: %g Wh\n", up_device_glue_get_energy_full (priv->proxy_device));
321
g_string_append_printf (string, " energy-full-design: %g Wh\n", up_device_glue_get_energy_full_design (priv->proxy_device));
323
if (kind == UP_DEVICE_KIND_BATTERY ||
324
kind == UP_DEVICE_KIND_MONITOR)
325
g_string_append_printf (string, " energy-rate: %g W\n", up_device_glue_get_energy_rate (priv->proxy_device));
326
if (kind == UP_DEVICE_KIND_UPS ||
327
kind == UP_DEVICE_KIND_BATTERY ||
328
kind == UP_DEVICE_KIND_MONITOR) {
329
if (up_device_glue_get_voltage (priv->proxy_device) > 0)
330
g_string_append_printf (string, " voltage: %g V\n", up_device_glue_get_voltage (priv->proxy_device));
332
if (kind == UP_DEVICE_KIND_KEYBOARD) {
333
if (up_device_glue_get_luminosity (priv->proxy_device) > 0)
334
g_string_append_printf (string, " luminosity: %g lx\n", up_device_glue_get_luminosity (priv->proxy_device));
336
if (kind == UP_DEVICE_KIND_BATTERY ||
337
kind == UP_DEVICE_KIND_UPS) {
338
if (up_device_glue_get_time_to_full (priv->proxy_device) > 0) {
339
time_str = up_device_to_text_time_to_string (up_device_glue_get_time_to_full (priv->proxy_device));
340
g_string_append_printf (string, " time to full: %s\n", time_str);
343
if (up_device_glue_get_time_to_empty (priv->proxy_device) > 0) {
344
time_str = up_device_to_text_time_to_string (up_device_glue_get_time_to_empty (priv->proxy_device));
345
g_string_append_printf (string, " time to empty: %s\n", time_str);
349
if (kind == UP_DEVICE_KIND_BATTERY ||
350
kind == UP_DEVICE_KIND_MOUSE ||
351
kind == UP_DEVICE_KIND_KEYBOARD ||
352
kind == UP_DEVICE_KIND_PHONE ||
353
kind == UP_DEVICE_KIND_TABLET ||
354
kind == UP_DEVICE_KIND_COMPUTER ||
355
kind == UP_DEVICE_KIND_MEDIA_PLAYER ||
356
kind == UP_DEVICE_KIND_UPS)
357
g_string_append_printf (string, " percentage: %g%%\n", up_device_glue_get_percentage (priv->proxy_device));
358
if (kind == UP_DEVICE_KIND_BATTERY) {
359
if (up_device_glue_get_temperature (priv->proxy_device) > 0)
360
g_string_append_printf (string, " temperature: %g degrees C\n", up_device_glue_get_temperature (priv->proxy_device));
361
if (up_device_glue_get_capacity (priv->proxy_device) > 0)
362
g_string_append_printf (string, " capacity: %g%%\n", up_device_glue_get_capacity (priv->proxy_device));
364
if (kind == UP_DEVICE_KIND_BATTERY) {
365
if (up_device_glue_get_technology (priv->proxy_device) != UP_DEVICE_TECHNOLOGY_UNKNOWN)
366
g_string_append_printf (string, " technology: %s\n", up_device_technology_to_string (up_device_glue_get_technology (priv->proxy_device)));
368
if (kind == UP_DEVICE_KIND_LINE_POWER)
369
g_string_append_printf (string, " online: %s\n", up_device_bool_to_string (up_device_glue_get_online (priv->proxy_device)));
371
g_string_append_printf (string, " icon-name: '%s'\n", up_device_glue_get_icon_name (priv->proxy_device));
373
/* if we can, get history */
374
if (up_device_glue_get_has_history (priv->proxy_device)) {
375
up_device_to_text_history (device, string, "charge");
376
up_device_to_text_history (device, string, "rate");
379
return g_string_free (string, FALSE);
383
* up_device_refresh_sync:
384
* @device: a #UpDevice instance.
385
* @cancellable: a #GCancellable or %NULL
386
* @error: a #GError, or %NULL.
388
* Refreshes properties on the device.
389
* This function is normally not required.
391
* Return value: #TRUE for success, else #FALSE and @error is used
396
up_device_refresh_sync (UpDevice *device, GCancellable *cancellable, GError **error)
398
g_return_val_if_fail (UP_IS_DEVICE (device), FALSE);
399
g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
401
return up_device_glue_call_refresh_sync (device->priv->proxy_device, cancellable, error);
405
* up_device_get_history_sync:
406
* @device: a #UpDevice instance.
407
* @type: The type of history, known values are "rate" and "charge".
408
* @timespec: the amount of time to look back into time.
409
* @resolution: the resolution of data.
410
* @cancellable: a #GCancellable or %NULL
411
* @error: a #GError, or %NULL.
413
* Gets the device history.
415
* Return value: (element-type UpHistoryItem) (transfer full): an array of #UpHistoryItem's, with the most
416
* recent one being first; %NULL if @error is set or @device is
422
up_device_get_history_sync (UpDevice *device, const gchar *type, guint timespec, guint resolution, GCancellable *cancellable, GError **error)
424
GError *error_local = NULL;
427
GPtrArray *array = NULL;
432
g_return_val_if_fail (UP_IS_DEVICE (device), NULL);
433
g_return_val_if_fail (device->priv->proxy_device != NULL, NULL);
435
/* get compound data */
436
ret = up_device_glue_call_get_history_sync (device->priv->proxy_device,
444
g_set_error (error, 1, 0, "GetHistory(%s,%i) on %s failed: %s", type, timespec,
445
up_device_get_object_path (device), error_local->message);
446
g_error_free (error_local);
450
iter = g_variant_iter_new (gva);
451
len = g_variant_iter_n_children (iter);
455
g_set_error_literal (error, 1, 0, "no data");
456
g_variant_iter_free (iter);
461
array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
462
for (i = 0; i < len; i++) {
468
v = g_variant_iter_next_value (iter);
469
g_variant_get (v, "(udu)",
470
&time, &value, &state);
473
obj = up_history_item_new ();
474
up_history_item_set_time (obj, time);
475
up_history_item_set_value (obj, value);
476
up_history_item_set_state (obj, state);
478
g_ptr_array_add (array, obj);
480
g_variant_iter_free (iter);
484
g_variant_unref (gva);
489
* up_device_get_statistics_sync:
490
* @device: a #UpDevice instance.
491
* @type: the type of statistics.
492
* @cancellable: a #GCancellable or %NULL
493
* @error: a #GError, or %NULL.
495
* Gets the device current statistics.
497
* Return value: (element-type UpStatsItem) (transfer full): an array of #UpStatsItem's, else #NULL and @error is used
502
up_device_get_statistics_sync (UpDevice *device, const gchar *type, GCancellable *cancellable, GError **error)
504
GError *error_local = NULL;
507
GPtrArray *array = NULL;
512
g_return_val_if_fail (UP_IS_DEVICE (device), NULL);
513
g_return_val_if_fail (device->priv->proxy_device != NULL, NULL);
515
/* get compound data */
516
ret = up_device_glue_call_get_statistics_sync (device->priv->proxy_device,
522
g_set_error (error, 1, 0, "GetStatistics(%s) on %s failed: %s", type,
523
up_device_get_object_path (device), error_local->message);
524
g_error_free (error_local);
528
iter = g_variant_iter_new (gva);
529
len = g_variant_iter_n_children (iter);
533
g_set_error_literal (error, 1, 0, "no data");
534
g_variant_iter_free (iter);
539
array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
540
for (i = 0; i < len; i++) {
543
gdouble value, accuracy;
545
v = g_variant_iter_next_value (iter);
546
g_variant_get (v, "(dd)",
550
obj = up_stats_item_new ();
551
up_stats_item_set_value (obj, value);
552
up_stats_item_set_accuracy (obj, accuracy);
554
g_ptr_array_add (array, obj);
556
g_variant_iter_free (iter);
560
g_variant_unref (gva);
565
* up_device_set_property:
568
up_device_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
570
UpDevice *device = UP_DEVICE (object);
572
if (device->priv->proxy_device == NULL) {
575
v = g_slice_new0 (GValue);
576
g_value_init (v, G_VALUE_TYPE (value));
577
g_value_copy (value, v);
578
g_hash_table_insert (device->priv->offline_props, GUINT_TO_POINTER (prop_id), v);
584
case PROP_NATIVE_PATH:
585
up_device_glue_set_native_path (device->priv->proxy_device, g_value_get_string (value));
588
up_device_glue_set_vendor (device->priv->proxy_device, g_value_get_string (value));
591
up_device_glue_set_model (device->priv->proxy_device, g_value_get_string (value));
594
up_device_glue_set_serial (device->priv->proxy_device, g_value_get_string (value));
596
case PROP_UPDATE_TIME:
597
up_device_glue_set_update_time (device->priv->proxy_device, g_value_get_uint64 (value));
600
up_device_glue_set_type_ (device->priv->proxy_device, g_value_get_uint (value));
602
case PROP_POWER_SUPPLY:
603
up_device_glue_set_power_supply (device->priv->proxy_device, g_value_get_boolean (value));
606
up_device_glue_set_online (device->priv->proxy_device, g_value_get_boolean (value));
608
case PROP_IS_PRESENT:
609
up_device_glue_set_is_present (device->priv->proxy_device, g_value_get_boolean (value));
611
case PROP_IS_RECHARGEABLE:
612
up_device_glue_set_is_rechargeable (device->priv->proxy_device, g_value_get_boolean (value));
614
case PROP_HAS_HISTORY:
615
up_device_glue_set_has_history (device->priv->proxy_device, g_value_get_boolean (value));
617
case PROP_HAS_STATISTICS:
618
up_device_glue_set_has_statistics (device->priv->proxy_device, g_value_get_boolean (value));
621
up_device_glue_set_state (device->priv->proxy_device, g_value_get_uint (value));
624
up_device_glue_set_capacity (device->priv->proxy_device, g_value_get_double (value));
627
up_device_glue_set_energy (device->priv->proxy_device, g_value_get_double (value));
629
case PROP_ENERGY_EMPTY:
630
up_device_glue_set_energy_empty (device->priv->proxy_device, g_value_get_double (value));
632
case PROP_ENERGY_FULL:
633
up_device_glue_set_energy_full (device->priv->proxy_device, g_value_get_double (value));
635
case PROP_ENERGY_FULL_DESIGN:
636
up_device_glue_set_energy_full_design (device->priv->proxy_device, g_value_get_double (value));
638
case PROP_ENERGY_RATE:
639
up_device_glue_set_energy_rate (device->priv->proxy_device, g_value_get_double (value));
642
up_device_glue_set_voltage (device->priv->proxy_device, g_value_get_double (value));
644
case PROP_LUMINOSITY:
645
up_device_glue_set_luminosity (device->priv->proxy_device, g_value_get_double (value));
647
case PROP_TIME_TO_EMPTY:
648
up_device_glue_set_time_to_empty (device->priv->proxy_device, g_value_get_int64 (value));
650
case PROP_TIME_TO_FULL:
651
up_device_glue_set_time_to_full (device->priv->proxy_device, g_value_get_int64 (value));
653
case PROP_PERCENTAGE:
654
up_device_glue_set_percentage (device->priv->proxy_device, g_value_get_double (value));
656
case PROP_TEMPERATURE:
657
up_device_glue_set_temperature (device->priv->proxy_device, g_value_get_double (value));
659
case PROP_TECHNOLOGY:
660
up_device_glue_set_technology (device->priv->proxy_device, g_value_get_uint (value));
662
case PROP_WARNING_LEVEL:
663
up_device_glue_set_warning_level (device->priv->proxy_device, g_value_get_uint (value));
666
up_device_glue_set_icon_name (device->priv->proxy_device, g_value_get_string (value));
669
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
675
* up_device_get_property:
678
up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
680
UpDevice *device = UP_DEVICE (object);
682
if (device->priv->proxy_device == NULL) {
685
v = g_hash_table_lookup (device->priv->offline_props, GUINT_TO_POINTER(prop_id));
687
g_value_copy (v, value);
689
g_warning ("Property ID '%s' (%d) was never set", pspec->name, prop_id);
695
case PROP_UPDATE_TIME:
696
g_value_set_uint64 (value, up_device_glue_get_update_time (device->priv->proxy_device));
699
g_value_set_string (value, up_device_glue_get_vendor (device->priv->proxy_device));
702
g_value_set_string (value, up_device_glue_get_model (device->priv->proxy_device));
705
g_value_set_string (value, up_device_glue_get_serial (device->priv->proxy_device));
707
case PROP_NATIVE_PATH:
708
g_value_set_string (value, up_device_glue_get_native_path (device->priv->proxy_device));
710
case PROP_POWER_SUPPLY:
711
g_value_set_boolean (value, up_device_glue_get_power_supply (device->priv->proxy_device));
714
g_value_set_boolean (value, up_device_glue_get_online (device->priv->proxy_device));
716
case PROP_IS_PRESENT:
717
g_value_set_boolean (value, up_device_glue_get_is_present (device->priv->proxy_device));
719
case PROP_IS_RECHARGEABLE:
720
g_value_set_boolean (value, up_device_glue_get_is_rechargeable (device->priv->proxy_device));
722
case PROP_HAS_HISTORY:
723
g_value_set_boolean (value, up_device_glue_get_has_history (device->priv->proxy_device));
725
case PROP_HAS_STATISTICS:
726
g_value_set_boolean (value, up_device_glue_get_has_statistics (device->priv->proxy_device));
729
g_value_set_uint (value, up_device_glue_get_type_ (device->priv->proxy_device));
732
g_value_set_uint (value, up_device_glue_get_state (device->priv->proxy_device));
734
case PROP_TECHNOLOGY:
735
g_value_set_uint (value, up_device_glue_get_technology (device->priv->proxy_device));
738
g_value_set_double (value, up_device_glue_get_capacity (device->priv->proxy_device));
741
g_value_set_double (value, up_device_glue_get_energy (device->priv->proxy_device));
743
case PROP_ENERGY_EMPTY:
744
g_value_set_double (value, up_device_glue_get_energy_empty (device->priv->proxy_device));
746
case PROP_ENERGY_FULL:
747
g_value_set_double (value, up_device_glue_get_energy_full (device->priv->proxy_device));
749
case PROP_ENERGY_FULL_DESIGN:
750
g_value_set_double (value, up_device_glue_get_energy_full_design (device->priv->proxy_device));
752
case PROP_ENERGY_RATE:
753
g_value_set_double (value, up_device_glue_get_energy_rate (device->priv->proxy_device));
756
g_value_set_double (value, up_device_glue_get_voltage (device->priv->proxy_device));
758
case PROP_LUMINOSITY:
759
g_value_set_double (value, up_device_glue_get_luminosity (device->priv->proxy_device));
761
case PROP_TIME_TO_EMPTY:
762
g_value_set_int64 (value, up_device_glue_get_time_to_empty (device->priv->proxy_device));
764
case PROP_TIME_TO_FULL:
765
g_value_set_int64 (value, up_device_glue_get_time_to_full (device->priv->proxy_device));
767
case PROP_PERCENTAGE:
768
g_value_set_double (value, up_device_glue_get_percentage (device->priv->proxy_device));
770
case PROP_TEMPERATURE:
771
g_value_set_double (value, up_device_glue_get_temperature (device->priv->proxy_device));
773
case PROP_WARNING_LEVEL:
774
g_value_set_uint (value, up_device_glue_get_warning_level (device->priv->proxy_device));
777
g_value_set_string (value, up_device_glue_get_icon_name (device->priv->proxy_device));
780
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
786
* up_device_class_init:
789
up_device_class_init (UpDeviceClass *klass)
791
GObjectClass *object_class = G_OBJECT_CLASS (klass);
792
object_class->finalize = up_device_finalize;
793
object_class->set_property = up_device_set_property;
794
object_class->get_property = up_device_get_property;
797
* UpDevice:update-time:
799
* The last time the device was updated.
803
g_object_class_install_property (object_class,
805
g_param_spec_uint64 ("update-time",
812
* The vendor of the device.
816
g_object_class_install_property (object_class,
818
g_param_spec_string ("vendor",
825
* The model of the device.
829
g_object_class_install_property (object_class,
831
g_param_spec_string ("model",
838
* The serial number of the device.
842
g_object_class_install_property (object_class,
844
g_param_spec_string ("serial",
849
* UpDevice:native-path:
851
* The native path of the device, useful for direct device access.
855
g_object_class_install_property (object_class,
857
g_param_spec_string ("native-path",
862
* UpDevice:power-supply:
864
* If the device is powering the system.
868
g_object_class_install_property (object_class,
870
g_param_spec_boolean ("power-supply",
877
* If the device is online, i.e. connected.
881
g_object_class_install_property (object_class,
883
g_param_spec_boolean ("online",
888
* UpDevice:is-present:
890
* If the device is present, as some devices like laptop batteries
891
* can be removed, leaving an empty bay that is still technically a
896
g_object_class_install_property (object_class,
898
g_param_spec_boolean ("is-present",
903
* UpDevice:is-rechargeable:
905
* If the device has a rechargable battery.
909
g_object_class_install_property (object_class,
910
PROP_IS_RECHARGEABLE,
911
g_param_spec_boolean ("is-rechargeable",
916
* UpDevice:has-history:
918
* If the device has history data that might be useful.
922
g_object_class_install_property (object_class,
924
g_param_spec_boolean ("has-history",
929
* UpDevice:has-statistics:
931
* If the device has statistics data that might be useful.
935
g_object_class_install_property (object_class,
937
g_param_spec_boolean ("has-statistics",
944
* The device kind, e.g. %UP_DEVICE_KIND_KEYBOARD.
948
g_object_class_install_property (object_class,
950
g_param_spec_uint ("kind",
952
UP_DEVICE_KIND_UNKNOWN,
954
UP_DEVICE_KIND_UNKNOWN,
959
* The state the device is in at this time, e.g. %UP_DEVICE_STATE_EMPTY.
963
g_object_class_install_property (object_class,
965
g_param_spec_uint ("state",
967
UP_DEVICE_STATE_UNKNOWN,
968
UP_DEVICE_STATE_LAST,
969
UP_DEVICE_STATE_UNKNOWN,
972
* UpDevice:technology:
974
* The battery technology e.g. %UP_DEVICE_TECHNOLOGY_LITHIUM_ION.
978
g_object_class_install_property (object_class,
980
g_param_spec_uint ("technology",
982
UP_DEVICE_TECHNOLOGY_UNKNOWN,
983
UP_DEVICE_TECHNOLOGY_LAST,
984
UP_DEVICE_TECHNOLOGY_UNKNOWN,
989
* The percentage capacity of the device where 100% means the device has
990
* the same charge potential as when it was manufactured.
994
g_object_class_install_property (object_class,
996
g_param_spec_double ("capacity", NULL, NULL,
1002
* The energy left in the device. Measured in mWh.
1006
g_object_class_install_property (object_class,
1008
g_param_spec_double ("energy", NULL, NULL,
1009
0.0, G_MAXDOUBLE, 0.0,
1010
G_PARAM_READWRITE));
1012
* UpDevice:energy-empty:
1014
* The energy the device will have when it is empty. This is usually zero.
1019
g_object_class_install_property (object_class,
1021
g_param_spec_double ("energy-empty", NULL, NULL,
1022
0.0, G_MAXDOUBLE, 0.0,
1023
G_PARAM_READWRITE));
1025
* UpDevice:energy-full:
1027
* The amount of energy when the device is fully charged. Measured in mWh.
1031
g_object_class_install_property (object_class,
1033
g_param_spec_double ("energy-full", NULL, NULL,
1034
0.0, G_MAXDOUBLE, 0.0,
1035
G_PARAM_READWRITE));
1037
* UpDevice:energy-full-design:
1039
* The amount of energy when the device was brand new. Measured in mWh.
1043
g_object_class_install_property (object_class,
1044
PROP_ENERGY_FULL_DESIGN,
1045
g_param_spec_double ("energy-full-design", NULL, NULL,
1046
0.0, G_MAXDOUBLE, 0.0,
1047
G_PARAM_READWRITE));
1049
* UpDevice:energy-rate:
1051
* The rate of discharge or charge. Measured in mW.
1055
g_object_class_install_property (object_class,
1057
g_param_spec_double ("energy-rate", NULL, NULL,
1058
0.0, G_MAXDOUBLE, 0.0,
1059
G_PARAM_READWRITE));
1063
* The current voltage of the device.
1067
g_object_class_install_property (object_class,
1069
g_param_spec_double ("voltage", NULL, NULL,
1070
0.0, G_MAXDOUBLE, 0.0,
1071
G_PARAM_READWRITE));
1074
* UpDevice:luminosity:
1076
* The current luminosity of the device.
1080
g_object_class_install_property (object_class,
1082
g_param_spec_double ("luminosity", NULL, NULL,
1083
0.0, G_MAXDOUBLE, 0.0,
1084
G_PARAM_READWRITE));
1086
* UpDevice:time-to-empty:
1088
* The amount of time until the device is empty.
1092
g_object_class_install_property (object_class,
1094
g_param_spec_int64 ("time-to-empty", NULL, NULL,
1096
G_PARAM_READWRITE));
1098
* UpDevice:time-to-full:
1100
* The amount of time until the device is fully charged.
1104
g_object_class_install_property (object_class,
1106
g_param_spec_int64 ("time-to-full", NULL, NULL,
1108
G_PARAM_READWRITE));
1110
* UpDevice:percentage:
1112
* The percentage charge of the device.
1116
g_object_class_install_property (object_class,
1118
g_param_spec_double ("percentage", NULL, NULL,
1120
G_PARAM_READWRITE));
1122
* UpDevice:temperature:
1124
* The temperature of the device in degrees Celsius.
1128
g_object_class_install_property (object_class,
1130
g_param_spec_double ("temperature", NULL, NULL,
1131
0.0, G_MAXDOUBLE, 0.0,
1132
G_PARAM_READWRITE));
1134
* UpDevice:warning-level:
1136
* The warning level e.g. %UP_DEVICE_LEVEL_WARNING.
1140
g_object_class_install_property (object_class,
1142
g_param_spec_uint ("warning-level",
1144
UP_DEVICE_LEVEL_UNKNOWN,
1145
UP_DEVICE_LEVEL_LAST,
1146
UP_DEVICE_LEVEL_UNKNOWN,
1147
G_PARAM_READWRITE));
1150
* UpDevice:icon-name:
1152
* The icon name, following the Icon Naming Speficiation
1156
g_object_class_install_property (object_class,
1158
g_param_spec_string ("icon-name",
1160
G_PARAM_READWRITE));
1162
g_type_class_add_private (klass, sizeof (UpDevicePrivate));
1166
value_free (GValue *value)
1168
g_value_unset (value);
1169
g_slice_free (GValue, value);
1176
up_device_init (UpDevice *device)
1178
device->priv = UP_DEVICE_GET_PRIVATE (device);
1179
device->priv->offline_props = g_hash_table_new_full (g_direct_hash,
1182
(GDestroyNotify) value_free);
1186
* up_device_finalize:
1189
up_device_finalize (GObject *object)
1193
g_return_if_fail (UP_IS_DEVICE (object));
1195
device = UP_DEVICE (object);
1197
if (device->priv->proxy_device != NULL)
1198
g_object_unref (device->priv->proxy_device);
1200
g_clear_pointer (&device->priv->offline_props, g_hash_table_unref);
1202
G_OBJECT_CLASS (up_device_parent_class)->finalize (object);
1208
* Creates a new #UpDevice object.
1210
* Return value: a new UpDevice object.
1215
up_device_new (void)
1217
return UP_DEVICE (g_object_new (UP_TYPE_DEVICE, NULL));