← Back to team overview

zeitgeist team mailing list archive

[Branch ~zeitgeist/zeitgeist/bluebird] Rev 321: Handle null events in event array properly

 

------------------------------------------------------------
revno: 321
committer: Michal Hruby <michal.mhr@xxxxxxxxx>
branch nick: bb-fts
timestamp: Thu 2011-10-20 16:20:17 +0200
message:
  Handle null events in event array properly
modified:
  extensions/blacklist.vala
  src/notify.vala
  src/zeitgeist-daemon.vala


--
lp:~zeitgeist/zeitgeist/bluebird
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird

Your team Zeitgeist Framework Team is subscribed to branch lp:~zeitgeist/zeitgeist/bluebird.
To unsubscribe from this branch go to https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== modified file 'extensions/blacklist.vala'
--- extensions/blacklist.vala	2011-09-29 15:30:04 +0000
+++ extensions/blacklist.vala	2011-10-20 14:20:17 +0000
@@ -147,6 +147,7 @@
         {
             for (int i = 0; i < events.length; i++)
             {
+                if (events[i] == null) continue;
                 foreach (var tmpl in blacklist.get_values ())
                 {
                     if (events[i].matches_template (tmpl))

=== modified file 'src/notify.vala'
--- src/notify.vala	2011-09-17 21:28:51 +0000
+++ src/notify.vala	2011-10-20 14:20:17 +0000
@@ -117,17 +117,17 @@
             public void notify_insert (TimeRange time_range, GenericArray<Event> events)
                 requires (proxy_object != null)
             {
-                var intersection_timerange = time_range.intersect(this.time_range);
-                if (intersection_timerange != null)
+                var intersect_tr = time_range.intersect (this.time_range);
+                if (intersect_tr != null)
                 {
-                    var matching_events = new GenericArray<Event>();
+                    var matching_events = new GenericArray<Event> ();
                     for (int i=0; i<events.length; i++)
                     {
-                        if (matches(events[i]) 
-                            && events[i].timestamp >= intersection_timerange.start
-                            && events[i].timestamp <= intersection_timerange.end)
+                        if (events[i] != null && matches (events[i])
+                            && events[i].timestamp >= intersect_tr.start
+                            && events[i].timestamp <= intersect_tr.end)
                         {
-                            matching_events.add(events[i]);
+                            matching_events.add (events[i]);
                         }
                     }
                     if (matching_events.length > 0)
@@ -136,7 +136,7 @@
                         debug ("Notifying %s about %d insertions",
                             p.get_name (), matching_events.length);
 
-                        proxy_object.notify_insert (intersection_timerange.to_variant (), 
+                        proxy_object.notify_insert (intersect_tr.to_variant (),
                             Events.to_variant (matching_events));
                     }
                 }
@@ -145,10 +145,10 @@
             public void notify_delete (TimeRange time_range, uint32[] event_ids)
                 requires (proxy_object != null)
             {
-                var intersection_timerange = time_range.intersect(this.time_range);
-                if (intersection_timerange != null)
+                var intersect_tr = time_range.intersect (this.time_range);
+                if (intersect_tr != null)
                 {
-                    proxy_object.notify_delete (intersection_timerange.to_variant (),
+                    proxy_object.notify_delete (intersect_tr.to_variant (),
                         event_ids);
                 }
             }
@@ -177,7 +177,7 @@
 
         public void remove_monitor (BusName peer, string object_path)
         {
-            debug("Removing monitor %s%s", peer, object_path);
+            debug ("Removing monitor %s%s", peer, object_path);
             var hash = "%s#%s".printf (peer, object_path);
             
             if (monitors.lookup (hash) != null)
@@ -197,20 +197,20 @@
                     }
                 }
             }
-            
+
         }
 
         public void notify_insert (TimeRange time_range,
             GenericArray<Event> events)
         {
             foreach (unowned Monitor mon in monitors.get_values ())
-                mon.notify_insert(time_range, events);
+                mon.notify_insert (time_range, events);
         }
 
         public void notify_delete (TimeRange time_range, uint32[] event_ids)
         {
             foreach (unowned Monitor mon in monitors.get_values ())
-                mon.notify_delete(time_range, event_ids);
+                mon.notify_delete (time_range, event_ids);
         }
     }
 

=== modified file 'src/zeitgeist-daemon.vala'
--- src/zeitgeist-daemon.vala	2011-10-13 15:59:53 +0000
+++ src/zeitgeist-daemon.vala	2011-10-20 14:20:17 +0000
@@ -179,14 +179,21 @@
             var events = Events.from_variant (vevents);
 
             uint32[] event_ids = engine.insert_events (events, sender);
-            var min_timestamp = events[0].timestamp;
-            var max_timestamp = min_timestamp;
+            var min_timestamp = int64.MAX;
+            var max_timestamp = int64.MIN;
             for (int i = 0; i < events.length; i++)
             {
+                if (events[i] == null) continue;
                 min_timestamp = int64.min (min_timestamp, events[i].timestamp);
                 max_timestamp = int64.max (max_timestamp, events[i].timestamp);
             }
-            notifications.notify_insert (new TimeRange (min_timestamp, max_timestamp), events);
+
+            if (min_timestamp < int64.MAX)
+            {
+                notifications.notify_insert (
+                    new TimeRange (min_timestamp, max_timestamp), events);
+            }
+            /* else { there's not even one valid event } */
 
             return event_ids;
         }