[banshee/gio-hardware] [Hardware] Add a new interface IUsbPortInfo exposed through IDevice.
- From: Alan McGovern <alanmc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee/gio-hardware] [Hardware] Add a new interface IUsbPortInfo exposed through IDevice.
- Date: Sun, 25 Jul 2010 20:04:17 +0000 (UTC)
commit 1395e1f190276247f5359906387ef01fcf296a34
Author: Alan McGovern <alan mcgovern gmail com>
Date: Sun Jul 25 20:58:23 2010 +0100
[Hardware] Add a new interface IUsbPortInfo exposed through IDevice.
IUsbPortInfo is used to access the usb Bus and Device numbers. MTP
devices require this information to accurately detect whether or not
a device is loadable via the MtpSource with libmtp.
.../Banshee.Gio/Banshee.Hardware.Gio/Device.cs | 9 ++
.../Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs | 136 ++++++++++++++++++++
.../Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs | 9 +-
.../Banshee.Hal/Banshee.HalBackend/Device.cs | 14 ++
.../Banshee.Hal/Banshee.HalBackend/UsbDevice.cs | 8 -
.../Banshee.Services/Banshee.Hardware/IDevice.cs | 1 +
.../Banshee.Hardware/IUsbDevice.cs | 2 -
.../Banshee.Hardware/IUsbPortInfo.cs | 36 +++++
.../Banshee.Hardware/UsbPortInfo.cs | 49 +++++++
src/Core/Banshee.Services/Banshee.Services.csproj | 2 +
src/Core/Banshee.Services/Makefile.am | 2 +
.../Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs | 28 +++--
12 files changed, 274 insertions(+), 22 deletions(-)
---
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/Device.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/Device.cs
index 8170bb6..277b949 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/Device.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/Device.cs
@@ -84,6 +84,15 @@ namespace Banshee.Hardware.Gio
return UsbDevice.ResolveRootDevice (this);
}
+ public IUsbPortInfo ResolveUsbPortInfo ()
+ {
+ var f = UsbDevice.ResolveRootDevice (this);
+ if (f != null) {
+ return new UsbPortInfo (f.BusNumber, f.DeviceNumber);
+ }
+ return null;
+ }
+
public bool PropertyExists (string key)
{
return device.PropertyExists (key);
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs
new file mode 100644
index 0000000..1f28424
--- /dev/null
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/LowLevel/RawUsbDevice.cs
@@ -0,0 +1,136 @@
+//
+// RawUsbDevice.cs
+//
+// Author:
+// Alan McGovern <alan mcgovern gmail com>
+//
+// Copyright (c) 2010 Alan McGovern
+//
+// 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;
+
+namespace Banshee.Hardware.Gio
+{
+ class RawUsbDevice : RawDevice {
+
+ public override string GetPropertyString (string key)
+ {
+ throw new System.NotImplementedException();
+ }
+
+
+ public override double GetPropertyDouble (string key)
+ {
+ throw new System.NotImplementedException();
+ }
+
+
+ public override bool GetPropertyBoolean (string key)
+ {
+ throw new System.NotImplementedException();
+ }
+
+
+ public override int GetPropertyInteger (string key)
+ {
+ throw new System.NotImplementedException();
+ }
+
+
+ public override ulong GetPropertyUInt64 (string key)
+ {
+ throw new System.NotImplementedException();
+ }
+
+
+ public override string[] GetPropertyStringList (string key)
+ {
+ throw new System.NotImplementedException();
+ }
+
+
+ public override bool PropertyExists (string key)
+ {
+ throw new System.NotImplementedException();
+ }
+
+
+ public override string Identifier {
+ get { return UdevMetadata.Serial; }
+ }
+
+
+ public override string IdMediaPlayer {
+ get { return UdevMetadata.IdMediaDevice; }
+ }
+
+
+ public override bool IsRemovable {
+ get { return true; }
+ }
+
+
+ public override IDeviceMediaCapabilities MediaCapabilities {
+ get { return new DeviceMediaCapabilities (this); }
+ }
+
+
+ public override string Name {
+ get { return UdevMetadata.Name; }
+ }
+
+
+ public override string Model {
+ get { return UdevMetadata.Model; }
+ }
+
+
+ public override string Product {
+ get { return UdevMetadata.Product; }
+ }
+
+
+ public override string Serial {
+ get { return UdevMetadata.Serial; }
+ }
+
+
+ public override string Subsystem {
+ get { return UdevMetadata.Subsystem; }
+ }
+
+
+ public override string Uuid {
+ get { return UdevMetadata.Uuid; }
+ }
+
+
+ public override string Vendor {
+ get { return UdevMetadata.Vendor; }
+ }
+
+ public RawUsbDevice (Manager manager, GioMetadataSource gioMetadata, UdevMetadataSource udevMetadata)
+ : base (manager, gioMetadata, udevMetadata)
+ {
+ }
+ }
+}
+
diff --git a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs
index 316dd4a..b067459 100644
--- a/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs
+++ b/src/Backends/Banshee.Gio/Banshee.Hardware.Gio/UsbDevice.cs
@@ -41,7 +41,7 @@ namespace Banshee.Hardware.Gio
const string UdevVendorId = "ID_VENDOR_ID";
const string UdevProductId = "ID_MODEL_ID";
- internal static IUsbDevice ResolveRootDevice (IDevice device)
+ internal static UsbDevice ResolveRootDevice (IDevice device)
{
// First check if the supplied device is an IUsbDevice itself
var result = Resolve (device);
@@ -68,6 +68,11 @@ namespace Banshee.Hardware.Gio
return this;
}
+ public IUsbPortInfo ResolveUsbPortInfo ()
+ {
+ return new UsbPortInfo (BusNumber, DeviceNumber);
+ }
+
public static int GetBusNumber (IUsbDevice device)
{
var raw = device as IRawDevice;
@@ -102,7 +107,7 @@ namespace Banshee.Hardware.Gio
throw new NotImplementedException ();
}
- public static IUsbDevice Resolve (IDevice device)
+ public static UsbDevice Resolve (IDevice device)
{
IRawDevice raw = device as IRawDevice;
if (raw != null) {
diff --git a/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs b/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs
index b5d9bc5..9f7e138 100644
--- a/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs
+++ b/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs
@@ -134,6 +134,20 @@ namespace Banshee.HalBackend
return UsbDevice.Resolve (HalManager, CollectUsbDeviceStack (device).Peek ());
}
+ public IUsbPortInfo ResolveUsbPortInfo ()
+ {
+ var device = this.device;
+ while (device != null) {
+ if (device.PropertyExists ("usb.bus_number") && device.PropertyExists ("usb.linux.device_number")) {
+ return new UsbPortInfo (device.GetPropertyInteger ("usb.bus_number"),
+ device.GetPropertyInteger ("usb.linux.device_number"));
+ }
+ device = device.Parent;
+ }
+ return null;
+ }
+
+
private static Stack<Hal.Device> CollectUsbDeviceStack (Hal.Device device)
{
Stack<Hal.Device> device_stack = new Stack<Hal.Device> ();
diff --git a/src/Backends/Banshee.Hal/Banshee.HalBackend/UsbDevice.cs b/src/Backends/Banshee.Hal/Banshee.HalBackend/UsbDevice.cs
index c0f58b3..206c7d5 100644
--- a/src/Backends/Banshee.Hal/Banshee.HalBackend/UsbDevice.cs
+++ b/src/Backends/Banshee.Hal/Banshee.HalBackend/UsbDevice.cs
@@ -49,14 +49,6 @@ namespace Banshee.HalBackend
{
}
- public int BusNumber {
- get { return HalDevice.GetPropertyInteger ("usb.bus_number"); }
- }
-
- public int DeviceNumber {
- get { return HalDevice.GetPropertyInteger ("usb.linux.device_number"); }
- }
-
public int VendorId {
get { return HalDevice.GetPropertyInteger ("usb_device.vendor_id"); }
}
diff --git a/src/Core/Banshee.Services/Banshee.Hardware/IDevice.cs b/src/Core/Banshee.Services/Banshee.Hardware/IDevice.cs
index 4c76bf5..667dd20 100644
--- a/src/Core/Banshee.Services/Banshee.Hardware/IDevice.cs
+++ b/src/Core/Banshee.Services/Banshee.Hardware/IDevice.cs
@@ -51,5 +51,6 @@ namespace Banshee.Hardware
string [] GetPropertyStringList (string key);
IUsbDevice ResolveRootUsbDevice ();
+ IUsbPortInfo ResolveUsbPortInfo ();
}
}
diff --git a/src/Core/Banshee.Services/Banshee.Hardware/IUsbDevice.cs b/src/Core/Banshee.Services/Banshee.Hardware/IUsbDevice.cs
index b6549e0..3dafb00 100644
--- a/src/Core/Banshee.Services/Banshee.Hardware/IUsbDevice.cs
+++ b/src/Core/Banshee.Services/Banshee.Hardware/IUsbDevice.cs
@@ -32,8 +32,6 @@ namespace Banshee.Hardware
{
public interface IUsbDevice : IDevice
{
- int BusNumber { get; }
- int DeviceNumber { get; }
int ProductId { get; }
int VendorId { get; }
double Speed { get; }
diff --git a/src/Core/Banshee.Services/Banshee.Hardware/IUsbPortInfo.cs b/src/Core/Banshee.Services/Banshee.Hardware/IUsbPortInfo.cs
new file mode 100644
index 0000000..4d3a220
--- /dev/null
+++ b/src/Core/Banshee.Services/Banshee.Hardware/IUsbPortInfo.cs
@@ -0,0 +1,36 @@
+//
+// IUsbPortInfo.cs
+//
+// Author:
+// Alan McGovern <alan mcgovern gmail com>
+//
+// Copyright (c) 2010 Alan McGovern
+//
+// 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;
+
+namespace Banshee.Hardware {
+
+ public interface IUsbPortInfo {
+ int BusNumber { get; }
+ int DeviceNumber { get; }
+ }
+}
diff --git a/src/Core/Banshee.Services/Banshee.Hardware/UsbPortInfo.cs b/src/Core/Banshee.Services/Banshee.Hardware/UsbPortInfo.cs
new file mode 100644
index 0000000..2113f45
--- /dev/null
+++ b/src/Core/Banshee.Services/Banshee.Hardware/UsbPortInfo.cs
@@ -0,0 +1,49 @@
+//
+// UsbPortInfo.cs
+//
+// Author:
+// Alan McGovern <alan mcgovern gmail com>
+//
+// Copyright (c) 2010 Alan McGovern
+//
+// 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;
+
+namespace Banshee.Hardware
+{
+ public class UsbPortInfo : IUsbPortInfo
+ {
+ public int BusNumber {
+ get; private set;
+ }
+
+ public int DeviceNumber {
+ get; private set;
+ }
+
+ public UsbPortInfo (int busNumber, int deviceNumber)
+ {
+ BusNumber = busNumber;
+ DeviceNumber = deviceNumber;
+ }
+ }
+}
+
diff --git a/src/Core/Banshee.Services/Banshee.Services.csproj b/src/Core/Banshee.Services/Banshee.Services.csproj
index efb2b9b..04e2791 100644
--- a/src/Core/Banshee.Services/Banshee.Services.csproj
+++ b/src/Core/Banshee.Services/Banshee.Services.csproj
@@ -318,6 +318,8 @@
<Compile Include="Banshee.Metrics\Configuration.cs" />
<Compile Include="Banshee.Collection.Database\RandomByOff.cs" />
<Compile Include="Banshee.Database\Tests.cs" />
+ <Compile Include="Banshee.Hardware\IUsbPortInfo.cs" />
+ <Compile Include="Banshee.Hardware\UsbPortInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Banshee.Services.addin.xml">
diff --git a/src/Core/Banshee.Services/Makefile.am b/src/Core/Banshee.Services/Makefile.am
index 89c6189..2ae3040 100644
--- a/src/Core/Banshee.Services/Makefile.am
+++ b/src/Core/Banshee.Services/Makefile.am
@@ -75,7 +75,9 @@ SOURCES = \
Banshee.Hardware/IDiskDevice.cs \
Banshee.Hardware/IHardwareManager.cs \
Banshee.Hardware/IUsbDevice.cs \
+ Banshee.Hardware/IUsbPortInfo.cs \
Banshee.Hardware/IVolume.cs \
+ Banshee.Hardware/UsbPortInfo.cs \
Banshee.Hardware/VendorProductDeviceNode.cs \
Banshee.Hardware/VendorProductInfo.cs \
Banshee.Library/HomeDirectoryImportSource.cs \
diff --git a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
index ec1a237..f2172a8 100644
--- a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
+++ b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
@@ -65,11 +65,13 @@ namespace Banshee.Dap.Mtp
{
base.DeviceInitialize (device);
- if (!(device is IUsbDevice))
+ var portInfo = device.ResolveUsbPortInfo ();
+ if (portInfo == null) {
throw new InvalidDeviceException ();
+ }
- int busnum = ((IUsbDevice) device).BusNumber;
- int devnum = ((IUsbDevice) device).DeviceNumber;
+ int busnum = portInfo.BusNumber;
+ int devnum = portInfo.DeviceNumber;
List<RawMtpDevice> devices = null;
try {
@@ -87,19 +89,25 @@ namespace Banshee.Dap.Mtp
throw new InvalidDeviceException ();
}
- IVolume volume = (IVolume) device;
+ IVolume volume = device as IVolume;
foreach (var v in devices) {
if (v.BusNumber == busnum && v.DeviceNumber == devnum) {
- volume.Unmount ();
- try {
- mtp_device = MtpDevice.Connect (v);
- } catch (Exception){
- Log.Debug ("Failed to connect to mtp device");
+ if (volume != null)
+ volume.Unmount ();
+ for (int i = 5; i > 0 && mtp_device == null; i--) {
+ try {
+ mtp_device = MtpDevice.Connect (v);
+ } catch (Exception){
+ Log.Debug (string.Format ("Failed to connect to mtp device. Trying {0} more times...", i - i));
+ }
+ if (mtp_device == null)
+ Thread.Sleep (2000);
}
}
}
- if (mtp_device == null)
+ if (mtp_device == null) {
throw new InvalidDeviceException ();
+ }
Name = mtp_device.Name;
Initialize ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]