~ubuntu-branches/debian/sid/upower/sid

« back to all changes in this revision

Viewing changes to .pc/git_init_variants.patch/libupower-glib/up-device.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2015-05-29 10:19:59 UTC
  • mfrom: (1.6.4)
  • Revision ID: package-import@ubuntu.com-20150529101959-1mdg1jrmzyxqs6mk
Tags: 0.99.3-1
* New upstream release:
  - Support Logitech Unifying in Linux 3.19+ (Closes: #785725, LP: #1448834)
  - Fix Bluetooth HID batteries with recent kernels (Closes: #772095,
    LP: #772095)
* Drop git_init_variants.patch, included in this release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2
 
 *
3
 
 * Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
4
 
 *
5
 
 * Licensed under the GNU General Public License Version 2
6
 
 *
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.
11
 
 *
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.
16
 
 *
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.
20
 
 */
21
 
 
22
 
/**
23
 
 * SECTION:up-device
24
 
 * @short_description: Client object for accessing information about UPower devices
25
 
 *
26
 
 * A helper GObject to use for accessing UPower devices, and to be notified
27
 
 * when it is changed.
28
 
 *
29
 
 * See also: #UpClient
30
 
 */
31
 
 
32
 
#include "config.h"
33
 
 
34
 
#include <stdlib.h>
35
 
#include <stdio.h>
36
 
#include <glib-object.h>
37
 
#include <string.h>
38
 
 
39
 
#include "up-device.h"
40
 
#include "up-device-glue.h"
41
 
#include "up-stats-item.h"
42
 
#include "up-history-item.h"
43
 
 
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);
47
 
 
48
 
#define UP_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_DEVICE, UpDevicePrivate))
49
 
 
50
 
/**
51
 
 * UpDevicePrivate:
52
 
 *
53
 
 * Private #PkDevice data
54
 
 **/
55
 
struct _UpDevicePrivate
56
 
{
57
 
        UpDeviceGlue            *proxy_device;
58
 
 
59
 
        /* For use when a UpDevice isn't backed by a D-Bus object
60
 
         * by the UPower daemon */
61
 
        GHashTable              *offline_props;
62
 
};
63
 
 
64
 
enum {
65
 
        PROP_0,
66
 
        PROP_UPDATE_TIME,
67
 
        PROP_VENDOR,
68
 
        PROP_MODEL,
69
 
        PROP_SERIAL,
70
 
        PROP_NATIVE_PATH,
71
 
        PROP_POWER_SUPPLY,
72
 
        PROP_ONLINE,
73
 
        PROP_IS_PRESENT,
74
 
        PROP_IS_RECHARGEABLE,
75
 
        PROP_HAS_HISTORY,
76
 
        PROP_HAS_STATISTICS,
77
 
        PROP_KIND,
78
 
        PROP_STATE,
79
 
        PROP_TECHNOLOGY,
80
 
        PROP_CAPACITY,
81
 
        PROP_ENERGY,
82
 
        PROP_ENERGY_EMPTY,
83
 
        PROP_ENERGY_FULL,
84
 
        PROP_ENERGY_FULL_DESIGN,
85
 
        PROP_ENERGY_RATE,
86
 
        PROP_VOLTAGE,
87
 
        PROP_LUMINOSITY,
88
 
        PROP_TIME_TO_EMPTY,
89
 
        PROP_TIME_TO_FULL,
90
 
        PROP_PERCENTAGE,
91
 
        PROP_TEMPERATURE,
92
 
        PROP_WARNING_LEVEL,
93
 
        PROP_ICON_NAME,
94
 
        PROP_LAST
95
 
};
96
 
 
97
 
G_DEFINE_TYPE (UpDevice, up_device, G_TYPE_OBJECT)
98
 
 
99
 
/*
100
 
 * up_device_changed_cb:
101
 
 */
102
 
static void
103
 
up_device_changed_cb (UpDeviceGlue *proxy, GParamSpec *pspec, UpDevice *device)
104
 
{
105
 
        if (g_strcmp0 (pspec->name, "type") == 0)
106
 
                g_object_notify (G_OBJECT (device), "kind");
107
 
        else
108
 
                g_object_notify (G_OBJECT (device), pspec->name);
109
 
}
110
 
 
111
 
/**
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.
117
 
 *
118
 
 * Sets the object path of the object and fills up initial properties.
119
 
 *
120
 
 * Return value: #TRUE for success, else #FALSE and @error is used
121
 
 *
122
 
 * Since: 0.9.0
123
 
 **/
124
 
gboolean
125
 
up_device_set_object_path_sync (UpDevice *device, const gchar *object_path, GCancellable *cancellable, GError **error)
126
 
{
127
 
        UpDeviceGlue *proxy_device;
128
 
        gboolean ret = TRUE;
129
 
 
130
 
        g_return_val_if_fail (UP_IS_DEVICE (device), FALSE);
131
 
        g_return_val_if_fail (object_path != NULL, FALSE);
132
 
 
133
 
        if (device->priv->proxy_device != NULL)
134
 
                return FALSE;
135
 
 
136
 
        /* check valid */
137
 
        if (!g_variant_is_object_path (object_path)) {
138
 
                ret = FALSE;
139
 
                g_set_error (error, 1, 0,
140
 
                             "Object path invalid: %s", object_path);
141
 
                goto out;
142
 
        }
143
 
 
144
 
        g_clear_pointer (&device->priv->offline_props, g_hash_table_unref);
145
 
 
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",
150
 
                                                              object_path,
151
 
                                                              cancellable,
152
 
                                                              error);
153
 
        if (proxy_device == NULL)
154
 
                return FALSE;
155
 
 
156
 
        /* listen to Changed */
157
 
        g_signal_connect (proxy_device, "notify",
158
 
                          G_CALLBACK (up_device_changed_cb), device);
159
 
 
160
 
        /* yay */
161
 
        device->priv->proxy_device = proxy_device;
162
 
out:
163
 
        return ret;
164
 
}
165
 
 
166
 
/**
167
 
 * up_device_get_object_path:
168
 
 * @device: a #UpDevice instance.
169
 
 *
170
 
 * Gets the object path for the device.
171
 
 *
172
 
 * Return value: the object path, or %NULL
173
 
 *
174
 
 * Since: 0.9.0
175
 
 **/
176
 
const gchar *
177
 
up_device_get_object_path (UpDevice *device)
178
 
{
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));
181
 
}
182
 
 
183
 
/*
184
 
 * up_device_to_text_history:
185
 
 */
186
 
static void
187
 
up_device_to_text_history (UpDevice *device, GString *string, const gchar *type)
188
 
{
189
 
        guint i;
190
 
        GPtrArray *array;
191
 
        UpHistoryItem *item;
192
 
 
193
 
        /* get a fair chunk of data */
194
 
        array = up_device_get_history_sync (device, type, 120, 10, NULL, NULL);
195
 
        if (array == NULL)
196
 
                return;
197
 
 
198
 
        /* pretty print */
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)));
206
 
        }
207
 
        g_ptr_array_unref (array);
208
 
}
209
 
 
210
 
/*
211
 
 * up_device_bool_to_string:
212
 
 */
213
 
static const gchar *
214
 
up_device_bool_to_string (gboolean ret)
215
 
{
216
 
        return ret ? "yes" : "no";
217
 
}
218
 
 
219
 
/*
220
 
 * up_device_to_text_time_to_string:
221
 
 */
222
 
static gchar *
223
 
up_device_to_text_time_to_string (gint seconds)
224
 
{
225
 
        gfloat value = seconds;
226
 
 
227
 
        if (value < 0)
228
 
                return g_strdup ("unknown");
229
 
        if (value < 60)
230
 
                return g_strdup_printf ("%.0f seconds", value);
231
 
        value /= 60.0;
232
 
        if (value < 60)
233
 
                return g_strdup_printf ("%.1f minutes", value);
234
 
        value /= 60.0;
235
 
        if (value < 60)
236
 
                return g_strdup_printf ("%.1f hours", value);
237
 
        value /= 24.0;
238
 
        return g_strdup_printf ("%.1f days", value);
239
 
}
240
 
 
241
 
/**
242
 
 * up_device_to_text:
243
 
 * @device: a #UpDevice instance.
244
 
 *
245
 
 * Converts the device to a string description.
246
 
 *
247
 
 * Return value: text representation of #UpDevice
248
 
 *
249
 
 * Since: 0.9.0
250
 
 **/
251
 
gchar *
252
 
up_device_to_text (UpDevice *device)
253
 
{
254
 
        struct tm *time_tm;
255
 
        time_t t;
256
 
        gchar time_buf[256];
257
 
        gchar *time_str;
258
 
        GString *string;
259
 
        UpDevicePrivate *priv;
260
 
        const gchar *vendor;
261
 
        const gchar *model;
262
 
        const gchar *serial;
263
 
        UpDeviceKind kind;
264
 
        gboolean is_display;
265
 
 
266
 
        g_return_val_if_fail (UP_IS_DEVICE (device), NULL);
267
 
        g_return_val_if_fail (device->priv->proxy_device != NULL, NULL);
268
 
 
269
 
        priv = device->priv;
270
 
 
271
 
        is_display = (g_strcmp0 ("/org/freedesktop/UPower/devices/DisplayDevice", up_device_get_object_path (device)) == 0);
272
 
 
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);
277
 
 
278
 
        string = g_string_new ("");
279
 
        if (!is_display)
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)));
294
 
 
295
 
        kind = up_device_glue_get_type_ (priv->proxy_device);
296
 
        g_string_append_printf (string, "  %s\n", up_device_kind_to_string (kind));
297
 
 
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) &&
307
 
            !is_display)
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));
317
 
                if (!is_display)
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));
320
 
                if (!is_display)
321
 
                        g_string_append_printf (string, "    energy-full-design:  %g Wh\n", up_device_glue_get_energy_full_design (priv->proxy_device));
322
 
        }
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));
331
 
        }
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));
335
 
        }
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);
341
 
                        g_free (time_str);
342
 
                }
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);
346
 
                        g_free (time_str);
347
 
                }
348
 
        }
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));
363
 
        }
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)));
367
 
        }
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)));
370
 
 
371
 
        g_string_append_printf (string, "    icon-name:          '%s'\n", up_device_glue_get_icon_name (priv->proxy_device));
372
 
 
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");
377
 
        }
378
 
 
379
 
        return g_string_free (string, FALSE);
380
 
}
381
 
 
382
 
/**
383
 
 * up_device_refresh_sync:
384
 
 * @device: a #UpDevice instance.
385
 
 * @cancellable: a #GCancellable or %NULL
386
 
 * @error: a #GError, or %NULL.
387
 
 *
388
 
 * Refreshes properties on the device.
389
 
 * This function is normally not required.
390
 
 *
391
 
 * Return value: #TRUE for success, else #FALSE and @error is used
392
 
 *
393
 
 * Since: 0.9.0
394
 
 **/
395
 
gboolean
396
 
up_device_refresh_sync (UpDevice *device, GCancellable *cancellable, GError **error)
397
 
{
398
 
        g_return_val_if_fail (UP_IS_DEVICE (device), FALSE);
399
 
        g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
400
 
 
401
 
        return up_device_glue_call_refresh_sync (device->priv->proxy_device, cancellable, error);
402
 
}
403
 
 
404
 
/**
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.
412
 
 *
413
 
 * Gets the device history.
414
 
 *
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
417
 
 *               invalid
418
 
 *
419
 
 * Since: 0.9.0
420
 
 **/
421
 
GPtrArray *
422
 
up_device_get_history_sync (UpDevice *device, const gchar *type, guint timespec, guint resolution, GCancellable *cancellable, GError **error)
423
 
{
424
 
        GError *error_local = NULL;
425
 
        GVariant *gva;
426
 
        guint i;
427
 
        GPtrArray *array = NULL;
428
 
        gboolean ret;
429
 
        gsize len;
430
 
        GVariantIter *iter;
431
 
 
432
 
        g_return_val_if_fail (UP_IS_DEVICE (device), NULL);
433
 
        g_return_val_if_fail (device->priv->proxy_device != NULL, NULL);
434
 
 
435
 
        /* get compound data */
436
 
        ret = up_device_glue_call_get_history_sync (device->priv->proxy_device,
437
 
                                                    type,
438
 
                                                    timespec,
439
 
                                                    resolution,
440
 
                                                    &gva,
441
 
                                                    NULL,
442
 
                                                    &error_local);
443
 
        if (!ret) {
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);
447
 
                goto out;
448
 
        }
449
 
 
450
 
        iter = g_variant_iter_new (gva);
451
 
        len = g_variant_iter_n_children (iter);
452
 
 
453
 
        /* no data */
454
 
        if (len == 0) {
455
 
                g_set_error_literal (error, 1, 0, "no data");
456
 
                g_variant_iter_free (iter);
457
 
                goto out;
458
 
        }
459
 
 
460
 
        /* convert */
461
 
        array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
462
 
        for (i = 0; i < len; i++) {
463
 
                UpHistoryItem *obj;
464
 
                GVariant *v;
465
 
                gdouble value;
466
 
                guint32 time, state;
467
 
 
468
 
                v = g_variant_iter_next_value (iter);
469
 
                g_variant_get (v, "(udu)",
470
 
                               &time, &value, &state);
471
 
                g_variant_unref (v);
472
 
 
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);
477
 
 
478
 
                g_ptr_array_add (array, obj);
479
 
        }
480
 
        g_variant_iter_free (iter);
481
 
 
482
 
out:
483
 
        if (gva != NULL)
484
 
                g_variant_unref (gva);
485
 
        return array;
486
 
}
487
 
 
488
 
/**
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.
494
 
 *
495
 
 * Gets the device current statistics.
496
 
 *
497
 
 * Return value: (element-type UpStatsItem) (transfer full): an array of #UpStatsItem's, else #NULL and @error is used
498
 
 *
499
 
 * Since: 0.9.0
500
 
 **/
501
 
GPtrArray *
502
 
up_device_get_statistics_sync (UpDevice *device, const gchar *type, GCancellable *cancellable, GError **error)
503
 
{
504
 
        GError *error_local = NULL;
505
 
        GVariant *gva;
506
 
        guint i;
507
 
        GPtrArray *array = NULL;
508
 
        gboolean ret;
509
 
        gsize len;
510
 
        GVariantIter *iter;
511
 
 
512
 
        g_return_val_if_fail (UP_IS_DEVICE (device), NULL);
513
 
        g_return_val_if_fail (device->priv->proxy_device != NULL, NULL);
514
 
 
515
 
        /* get compound data */
516
 
        ret = up_device_glue_call_get_statistics_sync (device->priv->proxy_device,
517
 
                                                       type,
518
 
                                                       &gva,
519
 
                                                       NULL,
520
 
                                                       &error_local);
521
 
        if (!ret) {
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);
525
 
                goto out;
526
 
        }
527
 
 
528
 
        iter = g_variant_iter_new (gva);
529
 
        len = g_variant_iter_n_children (iter);
530
 
 
531
 
        /* no data */
532
 
        if (len == 0) {
533
 
                g_set_error_literal (error, 1, 0, "no data");
534
 
                g_variant_iter_free (iter);
535
 
                goto out;
536
 
        }
537
 
 
538
 
        /* convert */
539
 
        array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
540
 
        for (i = 0; i < len; i++) {
541
 
                UpStatsItem *obj;
542
 
                GVariant *v;
543
 
                gdouble value, accuracy;
544
 
 
545
 
                v = g_variant_iter_next_value (iter);
546
 
                g_variant_get (v, "(dd)",
547
 
                               &value, &accuracy);
548
 
                g_variant_unref (v);
549
 
 
550
 
                obj = up_stats_item_new ();
551
 
                up_stats_item_set_value (obj, value);
552
 
                up_stats_item_set_accuracy (obj, accuracy);
553
 
 
554
 
                g_ptr_array_add (array, obj);
555
 
        }
556
 
        g_variant_iter_free (iter);
557
 
 
558
 
out:
559
 
        if (gva != NULL)
560
 
                g_variant_unref (gva);
561
 
        return array;
562
 
}
563
 
 
564
 
/*
565
 
 * up_device_set_property:
566
 
 */
567
 
static void
568
 
up_device_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
569
 
{
570
 
        UpDevice *device = UP_DEVICE (object);
571
 
 
572
 
        if (device->priv->proxy_device == NULL) {
573
 
                GValue *v;
574
 
 
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);
579
 
 
580
 
                return;
581
 
        }
582
 
 
583
 
        switch (prop_id) {
584
 
        case PROP_NATIVE_PATH:
585
 
                up_device_glue_set_native_path (device->priv->proxy_device, g_value_get_string (value));
586
 
                break;
587
 
        case PROP_VENDOR:
588
 
                up_device_glue_set_vendor (device->priv->proxy_device, g_value_get_string (value));
589
 
                break;
590
 
        case PROP_MODEL:
591
 
                up_device_glue_set_model (device->priv->proxy_device, g_value_get_string (value));
592
 
                break;
593
 
        case PROP_SERIAL:
594
 
                up_device_glue_set_serial (device->priv->proxy_device, g_value_get_string (value));
595
 
                break;
596
 
        case PROP_UPDATE_TIME:
597
 
                up_device_glue_set_update_time (device->priv->proxy_device, g_value_get_uint64 (value));
598
 
                break;
599
 
        case PROP_KIND:
600
 
                up_device_glue_set_type_ (device->priv->proxy_device, g_value_get_uint (value));
601
 
                break;
602
 
        case PROP_POWER_SUPPLY:
603
 
                up_device_glue_set_power_supply (device->priv->proxy_device, g_value_get_boolean (value));
604
 
                break;
605
 
        case PROP_ONLINE:
606
 
                up_device_glue_set_online (device->priv->proxy_device, g_value_get_boolean (value));
607
 
                break;
608
 
        case PROP_IS_PRESENT:
609
 
                up_device_glue_set_is_present (device->priv->proxy_device, g_value_get_boolean (value));
610
 
                break;
611
 
        case PROP_IS_RECHARGEABLE:
612
 
                up_device_glue_set_is_rechargeable (device->priv->proxy_device, g_value_get_boolean (value));
613
 
                break;
614
 
        case PROP_HAS_HISTORY:
615
 
                up_device_glue_set_has_history (device->priv->proxy_device, g_value_get_boolean (value));
616
 
                break;
617
 
        case PROP_HAS_STATISTICS:
618
 
                up_device_glue_set_has_statistics (device->priv->proxy_device, g_value_get_boolean (value));
619
 
                break;
620
 
        case PROP_STATE:
621
 
                up_device_glue_set_state (device->priv->proxy_device, g_value_get_uint (value));
622
 
                break;
623
 
        case PROP_CAPACITY:
624
 
                up_device_glue_set_capacity (device->priv->proxy_device, g_value_get_double (value));
625
 
                break;
626
 
        case PROP_ENERGY:
627
 
                up_device_glue_set_energy (device->priv->proxy_device, g_value_get_double (value));
628
 
                break;
629
 
        case PROP_ENERGY_EMPTY:
630
 
                up_device_glue_set_energy_empty (device->priv->proxy_device, g_value_get_double (value));
631
 
                break;
632
 
        case PROP_ENERGY_FULL:
633
 
                up_device_glue_set_energy_full (device->priv->proxy_device, g_value_get_double (value));
634
 
                break;
635
 
        case PROP_ENERGY_FULL_DESIGN:
636
 
                up_device_glue_set_energy_full_design (device->priv->proxy_device, g_value_get_double (value));
637
 
                break;
638
 
        case PROP_ENERGY_RATE:
639
 
                up_device_glue_set_energy_rate (device->priv->proxy_device, g_value_get_double (value));
640
 
                break;
641
 
        case PROP_VOLTAGE:
642
 
                up_device_glue_set_voltage (device->priv->proxy_device, g_value_get_double (value));
643
 
                break;
644
 
        case PROP_LUMINOSITY:
645
 
                up_device_glue_set_luminosity (device->priv->proxy_device, g_value_get_double (value));
646
 
                break;
647
 
        case PROP_TIME_TO_EMPTY:
648
 
                up_device_glue_set_time_to_empty (device->priv->proxy_device, g_value_get_int64 (value));
649
 
                break;
650
 
        case PROP_TIME_TO_FULL:
651
 
                up_device_glue_set_time_to_full (device->priv->proxy_device, g_value_get_int64 (value));
652
 
                break;
653
 
        case PROP_PERCENTAGE:
654
 
                up_device_glue_set_percentage (device->priv->proxy_device, g_value_get_double (value));
655
 
                break;
656
 
        case PROP_TEMPERATURE:
657
 
                up_device_glue_set_temperature (device->priv->proxy_device, g_value_get_double (value));
658
 
                break;
659
 
        case PROP_TECHNOLOGY:
660
 
                up_device_glue_set_technology (device->priv->proxy_device, g_value_get_uint (value));
661
 
                break;
662
 
        case PROP_WARNING_LEVEL:
663
 
                up_device_glue_set_warning_level (device->priv->proxy_device, g_value_get_uint (value));
664
 
                break;
665
 
        case PROP_ICON_NAME:
666
 
                up_device_glue_set_icon_name (device->priv->proxy_device, g_value_get_string (value));
667
 
                break;
668
 
        default:
669
 
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
670
 
                break;
671
 
        }
672
 
}
673
 
 
674
 
/*
675
 
 * up_device_get_property:
676
 
 */
677
 
static void
678
 
up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
679
 
{
680
 
        UpDevice *device = UP_DEVICE (object);
681
 
 
682
 
        if (device->priv->proxy_device == NULL) {
683
 
                GValue *v;
684
 
 
685
 
                v = g_hash_table_lookup (device->priv->offline_props, GUINT_TO_POINTER(prop_id));
686
 
                if (v)
687
 
                        g_value_copy (v, value);
688
 
                else
689
 
                        g_warning ("Property ID '%s' (%d) was never set", pspec->name, prop_id);
690
 
 
691
 
                return;
692
 
        }
693
 
 
694
 
        switch (prop_id) {
695
 
        case PROP_UPDATE_TIME:
696
 
                g_value_set_uint64 (value, up_device_glue_get_update_time (device->priv->proxy_device));
697
 
                break;
698
 
        case PROP_VENDOR:
699
 
                g_value_set_string (value, up_device_glue_get_vendor (device->priv->proxy_device));
700
 
                break;
701
 
        case PROP_MODEL:
702
 
                g_value_set_string (value, up_device_glue_get_model (device->priv->proxy_device));
703
 
                break;
704
 
        case PROP_SERIAL:
705
 
                g_value_set_string (value, up_device_glue_get_serial (device->priv->proxy_device));
706
 
                break;
707
 
        case PROP_NATIVE_PATH:
708
 
                g_value_set_string (value, up_device_glue_get_native_path (device->priv->proxy_device));
709
 
                break;
710
 
        case PROP_POWER_SUPPLY:
711
 
                g_value_set_boolean (value, up_device_glue_get_power_supply (device->priv->proxy_device));
712
 
                break;
713
 
        case PROP_ONLINE:
714
 
                g_value_set_boolean (value, up_device_glue_get_online (device->priv->proxy_device));
715
 
                break;
716
 
        case PROP_IS_PRESENT:
717
 
                g_value_set_boolean (value, up_device_glue_get_is_present (device->priv->proxy_device));
718
 
                break;
719
 
        case PROP_IS_RECHARGEABLE:
720
 
                g_value_set_boolean (value, up_device_glue_get_is_rechargeable (device->priv->proxy_device));
721
 
                break;
722
 
        case PROP_HAS_HISTORY:
723
 
                g_value_set_boolean (value, up_device_glue_get_has_history (device->priv->proxy_device));
724
 
                break;
725
 
        case PROP_HAS_STATISTICS:
726
 
                g_value_set_boolean (value, up_device_glue_get_has_statistics (device->priv->proxy_device));
727
 
                break;
728
 
        case PROP_KIND:
729
 
                g_value_set_uint (value, up_device_glue_get_type_ (device->priv->proxy_device));
730
 
                break;
731
 
        case PROP_STATE:
732
 
                g_value_set_uint (value, up_device_glue_get_state (device->priv->proxy_device));
733
 
                break;
734
 
        case PROP_TECHNOLOGY:
735
 
                g_value_set_uint (value, up_device_glue_get_technology (device->priv->proxy_device));
736
 
                break;
737
 
        case PROP_CAPACITY:
738
 
                g_value_set_double (value, up_device_glue_get_capacity (device->priv->proxy_device));
739
 
                break;
740
 
        case PROP_ENERGY:
741
 
                g_value_set_double (value, up_device_glue_get_energy (device->priv->proxy_device));
742
 
                break;
743
 
        case PROP_ENERGY_EMPTY:
744
 
                g_value_set_double (value, up_device_glue_get_energy_empty (device->priv->proxy_device));
745
 
                break;
746
 
        case PROP_ENERGY_FULL:
747
 
                g_value_set_double (value, up_device_glue_get_energy_full (device->priv->proxy_device));
748
 
                break;
749
 
        case PROP_ENERGY_FULL_DESIGN:
750
 
                g_value_set_double (value, up_device_glue_get_energy_full_design (device->priv->proxy_device));
751
 
                break;
752
 
        case PROP_ENERGY_RATE:
753
 
                g_value_set_double (value, up_device_glue_get_energy_rate (device->priv->proxy_device));
754
 
                break;
755
 
        case PROP_VOLTAGE:
756
 
                g_value_set_double (value, up_device_glue_get_voltage (device->priv->proxy_device));
757
 
                break;
758
 
        case PROP_LUMINOSITY:
759
 
                g_value_set_double (value, up_device_glue_get_luminosity (device->priv->proxy_device));
760
 
                break;
761
 
        case PROP_TIME_TO_EMPTY:
762
 
                g_value_set_int64 (value, up_device_glue_get_time_to_empty (device->priv->proxy_device));
763
 
                break;
764
 
        case PROP_TIME_TO_FULL:
765
 
                g_value_set_int64 (value, up_device_glue_get_time_to_full (device->priv->proxy_device));
766
 
                break;
767
 
        case PROP_PERCENTAGE:
768
 
                g_value_set_double (value, up_device_glue_get_percentage (device->priv->proxy_device));
769
 
                break;
770
 
        case PROP_TEMPERATURE:
771
 
                g_value_set_double (value, up_device_glue_get_temperature (device->priv->proxy_device));
772
 
                break;
773
 
        case PROP_WARNING_LEVEL:
774
 
                g_value_set_uint (value, up_device_glue_get_warning_level (device->priv->proxy_device));
775
 
                break;
776
 
        case PROP_ICON_NAME:
777
 
                g_value_set_string (value, up_device_glue_get_icon_name (device->priv->proxy_device));
778
 
                break;
779
 
        default:
780
 
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
781
 
                break;
782
 
    }
783
 
}
784
 
 
785
 
/*
786
 
 * up_device_class_init:
787
 
 */
788
 
static void
789
 
up_device_class_init (UpDeviceClass *klass)
790
 
{
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;
795
 
 
796
 
        /**
797
 
         * UpDevice:update-time:
798
 
         *
799
 
         * The last time the device was updated.
800
 
         *
801
 
         * Since: 0.9.0
802
 
         **/
803
 
        g_object_class_install_property (object_class,
804
 
                                         PROP_UPDATE_TIME,
805
 
                                         g_param_spec_uint64 ("update-time",
806
 
                                                              NULL, NULL,
807
 
                                                              0, G_MAXUINT64, 0,
808
 
                                                              G_PARAM_READWRITE));
809
 
        /**
810
 
         * UpDevice:vendor:
811
 
         *
812
 
         * The vendor of the device.
813
 
         *
814
 
         * Since: 0.9.0
815
 
         **/
816
 
        g_object_class_install_property (object_class,
817
 
                                         PROP_VENDOR,
818
 
                                         g_param_spec_string ("vendor",
819
 
                                                              NULL, NULL,
820
 
                                                              NULL,
821
 
                                                              G_PARAM_READWRITE));
822
 
        /**
823
 
         * UpDevice:model:
824
 
         *
825
 
         * The model of the device.
826
 
         *
827
 
         * Since: 0.9.0
828
 
         **/
829
 
        g_object_class_install_property (object_class,
830
 
                                         PROP_MODEL,
831
 
                                         g_param_spec_string ("model",
832
 
                                                              NULL, NULL,
833
 
                                                              NULL,
834
 
                                                              G_PARAM_READWRITE));
835
 
        /**
836
 
         * UpDevice:serial:
837
 
         *
838
 
         * The serial number of the device.
839
 
         *
840
 
         * Since: 0.9.0
841
 
         **/
842
 
        g_object_class_install_property (object_class,
843
 
                                         PROP_SERIAL,
844
 
                                         g_param_spec_string ("serial",
845
 
                                                              NULL, NULL,
846
 
                                                              NULL,
847
 
                                                              G_PARAM_READWRITE));
848
 
        /**
849
 
         * UpDevice:native-path:
850
 
         *
851
 
         * The native path of the device, useful for direct device access.
852
 
         *
853
 
         * Since: 0.9.0
854
 
         **/
855
 
        g_object_class_install_property (object_class,
856
 
                                         PROP_NATIVE_PATH,
857
 
                                         g_param_spec_string ("native-path",
858
 
                                                              NULL, NULL,
859
 
                                                              NULL,
860
 
                                                              G_PARAM_READWRITE));
861
 
        /**
862
 
         * UpDevice:power-supply:
863
 
         *
864
 
         * If the device is powering the system.
865
 
         *
866
 
         * Since: 0.9.0
867
 
         **/
868
 
        g_object_class_install_property (object_class,
869
 
                                         PROP_POWER_SUPPLY,
870
 
                                         g_param_spec_boolean ("power-supply",
871
 
                                                               NULL, NULL,
872
 
                                                               FALSE,
873
 
                                                               G_PARAM_READWRITE));
874
 
        /**
875
 
         * UpDevice:online:
876
 
         *
877
 
         * If the device is online, i.e. connected.
878
 
         *
879
 
         * Since: 0.9.0
880
 
         **/
881
 
        g_object_class_install_property (object_class,
882
 
                                         PROP_ONLINE,
883
 
                                         g_param_spec_boolean ("online",
884
 
                                                               NULL, NULL,
885
 
                                                               FALSE,
886
 
                                                               G_PARAM_READWRITE));
887
 
        /**
888
 
         * UpDevice:is-present:
889
 
         *
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
892
 
         * device.
893
 
         *
894
 
         * Since: 0.9.0
895
 
         **/
896
 
        g_object_class_install_property (object_class,
897
 
                                         PROP_IS_PRESENT,
898
 
                                         g_param_spec_boolean ("is-present",
899
 
                                                               NULL, NULL,
900
 
                                                               FALSE,
901
 
                                                               G_PARAM_READWRITE));
902
 
        /**
903
 
         * UpDevice:is-rechargeable:
904
 
         *
905
 
         * If the device has a rechargable battery.
906
 
         *
907
 
         * Since: 0.9.0
908
 
         **/
909
 
        g_object_class_install_property (object_class,
910
 
                                         PROP_IS_RECHARGEABLE,
911
 
                                         g_param_spec_boolean ("is-rechargeable",
912
 
                                                               NULL, NULL,
913
 
                                                               FALSE,
914
 
                                                               G_PARAM_READWRITE));
915
 
        /**
916
 
         * UpDevice:has-history:
917
 
         *
918
 
         * If the device has history data that might be useful.
919
 
         *
920
 
         * Since: 0.9.0
921
 
         **/
922
 
        g_object_class_install_property (object_class,
923
 
                                         PROP_HAS_HISTORY,
924
 
                                         g_param_spec_boolean ("has-history",
925
 
                                                               NULL, NULL,
926
 
                                                               FALSE,
927
 
                                                               G_PARAM_READWRITE));
928
 
        /**
929
 
         * UpDevice:has-statistics:
930
 
         *
931
 
         * If the device has statistics data that might be useful.
932
 
         *
933
 
         * Since: 0.9.0
934
 
         **/
935
 
        g_object_class_install_property (object_class,
936
 
                                         PROP_HAS_STATISTICS,
937
 
                                         g_param_spec_boolean ("has-statistics",
938
 
                                                               NULL, NULL,
939
 
                                                               FALSE,
940
 
                                                               G_PARAM_READWRITE));
941
 
        /**
942
 
         * UpDevice:kind:
943
 
         *
944
 
         * The device kind, e.g. %UP_DEVICE_KIND_KEYBOARD.
945
 
         *
946
 
         * Since: 0.9.0
947
 
         **/
948
 
        g_object_class_install_property (object_class,
949
 
                                         PROP_KIND,
950
 
                                         g_param_spec_uint ("kind",
951
 
                                                            NULL, NULL,
952
 
                                                            UP_DEVICE_KIND_UNKNOWN,
953
 
                                                            UP_DEVICE_KIND_LAST,
954
 
                                                            UP_DEVICE_KIND_UNKNOWN,
955
 
                                                            G_PARAM_READWRITE));
956
 
        /**
957
 
         * UpDevice:state:
958
 
         *
959
 
         * The state the device is in at this time, e.g. %UP_DEVICE_STATE_EMPTY.
960
 
         *
961
 
         * Since: 0.9.0
962
 
         **/
963
 
        g_object_class_install_property (object_class,
964
 
                                         PROP_STATE,
965
 
                                         g_param_spec_uint ("state",
966
 
                                                            NULL, NULL,
967
 
                                                            UP_DEVICE_STATE_UNKNOWN,
968
 
                                                            UP_DEVICE_STATE_LAST,
969
 
                                                            UP_DEVICE_STATE_UNKNOWN,
970
 
                                                            G_PARAM_READWRITE));
971
 
        /**
972
 
         * UpDevice:technology:
973
 
         *
974
 
         * The battery technology e.g. %UP_DEVICE_TECHNOLOGY_LITHIUM_ION.
975
 
         *
976
 
         * Since: 0.9.0
977
 
         **/
978
 
        g_object_class_install_property (object_class,
979
 
                                         PROP_TECHNOLOGY,
980
 
                                         g_param_spec_uint ("technology",
981
 
                                                            NULL, NULL,
982
 
                                                            UP_DEVICE_TECHNOLOGY_UNKNOWN,
983
 
                                                            UP_DEVICE_TECHNOLOGY_LAST,
984
 
                                                            UP_DEVICE_TECHNOLOGY_UNKNOWN,
985
 
                                                            G_PARAM_READWRITE));
986
 
        /**
987
 
         * UpDevice:capacity:
988
 
         *
989
 
         * The percentage capacity of the device where 100% means the device has
990
 
         * the same charge potential as when it was manufactured.
991
 
         *
992
 
         * Since: 0.9.0
993
 
         **/
994
 
        g_object_class_install_property (object_class,
995
 
                                         PROP_CAPACITY,
996
 
                                         g_param_spec_double ("capacity", NULL, NULL,
997
 
                                                              0.0, 100.f, 100.0,
998
 
                                                              G_PARAM_READWRITE));
999
 
        /**
1000
 
         * UpDevice:energy:
1001
 
         *
1002
 
         * The energy left in the device. Measured in mWh.
1003
 
         *
1004
 
         * Since: 0.9.0
1005
 
         **/
1006
 
        g_object_class_install_property (object_class,
1007
 
                                         PROP_ENERGY,
1008
 
                                         g_param_spec_double ("energy", NULL, NULL,
1009
 
                                                              0.0, G_MAXDOUBLE, 0.0,
1010
 
                                                              G_PARAM_READWRITE));
1011
 
        /**
1012
 
         * UpDevice:energy-empty:
1013
 
         *
1014
 
         * The energy the device will have when it is empty. This is usually zero.
1015
 
         * Measured in mWh.
1016
 
         *
1017
 
         * Since: 0.9.0
1018
 
         **/
1019
 
        g_object_class_install_property (object_class,
1020
 
                                         PROP_ENERGY_EMPTY,
1021
 
                                         g_param_spec_double ("energy-empty", NULL, NULL,
1022
 
                                                              0.0, G_MAXDOUBLE, 0.0,
1023
 
                                                              G_PARAM_READWRITE));
1024
 
        /**
1025
 
         * UpDevice:energy-full:
1026
 
         *
1027
 
         * The amount of energy when the device is fully charged. Measured in mWh.
1028
 
         *
1029
 
         * Since: 0.9.0
1030
 
         **/
1031
 
        g_object_class_install_property (object_class,
1032
 
                                         PROP_ENERGY_FULL,
1033
 
                                         g_param_spec_double ("energy-full", NULL, NULL,
1034
 
                                                              0.0, G_MAXDOUBLE, 0.0,
1035
 
                                                              G_PARAM_READWRITE));
1036
 
        /**
1037
 
         * UpDevice:energy-full-design:
1038
 
         *
1039
 
         * The amount of energy when the device was brand new. Measured in mWh.
1040
 
         *
1041
 
         * Since: 0.9.0
1042
 
         **/
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));
1048
 
        /**
1049
 
         * UpDevice:energy-rate:
1050
 
         *
1051
 
         * The rate of discharge or charge. Measured in mW.
1052
 
         *
1053
 
         * Since: 0.9.0
1054
 
         **/
1055
 
        g_object_class_install_property (object_class,
1056
 
                                         PROP_ENERGY_RATE,
1057
 
                                         g_param_spec_double ("energy-rate", NULL, NULL,
1058
 
                                                              0.0, G_MAXDOUBLE, 0.0,
1059
 
                                                              G_PARAM_READWRITE));
1060
 
        /**
1061
 
         * UpDevice:voltage:
1062
 
         *
1063
 
         * The current voltage of the device.
1064
 
         *
1065
 
         * Since: 0.9.0
1066
 
         **/
1067
 
        g_object_class_install_property (object_class,
1068
 
                                         PROP_VOLTAGE,
1069
 
                                         g_param_spec_double ("voltage", NULL, NULL,
1070
 
                                                              0.0, G_MAXDOUBLE, 0.0,
1071
 
                                                              G_PARAM_READWRITE));
1072
 
 
1073
 
        /**
1074
 
         * UpDevice:luminosity:
1075
 
         *
1076
 
         * The current luminosity of the device.
1077
 
         *
1078
 
         * Since: 0.9.19
1079
 
         **/
1080
 
        g_object_class_install_property (object_class,
1081
 
                                         PROP_LUMINOSITY,
1082
 
                                         g_param_spec_double ("luminosity", NULL, NULL,
1083
 
                                                              0.0, G_MAXDOUBLE, 0.0,
1084
 
                                                              G_PARAM_READWRITE));
1085
 
        /**
1086
 
         * UpDevice:time-to-empty:
1087
 
         *
1088
 
         * The amount of time until the device is empty.
1089
 
         *
1090
 
         * Since: 0.9.0
1091
 
         **/
1092
 
        g_object_class_install_property (object_class,
1093
 
                                         PROP_TIME_TO_EMPTY,
1094
 
                                         g_param_spec_int64 ("time-to-empty", NULL, NULL,
1095
 
                                                              0, G_MAXINT64, 0,
1096
 
                                                              G_PARAM_READWRITE));
1097
 
        /**
1098
 
         * UpDevice:time-to-full:
1099
 
         *
1100
 
         * The amount of time until the device is fully charged.
1101
 
         *
1102
 
         * Since: 0.9.0
1103
 
         **/
1104
 
        g_object_class_install_property (object_class,
1105
 
                                         PROP_TIME_TO_FULL,
1106
 
                                         g_param_spec_int64 ("time-to-full", NULL, NULL,
1107
 
                                                              0, G_MAXINT64, 0,
1108
 
                                                              G_PARAM_READWRITE));
1109
 
        /**
1110
 
         * UpDevice:percentage:
1111
 
         *
1112
 
         * The percentage charge of the device.
1113
 
         *
1114
 
         * Since: 0.9.0
1115
 
         **/
1116
 
        g_object_class_install_property (object_class,
1117
 
                                         PROP_PERCENTAGE,
1118
 
                                         g_param_spec_double ("percentage", NULL, NULL,
1119
 
                                                              0.0, 100.f, 100.0,
1120
 
                                                              G_PARAM_READWRITE));
1121
 
        /**
1122
 
         * UpDevice:temperature:
1123
 
         *
1124
 
         * The temperature of the device in degrees Celsius.
1125
 
         *
1126
 
         * Since: 0.9.22
1127
 
         **/
1128
 
        g_object_class_install_property (object_class,
1129
 
                                         PROP_TEMPERATURE,
1130
 
                                         g_param_spec_double ("temperature", NULL, NULL,
1131
 
                                                              0.0, G_MAXDOUBLE, 0.0,
1132
 
                                                              G_PARAM_READWRITE));
1133
 
        /**
1134
 
         * UpDevice:warning-level:
1135
 
         *
1136
 
         * The warning level e.g. %UP_DEVICE_LEVEL_WARNING.
1137
 
         *
1138
 
         * Since: 1.0
1139
 
         **/
1140
 
        g_object_class_install_property (object_class,
1141
 
                                         PROP_WARNING_LEVEL,
1142
 
                                         g_param_spec_uint ("warning-level",
1143
 
                                                            NULL, NULL,
1144
 
                                                            UP_DEVICE_LEVEL_UNKNOWN,
1145
 
                                                            UP_DEVICE_LEVEL_LAST,
1146
 
                                                            UP_DEVICE_LEVEL_UNKNOWN,
1147
 
                                                            G_PARAM_READWRITE));
1148
 
 
1149
 
        /**
1150
 
         * UpDevice:icon-name:
1151
 
         *
1152
 
         * The icon name, following the Icon Naming Speficiation
1153
 
         *
1154
 
         * Since: 1.0
1155
 
         **/
1156
 
        g_object_class_install_property (object_class,
1157
 
                                         PROP_ICON_NAME,
1158
 
                                         g_param_spec_string ("icon-name",
1159
 
                                                              NULL, NULL, NULL,
1160
 
                                                              G_PARAM_READWRITE));
1161
 
 
1162
 
        g_type_class_add_private (klass, sizeof (UpDevicePrivate));
1163
 
}
1164
 
 
1165
 
static void
1166
 
value_free (GValue *value)
1167
 
{
1168
 
        g_value_unset (value);
1169
 
        g_slice_free (GValue, value);
1170
 
}
1171
 
 
1172
 
/*
1173
 
 * up_device_init:
1174
 
 */
1175
 
static void
1176
 
up_device_init (UpDevice *device)
1177
 
{
1178
 
        device->priv = UP_DEVICE_GET_PRIVATE (device);
1179
 
        device->priv->offline_props = g_hash_table_new_full (g_direct_hash,
1180
 
                                                             g_direct_equal,
1181
 
                                                             NULL,
1182
 
                                                             (GDestroyNotify) value_free);
1183
 
}
1184
 
 
1185
 
/*
1186
 
 * up_device_finalize:
1187
 
 */
1188
 
static void
1189
 
up_device_finalize (GObject *object)
1190
 
{
1191
 
        UpDevice *device;
1192
 
 
1193
 
        g_return_if_fail (UP_IS_DEVICE (object));
1194
 
 
1195
 
        device = UP_DEVICE (object);
1196
 
 
1197
 
        if (device->priv->proxy_device != NULL)
1198
 
                g_object_unref (device->priv->proxy_device);
1199
 
 
1200
 
        g_clear_pointer (&device->priv->offline_props, g_hash_table_unref);
1201
 
 
1202
 
        G_OBJECT_CLASS (up_device_parent_class)->finalize (object);
1203
 
}
1204
 
 
1205
 
/**
1206
 
 * up_device_new:
1207
 
 *
1208
 
 * Creates a new #UpDevice object.
1209
 
 *
1210
 
 * Return value: a new UpDevice object.
1211
 
 *
1212
 
 * Since: 0.9.0
1213
 
 **/
1214
 
UpDevice *
1215
 
up_device_new (void)
1216
 
{
1217
 
        return UP_DEVICE (g_object_new (UP_TYPE_DEVICE, NULL));
1218
 
}