banshee r4392 - in trunk/banshee: . src/Backends/Banshee.Hal/Banshee.HalBackend src/Core/Banshee.Core/Banshee.Kernel src/Core/Banshee.Services/Banshee.Base src/Core/Banshee.Services/Banshee.Hardware src/Core/Banshee.Services/Banshee.Sources src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp src/Dap/Banshee.Dap/Banshee.Dap
- From: gburt svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r4392 - in trunk/banshee: . src/Backends/Banshee.Hal/Banshee.HalBackend src/Core/Banshee.Core/Banshee.Kernel src/Core/Banshee.Services/Banshee.Base src/Core/Banshee.Services/Banshee.Hardware src/Core/Banshee.Services/Banshee.Sources src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp src/Dap/Banshee.Dap/Banshee.Dap
- Date: Mon, 18 Aug 2008 02:14:16 +0000 (UTC)
Author: gburt
Date: Mon Aug 18 02:14:16 2008
New Revision: 4392
URL: http://svn.gnome.org/viewvc/banshee?rev=4392&view=rev
Log:
2008-08-17 Gabriel Burt <gabriel burt gmail com>
* src/Core/Banshee.Services/Banshee.Hardware/IDevice.cs:
* src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs:
* src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs:
* src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDevice.cs:
* src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs: Add Serial
property, keeping Uuid for the HAL udi (or equiv on other backends).
* src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs: Make more thread safe.
* src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs: Add
AssertInMainThread method; logs a warning if in --debug mode and not
called from the main thread.
* src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs: Assert that
we're in the main thread when adding and removing sources.
* src/Core/Banshee.Core/Banshee.Kernel/Scheduler.cs: Fix up the logging so
that jobs that have exceptions are actually logged.
Modified:
trunk/banshee/ChangeLog
trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Device.cs
trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs
trunk/banshee/src/Core/Banshee.Core/Banshee.Kernel/Scheduler.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IDevice.cs
trunk/banshee/src/Core/Banshee.Services/Banshee.Sources/SourceManager.cs
trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDevice.cs
trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
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 Mon Aug 18 02:14:16 2008
@@ -52,8 +52,13 @@
}
private string uuid;
- public virtual string Uuid {
- get { return uuid ?? uuid = String.IsNullOrEmpty (HalDevice["usb.serial"]) ? device.Udi : HalDevice["usb.serial"]; }
+ public string Uuid {
+ get { return uuid ?? uuid = device.Udi; /*String.IsNullOrEmpty (HalDevice["usb.serial"]) ? device.Udi : HalDevice["usb.serial"];*/ }
+ }
+
+ private string serial;
+ public virtual string Serial {
+ get { return serial ?? serial = HalDevice["usb.serial"]; }
}
private string name;
Modified: trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs
==============================================================================
--- trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs (original)
+++ trunk/banshee/src/Backends/Banshee.Hal/Banshee.HalBackend/Volume.cs Mon Aug 18 02:14:16 2008
@@ -85,18 +85,18 @@
get { return HalDevice["volume.fstype"]; }
}
- private string uuid;
- public override string Uuid {
+ /*private string serial;
+ public override string Serial {
get {
- if (uuid == null) {
- uuid = String.IsNullOrEmpty (HalDevice["volume.uuid"])
- ? base.Uuid
+ if (serial == null) {
+ serial = String.IsNullOrEmpty (HalDevice["volume.uuid"])
+ ? base.Serial
: HalDevice["volume.uuid"];
}
- return uuid;
+ return serial;
}
- }
+ }*/
public bool IsMounted {
get { return HalDevice.GetPropertyBoolean ("volume.is_mounted"); }
Modified: trunk/banshee/src/Core/Banshee.Core/Banshee.Kernel/Scheduler.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Core/Banshee.Kernel/Scheduler.cs (original)
+++ trunk/banshee/src/Core/Banshee.Core/Banshee.Kernel/Scheduler.cs Mon Aug 18 02:14:16 2008
@@ -30,6 +30,7 @@
using System.Threading;
using System.Collections.Generic;
+using Hyena;
using Hyena.Collections;
namespace Banshee.Kernel
@@ -63,7 +64,7 @@
}
heap.Push(job, (int)priority);
- Debug("Job scheduled ({0}, {1})", job, priority);
+ //Log.DebugFormat("Job scheduled ({0}, {1})", job, priority);
OnJobScheduled(job);
CheckRun();
}
@@ -77,10 +78,10 @@
}
if(heap.Remove(job)) {
- Debug("Job unscheduled ({0}), job", job);
+ Log.DebugFormat("Job unscheduled ({0}), job", job);
OnJobUnscheduled(job);
} else {
- Debug("Job not unscheduled; not located in heap");
+ Log.DebugFormat("Job not unscheduled; not located in heap");
}
}
}
@@ -183,7 +184,7 @@
private static bool IsDisposed()
{
if(disposed) {
- Debug("Job not unscheduled; disposing scheduler");
+ //Log.Debug("Job not unscheduled; disposing scheduler");
return true;
}
@@ -195,7 +196,6 @@
if(heap.Count <= 0) {
return;
} else if(job_thread == null) {
- Debug("execution thread created");
job_thread = new Thread(new ThreadStart(ProcessJobThread));
job_thread.Priority = ThreadPriority.BelowNormal;
job_thread.IsBackground = true;
@@ -215,27 +215,24 @@
lock(this_mutex) {
if(disposed) {
- Console.WriteLine("execution thread destroyed, dispose requested");
+ job_thread = null;
return;
}
try {
current_running_job = heap.Pop();
} catch(InvalidOperationException) {
- Debug("execution thread destroyed, no more jobs scheduled");
job_thread = null;
return;
}
}
try {
- Debug("Job started ({0})", current_running_job);
OnJobStarted(current_running_job);
current_running_job.Run();
- Debug("Job ended ({0})", current_running_job);
OnJobFinished(current_running_job);
} catch(Exception e) {
- Debug("Job threw an unhandled exception: {0}", e);
+ Log.Exception (e);
}
}
}
@@ -275,12 +272,5 @@
handler(job);
}
}
-
- private static void Debug(string message, params object [] args)
- {
- /*if(Banshee.Base.Globals.Debugging) {
- Console.Error.WriteLine(String.Format("** Scheduler: {0}", message), args);
- }*/
- }
}
}
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Base/ThreadAssist.cs Mon Aug 18 02:14:16 2008
@@ -50,6 +50,13 @@
}
}
+ public static void AssertInMainThread ()
+ {
+ if (ApplicationContext.Debugging && !InMainThread) {
+ Hyena.Log.Warning ("Not in main thread!", System.Environment.StackTrace);
+ }
+ }
+
public static void ProxyToMain (InvokeHandler handler)
{
if (!InMainThread) {
Modified: trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IDevice.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IDevice.cs (original)
+++ trunk/banshee/src/Core/Banshee.Services/Banshee.Hardware/IDevice.cs Mon Aug 18 02:14:16 2008
@@ -33,6 +33,7 @@
public interface IDevice
{
string Uuid { get; }
+ string Serial { get; }
string Name { get; }
string Product { get; }
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 Mon Aug 18 02:14:16 2008
@@ -136,6 +136,7 @@
public void AddSource(Source source, bool isDefault)
{
+ Banshee.Base.ThreadAssist.AssertInMainThread ();
if(source == null || ContainsSource (source)) {
return;
}
@@ -184,6 +185,7 @@
public void RemoveSource (Source source, bool recursivelyDispose)
{
+ Banshee.Base.ThreadAssist.AssertInMainThread ();
if(source == null || !ContainsSource (source)) {
return;
}
@@ -313,6 +315,7 @@
public void SetActiveSource(Source source, bool notify)
{
+ Banshee.Base.ThreadAssist.AssertInMainThread ();
if(source == null || !source.CanActivate || active_source == source) {
return;
}
Modified: trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDevice.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDevice.cs (original)
+++ trunk/banshee/src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/PodSleuthDevice.cs Mon Aug 18 02:14:16 2008
@@ -265,6 +265,11 @@
public string Uuid {
get { return volume.Uuid; }
}
+
+ public string Serial {
+ get { return volume.Serial; }
+ }
+
public string Product {
get { return volume.Product; }
}
Modified: trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs (original)
+++ trunk/banshee/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs Mon Aug 18 02:14:16 2008
@@ -104,7 +104,7 @@
} else {
string mtp_serial = devices[0].SerialNumber;
if (!String.IsNullOrEmpty (mtp_serial)) {
- if (mtp_serial.Contains (device.Uuid)) {
+ if (mtp_serial.Contains (device.Serial)) {
mtp_device = devices[0];
mtp_source = this;
}
Modified: trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs
==============================================================================
--- trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs (original)
+++ trunk/banshee/src/Dap/Banshee.Dap/Banshee.Dap/DapService.cs Mon Aug 18 02:14:16 2008
@@ -35,6 +35,7 @@
using Hyena;
using Banshee.Base;
+using Banshee.Kernel;
using Banshee.ServiceStack;
using Banshee.Sources;
using Banshee.Collection;
@@ -46,7 +47,7 @@
public class DapService : IExtensionService, IDelayedInitializeService, IDisposable
{
private Dictionary<string, DapSource> sources;
- private List<TypeExtensionNode> supported_dap_types = new List<TypeExtensionNode> ();
+ private List<TypeExtensionNode> supported_dap_types;
private bool initialized;
private object sync = new object ();
@@ -57,7 +58,11 @@
public void DelayedInitialize ()
{
lock (sync) {
+ if (initialized)
+ return;
+
sources = new Dictionary<string, DapSource> ();
+ supported_dap_types = new List<TypeExtensionNode> ();
AddinManager.AddExtensionNodeHandler ("/Banshee/Dap/DeviceClass", OnExtensionChanged);
@@ -100,6 +105,7 @@
public void Dispose ()
{
+ Scheduler.Unschedule (typeof(MapDeviceJob));
lock (sync) {
if (!initialized)
return;
@@ -117,6 +123,9 @@
sources.Clear ();
sources = null;
+ supported_dap_types.Clear ();
+ supported_dap_types = null;
+ initialized = false;
}
}
@@ -142,11 +151,32 @@
private void MapDevice (IDevice device)
{
- Banshee.Kernel.Scheduler.Schedule (new Banshee.Kernel.DelegateJob (delegate {
+ lock (sync) {
+ Scheduler.Schedule (new MapDeviceJob (this, device));
+ }
+ }
+
+ private class MapDeviceJob : IJob
+ {
+ IDevice device;
+ DapService service;
+
+ public MapDeviceJob (DapService service, IDevice device)
+ {
+ this.device = device;
+ this.service = service;
+ }
+
+ public string Uuid {
+ get { return device.Uuid; }
+ }
+
+ public void Run ()
+ {
DapSource source = null;
- lock (sync) {
+ lock (service.sync) {
try {
- if (sources.ContainsKey (device.Uuid)) {
+ if (service.sources.ContainsKey (device.Uuid)) {
return;
}
@@ -162,10 +192,10 @@
return;
}
- source = FindDeviceSource (device);
+ source = service.FindDeviceSource (device);
if (source != null) {
Log.DebugFormat ("Found DAP support ({0}) for device {1}", source.GetType ().FullName, source.Name);
- sources.Add (device.Uuid, source);
+ service.sources.Add (device.Uuid, source);
}
} catch (Exception e) {
Log.Exception (e);
@@ -173,10 +203,12 @@
}
if (source != null) {
- ServiceManager.SourceManager.AddSource (source);
- source.NotifyUser ();
+ ThreadAssist.ProxyToMain (delegate {
+ ServiceManager.SourceManager.AddSource (source);
+ source.NotifyUser ();
+ });
}
- }));
+ }
}
internal void UnmapDevice (string uuid)
@@ -193,7 +225,9 @@
if (source != null) {
try {
source.Dispose ();
- ServiceManager.SourceManager.RemoveSource (source);
+ ThreadAssist.ProxyToMain (delegate {
+ ServiceManager.SourceManager.RemoveSource (source);
+ });
} catch (Exception e) {
Log.Exception (e);
}
@@ -210,16 +244,12 @@
private void OnHardwareDeviceAdded (object o, DeviceAddedArgs args)
{
- lock (sync) {
- MapDevice (args.Device);
- }
+ MapDevice (args.Device);
}
private void OnHardwareDeviceRemoved (object o, DeviceRemovedArgs args)
{
- lock (sync) {
- UnmapDevice (args.DeviceUuid);
- }
+ UnmapDevice (args.DeviceUuid);
}
string IService.ServiceName {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]