banshee r3190 - in trunk/banshee: . src/Extensions/Banshee.DapCore src/Extensions/Banshee.DapCore/Banshee.DapCore src/Extensions/Banshee.DapCore/Resources



Author: rubenv
Date: Sat Feb  9 21:08:47 2008
New Revision: 3190
URL: http://svn.gnome.org/viewvc/banshee?rev=3190&view=rev

Log:
2008-02-09  Ruben Vermeersch  <ruben savanne be>

	* src/Extensions/Banshee.DapCore/Banshee.DapCore/DapCore.cs: Start porting
	the device initialization code.

	* src/Extensions/Banshee.DapCore/Banshee.DapCore/DeviceClassNode.cs:
	Added. Provides an extension node wich offers types, not instances (this
	could be useful outside of this extension as well).

	* src/Extensions/Banshee.DapCore/Banshee.DapCore/HalCore.cs: Don't make
	manager static (not needed).

	* src/Extensions/Banshee.DapCore/Banshee.DapCore/IDeviceClass.cs: Will
	soon be renamed to IDevice.

	* src/Extensions/Banshee.DapCore/Makefile.am: Add DeviceClassNode.

	* src/Extensions/Banshee.DapCore/Resources/Banshee.DapCore.addin.xml: Use
	DeviceClassNode instead of TypeExtensionNode.


Added:
   trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/DeviceClassNode.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/DapCore.cs
   trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/HalCore.cs
   trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/IDeviceClass.cs
   trunk/banshee/src/Extensions/Banshee.DapCore/Makefile.am
   trunk/banshee/src/Extensions/Banshee.DapCore/Resources/Banshee.DapCore.addin.xml

Modified: trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/DapCore.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/DapCore.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/DapCore.cs	Sat Feb  9 21:08:47 2008
@@ -27,28 +27,128 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using Banshee.Base;
+using Banshee.Hal;
 using Banshee.ServiceStack;
 
+using Hal;
 using Mono.Addins;
 
+using System;
+using System.Collections.Generic;
+
 namespace Banshee.Dap
 {
 
     public class DapCore : IExtensionService
     {
-        void IExtensionService.Initialize() {
-            AddinManager.AddExtensionNodeHandler ("/Banshee/Dap/Device", OnExtensionChanged);
+        private HalCore halCore;
+        private List<Type> supported_dap_types = new List<Type>();
+        private Dictionary<string, IDevice> device_table = new Dictionary<string, IDevice>();
+
+        private HalCore HalCore {
+            get { return halCore; }
+        }
+
+        void IExtensionService.Initialize () {
+            // TODO: This is the same construct as in NotificationAreaService.cs's Initialize.
+            
+            if (ServiceManager.Contains ("HalCore")) {
+                ContinueInitialize ();
+            } else {
+                ServiceManager.ServiceStarted += delegate (ServiceStartedArgs args) {
+                   if (args.Service is Banshee.Hal.HalCore) {
+                       ContinueInitialize ();
+                   }
+                };
+            }
         }
 
         private void OnExtensionChanged (object s, ExtensionNodeEventArgs args) {
-            IDeviceClass device_class = (IDeviceClass) args.ExtensionObject;
+            Type device_type = ((DeviceClassNode) args.ExtensionNode).Type;
             if (args.Change == ExtensionChange.Add) {
                 // Register device plugin
+                supported_dap_types.Add (device_type);
             } else {
                 // Unregister device plugin
+                supported_dap_types.Remove (device_type);
+            }
+        }
+
+        private void ContinueInitialize () {
+            // TODO: Hack!
+            AddinManager.AddExtensionNodeHandler ("/Banshee/Dap/DeviceClass", OnExtensionChanged);
+            halCore = ServiceManager.Get<HalCore> ("HalCore");
+            HalCore.Manager.DeviceAdded += OnHalDeviceAdded;
+            HalCore.Manager.DeviceRemoved += OnHalDeviceRemoved;
+
+            BuildDeviceTable();
+        }
+
+        private void BuildDeviceTable ()
+        {
+            // All volume devices, should cover all storage based players
+            foreach(string udi in HalCore.Manager.FindDeviceByStringMatch ("info.category", "volume")) {
+                Device device = new Device (udi);
+                if(device.PropertyExists ("volume.fsusage") && 
+                    device["volume.fsusage"] == "filesystem") {
+                    if((device.PropertyExists ("volume.is_disc") && 
+                        device.GetPropertyBoolean ("volume.is_disc")) || 
+                        (device.PropertyExists ("volume.ignore") &&
+                        device.GetPropertyBoolean ("volume.ignore"))) {
+                        continue;
+                    }
+                    
+                    AddDeviceThreaded (device);
+                }
+            }
+
+            // Non-storage based players
+            foreach(string udi in HalCore.Manager.FindDeviceByStringMatch ("info.category", "portable_audio_player")) {
+                AddDeviceThreaded (new Device (udi));
+            }
+        }
+
+        private void OnHalDeviceAdded(object o, DeviceAddedArgs args)
+        {
+            Device device = args.Device;
+            if(device["info.category"] == "portable_audio_player" ||
+                (device["info.category"] == "volume" &&
+                device.PropertyExists("volume.fsusage") &&
+                device["volume.fsusage"] == "filesystem" &&
+                (!device.PropertyExists("volume.is_disc") || 
+                !device.GetPropertyBoolean("volume.is_disc")))) {
+                AddDeviceThreaded (device);
             }
         }
 
+        private void AddDeviceThreaded (Device device)
+        {
+            ThreadAssist.Spawn (delegate {
+                AddDevice (device);
+            });
+        }
+
+        private void AddDevice(Device device)
+        {
+            lock (device_table) {
+                if (device_table.ContainsKey (device.Udi)) {
+                    return;
+                }
+
+                try {
+                    DapDevice dap_device = new DapDevice (device);
+                    device_table.Add (device.Udi, dap_device);
+                } catch (Exception e) {
+                    Console.WriteLine (e);
+                }
+            }
+        }
+        
+        private void OnHalDeviceRemoved(object o, DeviceRemovedArgs args)
+        {
+            // TODO: RemoveDevice(args.Udi);
+        }
 
         string IService.ServiceName {
             get { return "DapCore"; }

Added: trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/DeviceClassNode.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/DeviceClassNode.cs	Sat Feb  9 21:08:47 2008
@@ -0,0 +1,42 @@
+//
+// DeviceClassNode.cs
+//
+// Author:
+//   Ruben Vermeersch <ruben savanne be>
+//
+// Copyright (C) 2007-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 Mono.Addins;
+
+namespace Banshee.Dap 
+{
+    class DeviceClassNode : ExtensionNode
+    {
+        [NodeAttribute]
+        string type;
+
+        public Type Type {
+            return Addin.GetType (type);
+        }
+    }
+}

Modified: trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/HalCore.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/HalCore.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/HalCore.cs	Sat Feb  9 21:08:47 2008
@@ -34,7 +34,7 @@
 {
     public class HalCore : IExtensionService
     {
-        private Manager manager;
+        private static Manager manager;
 
         public void Initialize ()
         {

Modified: trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/IDeviceClass.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/IDeviceClass.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/IDeviceClass.cs	Sat Feb  9 21:08:47 2008
@@ -1,5 +1,5 @@
 //
-// IDeviceClass.cs
+// IDevice.cs
 //
 // Author:
 //   Ruben Vermeersch <ruben savanne be>
@@ -31,7 +31,7 @@
 
 namespace Banshee.Dap
 {
-    public interface IDeviceClass : IDisposable {
+    public interface IDevice: IDisposable {
 		
 		event EventHandler Ejected;
 		event EventHandler Initialized;
@@ -50,7 +50,7 @@
 		void UploadTrack (TrackInfo track);         // Should be TrackInfo, not 'object'
 
 		void Eject ();
-		void Initialize (object halDevice);   // Should be a Hal.Device, not 'object'
+		bool Initialize (Hal.Device device);
 		
 		//bool CanSetName { get; }
 		//bool CanSetOwner { get; }

Modified: trunk/banshee/src/Extensions/Banshee.DapCore/Makefile.am
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.DapCore/Makefile.am	(original)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/Makefile.am	Sat Feb  9 21:08:47 2008
@@ -4,8 +4,9 @@
 
 SOURCES =  \
 	Banshee.DapCore/DapCore.cs \
+	Banshee.DapCore/DeviceClassNode.cs \
 	Banshee.DapCore/HalCore.cs \
-	Banshee.DapCore/IDeviceClass.cs \
+	Banshee.DapCore/IDevice.cs \
 	hal-sharp/Device.cs \
 	hal-sharp/Manager.cs \
 	hal-sharp/Volume.cs

Modified: trunk/banshee/src/Extensions/Banshee.DapCore/Resources/Banshee.DapCore.addin.xml
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.DapCore/Resources/Banshee.DapCore.addin.xml	(original)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/Resources/Banshee.DapCore.addin.xml	Sat Feb  9 21:08:47 2008
@@ -21,7 +21,7 @@
   </Extension>
 
   <ExtensionPoint path="/Banshee/Dap/DeviceClass">
-    <ExtensionNode name="DeviceClass"/>
+    <ExtensionNode name="DeviceClass" type="Banshee.Dap.DeviceClassNode" />
   </ExtensionPoint>
 
 </Addin>



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