Merge lp:~rainct/zeitgeist/ugly-as-hell into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Siegfried Gevatter
Status: Superseded
Proposed branch: lp:~rainct/zeitgeist/ugly-as-hell
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 184 lines (+86/-15)
2 files modified
python/client.py (+4/-0)
src/notify.vala (+82/-15)
To merge this branch: bzr merge lp:~rainct/zeitgeist/ugly-as-hell
Reviewer Review Type Date Requested Status
Zeitgeist Framework Team Pending
Review via email: mp+90847@code.launchpad.net

This proposal has been superseded by a proposal from 2012-01-31.

To post a comment you must log in.

Unmerged revisions

379. By Siegfried Gevatter

Python API: Fix double connection to monitors

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'python/client.py'
2--- python/client.py 2011-10-29 13:31:12 +0000
3+++ python/client.py 2012-01-31 10:32:08 +0000
4@@ -172,11 +172,15 @@
5 self._generic_callbacks = set()
6
7 # Listen to (dis)connection notifications, for connect_exit and connect_join
8+ self._first_connection = True
9 def name_owner_changed(connection_name):
10 if connection_name == "":
11 callbacks = self._disconnect_callbacks
12 self.__methods = self.__signals = None
13 else:
14+ if self._first_connection:
15+ self._first_connection = False
16+ return
17 if not self._reconnect_when_needed:
18 return
19 self.reconnect()
20
21=== modified file 'src/notify.vala'
22--- src/notify.vala 2011-10-20 14:20:17 +0000
23+++ src/notify.vala 2012-01-31 10:32:08 +0000
24@@ -32,7 +32,7 @@
25 construct
26 {
27 monitors = new HashTable<string, Monitor> (str_hash, str_equal);
28- connections = new HashTable<string, GenericArray<string>>
29+ connections = new HashTable<string, GenericArray<string>>
30 (str_hash, str_equal);
31
32 // FIXME: it'd be nice if this supported arg2
33@@ -78,9 +78,47 @@
34 private TimeRange time_range;
35 private RemoteMonitor? proxy_object = null;
36
37+ private enum NotificationType
38+ {
39+ INSERTION,
40+ DELETION
41+ }
42+ [Compact]
43+ private class QueuedNotification {
44+ // (Compact classes don't support private fields)
45+ public NotificationType type;
46+ public Variant time_range;
47+ public Variant events; // for insertions
48+ public uint32[] event_ids; // for deletions
49+
50+ public QueuedNotification.insertion (Variant time_range, Variant events)
51+ {
52+ type = NotificationType.INSERTION;
53+ this.time_range = time_range;
54+ this.events = events;
55+ }
56+
57+ public QueuedNotification.deletion (Variant time_range, uint32[] event_ids)
58+ {
59+ type = NotificationType.DELETION;
60+ this.time_range = time_range;
61+ this.event_ids = event_ids;
62+ }
63+
64+ public void send (RemoteMonitor proxy_object)
65+ {
66+ if (type == NotificationType.INSERTION)
67+ proxy_object.notify_insert (time_range, events);
68+ else
69+ proxy_object.notify_delete (time_range, event_ids);
70+ }
71+ }
72+ private SList<QueuedNotification> queued_notifications;
73+
74 public Monitor (BusName peer, string object_path,
75 TimeRange tr, GenericArray<Event> templates)
76 {
77+ queued_notifications = new SList<QueuedNotification> ();
78 Bus.get_proxy<RemoteMonitor> (BusType.SESSION, peer,
79 object_path, DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
80 DBusProxyFlags.DO_NOT_CONNECT_SIGNALS,
81@@ -94,6 +132,15 @@
82 {
83 warning ("%s", err.message);
84 }
85+
86+ // Process queued notifications...
87+ queued_notifications.reverse ();
88+ foreach (unowned QueuedNotification notification
89+ in queued_notifications)
90+ {
91+ notification.send (proxy_object);
92+ }
93+ queued_notifications = null;
94 });
95 time_range = tr;
96 event_templates = templates;
97@@ -113,15 +160,13 @@
98 return false;
99 }
100
101- // FIXME: we need to queue the notification if proxy_object == null
102 public void notify_insert (TimeRange time_range, GenericArray<Event> events)
103- requires (proxy_object != null)
104 {
105 var intersect_tr = time_range.intersect (this.time_range);
106 if (intersect_tr != null)
107 {
108 var matching_events = new GenericArray<Event> ();
109- for (int i=0; i<events.length; i++)
110+ for (int i = 0; i < events.length; i++)
111 {
112 if (events[i] != null && matches (events[i])
113 && events[i].timestamp >= intersect_tr.start
114@@ -132,24 +177,46 @@
115 }
116 if (matching_events.length > 0)
117 {
118- DBusProxy p = (DBusProxy) proxy_object;
119- debug ("Notifying %s about %d insertions",
120- p.get_name (), matching_events.length);
121-
122- proxy_object.notify_insert (intersect_tr.to_variant (),
123- Events.to_variant (matching_events));
124+ Variant time_v = intersect_tr.to_variant ();
125+ // FIXME: do we want to "cache" this for sharing
126+ // between monitors?
127+ Variant events_v = Events.to_variant (matching_events);
128+
129+ if (proxy_object != null)
130+ {
131+ DBusProxy p = (DBusProxy) proxy_object;
132+ debug ("Notifying %s about %d insertions",
133+ p.get_name (), matching_events.length);
134+
135+ proxy_object.notify_insert (time_v, events_v);
136+ }
137+ else
138+ {
139+ debug ("Queueing notification about %d insertions",
140+ matching_events.length);
141+ queued_notifications.prepend (
142+ new QueuedNotification.insertion (time_v, events_v));
143+ }
144 }
145 }
146 }
147
148 public void notify_delete (TimeRange time_range, uint32[] event_ids)
149- requires (proxy_object != null)
150 {
151 var intersect_tr = time_range.intersect (this.time_range);
152 if (intersect_tr != null)
153 {
154- proxy_object.notify_delete (intersect_tr.to_variant (),
155- event_ids);
156+ Variant time_v = intersect_tr.to_variant ();
157+
158+ if (proxy_object != null)
159+ {
160+ proxy_object.notify_delete (time_v, event_ids);
161+ }
162+ else
163+ {
164+ queued_notifications.prepend (
165+ new QueuedNotification.deletion (time_v, event_ids));
166+ }
167 }
168 }
169 }
170@@ -179,12 +246,12 @@
171 {
172 debug ("Removing monitor %s%s", peer, object_path);
173 var hash = "%s#%s".printf (peer, object_path);
174-
175+
176 if (monitors.lookup (hash) != null)
177 monitors.remove (hash);
178 else
179 warning ("There's no monitor installed for %s", hash);
180-
181+
182 if (connections.lookup (peer) != null)
183 {
184 var paths = connections.lookup (peer);

Subscribers

People subscribed via source and target branches