[banshee] [HardwareManager] Prepare for gio/udev backend
- From: Gabriel Burt <gburt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] [HardwareManager] Prepare for gio/udev backend
- Date: Fri, 16 Jul 2010 20:05:40 +0000 (UTC)
commit 57461c9ad2d6ea2590099eaace70165271e5b213
Author: Gabriel Burt <gabriel burt gmail com>
Date: Fri Jul 16 13:04:12 2010 -0700
[HardwareManager] Prepare for gio/udev backend
Prefer GIO/udev backend over HAL, and share the backend ordering logic
with the IOProvider.
src/Backends/Banshee.Hal/Banshee.Hal.addin.xml | 2 +-
src/Core/Banshee.Core/Banshee.IO/Provider.cs | 46 +++++++++-----------
.../Banshee.Hardware/HardwareManager.cs | 14 +++---
3 files changed, 29 insertions(+), 33 deletions(-)
---
diff --git a/src/Backends/Banshee.Hal/Banshee.Hal.addin.xml b/src/Backends/Banshee.Hal/Banshee.Hal.addin.xml
index fd2f2c1..6c1cd2c 100644
--- a/src/Backends/Banshee.Hal/Banshee.Hal.addin.xml
+++ b/src/Backends/Banshee.Hal/Banshee.Hal.addin.xml
@@ -13,7 +13,7 @@
</Dependencies>
<Extension path="/Banshee/Platform/HardwareManager">
- <HardwareManager class="Banshee.HalBackend.HardwareManager"/>
+ <HardwareManager class="Banshee.HalBackend.HardwareManager" id="Banshee.HalBackend.HardwareManager" />
</Extension>
</Addin>
diff --git a/src/Core/Banshee.Core/Banshee.IO/Provider.cs b/src/Core/Banshee.Core/Banshee.IO/Provider.cs
index 16dac3c..345c992 100644
--- a/src/Core/Banshee.Core/Banshee.IO/Provider.cs
+++ b/src/Core/Banshee.Core/Banshee.IO/Provider.cs
@@ -27,6 +27,8 @@
//
using System;
+using System.Linq;
+using System.Collections.Generic;
using System.Reflection;
using Mono.Addins;
@@ -42,33 +44,33 @@ namespace Banshee.IO
private static IDirectory directory;
private static IFile file;
+ public static IEnumerable<TypeExtensionNode> GetOrderedExtensions (string extensionPoint, params string [] ordered_ids)
+ {
+ return AddinManager.GetExtensionNodes (extensionPoint)
+ .Cast<TypeExtensionNode> ()
+ .Where (n => n.HasId)
+ .OrderBy (n => {
+ var o = Array.IndexOf (ordered_ids, n.Id);
+ return o == -1 ? int.MaxValue : o;
+ });
+ }
+
static Provider () {
lock (typeof (Provider)) {
if (provider != null) {
return;
}
- TypeExtensionNode best_node = null;
- int best_index = Int32.MaxValue;
-
- foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes ("/Banshee/Platform/IOProvider")) {
- if (node.HasId) {
- if (node.Id == ProviderSchema.Get ()) {
- best_node = node;
- best_index = -1;
- } else {
- int idx = Array.IndexOf (builtin_backend_preference, node.Id);
- if (idx != -1 && idx < best_index) {
- best_index = idx;
- best_node = node;
- }
- }
- }
- }
+ var extensions = GetOrderedExtensions (
+ "/Banshee/Platform/IOProvider",
+ ProviderSchema.Get (),
+ "Banshee.IO.Gio.Provider", "Banshee.IO.Unix.Provider", "Banshee.IO.SystemIO.Provider"
+ );
- if (best_node != null) {
+ foreach (var node in extensions) {
try {
- provider = (IProvider)best_node.CreateInstance (typeof (IProvider));
+ provider = (IProvider)node.CreateInstance (typeof (IProvider));
+ break;
} catch (Exception e) {
Log.Warning ("IO provider extension failed to load", e.Message);
}
@@ -118,12 +120,6 @@ namespace Banshee.IO
return uri;
}
- private static string [] builtin_backend_preference = new string [] {
- "Banshee.IO.Gio.Provider",
- "Banshee.IO.Unix.Provider",
- "Banshee.IO.SystemIO.Provider"
- };
-
internal static readonly SchemaEntry<string> ProviderSchema = new SchemaEntry<string> (
"core", "io_provider",
"Banshee.IO.Gio.Provider",
diff --git a/src/Core/Banshee.Services/Banshee.Hardware/HardwareManager.cs b/src/Core/Banshee.Services/Banshee.Hardware/HardwareManager.cs
index a276d19..d88a7e1 100644
--- a/src/Core/Banshee.Services/Banshee.Hardware/HardwareManager.cs
+++ b/src/Core/Banshee.Services/Banshee.Hardware/HardwareManager.cs
@@ -46,15 +46,15 @@ namespace Banshee.Hardware
public HardwareManager ()
{
- foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes ("/Banshee/Platform/HardwareManager")) {
- try {
- if (manager != null) {
- throw new Exception (String.Format (
- "A HardwareManager has already been loaded ({0}). Only one can be loaded.",
- manager.GetType ().FullName));
- }
+ var extensions = Banshee.IO.Provider.GetOrderedExtensions (
+ "/Banshee/Platform/HardwareManager",
+ "Banshee.GioBackend.HardwareManager", "Banshee.HalBackend.HardwareManager"
+ );
+ foreach (var node in extensions) {
+ try {
manager = (IHardwareManager)node.CreateInstance (typeof (IHardwareManager));
+ break;
} catch (Exception e) {
Log.Exception ("Hardware manager extension failed to load", e);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]