banshee r3576 - in trunk/banshee: . src/Backends/Banshee.Hal src/Backends/Banshee.Hal/Banshee.HalBackend src/Core/Banshee.Services/Banshee.Hardware



Author: abock
Date: Fri Mar 28 20:36:14 2008
New Revision: 3576
URL: http://svn.gnome.org/viewvc/banshee?rev=3576&view=rev

Log:
2008-03-28  Aaron Bockover  <abock gnome org>

    * src/Backends/Banshee.Hal/Banshee.HalBackend/BlockDevice.cs: Implement
    GetEnumerator to provide child volumes

    * src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs:
    * src/Backends/Banshee.Hal/Banshee.HalBackend/DiskDevice.cs:
    * src/Backends/Banshee.Hal/Banshee.HalBackend/CdromDevice.cs:
    * src/Backends/Banshee.Hal/Banshee.HalBackend/HardwareManager.cs: Fix up
    protection levels and support holding on to the manager reference

    * src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs: Implemented the
    base HAL volume object with some properties

    * src/Backends/Banshee.Hal/Banshee.HalBackend/DiscVolume.cs: Implemented
    a child HAL volume object for optical disc volumes

    * src/Core/Banshee.Services/Banshee.Hardware/IDiscVolume.cs: Added
    MediaCapacity property

    * src/Core/Banshee.Services/Banshee.Hardware/IVolume.cs: Make Available
    long instead of ulong since it could be invalid (-1)
    
    * src/Core/Banshee.Services/Banshee.Hardware/HardwareManager.cs: Add
    some more tests/debug



Added:
   trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/DiscVolume.cs
   trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Backends/Banshee.Hal/Banshee.Hal.mdp
   trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/BlockDevice.cs
   trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/CdromDevice.cs
   trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs
   trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/DiskDevice.cs
   trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/HardwareManager.cs
   trunk/banshee/src/Backends/Banshee.Hal/Makefile.am
   trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/HardwareManager.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IDiscVolume.cs
   trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IVolume.cs

Modified: trunk/banshee/src/Backends/Banshee.Hal/Banshee.Hal.mdp
==============================================================================
--- trunk/banshee/src/Backends/Banshee.Hal/Banshee.Hal.mdp	(original)
+++ trunk/banshee/src/Backends/Banshee.Hal/Banshee.Hal.mdp	Fri Mar 28 20:36:14 2008
@@ -17,6 +17,8 @@
     <File name="Banshee.HalBackend/BlockDevice.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.HalBackend/CdromDevice.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.HalBackend/DiskDevice.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.HalBackend/Volume.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.HalBackend/DiscVolume.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Project" localcopy="True" refto="Banshee.Core" />

Modified: trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/BlockDevice.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/BlockDevice.cs	(original)
+++ trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/BlockDevice.cs	Fri Mar 28 20:36:14 2008
@@ -36,23 +36,24 @@
 {
     public abstract class BlockDevice : Device, IBlockDevice
     {
-        public static BlockDevice Resolve<T> (Hal.Device device) where T : IBlockDevice
+        public static BlockDevice Resolve<T> (Hal.Manager manager, Hal.Device device) where T : IBlockDevice
         {
             if (device["info.category"] == "storage" && device.QueryCapability ("block") && 
                 device.PropertyExists ("block.device")) {
                 if (typeof (T) == typeof (ICdromDevice)) {
-                    return CdromDevice.Resolve (device);
+                    return CdromDevice.Resolve (manager, device);
                 } else if (typeof (T) == typeof (IDiskDevice)) {
-                    return DiskDevice.Resolve (device);
+                    return DiskDevice.Resolve (manager, device);
                 }
                 
-                return (BlockDevice)CdromDevice.Resolve (device) ?? (BlockDevice)DiskDevice.Resolve (device);
+                return (BlockDevice)CdromDevice.Resolve (manager, device) 
+                    ?? (BlockDevice)DiskDevice.Resolve (manager, device);
             }
             
             return null;
         }
         
-        internal BlockDevice (Hal.Device device) : base (device)
+        protected BlockDevice (Hal.Manager manager, Hal.Device device) : base (manager, device)
         {
         }
         
@@ -66,7 +67,12 @@
         
         public IEnumerator<IVolume> GetEnumerator ()
         {
-            return null;
+            foreach (Hal.Device hal_device in HalDevice.GetChildrenAsDevice (HalManager)) {
+                Volume volume = Volume.Resolve (this, HalManager, hal_device);
+                if (volume != null) {
+                    yield return volume;
+                }
+            }
         }
         
         IEnumerator IEnumerable.GetEnumerator ()

Modified: trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/CdromDevice.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/CdromDevice.cs	(original)
+++ trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/CdromDevice.cs	Fri Mar 28 20:36:14 2008
@@ -36,16 +36,16 @@
 {
     public class CdromDevice : BlockDevice, ICdromDevice
     {
-        public new static CdromDevice Resolve (Hal.Device device)
+        public new static CdromDevice Resolve (Hal.Manager manager, Hal.Device device)
         {
             if (device["storage.drive_type"] == "cdrom") {
-                return new CdromDevice (device);
+                return new CdromDevice (manager, device);
             }
             
             return null;
         }
         
-        internal CdromDevice (Hal.Device device) : base (device)
+        private CdromDevice (Hal.Manager manager, Hal.Device device) : base (manager, device)
         {
         }
     }

Modified: trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs	(original)
+++ trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs	Fri Mar 28 20:36:14 2008
@@ -38,9 +38,15 @@
         protected Hal.Device HalDevice {
             get { return device; }
         }
+        
+        private Hal.Manager manager;
+        protected Hal.Manager HalManager {
+            get { return manager; }
+        }
 
-        internal Device (Hal.Device device)
+        protected Device (Hal.Manager manager, Hal.Device device)
         {
+            this.manager = manager;
             this.device = device;
         }
         

Added: trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/DiscVolume.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/DiscVolume.cs	Fri Mar 28 20:36:14 2008
@@ -0,0 +1,72 @@
+//
+// DiscVolume.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+using Banshee.Hardware;
+
+namespace Banshee.HalBackend
+{
+    public class DiscVolume : Volume, IDiscVolume
+    {
+        public new static DiscVolume Resolve (BlockDevice parent, Hal.Manager manager, Hal.Device device)
+        {
+            return device.QueryCapability ("volume.disc") ? new DiscVolume (parent, manager, device) : null;
+        }
+        
+        private DiscVolume (BlockDevice parent, Hal.Manager manager, Hal.Device device) : base (parent, manager, device)
+        {
+        }
+        
+        public bool HasAudio {
+            get { return HalDevice.GetPropertyBoolean ("volume.disc.has_audio"); }
+        }
+        
+        public bool HasData {
+            get { return HalDevice.GetPropertyBoolean ("volume.disc.has_data"); }
+        }
+        
+        public bool IsBlank {
+            get { return HalDevice.GetPropertyBoolean ("volume.disc.is_blank"); }
+        }
+        
+        public bool IsRewritable {
+            get { return HalDevice.GetPropertyBoolean ("volume.disc.is_rewritable"); }
+        }
+        
+        public ulong MediaCapacity {
+            get { return HalDevice.GetPropertyUInt64 ("volume.disc.capacity"); }
+        }
+        
+        public override string ToString ()
+        {
+            return String.Format ("Optical Disc, Audio = {0}, Data = {1}, Blank = {2}, Rewritable = {3}, Media Capacity = {4}",
+                HasAudio, HasData, IsBlank, IsRewritable, MediaCapacity);
+        }
+    }
+}

Modified: trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/DiskDevice.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/DiskDevice.cs	(original)
+++ trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/DiskDevice.cs	Fri Mar 28 20:36:14 2008
@@ -36,16 +36,16 @@
 {
     public class DiskDevice : BlockDevice, IDiskDevice
     {
-        public new static DiskDevice Resolve (Hal.Device device)
+        public new static DiskDevice Resolve (Hal.Manager manager, Hal.Device device)
         {
             if (device["storage.drive_type"] == "disk") {
-                return new DiskDevice (device);
+                return new DiskDevice (manager, device);
             }
             
             return null;
         }
         
-        internal DiskDevice (Hal.Device device) : base (device)
+        private DiskDevice (Hal.Manager manager, Hal.Device device) : base (manager, device)
         {
         }
     }

Modified: trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/HardwareManager.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/HardwareManager.cs	(original)
+++ trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/HardwareManager.cs	Fri Mar 28 20:36:14 2008
@@ -52,7 +52,7 @@
         private IEnumerable<T> GetAllBlockDevices<T> () where T : IBlockDevice
         {
             foreach (Hal.Device hal_device in manager.FindDeviceByCapabilityAsDevice ("block")) {
-                IBlockDevice device = BlockDevice.Resolve<T> (hal_device);
+                IBlockDevice device = BlockDevice.Resolve<T> (manager, hal_device);
                 if (device != null) {
                     yield return (T)device;
                 }

Added: trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs	Fri Mar 28 20:36:14 2008
@@ -0,0 +1,103 @@
+//
+// Volume.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+
+using Banshee.Hardware;
+
+namespace Banshee.HalBackend
+{
+    public class Volume : Device, IVolume
+    {
+        public static Volume Resolve (BlockDevice parent, Hal.Manager manager, Hal.Device device)
+        {
+            if (!device.IsVolume) {
+                return null;
+            }
+            
+            return parent is ICdromDevice 
+                ? DiscVolume.Resolve (parent, manager, device)
+                : new Volume (parent, manager, device);
+        }
+        
+        private BlockDevice parent;
+        
+        protected Volume (BlockDevice parent, Hal.Manager manager, Hal.Device device) : base (manager, device)
+        {
+            this.parent = parent;
+        }
+
+        public string MountPoint {
+            get { return HalDevice["volume.mount_point"]; }
+        }
+
+        public bool IsMounted {
+            get { return HalDevice.GetPropertyBoolean ("volume.is_mounted"); }
+        }
+
+        public bool IsMountedReadOnly {
+            get { return HalDevice.GetPropertyBoolean ("volume.is_mounted_read_only"); }
+        }
+
+        public ulong Capacity {
+            get { return HalDevice.GetPropertyUInt64 ("volume.size"); }
+        }
+
+        public long Available {
+            get {
+                if (!IsMounted) {
+                    return -1;
+                }
+                
+                try {
+                    Mono.Unix.Native.Statvfs statvfs_info;
+                    if (Mono.Unix.Native.Syscall.statvfs (MountPoint, out statvfs_info) != -1) {
+                        return ((long)statvfs_info.f_bavail) * ((long)statvfs_info.f_bsize);
+                    }
+                } catch {
+                }
+                
+                return -1;
+            }
+        }
+        
+        public IBlockDevice Parent {
+            get { return parent; }
+        }
+        
+        public override string ToString ()
+        {
+            if (IsMounted) {
+                return String.Format ("`{0}': mounted {1} volume at {2} with {3} bytes free (of {4})", 
+                    Name, IsMountedReadOnly ? "read only" : "read/write", MountPoint, Available, Capacity);
+            }
+            
+            return String.Format ("`{0}': not mounted (capacity: {1} bytes)", Name, Capacity);
+        }
+    }
+}

Modified: trunk/banshee/src/Backends/Banshee.Hal/Makefile.am
==============================================================================
--- trunk/banshee/src/Backends/Banshee.Hal/Makefile.am	(original)
+++ trunk/banshee/src/Backends/Banshee.Hal/Makefile.am	Fri Mar 28 20:36:14 2008
@@ -7,8 +7,10 @@
 	Banshee.HalBackend/BlockDevice.cs \
 	Banshee.HalBackend/CdromDevice.cs \
 	Banshee.HalBackend/Device.cs \
+	Banshee.HalBackend/DiscVolume.cs \
 	Banshee.HalBackend/DiskDevice.cs \
 	Banshee.HalBackend/HardwareManager.cs \
+	Banshee.HalBackend/Volume.cs \
 	Hal/Device.cs \
 	Hal/Manager.cs \
 	Hal/Volume.cs

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/HardwareManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/HardwareManager.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/HardwareManager.cs	Fri Mar 28 20:36:14 2008
@@ -84,18 +84,22 @@
         public void Test ()
         {
             Console.WriteLine ("All Block Devices:");
-            foreach (IBlockDevice device in GetAllBlockDevices ()) {
-                Console.WriteLine ("  {0}, {1}", device.GetType ().FullName, device);
-            }
+            PrintBlockDeviceList (GetAllBlockDevices ());
             
             Console.WriteLine ("All CD-ROM Devices:");
-            foreach (ICdromDevice device in GetAllCdromDevices ()) {
-                Console.WriteLine ("  {0}, {1}", device.GetType ().FullName, device);
-            }
+            PrintBlockDeviceList (GetAllCdromDevices ());
             
             Console.WriteLine ("All Disk Devices:");
-            foreach (IDiskDevice device in GetAllDiskDevices ()) {
-                Console.WriteLine ("  {0}, {1}", device.GetType ().FullName, device);
+            PrintBlockDeviceList (GetAllDiskDevices ());
+        }
+        
+        private void PrintBlockDeviceList (System.Collections.IEnumerable devices)
+        {
+            foreach (IBlockDevice device in devices) {
+                Console.WriteLine ("{0}, {1}", device.GetType ().FullName, device);
+                foreach (IVolume volume in device.Volumes) {
+                    Console.WriteLine ("  {0}, {1}", volume.GetType ().FullName, volume);
+                }
             }
         }
              

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IDiscVolume.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IDiscVolume.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IDiscVolume.cs	Fri Mar 28 20:36:14 2008
@@ -36,5 +36,6 @@
         bool HasData { get; }
         bool IsRewritable { get; }
         bool IsBlank { get; }
+        ulong MediaCapacity { get; }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IVolume.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IVolume.cs	(original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IVolume.cs	Fri Mar 28 20:36:14 2008
@@ -36,7 +36,7 @@
         bool IsMounted { get; }
         bool IsMountedReadOnly { get; }
         ulong Capacity { get; }
-        ulong Available { get; }
+        long Available { get; }
         new IBlockDevice Parent { get; }
     }
 }



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