summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2013-10-10 15:20:18 +0200
committerBastien Nocera <hadess@hadess.net>2013-10-14 10:42:55 +0200
commitd10cc97cbb826099530180450052f90b86cdcac8 (patch)
tree62b17c7c5c73eab6b46ca93a5f05907d695fb16b /src
parentc842f1a53ec5f1903bd911e0eee2383b0fc5503a (diff)
downloadupower-d10cc97cbb826099530180450052f90b86cdcac8.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am10
-rw-r--r--src/org.freedesktop.UPower.QoS.xml331
-rw-r--r--src/org.freedesktop.UPower.conf.in4
-rw-r--r--src/up-main.c5
-rw-r--r--src/up-qos.c641
-rw-r--r--src/up-qos.h80
-rw-r--r--src/up-self-test.c20
7 files changed, 0 insertions, 1091 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index affda04..0bbd20f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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 \
diff --git a/src/org.freedesktop.UPower.QoS.xml b/src/org.freedesktop.UPower.QoS.xml
deleted file mode 100644
index d3113f1..0000000
--- a/src/org.freedesktop.UPower.QoS.xml
+++ /dev/null
@@ -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>
diff --git a/src/org.freedesktop.UPower.conf.in b/src/org.freedesktop.UPower.conf.in
index fc2b604..5a6c660 100644
--- a/src/org.freedesktop.UPower.conf.in
+++ b/src/org.freedesktop.UPower.conf.in
@@ -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"
@@ -31,8 +29,6 @@
<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"
send_interface="org.freedesktop.UPower.Wakeups"/>
diff --git a/src/up-main.c b/src/up-main.c
index f1d81a2..ff9fbaf 100644
--- a/src/up-main.c
+++ b/src/up-main.c
@@ -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)
diff --git a/src/up-qos.c b/src/up-qos.c
deleted file mode 100644
index fc72643..0000000
--- a/src/up-qos.c
+++ /dev/null
@@ -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);
-}
-
diff --git a/src/up-qos.h b/src/up-qos.h
deleted file mode 100644
index 8bbc340..0000000
--- a/src/up-qos.h
+++ /dev/null
@@ -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 */
diff --git a/src/up-self-test.c b/src/up-self-test.c
index 1a0595d..ecf1ff9 100644
--- a/src/up-self-test.c
+++ b/src/up-self-test.c
@@ -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;
@@ -301,24 +300,6 @@ up_test_polkit_func (void)
}
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)
{
UpWakeups *wakeups;
@@ -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);