Merge lp:~rainct/zeitgeist/monitor-queue into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Siegfried Gevatter
Status: Merged
Approved by: Michal Hruby
Approved revision: 378
Merged at revision: 379
Proposed branch: lp:~rainct/zeitgeist/monitor-queue
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 164 lines (+82/-15)
1 file modified
src/notify.vala (+82/-15)
To merge this branch: bzr merge lp:~rainct/zeitgeist/monitor-queue
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+90720@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

22 + [Compact]
23 + private class InsertionData : NotificationData

I can't help it, but this looks like serious misusage of the type system, I'd rather go with single compact class that has an enum indicating the type plus a method that dispatches a call (passing in the proxy object - although as inner class it should be able to access private members of the parent class iirc)

121 + queued_notifications.append (

Appending SList is really slow, let's prepend and reverse when we're about to flush the queue.

review: Needs Fixing
lp:~rainct/zeitgeist/monitor-queue updated
378. By Siegfried Gevatter

Use a single class for the queued notifications

Revision history for this message
Michal Hruby (mhr3) wrote :

Beautiful :)

review: Approve

Preview Diff

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

Subscribers

People subscribed via source and target branches