banshee r3183 - in trunk/banshee: . build src/Extensions src/Extensions/Banshee.DapCore src/Extensions/Banshee.DapCore/Banshee.DapCore src/Extensions/Banshee.DapCore/Resources src/Extensions/Banshee.DapCore/hal-sharp
- From: rubenv svn gnome org
- To: svn-commits-list gnome org
- Subject: banshee r3183 - in trunk/banshee: . build src/Extensions src/Extensions/Banshee.DapCore src/Extensions/Banshee.DapCore/Banshee.DapCore src/Extensions/Banshee.DapCore/Resources src/Extensions/Banshee.DapCore/hal-sharp
- Date: Sat, 9 Feb 2008 17:20:55 +0000 (GMT)
Author: rubenv
Date: Sat Feb 9 17:20:55 2008
New Revision: 3183
URL: http://svn.gnome.org/viewvc/banshee?rev=3183&view=rev
Log:
2008-02-09 Ruben Vermeersch <ruben savanne be>
Add the groundwork for the DapCore plugin. Currently does... nothing.
Contains a copy of hal-sharp until we have a properly abstracted HAL.
* build/build.environment.mk: Add the dependencies for DapCore.
* configure.ac: Generate build files for the new addin.
* src/Extensions/Banshee.DapCore: Added.
* src/Extensions/Banshee.DapCore/Banshee.DapCore: Added.
* src/Extensions/Banshee.DapCore/Banshee.DapCore.mdp: Added.
* src/Extensions/Banshee.DapCore/Banshee.DapCore/DapCore.cs: Added.
* src/Extensions/Banshee.DapCore/Banshee.DapCore/HalCore.cs: Added.
* src/Extensions/Banshee.DapCore/Makefile.am: Added.
* src/Extensions/Banshee.DapCore/Resources: Added.
* src/Extensions/Banshee.DapCore/Resources/Banshee.DapCore.addin.xml: Added.
* src/Extensions/Banshee.DapCore/hal-sharp: Added.
* src/Extensions/Banshee.DapCore/hal-sharp/Device.cs: Added.
* src/Extensions/Banshee.DapCore/hal-sharp/Manager.cs: Added.
* src/Extensions/Banshee.DapCore/hal-sharp/Volume.cs: Added.
* src/Extensions/Makefile.am: Add Banshee.DapCore.
Added:
trunk/banshee/src/Extensions/Banshee.DapCore/ (props changed)
trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/
trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore.mdp
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/Makefile.am
trunk/banshee/src/Extensions/Banshee.DapCore/Resources/
trunk/banshee/src/Extensions/Banshee.DapCore/Resources/Banshee.DapCore.addin.xml
trunk/banshee/src/Extensions/Banshee.DapCore/hal-sharp/
trunk/banshee/src/Extensions/Banshee.DapCore/hal-sharp/Device.cs
trunk/banshee/src/Extensions/Banshee.DapCore/hal-sharp/Manager.cs
trunk/banshee/src/Extensions/Banshee.DapCore/hal-sharp/Volume.cs
Modified:
trunk/banshee/ChangeLog
trunk/banshee/build/build.environment.mk
trunk/banshee/configure.ac
trunk/banshee/src/Extensions/Makefile.am
Modified: trunk/banshee/build/build.environment.mk
==============================================================================
--- trunk/banshee/build/build.environment.mk (original)
+++ trunk/banshee/build/build.environment.mk Sat Feb 9 17:20:55 2008
@@ -101,6 +101,7 @@
# Extensions
REF_EXTENSION_AUDIOSCROBBLER = $(LINK_BANSHEE_SERVICES_DEPS)
+REF_EXTENSION_DAPCORE = $(LINK_BANSHEE_SERVICES_DEPS)
REF_EXTENSION_MULTIMEDIAKEYS = $(LINK_BANSHEE_SERVICES_DEPS)
REF_EXTENSION_NOTIFICATIONAREA = $(LINK_BANSHEE_THICKCLIENT_DEPS)
REF_EXTENSION_PLAYQUEUE = $(LINK_BANSHEE_THICKCLIENT_DEPS)
Modified: trunk/banshee/configure.ac
==============================================================================
--- trunk/banshee/configure.ac (original)
+++ trunk/banshee/configure.ac Sat Feb 9 17:20:55 2008
@@ -137,6 +137,7 @@
src/Extensions/Makefile
src/Extensions/Banshee.Audioscrobbler/Makefile
+src/Extensions/Banshee.DapCore/Makefile
src/Extensions/Banshee.MultimediaKeys/Makefile
src/Extensions/Banshee.NotificationArea/Makefile
src/Extensions/Banshee.PlayQueue/Makefile
Added: trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore.mdp
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore.mdp Sat Feb 9 17:20:55 2008
@@ -0,0 +1,28 @@
+<Project name="Banshee.DapCore" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
+ <Configurations active="Debug">
+ <Configuration name="Debug" ctype="DotNetProjectConfiguration">
+ <Output directory="../../../bin" assemblyKeyFile="." assembly="Banshee.DapCore" />
+ <Build debugmode="True" target="Library" />
+ <Execution runwithwarnings="True" consolepause="True" runtime="MsNet" clr-version="Net_2_0" />
+ <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
+ </Configuration>
+ </Configurations>
+ <Contents>
+ <File name="Banshee.DapCore.addin.xml" subtype="Code" buildaction="EmbedAsResource" />
+ </Contents>
+ <References>
+ <ProjectReference type="Project" localcopy="True" refto="Banshee.Core" />
+ <ProjectReference type="Project" localcopy="True" refto="Banshee.Services" />
+ <ProjectReference type="Project" localcopy="True" refto="Hyena" />
+ <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ </References>
+ <MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="True" RelativeMakefileName="./Makefile.am">
+ <BuildFilesVar Sync="True" Name="SOURCES" />
+ <DeployFilesVar />
+ <ResourcesVar Sync="True" Name="RESOURCES" />
+ <OthersVar />
+ <GacRefVar />
+ <AsmRefVar />
+ <ProjectRefVar />
+ </MonoDevelop.Autotools.MakefileInfo>
+</Project>
Added: trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/DapCore.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/DapCore.cs Sat Feb 9 17:20:55 2008
@@ -0,0 +1,45 @@
+//
+// DapCore.cs
+//
+// Author:
+// Aaron Bockover <abockover novell com>
+// 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 Banshee.ServiceStack;
+
+namespace Banshee.Dap
+{
+
+ public class DapCore : IExtensionService
+ {
+ void IExtensionService.Initialize() {
+
+ }
+
+ string IService.ServiceName {
+ get { return "DapCore"; }
+ }
+ }
+}
Added: trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/HalCore.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/Banshee.DapCore/HalCore.cs Sat Feb 9 17:20:55 2008
@@ -0,0 +1,52 @@
+//
+// DapCore.cs
+//
+// Author:
+// Aaron Bockover <abockover novell com>
+// Ruben Vermeersch <ruben savanne be>
+//
+// Copyright (C) 2005-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 Banshee.ServiceStack;
+using Hal;
+
+namespace Banshee.Hal
+{
+ public class HalCore : IExtensionService
+ {
+ private Manager manager;
+
+ public void Initialize ()
+ {
+ manager = new Manager ();
+ }
+
+ public Manager Manager {
+ get { return manager; }
+ }
+
+ string IService.ServiceName {
+ get { return "HalCore"; }
+ }
+ }
+}
Added: trunk/banshee/src/Extensions/Banshee.DapCore/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/Makefile.am Sat Feb 9 17:20:55 2008
@@ -0,0 +1,15 @@
+ASSEMBLY = Banshee.DapCore
+TARGET = library
+LINK = $(REF_EXTENSION_DAPCORE)
+
+SOURCES = \
+ Banshee.DapCore/DapCore.cs \
+ Banshee.DapCore/HalCore.cs \
+ hal-sharp/Device.cs \
+ hal-sharp/Manager.cs \
+ hal-sharp/Volume.cs
+
+RESOURCES = Resources/Banshee.DapCore.addin.xml
+
+include $(top_srcdir)/build/build.mk
+
Added: trunk/banshee/src/Extensions/Banshee.DapCore/Resources/Banshee.DapCore.addin.xml
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/Resources/Banshee.DapCore.addin.xml Sat Feb 9 17:20:55 2008
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Addin
+ id="Banshee.DapCore"
+ version="1.0"
+ compatVersion="1.0"
+ copyright="Â 2008 Novell Inc. Licensed under the MIT X11 license."
+ name=""
+ category=""
+ description=""
+ author="Ruben Vermeersch"
+ url="http://banshee-project.org/"
+ defaultEnabled="true">
+
+ <Dependencies>
+ <Addin id="Banshee.Services" version="1.0"/>
+ </Dependencies>
+
+ <Extension path="/Banshee/ServiceManager/Service">
+ <Service class="Banshee.Hal.HalCore"/>
+ <Service class="Banshee.Dap.DapCore"/>
+ </Extension>
+
+</Addin>
Added: trunk/banshee/src/Extensions/Banshee.DapCore/hal-sharp/Device.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/hal-sharp/Device.cs Sat Feb 9 17:20:55 2008
@@ -0,0 +1,370 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+using NDesk.DBus;
+
+namespace Hal
+{
+ public struct PropertyModification
+ {
+ public string Key;
+ public bool Added;
+ public bool Removed;
+ }
+
+ internal delegate void DBusPropertyModifiedHandler(int modificationsLength,
+ PropertyModification [] modifications);
+
+ [Interface("org.freedesktop.Hal.Device")]
+ internal interface IDevice
+ {
+ // TODO:
+ // Need to support the Condition event, but it has a
+ // variable number of arguments, not currently supported
+
+ event DBusPropertyModifiedHandler PropertyModified;
+
+ void SetPropertyString(string key, string value);
+ void SetPropertyInteger(string key, int value);
+ void SetPropertyBoolean(string key, bool value);
+ void SetPropertyDouble(string key, double value);
+ void SetPropertyStringList(string key, string [] value);
+
+ void SetProperty(string key, ulong value);
+ ulong GetProperty(string key); // nasty hack to get around the fact
+ // that HAL doesn't actually send this
+ // in a variant, nor does it have a
+ // GetPropertyUInt64
+ // should be object GetProperty(string key)
+
+ void StringListPrepend(string key, string value);
+ void StringListAppend(string key, string value);
+ void StringListRemove(string key, string value);
+
+ string GetPropertyString(string key);
+ int GetPropertyInteger(string key);
+ bool GetPropertyBoolean(string key);
+ double GetPropertyDouble(string key);
+ string [] GetPropertyStringList(string key);
+
+ IDictionary<string, object> GetAllProperties();
+ void RemoveProperty(string key);
+ PropertyType GetPropertyType(string key);
+ bool PropertyExists(string key);
+
+ void AddCapability(string capability);
+ bool QueryCapability(string capability);
+ void Lock(string reason);
+ void Unlock();
+ }
+
+ internal enum DType : byte
+ {
+ Invalid = (byte)'\0',
+ Byte = (byte)'y',
+ Boolean = (byte)'b',
+ Int16 = (byte)'n',
+ UInt16 = (byte)'q',
+ Int32 = (byte)'i',
+ UInt32 = (byte)'u',
+ Int64 = (byte)'x',
+ UInt64 = (byte)'t',
+ Single = (byte)'f',
+ Double = (byte)'d',
+ String = (byte)'s',
+ ObjectPath = (byte)'o',
+ Signature = (byte)'g',
+ Array = (byte)'a',
+ Struct = (byte)'r',
+ DictEntry = (byte)'e',
+ Variant = (byte)'v',
+ StructBegin = (byte)'(',
+ StructEnd = (byte)')',
+ DictEntryBegin = (byte)'{',
+ DictEntryEnd = (byte)'}',
+ }
+
+ public enum PropertyType
+ {
+ Invalid = DType.Invalid,
+ Int32 = DType.Int32,
+ UInt64 = DType.UInt64,
+ Double = DType.Double,
+ Boolean = DType.Boolean,
+ String = DType.String,
+ StrList = ((int)(DType.String << 8) + ('l'))
+ }
+
+ public class PropertyModifiedArgs : EventArgs
+ {
+ private PropertyModification [] modifications;
+
+ public PropertyModifiedArgs(PropertyModification [] modifications)
+ {
+ this.modifications = modifications;
+ }
+
+ public PropertyModification [] Modifications {
+ get { return modifications; }
+ }
+ }
+
+ public delegate void PropertyModifiedHandler(object o, PropertyModifiedArgs args);
+
+ public class Device : IEnumerable<KeyValuePair<string, object>>, IEqualityComparer<Device>,
+ IEquatable<Device>, IComparer<Device>, IComparable<Device>
+ {
+ private string udi;
+ private IDevice device;
+
+ public event PropertyModifiedHandler PropertyModified;
+
+ public Device(string udi)
+ {
+ this.udi = udi;
+
+ device = CastDevice<IDevice>();
+ device.PropertyModified += OnPropertyModified;
+ }
+
+ public static Device [] UdisToDevices(string [] udis)
+ {
+ if(udis == null || udis.Length == 0) {
+ return new Device[0];
+ }
+
+ Device [] devices = new Device[udis.Length];
+ for(int i = 0; i < udis.Length; i++) {
+ devices[i] = new Device(udis[i]);
+ }
+
+ return devices;
+ }
+
+ protected virtual void OnPropertyModified(int modificationsLength, PropertyModification [] modifications)
+ {
+ if(modifications.Length != modificationsLength) {
+ throw new ApplicationException("Number of modified properties does not match");
+ }
+
+ PropertyModifiedHandler handler = PropertyModified;
+ if(handler != null) {
+ handler(this, new PropertyModifiedArgs(modifications));
+ }
+ }
+
+ public string [] GetChildren(Manager manager)
+ {
+ return manager.FindDeviceByStringMatch("info.parent", Udi);
+ }
+
+ public Device [] GetChildrenAsDevice(Manager manager)
+ {
+ return manager.FindDeviceByStringMatchAsDevice("info.parent", Udi);
+ }
+
+ public void Lock(string reason)
+ {
+ device.Lock(reason);
+ }
+
+ public void Unlock()
+ {
+ device.Unlock();
+ }
+
+ public string GetPropertyString(string key)
+ {
+ return device.GetPropertyString(key);
+ }
+
+ public int GetPropertyInteger(string key)
+ {
+ return device.GetPropertyInteger(key);
+ }
+
+ public ulong GetPropertyUInt64(string key)
+ {
+ return device.GetProperty(key);
+ }
+
+ public double GetPropertyDouble(string key)
+ {
+ return device.GetPropertyDouble(key);
+ }
+
+ public bool GetPropertyBoolean(string key)
+ {
+ return device.GetPropertyBoolean(key);
+ }
+
+ public string [] GetPropertyStringList(string key)
+ {
+ return device.GetPropertyStringList(key);
+ }
+
+ public PropertyType GetPropertyType(string key)
+ {
+ return PropertyExists(key) ? device.GetPropertyType(key) : PropertyType.Invalid;
+ }
+
+ public void StringListPrepend(string key, string value)
+ {
+ device.SetPropertyString(key, value);
+ }
+
+ public void StringListAppend(string key, string value)
+ {
+ device.StringListAppend(key, value);
+ }
+
+ public void StringListRemove(string key, string value)
+ {
+ device.StringListRemove(key, value);
+ }
+
+ public void SetPropertyString(string key, string value)
+ {
+ device.SetPropertyString(key, value);
+ }
+
+ public void SetPropertyUInt64(string key, ulong value)
+ {
+ device.SetProperty(key, value);
+ }
+
+ public void SetPropertyInteger(string key, int value)
+ {
+ device.SetPropertyInteger(key, value);
+ }
+
+ public void SetPropertyDouble(string key, double value)
+ {
+ device.SetPropertyDouble(key, value);
+ }
+
+ public void SetPropertyBoolean(string key, bool value)
+ {
+ device.SetPropertyBoolean(key, value);
+ }
+
+ public void SetPropertyStringList(string key, string [] value)
+ {
+ device.SetPropertyStringList(key, value);
+ }
+
+ public void RemoveProperty(string key)
+ {
+ device.RemoveProperty(key);
+ }
+
+ public bool PropertyExists(string key)
+ {
+ return device.PropertyExists(key);
+ }
+
+ public void AddCapability(string capability)
+ {
+ device.AddCapability(capability);
+ }
+
+ public bool QueryCapability(string capability)
+ {
+ return device.QueryCapability(capability);
+ }
+
+ public T CastDevice<T>()
+ {
+ if(!Bus.System.NameHasOwner("org.freedesktop.Hal")) {
+ throw new ApplicationException("Could not find org.freedesktop.Hal");
+ }
+
+ return Bus.System.GetObject<T>("org.freedesktop.Hal", new ObjectPath(Udi));
+ }
+
+ public IEnumerator<KeyValuePair<string, object>> GetEnumerator()
+ {
+ return device.GetAllProperties().GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return device.GetAllProperties().GetEnumerator();
+ }
+
+ public bool Equals(Device other)
+ {
+ return Udi.Equals(other.Udi);
+ }
+
+ public bool Equals(Device a, Device b)
+ {
+ return a.Udi.Equals(b.Udi);
+ }
+
+ public int CompareTo(Device other)
+ {
+ return Udi.CompareTo(other.Udi);
+ }
+
+ public int Compare(Device a, Device b)
+ {
+ return a.Udi.CompareTo(b.Udi);
+ }
+
+ public int GetHashCode(Device a)
+ {
+ return a.Udi.GetHashCode();
+ }
+
+ public override int GetHashCode()
+ {
+ return Udi.GetHashCode();
+ }
+
+ public override string ToString()
+ {
+ return udi;
+ }
+
+ public string this[string property] {
+ get { return PropertyExists(property) ? GetPropertyString(property) : null; }
+ set { SetPropertyString(property, value); }
+ }
+
+ public string Udi {
+ get { return udi; }
+ }
+
+ public bool IsVolume {
+ get {
+ if(!PropertyExists("info.interfaces")) {
+ return false;
+ }
+
+ foreach(string @interface in GetPropertyStringList("info.interfaces")) {
+ if(@interface == "org.freedesktop.Hal.Device.Volume") {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ public Volume Volume {
+ get { return new Volume(Udi); }
+ }
+
+ public Device Parent {
+ get {
+ if(PropertyExists("info.parent")) {
+ return new Device(this["info.parent"]);
+ }
+
+ return null;
+ }
+ }
+ }
+}
Added: trunk/banshee/src/Extensions/Banshee.DapCore/hal-sharp/Manager.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/hal-sharp/Manager.cs Sat Feb 9 17:20:55 2008
@@ -0,0 +1,170 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+using NDesk.DBus;
+
+namespace Hal
+{
+ internal delegate void DBusDeviceAddedHandler(string udi);
+ internal delegate void DBusDeviceRemovedHandler(string udi);
+ internal delegate void DBusNewCapabilityHandler(string udi, string capability);
+
+ [Interface("org.freedesktop.Hal.Manager")]
+ internal interface IManager
+ {
+ event DBusDeviceAddedHandler DeviceAdded;
+ event DBusDeviceRemovedHandler DeviceRemoved;
+ event DBusNewCapabilityHandler NewCapability;
+
+ string [] GetAllDevices();
+ bool DeviceExists(string udi);
+ string [] FindDeviceStringMatch(string key, string value);
+ string [] FindDeviceByCapability(string capability);
+ }
+
+ public class DeviceArgs : EventArgs
+ {
+ private string udi;
+
+ public DeviceArgs(string udi)
+ {
+ this.udi = udi;
+ }
+
+ public string Udi {
+ get { return udi; }
+ }
+ }
+
+ public class DeviceAddedArgs : DeviceArgs
+ {
+ private Device device;
+
+ public DeviceAddedArgs(string udi) : base(udi)
+ {
+ }
+
+ public Device Device {
+ get {
+ if(device == null) {
+ device = new Device(Udi);
+ }
+
+ return device;
+ }
+ }
+ }
+
+ public class DeviceRemovedArgs : DeviceArgs
+ {
+ public DeviceRemovedArgs(string udi) : base(udi)
+ {
+ }
+ }
+
+ public class NewCapabilityArgs : DeviceArgs
+ {
+ private string capability;
+
+ public NewCapabilityArgs(string udi, string capability) : base(udi)
+ {
+ this.capability = capability;
+ }
+
+ public string Capability {
+ get { return capability; }
+ }
+ }
+
+ public delegate void DeviceAddedHandler(object o, DeviceAddedArgs args);
+ public delegate void DeviceRemovedHandler(object o, DeviceRemovedArgs args);
+ public delegate void NewCapabilityHandler(object o, NewCapabilityArgs args);
+
+ public class Manager : IEnumerable<string>
+ {
+ private IManager manager;
+
+ public event DeviceAddedHandler DeviceAdded;
+ public event DeviceRemovedHandler DeviceRemoved;
+ public event NewCapabilityHandler NewCapability;
+
+ public Manager()
+ {
+ if(!Bus.System.NameHasOwner("org.freedesktop.Hal")) {
+ throw new ApplicationException("Could not find org.freedesktop.Hal");
+ }
+
+ manager = Bus.System.GetObject<IManager>("org.freedesktop.Hal",
+ new ObjectPath("/org/freedesktop/Hal/Manager"));
+
+ if(manager == null) {
+ throw new ApplicationException("The /org/freedesktop/Hal/Manager object could not be located on the DBUs interface org.freedesktop.Hal");
+ }
+
+ manager.DeviceAdded += OnDeviceAdded;
+ manager.DeviceRemoved += OnDeviceRemoved;
+ manager.NewCapability += OnNewCapability;
+ }
+
+ protected virtual void OnDeviceAdded(string udi)
+ {
+ if(DeviceAdded != null)
+ DeviceAdded(this, new DeviceAddedArgs(udi));
+ }
+
+ protected virtual void OnDeviceRemoved(string udi)
+ {
+ if(DeviceRemoved != null)
+ DeviceRemoved(this, new DeviceRemovedArgs(udi));
+ }
+
+ protected virtual void OnNewCapability(string udi, string capability)
+ {
+ if(NewCapability != null)
+ NewCapability(this, new NewCapabilityArgs(udi, capability));
+ }
+
+ public bool DeviceExists(string udi)
+ {
+ return manager.DeviceExists(udi);
+ }
+
+ public string [] FindDeviceByStringMatch(string key, string value)
+ {
+ return manager.FindDeviceStringMatch(key, value);
+ }
+
+ public string [] FindDeviceByCapability(string capability)
+ {
+ return manager.FindDeviceByCapability(capability);
+ }
+
+ public Device [] FindDeviceByCapabilityAsDevice(string capability)
+ {
+ return Device.UdisToDevices(FindDeviceByCapability(capability));
+ }
+
+ public Device [] FindDeviceByStringMatchAsDevice(string key, string value)
+ {
+ return Device.UdisToDevices(FindDeviceByStringMatch(key, value));
+ }
+
+ public string [] GetAllDevices()
+ {
+ return manager.GetAllDevices();
+ }
+
+ public IEnumerator<string> GetEnumerator()
+ {
+ foreach(string device in GetAllDevices()) {
+ yield return device;
+ }
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+ }
+}
Added: trunk/banshee/src/Extensions/Banshee.DapCore/hal-sharp/Volume.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Extensions/Banshee.DapCore/hal-sharp/Volume.cs Sat Feb 9 17:20:55 2008
@@ -0,0 +1,53 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+using NDesk.DBus;
+
+namespace Hal
+{
+ [Interface("org.freedesktop.Hal.Device.Volume")]
+ internal interface IVolume
+ {
+ void Mount(string [] args);
+ void Unmount(string [] args);
+ void Eject(string [] args);
+ }
+
+ public class Volume : Device
+ {
+ public Volume(string udi) : base(udi)
+ {
+ }
+
+ public void Mount()
+ {
+ Mount(new string [] { String.Empty });
+ }
+
+ public void Mount(params string [] args)
+ {
+ CastDevice<IVolume>().Mount(args);
+ }
+
+ public void Unmount()
+ {
+ Unmount(new string [] { String.Empty });
+ }
+
+ public void Unmount(params string [] args)
+ {
+ CastDevice<IVolume>().Unmount(args);
+ }
+
+ public void Eject()
+ {
+ Eject(new string [] { String.Empty });
+ }
+
+ public void Eject(params string [] args)
+ {
+ CastDevice<IVolume>().Eject(args);
+ }
+ }
+}
Modified: trunk/banshee/src/Extensions/Makefile.am
==============================================================================
--- trunk/banshee/src/Extensions/Makefile.am (original)
+++ trunk/banshee/src/Extensions/Makefile.am Sat Feb 9 17:20:55 2008
@@ -1,5 +1,6 @@
SUBDIRS = \
Banshee.Audioscrobbler \
+ Banshee.DapCore \
Banshee.MultimediaKeys \
Banshee.NotificationArea \
Banshee.PlayQueue
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]