Commit af56b087 authored by Richard Hughes's avatar Richard Hughes

trivial: Add some useful GObjects for client and server use

parent 5e8ba545
......@@ -41,8 +41,8 @@ typedef struct
} DkpWakeupsObj;
typedef DkpWakeupsObj UpWakeupsObj;
#define up_wakeups_obj_free dkp_wakeups_obj_free
#define up_wakeups_obj_new dkp_wakeups_obj_new
#define up_wakeup_item_free dkp_wakeups_obj_free
#define up_wakeup_item_new dkp_wakeups_obj_new
DkpWakeupsObj *dkp_wakeups_obj_new (void);
void dkp_wakeups_obj_free (DkpWakeupsObj *obj);
......
dkp-wakeups-obj.h
\ No newline at end of file
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2009 Richard Hughes <richard@hughsie.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#if !defined (__UPOWER_H_INSIDE__) && !defined (UP_COMPILATION)
#error "Only <devicekit-power.h> can be included directly."
#endif
#ifndef __DKP_WAKEUPS_OBJ_H__
#define __DKP_WAKEUPS_OBJ_H__
#include <glib.h>
#include <devkit-power-gobject/dkp-enum.h>
G_BEGIN_DECLS
typedef struct
{
gboolean is_userspace;
guint id;
guint old;
gfloat value;
gchar *cmdline;
gchar *details;
} DkpWakeupsObj;
typedef DkpWakeupsObj UpWakeupsObj;
#define up_wakeups_obj_free dkp_wakeups_obj_free
#define up_wakeups_obj_new dkp_wakeups_obj_new
DkpWakeupsObj *dkp_wakeups_obj_new (void);
void dkp_wakeups_obj_free (DkpWakeupsObj *obj);
DkpWakeupsObj *dkp_wakeups_obj_copy (const DkpWakeupsObj *cobj);
gboolean dkp_wakeups_obj_print (const DkpWakeupsObj *obj);
gboolean dkp_wakeups_obj_equal (const DkpWakeupsObj *obj1,
const DkpWakeupsObj *obj2);
G_END_DECLS
#endif /* __DKP_WAKEUPS_OBJ_H__ */
......@@ -78,6 +78,10 @@
</partintro>
<xi:include href="xml/up-client.xml"/>
<xi:include href="xml/up-device.xml"/>
<xi:include href="xml/up-history-item.xml"/>
<xi:include href="xml/up-qos-item.xml"/>
<xi:include href="xml/up-stats-item.xml"/>
<xi:include href="xml/up-wakeup-item.xml"/>
</reference>
<reference id="libupower-glib-helpers">
......
......@@ -22,11 +22,19 @@ libupower_glib_include_HEADERS = \
up-version.h \
up-types.h \
up-device.h \
up-qos-item.h \
up-wakeup-item.h \
up-stats-item.h \
up-history-item.h \
up-client.h
libupower_glib_la_SOURCES = \
up-types.c \
up-client.c \
up-qos-item.c \
up-wakeup-item.c \
up-stats-item.c \
up-history-item.c \
up-device.c
libupower_glib_la_LIBADD = \
......@@ -45,8 +53,6 @@ libupower_glib_la_CFLAGS = \
$(NULL)
EXTRA_DIST = \
up-client.h \
up-device.h \
up-version.h.in
CLEANFILES = $(BUILT_SOURCES)
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib.h>
#include "up-history-item.h"
static void up_history_item_class_init (UpHistoryItemClass *klass);
static void up_history_item_init (UpHistoryItem *history_item);
static void up_history_item_finalize (GObject *object);
#define UP_HISTORY_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_HISTORY_ITEM, UpHistoryItemPrivate))
struct UpHistoryItemPrivate
{
gdouble value;
guint time;
UpDeviceState state;
};
enum {
PROP_0,
PROP_VALUE,
PROP_TIME,
PROP_STATE,
PROP_LAST
};
G_DEFINE_TYPE (UpHistoryItem, up_history_item, G_TYPE_OBJECT)
/**
* up_history_item_set_value:
* @history_item: #UpHistoryItem
* @value: the new value
*
* Sets the item value.
*
* Since: 0.9.0
**/
void
up_history_item_set_value (UpHistoryItem *history_item, gdouble value)
{
g_return_if_fail (UP_IS_HISTORY_ITEM (history_item));
history_item->priv->value = value;
g_object_notify (G_OBJECT(history_item), "value");
}
/**
* up_history_item_get_value:
* @history_item: #UpHistoryItem
*
* Gets the item value.
*
* Since: 0.9.0
**/
gdouble
up_history_item_get_value (UpHistoryItem *history_item)
{
g_return_val_if_fail (UP_IS_HISTORY_ITEM (history_item), G_MAXDOUBLE);
return history_item->priv->value;
}
/**
* up_history_item_set_time:
* @history_item: #UpHistoryItem
* @time: the new value
*
* Sets the item time.
*
* Since: 0.9.0
**/
void
up_history_item_set_time (UpHistoryItem *history_item, guint time)
{
g_return_if_fail (UP_IS_HISTORY_ITEM (history_item));
history_item->priv->time = time;
g_object_notify (G_OBJECT(history_item), "time");
}
/**
* up_history_item_get_time:
* @history_item: #UpHistoryItem
*
* Gets the item time.
*
* Since: 0.9.0
**/
guint
up_history_item_get_time (UpHistoryItem *history_item)
{
g_return_val_if_fail (UP_IS_HISTORY_ITEM (history_item), G_MAXUINT);
return history_item->priv->time;
}
/**
* up_history_item_set_state:
* @history_item: #UpHistoryItem
* @state: the new value
*
* Sets the item state.
*
* Since: 0.9.0
**/
void
up_history_item_set_state (UpHistoryItem *history_item, UpDeviceState state)
{
g_return_if_fail (UP_IS_HISTORY_ITEM (history_item));
history_item->priv->state = state;
g_object_notify (G_OBJECT(history_item), "state");
}
/**
* up_history_item_get_state:
* @history_item: #UpHistoryItem
*
* Gets the item state.
*
* Since: 0.9.0
**/
UpDeviceState
up_history_item_get_state (UpHistoryItem *history_item)
{
g_return_val_if_fail (UP_IS_HISTORY_ITEM (history_item), G_MAXUINT);
return history_item->priv->state;
}
/**
* up_history_item_set_property:
**/
static void
up_history_item_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
UpHistoryItem *history_item = UP_HISTORY_ITEM (object);
switch (prop_id) {
case PROP_VALUE:
history_item->priv->value = g_value_get_double (value);
break;
case PROP_TIME:
history_item->priv->time = g_value_get_uint (value);
break;
case PROP_STATE:
history_item->priv->state = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* up_history_item_get_property:
**/
static void
up_history_item_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
UpHistoryItem *history_item = UP_HISTORY_ITEM (object);
switch (prop_id) {
case PROP_VALUE:
g_value_set_double (value, history_item->priv->value);
break;
case PROP_TIME:
g_value_set_uint (value, history_item->priv->time);
break;
case PROP_STATE:
g_value_set_uint (value, history_item->priv->state);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* up_history_item_class_init:
**/
static void
up_history_item_class_init (UpHistoryItemClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = up_history_item_finalize;
object_class->set_property = up_history_item_set_property;
object_class->get_property = up_history_item_get_property;
/**
* UpHistoryItem:value:
*
* Since: 0.9.0
**/
g_object_class_install_property (object_class,
PROP_VALUE,
g_param_spec_double ("value", NULL, NULL,
0.0, G_MAXDOUBLE, 0.0,
G_PARAM_READWRITE));
/**
* UpHistoryItem:time:
*
* Since: 0.9.0
**/
g_object_class_install_property (object_class,
PROP_TIME,
g_param_spec_uint ("time", NULL, NULL,
0, G_MAXUINT, 0,
G_PARAM_READWRITE));
/**
* UpHistoryItem:state:
*
* Since: 0.9.0
**/
g_object_class_install_property (object_class,
PROP_STATE,
g_param_spec_uint ("state", NULL, NULL,
0, G_MAXUINT,
UP_DEVICE_STATE_UNKNOWN,
G_PARAM_READWRITE));
g_type_class_add_private (klass, sizeof (UpHistoryItemPrivate));
}
/**
* up_history_item_init:
**/
static void
up_history_item_init (UpHistoryItem *history_item)
{
history_item->priv = UP_HISTORY_ITEM_GET_PRIVATE (history_item);
history_item->priv->value = 0.0f;
history_item->priv->time = 0;
history_item->priv->state = UP_DEVICE_STATE_UNKNOWN;
}
/**
* up_history_item_finalize:
**/
static void
up_history_item_finalize (GObject *object)
{
g_return_if_fail (UP_IS_HISTORY_ITEM (object));
G_OBJECT_CLASS (up_history_item_parent_class)->finalize (object);
}
/**
* up_history_item_new:
*
* Return value: a new UpHistoryItem object.
*
* Since: 0.9.0
**/
UpHistoryItem *
up_history_item_new (void)
{
UpHistoryItem *history_item;
history_item = g_object_new (UP_TYPE_HISTORY_ITEM, NULL);
return UP_HISTORY_ITEM (history_item);
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if !defined (__UPOWER_H_INSIDE__) && !defined (UP_COMPILATION)
#error "Only <upower.h> can be included directly."
#endif
#ifndef __UP_HISTORY_ITEM_H
#define __UP_HISTORY_ITEM_H
#include <glib-object.h>
#include <libupower-glib/up-types.h>
G_BEGIN_DECLS
#define UP_TYPE_HISTORY_ITEM (up_history_item_get_type ())
#define UP_HISTORY_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UP_TYPE_HISTORY_ITEM, UpHistoryItem))
#define UP_HISTORY_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UP_TYPE_HISTORY_ITEM, UpHistoryItemClass))
#define UP_IS_HISTORY_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UP_TYPE_HISTORY_ITEM))
#define UP_IS_HISTORY_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UP_TYPE_HISTORY_ITEM))
#define UP_HISTORY_ITEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UP_TYPE_HISTORY_ITEM, UpHistoryItemClass))
typedef struct UpHistoryItemPrivate UpHistoryItemPrivate;
typedef struct
{
GObject parent;
UpHistoryItemPrivate *priv;
} UpHistoryItem;
typedef struct
{
GObjectClass parent_class;
} UpHistoryItemClass;
GType up_history_item_get_type (void);
UpHistoryItem *up_history_item_new (void);
gdouble up_history_item_get_value (UpHistoryItem *history_item);
void up_history_item_set_value (UpHistoryItem *history_item,
gdouble value);
guint up_history_item_get_time (UpHistoryItem *history_item);
void up_history_item_set_time (UpHistoryItem *history_item,
guint time);
UpDeviceState up_history_item_get_state (UpHistoryItem *history_item);
void up_history_item_set_state (UpHistoryItem *history_item,
UpDeviceState state);
G_END_DECLS
#endif /* __UP_HISTORY_ITEM_H */
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008-2010 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib.h>
#include "up-qos-item.h"
static void up_qos_item_class_init (UpQosItemClass *klass);
static void up_qos_item_init (UpQosItem *qos_item);
static void up_qos_item_finalize (GObject *object);
#define UP_QOS_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_QOS_ITEM, UpQosItemPrivate))
struct UpQosItemPrivate
{
guint uid;
guint pid;
gchar *sender;
gchar *cmdline;
guint cookie;
guint64 timespec;
gboolean persistent;
UpQosKind type;
gint value;
};
enum {
PROP_0,
PROP_UID,
PROP_PID,
PROP_SENDER,
PROP_CMDLINE,
PROP_COOKIE,
PROP_TIMESPEC,
PROP_PERSISTENT,
PROP_TYPE,
PROP_VALUE,
PROP_LAST
};
G_DEFINE_TYPE (UpQosItem, up_qos_item, G_TYPE_OBJECT)
/**
* up_qos_item_get_uid:
* @qos_item: #UpQosItem
*
* Gets the item uid.
*
* Return value: the value
*
* Since: 0.9.0
**/
guint
up_qos_item_get_uid (UpQosItem *qos_item)
{
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), G_MAXUINT);
return qos_item->priv->uid;
}
/**
* up_qos_item_set_uid:
* @qos_item: #UpQosItem
* @uid: the new value
*
* Sets the item uid.
*
* Since: 0.9.0
**/
void
up_qos_item_set_uid (UpQosItem *qos_item, guint uid)
{
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
qos_item->priv->uid = uid;
g_object_notify (G_OBJECT(qos_item), "uid");
}
/**
* up_qos_item_get_pid:
* @qos_item: #UpQosItem
*
* Gets the item pid.
*
* Return value: the value
*
* Since: 0.9.0
**/
guint
up_qos_item_get_pid (UpQosItem *qos_item)
{
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), G_MAXUINT);
return qos_item->priv->pid;
}
/**
* up_qos_item_set_pid:
* @qos_item: #UpQosItem
* @pid: the new value
*
* Sets the item pid.
*
* Since: 0.9.0
**/
void
up_qos_item_set_pid (UpQosItem *qos_item, guint pid)
{
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
qos_item->priv->pid = pid;
g_object_notify (G_OBJECT(qos_item), "pid");
}
/**
* up_qos_item_get_sender:
* @qos_item: #UpQosItem
*
* Gets the item sender.
*
* Return value: the value
*
* Since: 0.9.0
**/
const gchar *
up_qos_item_get_sender (UpQosItem *qos_item)
{
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), NULL);
return qos_item->priv->sender;
}
/**
* up_qos_item_set_sender:
* @qos_item: #UpQosItem
* @sender: the new value
*
* Sets the item sender.
*
* Since: 0.9.0
**/
void
up_qos_item_set_sender (UpQosItem *qos_item, const gchar *sender)
{
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
g_free (qos_item->priv->sender);
qos_item->priv->sender = g_strdup (sender);
g_object_notify (G_OBJECT(qos_item), "sender");
}
/**
* up_qos_item_get_cmdline:
* @qos_item: #UpQosItem
*
* Gets the item cmdline.
*
* Return value: the value
*
* Since: 0.9.0
**/
const gchar *
up_qos_item_get_cmdline (UpQosItem *qos_item)
{
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), NULL);
return qos_item->priv->cmdline;
}
/**
* up_qos_item_set_cmdline:
* @qos_item: #UpQosItem
* @cmdline: the new value
*
* Sets the item cmdline.
*