banshee r3831 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Hardware src/Core/Banshee.Services/Banshee.Sources src/Dap/Banshee.Dap.Ipod src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod
- From: abock svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3831 - in trunk/banshee: . src/Core/Banshee.Services/Banshee.Hardware src/Core/Banshee.Services/Banshee.Sources src/Dap/Banshee.Dap.Ipod src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod
- Date: Sat, 26 Apr 2008 05:38:06 +0100 (BST)
Author: abock
Date: Sat Apr 26 04:38:06 2008
New Revision: 3831
URL: http://svn.gnome.org/viewvc/banshee?rev=3831&view=rev
Log:
2008-04-26 Aaron Bockover <abock gnome org>
* src/Core/Banshee.Services/Banshee.Hardware/HardwareManager.cs:
Support runtime loading/unloading of hardware provider extensions
* src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDeviceProvider.cs:
* src/Core/Banshee.Services/Banshee.Hardware/ICustomDeviceProvider.cs:
Implement IDisposable
* src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs:
Support runtime loading/unloading of extension sources
* src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod.addin.xml: Order the
hardware provider for podsleuth first in the extension list just in case
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/HardwareManager.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/ICustomDeviceProvider.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs
trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod.addin.xml
trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDeviceProvider.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 Sat Apr 26 04:38:06 2008
@@ -39,7 +39,7 @@
public sealed class HardwareManager : IService, IHardwareManager, IDisposable
{
private IHardwareManager manager;
- private List<ICustomDeviceProvider> custom_device_providers = new List<ICustomDeviceProvider> ();
+ private Dictionary<string, ICustomDeviceProvider> custom_device_providers = new Dictionary<string, ICustomDeviceProvider> ();
public event DeviceAddedHandler DeviceAdded;
public event DeviceRemovedHandler DeviceRemoved;
@@ -67,9 +67,7 @@
manager.DeviceAdded += OnDeviceAdded;
manager.DeviceRemoved += OnDeviceRemoved;
- foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes ("/Banshee/Platform/HardwareDeviceProvider")) {
- custom_device_providers.Add ((ICustomDeviceProvider)node.CreateInstance (typeof (ICustomDeviceProvider)));
- }
+ AddinManager.AddExtensionNodeHandler ("/Banshee/Platform/HardwareDeviceProvider", OnExtensionChanged);
}
public void Dispose ()
@@ -83,16 +81,30 @@
}
if (custom_device_providers != null) {
- foreach (ICustomDeviceProvider provider in custom_device_providers) {
- IDisposable disposable = provider as IDisposable;
- if (disposable != null) {
- disposable.Dispose ();
- }
+ foreach (ICustomDeviceProvider provider in custom_device_providers.Values) {
+ provider.Dispose ();
}
custom_device_providers.Clear ();
custom_device_providers = null;
}
+
+ AddinManager.RemoveExtensionNodeHandler ("/Banshee/Platform/HardwareDeviceProvider", OnExtensionChanged);
+ }
+ }
+
+ private void OnExtensionChanged (object o, ExtensionNodeEventArgs args)
+ {
+ lock (this) {
+ TypeExtensionNode node = (TypeExtensionNode)args.ExtensionNode;
+
+ if (args.Change == ExtensionChange.Add && !custom_device_providers.ContainsKey (node.Id)) {
+ custom_device_providers.Add (node.Id, (ICustomDeviceProvider)node.CreateInstance ());
+ } else if (args.Change == ExtensionChange.Remove && custom_device_providers.ContainsKey (node.Id)) {
+ ICustomDeviceProvider provider = custom_device_providers[node.Id];
+ provider.Dispose ();
+ custom_device_providers.Remove (node.Id);
+ }
}
}
@@ -125,7 +137,7 @@
private T CastToCustomDevice<T> (T device) where T : class, IDevice
{
- foreach (ICustomDeviceProvider provider in custom_device_providers) {
+ foreach (ICustomDeviceProvider provider in custom_device_providers.Values) {
T new_device = provider.GetCustomDevice (device);
if (new_device != device && new_device is T) {
return new_device;
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/ICustomDeviceProvider.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/ICustomDeviceProvider.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/ICustomDeviceProvider.cs Sat Apr 26 04:38:06 2008
@@ -30,7 +30,7 @@
namespace Banshee.Hardware
{
- public interface ICustomDeviceProvider
+ public interface ICustomDeviceProvider : IDisposable
{
T GetCustomDevice<T> (T device) where T : class, IDevice;
}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs Sat Apr 26 04:38:06 2008
@@ -52,6 +52,8 @@
public class SourceManager : ISourceManager, IRequiredService, IDisposable
{
private List<Source> sources = new List<Source>();
+ private Dictionary<string, Source> extension_sources = new Dictionary<string, Source> ();
+
private Source active_source;
private Source default_source;
private MusicLibrarySource music_library;
@@ -64,16 +66,50 @@
internal void LoadExtensionSources ()
{
- foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes ("/Banshee/SourceManager/Source")) {
- node.CreateInstance (typeof (ISource));
+ lock (this) {
+ AddinManager.AddExtensionNodeHandler ("/Banshee/SourceManager/Source", OnExtensionChanged);
}
}
public void Dispose ()
{
- foreach (Source source in sources) {
- if (source is IDisposable) {
- ((IDisposable)source).Dispose ();
+ lock (this) {
+ while (sources.Count > 0) {
+ Source source = sources[0];
+ IDisposable disposable = source as IDisposable;
+
+ RemoveSource (source);
+
+ if (disposable != null) {
+ disposable.Dispose ();
+ }
+ }
+
+ sources.Clear ();
+ extension_sources.Clear ();
+
+ AddinManager.RemoveExtensionNodeHandler ("/Banshee/SourceManager/Source", OnExtensionChanged);
+ }
+ }
+
+ private void OnExtensionChanged (object o, ExtensionNodeEventArgs args)
+ {
+ lock (this) {
+ TypeExtensionNode node = (TypeExtensionNode)args.ExtensionNode;
+
+ if (args.Change == ExtensionChange.Add && !extension_sources.ContainsKey (node.Id)) {
+ Source source = (Source)node.CreateInstance ();
+ extension_sources.Add (node.Id, source);
+ AddSource (source);
+ } else if (args.Change == ExtensionChange.Remove && extension_sources.ContainsKey (node.Id)) {
+ Source source = extension_sources[node.Id];
+ extension_sources.Remove (node.Id);
+ RemoveSource (source);
+
+ IDisposable disposable = source as IDisposable;
+ if (disposable != null) {
+ disposable.Dispose ();
+ }
}
}
}
Modified: trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod.addin.xml
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod.addin.xml (original)
+++ trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod.addin.xml Sat Apr 26 04:38:06 2008
@@ -16,12 +16,12 @@
<Addin id="Banshee.Dap" version="1.0"/>
</Dependencies>
- <Extension path="/Banshee/Dap/DeviceClass">
- <DeviceClass class="Banshee.Dap.Ipod.IpodSource"/>
- </Extension>
-
<Extension path="/Banshee/Platform/HardwareDeviceProvider">
<HardwareDeviceProvider class="Banshee.Dap.Ipod.PodSleuthDeviceProvider"/>
</Extension>
+
+ <Extension path="/Banshee/Dap/DeviceClass">
+ <DeviceClass class="Banshee.Dap.Ipod.IpodSource"/>
+ </Extension>
</Addin>
Modified: trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDeviceProvider.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDeviceProvider.cs (original)
+++ trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDeviceProvider.cs Sat Apr 26 04:38:06 2008
@@ -54,6 +54,10 @@
return device;
}
+ public void Dispose ()
+ {
+ }
+
private T AsPodSleuthDevice<T> (IVolume volume, T original)
{
try {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]