mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2025-12-20 04:20:04 +01:00
Remove QoS interface
It was added for some workloads, but ill-suited and never really got traction. Using cgroups to manage the resources of particular services (using systemd), or something separate like rtkit is a better bet.
This commit is contained in:
parent
c842f1a53e
commit
d10cc97cbb
22 changed files with 2 additions and 1952 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
|
||||
|
||||
SUBDIRS = etc libupower-glib src doc tools policy po
|
||||
SUBDIRS = etc libupower-glib src doc tools po
|
||||
|
||||
if BACKEND_TYPE_LINUX
|
||||
SUBDIRS += rules
|
||||
|
|
|
|||
|
|
@ -250,7 +250,6 @@ doc/Makefile
|
|||
doc/version.xml
|
||||
doc/man/Makefile
|
||||
doc/dbus/Makefile
|
||||
policy/Makefile
|
||||
rules/Makefile
|
||||
libupower-glib/Makefile
|
||||
libupower-glib/up-version.h
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ content_files = \
|
|||
man/UPower.xml \
|
||||
dbus/org.freedesktop.UPower.ref.xml \
|
||||
dbus/org.freedesktop.UPower.Device.ref.xml \
|
||||
dbus/org.freedesktop.UPower.QoS.ref.xml \
|
||||
dbus/org.freedesktop.UPower.KbdBacklight.ref.xml \
|
||||
$(NULL)
|
||||
|
||||
|
|
@ -80,7 +79,6 @@ MAINTAINERCLEANFILES = \
|
|||
DISTCLEANFILES = \
|
||||
org.freedesktop.UPower.Device.ref.xml \
|
||||
org.freedesktop.UPower.KbdBacklight.ref.xml \
|
||||
org.freedesktop.UPower.QoS.ref.xml \
|
||||
org.freedesktop.UPower.ref.xml \
|
||||
upowerd.xml \
|
||||
upower.xml \
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
all : org.freedesktop.UPower.ref.xml org.freedesktop.UPower.Device.ref.xml org.freedesktop.UPower.QoS.ref.xml org.freedesktop.UPower.KbdBacklight.ref.xml org.freedesktop.UPower.Wakeups.ref.xml
|
||||
all : org.freedesktop.UPower.ref.xml org.freedesktop.UPower.Device.ref.xml org.freedesktop.UPower.KbdBacklight.ref.xml org.freedesktop.UPower.Wakeups.ref.xml
|
||||
|
||||
org.freedesktop.UPower.ref.xml : $(top_srcdir)/src/org.freedesktop.UPower.xml $(top_srcdir)/doc/dbus/spec-to-docbook.xsl
|
||||
echo "<?xml version=\"1.0\"?>""<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.1.2//EN\" \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">" > $@
|
||||
|
|
@ -9,10 +9,6 @@ org.freedesktop.UPower.Device.ref.xml : $(top_srcdir)/src/org.freedesktop.UPower
|
|||
echo "<?xml version=\"1.0\"?>""<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.1.2//EN\" \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">" > $@
|
||||
$(XSLTPROC) $(top_srcdir)/doc/dbus/spec-to-docbook.xsl $< | tail -n +2 >> $@
|
||||
|
||||
org.freedesktop.UPower.QoS.ref.xml : $(top_srcdir)/src/org.freedesktop.UPower.QoS.xml $(top_srcdir)/doc/dbus/spec-to-docbook.xsl
|
||||
echo "<?xml version=\"1.0\"?>""<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.1.2//EN\" \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">" > $@
|
||||
$(XSLTPROC) $(top_srcdir)/doc/dbus/spec-to-docbook.xsl $< | tail -n +2 >> $@
|
||||
|
||||
org.freedesktop.UPower.KbdBacklight.ref.xml : $(top_srcdir)/src/org.freedesktop.UPower.KbdBacklight.xml $(top_srcdir)/doc/dbus/spec-to-docbook.xsl
|
||||
echo "<?xml version=\"1.0\"?>""<!DOCTYPE refentry PUBLIC \"-//OASIS//DTD DocBook XML V4.1.2//EN\" \"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd\">" > $@
|
||||
$(XSLTPROC) $(top_srcdir)/doc/dbus/spec-to-docbook.xsl $< | tail -n +2 >> $@
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@
|
|||
</partintro>
|
||||
<xi:include href="dbus/org.freedesktop.UPower.ref.xml"/>
|
||||
<xi:include href="dbus/org.freedesktop.UPower.Device.ref.xml"/>
|
||||
<xi:include href="dbus/org.freedesktop.UPower.QoS.ref.xml"/>
|
||||
<xi:include href="dbus/org.freedesktop.UPower.KbdBacklight.ref.xml"/>
|
||||
</reference>
|
||||
|
||||
|
|
@ -80,7 +79,6 @@
|
|||
<xi:include href="xml/up-client.xml"/>
|
||||
<xi:include href="xml/up-device.xml"/>
|
||||
<xi:include href="xml/up-history-item.xml"/>
|
||||
<xi:include href="xml/up-qos-item.xml"/>
|
||||
<xi:include href="xml/up-stats-item.xml"/>
|
||||
<xi:include href="xml/up-wakeup-item.xml"/>
|
||||
</reference>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ UPower is an abstraction for enumerating power devices,
|
|||
listening to device events and querying history and statistics.
|
||||
Any application or service on the system can access the
|
||||
<code>org.freedesktop.UPower</code> service via the system message bus.
|
||||
Some operations (such as setting the QoS for the system) are restricted using <a href="http://hal.freedesktop.org/docs/PolicyKit/">PolicyKit</a>.
|
||||
</p>
|
||||
<p>
|
||||
UPower was <a href="http://lists.freedesktop.org/archives/devkit-devel/2009-December/000567.html">
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ libupower_glib_include_HEADERS = \
|
|||
up-version.h \
|
||||
up-types.h \
|
||||
up-device.h \
|
||||
up-qos-item.h \
|
||||
up-wakeup-item.h \
|
||||
up-stats-item.h \
|
||||
up-history-item.h \
|
||||
|
|
@ -34,7 +33,6 @@ libupower_glib_la_SOURCES = \
|
|||
up-types.c \
|
||||
up-client.c \
|
||||
up-wakeups.c \
|
||||
up-qos-item.c \
|
||||
up-wakeup-item.c \
|
||||
up-stats-item.c \
|
||||
up-history-item.c \
|
||||
|
|
|
|||
|
|
@ -1,627 +0,0 @@
|
|||
/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:up-qos-item
|
||||
* @short_description: Helper object representing one item of QOS data.
|
||||
*
|
||||
* This object represents one item of data which may be returned from the
|
||||
* daemon in response to a query.
|
||||
*
|
||||
* See also: #UpDevice, #UpClient
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "up-qos-item.h"
|
||||
|
||||
static void up_qos_item_class_init (UpQosItemClass *klass);
|
||||
static void up_qos_item_init (UpQosItem *qos_item);
|
||||
static void up_qos_item_finalize (GObject *object);
|
||||
|
||||
#define UP_QOS_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_QOS_ITEM, UpQosItemPrivate))
|
||||
|
||||
struct UpQosItemPrivate
|
||||
{
|
||||
guint uid;
|
||||
guint pid;
|
||||
gchar *sender;
|
||||
gchar *cmdline;
|
||||
guint cookie;
|
||||
guint64 timespec;
|
||||
gboolean persistent;
|
||||
UpQosKind type;
|
||||
gint value;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_UID,
|
||||
PROP_PID,
|
||||
PROP_SENDER,
|
||||
PROP_CMDLINE,
|
||||
PROP_COOKIE,
|
||||
PROP_TIMESPEC,
|
||||
PROP_PERSISTENT,
|
||||
PROP_TYPE,
|
||||
PROP_VALUE,
|
||||
PROP_LAST
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (UpQosItem, up_qos_item, G_TYPE_OBJECT)
|
||||
|
||||
|
||||
/**
|
||||
* up_qos_item_get_uid:
|
||||
* @qos_item: #UpQosItem
|
||||
*
|
||||
* Gets the item uid.
|
||||
*
|
||||
* Return value: the value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
guint
|
||||
up_qos_item_get_uid (UpQosItem *qos_item)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), G_MAXUINT);
|
||||
return qos_item->priv->uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_set_uid:
|
||||
* @qos_item: #UpQosItem
|
||||
* @uid: the new value
|
||||
*
|
||||
* Sets the item uid.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
void
|
||||
up_qos_item_set_uid (UpQosItem *qos_item, guint uid)
|
||||
{
|
||||
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
|
||||
qos_item->priv->uid = uid;
|
||||
g_object_notify (G_OBJECT(qos_item), "uid");
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_get_pid:
|
||||
* @qos_item: #UpQosItem
|
||||
*
|
||||
* Gets the item pid.
|
||||
*
|
||||
* Return value: the value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
guint
|
||||
up_qos_item_get_pid (UpQosItem *qos_item)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), G_MAXUINT);
|
||||
return qos_item->priv->pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_set_pid:
|
||||
* @qos_item: #UpQosItem
|
||||
* @pid: the new value
|
||||
*
|
||||
* Sets the item pid.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
void
|
||||
up_qos_item_set_pid (UpQosItem *qos_item, guint pid)
|
||||
{
|
||||
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
|
||||
qos_item->priv->pid = pid;
|
||||
g_object_notify (G_OBJECT(qos_item), "pid");
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_get_sender:
|
||||
* @qos_item: #UpQosItem
|
||||
*
|
||||
* Gets the item sender.
|
||||
*
|
||||
* Return value: the value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
const gchar *
|
||||
up_qos_item_get_sender (UpQosItem *qos_item)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), NULL);
|
||||
return qos_item->priv->sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_set_sender:
|
||||
* @qos_item: #UpQosItem
|
||||
* @sender: the new value
|
||||
*
|
||||
* Sets the item sender.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
void
|
||||
up_qos_item_set_sender (UpQosItem *qos_item, const gchar *sender)
|
||||
{
|
||||
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
|
||||
g_free (qos_item->priv->sender);
|
||||
qos_item->priv->sender = g_strdup (sender);
|
||||
g_object_notify (G_OBJECT(qos_item), "sender");
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_get_cmdline:
|
||||
* @qos_item: #UpQosItem
|
||||
*
|
||||
* Gets the item cmdline.
|
||||
*
|
||||
* Return value: the value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
const gchar *
|
||||
up_qos_item_get_cmdline (UpQosItem *qos_item)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), NULL);
|
||||
return qos_item->priv->cmdline;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_set_cmdline:
|
||||
* @qos_item: #UpQosItem
|
||||
* @cmdline: the new value
|
||||
*
|
||||
* Sets the item cmdline.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
void
|
||||
up_qos_item_set_cmdline (UpQosItem *qos_item, const gchar *cmdline)
|
||||
{
|
||||
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
|
||||
g_free (qos_item->priv->cmdline);
|
||||
qos_item->priv->cmdline = g_strdup (cmdline);
|
||||
g_object_notify (G_OBJECT(qos_item), "cmdline");
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_get_cookie:
|
||||
* @qos_item: #UpQosItem
|
||||
*
|
||||
* Gets the item cookie.
|
||||
*
|
||||
* Return value: the value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
guint
|
||||
up_qos_item_get_cookie (UpQosItem *qos_item)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), G_MAXUINT);
|
||||
return qos_item->priv->cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_set_cookie:
|
||||
* @qos_item: #UpQosItem
|
||||
* @cookie: the new value
|
||||
*
|
||||
* Sets the item cookie.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
void
|
||||
up_qos_item_set_cookie (UpQosItem *qos_item, guint cookie)
|
||||
{
|
||||
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
|
||||
qos_item->priv->cookie = cookie;
|
||||
g_object_notify (G_OBJECT(qos_item), "cookie");
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_get_timespec:
|
||||
* @qos_item: #UpQosItem
|
||||
*
|
||||
* Gets the item timespec.
|
||||
*
|
||||
* Return value: the value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
guint64
|
||||
up_qos_item_get_timespec (UpQosItem *qos_item)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), G_MAXUINT64);
|
||||
return qos_item->priv->timespec;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_set_timespec:
|
||||
* @qos_item: #UpQosItem
|
||||
* @timespec: the new value
|
||||
*
|
||||
* Sets the item timespec.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
void
|
||||
up_qos_item_set_timespec (UpQosItem *qos_item, guint64 timespec)
|
||||
{
|
||||
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
|
||||
qos_item->priv->timespec = timespec;
|
||||
g_object_notify (G_OBJECT(qos_item), "timespec");
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_get_persistent:
|
||||
* @qos_item: #UpQosItem
|
||||
*
|
||||
* Gets the item persistent.
|
||||
*
|
||||
* Return value: the value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
gboolean
|
||||
up_qos_item_get_persistent (UpQosItem *qos_item)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), G_MAXUINT);
|
||||
return qos_item->priv->persistent;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_set_persistent:
|
||||
* @qos_item: #UpQosItem
|
||||
* @persistent: the new value
|
||||
*
|
||||
* Sets the item persistent.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
void
|
||||
up_qos_item_set_persistent (UpQosItem *qos_item, gboolean persistent)
|
||||
{
|
||||
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
|
||||
qos_item->priv->persistent = persistent;
|
||||
g_object_notify (G_OBJECT(qos_item), "persistent");
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_get_kind:
|
||||
* @qos_item: #UpQosItem
|
||||
*
|
||||
* Gets the item type.
|
||||
*
|
||||
* Return value: the value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
UpQosKind
|
||||
up_qos_item_get_kind (UpQosItem *qos_item)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), G_MAXUINT);
|
||||
return qos_item->priv->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_set_kind:
|
||||
* @qos_item: #UpQosItem
|
||||
* @type: the new value
|
||||
*
|
||||
* Sets the item type.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
void
|
||||
up_qos_item_set_kind (UpQosItem *qos_item, UpQosKind type)
|
||||
{
|
||||
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
|
||||
qos_item->priv->type = type;
|
||||
g_object_notify (G_OBJECT(qos_item), "type");
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_get_value:
|
||||
* @qos_item: #UpQosItem
|
||||
*
|
||||
* Gets the item value.
|
||||
*
|
||||
* Return value: the value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
gint
|
||||
up_qos_item_get_value (UpQosItem *qos_item)
|
||||
{
|
||||
g_return_val_if_fail (UP_IS_QOS_ITEM (qos_item), G_MAXINT);
|
||||
return qos_item->priv->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_set_value:
|
||||
* @qos_item: #UpQosItem
|
||||
* @value: the new value
|
||||
*
|
||||
* Sets the item value.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
void
|
||||
up_qos_item_set_value (UpQosItem *qos_item, gint value)
|
||||
{
|
||||
g_return_if_fail (UP_IS_QOS_ITEM (qos_item));
|
||||
qos_item->priv->value = value;
|
||||
g_object_notify (G_OBJECT(qos_item), "value");
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_set_property:
|
||||
**/
|
||||
static void
|
||||
up_qos_item_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
UpQosItem *qos_item = UP_QOS_ITEM (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_UID:
|
||||
qos_item->priv->uid = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_PID:
|
||||
qos_item->priv->pid = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_SENDER:
|
||||
g_free (qos_item->priv->sender);
|
||||
qos_item->priv->sender = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
case PROP_CMDLINE:
|
||||
g_free (qos_item->priv->cmdline);
|
||||
qos_item->priv->cmdline = g_strdup (g_value_get_string (value));
|
||||
break;
|
||||
case PROP_COOKIE:
|
||||
qos_item->priv->cookie = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_TIMESPEC:
|
||||
qos_item->priv->timespec = g_value_get_uint64 (value);
|
||||
break;
|
||||
case PROP_PERSISTENT:
|
||||
qos_item->priv->persistent = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_TYPE:
|
||||
qos_item->priv->type = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_VALUE:
|
||||
qos_item->priv->value = g_value_get_int (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_get_property:
|
||||
**/
|
||||
static void
|
||||
up_qos_item_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
UpQosItem *qos_item = UP_QOS_ITEM (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_UID:
|
||||
g_value_set_uint (value, qos_item->priv->uid);
|
||||
break;
|
||||
case PROP_PID:
|
||||
g_value_set_uint (value, qos_item->priv->pid);
|
||||
break;
|
||||
case PROP_SENDER:
|
||||
g_value_set_string (value, qos_item->priv->sender);
|
||||
break;
|
||||
case PROP_CMDLINE:
|
||||
g_value_set_string (value, qos_item->priv->cmdline);
|
||||
break;
|
||||
case PROP_COOKIE:
|
||||
g_value_set_uint (value, qos_item->priv->cookie);
|
||||
break;
|
||||
case PROP_TIMESPEC:
|
||||
g_value_set_uint64 (value, qos_item->priv->timespec);
|
||||
break;
|
||||
case PROP_PERSISTENT:
|
||||
g_value_set_boolean (value, qos_item->priv->persistent);
|
||||
break;
|
||||
case PROP_TYPE:
|
||||
g_value_set_uint (value, qos_item->priv->type);
|
||||
break;
|
||||
case PROP_VALUE:
|
||||
g_value_set_int (value, qos_item->priv->value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_class_init:
|
||||
* @klass: The UpQosItemClass
|
||||
**/
|
||||
static void
|
||||
up_qos_item_class_init (UpQosItemClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
object_class->finalize = up_qos_item_finalize;
|
||||
object_class->set_property = up_qos_item_set_property;
|
||||
object_class->get_property = up_qos_item_get_property;
|
||||
|
||||
/**
|
||||
* UpQosItem:uid:
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_UID,
|
||||
g_param_spec_uint ("uid", NULL, NULL,
|
||||
0, G_MAXUINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpQosItem:pid:
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_PID,
|
||||
g_param_spec_uint ("pid", NULL, NULL,
|
||||
0, G_MAXUINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpQosItem:sender:
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_SENDER,
|
||||
g_param_spec_string ("sender", NULL, NULL,
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpQosItem:cmdline:
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_CMDLINE,
|
||||
g_param_spec_string ("cmdline", NULL, NULL,
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpQosItem:cookie:
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_COOKIE,
|
||||
g_param_spec_uint ("cookie", NULL, NULL,
|
||||
0, G_MAXUINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpQosItem:timespec:
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_TIMESPEC,
|
||||
g_param_spec_uint64 ("timespec", NULL, NULL,
|
||||
0, G_MAXUINT64, 0,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpQosItem:persistent:
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_PERSISTENT,
|
||||
g_param_spec_boolean ("persistent", NULL, NULL,
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpQosItem:type:
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_TYPE,
|
||||
g_param_spec_uint ("type", NULL, NULL,
|
||||
0, G_MAXUINT, UP_QOS_KIND_UNKNOWN,
|
||||
G_PARAM_READWRITE));
|
||||
/**
|
||||
* UpQosItem:value:
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_VALUE,
|
||||
g_param_spec_int ("value", NULL, NULL,
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_type_class_add_private (klass, sizeof (UpQosItemPrivate));
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_init:
|
||||
* @qos_item: This class instance
|
||||
**/
|
||||
static void
|
||||
up_qos_item_init (UpQosItem *qos_item)
|
||||
{
|
||||
qos_item->priv = UP_QOS_ITEM_GET_PRIVATE (qos_item);
|
||||
qos_item->priv->value = 0.0f;
|
||||
qos_item->priv->uid = 0;
|
||||
qos_item->priv->pid = 0;
|
||||
qos_item->priv->sender = NULL;
|
||||
qos_item->priv->cmdline = NULL;
|
||||
qos_item->priv->cookie = 0;
|
||||
qos_item->priv->timespec = 0;
|
||||
qos_item->priv->persistent = FALSE;
|
||||
qos_item->priv->type = UP_QOS_KIND_UNKNOWN;
|
||||
qos_item->priv->value = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_finalize:
|
||||
* @object: The object to finalize
|
||||
**/
|
||||
static void
|
||||
up_qos_item_finalize (GObject *object)
|
||||
{
|
||||
UpQosItem *qos_item;
|
||||
|
||||
g_return_if_fail (UP_IS_QOS_ITEM (object));
|
||||
|
||||
qos_item = UP_QOS_ITEM (object);
|
||||
|
||||
g_free (qos_item->priv->sender);
|
||||
g_free (qos_item->priv->cmdline);
|
||||
|
||||
G_OBJECT_CLASS (up_qos_item_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_item_new:
|
||||
*
|
||||
* Return value: a new UpQosItem object.
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
UpQosItem *
|
||||
up_qos_item_new (void)
|
||||
{
|
||||
UpQosItem *qos_item;
|
||||
qos_item = g_object_new (UP_TYPE_QOS_ITEM, NULL);
|
||||
return UP_QOS_ITEM (qos_item);
|
||||
}
|
||||
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/* -*- 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#if !defined (__UPOWER_H_INSIDE__) && !defined (UP_COMPILATION)
|
||||
#error "Only <upower.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __UP_QOS_ITEM_H
|
||||
#define __UP_QOS_ITEM_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <libupower-glib/up-types.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define UP_TYPE_QOS_ITEM (up_qos_item_get_type ())
|
||||
#define UP_QOS_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UP_TYPE_QOS_ITEM, UpQosItem))
|
||||
#define UP_QOS_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UP_TYPE_QOS_ITEM, UpQosItemClass))
|
||||
#define UP_IS_QOS_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UP_TYPE_QOS_ITEM))
|
||||
#define UP_IS_QOS_ITEM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UP_TYPE_QOS_ITEM))
|
||||
#define UP_QOS_ITEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UP_TYPE_QOS_ITEM, UpQosItemClass))
|
||||
|
||||
typedef struct UpQosItemPrivate UpQosItemPrivate;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObject parent;
|
||||
UpQosItemPrivate *priv;
|
||||
} UpQosItem;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
} UpQosItemClass;
|
||||
|
||||
GType up_qos_item_get_type (void);
|
||||
UpQosItem *up_qos_item_new (void);
|
||||
|
||||
/* accessors */
|
||||
guint up_qos_item_get_uid (UpQosItem *qos_item);
|
||||
void up_qos_item_set_uid (UpQosItem *qos_item,
|
||||
guint uid);
|
||||
guint up_qos_item_get_pid (UpQosItem *qos_item);
|
||||
void up_qos_item_set_pid (UpQosItem *qos_item,
|
||||
guint pid);
|
||||
const gchar *up_qos_item_get_sender (UpQosItem *qos_item);
|
||||
void up_qos_item_set_sender (UpQosItem *qos_item,
|
||||
const gchar *sender);
|
||||
const gchar *up_qos_item_get_cmdline (UpQosItem *qos_item);
|
||||
void up_qos_item_set_cmdline (UpQosItem *qos_item,
|
||||
const gchar *cmdline);
|
||||
guint up_qos_item_get_cookie (UpQosItem *qos_item);
|
||||
void up_qos_item_set_cookie (UpQosItem *qos_item,
|
||||
guint cookie);
|
||||
guint64 up_qos_item_get_timespec (UpQosItem *qos_item);
|
||||
void up_qos_item_set_timespec (UpQosItem *qos_item,
|
||||
guint64 timespec);
|
||||
gboolean up_qos_item_get_persistent (UpQosItem *qos_item);
|
||||
void up_qos_item_set_persistent (UpQosItem *qos_item,
|
||||
gboolean persistent);
|
||||
UpQosKind up_qos_item_get_kind (UpQosItem *qos_item);
|
||||
void up_qos_item_set_kind (UpQosItem *qos_item,
|
||||
UpQosKind type);
|
||||
gint up_qos_item_get_value (UpQosItem *qos_item);
|
||||
void up_qos_item_set_value (UpQosItem *qos_item,
|
||||
gint value);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __UP_QOS_ITEM_H */
|
||||
|
||||
|
|
@ -232,41 +232,3 @@ up_device_technology_from_string (const gchar *technology)
|
|||
return UP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE;
|
||||
return UP_DEVICE_TECHNOLOGY_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_kind_to_string:
|
||||
*
|
||||
* Converts a #UpQosKind to a string.
|
||||
*
|
||||
* Return value: identifier string
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
const gchar *
|
||||
up_qos_kind_to_string (UpQosKind type)
|
||||
{
|
||||
if (type == UP_QOS_KIND_NETWORK)
|
||||
return "network";
|
||||
if (type == UP_QOS_KIND_CPU_DMA)
|
||||
return "cpu_dma";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_kind_from_string:
|
||||
*
|
||||
* Converts a string to a #UpQosKind.
|
||||
*
|
||||
* Return value: enumerated value
|
||||
*
|
||||
* Since: 0.9.0
|
||||
**/
|
||||
UpQosKind
|
||||
up_qos_kind_from_string (const gchar *type)
|
||||
{
|
||||
if (g_strcmp0 (type, "network") == 0)
|
||||
return UP_QOS_KIND_NETWORK;
|
||||
if (g_strcmp0 (type, "cpu_dma") == 0)
|
||||
return UP_QOS_KIND_CPU_DMA;
|
||||
return UP_QOS_KIND_UNKNOWN;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,26 +83,12 @@ typedef enum {
|
|||
UP_DEVICE_TECHNOLOGY_LAST
|
||||
} UpDeviceTechnology;
|
||||
|
||||
/**
|
||||
* UpQosKind:
|
||||
*
|
||||
* The type of QOS request.
|
||||
**/
|
||||
typedef enum {
|
||||
UP_QOS_KIND_UNKNOWN,
|
||||
UP_QOS_KIND_NETWORK,
|
||||
UP_QOS_KIND_CPU_DMA,
|
||||
UP_QOS_KIND_LAST
|
||||
} UpQosKind;
|
||||
|
||||
const gchar *up_device_kind_to_string (UpDeviceKind type_enum);
|
||||
const gchar *up_device_state_to_string (UpDeviceState state_enum);
|
||||
const gchar *up_device_technology_to_string (UpDeviceTechnology technology_enum);
|
||||
UpDeviceKind up_device_kind_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_kind_to_string (UpQosKind type);
|
||||
UpQosKind up_qos_kind_from_string (const gchar *type);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@
|
|||
#include <libupower-glib/up-types.h>
|
||||
#include <libupower-glib/up-client.h>
|
||||
#include <libupower-glib/up-device.h>
|
||||
#include <libupower-glib/up-qos-item.h>
|
||||
#include <libupower-glib/up-history-item.h>
|
||||
#include <libupower-glib/up-stats-item.h>
|
||||
#include <libupower-glib/up-wakeup-item.h>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
# List of source files containing translatable strings.
|
||||
# Please keep this file sorted alphabetically.
|
||||
[encoding: UTF-8]
|
||||
policy/org.freedesktop.upower.qos.policy.in
|
||||
src/up-main.c
|
||||
tools/up-tool.c
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
polkit_policydir = $(datadir)/polkit-1/actions
|
||||
polkit_policy_DATA = \
|
||||
org.freedesktop.upower.qos.policy
|
||||
|
||||
# You will need a recent intltool or the patch from this bug
|
||||
# http://bugzilla.gnome.org/show_bug.cgi?id=462312
|
||||
@INTLTOOL_POLICY_RULE@
|
||||
|
||||
EXTRA_DIST = \
|
||||
org.freedesktop.upower.qos.policy.in
|
||||
|
||||
DISTCLEANFILES = \
|
||||
org.freedesktop.upower.qos.policy
|
||||
|
||||
clean-local :
|
||||
rm -f *~
|
||||
|
||||
-include $(top_srcdir)/git.mk
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!DOCTYPE policyconfig PUBLIC
|
||||
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
|
||||
|
||||
<!--
|
||||
Policy definitions for UPower
|
||||
|
||||
Copyright (c) 2008 David Zeuthen <david@fubar.dk>
|
||||
Copyright (c) 2008-2010 Richard Hughes <richard@hughsie.com>
|
||||
|
||||
NOTE: If you make changes to this file, make sure to validate the file
|
||||
using the polkit-policy-file-validate(1) tool. Changes made to this
|
||||
file are instantly applied.
|
||||
-->
|
||||
|
||||
<policyconfig>
|
||||
<vendor>The UPower Project</vendor>
|
||||
<vendor_url>http://upower.freedesktop.org/</vendor_url>
|
||||
<icon_name>system-suspend</icon_name>
|
||||
|
||||
<action id="org.freedesktop.upower.qos.request-latency">
|
||||
<_description>Set the required latency of an application</_description>
|
||||
<_message>Authentication is required to set the required latency of an application</_message>
|
||||
<defaults>
|
||||
<allow_inactive>no</allow_inactive>
|
||||
<allow_active>yes</allow_active>
|
||||
</defaults>
|
||||
</action>
|
||||
|
||||
<action id="org.freedesktop.upower.qos.request-latency-persistent">
|
||||
<_description>Set a persistent latency setting</_description>
|
||||
<_message>Authentication is required to set a persistent latency setting</_message>
|
||||
<defaults>
|
||||
<allow_inactive>no</allow_inactive>
|
||||
<allow_active>yes</allow_active>
|
||||
</defaults>
|
||||
</action>
|
||||
|
||||
<action id="org.freedesktop.upower.qos.set-minimum-latency">
|
||||
<_description>Set administrator settings for latency control</_description>
|
||||
<_message>Authentication is required to set administrator settings for latency control</_message>
|
||||
<defaults>
|
||||
<allow_inactive>no</allow_inactive>
|
||||
<allow_active>auth_admin</allow_active>
|
||||
</defaults>
|
||||
</action>
|
||||
|
||||
<action id="org.freedesktop.upower.qos.cancel-request">
|
||||
<_description>Cancel a latency request</_description>
|
||||
<_message>Authentication is required to cancel a latency request</_message>
|
||||
<defaults>
|
||||
<allow_inactive>no</allow_inactive>
|
||||
<allow_active>auth_admin</allow_active>
|
||||
</defaults>
|
||||
</action>
|
||||
|
||||
</policyconfig>
|
||||
|
|
@ -29,7 +29,6 @@ UPOWER_LIBS = $(top_builddir)/libupower-glib/libupower-glib.la
|
|||
BUILT_SOURCES = \
|
||||
up-daemon-glue.h \
|
||||
up-device-glue.h \
|
||||
up-qos-glue.h \
|
||||
up-kbd-backlight-glue.h \
|
||||
up-wakeups-glue.h \
|
||||
up-marshal.h \
|
||||
|
|
@ -47,9 +46,6 @@ up-daemon-glue.h: org.freedesktop.UPower.xml Makefile.am
|
|||
up-device-glue.h: org.freedesktop.UPower.Device.xml Makefile.am
|
||||
dbus-binding-tool --prefix=up_device --mode=glib-server --output=up-device-glue.h $(srcdir)/org.freedesktop.UPower.Device.xml
|
||||
|
||||
up-qos-glue.h: org.freedesktop.UPower.QoS.xml Makefile.am
|
||||
dbus-binding-tool --prefix=up_qos --mode=glib-server --output=up-qos-glue.h $(srcdir)/org.freedesktop.UPower.QoS.xml
|
||||
|
||||
up-kbd-backlight-glue.h: org.freedesktop.UPower.KbdBacklight.xml Makefile.am
|
||||
dbus-binding-tool --prefix=up_kbd_backlight --mode=glib-server --output=up-kbd-backlight-glue.h $(srcdir)/org.freedesktop.UPower.KbdBacklight.xml
|
||||
|
||||
|
|
@ -62,7 +58,6 @@ dbusifdir = $(datadir)/dbus-1/interfaces
|
|||
dbusif_DATA = \
|
||||
org.freedesktop.UPower.xml \
|
||||
org.freedesktop.UPower.Device.xml \
|
||||
org.freedesktop.UPower.QoS.xml \
|
||||
org.freedesktop.UPower.KbdBacklight.xml \
|
||||
org.freedesktop.UPower.Wakeups.xml
|
||||
|
||||
|
|
@ -75,8 +70,6 @@ upowerd_SOURCES = \
|
|||
up-device.c \
|
||||
up-device-list.h \
|
||||
up-device-list.c \
|
||||
up-qos.h \
|
||||
up-qos.c \
|
||||
up-config.h \
|
||||
up-config.c \
|
||||
up-kbd-backlight.h \
|
||||
|
|
@ -157,8 +150,6 @@ up_self_test_SOURCES = \
|
|||
up-device.c \
|
||||
up-device-list.h \
|
||||
up-device-list.c \
|
||||
up-qos.h \
|
||||
up-qos.c \
|
||||
up-kbd-backlight.h \
|
||||
up-kbd-backlight.c \
|
||||
up-wakeups.h \
|
||||
|
|
@ -223,7 +214,6 @@ MAINTAINERCLEANFILES = \
|
|||
EXTRA_DIST = \
|
||||
org.freedesktop.UPower.xml \
|
||||
org.freedesktop.UPower.Device.xml \
|
||||
org.freedesktop.UPower.QoS.xml \
|
||||
org.freedesktop.UPower.KbdBacklight.xml \
|
||||
org.freedesktop.UPower.Wakeups.xml \
|
||||
up-marshal.list \
|
||||
|
|
|
|||
|
|
@ -1,331 +0,0 @@
|
|||
<!DOCTYPE node PUBLIC
|
||||
"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" [
|
||||
<!ENTITY ERROR_GENERAL "org.freedesktop.UPower.GeneralError">
|
||||
]>
|
||||
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
|
||||
<interface name="org.freedesktop.UPower.QoS">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
org.freedesktop.UPower.QoS is a DBus interface implemented
|
||||
by UPower.
|
||||
It allows applications to request latencies, for example a couple of seconds
|
||||
for an IM application, or a few hundred microseconds for a multiplayer game.
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
Use cases:
|
||||
</doc:para>
|
||||
<doc:itemizedlist>
|
||||
<doc:listitem>
|
||||
<doc:para>
|
||||
I want my IM application to request 0.5s latency for messages.
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
I'm running an OpenGL simulation and want maximum performance,
|
||||
even when on battery power.
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
I'm running an SQL server for a credit card company, and want the
|
||||
server to request low latency CPU and network as any delay costs money.
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
I'm an admin, and want to change the power consumption vs. latency
|
||||
from cron scripts so it uses high latency during the night for
|
||||
maximum power saving, and low latency during business hours.
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
I want high throughput when copying files, but want low throughput
|
||||
for downloading updates in the background.
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
I want my power manager to set all latencies to lowest when on
|
||||
AC power.
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
I don't want my users messing with latency settings.
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
I'm and admin and I want to be able to override all latency
|
||||
settings on my machines.
|
||||
</doc:para>
|
||||
</doc:listitem>
|
||||
</doc:itemizedlist>
|
||||
<doc:para>
|
||||
Why don't applications use the PMQoS interface directly?
|
||||
By providing a framework we can override requests by policy, and also
|
||||
control requests from random services.
|
||||
You also can't set latencies unless you're the root user, which is not
|
||||
suitable for the desktop use case.
|
||||
</doc:para>
|
||||
<doc:para>
|
||||
Of course, you can do if you really want, but then you loose the
|
||||
benefits of the query interface and the policy override,
|
||||
and have to run your application as root.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
<method name="SetMinimumLatency">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
<arg name="type" direction="in" type="s">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
The type of latency to control, <doc:tt>cpu_dma</doc:tt> or
|
||||
<doc:tt>network</doc:tt>.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<arg name="value" direction="in" type="i">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
The value, in microseconds or kilobits per second.
|
||||
The value <doc:tt>-1</doc:tt> means unset and the default is used.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Set the minimum acceptable latency of the system.
|
||||
Setting this value tells the system to not attempt latencies below this setting.
|
||||
This may be useful in a data center or server room, when you want to override the
|
||||
latency requests from applications.
|
||||
This may be required if the server room is operating outside a standard thermal
|
||||
or power envelope, and an override is required.
|
||||
You do not have to use this method during normal operation.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
<doc:permission>Callers need the <doc:tt>org.freedesktop.upower.qos.set-minimum-latency</doc:tt> authorization</doc:permission>
|
||||
<doc:errors>
|
||||
<doc:error name="&ERROR_GENERAL;">if an error occured while setting the latency</doc:error>
|
||||
</doc:errors>
|
||||
</doc:doc>
|
||||
</method>
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
<method name="RequestLatency">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
<arg name="type" direction="in" type="s">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
The type of latency to control, <doc:tt>cpu_dma</doc:tt> or
|
||||
<doc:tt>network</doc:tt>.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<arg name="value" direction="in" type="i">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
The value, in microseconds or kilobits per second.
|
||||
The value <doc:tt>-1</doc:tt> means remove all latency requirements.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<arg name="persistent" direction="in" type="b">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
If the latency request outlives the connection.
|
||||
When the application issuing the request disconnects from the system
|
||||
bus, the latency request is automatically cleaned up.
|
||||
By setting this flag to TRUE, the request is not cleaned up when
|
||||
the client disconnects, and the cookie is preserved acress reboots.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<arg name="cookie" direction="out" type="u">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
A cookie that identifies the request. This allows an application or
|
||||
service to request multiple latency settings from one process, and for
|
||||
other processes to cancel requests.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Set the required latency of an application or service.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
<doc:permission>
|
||||
Callers need the
|
||||
<doc:tt>org.freedesktop.upower.qos.request-latency-persistent</doc:tt>
|
||||
authorization if <doc:tt>persistent</doc:tt> is TRUE, or
|
||||
<doc:tt>org.freedesktop.upower.qos.request-latency</doc:tt> otherwise.
|
||||
</doc:permission>
|
||||
<doc:errors>
|
||||
<doc:error name="&ERROR_GENERAL;">if an error occured while setting the latency</doc:error>
|
||||
</doc:errors>
|
||||
</doc:doc>
|
||||
</method>
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
<method name="CancelRequest">
|
||||
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
|
||||
<arg name="cookie" direction="in" type="u">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
A cookie that identifies the request. This allows an application or
|
||||
serivice to request multiple latency settings from one process.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Cancel the latency request from the application or service.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
<doc:permission>
|
||||
Callers need the
|
||||
<doc:tt>org.freedesktop.upower.qos.cancel-request</doc:tt>
|
||||
authorization if they were not the one issuing the request.
|
||||
</doc:permission>
|
||||
<doc:errors>
|
||||
<doc:error name="&ERROR_GENERAL;">if an error occured while clearing the latency</doc:error>
|
||||
</doc:errors>
|
||||
</doc:doc>
|
||||
</method>
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
<method name="GetLatency">
|
||||
<arg name="type" direction="in" type="s">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
The type of latency to return, <doc:tt>cpu_dma</doc:tt> or
|
||||
<doc:tt>network</doc:tt>.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<arg name="value" direction="out" type="i">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
The value, in microseconds or kilobits per second.
|
||||
The value <doc:tt>-1</doc:tt> means not set or unavailable.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Get the lowest latency state on the system at the current time.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
<doc:errors>
|
||||
<doc:error name="&ERROR_GENERAL;">if an error occured while getting the latency</doc:error>
|
||||
</doc:errors>
|
||||
</doc:doc>
|
||||
</method>
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
<signal name="LatencyChanged">
|
||||
<arg name="type" direction="out" type="s">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
The type of latency that changed, <doc:tt>cpu_dma</doc:tt> or
|
||||
<doc:tt>network</doc:tt>.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<arg name="value" direction="out" type="i">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
The value, in microseconds or kilobits per second.
|
||||
The value <doc:tt>-1</doc:tt> means not set or unavailable.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Some latency value has changed.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</signal>
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
<method name="GetLatencyRequests">
|
||||
<arg name="requests" direction="out" type="a(uuusxbssi)">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
The request lists, where each application can request different
|
||||
latency types.
|
||||
<doc:list>
|
||||
<doc:item>
|
||||
<doc:term>cookie</doc:term>
|
||||
<doc:definition>
|
||||
The random cookie that identifies the request.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>uid</doc:term>
|
||||
<doc:definition>
|
||||
The user ID that issued the request.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>pid</doc:term>
|
||||
<doc:definition>
|
||||
The process ID of the application.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>exec</doc:term>
|
||||
<doc:definition>
|
||||
The executable that issued the request.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>timespec</doc:term>
|
||||
<doc:definition>
|
||||
The number of seconds since the epoch.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>persistent</doc:term>
|
||||
<doc:definition>
|
||||
If the request is persistent and outlives the connection lifetime.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>type</doc:term>
|
||||
<doc:definition>
|
||||
The type of the request, <doc:tt>cpu_dma</doc:tt> or
|
||||
<doc:tt>network</doc:tt>.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
<doc:item>
|
||||
<doc:term>value</doc:term>
|
||||
<doc:definition>
|
||||
The value, in microseconds or kilobits per second.
|
||||
</doc:definition>
|
||||
</doc:item>
|
||||
</doc:list>
|
||||
</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
Gets all the system requests from all services and applications.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</method>
|
||||
|
||||
<!-- ************************************************************ -->
|
||||
<signal name="RequestsChanged">
|
||||
<doc:doc>
|
||||
<doc:description>
|
||||
<doc:para>
|
||||
The latency requests on the system have changed.
|
||||
</doc:para>
|
||||
</doc:description>
|
||||
</doc:doc>
|
||||
</signal>
|
||||
|
||||
</interface>
|
||||
|
||||
</node>
|
||||
|
|
@ -19,8 +19,6 @@
|
|||
send_interface="org.freedesktop.DBus.Properties"/>
|
||||
<allow send_destination="org.freedesktop.UPower.Device"
|
||||
send_interface="org.freedesktop.DBus.Properties"/>
|
||||
<allow send_destination="org.freedesktop.UPower.QoS"
|
||||
send_interface="org.freedesktop.DBus.Properties"/>
|
||||
<allow send_destination="org.freedesktop.UPower.KbdBacklight"
|
||||
send_interface="org.freedesktop.DBus.Properties"/>
|
||||
<allow send_destination="org.freedesktop.UPower.Wakeups"
|
||||
|
|
@ -30,8 +28,6 @@
|
|||
send_interface="org.freedesktop.UPower"/>
|
||||
<allow send_destination="org.freedesktop.UPower"
|
||||
send_interface="org.freedesktop.UPower.Device"/>
|
||||
<allow send_destination="org.freedesktop.UPower"
|
||||
send_interface="org.freedesktop.UPower.QoS"/>
|
||||
<allow send_destination="org.freedesktop.UPower"
|
||||
send_interface="org.freedesktop.UPower.KbdBacklight"/>
|
||||
<allow send_destination="org.freedesktop.UPower"
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@
|
|||
#include <dbus/dbus-glib-lowlevel.h>
|
||||
|
||||
#include "up-daemon.h"
|
||||
#include "up-qos.h"
|
||||
#include "up-kbd-backlight.h"
|
||||
#include "up-wakeups.h"
|
||||
|
||||
|
|
@ -180,7 +179,6 @@ main (gint argc, gchar **argv)
|
|||
{
|
||||
GError *error = NULL;
|
||||
UpDaemon *daemon = NULL;
|
||||
UpQos *qos = NULL;
|
||||
UpKbdBacklight *kbd_backlight = NULL;
|
||||
UpWakeups *wakeups = NULL;
|
||||
GOptionContext *context;
|
||||
|
|
@ -284,7 +282,6 @@ main (gint argc, gchar **argv)
|
|||
|
||||
g_debug ("Starting upowerd version %s", PACKAGE_VERSION);
|
||||
|
||||
qos = up_qos_new ();
|
||||
kbd_backlight = up_kbd_backlight_new ();
|
||||
wakeups = up_wakeups_new ();
|
||||
daemon = up_daemon_new ();
|
||||
|
|
@ -311,8 +308,6 @@ main (gint argc, gchar **argv)
|
|||
g_main_loop_run (loop);
|
||||
retval = 0;
|
||||
out:
|
||||
if (qos != NULL)
|
||||
g_object_unref (qos);
|
||||
if (kbd_backlight != NULL)
|
||||
g_object_unref (kbd_backlight);
|
||||
if (wakeups != NULL)
|
||||
|
|
|
|||
641
src/up-qos.c
641
src/up-qos.c
|
|
@ -1,641 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
#include <dbus/dbus-glib-lowlevel.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "up-qos.h"
|
||||
#include "up-marshal.h"
|
||||
#include "up-daemon.h"
|
||||
#include "up-polkit.h"
|
||||
#include "up-qos-item.h"
|
||||
#include "up-qos-glue.h"
|
||||
#include "up-types.h"
|
||||
|
||||
static void up_qos_finalize (GObject *object);
|
||||
|
||||
#define UP_QOS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_QOS, UpQosPrivate))
|
||||
|
||||
#define UP_QOS_REQUESTS_STRUCT_TYPE (dbus_g_type_get_struct ("GValueArray", \
|
||||
G_TYPE_UINT, \
|
||||
G_TYPE_UINT, \
|
||||
G_TYPE_UINT, \
|
||||
G_TYPE_STRING, \
|
||||
G_TYPE_UINT64, \
|
||||
G_TYPE_BOOLEAN, \
|
||||
G_TYPE_STRING, \
|
||||
G_TYPE_INT, \
|
||||
G_TYPE_INVALID))
|
||||
|
||||
struct UpQosPrivate
|
||||
{
|
||||
GPtrArray *data;
|
||||
gint fd[UP_QOS_KIND_LAST];
|
||||
gint last[UP_QOS_KIND_LAST];
|
||||
gint minimum[UP_QOS_KIND_LAST];
|
||||
UpPolkit *polkit;
|
||||
DBusGConnection *connection;
|
||||
DBusGProxy *proxy;
|
||||
};
|
||||
|
||||
enum {
|
||||
LATENCY_CHANGED,
|
||||
REQUESTS_CHANGED,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals [LAST_SIGNAL] = { 0 };
|
||||
|
||||
G_DEFINE_TYPE (UpQos, up_qos, G_TYPE_OBJECT)
|
||||
|
||||
/**
|
||||
* up_qos_find_from_cookie:
|
||||
**/
|
||||
static UpQosItem *
|
||||
up_qos_find_from_cookie (UpQos *qos, guint32 cookie)
|
||||
{
|
||||
guint i;
|
||||
GPtrArray *data;
|
||||
UpQosItem *item;
|
||||
|
||||
/* search list */
|
||||
data = qos->priv->data;
|
||||
for (i=0; i<data->len; i++) {
|
||||
item = g_ptr_array_index (data, i);
|
||||
if (up_qos_item_get_cookie (item) == cookie)
|
||||
return item;
|
||||
}
|
||||
|
||||
/* nothing found */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_generate_cookie:
|
||||
*
|
||||
* Return value: a random cookie not already allocated
|
||||
**/
|
||||
static guint32
|
||||
up_qos_generate_cookie (UpQos *qos)
|
||||
{
|
||||
guint32 cookie;
|
||||
|
||||
/* iterate until we have a unique cookie */
|
||||
do {
|
||||
cookie = (guint32) g_random_int_range (1, G_MAXINT32);
|
||||
} while (up_qos_find_from_cookie (qos, cookie) != NULL);
|
||||
|
||||
return cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_get_lowest:
|
||||
**/
|
||||
static gint
|
||||
up_qos_get_lowest (UpQos *qos, UpQosKind type)
|
||||
{
|
||||
guint i;
|
||||
gint lowest = G_MAXINT;
|
||||
GPtrArray *data;
|
||||
UpQosItem *item;
|
||||
|
||||
/* find lowest */
|
||||
data = qos->priv->data;
|
||||
for (i=0; i<data->len; i++) {
|
||||
item = g_ptr_array_index (data, i);
|
||||
if (up_qos_item_get_kind (item) == type &&
|
||||
up_qos_item_get_value (item) > 0 &&
|
||||
up_qos_item_get_value (item) < lowest)
|
||||
lowest = up_qos_item_get_value (item);
|
||||
}
|
||||
|
||||
/* over-ride */
|
||||
if (lowest < qos->priv->minimum[type]) {
|
||||
g_debug ("minium override from %i to %i", lowest, qos->priv->minimum[type]);
|
||||
lowest = qos->priv->minimum[type];
|
||||
}
|
||||
|
||||
/* no requests */
|
||||
if (lowest == G_MAXINT)
|
||||
lowest = -1;
|
||||
|
||||
return lowest;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_latency_write:
|
||||
**/
|
||||
static gboolean
|
||||
up_qos_latency_write (UpQos *qos, UpQosKind type, gint value)
|
||||
{
|
||||
gchar *text = NULL;
|
||||
gint retval;
|
||||
gint length;
|
||||
gboolean ret = TRUE;
|
||||
|
||||
/* write new values to pm-qos */
|
||||
if (qos->priv->fd[type] < 0) {
|
||||
g_warning ("cannot write to pm-qos as file not open");
|
||||
ret = FALSE;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* convert to text */
|
||||
text = g_strdup_printf ("%i", value);
|
||||
length = strlen (text);
|
||||
|
||||
/* write to device file */
|
||||
retval = write (qos->priv->fd[type], text, length);
|
||||
if (retval != length) {
|
||||
g_warning ("writing '%s' to device failed", text);
|
||||
ret = FALSE;
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
g_free (text);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_latency_perhaps_changed:
|
||||
**/
|
||||
static gboolean
|
||||
up_qos_latency_perhaps_changed (UpQos *qos, UpQosKind type)
|
||||
{
|
||||
gint lowest;
|
||||
gint *last;
|
||||
|
||||
/* re-find the lowest value */
|
||||
lowest = up_qos_get_lowest (qos, type);
|
||||
|
||||
/* find the last value */
|
||||
last = &qos->priv->last[type];
|
||||
|
||||
/* same value? */
|
||||
if (*last == lowest)
|
||||
return FALSE;
|
||||
|
||||
/* write to file */
|
||||
up_qos_latency_write (qos, type, lowest);
|
||||
|
||||
/* emit signal */
|
||||
g_signal_emit (qos, signals [LATENCY_CHANGED], 0, up_qos_kind_to_string (type), lowest);
|
||||
*last = lowest;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_get_cmdline:
|
||||
**/
|
||||
static gchar *
|
||||
up_qos_get_cmdline (gint pid)
|
||||
{
|
||||
gboolean ret;
|
||||
gchar *filename = NULL;
|
||||
gchar *cmdline = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
/* get command line from proc */
|
||||
filename = g_strdup_printf ("/proc/%i/cmdline", pid);
|
||||
ret = g_file_get_contents (filename, &cmdline, NULL, &error);
|
||||
if (!ret) {
|
||||
g_warning ("failed to get cmdline: %s", error->message);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
g_free (filename);
|
||||
return cmdline;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_request_latency:
|
||||
*
|
||||
* Return value: a new random cookie
|
||||
**/
|
||||
void
|
||||
up_qos_request_latency (UpQos *qos, const gchar *type_text, gint value, gboolean persistent, DBusGMethodInvocation *context)
|
||||
{
|
||||
UpQosItem *item;
|
||||
gchar *sender = NULL;
|
||||
const gchar *auth;
|
||||
gchar *cmdline = NULL;
|
||||
GError *error;
|
||||
guint uid;
|
||||
gint pid;
|
||||
PolkitSubject *subject = NULL;
|
||||
gboolean retval;
|
||||
UpQosKind type;
|
||||
|
||||
/* get correct data */
|
||||
type = up_qos_kind_from_string (type_text);
|
||||
if (type == UP_QOS_KIND_UNKNOWN) {
|
||||
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "type invalid: %s", type_text);
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* as we are async, we can get the sender */
|
||||
sender = dbus_g_method_get_sender (context);
|
||||
if (sender == NULL) {
|
||||
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "no DBUS sender");
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* get the subject */
|
||||
subject = up_polkit_get_subject (qos->priv->polkit, context);
|
||||
if (subject == NULL)
|
||||
goto out;
|
||||
|
||||
/* check auth */
|
||||
if (persistent)
|
||||
auth = "org.freedesktop.upower.qos.request-latency-persistent";
|
||||
else
|
||||
auth = "org.freedesktop.upower.qos.request-latency";
|
||||
if (!up_polkit_check_auth (qos->priv->polkit, subject, auth, context))
|
||||
goto out;
|
||||
|
||||
/* get uid */
|
||||
retval = up_polkit_get_uid (qos->priv->polkit, subject, &uid);
|
||||
if (!retval) {
|
||||
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "cannot get UID");
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* get pid */
|
||||
retval = up_polkit_get_pid (qos->priv->polkit, subject, &pid);
|
||||
if (!retval) {
|
||||
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "cannot get PID");
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* get command line */
|
||||
cmdline = up_qos_get_cmdline (pid);
|
||||
if (cmdline == NULL) {
|
||||
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "cannot get cmdline");
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* seems okay, add to list */
|
||||
item = up_qos_item_new ();
|
||||
up_qos_item_set_cookie (item, up_qos_generate_cookie (qos));
|
||||
up_qos_item_set_sender (item, sender);
|
||||
up_qos_item_set_value (item, value);
|
||||
up_qos_item_set_uid (item, uid);
|
||||
up_qos_item_set_pid (item, pid);
|
||||
up_qos_item_set_cmdline (item, cmdline);
|
||||
up_qos_item_set_persistent (item, persistent);
|
||||
up_qos_item_set_kind (item, type);
|
||||
g_ptr_array_add (qos->priv->data, item);
|
||||
|
||||
g_debug ("Recieved Qos from '%s' (%i:%i)' saving as #%i",
|
||||
up_qos_item_get_sender (item),
|
||||
up_qos_item_get_value (item),
|
||||
up_qos_item_get_persistent (item),
|
||||
up_qos_item_get_cookie (item));
|
||||
|
||||
/* TODO: if persistent add to datadase */
|
||||
|
||||
/* only emit event on the first one */
|
||||
up_qos_latency_perhaps_changed (qos, type);
|
||||
dbus_g_method_return (context, up_qos_item_get_cookie (item));
|
||||
out:
|
||||
if (subject != NULL)
|
||||
g_object_unref (subject);
|
||||
g_free (sender);
|
||||
g_free (cmdline);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_cancel_request:
|
||||
*
|
||||
* Removes a cookie and associated data from the UpQosItem struct.
|
||||
**/
|
||||
void
|
||||
up_qos_cancel_request (UpQos *qos, guint cookie, DBusGMethodInvocation *context)
|
||||
{
|
||||
UpQosItem *item;
|
||||
GError *error;
|
||||
gchar *sender = NULL;
|
||||
PolkitSubject *subject = NULL;
|
||||
UpQosKind item_kind;
|
||||
|
||||
/* find the correct cookie */
|
||||
item = up_qos_find_from_cookie (qos, cookie);
|
||||
if (item == NULL) {
|
||||
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL,
|
||||
"Cannot find request for #%i", cookie);
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* get the sender? */
|
||||
sender = dbus_g_method_get_sender (context);
|
||||
if (sender == NULL) {
|
||||
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "no DBUS sender");
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* are we not the sender? */
|
||||
if (g_strcmp0 (sender, up_qos_item_get_sender (item)) != 0) {
|
||||
subject = up_polkit_get_subject (qos->priv->polkit, context);
|
||||
if (subject == NULL)
|
||||
goto out;
|
||||
if (!up_polkit_check_auth (qos->priv->polkit, subject, "org.freedesktop.upower.qos.cancel-request", context))
|
||||
goto out;
|
||||
}
|
||||
|
||||
g_debug ("Clear #%i", cookie);
|
||||
|
||||
/* remove object from list */
|
||||
item_kind = up_qos_item_get_kind (item);
|
||||
g_ptr_array_remove (qos->priv->data, item);
|
||||
up_qos_latency_perhaps_changed (qos, item_kind);
|
||||
|
||||
/* TODO: if persistent remove from datadase */
|
||||
|
||||
g_signal_emit (qos, signals [REQUESTS_CHANGED], 0);
|
||||
|
||||
dbus_g_method_return (context, NULL);
|
||||
out:
|
||||
if (subject != NULL)
|
||||
g_object_unref (subject);
|
||||
g_free (sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_get_latency:
|
||||
*
|
||||
* Gets the current latency
|
||||
**/
|
||||
gboolean
|
||||
up_qos_get_latency (UpQos *qos, const gchar *type_text, gint *value, GError **error)
|
||||
{
|
||||
UpQosKind type;
|
||||
|
||||
/* get correct data */
|
||||
type = up_qos_kind_from_string (type_text);
|
||||
if (type == UP_QOS_KIND_UNKNOWN) {
|
||||
g_set_error (error, UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "type invalid: %s", type_text);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* get the lowest value for this type */
|
||||
*value = up_qos_get_lowest (qos, type);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_set_minimum_latency:
|
||||
**/
|
||||
void
|
||||
up_qos_set_minimum_latency (UpQos *qos, const gchar *type_text, gint value, DBusGMethodInvocation *context)
|
||||
{
|
||||
UpQosKind type;
|
||||
GError *error;
|
||||
|
||||
/* type valid? */
|
||||
type = up_qos_kind_from_string (type_text);
|
||||
if (type == UP_QOS_KIND_UNKNOWN) {
|
||||
error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "type invalid: %s", type_text);
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
g_debug ("setting %s minimum to %i", type_text, value);
|
||||
qos->priv->minimum[type] = value;
|
||||
|
||||
/* may have changed */
|
||||
up_qos_latency_perhaps_changed (qos, type);
|
||||
dbus_g_method_return (context, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_get_latency_requests:
|
||||
**/
|
||||
gboolean
|
||||
up_qos_get_latency_requests (UpQos *qos, GPtrArray **requests, GError **error)
|
||||
{
|
||||
guint i;
|
||||
GPtrArray *data;
|
||||
UpQosItem *item;
|
||||
|
||||
*requests = g_ptr_array_new ();
|
||||
data = qos->priv->data;
|
||||
for (i=0; i<data->len; i++) {
|
||||
GValue elem = {0};
|
||||
|
||||
item = g_ptr_array_index (data, i);
|
||||
g_value_init (&elem, UP_QOS_REQUESTS_STRUCT_TYPE);
|
||||
g_value_take_boxed (&elem, dbus_g_type_specialized_construct (UP_QOS_REQUESTS_STRUCT_TYPE));
|
||||
dbus_g_type_struct_set (&elem,
|
||||
0, up_qos_item_get_cookie (item),
|
||||
1, up_qos_item_get_uid (item),
|
||||
2, up_qos_item_get_pid (item),
|
||||
3, up_qos_item_get_cmdline (item),
|
||||
4, 0, //up_qos_item_get_timespec (item),
|
||||
5, up_qos_item_get_persistent (item),
|
||||
6, up_qos_kind_to_string (up_qos_item_get_kind (item)),
|
||||
7, up_qos_item_get_value (item),
|
||||
G_MAXUINT);
|
||||
g_ptr_array_add (*requests, g_value_get_boxed (&elem));
|
||||
}
|
||||
|
||||
// dbus_g_method_return (context, requests);
|
||||
// g_ptr_array_foreach (*requests, (GFunc) g_value_array_free, NULL);
|
||||
// g_ptr_array_unref (*requests);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* up_qos_remove_dbus:
|
||||
**/
|
||||
static void
|
||||
up_qos_remove_dbus (UpQos *qos, const gchar *sender)
|
||||
{
|
||||
guint i;
|
||||
GPtrArray *data;
|
||||
UpQosItem *item;
|
||||
UpQosKind item_kind;
|
||||
|
||||
/* remove *any* senders that match the sender */
|
||||
data = qos->priv->data;
|
||||
for (i=0; i<data->len; i++) {
|
||||
item = g_ptr_array_index (data, i);
|
||||
if (strcmp (up_qos_item_get_sender (item), sender) == 0) {
|
||||
g_debug ("Auto-revoked idle qos on %s", sender);
|
||||
item_kind = up_qos_item_get_kind (item);
|
||||
g_ptr_array_remove (qos->priv->data, item);
|
||||
up_qos_latency_perhaps_changed (qos, item_kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_name_owner_changed_cb:
|
||||
**/
|
||||
static void
|
||||
up_qos_name_owner_changed_cb (DBusGProxy *proxy, const gchar *name, const gchar *prev, const gchar *new, UpQos *qos)
|
||||
{
|
||||
if (strlen (new) == 0)
|
||||
up_qos_remove_dbus (qos, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_class_init:
|
||||
**/
|
||||
static void
|
||||
up_qos_class_init (UpQosClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
object_class->finalize = up_qos_finalize;
|
||||
|
||||
signals [LATENCY_CHANGED] =
|
||||
g_signal_new ("latency-changed",
|
||||
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (UpQosClass, latency_changed),
|
||||
NULL, NULL, up_marshal_VOID__STRING_INT,
|
||||
G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_INT);
|
||||
signals [REQUESTS_CHANGED] =
|
||||
g_signal_new ("requests-changed",
|
||||
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (UpQosClass, requests_changed),
|
||||
NULL, NULL, g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
/* introspection */
|
||||
dbus_g_object_type_install_info (UP_TYPE_QOS, &dbus_glib_up_qos_object_info);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (UpQosPrivate));
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_init:
|
||||
**/
|
||||
static void
|
||||
up_qos_init (UpQos *qos)
|
||||
{
|
||||
guint i;
|
||||
GError *error = NULL;
|
||||
|
||||
qos->priv = UP_QOS_GET_PRIVATE (qos);
|
||||
qos->priv->polkit = up_polkit_new ();
|
||||
qos->priv->data = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
||||
/* TODO: need to load persistent values */
|
||||
|
||||
/* setup lowest */
|
||||
for (i=0; i<UP_QOS_KIND_LAST; i++)
|
||||
qos->priv->last[i] = up_qos_get_lowest (qos, i);
|
||||
|
||||
/* setup minimum */
|
||||
for (i=0; i<UP_QOS_KIND_LAST; i++)
|
||||
qos->priv->minimum[i] = -1;
|
||||
|
||||
qos->priv->fd[UP_QOS_KIND_CPU_DMA] = open ("/dev/cpu_dma_latency", O_WRONLY);
|
||||
if (qos->priv->fd[UP_QOS_KIND_CPU_DMA] < 0)
|
||||
g_debug ("cannot open cpu_dma device file");
|
||||
qos->priv->fd[UP_QOS_KIND_NETWORK] = open ("/dev/network_latency", O_WRONLY);
|
||||
if (qos->priv->fd[UP_QOS_KIND_NETWORK] < 0)
|
||||
g_debug ("cannot open network device file");
|
||||
|
||||
qos->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
|
||||
if (error != NULL) {
|
||||
g_warning ("Cannot connect to bus: %s", error->message);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
||||
/* register on the bus */
|
||||
dbus_g_connection_register_g_object (qos->priv->connection, "/org/freedesktop/UPower/Policy", G_OBJECT (qos));
|
||||
|
||||
/* watch NOC */
|
||||
qos->priv->proxy = dbus_g_proxy_new_for_name_owner (qos->priv->connection, DBUS_SERVICE_DBUS,
|
||||
DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, NULL);
|
||||
dbus_g_proxy_add_signal (qos->priv->proxy, "NameOwnerChanged",
|
||||
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
|
||||
dbus_g_proxy_connect_signal (qos->priv->proxy, "NameOwnerChanged",
|
||||
G_CALLBACK (up_qos_name_owner_changed_cb), qos, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_finalize:
|
||||
**/
|
||||
static void
|
||||
up_qos_finalize (GObject *object)
|
||||
{
|
||||
UpQos *qos;
|
||||
guint i;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
g_return_if_fail (UP_IS_QOS (object));
|
||||
|
||||
qos = UP_QOS (object);
|
||||
qos->priv = UP_QOS_GET_PRIVATE (qos);
|
||||
|
||||
/* close files */
|
||||
for (i=0; i<UP_QOS_KIND_LAST; i++) {
|
||||
if (qos->priv->fd[i] > 0)
|
||||
close (qos->priv->fd[i]);
|
||||
}
|
||||
g_ptr_array_unref (qos->priv->data);
|
||||
g_object_unref (qos->priv->proxy);
|
||||
|
||||
g_object_unref (qos->priv->polkit);
|
||||
|
||||
G_OBJECT_CLASS (up_qos_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
/**
|
||||
* up_qos_new:
|
||||
**/
|
||||
UpQos *
|
||||
up_qos_new (void)
|
||||
{
|
||||
UpQos *qos;
|
||||
qos = g_object_new (UP_TYPE_QOS, NULL);
|
||||
return UP_QOS (qos);
|
||||
}
|
||||
|
||||
80
src/up-qos.h
80
src/up-qos.h
|
|
@ -1,80 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __UP_QOS_H
|
||||
#define __UP_QOS_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define UP_TYPE_QOS (up_qos_get_type ())
|
||||
#define UP_QOS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UP_TYPE_QOS, UpQos))
|
||||
#define UP_QOS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UP_TYPE_QOS, UpQosClass))
|
||||
#define UP_IS_QOS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UP_TYPE_QOS))
|
||||
#define UP_IS_QOS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UP_TYPE_QOS))
|
||||
#define UP_QOS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UP_TYPE_QOS, UpQosClass))
|
||||
|
||||
typedef struct UpQosPrivate UpQosPrivate;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObject parent;
|
||||
UpQosPrivate *priv;
|
||||
} UpQos;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
void (* latency_changed) (UpQos *qos,
|
||||
const gchar *type,
|
||||
gint value);
|
||||
void (* requests_changed) (UpQos *qos);
|
||||
} UpQosClass;
|
||||
|
||||
UpQos *up_qos_new (void);
|
||||
GType up_qos_get_type (void);
|
||||
void up_qos_test (gpointer user_data);
|
||||
|
||||
void up_qos_request_latency (UpQos *qos,
|
||||
const gchar *type,
|
||||
gint value,
|
||||
gboolean persistent,
|
||||
DBusGMethodInvocation *context);
|
||||
void up_qos_cancel_request (UpQos *qos,
|
||||
guint32 cookie,
|
||||
DBusGMethodInvocation *context);
|
||||
void up_qos_set_minimum_latency (UpQos *qos,
|
||||
const gchar *type,
|
||||
gint value,
|
||||
DBusGMethodInvocation *context);
|
||||
gboolean up_qos_get_latency (UpQos *qos,
|
||||
const gchar *type,
|
||||
gint *value,
|
||||
GError **error);
|
||||
gboolean up_qos_get_latency_requests (UpQos *qos,
|
||||
GPtrArray **requests,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __UP_QOS_H */
|
||||
|
|
@ -33,7 +33,6 @@
|
|||
#include "up-history.h"
|
||||
#include "up-native.h"
|
||||
#include "up-polkit.h"
|
||||
#include "up-qos.h"
|
||||
#include "up-wakeups.h"
|
||||
|
||||
gchar *history_dir = NULL;
|
||||
|
|
@ -300,24 +299,6 @@ up_test_polkit_func (void)
|
|||
g_object_unref (polkit);
|
||||
}
|
||||
|
||||
static void
|
||||
up_test_qos_func (void)
|
||||
{
|
||||
UpQos *qos;
|
||||
|
||||
/* needs polkit, which only listens to the system bus */
|
||||
if (!g_file_test (DBUS_SYSTEM_SOCKET, G_FILE_TEST_EXISTS)) {
|
||||
puts("No system D-BUS running, skipping test");
|
||||
return;
|
||||
}
|
||||
|
||||
qos = up_qos_new ();
|
||||
g_assert (qos != NULL);
|
||||
|
||||
/* unref */
|
||||
g_object_unref (qos);
|
||||
}
|
||||
|
||||
static void
|
||||
up_test_wakeups_func (void)
|
||||
{
|
||||
|
|
@ -351,7 +332,6 @@ main (int argc, char **argv)
|
|||
g_test_add_func ("/power/history", up_test_history_func);
|
||||
g_test_add_func ("/power/native", up_test_native_func);
|
||||
g_test_add_func ("/power/polkit", up_test_polkit_func);
|
||||
g_test_add_func ("/power/qos", up_test_qos_func);
|
||||
g_test_add_func ("/power/wakeups", up_test_wakeups_func);
|
||||
g_test_add_func ("/power/daemon", up_test_daemon_func);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue