mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2025-12-20 05:30:03 +01:00
Add libupower so applications can switch away from devkit-power-gobject
This commit is contained in:
parent
b8a200eb48
commit
0a2b06f298
13 changed files with 2548 additions and 4 deletions
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
SUBDIRS = devkit-power-gobject src doc tools policy po $(UDEV_RULES)
|
||||
SUBDIRS = devkit-power-gobject libupower-glib src doc tools policy po $(UDEV_RULES)
|
||||
|
||||
DIST_SUBDIRS = devkit-power-gobject src doc tools policy po rules
|
||||
DIST_SUBDIRS = devkit-power-gobject libupower-glib src doc tools policy po rules
|
||||
|
||||
# Creating ChangeLog from git log (taken from cairo/Makefile.am):
|
||||
ChangeLog: $(srcdir)/ChangeLog
|
||||
|
|
@ -31,7 +31,7 @@ snapshot:
|
|||
$(MAKE) dist distdir=$(PACKAGE)-$(VERSION)-`date +"%Y%m%d"`
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = devkit-power-gobject.pc
|
||||
pkgconfig_DATA = devkit-power-gobject.pc upower-glib.pc
|
||||
|
||||
# xsltproc barfs on 'make distcheck'; disable for now
|
||||
DISTCHECK_CONFIGURE_FLAGS=--disable-man-pages --enable-gtk-doc --enable-introspection
|
||||
|
|
|
|||
|
|
@ -216,6 +216,7 @@ AC_DEFINE_UNQUOTED([GETTEXT_PACKAGE],["$GETTEXT_PACKAGE"],[gettext domain])
|
|||
AC_OUTPUT([
|
||||
Makefile
|
||||
devkit-power-gobject.pc
|
||||
upower-glib.pc
|
||||
src/Makefile
|
||||
src/dummy/Makefile
|
||||
src/freebsd/Makefile
|
||||
|
|
@ -229,6 +230,8 @@ policy/Makefile
|
|||
rules/Makefile
|
||||
devkit-power-gobject/Makefile
|
||||
devkit-power-gobject/dkp-version.h
|
||||
libupower-glib/Makefile
|
||||
libupower-glib/up-version.h
|
||||
po/Makefile.in
|
||||
])
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ DOC_MAIN_SGML_FILE=upower-docs.xml
|
|||
SCAN_OPTIONS=--ignore-headers=config.h
|
||||
|
||||
# The directory containing the source code. Relative to $(srcdir)
|
||||
DOC_SOURCE_DIR=../policy
|
||||
DOC_SOURCE_DIR=../libupower-glib
|
||||
|
||||
# Used for dependencies
|
||||
HFILE_GLOB=
|
||||
|
|
|
|||
14
libupower-glib/.gitignore
vendored
Normal file
14
libupower-glib/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
.deps
|
||||
.libs
|
||||
*.o
|
||||
*.la
|
||||
*.lo
|
||||
*-marshal.c
|
||||
*-marshal.h
|
||||
*.gcov
|
||||
*.gcda
|
||||
*.gcno
|
||||
up-version.h
|
||||
*.gir
|
||||
*.typelib
|
||||
|
||||
813
libupower-glib/up-client.c
Normal file
813
libupower-glib/up-client.c
Normal file
|
|
@ -0,0 +1,813 @@
|
|||
/* -*- 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
#include "up-client.h"
|
||||
#include "up-device.h"
|
||||
|
||||
static void up_client_class_init (UpClientClass *klass);
|
||||
static void up_client_init (UpClient *client);
|
||||
static void up_client_finalize (GObject *object);
|
||||
|
||||
#define UP_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_CLIENT, UpClientPrivate))
|
||||
|
||||
struct UpClientPrivate
|
||||
{
|
||||
DBusGConnection *bus;
|
||||
DBusGProxy *proxy;
|
||||
DBusGProxy *prop_proxy;
|
||||
GPtrArray *array;
|
||||
gboolean have_properties;
|
||||
gchar *daemon_version;
|
||||
gboolean can_suspend;
|
||||
gboolean can_hibernate;
|
||||
gboolean lid_is_closed;
|
||||
gboolean on_battery;
|
||||
gboolean on_low_battery;
|
||||
gboolean lid_is_present;
|
||||
};
|
||||
|
||||
enum {
|
||||
UP_CLIENT_DEVICE_ADDED,
|
||||
UP_CLIENT_DEVICE_CHANGED,
|
||||
UP_CLIENT_DEVICE_REMOVED,
|
||||
UP_CLIENT_CHANGED,
|
||||
UP_CLIENT_LAST_SIGNAL
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_DAEMON_VERSION,
|
||||
PROP_CAN_SUSPEND,
|
||||
PROP_CAN_HIBERNATE,
|
||||
PROP_ON_BATTERY,
|
||||
PROP_ON_LOW_BATTERY,
|
||||
PROP_LID_IS_CLOSED,
|
||||
PROP_LID_IS_PRESENT,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
static guint signals [UP_CLIENT_LAST_SIGNAL] = { 0 };
|
||||
static gpointer up_client_object = NULL;
|
||||
|
||||
G_DEFINE_TYPE (UpClient, up_client, G_TYPE_OBJECT)
|
||||
|
||||
/**
|
||||
* up_client_get_device:
|
||||
**/
|
||||
static UpDevice *
|
||||
up_client_get_device (UpClient *client, const gchar *object_path)
|
||||
{
|
||||
guint i;
|
||||
const gchar *object_path_tmp;
|
||||
UpDevice *device;
|
||||
UpClientPrivate *priv = client->priv;
|
||||
|
||||
for (i=0; i<priv->array->len; i++) {
|
||||
device = g_ptr_array_index (priv->array, i);
|
||||
object_path_tmp = up_device_get_object_path (device);
|
||||
if (g_strcmp0 (object_path_tmp, object_path) == 0)
|
||||
return device;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_get_devices:
|
||||
*
|
||||
* Get a copy of the device objects.
|
||||
*
|
||||
* Return value: an array of #UpDevice objects, free with g_ptr_array_unref()
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
GPtrArray *
|
||||
up_client_get_devices (UpClient *client)
|
||||
{
|
||||
return g_ptr_array_ref (client->priv->array);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_get_devices_private:
|
||||
**/
|
||||
static GPtrArray *
|
||||
up_client_get_devices_private (UpClient *client, GError **error)
|
||||
{
|
||||
gboolean ret;
|
||||
GError *error_local = NULL;
|
||||
GPtrArray *devices = NULL;
|
||||
GType g_type_array;
|
||||
|
||||
if (!client->priv->proxy)
|
||||
return NULL;
|
||||
g_type_array = dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH);
|
||||
ret = dbus_g_proxy_call (client->priv->proxy, "EnumerateDevices", &error_local,
|
||||
G_TYPE_INVALID,
|
||||
g_type_array, &devices,
|
||||
G_TYPE_INVALID);
|
||||
if (!ret) {
|
||||
g_warning ("Couldn't enumerate devices: %s", error_local->message);
|
||||
g_set_error (error, 1, 0, "%s", error_local->message);
|
||||
g_error_free (error_local);
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_suspend_sync:
|
||||
* @client : a #UpClient instance.
|
||||
* @error : a #GError.
|
||||
*
|
||||
* Puts the computer into a low power state, but state is not preserved if the
|
||||
* power is lost.
|
||||
*
|
||||
* NOTE: The system is still consuming a small amount of power
|
||||
*
|
||||
* Return value: TRUE if system suspended okay, FALSE other wise.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
gboolean
|
||||
up_client_suspend_sync (UpClient *client, GError **error)
|
||||
{
|
||||
gboolean ret;
|
||||
GError *error_local = NULL;
|
||||
|
||||
g_return_val_if_fail (UP_IS_CLIENT (client), FALSE);
|
||||
g_return_val_if_fail (client->priv->proxy != NULL, FALSE);
|
||||
|
||||
ret = dbus_g_proxy_call (client->priv->proxy, "Suspend", &error_local,
|
||||
G_TYPE_INVALID, G_TYPE_INVALID);
|
||||
if (!ret) {
|
||||
/* DBus might time out, which is okay */
|
||||
if (g_error_matches (error_local, DBUS_GERROR, DBUS_GERROR_NO_REPLY)) {
|
||||
g_debug ("DBUS timed out, but recovering");
|
||||
ret = TRUE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* an actual error */
|
||||
g_warning ("Couldn't suspend: %s", error_local->message);
|
||||
g_set_error (error, 1, 0, "%s", error_local->message);
|
||||
}
|
||||
out:
|
||||
if (error_local != NULL)
|
||||
g_error_free (error_local);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_hibernate_sync:
|
||||
* @client : a #UpClient instance.
|
||||
* @error : a #GError.
|
||||
*
|
||||
* Puts the computer into a low power state, where state is preserved if the
|
||||
* power is lost.
|
||||
*
|
||||
* Return value: TRUE if system suspended okay, FALSE other wise.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
gboolean
|
||||
up_client_hibernate_sync (UpClient *client, GError **error)
|
||||
{
|
||||
gboolean ret;
|
||||
GError *error_local = NULL;
|
||||
|
||||
g_return_val_if_fail (UP_IS_CLIENT (client), FALSE);
|
||||
g_return_val_if_fail (client->priv->proxy != NULL, FALSE);
|
||||
|
||||
ret = dbus_g_proxy_call (client->priv->proxy, "Hibernate", &error_local,
|
||||
G_TYPE_INVALID, G_TYPE_INVALID);
|
||||
if (!ret) {
|
||||
/* DBus might time out, which is okay */
|
||||
if (g_error_matches (error_local, DBUS_GERROR, DBUS_GERROR_NO_REPLY)) {
|
||||
g_debug ("DBUS timed out, but recovering");
|
||||
ret = TRUE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* an actual error */
|
||||
g_warning ("Couldn't hibernate: %s", error_local->message);
|
||||
g_set_error (error, 1, 0, "%s", error_local->message);
|
||||
}
|
||||
out:
|
||||
if (error_local != NULL)
|
||||
g_error_free (error_local);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_get_properties_sync:
|
||||
**/
|
||||
gboolean
|
||||
up_client_get_properties_sync (UpClient *client, GError **error)
|
||||
{
|
||||
gboolean ret = TRUE;
|
||||
GHashTable *props;
|
||||
GValue *value;
|
||||
|
||||
props = NULL;
|
||||
|
||||
if (client->priv->have_properties)
|
||||
goto out;
|
||||
if (!client->priv->prop_proxy)
|
||||
goto out;
|
||||
|
||||
error = NULL;
|
||||
ret = dbus_g_proxy_call (client->priv->prop_proxy, "GetAll", error,
|
||||
G_TYPE_STRING, "org.freedesktop.UPower",
|
||||
G_TYPE_INVALID,
|
||||
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props,
|
||||
G_TYPE_INVALID);
|
||||
if (!ret)
|
||||
goto out;
|
||||
|
||||
value = g_hash_table_lookup (props, "DaemonVersion");
|
||||
if (value == NULL) {
|
||||
g_warning ("No 'DaemonVersion' property");
|
||||
goto out;
|
||||
}
|
||||
client->priv->daemon_version = g_strdup (g_value_get_string (value));
|
||||
|
||||
value = g_hash_table_lookup (props, "CanSuspend");
|
||||
if (value == NULL) {
|
||||
g_warning ("No 'CanSuspend' property");
|
||||
goto out;
|
||||
}
|
||||
ret = g_value_get_boolean (value);
|
||||
if (ret != client->priv->can_suspend) {
|
||||
client->priv->can_suspend = ret;
|
||||
g_object_notify (G_OBJECT(client), "can-suspend");
|
||||
}
|
||||
|
||||
value = g_hash_table_lookup (props, "CanHibernate");
|
||||
if (value == NULL) {
|
||||
g_warning ("No 'CanHibernate' property");
|
||||
goto out;
|
||||
}
|
||||
ret = g_value_get_boolean (value);
|
||||
if (ret != client->priv->can_hibernate) {
|
||||
client->priv->can_hibernate = ret;
|
||||
g_object_notify (G_OBJECT(client), "can-hibernate");
|
||||
}
|
||||
|
||||
value = g_hash_table_lookup (props, "LidIsClosed");
|
||||
if (value == NULL) {
|
||||
g_warning ("No 'LidIsClosed' property");
|
||||
goto out;
|
||||
}
|
||||
ret = g_value_get_boolean (value);
|
||||
if (ret != client->priv->lid_is_closed) {
|
||||
client->priv->lid_is_closed = ret;
|
||||
g_object_notify (G_OBJECT(client), "lid-is-closed");
|
||||
}
|
||||
|
||||
value = g_hash_table_lookup (props, "OnBattery");
|
||||
if (value == NULL) {
|
||||
g_warning ("No 'OnBattery' property");
|
||||
goto out;
|
||||
}
|
||||
ret = g_value_get_boolean (value);
|
||||
if (ret != client->priv->on_battery) {
|
||||
client->priv->on_battery = ret;
|
||||
g_object_notify (G_OBJECT(client), "on-battery");
|
||||
}
|
||||
|
||||
value = g_hash_table_lookup (props, "OnLowBattery");
|
||||
if (value == NULL) {
|
||||
g_warning ("No 'OnLowBattery' property");
|
||||
goto out;
|
||||
}
|
||||
ret = g_value_get_boolean (value);
|
||||
if (ret != client->priv->on_low_battery) {
|
||||
client->priv->on_low_battery = ret;
|
||||
g_object_notify (G_OBJECT(client), "on-low-battery");
|
||||
}
|
||||
|
||||
value = g_hash_table_lookup (props, "LidIsPresent");
|
||||
if (value == NULL) {
|
||||
g_warning ("No 'LidIsPresent' property");
|
||||
goto out;
|
||||
}
|
||||
ret = g_value_get_boolean (value);
|
||||
if (ret != client->priv->lid_is_present) {
|
||||
client->priv->lid_is_present = ret;
|
||||
g_object_notify (G_OBJECT(client), "lid-is-present");
|
||||
}
|
||||
|
||||
/* cached */
|
||||
client->priv->have_properties = TRUE;
|
||||
|
||||
out:
|
||||
if (props != NULL)
|
||||
g_hash_table_unref (props);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_get_daemon_version:
|
||||
* @client : a #UpClient instance.
|
||||
*
|
||||
* Get DeviceKit-power daemon version.
|
||||
*
|
||||
* Return value: string containing the daemon version, e.g. 008
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
const gchar *
|
||||
up_client_get_daemon_version (UpClient *client)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_CLIENT (client), NULL);
|
||||
up_client_get_properties_sync (client, NULL);
|
||||
return client->priv->daemon_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_get_can_hibernate:
|
||||
* @client : a #UpClient instance.
|
||||
*
|
||||
* Get whether the system is able to hibernate.
|
||||
*
|
||||
* Return value: TRUE if system can hibernate, FALSE other wise.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
gboolean
|
||||
up_client_get_can_hibernate (UpClient *client)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_CLIENT (client), FALSE);
|
||||
up_client_get_properties_sync (client, NULL);
|
||||
return client->priv->can_hibernate;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_get_lid_is_closed:
|
||||
* @client : a #UpClient instance.
|
||||
*
|
||||
* Get whether the laptop lid is closed.
|
||||
*
|
||||
* Return value: %TRUE if lid is closed or %FALSE otherwise.
|
||||
*/
|
||||
gboolean
|
||||
up_client_get_lid_is_closed (UpClient *client)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_CLIENT (client), FALSE);
|
||||
up_client_get_properties_sync (client, NULL);
|
||||
return client->priv->lid_is_closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_get_can_suspend:
|
||||
* @client : a #UpClient instance.
|
||||
*
|
||||
* Get whether the system is able to suspend.
|
||||
*
|
||||
* Return value: TRUE if system can suspend, FALSE other wise.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
gboolean
|
||||
up_client_get_can_suspend (UpClient *client)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_CLIENT (client), FALSE);
|
||||
up_client_get_properties_sync (client, NULL);
|
||||
return client->priv->can_suspend;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_get_on_battery:
|
||||
* @client : a #UpClient instance.
|
||||
*
|
||||
* Get whether the system is running on battery power.
|
||||
*
|
||||
* Return value: TRUE if the system is currently running on battery, FALSE other wise.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
gboolean
|
||||
up_client_get_on_battery (UpClient *client)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_CLIENT (client), FALSE);
|
||||
up_client_get_properties_sync (client, NULL);
|
||||
return client->priv->on_battery;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_get_on_low_battery:
|
||||
* @client : a #UpClient instance.
|
||||
*
|
||||
* Get whether the system is running on low battery power.
|
||||
*
|
||||
* Return value: TRUE if the system is currently on low battery power, FALSE other wise.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
gboolean
|
||||
up_client_get_on_low_battery (UpClient *client)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_CLIENT (client), FALSE);
|
||||
up_client_get_properties_sync (client, NULL);
|
||||
return client->priv->on_low_battery;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_add:
|
||||
**/
|
||||
static void
|
||||
up_client_add (UpClient *client, const gchar *object_path)
|
||||
{
|
||||
UpDevice *device;
|
||||
gboolean ret;
|
||||
|
||||
/* create new device */
|
||||
device = up_device_new ();
|
||||
ret = up_device_set_object_path_sync (device, object_path, NULL);
|
||||
if (!ret)
|
||||
goto out;
|
||||
|
||||
/* add to array */
|
||||
g_ptr_array_add (client->priv->array, g_object_ref (device));
|
||||
g_signal_emit (client, signals [UP_CLIENT_DEVICE_ADDED], 0, device);
|
||||
out:
|
||||
g_object_unref (device);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_added_cb:
|
||||
**/
|
||||
static void
|
||||
up_device_added_cb (DBusGProxy *proxy, const gchar *object_path, UpClient *client)
|
||||
{
|
||||
up_client_add (client, object_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_changed_cb:
|
||||
**/
|
||||
static void
|
||||
up_device_changed_cb (DBusGProxy *proxy, const gchar *object_path, UpClient *client)
|
||||
{
|
||||
UpDevice *device;
|
||||
device = up_client_get_device (client, object_path);
|
||||
if (device != NULL)
|
||||
g_signal_emit (client, signals [UP_CLIENT_DEVICE_CHANGED], 0, device);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_removed_cb:
|
||||
**/
|
||||
static void
|
||||
up_device_removed_cb (DBusGProxy *proxy, const gchar *object_path, UpClient *client)
|
||||
{
|
||||
UpDevice *device;
|
||||
device = up_client_get_device (client, object_path);
|
||||
if (device != NULL) {
|
||||
g_signal_emit (client, signals [UP_CLIENT_DEVICE_REMOVED], 0, device);
|
||||
g_ptr_array_remove (client->priv->array, device);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_changed_cb:
|
||||
**/
|
||||
static void
|
||||
up_client_changed_cb (DBusGProxy *proxy, UpClient *client)
|
||||
{
|
||||
client->priv->have_properties = FALSE;
|
||||
g_signal_emit (client, signals [UP_CLIENT_CHANGED], 0);
|
||||
}
|
||||
|
||||
static void
|
||||
up_client_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
UpClient *client;
|
||||
client = UP_CLIENT (object);
|
||||
|
||||
up_client_get_properties_sync (client, NULL);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON_VERSION:
|
||||
g_value_set_string (value, client->priv->daemon_version);
|
||||
break;
|
||||
case PROP_CAN_SUSPEND:
|
||||
g_value_set_boolean (value, client->priv->can_suspend);
|
||||
break;
|
||||
case PROP_CAN_HIBERNATE:
|
||||
g_value_set_boolean (value, client->priv->can_hibernate);
|
||||
break;
|
||||
case PROP_ON_BATTERY:
|
||||
g_value_set_boolean (value, client->priv->on_battery);
|
||||
break;
|
||||
case PROP_ON_LOW_BATTERY:
|
||||
g_value_set_boolean (value, client->priv->on_low_battery);
|
||||
break;
|
||||
case PROP_LID_IS_CLOSED:
|
||||
g_value_set_boolean (value, client->priv->lid_is_closed);
|
||||
break;
|
||||
case PROP_LID_IS_PRESENT:
|
||||
g_value_set_boolean (value, client->priv->lid_is_present);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_class_init:
|
||||
* @klass: The UpClientClass
|
||||
**/
|
||||
static void
|
||||
up_client_class_init (UpClientClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->get_property = up_client_get_property;
|
||||
object_class->finalize = up_client_finalize;
|
||||
|
||||
/**
|
||||
* UpClient:daemon-version:
|
||||
*
|
||||
* The daemon version.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
*/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_DAEMON_VERSION,
|
||||
g_param_spec_string ("daemon-version",
|
||||
"Daemon version",
|
||||
NULL,
|
||||
NULL,
|
||||
G_PARAM_READABLE));
|
||||
/**
|
||||
* UpClient:can-suspend:
|
||||
*
|
||||
* If the computer can suspend.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
*/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_CAN_SUSPEND,
|
||||
g_param_spec_boolean ("can-suspend",
|
||||
"If the computer can suspend",
|
||||
NULL,
|
||||
FALSE,
|
||||
G_PARAM_READABLE));
|
||||
/**
|
||||
* UpClient:can-hibernate:
|
||||
*
|
||||
* If the computer can hibernate.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
*/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_CAN_HIBERNATE,
|
||||
g_param_spec_boolean ("can-hibernate",
|
||||
"If the computer can hibernate",
|
||||
NULL,
|
||||
FALSE,
|
||||
G_PARAM_READABLE));
|
||||
/**
|
||||
* UpClient:on-battery:
|
||||
*
|
||||
* If the computer is on battery power.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
*/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_ON_BATTERY,
|
||||
g_param_spec_boolean ("on-battery",
|
||||
"If the computer is on battery power",
|
||||
NULL,
|
||||
FALSE,
|
||||
G_PARAM_READABLE));
|
||||
/**
|
||||
* UpClient:on-low-battery:
|
||||
*
|
||||
* If the computer is on low battery power.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
*/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_ON_LOW_BATTERY,
|
||||
g_param_spec_boolean ("on-low-battery",
|
||||
"If the computer is on low battery power",
|
||||
NULL,
|
||||
FALSE,
|
||||
G_PARAM_READABLE));
|
||||
/**
|
||||
* UpClient:lid-is-closed:
|
||||
*
|
||||
* If the laptop lid is closed.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
*/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_LID_IS_CLOSED,
|
||||
g_param_spec_boolean ("lid-is-closed",
|
||||
"If the laptop lid is closed",
|
||||
NULL,
|
||||
FALSE,
|
||||
G_PARAM_READABLE));
|
||||
/**
|
||||
* UpClient:lid-is-present:
|
||||
*
|
||||
* If a laptop lid is present.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
*/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_LID_IS_PRESENT,
|
||||
g_param_spec_boolean ("lid-is-present",
|
||||
"If a laptop lid is present",
|
||||
NULL,
|
||||
FALSE,
|
||||
G_PARAM_READABLE));
|
||||
|
||||
signals [UP_CLIENT_DEVICE_ADDED] =
|
||||
g_signal_new ("device-added",
|
||||
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (UpClientClass, device_added),
|
||||
NULL, NULL, g_cclosure_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE, 1, G_TYPE_POINTER);
|
||||
signals [UP_CLIENT_DEVICE_REMOVED] =
|
||||
g_signal_new ("device-removed",
|
||||
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (UpClientClass, device_removed),
|
||||
NULL, NULL, g_cclosure_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE, 1, G_TYPE_POINTER);
|
||||
signals [UP_CLIENT_DEVICE_CHANGED] =
|
||||
g_signal_new ("device-changed",
|
||||
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (UpClientClass, device_changed),
|
||||
NULL, NULL, g_cclosure_marshal_VOID__POINTER,
|
||||
G_TYPE_NONE, 1, G_TYPE_POINTER);
|
||||
signals [UP_CLIENT_CHANGED] =
|
||||
g_signal_new ("changed",
|
||||
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (UpClientClass, changed),
|
||||
NULL, NULL, g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (UpClientPrivate));
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_enumerate_devices_sync:
|
||||
**/
|
||||
gboolean
|
||||
up_client_enumerate_devices_sync (UpClient *client, GError **error)
|
||||
{
|
||||
const gchar *object_path;
|
||||
GPtrArray *devices;
|
||||
guint i;
|
||||
gboolean ret = TRUE;
|
||||
|
||||
/* coldplug */
|
||||
devices = up_client_get_devices_private (client, error);
|
||||
if (devices == NULL) {
|
||||
ret = FALSE;
|
||||
goto out;
|
||||
}
|
||||
for (i=0; i<devices->len; i++) {
|
||||
object_path = (const gchar *) g_ptr_array_index (devices, i);
|
||||
up_client_add (client, object_path);
|
||||
}
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_init:
|
||||
* @client: This class instance
|
||||
**/
|
||||
static void
|
||||
up_client_init (UpClient *client)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
client->priv = UP_CLIENT_GET_PRIVATE (client);
|
||||
client->priv->array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
||||
client->priv->have_properties = FALSE;
|
||||
|
||||
/* get on the bus */
|
||||
client->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
|
||||
if (client->priv->bus == NULL) {
|
||||
g_warning ("Couldn't connect to system bus: %s", error->message);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* connect to main interface */
|
||||
client->priv->proxy = dbus_g_proxy_new_for_name (client->priv->bus,
|
||||
"org.freedesktop.UPower",
|
||||
"/org/freedesktop/UPower",
|
||||
"org.freedesktop.UPower");
|
||||
if (client->priv->proxy == NULL) {
|
||||
g_warning ("Couldn't connect to proxy");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* connect to properties interface */
|
||||
client->priv->prop_proxy = dbus_g_proxy_new_for_name (client->priv->bus,
|
||||
"org.freedesktop.UPower",
|
||||
"/org/freedesktop/UPower",
|
||||
"org.freedesktop.DBus.Properties");
|
||||
if (client->priv->prop_proxy == NULL) {
|
||||
g_warning ("Couldn't connect to proxy");
|
||||
goto out;
|
||||
}
|
||||
|
||||
dbus_g_proxy_add_signal (client->priv->proxy, "DeviceAdded", G_TYPE_STRING, G_TYPE_INVALID);
|
||||
dbus_g_proxy_add_signal (client->priv->proxy, "DeviceRemoved", G_TYPE_STRING, G_TYPE_INVALID);
|
||||
dbus_g_proxy_add_signal (client->priv->proxy, "DeviceChanged", G_TYPE_STRING, G_TYPE_INVALID);
|
||||
dbus_g_proxy_add_signal (client->priv->proxy, "Changed", G_TYPE_INVALID);
|
||||
|
||||
/* all callbacks */
|
||||
dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceAdded",
|
||||
G_CALLBACK (up_device_added_cb), client, NULL);
|
||||
dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceRemoved",
|
||||
G_CALLBACK (up_device_removed_cb), client, NULL);
|
||||
dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceChanged",
|
||||
G_CALLBACK (up_device_changed_cb), client, NULL);
|
||||
dbus_g_proxy_connect_signal (client->priv->proxy, "Changed",
|
||||
G_CALLBACK (up_client_changed_cb), client, NULL);
|
||||
out:
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_finalize:
|
||||
**/
|
||||
static void
|
||||
up_client_finalize (GObject *object)
|
||||
{
|
||||
UpClient *client;
|
||||
|
||||
g_return_if_fail (UP_IS_CLIENT (object));
|
||||
|
||||
client = UP_CLIENT (object);
|
||||
|
||||
g_ptr_array_unref (client->priv->array);
|
||||
|
||||
if (client->priv->bus)
|
||||
dbus_g_connection_unref (client->priv->bus);
|
||||
|
||||
if (client->priv->proxy != NULL)
|
||||
g_object_unref (client->priv->proxy);
|
||||
|
||||
if (client->priv->prop_proxy != NULL)
|
||||
g_object_unref (client->priv->prop_proxy);
|
||||
|
||||
g_free (client->priv->daemon_version);
|
||||
|
||||
G_OBJECT_CLASS (up_client_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_client_new:
|
||||
*
|
||||
* Return value: a new UpClient object.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
UpClient *
|
||||
up_client_new (void)
|
||||
{
|
||||
if (up_client_object != NULL) {
|
||||
g_object_ref (up_client_object);
|
||||
} else {
|
||||
up_client_object = g_object_new (UP_TYPE_CLIENT, NULL);
|
||||
g_object_add_weak_pointer (up_client_object, &up_client_object);
|
||||
}
|
||||
return UP_CLIENT (up_client_object);
|
||||
}
|
||||
|
||||
99
libupower-glib/up-client.h
Normal file
99
libupower-glib/up-client.h
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#if !defined (__UPOWER_H_INSIDE__) && !defined (UP_COMPILATION)
|
||||
#error "Only <upower.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __UP_CLIENT_H
|
||||
#define __UP_CLIENT_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <libupower-glib/up-device.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define UP_TYPE_CLIENT (up_client_get_type ())
|
||||
#define UP_CLIENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UP_TYPE_CLIENT, UpClient))
|
||||
#define UP_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UP_TYPE_CLIENT, UpClientClass))
|
||||
#define UP_IS_CLIENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UP_TYPE_CLIENT))
|
||||
#define UP_IS_CLIENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UP_TYPE_CLIENT))
|
||||
#define UP_CLIENT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UP_TYPE_CLIENT, UpClientClass))
|
||||
#define UP_CLIENT_ERROR (up_client_error_quark ())
|
||||
#define UP_CLIENT_TYPE_ERROR (up_client_error_get_type ())
|
||||
|
||||
typedef struct UpClientPrivate UpClientPrivate;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObject parent;
|
||||
UpClientPrivate *priv;
|
||||
} UpClient;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
void (*device_added) (UpClient *client,
|
||||
UpDevice *device);
|
||||
void (*device_changed) (UpClient *client,
|
||||
UpDevice *device);
|
||||
void (*device_removed) (UpClient *client,
|
||||
UpDevice *device);
|
||||
void (*changed) (UpClient *client);
|
||||
/*< private >*/
|
||||
/* Padding for future expansion */
|
||||
void (*_up_client_reserved1) (void);
|
||||
void (*_up_client_reserved2) (void);
|
||||
void (*_up_client_reserved3) (void);
|
||||
void (*_up_client_reserved4) (void);
|
||||
void (*_up_client_reserved5) (void);
|
||||
void (*_up_client_reserved6) (void);
|
||||
void (*_up_client_reserved7) (void);
|
||||
void (*_up_client_reserved8) (void);
|
||||
} UpClientClass;
|
||||
|
||||
/* general */
|
||||
GType up_client_get_type (void);
|
||||
UpClient *up_client_new (void);
|
||||
|
||||
/* sync versions */
|
||||
gboolean up_client_get_properties_sync (UpClient *client,
|
||||
GError **error);
|
||||
gboolean up_client_enumerate_devices_sync (UpClient *client,
|
||||
GError **error);
|
||||
gboolean up_client_suspend_sync (UpClient *client,
|
||||
GError **error);
|
||||
gboolean up_client_hibernate_sync (UpClient *client,
|
||||
GError **error);
|
||||
|
||||
/* accessors */
|
||||
GPtrArray *up_client_get_devices (UpClient *client);
|
||||
const gchar *up_client_get_daemon_version (UpClient *client);
|
||||
gboolean up_client_get_can_hibernate (UpClient *client);
|
||||
gboolean up_client_get_lid_is_closed (UpClient *client);
|
||||
gboolean up_client_get_can_suspend (UpClient *client);
|
||||
gboolean up_client_get_on_battery (UpClient *client);
|
||||
gboolean up_client_get_on_low_battery (UpClient *client);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __UP_CLIENT_H */
|
||||
|
||||
1068
libupower-glib/up-device.c
Normal file
1068
libupower-glib/up-device.c
Normal file
File diff suppressed because it is too large
Load diff
94
libupower-glib/up-device.h
Normal file
94
libupower-glib/up-device.h
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/* -*- 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_DEVICE_H
|
||||
#define __UP_DEVICE_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <up-types.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define UP_TYPE_DEVICE (up_device_get_type ())
|
||||
#define UP_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UP_TYPE_DEVICE, UpDevice))
|
||||
#define UP_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UP_TYPE_DEVICE, UpDeviceClass))
|
||||
#define UP_IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UP_TYPE_DEVICE))
|
||||
#define UP_IS_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UP_TYPE_DEVICE))
|
||||
#define UP_DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UP_TYPE_DEVICE, UpDeviceClass))
|
||||
#define UP_DEVICE_ERROR (up_device_error_quark ())
|
||||
#define UP_DEVICE_TYPE_ERROR (up_device_error_get_type ())
|
||||
|
||||
typedef struct UpDevicePrivate UpDevicePrivate;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObject parent;
|
||||
UpDevicePrivate *priv;
|
||||
} UpDevice;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
void (*changed) (UpDevice *device,
|
||||
gpointer *obj);
|
||||
/*< private >*/
|
||||
/* Padding for future expansion */
|
||||
void (*_up_device_reserved1) (void);
|
||||
void (*_up_device_reserved2) (void);
|
||||
void (*_up_device_reserved3) (void);
|
||||
void (*_up_device_reserved4) (void);
|
||||
void (*_up_device_reserved5) (void);
|
||||
void (*_up_device_reserved6) (void);
|
||||
void (*_up_device_reserved7) (void);
|
||||
void (*_up_device_reserved8) (void);
|
||||
} UpDeviceClass;
|
||||
|
||||
/* general */
|
||||
GType up_device_get_type (void);
|
||||
UpDevice *up_device_new (void);
|
||||
gchar *up_device_to_text (UpDevice *device);
|
||||
|
||||
/* sync versions */
|
||||
gboolean up_device_refresh_sync (UpDevice *device,
|
||||
GError **error);
|
||||
gboolean up_device_set_object_path_sync (UpDevice *device,
|
||||
const gchar *object_path,
|
||||
GError **error);
|
||||
GPtrArray *up_device_get_history_sync (UpDevice *device,
|
||||
const gchar *type,
|
||||
guint timespec,
|
||||
guint resolution,
|
||||
GError **error);
|
||||
GPtrArray *up_device_get_statistics_sync (UpDevice *device,
|
||||
const gchar *type,
|
||||
GError **error);
|
||||
|
||||
/* accessors */
|
||||
const gchar *up_device_get_object_path (UpDevice *device);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __UP_DEVICE_H */
|
||||
|
||||
279
libupower-glib/up-types.c
Normal file
279
libupower-glib/up-types.c
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
/* -*- 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-types.h"
|
||||
|
||||
/**
|
||||
* up_device_type_to_string:
|
||||
*
|
||||
* Converts a #UpDeviceType to a string.
|
||||
*
|
||||
* Return value: identifier string
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
const gchar *
|
||||
up_device_type_to_string (UpDeviceType type_enum)
|
||||
{
|
||||
const gchar *type = NULL;
|
||||
switch (type_enum) {
|
||||
case UP_DEVICE_TYPE_LINE_POWER:
|
||||
type = "line-power";
|
||||
break;
|
||||
case UP_DEVICE_TYPE_BATTERY:
|
||||
type = "battery";
|
||||
break;
|
||||
case UP_DEVICE_TYPE_UPS:
|
||||
type = "ups";
|
||||
break;
|
||||
case UP_DEVICE_TYPE_MONITOR:
|
||||
type = "monitor";
|
||||
break;
|
||||
case UP_DEVICE_TYPE_MOUSE:
|
||||
type = "mouse";
|
||||
break;
|
||||
case UP_DEVICE_TYPE_KEYBOARD:
|
||||
type = "keyboard";
|
||||
break;
|
||||
case UP_DEVICE_TYPE_PDA:
|
||||
type = "pda";
|
||||
break;
|
||||
case UP_DEVICE_TYPE_PHONE:
|
||||
type = "phone";
|
||||
break;
|
||||
default:
|
||||
type = "unknown";
|
||||
break;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_device_type_from_string:
|
||||
*
|
||||
* Converts a string to a #UpDeviceType.
|
||||
*
|
||||
* Return value: enumerated value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
UpDeviceType
|
||||
up_device_type_from_string (const gchar *type)
|
||||
{
|
||||
if (type == NULL)
|
||||
return UP_DEVICE_TYPE_UNKNOWN;
|
||||
if (g_strcmp0 (type, "line-power") == 0)
|
||||
return UP_DEVICE_TYPE_LINE_POWER;
|
||||
if (g_strcmp0 (type, "battery") == 0)
|
||||
return UP_DEVICE_TYPE_BATTERY;
|
||||
if (g_strcmp0 (type, "ups") == 0)
|
||||
return UP_DEVICE_TYPE_UPS;
|
||||
if (g_strcmp0 (type, "monitor") == 0)
|
||||
return UP_DEVICE_TYPE_MONITOR;
|
||||
if (g_strcmp0 (type, "mouse") == 0)
|
||||
return UP_DEVICE_TYPE_MOUSE;
|
||||
if (g_strcmp0 (type, "keyboard") == 0)
|
||||
return UP_DEVICE_TYPE_KEYBOARD;
|
||||
if (g_strcmp0 (type, "pda") == 0)
|
||||
return UP_DEVICE_TYPE_PDA;
|
||||
if (g_strcmp0 (type, "phone") == 0)
|
||||
return UP_DEVICE_TYPE_PHONE;
|
||||
return UP_DEVICE_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_device_state_to_string:
|
||||
*
|
||||
* Converts a #UpDeviceState to a string.
|
||||
*
|
||||
* Return value: identifier string
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
const gchar *
|
||||
up_device_state_to_string (UpDeviceState state_enum)
|
||||
{
|
||||
const gchar *state = NULL;
|
||||
switch (state_enum) {
|
||||
case UP_DEVICE_STATE_CHARGING:
|
||||
state = "charging";
|
||||
break;
|
||||
case UP_DEVICE_STATE_DISCHARGING:
|
||||
state = "discharging";
|
||||
break;
|
||||
case UP_DEVICE_STATE_EMPTY:
|
||||
state = "empty";
|
||||
break;
|
||||
case UP_DEVICE_STATE_FULLY_CHARGED:
|
||||
state = "fully-charged";
|
||||
break;
|
||||
case UP_DEVICE_STATE_PENDING_CHARGE:
|
||||
state = "pending-charge";
|
||||
break;
|
||||
case UP_DEVICE_STATE_PENDING_DISCHARGE:
|
||||
state = "pending-discharge";
|
||||
break;
|
||||
default:
|
||||
state = "unknown";
|
||||
break;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_device_state_from_string:
|
||||
*
|
||||
* Converts a string to a #UpDeviceState.
|
||||
*
|
||||
* Return value: enumerated value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
UpDeviceState
|
||||
up_device_state_from_string (const gchar *state)
|
||||
{
|
||||
if (state == NULL)
|
||||
return UP_DEVICE_STATE_UNKNOWN;
|
||||
if (g_strcmp0 (state, "charging") == 0)
|
||||
return UP_DEVICE_STATE_CHARGING;
|
||||
if (g_strcmp0 (state, "discharging") == 0)
|
||||
return UP_DEVICE_STATE_DISCHARGING;
|
||||
if (g_strcmp0 (state, "empty") == 0)
|
||||
return UP_DEVICE_STATE_EMPTY;
|
||||
if (g_strcmp0 (state, "fully-charged") == 0)
|
||||
return UP_DEVICE_STATE_FULLY_CHARGED;
|
||||
if (g_strcmp0 (state, "pending-charge") == 0)
|
||||
return UP_DEVICE_STATE_PENDING_CHARGE;
|
||||
if (g_strcmp0 (state, "pending-discharge") == 0)
|
||||
return UP_DEVICE_STATE_PENDING_DISCHARGE;
|
||||
return UP_DEVICE_STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_device_technology_to_string:
|
||||
*
|
||||
* Converts a #UpDeviceTechnology to a string.
|
||||
*
|
||||
* Return value: identifier string
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
const gchar *
|
||||
up_device_technology_to_string (UpDeviceTechnology technology_enum)
|
||||
{
|
||||
const gchar *technology = NULL;
|
||||
switch (technology_enum) {
|
||||
case UP_DEVICE_TECHNOLOGY_LITHIUM_ION:
|
||||
technology = "lithium-ion";
|
||||
break;
|
||||
case UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER:
|
||||
technology = "lithium-polymer";
|
||||
break;
|
||||
case UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE:
|
||||
technology = "lithium-iron-phosphate";
|
||||
break;
|
||||
case UP_DEVICE_TECHNOLOGY_LEAD_ACID:
|
||||
technology = "lead-acid";
|
||||
break;
|
||||
case UP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM:
|
||||
technology = "nickel-cadmium";
|
||||
break;
|
||||
case UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE:
|
||||
technology = "nickel-metal-hydride";
|
||||
break;
|
||||
default:
|
||||
technology = "unknown";
|
||||
break;
|
||||
}
|
||||
return technology;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_device_technology_from_string:
|
||||
*
|
||||
* Converts a string to a #UpDeviceTechnology.
|
||||
*
|
||||
* Return value: enumerated value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
UpDeviceTechnology
|
||||
up_device_technology_from_string (const gchar *technology)
|
||||
{
|
||||
if (technology == NULL)
|
||||
return UP_DEVICE_TECHNOLOGY_UNKNOWN;
|
||||
if (g_strcmp0 (technology, "lithium-ion") == 0)
|
||||
return UP_DEVICE_TECHNOLOGY_LITHIUM_ION;
|
||||
if (g_strcmp0 (technology, "lithium-polymer") == 0)
|
||||
return UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER;
|
||||
if (g_strcmp0 (technology, "lithium-iron-phosphate") == 0)
|
||||
return UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE;
|
||||
if (g_strcmp0 (technology, "lead-acid") == 0)
|
||||
return UP_DEVICE_TECHNOLOGY_LEAD_ACID;
|
||||
if (g_strcmp0 (technology, "nickel-cadmium") == 0)
|
||||
return UP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM;
|
||||
if (g_strcmp0 (technology, "nickel-metal-hydride") == 0)
|
||||
return UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE;
|
||||
return UP_DEVICE_TECHNOLOGY_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_type_to_string:
|
||||
*
|
||||
* Converts a #UpQosType to a string.
|
||||
*
|
||||
* Return value: identifier string
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
const gchar *
|
||||
up_qos_type_to_string (UpQosType type)
|
||||
{
|
||||
if (type == UP_QOS_TYPE_NETWORK)
|
||||
return "network";
|
||||
if (type == UP_QOS_TYPE_CPU_DMA)
|
||||
return "cpu_dma";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_type_from_string:
|
||||
*
|
||||
* Converts a string to a #UpQosType.
|
||||
*
|
||||
* Return value: enumerated value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
UpQosType
|
||||
up_qos_type_from_string (const gchar *type)
|
||||
{
|
||||
if (g_strcmp0 (type, "network") == 0)
|
||||
return UP_QOS_TYPE_NETWORK;
|
||||
if (g_strcmp0 (type, "cpu_dma") == 0)
|
||||
return UP_QOS_TYPE_CPU_DMA;
|
||||
return UP_QOS_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
87
libupower-glib/up-types.h
Normal file
87
libupower-glib/up-types.h
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/* -*- 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_TYPES_H
|
||||
#define __UP_TYPES_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
UP_DEVICE_TYPE_UNKNOWN,
|
||||
UP_DEVICE_TYPE_LINE_POWER,
|
||||
UP_DEVICE_TYPE_BATTERY,
|
||||
UP_DEVICE_TYPE_UPS,
|
||||
UP_DEVICE_TYPE_MONITOR,
|
||||
UP_DEVICE_TYPE_MOUSE,
|
||||
UP_DEVICE_TYPE_KEYBOARD,
|
||||
UP_DEVICE_TYPE_PDA,
|
||||
UP_DEVICE_TYPE_PHONE,
|
||||
UP_DEVICE_TYPE_LAST
|
||||
} UpDeviceType;
|
||||
|
||||
typedef enum {
|
||||
UP_DEVICE_STATE_UNKNOWN,
|
||||
UP_DEVICE_STATE_CHARGING,
|
||||
UP_DEVICE_STATE_DISCHARGING,
|
||||
UP_DEVICE_STATE_EMPTY,
|
||||
UP_DEVICE_STATE_FULLY_CHARGED,
|
||||
UP_DEVICE_STATE_PENDING_CHARGE,
|
||||
UP_DEVICE_STATE_PENDING_DISCHARGE,
|
||||
UP_DEVICE_STATE_LAST
|
||||
} UpDeviceState;
|
||||
|
||||
typedef enum {
|
||||
UP_DEVICE_TECHNOLOGY_UNKNOWN,
|
||||
UP_DEVICE_TECHNOLOGY_LITHIUM_ION,
|
||||
UP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER,
|
||||
UP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE,
|
||||
UP_DEVICE_TECHNOLOGY_LEAD_ACID,
|
||||
UP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM,
|
||||
UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE,
|
||||
UP_DEVICE_TECHNOLOGY_LAST
|
||||
} UpDeviceTechnology;
|
||||
|
||||
typedef enum {
|
||||
UP_QOS_TYPE_UNKNOWN,
|
||||
UP_QOS_TYPE_NETWORK,
|
||||
UP_QOS_TYPE_CPU_DMA,
|
||||
UP_QOS_TYPE_LAST
|
||||
} UpQosType;
|
||||
|
||||
const gchar *up_device_type_to_string (UpDeviceType type_enum);
|
||||
const gchar *up_device_state_to_string (UpDeviceState state_enum);
|
||||
const gchar *up_device_technology_to_string (UpDeviceTechnology technology_enum);
|
||||
UpDeviceType up_device_type_from_string (const gchar *type);
|
||||
UpDeviceState up_device_state_from_string (const gchar *state);
|
||||
UpDeviceTechnology up_device_technology_from_string (const gchar *technology);
|
||||
const gchar *up_qos_type_to_string (UpQosType type);
|
||||
UpQosType up_qos_type_from_string (const gchar *type);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __UP_TYPES_H */
|
||||
|
||||
39
libupower-glib/up-version.h.in
Normal file
39
libupower-glib/up-version.h.in
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2009-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.
|
||||
*/
|
||||
|
||||
#if !defined (__UPOWER_H_INSIDE__) && !defined (UP_COMPILATION)
|
||||
#error "Only <upower.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __UP_VERSION_H
|
||||
#define __UP_VERSION_H
|
||||
|
||||
/* compile time version
|
||||
*/
|
||||
#define UP_COMPILE_VERSION (0x@VERSION@)
|
||||
|
||||
/* check whether a the version is above the compile time version.
|
||||
*/
|
||||
#define UP_CHECK_VERSION(ver) \
|
||||
(UP_COMPILE_VERSION > (ver) || \
|
||||
(UP_COMPILE_VERSION == (ver)))
|
||||
|
||||
#endif /* __UP_VERSION_H */
|
||||
35
libupower-glib/upower.h
Normal file
35
libupower-glib/upower.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef __UPOWER_H__
|
||||
#define __UPOWER_H__
|
||||
|
||||
#define __UPOWER_H_INSIDE__
|
||||
|
||||
#include <libupower-glib/up-version.h>
|
||||
#include <libupower-glib/up-types.h>
|
||||
#include <libupower-glib/up-client.h>
|
||||
#include <libupower-glib/up-device.h>
|
||||
|
||||
#undef __UPOWER_H_INSIDE__
|
||||
|
||||
#endif /* __UPOWER_H__ */
|
||||
|
||||
13
upower-glib.pc.in
Normal file
13
upower-glib.pc.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: upower-glib
|
||||
Description: UPower is a system daemon for managing power devices
|
||||
Version: @VERSION@
|
||||
Requires.private: dbus-1, gthread-2.0
|
||||
Requires: glib-2.0, gobject-2.0
|
||||
Libs: -L${libdir} -lupower
|
||||
Cflags: -I${includedir}/UPower
|
||||
|
||||
Loading…
Add table
Reference in a new issue