[blam] Add locks and null checks



commit 43eae60ec68457a57a3a5b2a8d45706fd760eb4d
Author: Carlos Martín Nieto <carlos cmartin tk>
Date:   Thu Mar 24 00:08:47 2011 +0100

    Add locks and null checks
    
    Signed-off-by: Carlos Martín Nieto <carlos cmartin tk>

 src/Channel.cs  |   35 ++++++++++++++++++++++++-----------
 src/Item.cs     |    2 +-
 src/ItemList.cs |    3 +++
 3 files changed, 28 insertions(+), 12 deletions(-)
---
diff --git a/src/Channel.cs b/src/Channel.cs
index 355b94b..3627073 100644
--- a/src/Channel.cs
+++ b/src/Channel.cs
@@ -83,9 +83,11 @@ namespace Imendio.Blam {
                 Item item;
                 lock(obj){
                     foreach (string id in item_list) {
-                        item = store.Items[id] as Item;
-                        if(item.Unread){
-                            ++unread;
+                        if(id != null){
+                            item = store.Items[id] as Item;
+                            if(item.Unread){
+                                ++unread;
+                            }
                         }
                     }
                 }
@@ -100,6 +102,9 @@ namespace Imendio.Blam {
                 Item item;
                 lock(obj){
                     foreach(string id in item_list){
+                        if(id == null){ /* TODO: Figure out why this happens */
+                            continue;
+                        }
                         item = store.Items[id] as Item;
                         if(item != null && item.Unread && !item.Old){
                             ++new_items;
@@ -155,15 +160,20 @@ namespace Imendio.Blam {
 
         public void Setup()
         {
-            for(int i = item_list.Count - 1; i >= 0; --i){
-                string id = item_list[i] as string;
-                Item item = store.Items[id] as Item;
-                /* Maybe it got lost or deleted */
-                if(item == null){
-                    item_list.Remove(id);
-                } else {
-                    item.Updated += ItemUpdated;
+            lock(obj){
+                ArrayList nlist = new ArrayList();
+                foreach(string id in item_list){
+                    if(id == null){
+                        continue;
+                    }
+                    Item item = store.Items[id] as Item;
+                    if(item == null){
+                    } else {
+                        nlist.Add(id);
+                        item.Updated += ItemUpdated;
+                    }
                 }
+                item_list = nlist;
             }
         }
 
@@ -228,6 +238,9 @@ namespace Imendio.Blam {
             foreach(SyndicationItem sitem in feed.Items){
                 nitems.Add(sitem.Id);
                 if(item_list.Contains(sitem.Id)){
+                    if(sitem.Id == null){
+                        continue;
+                    }
                     /* We already had it, so just update it */
                     (store.Items[sitem.Id] as Item).Update(sitem);
                 } else {
diff --git a/src/Item.cs b/src/Item.cs
index 8d5e088..d0f8211 100644
--- a/src/Item.cs
+++ b/src/Item.cs
@@ -18,7 +18,7 @@ namespace Imendio.Blam {
 
         private int ref_cnt = 0;
         private Object obj = new Object();
-        public SyndicationContent exposed_text;
+        public SyndicationContent exposed_text = null;
 
         public delegate void UpdateHandler(Item item);
         public event UpdateHandler Updated;
diff --git a/src/ItemList.cs b/src/ItemList.cs
index f1ff6e7..c1b721a 100644
--- a/src/ItemList.cs
+++ b/src/ItemList.cs
@@ -174,6 +174,9 @@ namespace Imendio.Blam {
 		return;
 	    }
             foreach(string id in channel.ItemList){
+                if(id == null){
+                    continue;
+                }
                 (Model as ListStore).AppendValues(store.Items[id]);
             }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]