1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3
* Copyright (C) 2008-2010 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.
23
* SECTION:up-wakeup-item
24
* @short_description: Helper object representing one item of wakeup data.
26
* This object represents one item of data which may be returned from the
27
* daemon in response to a query.
29
* See also: #UpDevice, #UpClient
36
#include "up-wakeup-item.h"
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);
42
#define UP_WAKEUP_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_WAKEUP_ITEM, UpWakeupItemPrivate))
44
struct UpWakeupItemPrivate
46
gboolean is_userspace;
65
G_DEFINE_TYPE (UpWakeupItem, up_wakeup_item, G_TYPE_OBJECT)
68
* up_wakeup_item_get_is_userspace:
69
* @history_item: #UpWakeupItem
71
* Gets if the item is userspace.
73
* Return value: the value
78
up_wakeup_item_get_is_userspace (UpWakeupItem *wakeup_item)
80
g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), FALSE);
81
return wakeup_item->priv->is_userspace;
85
* up_wakeup_item_set_is_userspace:
86
* @history_item: #UpWakeupItem
87
* @is_userspace: the new value
89
* Sets if the item is userspace.
94
up_wakeup_item_set_is_userspace (UpWakeupItem *wakeup_item, gboolean is_userspace)
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");
102
* up_wakeup_item_get_id:
103
* @history_item: #UpWakeupItem
107
* Return value: the value
112
up_wakeup_item_get_id (UpWakeupItem *wakeup_item)
114
g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), G_MAXUINT);
115
return wakeup_item->priv->id;
119
* up_wakeup_item_set_id:
120
* @history_item: #UpWakeupItem
128
up_wakeup_item_set_id (UpWakeupItem *wakeup_item, guint id)
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");
136
* up_wakeup_item_get_old:
137
* @history_item: #UpWakeupItem
141
* Return value: the value
146
up_wakeup_item_get_old (UpWakeupItem *wakeup_item)
148
g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), G_MAXUINT);
149
return wakeup_item->priv->old;
153
* up_wakeup_item_set_old:
154
* @history_item: #UpWakeupItem
155
* @old: the new value
162
up_wakeup_item_set_old (UpWakeupItem *wakeup_item, guint old)
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");
170
* up_wakeup_item_get_value:
171
* @history_item: #UpWakeupItem
173
* Gets the item value.
175
* Return value: the value
180
up_wakeup_item_get_value (UpWakeupItem *wakeup_item)
182
g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), G_MAXDOUBLE);
183
return wakeup_item->priv->value;
187
* up_wakeup_item_set_value:
188
* @history_item: #UpWakeupItem
189
* @value: the new value
191
* Sets the item value.
196
up_wakeup_item_set_value (UpWakeupItem *wakeup_item, gdouble value)
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");
204
* up_wakeup_item_get_cmdline:
205
* @history_item: #UpWakeupItem
207
* Gets the item cmdline.
209
* Return value: the value
214
up_wakeup_item_get_cmdline (UpWakeupItem *wakeup_item)
216
g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), NULL);
217
return wakeup_item->priv->cmdline;
221
* up_wakeup_item_set_cmdline:
222
* @history_item: #UpWakeupItem
223
* @cmdline: the new value
225
* Sets the item cmdline.
230
up_wakeup_item_set_cmdline (UpWakeupItem *wakeup_item, const gchar *cmdline)
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");
239
* up_wakeup_item_get_details:
240
* @history_item: #UpWakeupItem
242
* Gets the item details.
244
* Return value: the value
249
up_wakeup_item_get_details (UpWakeupItem *wakeup_item)
251
g_return_val_if_fail (UP_IS_WAKEUP_ITEM (wakeup_item), NULL);
252
return wakeup_item->priv->details;
256
* up_wakeup_item_set_details:
257
* @history_item: #UpWakeupItem
258
* @details: the new value
260
* Sets the item details.
265
up_wakeup_item_set_details (UpWakeupItem *wakeup_item, const gchar *details)
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");
274
* up_wakeup_item_set_property:
277
up_wakeup_item_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
279
UpWakeupItem *wakeup_item = UP_WAKEUP_ITEM (object);
282
case PROP_IS_USERSPACE:
283
wakeup_item->priv->is_userspace = g_value_get_boolean (value);
286
wakeup_item->priv->id = g_value_get_uint (value);
289
wakeup_item->priv->old = g_value_get_uint (value);
292
wakeup_item->priv->value = g_value_get_double (value);
295
g_free (wakeup_item->priv->cmdline);
296
wakeup_item->priv->cmdline = g_strdup (g_value_get_string (value));
299
g_free (wakeup_item->priv->details);
300
wakeup_item->priv->details = g_strdup (g_value_get_string (value));
303
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
309
* up_wakeup_item_get_property:
312
up_wakeup_item_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
314
UpWakeupItem *wakeup_item = UP_WAKEUP_ITEM (object);
317
case PROP_IS_USERSPACE:
318
g_value_set_boolean (value, wakeup_item->priv->is_userspace);
321
g_value_set_uint (value, wakeup_item->priv->id);
324
g_value_set_uint (value, wakeup_item->priv->old);
327
g_value_set_double (value, wakeup_item->priv->value);
330
g_value_set_string (value, wakeup_item->priv->cmdline);
333
g_value_set_string (value, wakeup_item->priv->details);
336
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
342
* up_wakeup_item_class_init:
343
* @klass: The UpWakeupItemClass
346
up_wakeup_item_class_init (UpWakeupItemClass *klass)
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;
354
* UpWakeupItem:is-userspace:
358
g_object_class_install_property (object_class,
360
g_param_spec_boolean ("is-userspace", NULL, NULL,
368
g_object_class_install_property (object_class,
370
g_param_spec_uint ("id", NULL, NULL,
378
g_object_class_install_property (object_class,
380
g_param_spec_uint ("old", NULL, NULL,
384
* UpWakeupItem:value:
388
g_object_class_install_property (object_class,
390
g_param_spec_double ("value", NULL, NULL,
391
0.0, G_MAXDOUBLE, 0.0,
394
* UpWakeupItem:cmdline:
398
g_object_class_install_property (object_class,
400
g_param_spec_string ("cmdline", NULL, NULL,
404
* UpWakeupItem:details:
408
g_object_class_install_property (object_class,
410
g_param_spec_string ("details", NULL, NULL,
414
g_type_class_add_private (klass, sizeof (UpWakeupItemPrivate));
418
* up_wakeup_item_init:
419
* @wakeup_item: This class instance
422
up_wakeup_item_init (UpWakeupItem *wakeup_item)
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;
434
* up_wakeup_item_finalize:
435
* @object: The object to finalize
438
up_wakeup_item_finalize (GObject *object)
440
UpWakeupItem *wakeup_item;
442
g_return_if_fail (UP_IS_WAKEUP_ITEM (object));
444
wakeup_item = UP_WAKEUP_ITEM (object);
445
g_free (wakeup_item->priv->cmdline);
446
g_free (wakeup_item->priv->details);
448
G_OBJECT_CLASS (up_wakeup_item_parent_class)->finalize (object);
452
* up_wakeup_item_new:
454
* Return value: a new UpWakeupItem object.
459
up_wakeup_item_new (void)
461
UpWakeupItem *wakeup_item;
462
wakeup_item = g_object_new (UP_TYPE_WAKEUP_ITEM, NULL);
463
return UP_WAKEUP_ITEM (wakeup_item);