mirror of
https://gitlab.freedesktop.org/upower/power-profiles-daemon.git
synced 2025-12-20 04:30:09 +01:00
cleanup: Use UPower namespace as default DBus name preserving old one
Expose the daemon as 'org.freedesktop.UPower.PowerProfiles' by default but we also own the old 'net.hadess.PowerProfiles' name for compatibility resons. Also dbus objects are now registered also in the path /org/freedesktop/UPower/PowerProfiles and they implement the org.freedesktop.UPower.PowerProfiles interface. Even in this case we preserve the compatibility with the old ones. To make this switch as most reliable as possible, the code is now generated for dbus configuration files preserving the previous ones as base. Tests are now performed checking both names, to ensure again that we're not breaking the expectations for the old APIs consumers.
This commit is contained in:
parent
520622ba70
commit
3b29b0e52b
18 changed files with 393 additions and 120 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,4 +1,3 @@
|
|||
power-profiles-daemon
|
||||
data/net.hadess.PowerProfiles.conf
|
||||
__pycache__
|
||||
.vscode
|
||||
|
|
|
|||
|
|
@ -84,8 +84,12 @@ reboot in `/var/lib/power-profiles-daemon/state.ini`.
|
|||
Those commands are also available through the D-Bus interface:
|
||||
|
||||
```sh
|
||||
gdbus introspect --system --dest net.hadess.PowerProfiles --object-path /net/hadess/PowerProfiles
|
||||
gdbus call --system --dest net.hadess.PowerProfiles --object-path /net/hadess/PowerProfiles --method org.freedesktop.DBus.Properties.Set 'net.hadess.PowerProfiles' 'ActiveProfile' "<'power-saver'>"
|
||||
gdbus introspect --system --dest org.freedesktop.UPower.PowerProfiles \
|
||||
--object-path /org/freedesktop/UPower/PowerProfiles
|
||||
gdbus call --system --dest org.freedesktop.UPower.PowerProfiles \
|
||||
--object-path /org/freedesktop/UPower/PowerProfiles \
|
||||
--method org.freedesktop.DBus.Properties.Set 'org.freedesktop.UPower.PowerProfiles' \
|
||||
'ActiveProfile' "<'power-saver'>"
|
||||
```
|
||||
|
||||
If that doesn't work, please file an issue, attach the output of:
|
||||
|
|
|
|||
|
|
@ -1,24 +1,32 @@
|
|||
data_conf = configuration_data()
|
||||
data_conf.set('libexecdir', libexecdir)
|
||||
|
||||
configure_file(
|
||||
input: 'power-profiles-daemon.service.in',
|
||||
output: 'power-profiles-daemon.service',
|
||||
configuration: data_conf,
|
||||
configuration: {
|
||||
'libexecdir': libexecdir,
|
||||
},
|
||||
install_dir: systemd_system_unit_dir,
|
||||
)
|
||||
|
||||
configure_file(
|
||||
input: 'net.hadess.PowerProfiles.conf.in',
|
||||
output: 'net.hadess.PowerProfiles.conf',
|
||||
configuration: data_conf,
|
||||
install_dir: dbusconfdir
|
||||
)
|
||||
foreach name, _: bus_names
|
||||
config = {
|
||||
'dbus_name': name,
|
||||
'dbus_iface': name,
|
||||
}
|
||||
|
||||
install_data(
|
||||
'net.hadess.PowerProfiles.service',
|
||||
install_dir: dbusservicedir
|
||||
)
|
||||
configure_file(
|
||||
input: 'power-profiles-daemon.dbus.conf.in',
|
||||
output: name + '.conf',
|
||||
configuration: config,
|
||||
install_dir: dbusconfdir
|
||||
)
|
||||
|
||||
configure_file(
|
||||
input: 'power-profiles-daemon.dbus.service.in',
|
||||
output: name + '.service',
|
||||
configuration: config,
|
||||
install_dir: dbusservicedir
|
||||
)
|
||||
endforeach
|
||||
|
||||
polkit_policy = 'power-profiles-daemon.policy'
|
||||
if xmllint.found()
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
|
||||
|
||||
<!DOCTYPE busconfig PUBLIC
|
||||
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
|
||||
<!-- Only root can own the service -->
|
||||
<policy user="root">
|
||||
<allow own="net.hadess.PowerProfiles"/>
|
||||
</policy>
|
||||
|
||||
<!-- Anyone can talk to the main interface -->
|
||||
<policy context="default">
|
||||
<allow send_destination="net.hadess.PowerProfiles" send_interface="net.hadess.PowerProfiles"/>
|
||||
<allow send_destination="net.hadess.PowerProfiles" send_interface="org.freedesktop.DBus.Introspectable"/>
|
||||
<allow send_destination="net.hadess.PowerProfiles" send_interface="org.freedesktop.DBus.Properties"/>
|
||||
<allow send_destination="net.hadess.PowerProfiles" send_interface="org.freedesktop.DBus.Peer"/>
|
||||
</policy>
|
||||
|
||||
</busconfig>
|
||||
21
data/power-profiles-daemon.dbus.conf.in
Normal file
21
data/power-profiles-daemon.dbus.conf.in
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
|
||||
|
||||
<!DOCTYPE busconfig PUBLIC
|
||||
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
|
||||
<!-- Only root can own the service -->
|
||||
<policy user="root">
|
||||
<allow own="@dbus_name@"/>
|
||||
</policy>
|
||||
|
||||
<!-- Anyone can talk to the main interface -->
|
||||
<policy context="default">
|
||||
<allow send_destination="@dbus_name@" send_interface="@dbus_iface@"/>
|
||||
<allow send_destination="@dbus_name@" send_interface="org.freedesktop.DBus.Introspectable"/>
|
||||
<allow send_destination="@dbus_name@" send_interface="org.freedesktop.DBus.Properties"/>
|
||||
<allow send_destination="@dbus_name@" send_interface="org.freedesktop.DBus.Peer"/>
|
||||
</policy>
|
||||
|
||||
</busconfig>
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
# the Free Software Foundation.
|
||||
|
||||
[D-BUS Service]
|
||||
Name=net.hadess.PowerProfiles
|
||||
Name=@dbus_name@
|
||||
Exec=/bin/false
|
||||
User=root
|
||||
SystemdService=power-profiles-daemon.service
|
||||
|
|
@ -5,7 +5,7 @@ Before=multi-user.target display-manager.target
|
|||
|
||||
[Service]
|
||||
Type=dbus
|
||||
BusName=net.hadess.PowerProfiles
|
||||
BusName=org.freedesktop.UPower.PowerProfiles
|
||||
ExecStart=@libexecdir@/power-profiles-daemon
|
||||
Restart=on-failure
|
||||
# This always corresponds to /var/lib/power-profiles-daemon
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ content_files += configure_file(
|
|||
|
||||
content_files += gnome.gdbus_codegen(
|
||||
meson.project_name(),
|
||||
sources: meson.source_root() / 'src' / 'net.hadess.PowerProfiles.xml',
|
||||
interface_prefix: 'net.hadess',
|
||||
sources: dbus_xml['org.freedesktop.UPower.PowerProfiles'],
|
||||
interface_prefix: 'org.freedesktop.UPower',
|
||||
namespace: 'PowerProfiles',
|
||||
docbook: 'docs',
|
||||
build_by_default: true,
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@
|
|||
Power Profiles daemon.
|
||||
</para>
|
||||
</partintro>
|
||||
<xi:include href="docs-net.hadess.PowerProfiles.xml"/>
|
||||
<xi:include href="docs-org.freedesktop.UPower.PowerProfiles.xml"/>
|
||||
</reference>
|
||||
|
||||
<reference id="internal-api">
|
||||
|
|
|
|||
|
|
@ -54,6 +54,11 @@ if get_option('pylint')
|
|||
endif
|
||||
xmllint = find_program('xmllint', required: false)
|
||||
|
||||
bus_names = {
|
||||
'org.freedesktop.UPower.PowerProfiles': '/org/freedesktop/UPower/PowerProfiles',
|
||||
'net.hadess.PowerProfiles': '/net/hadess/PowerProfiles',
|
||||
}
|
||||
|
||||
subdir('src')
|
||||
subdir('data')
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,46 @@ config_h_files = configure_file(
|
|||
configuration: config_h
|
||||
)
|
||||
|
||||
dbus_xml = {}
|
||||
dbus_xml_sources = []
|
||||
resources_contents = []
|
||||
|
||||
foreach name, path: bus_names
|
||||
config = {
|
||||
'dbus_name': name,
|
||||
'dbus_iface': name,
|
||||
'dbus_path': path,
|
||||
}
|
||||
|
||||
xml_source = configure_file(
|
||||
input: 'power-profiles-daemon.dbus.xml.in',
|
||||
output: name + '.xml',
|
||||
configuration: config,
|
||||
)
|
||||
dbus_xml_sources += xml_source
|
||||
dbus_xml += {name: xml_source}
|
||||
|
||||
resources_contents += '<file preprocess="xml-stripblanks">@0@.xml</file>'.format(name)
|
||||
endforeach
|
||||
|
||||
resources_xml = configure_file(
|
||||
input: 'power-profiles-daemon.gresource.xml.in',
|
||||
output: '@BASENAME@',
|
||||
configuration: {
|
||||
'prefix': bus_names['org.freedesktop.UPower.PowerProfiles'],
|
||||
'contents': '\n'.join(resources_contents),
|
||||
},
|
||||
)
|
||||
|
||||
resources = gnome.compile_resources(
|
||||
'power-profiles-daemon-resources', 'power-profiles-daemon.gresource.xml',
|
||||
c_name: 'power_profiles_daemon',
|
||||
source_dir: '.',
|
||||
export: true
|
||||
'power-profiles-daemon-resources', resources_xml,
|
||||
c_name: 'power_profiles_daemon',
|
||||
dependencies: dbus_xml_sources,
|
||||
source_dir: [
|
||||
meson.current_source_dir(),
|
||||
meson.current_build_dir(),
|
||||
],
|
||||
export: true
|
||||
)
|
||||
|
||||
sources = [
|
||||
|
|
|
|||
140
src/org.freedesktop.UPower.PowerProfiles.xml
Normal file
140
src/org.freedesktop.UPower.PowerProfiles.xml
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
|
||||
<node>
|
||||
|
||||
<!--
|
||||
org.freedesktop.UPower.PowerProfiles:
|
||||
@short_description: Power Profiles daemon
|
||||
|
||||
The power-profiles-daemon API is meant to be used by parts of the OS or
|
||||
desktop environment to switch system power profiles based on user choice,
|
||||
or user intent.
|
||||
|
||||
OS components would typically use the "Profiles" property to construct
|
||||
their UI (2 or 3 profiles available), and monitor the "ActiveProfile"
|
||||
and the "PerformanceDegraded" properties to update that UI. The UI
|
||||
would try to set the "ActiveProfile" property if the user selected
|
||||
a different one.
|
||||
|
||||
Note that the reason why the project exists and how it is different from
|
||||
existing projects is explained <ulink href=" https://gitlab.freedesktop.org/hadess/power-profiles-daemon/-/blob/master/README.md">
|
||||
in the project's README file</ulink>.
|
||||
|
||||
The object path will be "/org/freedesktop/UPower/PowerProfiles".
|
||||
-->
|
||||
<interface name="org.freedesktop.UPower.PowerProfiles">
|
||||
|
||||
<!--
|
||||
HoldProfile:
|
||||
|
||||
This forces the passed profile (either 'power-saver' or 'performance')
|
||||
to be activated until either the caller quits, "ReleaseProfile" is
|
||||
called, or the "ActiveProfile" is changed by the user.
|
||||
|
||||
This should be used programmatically by OS components when, eg. high-
|
||||
performance workloads are started with the "performance" profile, or
|
||||
battery will soon be critically low with the "power-saver" profile.
|
||||
|
||||
When conflicting profiles are requested to be held, the 'power-saver' profile
|
||||
will be activated in preference to the 'performance' profile.
|
||||
|
||||
Those holds will be automatically cancelled if the user manually switches
|
||||
to another profile, and the "ProfileReleased" signal will be emitted.
|
||||
-->
|
||||
<method name="HoldProfile">
|
||||
<arg name="profile" type="s" direction="in"/>
|
||||
<arg name="reason" type="s" direction="in"/>
|
||||
<arg name="application_id" type="s" direction="in" />
|
||||
<arg name="cookie" type="u" direction="out"/>
|
||||
</method>
|
||||
|
||||
<!--
|
||||
ReleaseProfile:
|
||||
|
||||
This removes the hold that was set on a profile.
|
||||
-->
|
||||
<method name="ReleaseProfile">
|
||||
<arg name="cookie" type="u" direction="in"/>
|
||||
</method>
|
||||
|
||||
<!--
|
||||
ProfileReleased:
|
||||
|
||||
This signal will be emitted if the profile is released because the
|
||||
"ActiveProfile" was manually changed. The signal will only be emitted
|
||||
to the process that originally called "HoldProfile".
|
||||
-->
|
||||
<signal name="ProfileReleased">
|
||||
<arg name="cookie" type="u" direction="out"/>
|
||||
</signal>
|
||||
|
||||
<!--
|
||||
ActiveProfile:
|
||||
|
||||
The type of the currently active profile. It might change automatically
|
||||
if a profile is held, using the "HoldProfile" function.
|
||||
-->
|
||||
<property name="ActiveProfile" type="s" access="readwrite"/>
|
||||
|
||||
<!--
|
||||
PerformanceInhibited:
|
||||
|
||||
This property is deprecated, and unused since version 0.9.
|
||||
-->
|
||||
<property name="PerformanceInhibited" type="s" access="read"/>
|
||||
|
||||
<!--
|
||||
PerformanceDegraded:
|
||||
|
||||
This will be set if the performance power profile is running in degraded
|
||||
mode, with the value being used to identify the reason for that degradation.
|
||||
As new reasons can be added, it is recommended that front-ends show a generic
|
||||
reason if they do not recognise the value. Possible values are:
|
||||
- "lap-detected" (the computer is sitting on the user's lap)
|
||||
- "high-operating-temperature" (the computer is close to overheating)
|
||||
- "" (the empty string, if not performance is not degraded)
|
||||
-->
|
||||
<property name="PerformanceDegraded" type="s" access="read"/>
|
||||
|
||||
<!--
|
||||
Profiles:
|
||||
|
||||
An array of key-pair values representing each profile. The key named
|
||||
"Driver" (s) identifies the power-profiles-daemon backend code used to
|
||||
implement the profile.
|
||||
|
||||
The key named "Profile" (s) will be one of:
|
||||
- "power-saver" (battery saving profile)
|
||||
- "balanced" (the default profile)
|
||||
- "performance" (a profile that does not care about noise or battery consumption)
|
||||
|
||||
Only one of each type of profile will be listed, with the daemon choosing the
|
||||
more appropriate "driver" for each profile type.
|
||||
|
||||
This list is guaranteed to be sorted in the same order that the profiles
|
||||
are listed above.
|
||||
-->
|
||||
<property name="Profiles" type="aa{sv}" access="read"/>
|
||||
|
||||
<!--
|
||||
Actions:
|
||||
|
||||
An array of strings listing each one of the "actions" implemented in
|
||||
the running daemon. This is used by API users to figure out whether
|
||||
particular functionality is available in a version of the daemon.
|
||||
-->
|
||||
<property name="Actions" type="as" access="read"/>
|
||||
|
||||
<!--
|
||||
ActiveProfileHolds:
|
||||
|
||||
A list of dictionaries representing the current profile holds.
|
||||
The keys in the dict are "ApplicationId", "Profile" and "Reason",
|
||||
and correspond to the "application_id", "profile" and "reason" arguments
|
||||
passed to the HoldProfile() method.
|
||||
-->
|
||||
<property name="ActiveProfileHolds" type="aa{sv}" access="read"/>
|
||||
|
||||
</interface>
|
||||
</node>
|
||||
|
|
@ -23,12 +23,18 @@
|
|||
#include "ppd-action.h"
|
||||
#include "ppd-enums.h"
|
||||
|
||||
#define POWER_PROFILES_DBUS_NAME "net.hadess.PowerProfiles"
|
||||
#define POWER_PROFILES_DBUS_PATH "/net/hadess/PowerProfiles"
|
||||
#define POWER_PROFILES_DBUS_NAME "org.freedesktop.UPower.PowerProfiles"
|
||||
#define POWER_PROFILES_DBUS_PATH "/org/freedesktop/UPower/PowerProfiles"
|
||||
#define POWER_PROFILES_IFACE_NAME POWER_PROFILES_DBUS_NAME
|
||||
|
||||
#define POWER_PROFILES_LEGACY_DBUS_NAME "net.hadess.PowerProfiles"
|
||||
#define POWER_PROFILES_LEGACY_DBUS_PATH "/net/hadess/PowerProfiles"
|
||||
#define POWER_PROFILES_LEGACY_IFACE_NAME POWER_PROFILES_LEGACY_DBUS_NAME
|
||||
|
||||
#define POWER_PROFILES_POLICY_NAMESPACE "org.freedesktop.UPower.PowerProfiles"
|
||||
|
||||
#define POWER_PROFILES_RESOURCES_PATH "/org/freedesktop/UPower/PowerProfiles"
|
||||
|
||||
#ifndef POLKIT_HAS_AUTOPOINTERS
|
||||
/* FIXME: Remove this once we're fine to depend on polkit 0.114 */
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (PolkitAuthorizationResult, g_object_unref)
|
||||
|
|
@ -37,9 +43,9 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (PolkitSubject, g_object_unref)
|
|||
|
||||
typedef struct {
|
||||
GMainLoop *main_loop;
|
||||
GDBusNodeInfo *introspection_data;
|
||||
GDBusConnection *connection;
|
||||
guint name_id;
|
||||
guint legacy_name_id;
|
||||
gboolean was_started;
|
||||
int ret;
|
||||
|
||||
|
|
@ -837,7 +843,8 @@ handle_method_call (GDBusConnection *connection,
|
|||
PpdApp *data = user_data;
|
||||
g_assert (data->connection);
|
||||
|
||||
if (g_strcmp0 (interface_name, POWER_PROFILES_IFACE_NAME) != 0) {
|
||||
if (!g_str_equal (interface_name, POWER_PROFILES_IFACE_NAME) &&
|
||||
!g_str_equal (interface_name, POWER_PROFILES_LEGACY_IFACE_NAME)) {
|
||||
g_dbus_method_invocation_return_error (invocation,G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_INTERFACE,
|
||||
"Unknown interface %s", interface_name);
|
||||
return;
|
||||
|
|
@ -870,16 +877,34 @@ static const GDBusInterfaceVTable interface_vtable =
|
|||
handle_set_property
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
PpdApp *app;
|
||||
GBusNameOwnerFlags flags;
|
||||
GDBusInterfaceInfo *interface;
|
||||
GDBusInterfaceInfo *legacy_interface;
|
||||
} PpdBusOwnData;
|
||||
|
||||
static void
|
||||
ppd_bus_own_data_free (PpdBusOwnData *data)
|
||||
{
|
||||
g_clear_pointer (&data->interface, g_dbus_interface_info_unref);
|
||||
g_clear_pointer (&data->legacy_interface, g_dbus_interface_info_unref);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
static void
|
||||
name_lost_handler (GDBusConnection *connection,
|
||||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
PpdApp *data = user_data;
|
||||
PpdBusOwnData *data = user_data;
|
||||
PpdApp *app = data->app;
|
||||
|
||||
g_debug ("power-profiles-daemon is already running, or it cannot own its D-Bus name. Verify installation.");
|
||||
if (!data->was_started)
|
||||
data->ret = 1;
|
||||
g_main_loop_quit (data->main_loop);
|
||||
if (!app->was_started)
|
||||
app->ret = 1;
|
||||
|
||||
g_main_loop_quit (app->main_loop);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -887,17 +912,33 @@ bus_acquired_handler (GDBusConnection *connection,
|
|||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
PpdApp *data = user_data;
|
||||
PpdBusOwnData *data = user_data;
|
||||
|
||||
g_dbus_connection_register_object (connection,
|
||||
POWER_PROFILES_DBUS_PATH,
|
||||
data->introspection_data->interfaces[0],
|
||||
data->interface,
|
||||
&interface_vtable,
|
||||
data,
|
||||
data->app,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
data->connection = g_object_ref (connection);
|
||||
g_dbus_connection_register_object (connection,
|
||||
POWER_PROFILES_LEGACY_DBUS_PATH,
|
||||
data->legacy_interface,
|
||||
&interface_vtable,
|
||||
data->app,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
data->app->legacy_name_id = g_bus_own_name_on_connection (connection,
|
||||
POWER_PROFILES_LEGACY_DBUS_NAME,
|
||||
data->flags,
|
||||
NULL,
|
||||
name_lost_handler,
|
||||
data,
|
||||
NULL);
|
||||
|
||||
data->app->connection = g_object_ref (connection);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -1067,37 +1108,63 @@ name_acquired_handler (GDBusConnection *connection,
|
|||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
PpdApp *data = user_data;
|
||||
PpdBusOwnData *data = user_data;
|
||||
|
||||
start_profile_drivers (data);
|
||||
start_profile_drivers (data->app);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
setup_dbus (PpdApp *data,
|
||||
gboolean replace)
|
||||
setup_dbus (PpdApp *data,
|
||||
gboolean replace,
|
||||
GError **error)
|
||||
{
|
||||
GBytes *bytes;
|
||||
GBusNameOwnerFlags flags;
|
||||
g_autoptr(GBytes) iface_data = NULL;
|
||||
g_autoptr(GBytes) legacy_iface_data = NULL;
|
||||
g_autoptr(GDBusNodeInfo) introspection_data = NULL;
|
||||
g_autoptr(GDBusNodeInfo) legacy_introspection_data = NULL;
|
||||
PpdBusOwnData *own_data;
|
||||
|
||||
bytes = g_resources_lookup_data ("/net/hadess/PowerProfiles/net.hadess.PowerProfiles.xml",
|
||||
G_RESOURCE_LOOKUP_FLAGS_NONE,
|
||||
NULL);
|
||||
data->introspection_data = g_dbus_node_info_new_for_xml (g_bytes_get_data (bytes, NULL), NULL);
|
||||
g_bytes_unref (bytes);
|
||||
g_assert (data->introspection_data != NULL);
|
||||
iface_data = g_resources_lookup_data (POWER_PROFILES_RESOURCES_PATH "/"
|
||||
POWER_PROFILES_DBUS_NAME ".xml",
|
||||
G_RESOURCE_LOOKUP_FLAGS_NONE,
|
||||
error);
|
||||
if (!iface_data)
|
||||
return FALSE;
|
||||
|
||||
flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
|
||||
legacy_iface_data = g_resources_lookup_data (POWER_PROFILES_RESOURCES_PATH "/"
|
||||
POWER_PROFILES_LEGACY_DBUS_NAME ".xml",
|
||||
G_RESOURCE_LOOKUP_FLAGS_NONE,
|
||||
error);
|
||||
if (!legacy_iface_data)
|
||||
return FALSE;
|
||||
|
||||
introspection_data = g_dbus_node_info_new_for_xml (g_bytes_get_data (iface_data, NULL),
|
||||
error);
|
||||
if (!introspection_data)
|
||||
return FALSE;
|
||||
|
||||
legacy_introspection_data = g_dbus_node_info_new_for_xml (g_bytes_get_data (legacy_iface_data, NULL),
|
||||
error);
|
||||
if (!legacy_introspection_data)
|
||||
return FALSE;
|
||||
|
||||
own_data = g_new0 (PpdBusOwnData, 1);
|
||||
own_data->app = data;
|
||||
own_data->interface = g_dbus_interface_info_ref (introspection_data->interfaces[0]);
|
||||
own_data->legacy_interface = g_dbus_interface_info_ref (legacy_introspection_data->interfaces[0]);
|
||||
|
||||
own_data->flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
|
||||
if (replace)
|
||||
flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE;
|
||||
own_data->flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE;
|
||||
|
||||
data->name_id = g_bus_own_name (G_BUS_TYPE_SYSTEM,
|
||||
POWER_PROFILES_DBUS_NAME,
|
||||
flags,
|
||||
own_data->flags,
|
||||
bus_acquired_handler,
|
||||
name_acquired_handler,
|
||||
name_lost_handler,
|
||||
data,
|
||||
NULL);
|
||||
own_data,
|
||||
(GDestroyNotify) ppd_bus_own_data_free);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -1108,10 +1175,8 @@ free_app_data (PpdApp *data)
|
|||
if (data == NULL)
|
||||
return;
|
||||
|
||||
if (data->name_id != 0) {
|
||||
g_bus_unown_name (data->name_id);
|
||||
data->name_id = 0;
|
||||
}
|
||||
g_clear_handle_id (&data->name_id, g_bus_unown_name);
|
||||
g_clear_handle_id (&data->legacy_name_id, g_bus_unown_name);
|
||||
|
||||
g_clear_pointer (&data->config_path, g_free);
|
||||
g_clear_pointer (&data->config, g_key_file_unref);
|
||||
|
|
@ -1124,7 +1189,6 @@ free_app_data (PpdApp *data)
|
|||
g_clear_object (&data->auth);
|
||||
|
||||
g_clear_pointer (&data->main_loop, g_main_loop_unref);
|
||||
g_clear_pointer (&data->introspection_data, g_dbus_node_info_unref);
|
||||
g_clear_object (&data->connection);
|
||||
g_free (data);
|
||||
ppd_app = NULL;
|
||||
|
|
@ -1227,7 +1291,10 @@ int main (int argc, char **argv)
|
|||
ppd_app = data;
|
||||
|
||||
/* Set up D-Bus */
|
||||
setup_dbus (data, replace);
|
||||
if (!setup_dbus (data, replace, &error)) {
|
||||
g_error ("Failed to start dbus: %s", error->message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
g_main_loop_run (data->main_loop);
|
||||
ret = data->ret;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<node>
|
||||
|
||||
<!--
|
||||
net.hadess.PowerProfiles:
|
||||
@dbus_iface@:
|
||||
@short_description: Power Profiles daemon
|
||||
|
||||
The power-profiles-daemon API is meant to be used by parts of the OS or
|
||||
|
|
@ -21,9 +21,9 @@
|
|||
existing projects is explained <ulink href=" https://gitlab.freedesktop.org/hadess/power-profiles-daemon/-/blob/master/README.md">
|
||||
in the project's README file</ulink>.
|
||||
|
||||
The object path will be "/net/hadess/PowerProfiles".
|
||||
The object path will be "@dbus_path@".
|
||||
-->
|
||||
<interface name="net.hadess.PowerProfiles">
|
||||
<interface name="@dbus_iface@">
|
||||
|
||||
<!--
|
||||
HoldProfile:
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/net/hadess/PowerProfiles">
|
||||
<file preprocess="xml-stripblanks">net.hadess.PowerProfiles.xml</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
||||
6
src/power-profiles-daemon.gresource.xml.in
Normal file
6
src/power-profiles-daemon.gresource.xml.in
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="@prefix@">
|
||||
@contents@
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
|
@ -94,8 +94,8 @@ def get_proxy():
|
|||
try:
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||
proxy = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, None,
|
||||
'net.hadess.PowerProfiles',
|
||||
'/net/hadess/PowerProfiles',
|
||||
'org.freedesktop.UPower.PowerProfiles',
|
||||
'/org/freedesktop/UPower/PowerProfiles',
|
||||
'org.freedesktop.DBus.Properties', None)
|
||||
except:
|
||||
raise
|
||||
|
|
@ -103,14 +103,14 @@ def get_proxy():
|
|||
|
||||
def _get():
|
||||
proxy = get_proxy()
|
||||
profile = proxy.Get('(ss)', 'net.hadess.PowerProfiles', 'ActiveProfile')
|
||||
profile = proxy.Get('(ss)', 'org.freedesktop.UPower.PowerProfiles', 'ActiveProfile')
|
||||
print(profile)
|
||||
|
||||
def _set(profile):
|
||||
try:
|
||||
proxy = get_proxy()
|
||||
proxy.Set('(ssv)',
|
||||
'net.hadess.PowerProfiles',
|
||||
'org.freedesktop.UPower.PowerProfiles',
|
||||
'ActiveProfile',
|
||||
GLib.Variant.new_string(profile))
|
||||
except:
|
||||
|
|
@ -124,7 +124,7 @@ def get_profiles_property(prop):
|
|||
|
||||
profiles = None
|
||||
try:
|
||||
profiles = proxy.Get('(ss)', 'net.hadess.PowerProfiles', prop)
|
||||
profiles = proxy.Get('(ss)', 'org.freedesktop.UPower.PowerProfiles', prop)
|
||||
except:
|
||||
raise
|
||||
return profiles
|
||||
|
|
@ -132,9 +132,9 @@ def get_profiles_property(prop):
|
|||
def _list():
|
||||
try:
|
||||
profiles = get_profiles_property('Profiles')
|
||||
reason = get_proxy().Get('(ss)', 'net.hadess.PowerProfiles', 'PerformanceDegraded')
|
||||
reason = get_proxy().Get('(ss)', 'org.freedesktop.UPower.PowerProfiles', 'PerformanceDegraded')
|
||||
degraded = reason != ''
|
||||
active = get_proxy().Get('(ss)', 'net.hadess.PowerProfiles', 'ActiveProfile')
|
||||
active = get_proxy().Get('(ss)', 'org.freedesktop.UPower.PowerProfiles', 'ActiveProfile')
|
||||
except:
|
||||
raise
|
||||
|
||||
|
|
@ -174,9 +174,9 @@ def _launch(args, profile, appid, reason):
|
|||
try:
|
||||
bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None)
|
||||
proxy = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, None,
|
||||
'net.hadess.PowerProfiles',
|
||||
'/net/hadess/PowerProfiles',
|
||||
'net.hadess.PowerProfiles', None)
|
||||
'org.freedesktop.UPower.PowerProfiles',
|
||||
'/org/freedesktop/UPower/PowerProfiles',
|
||||
'org.freedesktop.UPower.PowerProfiles', None)
|
||||
except:
|
||||
raise
|
||||
|
||||
|
|
|
|||
|
|
@ -54,15 +54,14 @@ except ImportError:
|
|||
sys.exit(77)
|
||||
|
||||
|
||||
PP = "net.hadess.PowerProfiles"
|
||||
PP_PATH = "/net/hadess/PowerProfiles"
|
||||
PP_INTERFACE = "net.hadess.PowerProfiles"
|
||||
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
class Tests(dbusmock.DBusTestCase):
|
||||
"""Dbus based integration unit tests"""
|
||||
|
||||
PP = "org.freedesktop.UPower.PowerProfiles"
|
||||
PP_PATH = "/org/freedesktop/UPower/PowerProfiles"
|
||||
PP_INTERFACE = "org.freedesktop.UPower.PowerProfiles"
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
# run from local build tree if we are in one, otherwise use system instance
|
||||
|
|
@ -207,7 +206,13 @@ class Tests(dbusmock.DBusTestCase):
|
|||
self.fail("daemon did not start in 10 seconds")
|
||||
|
||||
self.proxy = Gio.DBusProxy.new_sync(
|
||||
self.dbus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None, PP, PP_PATH, PP, None
|
||||
self.dbus,
|
||||
Gio.DBusProxyFlags.DO_NOT_AUTO_START,
|
||||
None,
|
||||
self.PP,
|
||||
self.PP_PATH,
|
||||
self.PP_INTERFACE,
|
||||
None,
|
||||
)
|
||||
|
||||
self.assertEqual(self.daemon.poll(), None, "daemon crashed")
|
||||
|
|
@ -231,12 +236,12 @@ class Tests(dbusmock.DBusTestCase):
|
|||
self.dbus,
|
||||
Gio.DBusProxyFlags.DO_NOT_AUTO_START,
|
||||
None,
|
||||
PP,
|
||||
PP_PATH,
|
||||
self.PP,
|
||||
self.PP_PATH,
|
||||
"org.freedesktop.DBus.Properties",
|
||||
None,
|
||||
)
|
||||
return proxy.Get("(ss)", PP, name)
|
||||
return proxy.Get("(ss)", self.PP, name)
|
||||
|
||||
def set_dbus_property(self, name, value):
|
||||
"""Set property value on daemon D-Bus interface."""
|
||||
|
|
@ -245,12 +250,12 @@ class Tests(dbusmock.DBusTestCase):
|
|||
self.dbus,
|
||||
Gio.DBusProxyFlags.DO_NOT_AUTO_START,
|
||||
None,
|
||||
PP,
|
||||
PP_PATH,
|
||||
self.PP,
|
||||
self.PP_PATH,
|
||||
"org.freedesktop.DBus.Properties",
|
||||
None,
|
||||
)
|
||||
return proxy.Set("(ssv)", PP, name, value)
|
||||
return proxy.Set("(ssv)", self.PP, name, value)
|
||||
|
||||
def call_dbus_method(self, name, parameters):
|
||||
"""Call a method of the daemon D-Bus interface."""
|
||||
|
|
@ -259,9 +264,9 @@ class Tests(dbusmock.DBusTestCase):
|
|||
self.dbus,
|
||||
Gio.DBusProxyFlags.DO_NOT_AUTO_START,
|
||||
None,
|
||||
PP,
|
||||
PP_PATH,
|
||||
PP_INTERFACE,
|
||||
self.PP,
|
||||
self.PP_PATH,
|
||||
self.PP_INTERFACE,
|
||||
None,
|
||||
)
|
||||
return proxy.call_sync(
|
||||
|
|
@ -1737,14 +1742,17 @@ class Tests(dbusmock.DBusTestCase):
|
|||
self.dbus,
|
||||
Gio.DBusProxyFlags.DO_NOT_AUTO_START,
|
||||
None,
|
||||
PP,
|
||||
PP_PATH,
|
||||
self.PP,
|
||||
self.PP_PATH,
|
||||
"org.freedesktop.DBus.Properties",
|
||||
None,
|
||||
)
|
||||
with self.assertRaises(gi.repository.GLib.GError) as error:
|
||||
proxy.Set(
|
||||
"(ssv)", PP, "ActiveProfile", GLib.Variant.new_string("power-saver")
|
||||
"(ssv)",
|
||||
self.PP,
|
||||
"ActiveProfile",
|
||||
GLib.Variant.new_string("power-saver"),
|
||||
)
|
||||
self.assertIn("AccessDenied", str(error.exception))
|
||||
|
||||
|
|
@ -1874,6 +1882,14 @@ class Tests(dbusmock.DBusTestCase):
|
|||
return prop_str
|
||||
|
||||
|
||||
class LegacyDBusNameTests(Tests):
|
||||
"""This will repeats all the tests in the Tests class using the legacy dbus name"""
|
||||
|
||||
PP = "net.hadess.PowerProfiles"
|
||||
PP_PATH = "/net/hadess/PowerProfiles"
|
||||
PP_INTERFACE = "net.hadess.PowerProfiles"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# run ourselves under umockdev
|
||||
if "umockdev" not in os.environ.get("LD_PRELOAD", ""):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue