Merge lp:~larsu/indicator-sound/use-match-rules into lp:indicator-sound/13.04

Proposed by Lars Karlitski
Status: Merged
Approved by: Mathieu Trudel-Lapierre
Approved revision: 343
Merged at revision: 343
Proposed branch: lp:~larsu/indicator-sound/use-match-rules
Merge into: lp:indicator-sound/13.04
Diff against target: 115 lines (+53/-24)
1 file modified
src/mpris2-watcher.vala (+53/-24)
To merge this branch: bzr merge lp:~larsu/indicator-sound/use-match-rules
Reviewer Review Type Date Requested Status
Mathieu Trudel-Lapierre Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+151645@code.launchpad.net

Commit message

Mpris2Watcher: use match rules to avoid unnecessary wakeups

Previously, indicator-sound-service was waking up every time the owner of any name on the bus changed.

Description of the change

Mpris2Watcher: use match rules to avoid unnecessary wakeups

Previously, indicator-sound-service was waking up every time the owner of any name on the bus changed.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Ack.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/mpris2-watcher.vala'
2--- src/mpris2-watcher.vala 2011-06-29 08:24:23 +0000
3+++ src/mpris2-watcher.vala 2013-03-04 23:11:27 +0000
4@@ -21,8 +21,8 @@
5
6 public class Mpris2Watcher : GLib.Object
7 {
8- FreeDesktopObject fdesktop_obj;
9-
10+ DBusConnection session_bus;
11+
12 public signal void client_appeared ( string desktop_file_name,
13 string dbus_name,
14 bool use_playlists );
15@@ -33,18 +33,37 @@
16 }
17
18 construct
19- {
20+ {
21+ const string match_rule = "type='signal'," +
22+ "sender='org.freedesktop.DBus'," +
23+ "interface='org.freedesktop.DBus'," +
24+ "member='NameOwnerChanged'," +
25+ "path='/org/freedesktop/DBus'," +
26+ "arg0namespace='org.mpris.MediaPlayer2'";
27 try {
28- this.fdesktop_obj = Bus.get_proxy_sync ( BusType.SESSION,
29- FREEDESKTOP_SERVICE,
30- FREEDESKTOP_OBJECT,
31- DBusProxyFlags.DO_NOT_LOAD_PROPERTIES );
32- this.fdesktop_obj.name_owner_changed.connect (this.name_changes_detected);
33+ this.session_bus = Bus.get_sync (BusType.SESSION);
34+
35+ this.session_bus.call_sync ("org.freedesktop.DBus",
36+ "/",
37+ "org.freedesktop.DBus",
38+ "AddMatch",
39+ new Variant ("(s)", match_rule),
40+ VariantType.TUPLE,
41+ DBusCallFlags.NONE,
42+ -1);
43+
44+ this.session_bus.signal_subscribe ("org.freedesktop.DBus",
45+ "org.freedesktop.DBus",
46+ "NameOwnerChanged",
47+ "/org/freedesktop/DBus",
48+ null,
49+ DBusSignalFlags.NO_MATCH_RULE,
50+ this.name_owner_changed);
51+
52 this.check_for_active_clients.begin();
53 }
54- catch ( IOError e ){
55- warning( "Mpris2watcher could not set up a watch for mpris clients appearing on the bus: %s",
56- e.message );
57+ catch (GLib.Error e) {
58+ warning ("unable to set up name watch for mrpis clients: %s", e.message);
59 }
60 }
61
62@@ -52,16 +71,25 @@
63 // More relevant for development and daemon's like mpd.
64 public async void check_for_active_clients()
65 {
66- string[] interfaces;
67- try{
68- interfaces = yield this.fdesktop_obj.list_names();
69+ Variant interfaces;
70+
71+ try {
72+ interfaces = yield this.session_bus.call ("org.freedesktop.DBus",
73+ "/",
74+ "org.freedesktop.DBus",
75+ "ListNames",
76+ null,
77+ new VariantType ("(as)"),
78+ DBusCallFlags.NONE,
79+ -1);
80 }
81- catch ( IOError e) {
82- warning( "Mpris2watcher could fetch active interfaces at startup: %s",
83- e.message );
84+ catch (GLib.Error e) {
85+ warning ("unable to search for existing mpris clients: %s ", e.message);
86 return;
87 }
88- foreach (var address in interfaces) {
89+
90+ foreach (var val in interfaces.get_child_value (0)) {
91+ var address = (string) val;
92 if (address.has_prefix (MPRIS_PREFIX)){
93 MprisRoot? mpris2_root = this.create_mpris_root(address);
94 if (mpris2_root == null) return;
95@@ -71,13 +99,14 @@
96 }
97 }
98
99- private void name_changes_detected ( FreeDesktopObject dbus_obj,
100- string name,
101- string previous_owner,
102- string current_owner )
103+ public void name_owner_changed (DBusConnection con, string sender, string object_path,
104+ string interface_name, string signal_name, Variant parameters)
105 {
106- MprisRoot? mpris2_root = this.create_mpris_root(name);
107-
108+ string name, previous_owner, current_owner;
109+
110+ parameters.get ("(sss)", out name, out previous_owner, out current_owner);
111+
112+ MprisRoot? mpris2_root = this.create_mpris_root (name);
113 if (mpris2_root == null) return;
114
115 if (previous_owner != "" && current_owner == "") {

Subscribers

People subscribed via source and target branches