Commit 55db60ef authored by Richard Hughes's avatar Richard Hughes

bugfix: remove use of EggObjList, which was pretty hacky, and try to make the library more sane

parent 39ba30a4
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
......
This diff is collapsed.
/* -*- 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;
}
......
This diff is collapsed.
......@@ -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\"" \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment