[kdbus] KDBUS_ITEM_PAYLOAD_OFF items are (once again) relative to msg header
[platform/upstream/glib.git] / gio / gfilemonitor.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
17  *
18  * Author: Alexander Larsson <alexl@redhat.com>
19  */
20
21 #include "config.h"
22 #include <string.h>
23
24 #include "gfilemonitor.h"
25 #include "gioenumtypes.h"
26 #include "gfile.h"
27 #include "gvfs.h"
28 #include "glibintl.h"
29
30
31 struct _FileChange;
32 typedef struct _FileChange FileChange;
33 static void file_change_free (FileChange *change);
34
35 /**
36  * SECTION:gfilemonitor
37  * @short_description: File Monitor
38  * @include: gio/gio.h
39  *
40  * Monitors a file or directory for changes.
41  *
42  * To obtain a #GFileMonitor for a file or directory, use
43  * g_file_monitor(), g_file_monitor_file(), or
44  * g_file_monitor_directory().
45  *
46  * To get informed about changes to the file or directory you are
47  * monitoring, connect to the #GFileMonitor::changed signal. The
48  * signal will be emitted in the
49  * [thread-default main context][g-main-context-push-thread-default]
50  * of the thread that the monitor was created in
51  * (though if the global default main context is blocked, this may
52  * cause notifications to be blocked even if the thread-default
53  * context is still running).
54  **/
55
56 G_LOCK_DEFINE_STATIC(cancelled);
57
58 enum {
59   CHANGED,
60   LAST_SIGNAL
61 };
62
63 typedef struct {
64   GFile *file;
65   guint32 last_sent_change_time; /* 0 == not sent */
66   guint32 send_delayed_change_at; /* 0 == never */
67   guint32 send_virtual_changes_done_at; /* 0 == never */
68 } RateLimiter;
69
70 struct _GFileMonitorPrivate {
71   gboolean cancelled;
72   int rate_limit_msec;
73
74   /* Rate limiting change events */
75   GHashTable *rate_limiter;
76
77   GMutex mutex;
78   GSource *pending_file_change_source;
79   GSList *pending_file_changes; /* FileChange */
80
81   GSource *timeout;
82   guint32 timeout_fires_at;
83
84   GMainContext *context;
85 };
86
87 enum {
88   PROP_0,
89   PROP_RATE_LIMIT,
90   PROP_CANCELLED,
91   PROP_CONTEXT
92 };
93
94 /* work around a limitation of the aliasing foo */
95 #undef g_file_monitor
96
97 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GFileMonitor, g_file_monitor, G_TYPE_OBJECT)
98
99 static void
100 g_file_monitor_set_property (GObject      *object,
101                              guint         prop_id,
102                              const GValue *value,
103                              GParamSpec   *pspec)
104 {
105   GFileMonitor *monitor;
106
107   monitor = G_FILE_MONITOR (object);
108
109   switch (prop_id)
110     {
111     case PROP_RATE_LIMIT:
112       g_file_monitor_set_rate_limit (monitor, g_value_get_int (value));
113       break;
114
115     case PROP_CONTEXT:
116       monitor->priv->context = g_value_dup_boxed (value);
117       if (monitor->priv->context == NULL)
118         monitor->priv->context = g_main_context_ref_thread_default ();
119       break;
120
121     default:
122       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
123       break;
124     }
125 }
126
127 static void
128 g_file_monitor_get_property (GObject    *object,
129                              guint       prop_id,
130                              GValue     *value,
131                              GParamSpec *pspec)
132 {
133   GFileMonitor *monitor;
134   GFileMonitorPrivate *priv;
135
136   monitor = G_FILE_MONITOR (object);
137   priv = monitor->priv;
138
139   switch (prop_id)
140     {
141     case PROP_RATE_LIMIT:
142       g_value_set_int (value, priv->rate_limit_msec);
143       break;
144
145     case PROP_CANCELLED:
146       G_LOCK (cancelled);
147       g_value_set_boolean (value, priv->cancelled);
148       G_UNLOCK (cancelled);
149       break;
150
151     default:
152       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
153       break;
154     }
155 }
156
157 #define DEFAULT_RATE_LIMIT_MSECS 800
158 #define DEFAULT_VIRTUAL_CHANGES_DONE_DELAY_SECS 2
159
160 static guint signals[LAST_SIGNAL] = { 0 };
161
162 static void
163 rate_limiter_free (RateLimiter *limiter)
164 {
165   g_object_unref (limiter->file);
166   g_slice_free (RateLimiter, limiter);
167 }
168
169 static void
170 g_file_monitor_finalize (GObject *object)
171 {
172   GFileMonitor *monitor;
173
174   monitor = G_FILE_MONITOR (object);
175
176   if (monitor->priv->timeout)
177     {
178       g_source_destroy (monitor->priv->timeout);
179       g_source_unref (monitor->priv->timeout);
180     }
181
182   g_hash_table_destroy (monitor->priv->rate_limiter);
183
184   g_main_context_unref (monitor->priv->context);
185   g_mutex_clear (&monitor->priv->mutex);
186
187   G_OBJECT_CLASS (g_file_monitor_parent_class)->finalize (object);
188 }
189
190 static void
191 g_file_monitor_dispose (GObject *object)
192 {
193   GFileMonitor *monitor;
194   GFileMonitorPrivate *priv;
195   
196   monitor = G_FILE_MONITOR (object);
197   priv = monitor->priv;
198
199   if (priv->pending_file_change_source)
200     {
201       g_source_destroy (priv->pending_file_change_source);
202       g_source_unref (priv->pending_file_change_source);
203       priv->pending_file_change_source = NULL;
204     }
205   g_slist_free_full (priv->pending_file_changes, (GDestroyNotify) file_change_free);
206   priv->pending_file_changes = NULL;
207
208   /* Make sure we cancel on last unref */
209   g_file_monitor_cancel (monitor);
210
211   G_OBJECT_CLASS (g_file_monitor_parent_class)->dispose (object);
212 }
213
214 static void
215 g_file_monitor_class_init (GFileMonitorClass *klass)
216 {
217   GObjectClass *object_class;
218
219   object_class = G_OBJECT_CLASS (klass);
220   object_class->finalize = g_file_monitor_finalize;
221   object_class->dispose = g_file_monitor_dispose;
222   object_class->get_property = g_file_monitor_get_property;
223   object_class->set_property = g_file_monitor_set_property;
224
225   /**
226    * GFileMonitor::changed:
227    * @monitor: a #GFileMonitor.
228    * @file: a #GFile.
229    * @other_file: (allow-none): a #GFile or #NULL.
230    * @event_type: a #GFileMonitorEvent.
231    *
232    * Emitted when @file has been changed.
233    *
234    * If using #G_FILE_MONITOR_SEND_MOVED flag and @event_type is
235    * #G_FILE_MONITOR_EVENT_MOVED, @file will be set to a #GFile containing the
236    * old path, and @other_file will be set to a #GFile containing the new path.
237    *
238    * In all the other cases, @other_file will be set to #NULL.
239    **/
240   signals[CHANGED] =
241     g_signal_new (I_("changed"),
242                   G_TYPE_FILE_MONITOR,
243                   G_SIGNAL_RUN_LAST,
244                   G_STRUCT_OFFSET (GFileMonitorClass, changed),
245                   NULL, NULL,
246                   NULL,
247                   G_TYPE_NONE, 3,
248                   G_TYPE_FILE, G_TYPE_FILE, G_TYPE_FILE_MONITOR_EVENT);
249
250   g_object_class_install_property (object_class,
251                                    PROP_RATE_LIMIT,
252                                    g_param_spec_int ("rate-limit",
253                                                      P_("Rate limit"),
254                                                      P_("The limit of the monitor to watch for changes, in milliseconds"),
255                                                      0, G_MAXINT,
256                                                      DEFAULT_RATE_LIMIT_MSECS,
257                                                      G_PARAM_READWRITE|
258                                                      G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
259
260   g_object_class_install_property (object_class,
261                                    PROP_CANCELLED,
262                                    g_param_spec_boolean ("cancelled",
263                                                          P_("Cancelled"),
264                                                          P_("Whether the monitor has been cancelled"),
265                                                          FALSE,
266                                                          G_PARAM_READABLE|
267                                                          G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
268
269   g_object_class_install_property (object_class,
270                                    PROP_CONTEXT,
271                                    g_param_spec_boxed ("context",
272                                                        P_("Context"),
273                                                        P_("The main context to dispatch from"),
274                                                        G_TYPE_MAIN_CONTEXT, G_PARAM_WRITABLE |
275                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
276 }
277
278 static void
279 g_file_monitor_init (GFileMonitor *monitor)
280 {
281   monitor->priv = g_file_monitor_get_instance_private (monitor);
282   monitor->priv->rate_limit_msec = DEFAULT_RATE_LIMIT_MSECS;
283   monitor->priv->rate_limiter = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal,
284                                                        NULL, (GDestroyNotify) rate_limiter_free);
285   g_mutex_init (&monitor->priv->mutex);
286 }
287
288 /**
289  * g_file_monitor_is_cancelled:
290  * @monitor: a #GFileMonitor
291  * 
292  * Returns whether the monitor is canceled.
293  *
294  * Returns: %TRUE if monitor is canceled. %FALSE otherwise.
295  **/
296 gboolean
297 g_file_monitor_is_cancelled (GFileMonitor *monitor)
298 {
299   gboolean res;
300
301   g_return_val_if_fail (G_IS_FILE_MONITOR (monitor), FALSE);
302
303   G_LOCK (cancelled);
304   res = monitor->priv->cancelled;
305   G_UNLOCK (cancelled);
306   
307   return res;
308 }
309
310 /**
311  * g_file_monitor_cancel:
312  * @monitor: a #GFileMonitor.
313  * 
314  * Cancels a file monitor.
315  * 
316  * Returns: %TRUE if monitor was cancelled.
317  **/
318 gboolean
319 g_file_monitor_cancel (GFileMonitor* monitor)
320 {
321   GFileMonitorClass *klass;
322   
323   g_return_val_if_fail (G_IS_FILE_MONITOR (monitor), FALSE);
324   
325   G_LOCK (cancelled);
326   if (monitor->priv->cancelled)
327     {
328       G_UNLOCK (cancelled);
329       return TRUE;
330     }
331   
332   monitor->priv->cancelled = TRUE;
333   G_UNLOCK (cancelled);
334   
335   g_object_notify (G_OBJECT (monitor), "cancelled");
336
337   klass = G_FILE_MONITOR_GET_CLASS (monitor);
338   return (* klass->cancel) (monitor);
339 }
340
341 /**
342  * g_file_monitor_set_rate_limit:
343  * @monitor: a #GFileMonitor.
344  * @limit_msecs: a non-negative integer with the limit in milliseconds
345  *     to poll for changes
346  *
347  * Sets the rate limit to which the @monitor will report
348  * consecutive change events to the same file.
349  */
350 void
351 g_file_monitor_set_rate_limit (GFileMonitor *monitor,
352                                gint          limit_msecs)
353 {
354   GFileMonitorPrivate *priv;
355
356   g_return_if_fail (G_IS_FILE_MONITOR (monitor));
357   g_return_if_fail (limit_msecs >= 0);
358
359   priv = monitor->priv;
360   if (priv->rate_limit_msec != limit_msecs)
361     {
362       monitor->priv->rate_limit_msec = limit_msecs;
363       g_object_notify (G_OBJECT (monitor), "rate-limit");
364     }
365 }
366
367 struct _FileChange {
368   GFile             *child;
369   GFile             *other_file;
370   GFileMonitorEvent  event_type;
371 };
372
373 static void
374 file_change_free (FileChange *change)
375 {
376   g_object_unref (change->child);
377   if (change->other_file)
378     g_object_unref (change->other_file);
379   
380   g_slice_free (FileChange, change);
381 }
382
383 static gboolean
384 emit_cb (gpointer data)
385 {
386   GFileMonitor *monitor = G_FILE_MONITOR (data);
387   GSList *pending, *iter;
388
389   g_mutex_lock (&monitor->priv->mutex);
390   pending = g_slist_reverse (monitor->priv->pending_file_changes);
391   monitor->priv->pending_file_changes = NULL;
392   if (monitor->priv->pending_file_change_source)
393     {
394       g_source_unref (monitor->priv->pending_file_change_source);
395       monitor->priv->pending_file_change_source = NULL;
396     }
397   g_mutex_unlock (&monitor->priv->mutex);
398
399   g_object_ref (monitor);
400   for (iter = pending; iter; iter = iter->next)
401     {
402        FileChange *change = iter->data;
403
404        g_signal_emit (monitor, signals[CHANGED], 0,
405                       change->child, change->other_file, change->event_type);
406        file_change_free (change);
407     }
408   g_slist_free (pending);
409   g_object_unref (monitor);
410
411   return FALSE;
412 }
413
414 static void
415 emit_in_idle (GFileMonitor      *monitor,
416               GFile             *child,
417               GFile             *other_file,
418               GFileMonitorEvent  event_type)
419 {
420   GSource *source;
421   FileChange *change;
422   GFileMonitorPrivate *priv;
423
424   priv = monitor->priv;
425
426   change = g_slice_new (FileChange);
427
428   change->child = g_object_ref (child);
429   if (other_file)
430     change->other_file = g_object_ref (other_file);
431   else
432     change->other_file = NULL;
433   change->event_type = event_type;
434
435   g_mutex_lock (&monitor->priv->mutex);
436   if (!priv->pending_file_change_source)
437     {
438       source = g_idle_source_new ();
439       priv->pending_file_change_source = source;
440       g_source_set_priority (source, 0);
441
442       /* We don't ref monitor here - instead dispose will free any
443        * pending idles.
444        */
445       g_source_set_callback (source, emit_cb, monitor, NULL);
446       g_source_set_name (source, "[gio] emit_cb");
447       g_source_attach (source, monitor->priv->context);
448     }
449   /* We reverse this in the processor */
450   priv->pending_file_changes = g_slist_prepend (priv->pending_file_changes, change);
451   g_mutex_unlock (&monitor->priv->mutex);
452 }
453
454 static guint32
455 get_time_msecs (void)
456 {
457   return g_get_monotonic_time () / G_TIME_SPAN_MILLISECOND;
458 }
459
460 static guint32
461 time_difference (guint32 from, guint32 to)
462 {
463   if (from > to)
464     return 0;
465   return to - from;
466 }
467
468 /* Change event rate limiting support: */
469
470 static RateLimiter *
471 new_limiter (GFileMonitor *monitor,
472              GFile             *file)
473 {
474   RateLimiter *limiter;
475
476   limiter = g_slice_new0 (RateLimiter);
477   limiter->file = g_object_ref (file);
478   g_hash_table_insert (monitor->priv->rate_limiter, file, limiter);
479   
480   return limiter;
481 }
482
483 static void
484 rate_limiter_send_virtual_changes_done_now (GFileMonitor *monitor, 
485                                             RateLimiter  *limiter)
486 {
487   if (limiter->send_virtual_changes_done_at != 0)
488     {
489       emit_in_idle (monitor, limiter->file, NULL,
490                     G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT);
491       limiter->send_virtual_changes_done_at = 0;
492     }
493 }
494
495 static void
496 rate_limiter_send_delayed_change_now (GFileMonitor *monitor, 
497                                       RateLimiter *limiter, 
498                                       guint32 time_now)
499 {
500   if (limiter->send_delayed_change_at != 0)
501     {
502       emit_in_idle (monitor, 
503                     limiter->file, NULL,
504                     G_FILE_MONITOR_EVENT_CHANGED);
505       limiter->send_delayed_change_at = 0;
506       limiter->last_sent_change_time = time_now;
507     }
508 }
509
510 typedef struct {
511   guint32 min_time;
512   guint32 time_now;
513   GFileMonitor *monitor;
514 } ForEachData;
515
516 static gboolean
517 calc_min_time (GFileMonitor *monitor, 
518                RateLimiter *limiter, 
519                guint32 time_now, 
520                guint32 *min_time)
521 {
522   gboolean delete_me;
523   guint32 expire_at;
524
525   delete_me = TRUE;
526
527   if (limiter->last_sent_change_time != 0)
528     {
529       /* Set a timeout at 2*rate limit so that we can clear out the change from the hash eventually */
530       expire_at = limiter->last_sent_change_time + 2 * monitor->priv->rate_limit_msec;
531
532       if (time_difference (time_now, expire_at) > 0)
533         {
534           delete_me = FALSE;
535           *min_time = MIN (*min_time,
536                            time_difference (time_now, expire_at));
537         }
538     }
539
540   if (limiter->send_delayed_change_at != 0)
541     {
542       delete_me = FALSE;
543       *min_time = MIN (*min_time,
544                        time_difference (time_now, limiter->send_delayed_change_at));
545     }
546
547   if (limiter->send_virtual_changes_done_at != 0)
548     {
549       delete_me = FALSE;
550       *min_time = MIN (*min_time,
551                        time_difference (time_now, limiter->send_virtual_changes_done_at));
552     }
553
554   return delete_me;
555 }
556
557 static gboolean
558 foreach_rate_limiter_fire (gpointer key,
559                            gpointer value,
560                            gpointer user_data)
561 {
562   RateLimiter *limiter = value;
563   ForEachData *data = user_data;
564
565   if (limiter->send_delayed_change_at != 0 &&
566       time_difference (data->time_now, limiter->send_delayed_change_at) == 0)
567     rate_limiter_send_delayed_change_now (data->monitor, limiter, data->time_now);
568   
569   if (limiter->send_virtual_changes_done_at != 0 &&
570       time_difference (data->time_now, limiter->send_virtual_changes_done_at) == 0)
571     rate_limiter_send_virtual_changes_done_now (data->monitor, limiter);
572   
573   return calc_min_time (data->monitor, limiter, data->time_now, &data->min_time);
574 }
575
576 static gboolean 
577 rate_limiter_timeout (gpointer timeout_data)
578 {
579   GFileMonitor *monitor = timeout_data;
580   ForEachData data;
581   GSource *source;
582   
583   data.min_time = G_MAXUINT32;
584   data.monitor = monitor;
585   data.time_now = get_time_msecs ();
586   g_hash_table_foreach_remove (monitor->priv->rate_limiter,
587                                foreach_rate_limiter_fire,
588                                &data);
589   
590   /* Remove old timeout */
591   if (monitor->priv->timeout)
592     {
593       g_source_destroy (monitor->priv->timeout);
594       g_source_unref (monitor->priv->timeout);
595       monitor->priv->timeout = NULL;
596       monitor->priv->timeout_fires_at = 0;
597     }
598   
599   /* Set up new timeout */
600   if (data.min_time != G_MAXUINT32)
601     {
602       source = g_timeout_source_new (data.min_time + 1); /* + 1 to make sure we've really passed the time */
603       g_source_set_callback (source, rate_limiter_timeout, monitor, NULL);
604       g_source_attach (source, monitor->priv->context);
605       
606       monitor->priv->timeout = source;
607       monitor->priv->timeout_fires_at = data.time_now + data.min_time; 
608     }
609   
610   return FALSE;
611 }
612
613 static gboolean
614 foreach_rate_limiter_update (gpointer key,
615                              gpointer value,
616                              gpointer user_data)
617 {
618   RateLimiter *limiter = value;
619   ForEachData *data = user_data;
620
621   return calc_min_time (data->monitor, limiter, data->time_now, &data->min_time);
622 }
623
624 static void
625 update_rate_limiter_timeout (GFileMonitor *monitor, 
626                              guint new_time)
627 {
628   ForEachData data;
629   GSource *source;
630   
631   if (monitor->priv->timeout_fires_at != 0 && new_time != 0 &&
632       time_difference (new_time, monitor->priv->timeout_fires_at) == 0)
633     return; /* Nothing to do, we already fire earlier than that */
634
635   data.min_time = G_MAXUINT32;
636   data.monitor = monitor;
637   data.time_now = get_time_msecs ();
638   g_hash_table_foreach_remove (monitor->priv->rate_limiter,
639                                foreach_rate_limiter_update,
640                                &data);
641
642   /* Remove old timeout */
643   if (monitor->priv->timeout)
644     {
645       g_source_destroy (monitor->priv->timeout);
646       g_source_unref (monitor->priv->timeout);
647       monitor->priv->timeout_fires_at = 0;
648       monitor->priv->timeout = NULL;
649     }
650
651   /* Set up new timeout */
652   if (data.min_time != G_MAXUINT32)
653     {
654       source = g_timeout_source_new (data.min_time + 1);  /* + 1 to make sure we've really passed the time */
655       g_source_set_callback (source, rate_limiter_timeout, monitor, NULL);
656       g_source_attach (source, monitor->priv->context);
657       
658       monitor->priv->timeout = source;
659       monitor->priv->timeout_fires_at = data.time_now + data.min_time; 
660     }
661 }
662
663 /**
664  * g_file_monitor_emit_event:
665  * @monitor: a #GFileMonitor.
666  * @child: a #GFile.
667  * @other_file: a #GFile.
668  * @event_type: a set of #GFileMonitorEvent flags.
669  * 
670  * Emits the #GFileMonitor::changed signal if a change
671  * has taken place. Should be called from file monitor 
672  * implementations only.
673  *
674  * The signal will be emitted from an idle handler (in the
675  * [thread-default main context][g-main-context-push-thread-default]).
676  **/
677 void
678 g_file_monitor_emit_event (GFileMonitor      *monitor,
679                            GFile             *child,
680                            GFile             *other_file,
681                            GFileMonitorEvent  event_type)
682 {
683   guint32 time_now, since_last;
684   gboolean emit_now;
685   RateLimiter *limiter;
686
687   g_return_if_fail (G_IS_FILE_MONITOR (monitor));
688   g_return_if_fail (G_IS_FILE (child));
689
690   limiter = g_hash_table_lookup (monitor->priv->rate_limiter, child);
691
692   if (event_type != G_FILE_MONITOR_EVENT_CHANGED)
693     {
694       if (limiter)
695         {
696           rate_limiter_send_delayed_change_now (monitor, limiter, get_time_msecs ());
697           if (event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
698             limiter->send_virtual_changes_done_at = 0;
699           else
700             rate_limiter_send_virtual_changes_done_now (monitor, limiter);
701           update_rate_limiter_timeout (monitor, 0);
702         }
703       emit_in_idle (monitor, child, other_file, event_type);
704     }
705   else
706     {
707       /* Changed event, rate limit */
708       time_now = get_time_msecs ();
709       emit_now = TRUE;
710       
711       if (limiter)
712         {
713           since_last = time_difference (limiter->last_sent_change_time, time_now);
714           if (since_last < monitor->priv->rate_limit_msec)
715             {
716               /* We ignore this change, but arm a timer so that we can fire it later if we
717                  don't get any other events (that kill this timeout) */
718               emit_now = FALSE;
719               if (limiter->send_delayed_change_at == 0)
720                 {
721                   limiter->send_delayed_change_at = time_now + monitor->priv->rate_limit_msec;
722                   update_rate_limiter_timeout (monitor, limiter->send_delayed_change_at);
723                 }
724             }
725         }
726       
727       if (limiter == NULL)
728         limiter = new_limiter (monitor, child);
729       
730       if (emit_now)
731         {
732           emit_in_idle (monitor, child, other_file, event_type);
733           
734           limiter->last_sent_change_time = time_now;
735           limiter->send_delayed_change_at = 0;
736           /* Set a timeout of 2*rate limit so that we can clear out the change from the hash eventually */
737           update_rate_limiter_timeout (monitor, time_now + 2 * monitor->priv->rate_limit_msec);
738         }
739       
740       /* Schedule a virtual change done. This is removed if we get a real one, and
741          postponed if we get more change events. */
742       
743       limiter->send_virtual_changes_done_at = time_now + DEFAULT_VIRTUAL_CHANGES_DONE_DELAY_SECS * 1000;
744       update_rate_limiter_timeout (monitor, limiter->send_virtual_changes_done_at);
745     }
746 }