[banshee] Gio: protect call to event delegates in HardwareManager



commit 3efd419d7dcdf4597645b93b2d48e72a3f8ca88e
Author: Nicholas Little <arealityfarbetween googlemail com>
Date:   Tue Jun 3 13:24:52 2014 +0200

    Gio: protect call to event delegates in HardwareManager
    
    Make Gio's HardwareManager class respect this concurrency rule
    that is already a good practice held in other parts of the
    codebase. (For a good explanation, you can check [1])
    
    This commit also makes the event handling more consistent to
    how it is done in other parts of this class (having two overloads
    of the same method, with different parameter types).
    
    [1] http://www.mono-project.com/Gendarme.Rules.Concurrency#ProtectCallToEventDelegatesRule
    
    Signed-off-by: Andrés G. Aragoneses <knocte gmail com>

 .../Banshee.Hardware.Gio/HardwareManager.cs        |   25 ++++++++++++++++----
 1 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/HardwareManager.cs 
b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/HardwareManager.cs
index fe3366c..7a299b1 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/HardwareManager.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/HardwareManager.cs
@@ -56,15 +56,30 @@ namespace Banshee.Hardware.Gio
 
         void HandleManagerDeviceRemoved (object o, MountArgs args)
         {
-            if (DeviceRemoved != null) {
-                DeviceRemoved (this, new DeviceRemovedArgs (args.Device.Uuid));
-            }
+            HandleManagerDeviceRemoved (args.Device);
         }
 
         void HandleManagerDeviceAdded (IDevice device)
         {
-            if (device != null && DeviceAdded != null) {
-                DeviceAdded (this, new DeviceAddedArgs (device));
+            if (device == null) {
+                return;
+            }
+
+            var handler = DeviceAdded;
+            if (handler != null) {
+                handler (this, new DeviceAddedArgs (device));
+            }
+        }
+
+        private void HandleManagerDeviceRemoved (IDevice device)
+        {
+            if (device == null) {
+                return;
+            }
+
+            var handler = DeviceRemoved;
+            if (handler != null) {
+                handler (this, new DeviceRemovedArgs (device.Uuid));
             }
         }
 


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