diff options
author | Richard Hughes <richard@hughsie.com> | 2009-07-27 16:40:11 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2009-07-27 16:40:11 +0100 |
commit | 0c8d29a90f5b5b7d84ec834213ac7e4390e89db9 (patch) | |
tree | 913239be76d6075d7926c8cd1252060ca9dc170f /src/dummy | |
parent | 8cf5c058c337a114d6fc5cf18593c5ecf1099efd (diff) | |
download | upower-0c8d29a90f5b5b7d84ec834213ac7e4390e89db9.tar.gz |
Initial split to make DeviceKit-power compile without GUdev for non-linux platforms
Diffstat (limited to 'src/dummy')
-rw-r--r-- | src/dummy/.gitignore | 5 | ||||
-rw-r--r-- | src/dummy/Makefile.am | 23 | ||||
-rw-r--r-- | src/dummy/dkp-backend.c | 221 | ||||
-rw-r--r-- | src/dummy/dkp-native.c | 40 |
4 files changed, 289 insertions, 0 deletions
diff --git a/src/dummy/.gitignore b/src/dummy/.gitignore new file mode 100644 index 0000000..ed89e2f --- /dev/null +++ b/src/dummy/.gitignore @@ -0,0 +1,5 @@ +.deps +.libs +*.o +*.a + diff --git a/src/dummy/Makefile.am b/src/dummy/Makefile.am new file mode 100644 index 0000000..aa1c944 --- /dev/null +++ b/src/dummy/Makefile.am @@ -0,0 +1,23 @@ +## Process this file with automake to produce Makefile.in + +INCLUDES = \ + -I$(top_builddir)/src -I$(top_srcdir)/src \ + -DEGG_LOG_FILE=\""$(DKP_LOG_DIR)/DeviceKit-power"\" \ + -DEGG_VERBOSE="\"DKP_VERBOSE\"" \ + -DEGG_LOGGING="\"DKP_LOGGING\"" \ + -DEGG_CONSOLE="\"DKP_CONSOLE\"" \ + -DDKP_COMPILATION \ + -I$(top_srcdir)/devkit-power-gobject \ + $(DBUS_GLIB_CFLAGS) \ + $(POLKIT_CFLAGS) \ + $(GLIB_CFLAGS) + +noinst_LIBRARIES = libdkpshared.a +libdkpshared_a_SOURCES = \ + dkp-backend.c \ + dkp-native.c \ + $(BUILT_SOURCES) + +clean-local : + rm -f *~ + diff --git a/src/dummy/dkp-backend.c b/src/dummy/dkp-backend.c new file mode 100644 index 0000000..0241a76 --- /dev/null +++ b/src/dummy/dkp-backend.c @@ -0,0 +1,221 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2009 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 <stdlib.h> +#include <stdio.h> +#include <math.h> +#include <glib/gi18n.h> +#include <gio/gio.h> + +#include "egg-debug.h" + +#include "dkp-backend.h" +#include "dkp-daemon.h" +#include "dkp-marshal.h" +#include "dkp-device.h" + +static void dkp_backend_class_init (DkpBackendClass *klass); +static void dkp_backend_init (DkpBackend *backend); +static void dkp_backend_finalize (GObject *object); + +#define DKP_BACKEND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_TYPE_BACKEND, DkpBackendPrivate)) + +struct DkpBackendPrivate +{ + DkpDaemon *daemon; + DkpDevice *device; + DkpDeviceList *device_list; /* unused */ + GObject *native; +}; + +enum { + SIGNAL_DEVICE_ADDED, + SIGNAL_DEVICE_CHANGED, + SIGNAL_DEVICE_REMOVED, + SIGNAL_LAST +}; + +static guint signals [SIGNAL_LAST] = { 0 }; + +G_DEFINE_TYPE (DkpBackend, dkp_backend, G_TYPE_OBJECT) + +/** + * dkp_backend_changed_time_cb: + **/ +static gboolean +dkp_backend_changed_time_cb (DkpBackend *backend) +{ + /* emit */ + g_signal_emit (backend, signals[SIGNAL_DEVICE_CHANGED], 0, backend->priv->native, backend->priv->device, TRUE); + return TRUE; +} + +/** + * dkp_backend_add_cb: + **/ +static gboolean +dkp_backend_add_cb (DkpBackend *backend) +{ + gboolean ret; + + /* coldplug */ + ret = dkp_device_coldplug (backend->priv->device, backend->priv->daemon, backend->priv->native); + if (!ret) { + egg_warning ("failed to coldplug"); + goto out; + } + + /* emit */ + g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, backend->priv->native, backend->priv->device, TRUE); + + /* setup poll */ + g_timeout_add_seconds (2, (GSourceFunc) dkp_backend_changed_time_cb, backend); +out: + return FALSE; +} + +/** + * dkp_backend_coldplug: + * @backend: The %DkpBackend class instance + * @daemon: The %DkpDaemon controlling instance + * + * Finds all the devices already plugged in, and emits device-add signals for + * each of them. + * + * Return value: %TRUE for success + **/ +gboolean +dkp_backend_coldplug (DkpBackend *backend, DkpDaemon *daemon) +{ + backend->priv->daemon = g_object_ref (daemon); + backend->priv->device_list = dkp_daemon_get_device_list (daemon); + + /* small delay until first device is added */ + g_timeout_add_seconds (1, (GSourceFunc) dkp_backend_add_cb, backend); + + return TRUE; +} + +/** + * dkp_backend_class_init: + * @klass: The DkpBackendClass + **/ +static void +dkp_backend_class_init (DkpBackendClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->finalize = dkp_backend_finalize; + + signals [SIGNAL_DEVICE_ADDED] = + g_signal_new ("device-added", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (DkpBackendClass, device_added), + NULL, NULL, dkp_marshal_VOID__POINTER_POINTER_BOOLEAN, + G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_BOOLEAN); + signals [SIGNAL_DEVICE_CHANGED] = + g_signal_new ("device-changed", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (DkpBackendClass, device_changed), + NULL, NULL, dkp_marshal_VOID__POINTER_POINTER_BOOLEAN, + G_TYPE_NONE, 3, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_BOOLEAN); + signals [SIGNAL_DEVICE_REMOVED] = + g_signal_new ("device-removed", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (DkpBackendClass, device_removed), + NULL, NULL, dkp_marshal_VOID__POINTER_POINTER, + G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER); + + g_type_class_add_private (klass, sizeof (DkpBackendPrivate)); +} + +/** + * dkp_backend_init: + **/ +static void +dkp_backend_init (DkpBackend *backend) +{ + backend->priv = DKP_BACKEND_GET_PRIVATE (backend); + backend->priv->daemon = NULL; + backend->priv->device_list = NULL; + backend->priv->native = g_object_new (DKP_TYPE_DEVICE, NULL); + backend->priv->device = dkp_device_new (); + + /* setup dummy */ + g_object_set (backend->priv->device, + "native-path", "/hal/blows/goats", + "vendor", "hughsie", + "model", "BAT1", + "serial", "0001", + "type", DKP_DEVICE_TYPE_BATTERY, + "online", FALSE, + "power-supply", TRUE, + "is-present", TRUE, + "is-rechargeable", TRUE, + "has-history", FALSE, + "has-statistics", FALSE, + "state", DKP_DEVICE_STATE_DISCHARGING, + "energy", 0.0f, + "energy-empty", 0.0f, + "energy-full", 10.0f, + "energy-full-design", 10.0f, + "energy-rate", 5.0f, + "percentage", 50.0f, + NULL); +} + +/** + * dkp_backend_finalize: + **/ +static void +dkp_backend_finalize (GObject *object) +{ + DkpBackend *backend; + + g_return_if_fail (DKP_IS_BACKEND (object)); + + backend = DKP_BACKEND (object); + + if (backend->priv->daemon != NULL) + g_object_unref (backend->priv->daemon); + if (backend->priv->device_list != NULL) + g_object_unref (backend->priv->device_list); + + g_object_unref (backend->priv->native); + g_object_unref (backend->priv->device); + + G_OBJECT_CLASS (dkp_backend_parent_class)->finalize (object); +} + +/** + * dkp_backend_new: + * + * Return value: a new %DkpBackend object. + **/ +DkpBackend * +dkp_backend_new (void) +{ + DkpBackend *backend; + backend = g_object_new (DKP_TYPE_BACKEND, NULL); + return DKP_BACKEND (backend); +} + diff --git a/src/dummy/dkp-native.c b/src/dummy/dkp-native.c new file mode 100644 index 0000000..1dea65c --- /dev/null +++ b/src/dummy/dkp-native.c @@ -0,0 +1,40 @@ +/* -*- 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 + * + */ + +#include <glib.h> + +#include "dkp-native.h" + +/** + * dkp_native_get_native_path: + * @object: the native tracking object + * + * This converts a GObject used as the device data into a native path. + * This would be implemented on a Linux system using: + * g_udev_device_get_sysfs_path (G_UDEV_DEVICE (object)) + * + * Return value: The native path for the device which is unique, e.g. "/sys/class/power/BAT1" + **/ +const gchar * +dkp_native_get_native_path (GObject *object) +{ + return "/sys/dummy"; +} + |