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.
27
#include <dbus/dbus-glib.h>
30
#include "dkp-device.h"
31
#include "dkp-stats-obj.h"
32
#include "dkp-history-obj.h"
34
static void dkp_device_class_init (DkpDeviceClass *klass);
35
static void dkp_device_init (DkpDevice *device);
36
static void dkp_device_finalize (GObject *object);
38
#define DKP_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_TYPE_DEVICE, DkpDevicePrivate))
40
struct DkpDevicePrivate
44
DBusGProxy *proxy_device;
45
DBusGProxy *proxy_props;
53
gboolean power_supply;
56
gboolean is_rechargeable;
58
gboolean has_statistics;
61
DkpDeviceTechnology technology;
62
gdouble capacity; /* percent */
63
gdouble energy; /* Watt Hours */
64
gdouble energy_empty; /* Watt Hours */
65
gdouble energy_full; /* Watt Hours */
66
gdouble energy_full_design; /* Watt Hours */
67
gdouble energy_rate; /* Watts */
68
gdouble voltage; /* Volts */
69
gint64 time_to_empty; /* seconds */
70
gint64 time_to_full; /* seconds */
71
gdouble percentage; /* percent */
72
gboolean recall_notice;
97
PROP_ENERGY_FULL_DESIGN,
111
DKP_DEVICE_LAST_SIGNAL
114
static guint signals [DKP_DEVICE_LAST_SIGNAL] = { 0 };
116
G_DEFINE_TYPE (DkpDevice, dkp_device, G_TYPE_OBJECT)
119
* dkp_device_get_device_properties:
122
dkp_device_get_device_properties (DkpDevice *device, GError **error)
125
GError *error_local = NULL;
126
GHashTable *hash_table = NULL;
128
ret = dbus_g_proxy_call (device->priv->proxy_props, "GetAll", &error_local,
129
G_TYPE_STRING, "org.freedesktop.UPower.Device",
131
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
135
g_set_error (error, 1, 0, "Couldn't call GetAll() to get properties for %s: %s", device->priv->object_path, error_local->message);
136
g_error_free (error_local);
144
* dkp_device_collect_props_cb:
147
dkp_device_collect_props_cb (const char *key, const GValue *value, DkpDevice *device)
149
if (g_strcmp0 (key, "NativePath") == 0) {
150
g_free (device->priv->native_path);
151
device->priv->native_path = g_strdup (g_value_get_string (value));
152
} else if (g_strcmp0 (key, "Vendor") == 0) {
153
g_free (device->priv->vendor);
154
device->priv->vendor = g_strdup (g_value_get_string (value));
155
} else if (g_strcmp0 (key, "Model") == 0) {
156
g_free (device->priv->model);
157
device->priv->model = g_strdup (g_value_get_string (value));
158
} else if (g_strcmp0 (key, "Serial") == 0) {
159
g_free (device->priv->serial);
160
device->priv->serial = g_strdup (g_value_get_string (value));
161
} else if (g_strcmp0 (key, "UpdateTime") == 0) {
162
device->priv->update_time = g_value_get_uint64 (value);
163
} else if (g_strcmp0 (key, "Type") == 0) {
164
device->priv->type = g_value_get_uint (value);
165
} else if (g_strcmp0 (key, "Online") == 0) {
166
device->priv->online = g_value_get_boolean (value);
167
} else if (g_strcmp0 (key, "HasHistory") == 0) {
168
device->priv->has_history = g_value_get_boolean (value);
169
} else if (g_strcmp0 (key, "HasStatistics") == 0) {
170
device->priv->has_statistics = g_value_get_boolean (value);
171
} else if (g_strcmp0 (key, "Energy") == 0) {
172
device->priv->energy = g_value_get_double (value);
173
} else if (g_strcmp0 (key, "EnergyEmpty") == 0) {
174
device->priv->energy_empty = g_value_get_double (value);
175
} else if (g_strcmp0 (key, "EnergyFull") == 0) {
176
device->priv->energy_full = g_value_get_double (value);
177
} else if (g_strcmp0 (key, "EnergyFullDesign") == 0) {
178
device->priv->energy_full_design = g_value_get_double (value);
179
} else if (g_strcmp0 (key, "EnergyRate") == 0) {
180
device->priv->energy_rate = g_value_get_double (value);
181
} else if (g_strcmp0 (key, "Voltage") == 0) {
182
device->priv->voltage = g_value_get_double (value);
183
} else if (g_strcmp0 (key, "TimeToFull") == 0) {
184
device->priv->time_to_full = g_value_get_int64 (value);
185
} else if (g_strcmp0 (key, "TimeToEmpty") == 0) {
186
device->priv->time_to_empty = g_value_get_int64 (value);
187
} else if (g_strcmp0 (key, "Percentage") == 0) {
188
device->priv->percentage = g_value_get_double (value);
189
} else if (g_strcmp0 (key, "Technology") == 0) {
190
device->priv->technology = g_value_get_uint (value);
191
} else if (g_strcmp0 (key, "IsPresent") == 0) {
192
device->priv->is_present = g_value_get_boolean (value);
193
} else if (g_strcmp0 (key, "IsRechargeable") == 0) {
194
device->priv->is_rechargeable = g_value_get_boolean (value);
195
} else if (g_strcmp0 (key, "PowerSupply") == 0) {
196
device->priv->power_supply = g_value_get_boolean (value);
197
} else if (g_strcmp0 (key, "Capacity") == 0) {
198
device->priv->capacity = g_value_get_double (value);
199
} else if (g_strcmp0 (key, "State") == 0) {
200
device->priv->state = g_value_get_uint (value);
201
} else if (g_strcmp0 (key, "RecallNotice") == 0) {
202
device->priv->recall_notice = g_value_get_boolean (value);
203
} else if (g_strcmp0 (key, "RecallVendor") == 0) {
204
g_free (device->priv->recall_vendor);
205
device->priv->recall_vendor = g_strdup (g_value_get_string (value));
206
} else if (g_strcmp0 (key, "RecallUrl") == 0) {
207
g_free (device->priv->recall_url);
208
device->priv->recall_url = g_strdup (g_value_get_string (value));
210
g_warning ("unhandled property '%s'", key);
215
* dkp_device_refresh_internal:
218
dkp_device_refresh_internal (DkpDevice *device, GError **error)
221
GError *error_local = NULL;
223
/* get all the properties */
224
hash = dkp_device_get_device_properties (device, &error_local);
226
g_set_error (error, 1, 0, "Cannot get device properties for %s: %s", device->priv->object_path, error_local->message);
227
g_error_free (error_local);
230
g_hash_table_foreach (hash, (GHFunc) dkp_device_collect_props_cb, device);
231
g_hash_table_unref (hash);
236
* dkp_device_changed_cb:
239
dkp_device_changed_cb (DBusGProxy *proxy, DkpDevice *device)
241
g_return_if_fail (DKP_IS_DEVICE (device));
242
dkp_device_refresh_internal (device, NULL);
243
g_signal_emit (device, signals [DKP_DEVICE_CHANGED], 0, NULL); //TODO xxx
247
* dkp_device_set_object_path:
250
dkp_device_set_object_path (DkpDevice *device, const gchar *object_path, GError **error)
252
GError *error_local = NULL;
253
gboolean ret = FALSE;
254
DBusGProxy *proxy_device;
255
DBusGProxy *proxy_props;
257
g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
259
if (device->priv->object_path != NULL)
261
if (object_path == NULL)
264
/* connect to the bus */
265
device->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error_local);
266
if (device->priv->bus == NULL) {
267
g_set_error (error, 1, 0, "Couldn't connect to system bus: %s", error_local->message);
268
g_error_free (error_local);
272
/* connect to the correct path for properties */
273
proxy_props = dbus_g_proxy_new_for_name (device->priv->bus, "org.freedesktop.UPower",
274
object_path, "org.freedesktop.DBus.Properties");
275
if (proxy_props == NULL) {
276
g_set_error_literal (error, 1, 0, "Couldn't connect to proxy");
280
/* connect to the correct path for all the other methods */
281
proxy_device = dbus_g_proxy_new_for_name (device->priv->bus, "org.freedesktop.UPower",
282
object_path, "org.freedesktop.UPower.Device");
283
if (proxy_device == NULL) {
284
g_set_error_literal (error, 1, 0, "Couldn't connect to proxy");
288
/* listen to Changed */
289
dbus_g_proxy_add_signal (proxy_device, "Changed", G_TYPE_INVALID);
290
dbus_g_proxy_connect_signal (proxy_device, "Changed",
291
G_CALLBACK (dkp_device_changed_cb), device, NULL);
294
device->priv->proxy_device = proxy_device;
295
device->priv->proxy_props = proxy_props;
296
device->priv->object_path = g_strdup (object_path);
299
ret = dkp_device_refresh_internal (device, &error_local);
301
g_set_error (error, 1, 0, "cannot refresh: %s", error_local->message);
302
g_error_free (error_local);
309
* dkp_device_get_object_path:
312
dkp_device_get_object_path (const DkpDevice *device)
314
g_return_val_if_fail (DKP_IS_DEVICE (device), NULL);
315
return device->priv->object_path;
319
* dkp_device_print_history:
322
dkp_device_print_history (const DkpDevice *device, const gchar *type)
326
const DkpHistoryObj *obj;
327
gboolean ret = FALSE;
329
/* get a fair chunk of data */
330
array = dkp_device_get_history (device, type, 120, 10, NULL);
335
g_print (" History (%s):\n", type);
336
for (i=0; i<array->len; i++) {
337
obj = (const DkpHistoryObj *) g_ptr_array_index (array, i);
338
g_print (" %i\t%.3f\t%s\n", obj->time, obj->value, dkp_device_state_to_text (obj->state));
340
g_ptr_array_unref (array);
347
* dkp_device_print_bool_to_text:
350
dkp_device_print_bool_to_text (gboolean ret)
352
return ret ? "yes" : "no";
356
* dkp_device_print_time_to_text:
359
dkp_device_print_time_to_text (gint seconds)
361
gfloat value = seconds;
364
return g_strdup ("unknown");
366
return g_strdup_printf ("%.0f seconds", value);
369
return g_strdup_printf ("%.1f minutes", value);
372
return g_strdup_printf ("%.1f hours", value);
374
return g_strdup_printf ("%.1f days", value);
381
dkp_device_print (const DkpDevice *device)
388
g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
390
/* get a human readable time */
391
t = (time_t) device->priv->update_time;
392
time_tm = localtime (&t);
393
strftime (time_buf, sizeof time_buf, "%c", time_tm);
395
g_print (" native-path: %s\n", device->priv->native_path);
396
if (device->priv->vendor != NULL && device->priv->vendor[0] != '\0')
397
g_print (" vendor: %s\n", device->priv->vendor);
398
if (device->priv->model != NULL && device->priv->model[0] != '\0')
399
g_print (" model: %s\n", device->priv->model);
400
if (device->priv->serial != NULL && device->priv->serial[0] != '\0')
401
g_print (" serial: %s\n", device->priv->serial);
402
g_print (" power supply: %s\n", dkp_device_print_bool_to_text (device->priv->power_supply));
403
g_print (" updated: %s (%d seconds ago)\n", time_buf, (int) (time (NULL) - device->priv->update_time));
404
g_print (" has history: %s\n", dkp_device_print_bool_to_text (device->priv->has_history));
405
g_print (" has statistics: %s\n", dkp_device_print_bool_to_text (device->priv->has_statistics));
406
g_print (" %s\n", dkp_device_type_to_text (device->priv->type));
408
if (device->priv->type == DKP_DEVICE_TYPE_BATTERY ||
409
device->priv->type == DKP_DEVICE_TYPE_MOUSE ||
410
device->priv->type == DKP_DEVICE_TYPE_KEYBOARD ||
411
device->priv->type == DKP_DEVICE_TYPE_UPS)
412
g_print (" present: %s\n", dkp_device_print_bool_to_text (device->priv->is_present));
413
if (device->priv->type == DKP_DEVICE_TYPE_BATTERY ||
414
device->priv->type == DKP_DEVICE_TYPE_MOUSE ||
415
device->priv->type == DKP_DEVICE_TYPE_KEYBOARD)
416
g_print (" rechargeable: %s\n", dkp_device_print_bool_to_text (device->priv->is_rechargeable));
417
if (device->priv->type == DKP_DEVICE_TYPE_BATTERY ||
418
device->priv->type == DKP_DEVICE_TYPE_MOUSE ||
419
device->priv->type == DKP_DEVICE_TYPE_KEYBOARD ||
420
device->priv->type == DKP_DEVICE_TYPE_UPS)
421
g_print (" state: %s\n", dkp_device_state_to_text (device->priv->state));
422
if (device->priv->type == DKP_DEVICE_TYPE_BATTERY) {
423
g_print (" energy: %g Wh\n", device->priv->energy);
424
g_print (" energy-empty: %g Wh\n", device->priv->energy_empty);
425
g_print (" energy-full: %g Wh\n", device->priv->energy_full);
426
g_print (" energy-full-design: %g Wh\n", device->priv->energy_full_design);
428
if (device->priv->type == DKP_DEVICE_TYPE_BATTERY ||
429
device->priv->type == DKP_DEVICE_TYPE_MONITOR)
430
g_print (" energy-rate: %g W\n", device->priv->energy_rate);
431
if (device->priv->type == DKP_DEVICE_TYPE_UPS ||
432
device->priv->type == DKP_DEVICE_TYPE_BATTERY ||
433
device->priv->type == DKP_DEVICE_TYPE_MONITOR) {
434
if (device->priv->voltage > 0)
435
g_print (" voltage: %g V\n", device->priv->voltage);
437
if (device->priv->type == DKP_DEVICE_TYPE_BATTERY ||
438
device->priv->type == DKP_DEVICE_TYPE_UPS) {
439
if (device->priv->time_to_full > 0) {
440
time_str = dkp_device_print_time_to_text (device->priv->time_to_full);
441
g_print (" time to full: %s\n", time_str);
444
if (device->priv->time_to_empty > 0) {
445
time_str = dkp_device_print_time_to_text (device->priv->time_to_empty);
446
g_print (" time to empty: %s\n", time_str);
450
if (device->priv->type == DKP_DEVICE_TYPE_BATTERY ||
451
device->priv->type == DKP_DEVICE_TYPE_MOUSE ||
452
device->priv->type == DKP_DEVICE_TYPE_KEYBOARD ||
453
device->priv->type == DKP_DEVICE_TYPE_UPS)
454
g_print (" percentage: %g%%\n", device->priv->percentage);
455
if (device->priv->type == DKP_DEVICE_TYPE_BATTERY) {
456
if (device->priv->capacity > 0)
457
g_print (" capacity: %g%%\n", device->priv->capacity);
459
if (device->priv->type == DKP_DEVICE_TYPE_BATTERY) {
460
if (device->priv->technology != DKP_DEVICE_TECHNOLOGY_UNKNOWN)
461
g_print (" technology: %s\n", dkp_device_technology_to_text (device->priv->technology));
463
if (device->priv->type == DKP_DEVICE_TYPE_LINE_POWER)
464
g_print (" online: %s\n", dkp_device_print_bool_to_text (device->priv->online));
465
if (device->priv->type == DKP_DEVICE_TYPE_BATTERY) {
466
if (device->priv->recall_notice) {
467
g_print (" recall vendor: %s\n", device->priv->recall_vendor);
468
g_print (" recall url: %s\n", device->priv->recall_url);
472
/* if we can, get history */
473
if (device->priv->has_history) {
474
dkp_device_print_history (device, "charge");
475
dkp_device_print_history (device, "rate");
482
* dkp_device_refresh:
485
dkp_device_refresh (DkpDevice *device, GError **error)
487
GError *error_local = NULL;
490
g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
491
g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
493
/* just refresh the device */
494
ret = dbus_g_proxy_call (device->priv->proxy_device, "Refresh", &error_local,
495
G_TYPE_INVALID, G_TYPE_INVALID);
497
g_set_error (error, 1, 0, "Refresh() on %s failed: %s", device->priv->object_path, error_local->message);
498
g_error_free (error_local);
506
* dkp_device_get_history:
508
* Returns an array of %DkpHistoryObj's, free with g_ptr_array_unref()
511
dkp_device_get_history (const DkpDevice *device, const gchar *type, guint timespec, guint resolution, GError **error)
513
GError *error_local = NULL;
514
GType g_type_gvalue_array;
515
GPtrArray *gvalue_ptr_array = NULL;
520
GPtrArray *array = NULL;
523
g_return_val_if_fail (DKP_IS_DEVICE (device), NULL);
524
g_return_val_if_fail (device->priv->proxy_device != NULL, NULL);
526
g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
527
dbus_g_type_get_struct("GValueArray",
533
/* get compound data */
534
ret = dbus_g_proxy_call (device->priv->proxy_device, "GetHistory", &error_local,
536
G_TYPE_UINT, timespec,
537
G_TYPE_UINT, resolution,
539
g_type_gvalue_array, &gvalue_ptr_array,
542
g_set_error (error, 1, 0, "GetHistory(%s,%i) on %s failed: %s", type, timespec,
543
device->priv->object_path, error_local->message);
544
g_error_free (error_local);
549
if (gvalue_ptr_array->len == 0) {
550
g_set_error_literal (error, 1, 0, "no data");
555
array = g_ptr_array_new_with_free_func ((GDestroyNotify) dkp_history_obj_free);
557
for (i=0; i<gvalue_ptr_array->len; i++) {
558
gva = (GValueArray *) g_ptr_array_index (gvalue_ptr_array, i);
559
obj = dkp_history_obj_new ();
561
gv = g_value_array_get_nth (gva, 0);
562
obj->time = g_value_get_uint (gv);
565
gv = g_value_array_get_nth (gva, 1);
566
obj->value = g_value_get_double (gv);
569
gv = g_value_array_get_nth (gva, 2);
570
obj->state = g_value_get_uint (gv);
572
g_ptr_array_add (array, obj);
573
g_value_array_free (gva);
577
if (gvalue_ptr_array != NULL)
578
g_ptr_array_free (gvalue_ptr_array, TRUE);
583
* dkp_device_get_statistics:
585
* Returns an array of %DkpStatsObj's
588
dkp_device_get_statistics (const DkpDevice *device, const gchar *type, GError **error)
590
GError *error_local = NULL;
591
GType g_type_gvalue_array;
592
GPtrArray *gvalue_ptr_array = NULL;
597
GPtrArray *array = NULL;
600
g_return_val_if_fail (DKP_IS_DEVICE (device), NULL);
601
g_return_val_if_fail (device->priv->proxy_device != NULL, NULL);
603
g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
604
dbus_g_type_get_struct("GValueArray",
609
/* get compound data */
610
ret = dbus_g_proxy_call (device->priv->proxy_device, "GetStatistics", &error_local,
613
g_type_gvalue_array, &gvalue_ptr_array,
616
g_set_error (error, 1, 0, "GetStatistics(%s) on %s failed: %s", type,
617
device->priv->object_path, error_local->message);
618
g_error_free (error_local);
623
if (gvalue_ptr_array->len == 0) {
624
g_set_error_literal (error, 1, 0, "no data");
629
array = g_ptr_array_new ();
631
for (i=0; i<gvalue_ptr_array->len; i++) {
632
gva = (GValueArray *) g_ptr_array_index (gvalue_ptr_array, i);
633
obj = dkp_stats_obj_new ();
635
gv = g_value_array_get_nth (gva, 0);
636
obj->value = g_value_get_double (gv);
639
gv = g_value_array_get_nth (gva, 1);
640
obj->accuracy = g_value_get_double (gv);
643
g_ptr_array_add (array, obj);
644
g_value_array_free (gva);
647
if (gvalue_ptr_array != NULL)
648
g_ptr_array_free (gvalue_ptr_array, TRUE);
653
* dkp_device_set_property:
656
dkp_device_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
658
DkpDevice *device = DKP_DEVICE (object);
661
case PROP_NATIVE_PATH:
662
g_free (device->priv->native_path);
663
device->priv->native_path = g_strdup (g_value_get_string (value));
666
g_free (device->priv->vendor);
667
device->priv->vendor = g_strdup (g_value_get_string (value));
670
g_free (device->priv->model);
671
device->priv->model = g_strdup (g_value_get_string (value));
674
g_free (device->priv->serial);
675
device->priv->serial = g_strdup (g_value_get_string (value));
677
case PROP_UPDATE_TIME:
678
device->priv->update_time = g_value_get_uint64 (value);
681
device->priv->type = g_value_get_uint (value);
683
case PROP_POWER_SUPPLY:
684
device->priv->power_supply = g_value_get_boolean (value);
687
device->priv->online = g_value_get_boolean (value);
689
case PROP_IS_PRESENT:
690
device->priv->is_present = g_value_get_boolean (value);
692
case PROP_IS_RECHARGEABLE:
693
device->priv->is_rechargeable = g_value_get_boolean (value);
695
case PROP_HAS_HISTORY:
696
device->priv->has_history = g_value_get_boolean (value);
698
case PROP_HAS_STATISTICS:
699
device->priv->has_statistics = g_value_get_boolean (value);
702
device->priv->state = g_value_get_uint (value);
705
device->priv->capacity = g_value_get_double (value);
708
device->priv->energy = g_value_get_double (value);
710
case PROP_ENERGY_EMPTY:
711
device->priv->energy_empty = g_value_get_double (value);
713
case PROP_ENERGY_FULL:
714
device->priv->energy_full = g_value_get_double (value);
716
case PROP_ENERGY_FULL_DESIGN:
717
device->priv->energy_full_design = g_value_get_double (value);
719
case PROP_ENERGY_RATE:
720
device->priv->energy_rate = g_value_get_double (value);
723
device->priv->voltage = g_value_get_double (value);
725
case PROP_TIME_TO_EMPTY:
726
device->priv->time_to_empty = g_value_get_int64 (value);
728
case PROP_TIME_TO_FULL:
729
device->priv->time_to_full = g_value_get_int64 (value);
731
case PROP_PERCENTAGE:
732
device->priv->percentage = g_value_get_double (value);
734
case PROP_TECHNOLOGY:
735
device->priv->technology = g_value_get_uint (value);
737
case PROP_RECALL_NOTICE:
738
device->priv->recall_notice = g_value_get_boolean (value);
740
case PROP_RECALL_VENDOR:
741
g_free (device->priv->recall_vendor);
742
device->priv->recall_vendor = g_strdup (g_value_get_string (value));
744
case PROP_RECALL_URL:
745
g_free (device->priv->recall_url);
746
device->priv->recall_url = g_strdup (g_value_get_string (value));
749
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
755
* dkp_device_get_property:
758
dkp_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
760
DkpDevice *device = DKP_DEVICE (object);
763
case PROP_UPDATE_TIME:
764
g_value_set_uint64 (value, device->priv->update_time);
767
g_value_set_string (value, device->priv->vendor);
770
g_value_set_string (value, device->priv->model);
773
g_value_set_string (value, device->priv->serial);
775
case PROP_NATIVE_PATH:
776
g_value_set_string (value, device->priv->native_path);
778
case PROP_POWER_SUPPLY:
779
g_value_set_boolean (value, device->priv->power_supply);
782
g_value_set_boolean (value, device->priv->online);
784
case PROP_IS_PRESENT:
785
g_value_set_boolean (value, device->priv->is_present);
787
case PROP_IS_RECHARGEABLE:
788
g_value_set_boolean (value, device->priv->is_rechargeable);
790
case PROP_HAS_HISTORY:
791
g_value_set_boolean (value, device->priv->has_history);
793
case PROP_HAS_STATISTICS:
794
g_value_set_boolean (value, device->priv->has_statistics);
797
g_value_set_uint (value, device->priv->type);
800
g_value_set_uint (value, device->priv->state);
802
case PROP_TECHNOLOGY:
803
g_value_set_uint (value, device->priv->technology);
806
g_value_set_double (value, device->priv->capacity);
809
g_value_set_double (value, device->priv->energy);
811
case PROP_ENERGY_EMPTY:
812
g_value_set_double (value, device->priv->energy_empty);
814
case PROP_ENERGY_FULL:
815
g_value_set_double (value, device->priv->energy_full);
817
case PROP_ENERGY_FULL_DESIGN:
818
g_value_set_double (value, device->priv->energy_full_design);
820
case PROP_ENERGY_RATE:
821
g_value_set_double (value, device->priv->energy_rate);
824
g_value_set_double (value, device->priv->voltage);
826
case PROP_TIME_TO_EMPTY:
827
g_value_set_int64 (value, device->priv->time_to_empty);
829
case PROP_TIME_TO_FULL:
830
g_value_set_int64 (value, device->priv->time_to_full);
832
case PROP_PERCENTAGE:
833
g_value_set_double (value, device->priv->percentage);
835
case PROP_RECALL_NOTICE:
836
g_value_set_boolean (value, device->priv->recall_notice);
838
case PROP_RECALL_VENDOR:
839
g_value_set_string (value, device->priv->recall_vendor);
841
case PROP_RECALL_URL:
842
g_value_set_string (value, device->priv->recall_url);
845
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
851
* dkp_device_class_init:
852
* @klass: The DkpDeviceClass
855
dkp_device_class_init (DkpDeviceClass *klass)
857
GObjectClass *object_class = G_OBJECT_CLASS (klass);
858
object_class->finalize = dkp_device_finalize;
859
object_class->set_property = dkp_device_set_property;
860
object_class->get_property = dkp_device_get_property;
864
* @device: the #DkpDevice instance that emitted the signal
865
* @obj: the #DkpObject that has changed //TODO
867
* The ::changed signal is emitted when the device data has changed.
869
signals [DKP_DEVICE_CHANGED] =
870
g_signal_new ("changed",
871
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
872
G_STRUCT_OFFSET (DkpDeviceClass, changed),
873
NULL, NULL, g_cclosure_marshal_VOID__POINTER,
874
G_TYPE_NONE, 1, G_TYPE_POINTER);
877
* DkpDevice:update-time:
879
g_object_class_install_property (object_class,
881
g_param_spec_uint64 ("update-time",
888
g_object_class_install_property (object_class,
890
g_param_spec_string ("vendor",
897
g_object_class_install_property (object_class,
899
g_param_spec_string ("model",
906
g_object_class_install_property (object_class,
908
g_param_spec_string ("serial",
913
* DkpDevice:native-path:
915
g_object_class_install_property (object_class,
917
g_param_spec_string ("native-path",
922
* DkpDevice:power-supply:
924
g_object_class_install_property (object_class,
926
g_param_spec_boolean ("power-supply",
933
g_object_class_install_property (object_class,
935
g_param_spec_boolean ("online",
940
* DkpDevice:is-present:
942
g_object_class_install_property (object_class,
944
g_param_spec_boolean ("is-present",
949
* DkpDevice:is-rechargeable:
951
g_object_class_install_property (object_class,
952
PROP_IS_RECHARGEABLE,
953
g_param_spec_boolean ("is-rechargeable",
958
* DkpDevice:has-history:
960
g_object_class_install_property (object_class,
962
g_param_spec_boolean ("has-history",
967
* DkpDevice:has-statistics:
969
g_object_class_install_property (object_class,
971
g_param_spec_boolean ("has-statistics",
978
g_object_class_install_property (object_class,
980
g_param_spec_uint ("type",
982
DKP_DEVICE_TYPE_UNKNOWN,
983
DKP_DEVICE_TYPE_LAST,
984
DKP_DEVICE_TYPE_UNKNOWN,
989
g_object_class_install_property (object_class,
991
g_param_spec_uint ("state",
993
DKP_DEVICE_STATE_UNKNOWN,
994
DKP_DEVICE_STATE_LAST,
995
DKP_DEVICE_STATE_UNKNOWN,
998
* DkpDevice:technology:
1000
g_object_class_install_property (object_class,
1002
g_param_spec_uint ("technology",
1004
DKP_DEVICE_TECHNOLOGY_UNKNOWN,
1005
DKP_DEVICE_TECHNOLOGY_LAST,
1006
DKP_DEVICE_TECHNOLOGY_UNKNOWN,
1007
G_PARAM_READWRITE));
1009
* DkpDevice:capacity:
1011
g_object_class_install_property (object_class,
1013
g_param_spec_double ("capacity", NULL, NULL,
1015
G_PARAM_READWRITE));
1019
g_object_class_install_property (object_class,
1021
g_param_spec_double ("energy", NULL, NULL,
1022
0.0, G_MAXDOUBLE, 0.0,
1023
G_PARAM_READWRITE));
1025
* DkpDevice:energy-empty:
1027
g_object_class_install_property (object_class,
1029
g_param_spec_double ("energy-empty", NULL, NULL,
1030
0.0, G_MAXDOUBLE, 0.0,
1031
G_PARAM_READWRITE));
1033
* DkpDevice:energy-full:
1035
g_object_class_install_property (object_class,
1037
g_param_spec_double ("energy-full", NULL, NULL,
1038
0.0, G_MAXDOUBLE, 0.0,
1039
G_PARAM_READWRITE));
1041
* DkpDevice:energy-full-design:
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
* DkpDevice:energy-rate:
1051
g_object_class_install_property (object_class,
1053
g_param_spec_double ("energy-rate", NULL, NULL,
1054
0.0, G_MAXDOUBLE, 0.0,
1055
G_PARAM_READWRITE));
1057
* DkpDevice:voltage:
1059
g_object_class_install_property (object_class,
1061
g_param_spec_double ("voltage", NULL, NULL,
1062
0.0, G_MAXDOUBLE, 0.0,
1063
G_PARAM_READWRITE));
1065
* DkpDevice:time-to-empty:
1067
g_object_class_install_property (object_class,
1069
g_param_spec_int64 ("time-to-empty", NULL, NULL,
1071
G_PARAM_READWRITE));
1073
* DkpDevice:time-to-full:
1075
g_object_class_install_property (object_class,
1077
g_param_spec_int64 ("time-to-full", NULL, NULL,
1079
G_PARAM_READWRITE));
1081
* DkpDevice:percentage:
1083
g_object_class_install_property (object_class,
1085
g_param_spec_double ("percentage", NULL, NULL,
1087
G_PARAM_READWRITE));
1089
* DkpDevice:recall-notice:
1091
g_object_class_install_property (object_class,
1093
g_param_spec_boolean ("recall-notice",
1096
G_PARAM_READWRITE));
1098
* DkpDevice:recall-vendor:
1100
g_object_class_install_property (object_class,
1102
g_param_spec_string ("recall-vendor",
1105
G_PARAM_READWRITE));
1107
* DkpDevice:recall-url:
1109
g_object_class_install_property (object_class,
1111
g_param_spec_string ("recall-url",
1114
G_PARAM_READWRITE));
1116
g_type_class_add_private (klass, sizeof (DkpDevicePrivate));
1121
* @device: This class instance
1124
dkp_device_init (DkpDevice *device)
1126
device->priv = DKP_DEVICE_GET_PRIVATE (device);
1127
device->priv->object_path = NULL;
1128
device->priv->proxy_device = NULL;
1129
device->priv->proxy_props = NULL;
1133
* dkp_device_finalize:
1134
* @object: The object to finalize
1137
dkp_device_finalize (GObject *object)
1141
g_return_if_fail (DKP_IS_DEVICE (object));
1143
device = DKP_DEVICE (object);
1145
g_free (device->priv->object_path);
1146
g_free (device->priv->vendor);
1147
g_free (device->priv->model);
1148
g_free (device->priv->serial);
1149
g_free (device->priv->native_path);
1150
g_free (device->priv->recall_vendor);
1151
g_free (device->priv->recall_url);
1152
if (device->priv->proxy_device != NULL)
1153
g_object_unref (device->priv->proxy_device);
1154
if (device->priv->proxy_props != NULL)
1155
g_object_unref (device->priv->proxy_props);
1157
G_OBJECT_CLASS (dkp_device_parent_class)->finalize (object);
1163
* Return value: a new DkpDevice object.
1166
dkp_device_new (void)
1169
device = g_object_new (DKP_TYPE_DEVICE, NULL);
1170
return DKP_DEVICE (device);