~xavi-garcia-mena/ubuntu/vivid/upower/percentages-power-off

« back to all changes in this revision

Viewing changes to libupower-glib/up-wakeup-item.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2010-02-16 10:16:24 UTC
  • Revision ID: james.westby@ubuntu.com-20100216101624-2cmwqsr1ndftdd87
Tags: upstream-0.9.0+git20100216.72bb2
ImportĀ upstreamĀ versionĀ 0.9.0+git20100216.72bb2

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-2010 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-wakeup-item
 
24
 * @short_description: Helper object representing one item of wakeup data.
 
25
 *
 
26
 * This object represents one item of data which may be returned from the
 
27
 * daemon in response to a query.
 
28
 *
 
29
 * See also: #UpDevice, #UpClient
 
30
 */
 
31
 
 
32
#include "config.h"
 
33
 
 
34
#include <glib.h>
 
35
 
 
36
#include "up-wakeup-item.h"
 
37
 
 
38
static void     up_wakeup_item_class_init       (UpWakeupItemClass      *klass);
 
39
static void     up_wakeup_item_init             (UpWakeupItem           *wakeup_item);
 
40
static void     up_wakeup_item_finalize         (GObject                *object);
 
41
 
 
42
#define UP_WAKEUP_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_WAKEUP_ITEM, UpWakeupItemPrivate))
 
43
 
 
44
struct UpWakeupItemPrivate
 
45
{
 
46
        gboolean                 is_userspace;
 
47
        guint                    id;
 
48
        guint                    old;
 
49
        gdouble                  value;
 
50
        gchar                   *cmdline;
 
51
        gchar                   *details;
 
52
};
 
53
 
 
54
enum {
 
55
        PROP_0,
 
56
        PROP_IS_USERSPACE,
 
57
        PROP_ID,
 
58
        PROP_OLD,
 
59
        PROP_VALUE,
 
60
        PROP_CMDLINE,
 
61
        PROP_DETAILS,
 
62
        PROP_LAST
 
63
};
 
64
 
 
65
G_DEFINE_TYPE (UpWakeupItem, up_wakeup_item, G_TYPE_OBJECT)
 
66
 
 
67
/**
 
68
 * up_wakeup_item_get_is_userspace:
 
69
 * @history_item: #UpWakeupItem
 
70
 *
 
71
 * Gets if the item is userspace.
 
72
 *
 
73
 * Return value: the value
 
74
 *
 
75
 * Since: 0.9.0
 
76
 **/
 
77
gboolean
 
78
up_wakeup_item_get_is_userspace (UpWakeupItem *wakeup_item)
 
79
{
 
80
        g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), FALSE);
 
81
        return wakeup_item->priv->is_userspace;
 
82
}
 
83
 
 
84
/**
 
85
 * up_wakeup_item_set_is_userspace:
 
86
 * @history_item: #UpWakeupItem
 
87
 * @is_userspace: the new value
 
88
 *
 
89
 * Sets if the item is userspace.
 
90
 *
 
91
 * Since: 0.9.0
 
92
 **/
 
93
void
 
94
up_wakeup_item_set_is_userspace (UpWakeupItem *wakeup_item, gboolean is_userspace)
 
95
{
 
96
        g_return_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item));
 
97
        wakeup_item->priv->is_userspace = is_userspace;
 
98
        g_object_notify (G_OBJECT(wakeup_item), "is-userspace");
 
99
}
 
100
 
 
101
/**
 
102
 * up_wakeup_item_get_id:
 
103
 * @history_item: #UpWakeupItem
 
104
 *
 
105
 * Gets the item id.
 
106
 *
 
107
 * Return value: the value
 
108
 *
 
109
 * Since: 0.9.0
 
110
 **/
 
111
guint
 
112
up_wakeup_item_get_id (UpWakeupItem *wakeup_item)
 
113
{
 
114
        g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), G_MAXUINT);
 
115
        return wakeup_item->priv->id;
 
116
}
 
117
 
 
118
/**
 
119
 * up_wakeup_item_set_id:
 
120
 * @history_item: #UpWakeupItem
 
121
 * @id: the new value
 
122
 *
 
123
 * Sets the item id.
 
124
 *
 
125
 * Since: 0.9.0
 
126
 **/
 
127
void
 
128
up_wakeup_item_set_id (UpWakeupItem *wakeup_item, guint id)
 
129
{
 
130
        g_return_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item));
 
131
        wakeup_item->priv->id = id;
 
132
        g_object_notify (G_OBJECT(wakeup_item), "id");
 
133
}
 
134
 
 
135
/**
 
136
 * up_wakeup_item_get_old:
 
137
 * @history_item: #UpWakeupItem
 
138
 *
 
139
 * Gets the item old.
 
140
 *
 
141
 * Return value: the value
 
142
 *
 
143
 * Since: 0.9.0
 
144
 **/
 
145
guint
 
146
up_wakeup_item_get_old (UpWakeupItem *wakeup_item)
 
147
{
 
148
        g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), G_MAXUINT);
 
149
        return wakeup_item->priv->old;
 
150
}
 
151
 
 
152
/**
 
153
 * up_wakeup_item_set_old:
 
154
 * @history_item: #UpWakeupItem
 
155
 * @old: the new value
 
156
 *
 
157
 * Sets the item old.
 
158
 *
 
159
 * Since: 0.9.0
 
160
 **/
 
161
void
 
162
up_wakeup_item_set_old (UpWakeupItem *wakeup_item, guint old)
 
163
{
 
164
        g_return_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item));
 
165
        wakeup_item->priv->old = old;
 
166
        g_object_notify (G_OBJECT(wakeup_item), "old");
 
167
}
 
168
 
 
169
/**
 
170
 * up_wakeup_item_get_value:
 
171
 * @history_item: #UpWakeupItem
 
172
 *
 
173
 * Gets the item value.
 
174
 *
 
175
 * Return value: the value
 
176
 *
 
177
 * Since: 0.9.0
 
178
 **/
 
179
gdouble
 
180
up_wakeup_item_get_value (UpWakeupItem *wakeup_item)
 
181
{
 
182
        g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), G_MAXDOUBLE);
 
183
        return wakeup_item->priv->value;
 
184
}
 
185
 
 
186
/**
 
187
 * up_wakeup_item_set_value:
 
188
 * @history_item: #UpWakeupItem
 
189
 * @value: the new value
 
190
 *
 
191
 * Sets the item value.
 
192
 *
 
193
 * Since: 0.9.0
 
194
 **/
 
195
void
 
196
up_wakeup_item_set_value (UpWakeupItem *wakeup_item, gdouble value)
 
197
{
 
198
        g_return_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item));
 
199
        wakeup_item->priv->value = value;
 
200
        g_object_notify (G_OBJECT(wakeup_item), "value");
 
201
}
 
202
 
 
203
/**
 
204
 * up_wakeup_item_get_cmdline:
 
205
 * @history_item: #UpWakeupItem
 
206
 *
 
207
 * Gets the item cmdline.
 
208
 *
 
209
 * Return value: the value
 
210
 *
 
211
 * Since: 0.9.0
 
212
 **/
 
213
const gchar *
 
214
up_wakeup_item_get_cmdline (UpWakeupItem *wakeup_item)
 
215
{
 
216
        g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), NULL);
 
217
        return wakeup_item->priv->cmdline;
 
218
}
 
219
 
 
220
/**
 
221
 * up_wakeup_item_set_cmdline:
 
222
 * @history_item: #UpWakeupItem
 
223
 * @cmdline: the new value
 
224
 *
 
225
 * Sets the item cmdline.
 
226
 *
 
227
 * Since: 0.9.0
 
228
 **/
 
229
void
 
230
up_wakeup_item_set_cmdline (UpWakeupItem *wakeup_item, const gchar *cmdline)
 
231
{
 
232
        g_return_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item));
 
233
        g_free (wakeup_item->priv->cmdline);
 
234
        wakeup_item->priv->cmdline = g_strdup (cmdline);
 
235
        g_object_notify (G_OBJECT(wakeup_item), "cmdline");
 
236
}
 
237
 
 
238
/**
 
239
 * up_wakeup_item_get_details:
 
240
 * @history_item: #UpWakeupItem
 
241
 *
 
242
 * Gets the item details.
 
243
 *
 
244
 * Return value: the value
 
245
 *
 
246
 * Since: 0.9.0
 
247
 **/
 
248
const gchar *
 
249
up_wakeup_item_get_details (UpWakeupItem *wakeup_item)
 
250
{
 
251
        g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), NULL);
 
252
        return wakeup_item->priv->details;
 
253
}
 
254
 
 
255
/**
 
256
 * up_wakeup_item_set_details:
 
257
 * @history_item: #UpWakeupItem
 
258
 * @details: the new value
 
259
 *
 
260
 * Sets the item details.
 
261
 *
 
262
 * Since: 0.9.0
 
263
 **/
 
264
void
 
265
up_wakeup_item_set_details (UpWakeupItem *wakeup_item, const gchar *details)
 
266
{
 
267
        g_return_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item));
 
268
        g_free (wakeup_item->priv->details);
 
269
        wakeup_item->priv->details = g_strdup (details);
 
270
        g_object_notify (G_OBJECT(wakeup_item), "details");
 
271
}
 
272
 
 
273
/**
 
274
 * up_wakeup_item_set_property:
 
275
 **/
 
276
static void
 
277
up_wakeup_item_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 
278
{
 
279
        UpWakeupItem *wakeup_item = UP_WAKEUP_ITEM (object);
 
280
 
 
281
        switch (prop_id) {
 
282
        case PROP_IS_USERSPACE:
 
283
                wakeup_item->priv->is_userspace = g_value_get_boolean (value);
 
284
                break;
 
285
        case PROP_ID:
 
286
                wakeup_item->priv->id = g_value_get_uint (value);
 
287
                break;
 
288
        case PROP_OLD:
 
289
                wakeup_item->priv->old = g_value_get_uint (value);
 
290
                break;
 
291
        case PROP_VALUE:
 
292
                wakeup_item->priv->value = g_value_get_double (value);
 
293
                break;
 
294
        case PROP_CMDLINE:
 
295
                g_free (wakeup_item->priv->cmdline);
 
296
                wakeup_item->priv->cmdline = g_strdup (g_value_get_string (value));
 
297
                break;
 
298
        case PROP_DETAILS:
 
299
                g_free (wakeup_item->priv->details);
 
300
                wakeup_item->priv->details = g_strdup (g_value_get_string (value));
 
301
                break;
 
302
        default:
 
303
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
304
                break;
 
305
        }
 
306
}
 
307
 
 
308
/**
 
309
 * up_wakeup_item_get_property:
 
310
 **/
 
311
static void
 
312
up_wakeup_item_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 
313
{
 
314
        UpWakeupItem *wakeup_item = UP_WAKEUP_ITEM (object);
 
315
 
 
316
        switch (prop_id) {
 
317
        case PROP_IS_USERSPACE:
 
318
                g_value_set_boolean (value, wakeup_item->priv->is_userspace);
 
319
                break;
 
320
        case PROP_ID:
 
321
                g_value_set_uint (value, wakeup_item->priv->id);
 
322
                break;
 
323
        case PROP_OLD:
 
324
                g_value_set_uint (value, wakeup_item->priv->old);
 
325
                break;
 
326
        case PROP_VALUE:
 
327
                g_value_set_double (value, wakeup_item->priv->value);
 
328
                break;
 
329
        case PROP_CMDLINE:
 
330
                g_value_set_string (value, wakeup_item->priv->cmdline);
 
331
                break;
 
332
        case PROP_DETAILS:
 
333
                g_value_set_string (value, wakeup_item->priv->details);
 
334
                break;
 
335
        default:
 
336
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
337
                break;
 
338
    }
 
339
}
 
340
 
 
341
/**
 
342
 * up_wakeup_item_class_init:
 
343
 * @klass: The UpWakeupItemClass
 
344
 **/
 
345
static void
 
346
up_wakeup_item_class_init (UpWakeupItemClass *klass)
 
347
{
 
348
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
349
        object_class->finalize = up_wakeup_item_finalize;
 
350
        object_class->set_property = up_wakeup_item_set_property;
 
351
        object_class->get_property = up_wakeup_item_get_property;
 
352
 
 
353
        /**
 
354
         * UpWakeupItem:is-userspace:
 
355
         *
 
356
         * Since: 0.9.0
 
357
         **/
 
358
        g_object_class_install_property (object_class,
 
359
                                         PROP_IS_USERSPACE,
 
360
                                         g_param_spec_boolean ("is-userspace", NULL, NULL,
 
361
                                                               FALSE,
 
362
                                                               G_PARAM_READWRITE));
 
363
        /**
 
364
         * UpWakeupItem:id:
 
365
         *
 
366
         * Since: 0.9.0
 
367
         **/
 
368
        g_object_class_install_property (object_class,
 
369
                                         PROP_ID,
 
370
                                         g_param_spec_uint ("id", NULL, NULL,
 
371
                                                            0, G_MAXUINT, 0,
 
372
                                                            G_PARAM_READWRITE));
 
373
        /**
 
374
         * UpWakeupItem:old:
 
375
         *
 
376
         * Since: 0.9.0
 
377
         **/
 
378
        g_object_class_install_property (object_class,
 
379
                                         PROP_OLD,
 
380
                                         g_param_spec_uint ("old", NULL, NULL,
 
381
                                                            0, G_MAXUINT, 0,
 
382
                                                            G_PARAM_READWRITE));
 
383
        /**
 
384
         * UpWakeupItem:value:
 
385
         *
 
386
         * Since: 0.9.0
 
387
         **/
 
388
        g_object_class_install_property (object_class,
 
389
                                         PROP_VALUE,
 
390
                                         g_param_spec_double ("value", NULL, NULL,
 
391
                                                              0.0, G_MAXDOUBLE, 0.0,
 
392
                                                              G_PARAM_READWRITE));
 
393
        /**
 
394
         * UpWakeupItem:cmdline:
 
395
         *
 
396
         * Since: 0.9.0
 
397
         **/
 
398
        g_object_class_install_property (object_class,
 
399
                                         PROP_CMDLINE,
 
400
                                         g_param_spec_string ("cmdline", NULL, NULL,
 
401
                                                              NULL,
 
402
                                                              G_PARAM_READWRITE));
 
403
        /**
 
404
         * UpWakeupItem:details:
 
405
         *
 
406
         * Since: 0.9.0
 
407
         **/
 
408
        g_object_class_install_property (object_class,
 
409
                                         PROP_DETAILS,
 
410
                                         g_param_spec_string ("details", NULL, NULL,
 
411
                                                              NULL,
 
412
                                                              G_PARAM_READWRITE));
 
413
 
 
414
        g_type_class_add_private (klass, sizeof (UpWakeupItemPrivate));
 
415
}
 
416
 
 
417
/**
 
418
 * up_wakeup_item_init:
 
419
 * @wakeup_item: This class instance
 
420
 **/
 
421
static void
 
422
up_wakeup_item_init (UpWakeupItem *wakeup_item)
 
423
{
 
424
        wakeup_item->priv = UP_WAKEUP_ITEM_GET_PRIVATE (wakeup_item);
 
425
        wakeup_item->priv->is_userspace = FALSE;
 
426
        wakeup_item->priv->id = 0;
 
427
        wakeup_item->priv->old = 0;
 
428
        wakeup_item->priv->value = 0.0f;
 
429
        wakeup_item->priv->cmdline = NULL;
 
430
        wakeup_item->priv->details = NULL;
 
431
}
 
432
 
 
433
/**
 
434
 * up_wakeup_item_finalize:
 
435
 * @object: The object to finalize
 
436
 **/
 
437
static void
 
438
up_wakeup_item_finalize (GObject *object)
 
439
{
 
440
        UpWakeupItem *wakeup_item;
 
441
 
 
442
        g_return_if_fail (UP_IS_WAKEUP_ITEM (object));
 
443
 
 
444
        wakeup_item = UP_WAKEUP_ITEM (object);
 
445
        g_free (wakeup_item->priv->cmdline);
 
446
        g_free (wakeup_item->priv->details);
 
447
 
 
448
        G_OBJECT_CLASS (up_wakeup_item_parent_class)->finalize (object);
 
449
}
 
450
 
 
451
/**
 
452
 * up_wakeup_item_new:
 
453
 *
 
454
 * Return value: a new UpWakeupItem object.
 
455
 *
 
456
 * Since: 0.9.0
 
457
 **/
 
458
UpWakeupItem *
 
459
up_wakeup_item_new (void)
 
460
{
 
461
        UpWakeupItem *wakeup_item;
 
462
        wakeup_item = g_object_new (UP_TYPE_WAKEUP_ITEM, NULL);
 
463
        return UP_WAKEUP_ITEM (wakeup_item);
 
464
}
 
465