mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-27 10:08:25 +02:00
bugfix: remove use of EggObjList, which was pretty hacky, and try to make the library more sane
This commit is contained in:
parent
39ba30a4b4
commit
55db60ef82
18 changed files with 262 additions and 917 deletions
|
|
@ -1,7 +1,9 @@
|
|||
INCLUDES = \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(DBUS_GLIB_CFLAGS) \
|
||||
-I$(top_srcdir) \
|
||||
-I$(top_srcdir)/libdevkit-power \
|
||||
-DDKP_COMPILATION \
|
||||
-DEGG_LOG_FILE=\""$(DKP_LOG_DIR)/DeviceKit-power"\" \
|
||||
-DEGG_VERBOSE="\"DKP_VERBOSE\"" \
|
||||
-DEGG_LOGGING="\"DKP_LOGGING\"" \
|
||||
|
|
@ -17,8 +19,7 @@ libdevkit_power_la_SOURCES = \
|
|||
egg-debug.h \
|
||||
egg-string.c \
|
||||
egg-string.h \
|
||||
egg-obj-list.c \
|
||||
egg-obj-list.h \
|
||||
devicekit-power.h \
|
||||
dkp-client.c \
|
||||
dkp-client.h \
|
||||
dkp-device.c \
|
||||
|
|
|
|||
|
|
@ -19,12 +19,16 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if !defined (__DEVICEKIT_POWER_H_INSIDE__) && !defined (DKP_COMPILATION)
|
||||
#error "Only <devicekit-power.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __DKP_CLIENT_H
|
||||
#define __DKP_CLIENT_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <dkp-enum.h>
|
||||
#include "dkp-device.h"
|
||||
#include <libdevkit-power/dkp-enum.h>
|
||||
#include <libdevkit-power/dkp-device.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
#include <dbus/dbus-glib.h>
|
||||
|
||||
#include "egg-debug.h"
|
||||
#include "egg-obj-list.h"
|
||||
|
||||
#include "dkp-device.h"
|
||||
#include "dkp-object.h"
|
||||
|
|
@ -201,8 +200,8 @@ static gboolean
|
|||
dkp_device_print_history (const DkpDevice *device, const gchar *type)
|
||||
{
|
||||
guint i;
|
||||
EggObjList *array;
|
||||
DkpHistoryObj *obj;
|
||||
GPtrArray *array;
|
||||
const DkpHistoryObj *obj;
|
||||
gboolean ret = FALSE;
|
||||
|
||||
/* get a fair chunk of data */
|
||||
|
|
@ -213,10 +212,11 @@ dkp_device_print_history (const DkpDevice *device, const gchar *type)
|
|||
/* pretty print */
|
||||
g_print (" History (%s):\n", type);
|
||||
for (i=0; i<array->len; i++) {
|
||||
obj = (DkpHistoryObj *) egg_obj_list_index (array, i);
|
||||
obj = (const DkpHistoryObj *) g_ptr_array_index (array, i);
|
||||
g_print (" %i\t%.3f\t%s\n", obj->time, obj->value, dkp_device_state_to_text (obj->state));
|
||||
}
|
||||
g_object_unref (array);
|
||||
g_ptr_array_foreach (array, (GFunc) dkp_history_obj_free, NULL);
|
||||
g_ptr_array_free (array, TRUE);
|
||||
ret = TRUE;
|
||||
out:
|
||||
return ret;
|
||||
|
|
@ -269,7 +269,7 @@ out:
|
|||
*
|
||||
* Returns an array of %DkpHistoryObj's
|
||||
**/
|
||||
EggObjList *
|
||||
GPtrArray *
|
||||
dkp_device_get_history (const DkpDevice *device, const gchar *type, guint timespec, guint resolution)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
|
@ -279,11 +279,11 @@ dkp_device_get_history (const DkpDevice *device, const gchar *type, guint timesp
|
|||
GValue *gv;
|
||||
guint i;
|
||||
DkpHistoryObj *obj;
|
||||
EggObjList *array = NULL;
|
||||
GPtrArray *array = NULL;
|
||||
gboolean ret;
|
||||
|
||||
g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
|
||||
g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
|
||||
g_return_val_if_fail (DKP_IS_DEVICE (device), NULL);
|
||||
g_return_val_if_fail (device->priv->proxy_device != NULL, NULL);
|
||||
|
||||
g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
|
||||
dbus_g_type_get_struct("GValueArray",
|
||||
|
|
@ -312,9 +312,7 @@ dkp_device_get_history (const DkpDevice *device, const gchar *type, guint timesp
|
|||
goto out;
|
||||
|
||||
/* convert */
|
||||
array = egg_obj_list_new ();
|
||||
egg_obj_list_set_copy (array, (EggObjListCopyFunc) dkp_history_obj_copy);
|
||||
egg_obj_list_set_free (array, (EggObjListFreeFunc) dkp_history_obj_free);
|
||||
array = g_ptr_array_new ();
|
||||
|
||||
for (i=0; i<gvalue_ptr_array->len; i++) {
|
||||
gva = (GValueArray *) g_ptr_array_index (gvalue_ptr_array, i);
|
||||
|
|
@ -331,8 +329,7 @@ dkp_device_get_history (const DkpDevice *device, const gchar *type, guint timesp
|
|||
gv = g_value_array_get_nth (gva, 2);
|
||||
obj->state = dkp_device_state_from_text (g_value_get_string (gv));
|
||||
g_value_unset (gv);
|
||||
egg_obj_list_add (array, obj);
|
||||
dkp_history_obj_free (obj);
|
||||
g_ptr_array_add (array, obj);
|
||||
g_value_array_free (gva);
|
||||
}
|
||||
|
||||
|
|
@ -347,7 +344,7 @@ out:
|
|||
*
|
||||
* Returns an array of %DkpStatsObj's
|
||||
**/
|
||||
EggObjList *
|
||||
GPtrArray *
|
||||
dkp_device_get_statistics (const DkpDevice *device, const gchar *type)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
|
@ -357,11 +354,11 @@ dkp_device_get_statistics (const DkpDevice *device, const gchar *type)
|
|||
GValue *gv;
|
||||
guint i;
|
||||
DkpStatsObj *obj;
|
||||
EggObjList *array = NULL;
|
||||
GPtrArray *array = NULL;
|
||||
gboolean ret;
|
||||
|
||||
g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
|
||||
g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
|
||||
g_return_val_if_fail (DKP_IS_DEVICE (device), NULL);
|
||||
g_return_val_if_fail (device->priv->proxy_device != NULL, NULL);
|
||||
|
||||
g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
|
||||
dbus_g_type_get_struct("GValueArray",
|
||||
|
|
@ -387,11 +384,7 @@ dkp_device_get_statistics (const DkpDevice *device, const gchar *type)
|
|||
goto out;
|
||||
|
||||
/* convert */
|
||||
array = egg_obj_list_new ();
|
||||
egg_obj_list_set_copy (array, (EggObjListCopyFunc) dkp_stats_obj_copy);
|
||||
egg_obj_list_set_free (array, (EggObjListFreeFunc) dkp_stats_obj_free);
|
||||
egg_obj_list_set_to_string (array, (EggObjListToStringFunc) dkp_stats_obj_to_string);
|
||||
egg_obj_list_set_from_string (array, (EggObjListFromStringFunc) dkp_stats_obj_from_string);
|
||||
array = g_ptr_array_new ();
|
||||
|
||||
for (i=0; i<gvalue_ptr_array->len; i++) {
|
||||
gva = (GValueArray *) g_ptr_array_index (gvalue_ptr_array, i);
|
||||
|
|
@ -405,8 +398,7 @@ dkp_device_get_statistics (const DkpDevice *device, const gchar *type)
|
|||
obj->accuracy = g_value_get_double (gv);
|
||||
g_value_unset (gv);
|
||||
/* 2 */
|
||||
egg_obj_list_add (array, obj);
|
||||
dkp_stats_obj_free (obj);
|
||||
g_ptr_array_add (array, obj);
|
||||
g_value_array_free (gva);
|
||||
}
|
||||
out:
|
||||
|
|
|
|||
|
|
@ -19,13 +19,16 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if !defined (__DEVICEKIT_POWER_H_INSIDE__) && !defined (DKP_COMPILATION)
|
||||
#error "Only <devicekit-power.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __DKP_DEVICE_H
|
||||
#define __DKP_DEVICE_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <dkp-enum.h>
|
||||
#include <dkp-object.h>
|
||||
#include "egg-obj-list.h"
|
||||
#include <libdevkit-power/dkp-enum.h>
|
||||
#include <libdevkit-power/dkp-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
@ -63,11 +66,11 @@ gboolean dkp_device_set_object_path (DkpDevice *device,
|
|||
|
||||
gboolean dkp_device_print (const DkpDevice *device);
|
||||
gboolean dkp_device_refresh (DkpDevice *device);
|
||||
EggObjList *dkp_device_get_history (const DkpDevice *device,
|
||||
GPtrArray *dkp_device_get_history (const DkpDevice *device,
|
||||
const gchar *type,
|
||||
guint timespec,
|
||||
guint resolution);
|
||||
EggObjList *dkp_device_get_statistics (const DkpDevice *device,
|
||||
GPtrArray *dkp_device_get_statistics (const DkpDevice *device,
|
||||
const gchar *type);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if !defined (__DEVICEKIT_POWER_H_INSIDE__) && !defined (DKP_COMPILATION)
|
||||
#error "Only <devicekit-power.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __DKP_ENUM_H__
|
||||
#define __DKP_ENUM_H__
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,15 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if !defined (__DEVICEKIT_POWER_H_INSIDE__) && !defined (DKP_COMPILATION)
|
||||
#error "Only <devicekit-power.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __DKP_HISTORY_OBJ_H__
|
||||
#define __DKP_HISTORY_OBJ_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include "dkp-enum.h"
|
||||
#include <libdevkit-power/dkp-enum.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,15 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if !defined (__DEVICEKIT_POWER_H_INSIDE__) && !defined (DKP_COMPILATION)
|
||||
#error "Only <devicekit-power.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __DKP_OBJECT_H__
|
||||
#define __DKP_OBJECT_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include "dkp-enum.h"
|
||||
#include <libdevkit-power/dkp-enum.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,15 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if !defined (__DEVICEKIT_POWER_H_INSIDE__) && !defined (DKP_COMPILATION)
|
||||
#error "Only <devicekit-power.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __DKP_QOS_OBJ_H__
|
||||
#define __DKP_QOS_OBJ_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include "dkp-enum.h"
|
||||
#include <libdevkit-power/dkp-enum.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,15 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if !defined (__DEVICEKIT_POWER_H_INSIDE__) && !defined (DKP_COMPILATION)
|
||||
#error "Only <devicekit-power.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __DKP_STATS_OBJ_H__
|
||||
#define __DKP_STATS_OBJ_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include "dkp-enum.h"
|
||||
#include <libdevkit-power/dkp-enum.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,15 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#if !defined (__DEVICEKIT_POWER_H_INSIDE__) && !defined (DKP_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 "dkp-enum.h"
|
||||
#include <libdevkit-power/dkp-enum.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -19,13 +19,17 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#if !defined (__DEVICEKIT_POWER_H_INSIDE__) && !defined (DKP_COMPILATION)
|
||||
#error "Only <devicekit-power.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __DKP_WAKEUPS_H
|
||||
#define __DKP_WAKEUPS_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <dkp-enum.h>
|
||||
#include "dkp-device.h"
|
||||
#include "dkp-wakeups-obj.h"
|
||||
#include <libdevkit-power/dkp-enum.h>
|
||||
#include <libdevkit-power/dkp-device.h>
|
||||
#include <libdevkit-power/dkp-wakeups-obj.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -1,668 +0,0 @@
|
|||
/* -*- 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "egg-debug.h"
|
||||
#include "egg-obj-list.h"
|
||||
|
||||
#define EGG_OBJ_LIST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), EGG_TYPE_OBJ_LIST, EggObjListPrivate))
|
||||
|
||||
struct EggObjListPrivate
|
||||
{
|
||||
EggObjListNewFunc func_new;
|
||||
EggObjListCopyFunc func_copy;
|
||||
EggObjListFreeFunc func_free;
|
||||
EggObjListCompareFunc func_compare;
|
||||
EggObjListToStringFunc func_to_string;
|
||||
EggObjListFromStringFunc func_from_string;
|
||||
GPtrArray *array;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (EggObjList, egg_obj_list, G_TYPE_OBJECT)
|
||||
|
||||
/**
|
||||
* egg_obj_list_set_new:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @func: typedef'd function
|
||||
*
|
||||
* Adds a creation func
|
||||
**/
|
||||
void
|
||||
egg_obj_list_set_new (EggObjList *list, EggObjListNewFunc func)
|
||||
{
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (list));
|
||||
list->priv->func_new = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_set_copy:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @func: typedef'd function
|
||||
*
|
||||
* Adds a copy func
|
||||
**/
|
||||
void
|
||||
egg_obj_list_set_copy (EggObjList *list, EggObjListCopyFunc func)
|
||||
{
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (list));
|
||||
list->priv->func_copy = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_set_free:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @func: typedef'd function
|
||||
*
|
||||
* Adds a free func
|
||||
**/
|
||||
void
|
||||
egg_obj_list_set_free (EggObjList *list, EggObjListFreeFunc func)
|
||||
{
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (list));
|
||||
list->priv->func_free = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_set_compare:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @func: typedef'd function
|
||||
*
|
||||
* Adds a compare func
|
||||
**/
|
||||
void
|
||||
egg_obj_list_set_compare (EggObjList *list, EggObjListCompareFunc func)
|
||||
{
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (list));
|
||||
list->priv->func_compare = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_set_to_string:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @func: typedef'd function
|
||||
*
|
||||
* Adds a to string func
|
||||
**/
|
||||
void
|
||||
egg_obj_list_set_to_string (EggObjList *list, EggObjListToStringFunc func)
|
||||
{
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (list));
|
||||
list->priv->func_to_string = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_set_from_string:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @func: typedef'd function
|
||||
*
|
||||
* Adds a from string func
|
||||
**/
|
||||
void
|
||||
egg_obj_list_set_from_string (EggObjList *list, EggObjListFromStringFunc func)
|
||||
{
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (list));
|
||||
list->priv->func_from_string = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_clear:
|
||||
* @list: a valid #EggObjList instance
|
||||
*
|
||||
* Clears the package list
|
||||
**/
|
||||
void
|
||||
egg_obj_list_clear (EggObjList *list)
|
||||
{
|
||||
GPtrArray *array;
|
||||
EggObjListFreeFunc func_free;
|
||||
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (list));
|
||||
|
||||
array = list->priv->array;
|
||||
func_free = list->priv->func_free;
|
||||
if (func_free != NULL)
|
||||
g_ptr_array_foreach (array, (GFunc) func_free, NULL);
|
||||
g_ptr_array_remove_range (array, 0, array->len);
|
||||
|
||||
list->len = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_print:
|
||||
* @list: a valid #EggObjList instance
|
||||
*
|
||||
* Prints the package list
|
||||
**/
|
||||
void
|
||||
egg_obj_list_print (EggObjList *list)
|
||||
{
|
||||
guint i;
|
||||
gpointer obj;
|
||||
GPtrArray *array;
|
||||
gchar *text;
|
||||
EggObjListToStringFunc func_to_string;
|
||||
|
||||
g_return_if_fail (list->priv->func_to_string != NULL);
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (list));
|
||||
|
||||
array = list->priv->array;
|
||||
func_to_string = list->priv->func_to_string;
|
||||
for (i=0; i<array->len; i++) {
|
||||
obj = g_ptr_array_index (array, i);
|
||||
text = func_to_string (obj);
|
||||
g_print ("(%i)\t%s\n", i, text);
|
||||
g_free (text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_to_string:
|
||||
* @list: a valid #EggObjList instance
|
||||
*
|
||||
* Converts the list to a newline delimited string
|
||||
**/
|
||||
gchar *
|
||||
egg_obj_list_to_string (EggObjList *list)
|
||||
{
|
||||
guint i;
|
||||
gpointer obj;
|
||||
GPtrArray *array;
|
||||
gchar *text;
|
||||
EggObjListToStringFunc func_to_string;
|
||||
GString *string;
|
||||
|
||||
g_return_val_if_fail (list->priv->func_to_string != NULL, NULL);
|
||||
g_return_val_if_fail (EGG_IS_OBJ_LIST (list), NULL);
|
||||
|
||||
array = list->priv->array;
|
||||
func_to_string = list->priv->func_to_string;
|
||||
string = g_string_new ("");
|
||||
for (i=0; i<array->len; i++) {
|
||||
obj = g_ptr_array_index (array, i);
|
||||
text = func_to_string (obj);
|
||||
g_string_append_printf (string, "%s\n", text);
|
||||
g_free (text);
|
||||
}
|
||||
/* remove trailing newline */
|
||||
if (string->len != 0)
|
||||
g_string_set_size (string, string->len-1);
|
||||
|
||||
return g_string_free (string, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_add:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @obj: a valid #gpointer object
|
||||
*
|
||||
* Adds a copy of the object to the list
|
||||
**/
|
||||
void
|
||||
egg_obj_list_add (EggObjList *list, gconstpointer obj)
|
||||
{
|
||||
gpointer obj_new;
|
||||
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (list));
|
||||
g_return_if_fail (obj != NULL);
|
||||
g_return_if_fail (list->priv->func_copy != NULL);
|
||||
|
||||
/* TODO: are we already in the list? */
|
||||
obj_new = list->priv->func_copy (obj);
|
||||
g_ptr_array_add (list->priv->array, obj_new);
|
||||
list->len = list->priv->array->len;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_add_list:
|
||||
*
|
||||
* Makes a deep copy of the list
|
||||
**/
|
||||
void
|
||||
egg_obj_list_add_list (EggObjList *list, const EggObjList *data)
|
||||
{
|
||||
guint i;
|
||||
gconstpointer obj;
|
||||
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (list));
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (data));
|
||||
|
||||
/* add data items to list */
|
||||
for (i=0; i < data->len; i++) {
|
||||
obj = egg_obj_list_index (data, i);
|
||||
egg_obj_list_add (list, obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_remove_list:
|
||||
*
|
||||
* Makes a deep copy of the list
|
||||
**/
|
||||
void
|
||||
egg_obj_list_remove_list (EggObjList *list, const EggObjList *data)
|
||||
{
|
||||
guint i;
|
||||
gconstpointer obj;
|
||||
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (list));
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (data));
|
||||
|
||||
/* remove data items from list */
|
||||
for (i=0; i < data->len; i++) {
|
||||
obj = egg_obj_list_index (data, i);
|
||||
egg_obj_list_remove (list, obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_find_obj:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @obj: a valid #gpointer object
|
||||
*
|
||||
* Return value: the object
|
||||
*
|
||||
* Removes an item from a list
|
||||
**/
|
||||
static gboolean
|
||||
egg_obj_list_obj_equal (EggObjList *list, gconstpointer obj1, gconstpointer obj2)
|
||||
{
|
||||
EggObjListCompareFunc func_compare;
|
||||
|
||||
/* two less pointer deferences... */
|
||||
func_compare = list->priv->func_compare;
|
||||
|
||||
/* trivial case */
|
||||
if (func_compare == NULL)
|
||||
return obj1 == obj2;
|
||||
|
||||
/* use helper function */
|
||||
return func_compare (obj1, obj2) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_remove_duplicate:
|
||||
*
|
||||
* Removes duplicate entries
|
||||
**/
|
||||
void
|
||||
egg_obj_list_remove_duplicate (EggObjList *list)
|
||||
{
|
||||
guint i, j;
|
||||
gconstpointer obj1;
|
||||
gconstpointer obj2;
|
||||
|
||||
for (i=0; i<list->len; i++) {
|
||||
obj1 = egg_obj_list_index (list, i);
|
||||
for (j=0; j<list->len; j++) {
|
||||
if (i == j)
|
||||
break;
|
||||
obj2 = egg_obj_list_index (list, j);
|
||||
if (egg_obj_list_obj_equal (list, obj1, obj2))
|
||||
egg_obj_list_remove_index (list, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_find_obj:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @obj: a valid #gpointer object
|
||||
*
|
||||
* Return value: the object
|
||||
*
|
||||
* Removes an item from a list
|
||||
**/
|
||||
static gpointer
|
||||
egg_obj_list_find_obj (EggObjList *list, gconstpointer obj)
|
||||
{
|
||||
guint i;
|
||||
gconstpointer obj_tmp;
|
||||
EggObjListCompareFunc func_compare;
|
||||
|
||||
/* the pointers point to the same thing */
|
||||
func_compare = list->priv->func_compare;
|
||||
if (func_compare == NULL)
|
||||
return (gpointer) obj;
|
||||
|
||||
/* remove data items from list */
|
||||
for (i=0; i < list->len; i++) {
|
||||
obj_tmp = egg_obj_list_index (list, i);
|
||||
if (func_compare (obj_tmp, obj) == 0)
|
||||
return (gpointer) obj_tmp;
|
||||
}
|
||||
|
||||
/* nothing found */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_remove:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @obj: a valid #gpointer object
|
||||
*
|
||||
* Return value: TRUE is we removed something
|
||||
*
|
||||
* Removes all the items from a list matching obj
|
||||
**/
|
||||
gboolean
|
||||
egg_obj_list_remove (EggObjList *list, gconstpointer obj)
|
||||
{
|
||||
gboolean ret;
|
||||
gpointer obj_new;
|
||||
gboolean found = FALSE;
|
||||
|
||||
g_return_val_if_fail (EGG_IS_OBJ_LIST (list), FALSE);
|
||||
g_return_val_if_fail (obj != NULL, FALSE);
|
||||
g_return_val_if_fail (list->priv->func_free != NULL, FALSE);
|
||||
|
||||
do {
|
||||
/* get the object */
|
||||
obj_new = egg_obj_list_find_obj (list, obj);
|
||||
if (obj_new == NULL)
|
||||
break;
|
||||
|
||||
/* try to remove */
|
||||
ret = g_ptr_array_remove (list->priv->array, obj_new);
|
||||
|
||||
/* no compare function, and pointer not found */
|
||||
if (!ret)
|
||||
break;
|
||||
|
||||
found = TRUE;
|
||||
list->priv->func_free (obj_new);
|
||||
list->len = list->priv->array->len;
|
||||
} while (ret);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_remove_index:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @index: the number to remove
|
||||
*
|
||||
* Return value: TRUE is we removed something
|
||||
*
|
||||
* Removes an item from a list
|
||||
**/
|
||||
gboolean
|
||||
egg_obj_list_remove_index (EggObjList *list, guint index)
|
||||
{
|
||||
gpointer obj;
|
||||
|
||||
g_return_val_if_fail (EGG_IS_OBJ_LIST (list), FALSE);
|
||||
g_return_val_if_fail (list->priv->func_free != NULL, FALSE);
|
||||
|
||||
/* get the object */
|
||||
obj = g_ptr_array_remove_index (list->priv->array, index);
|
||||
if (obj == NULL)
|
||||
return FALSE;
|
||||
list->priv->func_free (obj);
|
||||
list->len = list->priv->array->len;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_to_file:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @filename: a filename
|
||||
*
|
||||
* Saves a copy of the list to a file
|
||||
**/
|
||||
gboolean
|
||||
egg_obj_list_to_file (EggObjList *list, const gchar *filename)
|
||||
{
|
||||
guint i;
|
||||
gconstpointer obj;
|
||||
gchar *part;
|
||||
GString *string;
|
||||
gboolean ret = TRUE;
|
||||
GError *error = NULL;
|
||||
EggObjListFreeFunc func_free;
|
||||
EggObjListToStringFunc func_to_string;
|
||||
|
||||
g_return_val_if_fail (EGG_IS_OBJ_LIST (list), FALSE);
|
||||
g_return_val_if_fail (list->priv->func_to_string != NULL, FALSE);
|
||||
g_return_val_if_fail (list->priv->func_free != NULL, FALSE);
|
||||
|
||||
func_free = list->priv->func_free;
|
||||
func_to_string = list->priv->func_to_string;
|
||||
|
||||
/* generate data */
|
||||
string = g_string_new ("");
|
||||
for (i=0; i<list->len; i++) {
|
||||
obj = egg_obj_list_index (list, i);
|
||||
part = func_to_string (obj);
|
||||
if (part == NULL) {
|
||||
ret = FALSE;
|
||||
break;
|
||||
}
|
||||
g_string_append_printf (string, "%s\n", part);
|
||||
g_free (part);
|
||||
}
|
||||
part = g_string_free (string, FALSE);
|
||||
|
||||
/* we failed to convert to string */
|
||||
if (!ret) {
|
||||
egg_warning ("failed to convert");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* save to disk */
|
||||
ret = g_file_set_contents (filename, part, -1, &error);
|
||||
if (!ret) {
|
||||
egg_warning ("failed to set data: %s", error->message);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
egg_debug ("saved %s", filename);
|
||||
|
||||
out:
|
||||
g_free (part);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_from_file:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @filename: a filename
|
||||
*
|
||||
* Appends the list from a file
|
||||
**/
|
||||
gboolean
|
||||
egg_obj_list_from_file (EggObjList *list, const gchar *filename)
|
||||
{
|
||||
gboolean ret;
|
||||
GError *error = NULL;
|
||||
gchar *data = NULL;
|
||||
gchar **parts = NULL;
|
||||
guint i;
|
||||
guint length;
|
||||
gpointer obj;
|
||||
EggObjListFreeFunc func_free;
|
||||
EggObjListFromStringFunc func_from_string;
|
||||
|
||||
g_return_val_if_fail (EGG_IS_OBJ_LIST (list), FALSE);
|
||||
g_return_val_if_fail (list->priv->func_from_string != NULL, FALSE);
|
||||
g_return_val_if_fail (list->priv->func_free != NULL, FALSE);
|
||||
|
||||
func_free = list->priv->func_free;
|
||||
func_from_string = list->priv->func_from_string;
|
||||
|
||||
/* do we exist */
|
||||
ret = g_file_test (filename, G_FILE_TEST_EXISTS);
|
||||
if (!ret) {
|
||||
egg_debug ("failed to get data from %s as file does not exist", filename);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* get contents */
|
||||
ret = g_file_get_contents (filename, &data, NULL, &error);
|
||||
if (!ret) {
|
||||
egg_warning ("failed to get data: %s", error->message);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* split by line ending */
|
||||
parts = g_strsplit (data, "\n", 0);
|
||||
length = g_strv_length (parts);
|
||||
if (length == 0) {
|
||||
egg_debug ("no data in %s", filename);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* add valid entries */
|
||||
egg_debug ("loading %i items of data from %s", length, filename);
|
||||
for (i=0; i<length-1; i++) {
|
||||
obj = func_from_string (parts[i]);
|
||||
if (obj != NULL)
|
||||
egg_obj_list_add (list, obj);
|
||||
func_free (obj);
|
||||
}
|
||||
|
||||
out:
|
||||
g_strfreev (parts);
|
||||
g_free (data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_index:
|
||||
* @list: a valid #EggObjList instance
|
||||
* @index: the element to return
|
||||
*
|
||||
* Gets an object from the list
|
||||
**/
|
||||
gconstpointer
|
||||
egg_obj_list_index (const EggObjList *list, guint index)
|
||||
{
|
||||
gconstpointer obj;
|
||||
|
||||
g_return_val_if_fail (EGG_IS_OBJ_LIST (list), NULL);
|
||||
|
||||
obj = g_ptr_array_index (list->priv->array, index);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_finalize:
|
||||
* @object: a valid #EggObjList instance
|
||||
**/
|
||||
static void
|
||||
egg_obj_list_finalize (GObject *object)
|
||||
{
|
||||
EggObjListFreeFunc func_free;
|
||||
gpointer obj;
|
||||
guint i;
|
||||
EggObjList *list;
|
||||
GPtrArray *array;
|
||||
g_return_if_fail (EGG_IS_OBJ_LIST (object));
|
||||
list = EGG_OBJ_LIST (object);
|
||||
|
||||
array = list->priv->array;
|
||||
func_free = list->priv->func_free;
|
||||
for (i=0; i<array->len; i++) {
|
||||
obj = g_ptr_array_index (array, i);
|
||||
if (func_free != NULL)
|
||||
func_free (obj);
|
||||
}
|
||||
g_ptr_array_free (array, TRUE);
|
||||
|
||||
G_OBJECT_CLASS (egg_obj_list_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_class_init:
|
||||
* @klass: a valid #EggObjListClass instance
|
||||
**/
|
||||
static void
|
||||
egg_obj_list_class_init (EggObjListClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
object_class->finalize = egg_obj_list_finalize;
|
||||
g_type_class_add_private (klass, sizeof (EggObjListPrivate));
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_init:
|
||||
* @list: a valid #EggObjList instance
|
||||
*
|
||||
* Initializes the obj_list class.
|
||||
**/
|
||||
static void
|
||||
egg_obj_list_init (EggObjList *list)
|
||||
{
|
||||
list->priv = EGG_OBJ_LIST_GET_PRIVATE (list);
|
||||
list->priv->func_new = NULL;
|
||||
list->priv->func_copy = NULL;
|
||||
list->priv->func_free = NULL;
|
||||
list->priv->func_compare = NULL;
|
||||
list->priv->func_to_string = NULL;
|
||||
list->priv->func_from_string = NULL;
|
||||
list->priv->array = g_ptr_array_new ();
|
||||
list->len = list->priv->array->len;
|
||||
}
|
||||
|
||||
/**
|
||||
* egg_obj_list_new:
|
||||
*
|
||||
* Return value: A new list class instance.
|
||||
**/
|
||||
EggObjList *
|
||||
egg_obj_list_new (void)
|
||||
{
|
||||
EggObjList *list;
|
||||
list = g_object_new (EGG_TYPE_OBJ_LIST, NULL);
|
||||
return EGG_OBJ_LIST (list);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
*** MAKE CHECK TESTS ***
|
||||
***************************************************************************/
|
||||
#ifdef EGG_TEST
|
||||
#include "egg-test.h"
|
||||
|
||||
void
|
||||
egg_obj_list_test (EggTest *test)
|
||||
{
|
||||
EggObjList *list;
|
||||
|
||||
if (!egg_test_start (test, "EggObjList"))
|
||||
return;
|
||||
|
||||
/************************************************************/
|
||||
egg_test_title (test, "get an instance");
|
||||
list = egg_obj_list_new ();
|
||||
egg_test_assert (test, list != NULL);
|
||||
|
||||
g_object_unref (list);
|
||||
|
||||
egg_test_end (test);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef __EGG_OBJ_LIST_H
|
||||
#define __EGG_OBJ_LIST_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define EGG_TYPE_OBJ_LIST (egg_obj_list_get_type ())
|
||||
#define EGG_OBJ_LIST(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EGG_TYPE_OBJ_LIST, EggObjList))
|
||||
#define EGG_OBJ_LIST_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EGG_TYPE_OBJ_LIST, EggObjListClass))
|
||||
#define EGG_IS_OBJ_LIST(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EGG_TYPE_OBJ_LIST))
|
||||
#define EGG_IS_OBJ_LIST_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EGG_TYPE_OBJ_LIST))
|
||||
#define EGG_OBJ_LIST_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EGG_TYPE_OBJ_LIST, EggObjListClass))
|
||||
|
||||
typedef struct EggObjListPrivate EggObjListPrivate;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObject parent;
|
||||
EggObjListPrivate *priv;
|
||||
guint len;
|
||||
} EggObjList;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
} EggObjListClass;
|
||||
|
||||
typedef gpointer (*EggObjListNewFunc) (void);
|
||||
typedef gpointer (*EggObjListCopyFunc) (gconstpointer data);
|
||||
typedef void (*EggObjListFreeFunc) (gpointer data);
|
||||
typedef gint (*EggObjListCompareFunc) (gconstpointer data1,
|
||||
gconstpointer data2);
|
||||
typedef gpointer (*EggObjListFromStringFunc) (const gchar *data);
|
||||
typedef gchar *(*EggObjListToStringFunc) (gconstpointer data);
|
||||
|
||||
GType egg_obj_list_get_type (void);
|
||||
EggObjList *egg_obj_list_new (void);
|
||||
|
||||
void egg_obj_list_set_new (EggObjList *list,
|
||||
EggObjListNewFunc func);
|
||||
void egg_obj_list_set_copy (EggObjList *list,
|
||||
EggObjListCopyFunc func);
|
||||
void egg_obj_list_set_free (EggObjList *list,
|
||||
EggObjListFreeFunc func);
|
||||
void egg_obj_list_set_compare (EggObjList *list,
|
||||
EggObjListCompareFunc func);
|
||||
void egg_obj_list_set_to_string (EggObjList *list,
|
||||
EggObjListToStringFunc func);
|
||||
void egg_obj_list_set_from_string (EggObjList *list,
|
||||
EggObjListFromStringFunc func);
|
||||
void egg_obj_list_clear (EggObjList *list);
|
||||
void egg_obj_list_print (EggObjList *list);
|
||||
gchar *egg_obj_list_to_string (EggObjList *list)
|
||||
G_GNUC_WARN_UNUSED_RESULT;
|
||||
gboolean egg_obj_list_to_file (EggObjList *list,
|
||||
const gchar *filename);
|
||||
gboolean egg_obj_list_from_file (EggObjList *list,
|
||||
const gchar *filename);
|
||||
void egg_obj_list_add (EggObjList *list,
|
||||
gconstpointer data);
|
||||
void egg_obj_list_add_list (EggObjList *list,
|
||||
const EggObjList *data);
|
||||
void egg_obj_list_remove_list (EggObjList *list,
|
||||
const EggObjList *data);
|
||||
void egg_obj_list_remove_duplicate (EggObjList *list);
|
||||
gboolean egg_obj_list_remove (EggObjList *list,
|
||||
gconstpointer data);
|
||||
gboolean egg_obj_list_remove_index (EggObjList *list,
|
||||
guint index);
|
||||
gconstpointer egg_obj_list_index (const EggObjList *list,
|
||||
guint index);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __EGG_OBJ_LIST_H */
|
||||
|
|
@ -10,6 +10,7 @@ INCLUDES = \
|
|||
-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
|
||||
-DPACKAGE_LIB_DIR=\""$(libdir)"\" \
|
||||
-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT \
|
||||
-DDKP_COMPILATION \
|
||||
-DEGG_LOG_FILE=\""$(DKP_LOG_DIR)/DeviceKit-power"\" \
|
||||
-DEGG_VERBOSE="\"DKP_VERBOSE\"" \
|
||||
-DEGG_LOGGING="\"DKP_LOGGING\"" \
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ gboolean
|
|||
dkp_device_get_statistics (DkpDevice *device, const gchar *type, DBusGMethodInvocation *context)
|
||||
{
|
||||
GError *error;
|
||||
EggObjList *array = NULL;
|
||||
GPtrArray *array = NULL;
|
||||
GPtrArray *complex;
|
||||
const DkpStatsObj *obj;
|
||||
GValue *value;
|
||||
|
|
@ -376,7 +376,7 @@ dkp_device_get_statistics (DkpDevice *device, const gchar *type, DBusGMethodInvo
|
|||
/* copy data to dbus struct */
|
||||
complex = g_ptr_array_sized_new (array->len);
|
||||
for (i=0; i<array->len; i++) {
|
||||
obj = (const DkpStatsObj *) egg_obj_list_index (array, i);
|
||||
obj = (const DkpStatsObj *) g_ptr_array_index (array, i);
|
||||
value = g_new0 (GValue, 1);
|
||||
g_value_init (value, DKP_DBUS_STRUCT_DOUBLE_DOUBLE);
|
||||
g_value_take_boxed (value, dbus_g_type_specialized_construct (DKP_DBUS_STRUCT_DOUBLE_DOUBLE));
|
||||
|
|
@ -387,8 +387,10 @@ dkp_device_get_statistics (DkpDevice *device, const gchar *type, DBusGMethodInvo
|
|||
|
||||
dbus_g_method_return (context, complex);
|
||||
out:
|
||||
if (array != NULL)
|
||||
g_object_unref (array);
|
||||
if (array != NULL) {
|
||||
g_ptr_array_foreach (array, (GFunc) dkp_stats_obj_free, NULL);
|
||||
g_ptr_array_free (array, TRUE);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -399,7 +401,7 @@ gboolean
|
|||
dkp_device_get_history (DkpDevice *device, const gchar *type_string, guint timespan, guint resolution, DBusGMethodInvocation *context)
|
||||
{
|
||||
GError *error;
|
||||
EggObjList *array = NULL;
|
||||
GPtrArray *array = NULL;
|
||||
GPtrArray *complex;
|
||||
const DkpHistoryObj *obj;
|
||||
GValue *value;
|
||||
|
|
@ -440,7 +442,7 @@ dkp_device_get_history (DkpDevice *device, const gchar *type_string, guint times
|
|||
/* copy data to dbus struct */
|
||||
complex = g_ptr_array_sized_new (array->len);
|
||||
for (i=0; i<array->len; i++) {
|
||||
obj = (const DkpHistoryObj *) egg_obj_list_index (array, i);
|
||||
obj = (const DkpHistoryObj *) g_ptr_array_index (array, i);
|
||||
value = g_new0 (GValue, 1);
|
||||
g_value_init (value, DKP_DBUS_STRUCT_UINT_DOUBLE_STRING);
|
||||
g_value_take_boxed (value, dbus_g_type_specialized_construct (DKP_DBUS_STRUCT_UINT_DOUBLE_STRING));
|
||||
|
|
@ -451,8 +453,10 @@ dkp_device_get_history (DkpDevice *device, const gchar *type_string, guint times
|
|||
|
||||
dbus_g_method_return (context, complex);
|
||||
out:
|
||||
if (array != NULL)
|
||||
g_object_unref (array);
|
||||
if (array != NULL) {
|
||||
g_ptr_array_foreach (array, (GFunc) dkp_history_obj_free, NULL);
|
||||
g_ptr_array_free (array, TRUE);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,10 +48,10 @@ struct DkpHistoryPrivate
|
|||
gint64 time_empty_last;
|
||||
gdouble percentage_last;
|
||||
DkpDeviceState state;
|
||||
EggObjList *data_rate;
|
||||
EggObjList *data_charge;
|
||||
EggObjList *data_time_full;
|
||||
EggObjList *data_time_empty;
|
||||
GPtrArray *data_rate;
|
||||
GPtrArray *data_charge;
|
||||
GPtrArray *data_time_full;
|
||||
GPtrArray *data_time_empty;
|
||||
guint save_id;
|
||||
};
|
||||
|
||||
|
|
@ -63,38 +63,6 @@ enum {
|
|||
G_DEFINE_TYPE (DkpHistory, dkp_history, G_TYPE_OBJECT)
|
||||
#define DKP_HISTORY_FILE_HEADER "PackageKit Profile"
|
||||
|
||||
/**
|
||||
* dkp_history_get_history_list:
|
||||
**/
|
||||
static EggObjList *
|
||||
dkp_history_new_history_list (void)
|
||||
{
|
||||
EggObjList *list;
|
||||
list = egg_obj_list_new ();
|
||||
egg_obj_list_set_new (list, (EggObjListNewFunc) dkp_history_obj_new);
|
||||
egg_obj_list_set_copy (list, (EggObjListCopyFunc) dkp_history_obj_copy);
|
||||
egg_obj_list_set_free (list, (EggObjListFreeFunc) dkp_history_obj_free);
|
||||
egg_obj_list_set_to_string (list, (EggObjListToStringFunc) dkp_history_obj_to_string);
|
||||
egg_obj_list_set_from_string (list, (EggObjListFromStringFunc) dkp_history_obj_from_string);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_history_get_stats_list:
|
||||
**/
|
||||
static EggObjList *
|
||||
dkp_history_new_stats_list (void)
|
||||
{
|
||||
EggObjList *list;
|
||||
list = egg_obj_list_new ();
|
||||
egg_obj_list_set_new (list, (EggObjListNewFunc) dkp_stats_obj_new);
|
||||
egg_obj_list_set_copy (list, (EggObjListCopyFunc) dkp_stats_obj_copy);
|
||||
egg_obj_list_set_free (list, (EggObjListFreeFunc) dkp_stats_obj_free);
|
||||
egg_obj_list_set_to_string (list, (EggObjListToStringFunc) dkp_stats_obj_to_string);
|
||||
egg_obj_list_set_from_string (list, (EggObjListFromStringFunc) dkp_stats_obj_from_string);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_history_array_limit_resolution:
|
||||
* @array: The data we have for a specific graph
|
||||
|
|
@ -128,8 +96,8 @@ dkp_history_new_stats_list (void)
|
|||
* 2 = 41,70
|
||||
* 3 = 85,30
|
||||
**/
|
||||
static EggObjList *
|
||||
dkp_history_array_limit_resolution (EggObjList *array, guint max_num)
|
||||
static GPtrArray *
|
||||
dkp_history_array_limit_resolution (GPtrArray *array, guint max_num)
|
||||
{
|
||||
const DkpHistoryObj *obj;
|
||||
DkpHistoryObj *nobj;
|
||||
|
|
@ -138,7 +106,7 @@ dkp_history_array_limit_resolution (EggObjList *array, guint max_num)
|
|||
gint i;
|
||||
guint last;
|
||||
guint first;
|
||||
EggObjList *new;
|
||||
GPtrArray *new;
|
||||
DkpDeviceState state = DKP_DEVICE_STATE_UNKNOWN;
|
||||
guint64 time = 0;
|
||||
gdouble value = 0;
|
||||
|
|
@ -153,14 +121,13 @@ dkp_history_array_limit_resolution (EggObjList *array, guint max_num)
|
|||
goto out;
|
||||
}
|
||||
|
||||
new = dkp_history_new_stats_list ();
|
||||
nobj = dkp_history_obj_new ();
|
||||
new = g_ptr_array_new ();
|
||||
egg_debug ("length of array (before) %i", array->len);
|
||||
|
||||
/* last element */
|
||||
obj = (const DkpHistoryObj *) egg_obj_list_index (array, length-1);
|
||||
obj = (const DkpHistoryObj *) g_ptr_array_index (array, length-1);
|
||||
last = obj->time;
|
||||
obj = (const DkpHistoryObj *) egg_obj_list_index (array, 0);
|
||||
obj = (const DkpHistoryObj *) g_ptr_array_index (array, 0);
|
||||
first = obj->time;
|
||||
|
||||
div = (first - last) / (gfloat) max_num;
|
||||
|
|
@ -170,15 +137,16 @@ dkp_history_array_limit_resolution (EggObjList *array, guint max_num)
|
|||
* division algorithm so we don't keep diluting the previous
|
||||
* data with a conventional 1-in-x type algorithm. */
|
||||
for (i=length-1; i>=0; i--) {
|
||||
obj = (const DkpHistoryObj *) egg_obj_list_index (array, i);
|
||||
obj = (const DkpHistoryObj *) g_ptr_array_index (array, i);
|
||||
preset = last + (div * (gfloat) step);
|
||||
|
||||
/* if state changed or we went over the preset do a new point */
|
||||
if (count > 0 && (obj->time > preset || obj->state != state)) {
|
||||
nobj = dkp_history_obj_new ();
|
||||
nobj->time = time / count;
|
||||
nobj->value = value / count;
|
||||
nobj->state = state;
|
||||
egg_obj_list_add (new, nobj);
|
||||
g_ptr_array_add (new, nobj);
|
||||
|
||||
step++;
|
||||
time = obj->time;
|
||||
|
|
@ -192,14 +160,14 @@ dkp_history_array_limit_resolution (EggObjList *array, guint max_num)
|
|||
}
|
||||
}
|
||||
|
||||
nobj = dkp_history_obj_new ();
|
||||
nobj->time = time / count;
|
||||
nobj->value = value / count;
|
||||
nobj->state = state;
|
||||
egg_obj_list_add (new, nobj);
|
||||
g_ptr_array_add (new, nobj);
|
||||
|
||||
/* check length */
|
||||
egg_debug ("length of array (after) %i", new->len);
|
||||
dkp_history_obj_free (nobj);
|
||||
out:
|
||||
return new;
|
||||
}
|
||||
|
|
@ -207,12 +175,12 @@ out:
|
|||
/**
|
||||
* dkp_history_copy_array_timespan:
|
||||
**/
|
||||
static EggObjList *
|
||||
dkp_history_copy_array_timespan (const EggObjList *array, guint timespan)
|
||||
static GPtrArray *
|
||||
dkp_history_copy_array_timespan (const GPtrArray *array, guint timespan)
|
||||
{
|
||||
guint i;
|
||||
const DkpHistoryObj *obj;
|
||||
EggObjList *array_new;
|
||||
GPtrArray *array_new;
|
||||
guint start;
|
||||
|
||||
/* no data */
|
||||
|
|
@ -220,16 +188,16 @@ dkp_history_copy_array_timespan (const EggObjList *array, guint timespan)
|
|||
return NULL;
|
||||
|
||||
/* new data */
|
||||
array_new = dkp_history_new_history_list ();
|
||||
array_new = g_ptr_array_new ();
|
||||
|
||||
/* treat the timespan like a range, and search backwards */
|
||||
obj = (const DkpHistoryObj *) egg_obj_list_index (array, array->len-1);
|
||||
obj = (const DkpHistoryObj *) g_ptr_array_index (array, array->len-1);
|
||||
start = obj->time;
|
||||
timespan *= 0.95f;
|
||||
for (i=array->len-1; i>0; i--) {
|
||||
obj = (const DkpHistoryObj *) egg_obj_list_index (array, i);
|
||||
obj = (const DkpHistoryObj *) g_ptr_array_index (array, i);
|
||||
if (start - obj->time < timespan)
|
||||
egg_obj_list_add (array_new, (const gpointer) obj);
|
||||
g_ptr_array_add (array_new, dkp_history_obj_copy (obj));
|
||||
}
|
||||
|
||||
return array_new;
|
||||
|
|
@ -238,12 +206,12 @@ dkp_history_copy_array_timespan (const EggObjList *array, guint timespan)
|
|||
/**
|
||||
* dkp_history_get_data:
|
||||
**/
|
||||
EggObjList *
|
||||
GPtrArray *
|
||||
dkp_history_get_data (DkpHistory *history, DkpHistoryType type, guint timespan, guint resolution)
|
||||
{
|
||||
EggObjList *array;
|
||||
EggObjList *array_resolution;
|
||||
const EggObjList *array_data = NULL;
|
||||
GPtrArray *array;
|
||||
GPtrArray *array_resolution;
|
||||
const GPtrArray *array_data = NULL;
|
||||
|
||||
g_return_val_if_fail (DKP_IS_HISTORY (history), NULL);
|
||||
|
||||
|
|
@ -270,7 +238,8 @@ dkp_history_get_data (DkpHistory *history, DkpHistoryType type, guint timespan,
|
|||
|
||||
/* only add a certain number of points */
|
||||
array_resolution = dkp_history_array_limit_resolution (array, resolution);
|
||||
g_object_unref (array);
|
||||
g_ptr_array_foreach (array, (GFunc) dkp_history_obj_free, NULL);
|
||||
g_ptr_array_free (array, TRUE);
|
||||
|
||||
return array_resolution;
|
||||
}
|
||||
|
|
@ -278,7 +247,7 @@ dkp_history_get_data (DkpHistory *history, DkpHistoryType type, guint timespan,
|
|||
/**
|
||||
* dkp_history_get_profile_data:
|
||||
**/
|
||||
EggObjList *
|
||||
GPtrArray *
|
||||
dkp_history_get_profile_data (DkpHistory *history, gboolean charging)
|
||||
{
|
||||
guint i;
|
||||
|
|
@ -290,8 +259,8 @@ dkp_history_get_profile_data (DkpHistory *history, gboolean charging)
|
|||
const DkpHistoryObj *obj;
|
||||
const DkpHistoryObj *obj_old = NULL;
|
||||
DkpStatsObj *stats;
|
||||
EggObjList *array;
|
||||
EggObjList *data;
|
||||
GPtrArray *array;
|
||||
GPtrArray *data;
|
||||
guint time;
|
||||
gdouble value;
|
||||
gdouble total_value = 0.0f;
|
||||
|
|
@ -299,16 +268,15 @@ dkp_history_get_profile_data (DkpHistory *history, gboolean charging)
|
|||
g_return_val_if_fail (DKP_IS_HISTORY (history), NULL);
|
||||
|
||||
/* create 100 item list and set to zero */
|
||||
data = dkp_history_new_stats_list ();
|
||||
data = g_ptr_array_new ();
|
||||
for (i=0; i<101; i++) {
|
||||
stats = dkp_stats_obj_create (0.0f, 0.0f);
|
||||
egg_obj_list_add (data, stats);
|
||||
dkp_stats_obj_free (stats);
|
||||
g_ptr_array_add (data, stats);
|
||||
}
|
||||
|
||||
array = history->priv->data_charge;
|
||||
for (i=0; i<array->len; i++) {
|
||||
obj = (const DkpHistoryObj *) egg_obj_list_index (array, i);
|
||||
obj = (const DkpHistoryObj *) g_ptr_array_index (array, i);
|
||||
if (obj_last == NULL || obj->state != obj_last->state) {
|
||||
obj_old = NULL;
|
||||
goto cont;
|
||||
|
|
@ -334,7 +302,7 @@ dkp_history_get_profile_data (DkpHistory *history, gboolean charging)
|
|||
/* use the accuracy field as a counter for now */
|
||||
if ((charging && obj->state == DKP_DEVICE_STATE_CHARGING) ||
|
||||
(!charging && obj->state == DKP_DEVICE_STATE_DISCHARGING)) {
|
||||
stats = (DkpStatsObj *) egg_obj_list_index (data, bin);
|
||||
stats = (DkpStatsObj *) g_ptr_array_index (data, bin);
|
||||
stats->value += time;
|
||||
stats->accuracy++;
|
||||
}
|
||||
|
|
@ -347,14 +315,14 @@ cont:
|
|||
|
||||
/* divide the value by the number of samples to make the average */
|
||||
for (i=0; i<101; i++) {
|
||||
stats = (DkpStatsObj *) egg_obj_list_index (data, i);
|
||||
stats = (DkpStatsObj *) g_ptr_array_index (data, i);
|
||||
if (stats->accuracy != 0)
|
||||
stats->value = stats->value / stats->accuracy;
|
||||
}
|
||||
|
||||
/* find non-zero accuracy values for the average */
|
||||
for (i=0; i<101; i++) {
|
||||
stats = (DkpStatsObj *) egg_obj_list_index (data, i);
|
||||
stats = (DkpStatsObj *) g_ptr_array_index (data, i);
|
||||
if (stats->accuracy > 0) {
|
||||
total_value += stats->value;
|
||||
non_zero_accuracy++;
|
||||
|
|
@ -369,7 +337,7 @@ cont:
|
|||
/* make the values a factor of 0, so that 1.0 is twice the
|
||||
* average, and -1.0 is half the average */
|
||||
for (i=0; i<101; i++) {
|
||||
stats = (DkpStatsObj *) egg_obj_list_index (data, i);
|
||||
stats = (DkpStatsObj *) g_ptr_array_index (data, i);
|
||||
if (stats->accuracy > 0)
|
||||
stats->value = (stats->value - average) / average;
|
||||
else
|
||||
|
|
@ -378,7 +346,7 @@ cont:
|
|||
|
||||
/* accuracy is a percentage scale, where each cycle = 20% */
|
||||
for (i=0; i<101; i++) {
|
||||
stats = (DkpStatsObj *) egg_obj_list_index (data, i);
|
||||
stats = (DkpStatsObj *) g_ptr_array_index (data, i);
|
||||
stats->accuracy *= 20;
|
||||
if (stats->accuracy > 100.0f)
|
||||
stats->accuracy = 100.0f;
|
||||
|
|
@ -402,6 +370,112 @@ dkp_history_get_filename (DkpHistory *history, const gchar *type)
|
|||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_history_array_to_file:
|
||||
* @list: a valid #GPtrArray instance
|
||||
* @filename: a filename
|
||||
*
|
||||
* Saves a copy of the list to a file
|
||||
**/
|
||||
static gboolean
|
||||
dkp_history_array_to_file (GPtrArray *list, const gchar *filename)
|
||||
{
|
||||
guint i;
|
||||
const DkpHistoryObj *obj;
|
||||
gchar *part;
|
||||
GString *string;
|
||||
gboolean ret = TRUE;
|
||||
GError *error = NULL;
|
||||
|
||||
/* generate data */
|
||||
string = g_string_new ("");
|
||||
for (i=0; i<list->len; i++) {
|
||||
obj = g_ptr_array_index (list, i);
|
||||
part = dkp_history_obj_to_string (obj);
|
||||
if (part == NULL) {
|
||||
ret = FALSE;
|
||||
break;
|
||||
}
|
||||
g_string_append_printf (string, "%s\n", part);
|
||||
g_free (part);
|
||||
}
|
||||
part = g_string_free (string, FALSE);
|
||||
|
||||
/* we failed to convert to string */
|
||||
if (!ret) {
|
||||
egg_warning ("failed to convert");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* save to disk */
|
||||
ret = g_file_set_contents (filename, part, -1, &error);
|
||||
if (!ret) {
|
||||
egg_warning ("failed to set data: %s", error->message);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
egg_debug ("saved %s", filename);
|
||||
|
||||
out:
|
||||
g_free (part);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_history_array_from_file:
|
||||
* @list: a valid #GPtrArray instance
|
||||
* @filename: a filename
|
||||
*
|
||||
* Appends the list from a file
|
||||
**/
|
||||
static gboolean
|
||||
dkp_history_array_from_file (GPtrArray *list, const gchar *filename)
|
||||
{
|
||||
gboolean ret;
|
||||
GError *error = NULL;
|
||||
gchar *data = NULL;
|
||||
gchar **parts = NULL;
|
||||
guint i;
|
||||
guint length;
|
||||
DkpHistoryObj *obj;
|
||||
|
||||
/* do we exist */
|
||||
ret = g_file_test (filename, G_FILE_TEST_EXISTS);
|
||||
if (!ret) {
|
||||
egg_debug ("failed to get data from %s as file does not exist", filename);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* get contents */
|
||||
ret = g_file_get_contents (filename, &data, NULL, &error);
|
||||
if (!ret) {
|
||||
egg_warning ("failed to get data: %s", error->message);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* split by line ending */
|
||||
parts = g_strsplit (data, "\n", 0);
|
||||
length = g_strv_length (parts);
|
||||
if (length == 0) {
|
||||
egg_debug ("no data in %s", filename);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* add valid entries */
|
||||
egg_debug ("loading %i items of data from %s", length, filename);
|
||||
for (i=0; i<length-1; i++) {
|
||||
obj = dkp_history_obj_from_string (parts[i]);
|
||||
if (obj != NULL)
|
||||
g_ptr_array_add (list, obj);
|
||||
}
|
||||
|
||||
out:
|
||||
g_strfreev (parts);
|
||||
g_free (data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_history_save_data:
|
||||
**/
|
||||
|
|
@ -418,22 +492,22 @@ dkp_history_save_data (DkpHistory *history)
|
|||
|
||||
/* save rate history to disk */
|
||||
filename = dkp_history_get_filename (history, "rate");
|
||||
egg_obj_list_to_file (history->priv->data_rate, filename);
|
||||
dkp_history_array_to_file (history->priv->data_rate, filename);
|
||||
g_free (filename);
|
||||
|
||||
/* save charge history to disk */
|
||||
filename = dkp_history_get_filename (history, "charge");
|
||||
egg_obj_list_to_file (history->priv->data_charge, filename);
|
||||
dkp_history_array_to_file (history->priv->data_charge, filename);
|
||||
g_free (filename);
|
||||
|
||||
/* save charge history to disk */
|
||||
filename = dkp_history_get_filename (history, "time-full");
|
||||
egg_obj_list_to_file (history->priv->data_time_full, filename);
|
||||
dkp_history_array_to_file (history->priv->data_time_full, filename);
|
||||
g_free (filename);
|
||||
|
||||
/* save charge history to disk */
|
||||
filename = dkp_history_get_filename (history, "time-empty");
|
||||
egg_obj_list_to_file (history->priv->data_time_empty, filename);
|
||||
dkp_history_array_to_file (history->priv->data_time_empty, filename);
|
||||
g_free (filename);
|
||||
|
||||
return TRUE;
|
||||
|
|
@ -469,7 +543,7 @@ dkp_history_is_low_power (DkpHistory *history)
|
|||
return FALSE;
|
||||
|
||||
/* get the last saved charge object */
|
||||
obj = (const DkpHistoryObj *) egg_obj_list_index (history->priv->data_charge, length-1);
|
||||
obj = (const DkpHistoryObj *) g_ptr_array_index (history->priv->data_charge, length-1);
|
||||
if (obj->state != DKP_DEVICE_STATE_DISCHARGING)
|
||||
return FALSE;
|
||||
|
||||
|
|
@ -522,30 +596,30 @@ dkp_history_load_data (DkpHistory *history)
|
|||
|
||||
/* load rate history from disk */
|
||||
filename = dkp_history_get_filename (history, "rate");
|
||||
egg_obj_list_from_file (history->priv->data_rate, filename);
|
||||
dkp_history_array_from_file (history->priv->data_rate, filename);
|
||||
g_free (filename);
|
||||
|
||||
/* load charge history from disk */
|
||||
filename = dkp_history_get_filename (history, "charge");
|
||||
egg_obj_list_from_file (history->priv->data_charge, filename);
|
||||
dkp_history_array_from_file (history->priv->data_charge, filename);
|
||||
g_free (filename);
|
||||
|
||||
/* load charge history from disk */
|
||||
filename = dkp_history_get_filename (history, "time-full");
|
||||
egg_obj_list_from_file (history->priv->data_time_full, filename);
|
||||
dkp_history_array_from_file (history->priv->data_time_full, filename);
|
||||
g_free (filename);
|
||||
|
||||
/* load charge history from disk */
|
||||
filename = dkp_history_get_filename (history, "time-empty");
|
||||
egg_obj_list_from_file (history->priv->data_time_empty, filename);
|
||||
dkp_history_array_from_file (history->priv->data_time_empty, filename);
|
||||
g_free (filename);
|
||||
|
||||
/* save a marker so we don't use incomplete percentages */
|
||||
obj = dkp_history_obj_create (0, DKP_DEVICE_STATE_UNKNOWN);
|
||||
egg_obj_list_add (history->priv->data_rate, obj);
|
||||
egg_obj_list_add (history->priv->data_charge, obj);
|
||||
egg_obj_list_add (history->priv->data_time_full, obj);
|
||||
egg_obj_list_add (history->priv->data_time_empty, obj);
|
||||
g_ptr_array_add (history->priv->data_rate, dkp_history_obj_copy (obj));
|
||||
g_ptr_array_add (history->priv->data_charge, dkp_history_obj_copy (obj));
|
||||
g_ptr_array_add (history->priv->data_time_full, dkp_history_obj_copy (obj));
|
||||
g_ptr_array_add (history->priv->data_time_empty, dkp_history_obj_copy (obj));
|
||||
dkp_history_obj_free (obj);
|
||||
dkp_history_schedule_save (history);
|
||||
|
||||
|
|
@ -607,8 +681,7 @@ dkp_history_set_charge_data (DkpHistory *history, gdouble percentage)
|
|||
|
||||
/* add to array and schedule save file */
|
||||
obj = dkp_history_obj_create (percentage, history->priv->state);
|
||||
egg_obj_list_add (history->priv->data_charge, obj);
|
||||
dkp_history_obj_free (obj);
|
||||
g_ptr_array_add (history->priv->data_charge, obj);
|
||||
dkp_history_schedule_save (history);
|
||||
|
||||
/* save last value */
|
||||
|
|
@ -636,8 +709,7 @@ dkp_history_set_rate_data (DkpHistory *history, gdouble rate)
|
|||
|
||||
/* add to array and schedule save file */
|
||||
obj = dkp_history_obj_create (rate, history->priv->state);
|
||||
egg_obj_list_add (history->priv->data_rate, obj);
|
||||
dkp_history_obj_free (obj);
|
||||
g_ptr_array_add (history->priv->data_rate, obj);
|
||||
dkp_history_schedule_save (history);
|
||||
|
||||
/* save last value */
|
||||
|
|
@ -667,8 +739,7 @@ dkp_history_set_time_full_data (DkpHistory *history, gint64 time)
|
|||
|
||||
/* add to array and schedule save file */
|
||||
obj = dkp_history_obj_create ((gdouble) time, history->priv->state);
|
||||
egg_obj_list_add (history->priv->data_time_full, obj);
|
||||
dkp_history_obj_free (obj);
|
||||
g_ptr_array_add (history->priv->data_time_full, obj);
|
||||
dkp_history_schedule_save (history);
|
||||
|
||||
/* save last value */
|
||||
|
|
@ -698,8 +769,7 @@ dkp_history_set_time_empty_data (DkpHistory *history, gint64 time)
|
|||
|
||||
/* add to array and schedule save file */
|
||||
obj = dkp_history_obj_create ((gdouble) time, history->priv->state);
|
||||
egg_obj_list_add (history->priv->data_time_empty, obj);
|
||||
dkp_history_obj_free (obj);
|
||||
g_ptr_array_add (history->priv->data_time_empty, obj);
|
||||
dkp_history_schedule_save (history);
|
||||
|
||||
/* save last value */
|
||||
|
|
@ -732,10 +802,10 @@ dkp_history_init (DkpHistory *history)
|
|||
history->priv->rate_last = 0;
|
||||
history->priv->percentage_last = 0;
|
||||
history->priv->state = DKP_DEVICE_STATE_UNKNOWN;
|
||||
history->priv->data_rate = dkp_history_new_history_list ();
|
||||
history->priv->data_charge = dkp_history_new_history_list ();
|
||||
history->priv->data_time_full = dkp_history_new_history_list ();
|
||||
history->priv->data_time_empty = dkp_history_new_history_list ();
|
||||
history->priv->data_rate = g_ptr_array_new ();
|
||||
history->priv->data_charge = g_ptr_array_new ();
|
||||
history->priv->data_time_full = g_ptr_array_new ();
|
||||
history->priv->data_time_empty = g_ptr_array_new ();
|
||||
history->priv->save_id = 0;
|
||||
}
|
||||
|
||||
|
|
@ -757,10 +827,16 @@ dkp_history_finalize (GObject *object)
|
|||
g_source_remove (history->priv->save_id);
|
||||
if (history->priv->id != NULL)
|
||||
dkp_history_save_data (history);
|
||||
g_object_unref (history->priv->data_rate);
|
||||
g_object_unref (history->priv->data_charge);
|
||||
g_object_unref (history->priv->data_time_full);
|
||||
g_object_unref (history->priv->data_time_empty);
|
||||
|
||||
g_ptr_array_foreach (history->priv->data_rate, (GFunc) dkp_history_obj_free, NULL);
|
||||
g_ptr_array_free (history->priv->data_rate, TRUE);
|
||||
g_ptr_array_foreach (history->priv->data_charge, (GFunc) dkp_history_obj_free, NULL);
|
||||
g_ptr_array_free (history->priv->data_charge, TRUE);
|
||||
g_ptr_array_foreach (history->priv->data_time_full, (GFunc) dkp_history_obj_free, NULL);
|
||||
g_ptr_array_free (history->priv->data_time_full, TRUE);
|
||||
g_ptr_array_foreach (history->priv->data_time_empty, (GFunc) dkp_history_obj_free, NULL);
|
||||
g_ptr_array_free (history->priv->data_time_empty, TRUE);
|
||||
|
||||
g_free (history->priv->id);
|
||||
|
||||
g_return_if_fail (history->priv != NULL);
|
||||
|
|
|
|||
|
|
@ -62,11 +62,11 @@ typedef enum {
|
|||
|
||||
GType dkp_history_get_type (void);
|
||||
DkpHistory *dkp_history_new (void);
|
||||
EggObjList *dkp_history_get_data (DkpHistory *history,
|
||||
GPtrArray *dkp_history_get_data (DkpHistory *history,
|
||||
DkpHistoryType type,
|
||||
guint timespan,
|
||||
guint resolution);
|
||||
EggObjList *dkp_history_get_profile_data (DkpHistory *history,
|
||||
GPtrArray *dkp_history_get_profile_data (DkpHistory *history,
|
||||
gboolean charging);
|
||||
gboolean dkp_history_set_id (DkpHistory *history,
|
||||
const gchar *id);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ INCLUDES = \
|
|||
-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
|
||||
-DPACKAGE_LIB_DIR=\""$(libdir)"\" \
|
||||
-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT \
|
||||
-DDKP_COMPILATION \
|
||||
-DEGG_LOG_FILE=\""$(DKP_LOG_DIR)/DeviceKit-power"\" \
|
||||
-DEGG_VERBOSE="\"DKP_VERBOSE\"" \
|
||||
-DEGG_LOGGING="\"DKP_LOGGING\"" \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue