зеркало из https://github.com/mono/hal-sharp.git
2005-11-30 Aaron Bockover <aaron@aaronbock.net>
* src/HalDevice.cs: Use DBusError when adding/removing property watch * src/HalTest.cs: Stripped down test * src/Makefile.am: Added DBusError.cs * src/DBusError.cs: Bindings to DBusError (dbus_error_init, dbus_error_free, dbus_error_is_set) * src/HalContext.cs: Use DBusError in places svn path=/trunk/hal-sharp/; revision=53731
This commit is contained in:
Родитель
c0d83bec7b
Коммит
f3313b7d18
|
@ -1,3 +1,12 @@
|
|||
2005-11-30 Aaron Bockover <aaron@aaronbock.net>
|
||||
|
||||
* src/HalDevice.cs: Use DBusError when adding/removing property watch
|
||||
* src/HalTest.cs: Stripped down test
|
||||
* src/Makefile.am: Added DBusError.cs
|
||||
* src/DBusError.cs: Bindings to DBusError (dbus_error_init,
|
||||
dbus_error_free, dbus_error_is_set)
|
||||
* src/HalContext.cs: Use DBusError in places
|
||||
|
||||
2005-11-26 Aaron Bockover <aaron@aaronbock.net>
|
||||
|
||||
* src/HalContext.cs: New Parent property that returns an instantiated
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<File name="./src/HalContext.cs" subtype="Code" buildaction="Compile" />
|
||||
<File name="./src/HalDefines.cs" subtype="Code" buildaction="Compile" />
|
||||
<File name="./src/HalCallbacks.cs" subtype="Code" buildaction="Compile" />
|
||||
<File name="./src/DBusError.cs" subtype="Code" buildaction="Compile" />
|
||||
</Contents>
|
||||
<References>
|
||||
<ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Mono.Unix;
|
||||
|
||||
namespace Hal
|
||||
{
|
||||
public class DBusError : IDisposable
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct UnmanagedError
|
||||
{
|
||||
public IntPtr name;
|
||||
public IntPtr message;
|
||||
public uint dummy1;
|
||||
public uint dummy2;
|
||||
public uint dummy3;
|
||||
public uint dummy4;
|
||||
public uint dummy5;
|
||||
public IntPtr padding1;
|
||||
}
|
||||
|
||||
[DllImport("libdbus-1")]
|
||||
private static extern void dbus_error_init(IntPtr handle);
|
||||
|
||||
[DllImport("libdbus-1")]
|
||||
private static extern void dbus_error_free(IntPtr handle);
|
||||
|
||||
[DllImport("libdbus-1")]
|
||||
private static extern bool dbus_error_is_set(IntPtr handle);
|
||||
|
||||
private IntPtr error_ptr;
|
||||
private UnmanagedError error;
|
||||
|
||||
public DBusError()
|
||||
{
|
||||
error = new UnmanagedError();
|
||||
error_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(error));
|
||||
dbus_error_init(error_ptr);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
dbus_error_free(error_ptr);
|
||||
Marshal.FreeHGlobal(error_ptr);
|
||||
}
|
||||
|
||||
public void ThrowExceptionIfSet(string message)
|
||||
{
|
||||
if(IsSet) {
|
||||
message += String.Format(": [{0}] {1}", Name, Message);
|
||||
Dispose();
|
||||
throw new HalException(message);
|
||||
} else {
|
||||
Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsSet {
|
||||
get {
|
||||
return dbus_error_is_set(error_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
public string Name {
|
||||
get {
|
||||
return UnixMarshal.PtrToString(error.name);
|
||||
}
|
||||
}
|
||||
|
||||
public string Message {
|
||||
get {
|
||||
return UnixMarshal.PtrToString(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
public IntPtr Raw {
|
||||
get {
|
||||
return error_ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -101,10 +101,13 @@ namespace Hal
|
|||
|
||||
public void Initialize()
|
||||
{
|
||||
if(!Unmanaged.libhal_ctx_init(ctx_handle, IntPtr.Zero)) {
|
||||
throw new HalException("Could not initialize HAL Context");
|
||||
DBusError error = new DBusError();
|
||||
if(!Unmanaged.libhal_ctx_init(ctx_handle, error.Raw)) {
|
||||
error.ThrowExceptionIfSet("Could not initialize HAL Context");
|
||||
return;
|
||||
}
|
||||
|
||||
error.Dispose();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -188,9 +188,13 @@ namespace Hal
|
|||
public bool WatchProperties
|
||||
{
|
||||
set {
|
||||
DBusError error = new DBusError();
|
||||
|
||||
bool result = value
|
||||
? Unmanaged.libhal_device_add_property_watch(ctx.Raw, udi, IntPtr.Zero)
|
||||
: Unmanaged.libhal_device_remove_property_watch(ctx.Raw, udi, IntPtr.Zero);
|
||||
? Unmanaged.libhal_device_add_property_watch(ctx.Raw, udi, error.Raw)
|
||||
: Unmanaged.libhal_device_remove_property_watch(ctx.Raw, udi, error.Raw);
|
||||
|
||||
error.ThrowExceptionIfSet("Could not update watch on property");
|
||||
|
||||
if(!result) {
|
||||
throw new HalException("Could not " + (value ? "add" : "remove") + " property watch");
|
||||
|
|
|
@ -29,14 +29,10 @@
|
|||
using System;
|
||||
using Hal;
|
||||
|
||||
public class Entry
|
||||
public static class HalTest
|
||||
{
|
||||
public static void Main()
|
||||
public static void Main(string [] args)
|
||||
{
|
||||
using(Context ctx = new Context()) {
|
||||
foreach(Device device in Device.FindByCapability(ctx, "portable_audio_player")) {
|
||||
device.Print();
|
||||
}
|
||||
}
|
||||
Context ctx = new Context();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ CLEANFILES = hal-sharp.dll hal-test.exe
|
|||
DISTCLEANFILES = Makefile.in *.mdb AssemblyInfo.cs hal-sharp.dll.config
|
||||
|
||||
halsharp_sources = \
|
||||
DBusError.cs \
|
||||
HalContext.cs \
|
||||
HalDevice.cs \
|
||||
HalUnmanaged.cs \
|
||||
|
|
Загрузка…
Ссылка в новой задаче