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.
23
* SECTION:up-stats-item
24
* @short_description: Helper object representing one item of statistics 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-stats-item.h"
38
static void up_stats_item_class_init (UpStatsItemClass *klass);
39
static void up_stats_item_init (UpStatsItem *stats_item);
40
static void up_stats_item_finalize (GObject *object);
42
#define UP_STATS_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_STATS_ITEM, UpStatsItemPrivate))
44
struct UpStatsItemPrivate
57
G_DEFINE_TYPE (UpStatsItem, up_stats_item, G_TYPE_OBJECT)
60
* up_stats_item_set_value:
62
* Sets the item value.
67
up_stats_item_set_value (UpStatsItem *stats_item, gdouble value)
69
g_return_if_fail (UP_IS_STATS_ITEM (stats_item));
70
stats_item->priv->value = value;
71
g_object_notify (G_OBJECT(stats_item), "value");
75
* up_stats_item_get_value:
77
* Gets the item value.
82
up_stats_item_get_value (UpStatsItem *stats_item)
84
g_return_val_if_fail (UP_IS_STATS_ITEM (stats_item), G_MAXDOUBLE);
85
return stats_item->priv->value;
89
* up_stats_item_set_accuracy:
91
* Sets the item accuracy.
96
up_stats_item_set_accuracy (UpStatsItem *stats_item, gdouble accuracy)
98
g_return_if_fail (UP_IS_STATS_ITEM (stats_item));
99
stats_item->priv->accuracy = accuracy;
100
g_object_notify (G_OBJECT(stats_item), "accuracy");
104
* up_stats_item_get_accuracy:
106
* Gets the item accuracy.
111
up_stats_item_get_accuracy (UpStatsItem *stats_item)
113
g_return_val_if_fail (UP_IS_STATS_ITEM (stats_item), G_MAXDOUBLE);
114
return stats_item->priv->accuracy;
118
* up_stats_item_set_property:
121
up_stats_item_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
123
UpStatsItem *stats_item = UP_STATS_ITEM (object);
127
stats_item->priv->value = g_value_get_double (value);
130
stats_item->priv->accuracy = g_value_get_double (value);
133
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
139
* up_stats_item_get_property:
142
up_stats_item_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
144
UpStatsItem *stats_item = UP_STATS_ITEM (object);
148
g_value_set_double (value, stats_item->priv->value);
151
g_value_set_double (value, stats_item->priv->accuracy);
154
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
160
* up_stats_item_class_init:
161
* @klass: The UpStatsItemClass
164
up_stats_item_class_init (UpStatsItemClass *klass)
166
GObjectClass *object_class = G_OBJECT_CLASS (klass);
167
object_class->finalize = up_stats_item_finalize;
168
object_class->set_property = up_stats_item_set_property;
169
object_class->get_property = up_stats_item_get_property;
176
g_object_class_install_property (object_class,
178
g_param_spec_double ("value", NULL, NULL,
179
0.0, G_MAXDOUBLE, 0.0,
182
* UpStatsItem:accuracy:
186
g_object_class_install_property (object_class,
188
g_param_spec_double ("accuracy", NULL, NULL,
189
0.0, G_MAXDOUBLE, 0.0,
192
g_type_class_add_private (klass, sizeof (UpStatsItemPrivate));
196
* up_stats_item_init:
197
* @stats_item: This class instance
200
up_stats_item_init (UpStatsItem *stats_item)
202
stats_item->priv = UP_STATS_ITEM_GET_PRIVATE (stats_item);
203
stats_item->priv->value = 0.0f;
204
stats_item->priv->accuracy = 0.0f;
208
* up_stats_item_finalize:
209
* @object: The object to finalize
212
up_stats_item_finalize (GObject *object)
214
g_return_if_fail (UP_IS_STATS_ITEM (object));
215
G_OBJECT_CLASS (up_stats_item_parent_class)->finalize (object);
221
* Return value: a new UpStatsItem object.
226
up_stats_item_new (void)
228
UpStatsItem *stats_item;
229
stats_item = g_object_new (UP_TYPE_STATS_ITEM, NULL);
230
return UP_STATS_ITEM (stats_item);