~rainct/zeitgeist/rebuild-fts-on-new-db

« back to all changes in this revision

Viewing changes to src/notify.vala

  • Committer: Michal Hruby
  • Date: 2012-02-07 12:46:46 UTC
  • mto: This revision was merged to the branch mainline in revision 390.
  • Revision ID: michal.mhr@gmail.com-20120207124646-oyk4anmdpntrf7jl
Turn MonitorManager into a kind-of-singleton

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    public class MonitorManager : Object
27
27
    {
28
28
 
 
29
        private static unowned MonitorManager? instance;
 
30
 
29
31
        private HashTable<string, Monitor> monitors;
30
32
        private HashTable<string, GenericArray<string>> connections;
31
33
 
 
34
        // ref-counted singleton - it can get destroyed easily, but has
 
35
        // singleton semantics as long as some top-level instance keeps
 
36
        // a reference to it
 
37
        public static MonitorManager get_default ()
 
38
        {
 
39
            return instance ?? new MonitorManager ();
 
40
        }
 
41
 
 
42
        private MonitorManager ()
 
43
        {
 
44
        }
 
45
 
 
46
        ~MonitorManager ()
 
47
        {
 
48
            instance = null;
 
49
        }
 
50
 
32
51
        construct
33
52
        {
 
53
            instance = this;
 
54
 
34
55
            monitors = new HashTable<string, Monitor> (str_hash, str_equal);
35
56
            connections = new HashTable<string, GenericArray<string>>
36
57
                (str_hash, str_equal);
53
74
 
54
75
                        foreach (var owner in connections.get_keys())
55
76
                        {
56
 
                            if (arg0 == owner)
 
77
                            // Don't disconnect monitors using service names
 
78
                            if (arg0 == owner && g_dbus_is_unique_name (arg0))
57
79
                            {
58
80
                                var paths = connections.lookup (arg0);
59
81
                                debug("Client disconnected %s", owner);
120
142
            {
121
143
                queued_notifications = new SList<QueuedNotification> ();
122
144
                Bus.get_proxy<RemoteMonitor> (BusType.SESSION, peer,
123
 
                    object_path, DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
124
 
                    DBusProxyFlags.DO_NOT_CONNECT_SIGNALS,
 
145
                    object_path,
 
146
                    DBusProxyFlags.DO_NOT_LOAD_PROPERTIES
 
147
                    | DBusProxyFlags.DO_NOT_CONNECT_SIGNALS
 
148
                    | DBusProxyFlags.DO_NOT_AUTO_START,
125
149
                    null, (obj, res) =>
126
150
                    {
127
151
                        try
128
152
                        {
129
153
                            proxy_object = Bus.get_proxy.end (res);
 
154
                            // Process queued notifications...
 
155
                            flush_notifications ();
 
156
 
 
157
                            proxy_object.notify["g-name-owner"].connect (name_owner_changed);
130
158
                        }
131
159
                        catch (IOError err)
132
160
                        {
133
161
                            warning ("%s", err.message);
134
162
                        }
135
 
 
136
 
                        // Process queued notifications...
137
 
                        queued_notifications.reverse ();
138
 
                        foreach (unowned QueuedNotification notification
139
 
                            in queued_notifications)
140
 
                        {
141
 
                            notification.send (proxy_object);
142
 
                        }
143
 
                        queued_notifications = null;
144
163
                    });
145
164
                time_range = tr;
146
165
                event_templates = templates;
147
166
            }
148
167
 
 
168
            private void name_owner_changed ()
 
169
                requires (proxy_object != null)
 
170
            {
 
171
                // FIXME: can we use this to actually remove the monitor?
 
172
                //  (instead of using NameOwnerChanged signal)
 
173
                DBusProxy p = proxy_object as DBusProxy;
 
174
                if (p.g_name_owner != null) flush_notifications ();
 
175
            }
 
176
 
 
177
            private void flush_notifications ()
 
178
            {
 
179
                queued_notifications.reverse ();
 
180
                foreach (unowned QueuedNotification notification
 
181
                    in queued_notifications)
 
182
                {
 
183
                    notification.send (proxy_object);
 
184
                }
 
185
                queued_notifications = null;
 
186
            }
 
187
 
149
188
            private bool matches (Event event)
150
189
            {
151
190
                if (event_templates.length == 0)
182
221
                        // between monitors?
183
222
                        Variant events_v = Events.to_variant (matching_events);
184
223
 
 
224
                        string? name_owner = null;
185
225
                        if (proxy_object != null)
186
226
                        {
 
227
                            DBusProxy p = proxy_object as DBusProxy;
 
228
                            if (p != null) name_owner = p.g_name_owner;
 
229
                        }
 
230
 
 
231
                        if (proxy_object != null && name_owner != null)
 
232
                        {
187
233
                            DBusProxy p = (DBusProxy) proxy_object;
188
234
                            debug ("Notifying %s about %d insertions",
189
235
                                p.get_name (), matching_events.length);
208
254
                {
209
255
                    Variant time_v = intersect_tr.to_variant ();
210
256
 
 
257
                    string? name_owner = null;
211
258
                    if (proxy_object != null)
212
259
                    {
 
260
                        DBusProxy p = proxy_object as DBusProxy;
 
261
                        if (p != null) name_owner = p.g_name_owner;
 
262
                    }
 
263
 
 
264
                    if (proxy_object != null && name_owner != null)
 
265
                    {
213
266
                        proxy_object.notify_delete (time_v, event_ids);
214
267
                    }
215
268
                    else