From 5b9337a20aabca4ea36f782ce6980ab6bcd0eca4 Mon Sep 17 00:00:00 2001 From: Aaron Bockover Date: Sun, 17 Jul 2005 00:03:05 +0000 Subject: [PATCH] Initial hal-sharp Import svn path=/trunk/hal-sharp/; revision=47360 --- AUTHORS | 2 + COPYING | 5 + ChangeLog | 10 ++ Makefile.am | 9 ++ NEWS | 2 + README | 7 + autogen.sh | 6 + configure.ac | 46 ++++++ hal-sharp.mdp | 31 ++++ hal-sharp.mds | 16 ++ hal-sharp.pc.in | 11 ++ src/AssemblyInfo.cs.in | 9 ++ src/HalContext.cs | 135 +++++++++++++++++ src/HalDefines.cs | 46 ++++++ src/HalDevice.cs | 327 +++++++++++++++++++++++++++++++++++++++++ src/HalExceptions.cs | 40 +++++ src/HalTest.cs | 52 +++++++ src/HalUnmanaged.cs | 229 +++++++++++++++++++++++++++++ src/Makefile.am | 19 +++ 19 files changed, 1002 insertions(+) create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 ChangeLog create mode 100644 Makefile.am create mode 100644 NEWS create mode 100644 README create mode 100755 autogen.sh create mode 100644 configure.ac create mode 100644 hal-sharp.mdp create mode 100644 hal-sharp.mds create mode 100644 hal-sharp.pc.in create mode 100644 src/AssemblyInfo.cs.in create mode 100644 src/HalContext.cs create mode 100644 src/HalDefines.cs create mode 100644 src/HalDevice.cs create mode 100644 src/HalExceptions.cs create mode 100644 src/HalTest.cs create mode 100644 src/HalUnmanaged.cs create mode 100644 src/Makefile.am diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..f1c167e --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Aaron Bockover + diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..1f95d26 --- /dev/null +++ b/COPYING @@ -0,0 +1,5 @@ +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. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..09add0a --- /dev/null +++ b/ChangeLog @@ -0,0 +1,10 @@ +2005-07-16 Aaron Bockover + + * hal-sharp: Version 0.1 Committed to Mono SVN + * hal-sharp: Most of HAL 0.5.2 API binding complete, decent set + of classes, and most works. Bindings missing: + + - PSI Functions + - Agent Functions + - Callbacks + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..38694a4 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,9 @@ +SUBDIRS = src +EXTRA_DIST = hal-sharp.pc.in hal-sharp.mds hal-sharp.mdp + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = hal-sharp.pc + +DISTCLEANFILES = config.* configure INSTALL install-sh missing aclocal.m4 Makefile.in + + diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..9f64a76 --- /dev/null +++ b/NEWS @@ -0,0 +1,2 @@ +2005-07-16: hal-sharp 0.1 Committed to Mono SVN + diff --git a/README b/README new file mode 100644 index 0000000..06b6006 --- /dev/null +++ b/README @@ -0,0 +1,7 @@ +These bindings aren't complete, but for the most part are functional with +the exception of callback support. Missing pieces are: + + * Agent Support + * PSI Support + * Callback Support + diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..6dffc06 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,6 @@ +#!/bin/sh +aclocal +automake -a +autoconf +./configure --enable-maintainer-mode $* + diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..a773b71 --- /dev/null +++ b/configure.ac @@ -0,0 +1,46 @@ +AC_INIT(README) +AC_CANONICAL_SYSTEM +AM_INIT_AUTOMAKE(hal-sharp, 0.1) +AM_MAINTAINER_MODE + +AC_PROG_INSTALL + +dnl pkg-config +AC_PATH_PROG(PKG_CONFIG, pkg-config, no) +if test "x$PKG_CONFIG" = "xno"; then + AC_MSG_ERROR([You need to install pkg-config]) +fi + +AC_PATH_PROG(INSTALL, install, /usr/bin/install) +AC_SUBST(INSTALL) +AC_SUBST(PKG_CONFIG) + +dnl Mono C# Compiler and Runtime +AC_PATH_PROG(MCS, mcs, no) +AC_PATH_PROG(MONO, mono, no) +CS="C#" + +if test "x$MCS" = "xno"; then + AC_MSG_ERROR([You need to install the Mono $CS compiler]) +fi + +if test "x$MONO" = "xno"; then + AC_MSG_ERROR([You need to install the Mono runtime]) +fi + +dnl Test for HAL +PKG_CHECK_MODULES(HAL, + dbus-1 \ + dbus-glib-1 \ + hal >= 0.5.2) + +AC_SUBST(MCS) + +AC_OUTPUT([ + Makefile + src/Makefile + src/AssemblyInfo.cs + hal-sharp.pc +]) + + diff --git a/hal-sharp.mdp b/hal-sharp.mdp new file mode 100644 index 0000000..7946d92 --- /dev/null +++ b/hal-sharp.mdp @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hal-sharp.mds b/hal-sharp.mds new file mode 100644 index 0000000..16e7e0b --- /dev/null +++ b/hal-sharp.mds @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/hal-sharp.pc.in b/hal-sharp.pc.in new file mode 100644 index 0000000..7a5868f --- /dev/null +++ b/hal-sharp.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ +Libraries=@libdir@/hal-sharp/hal-sharp.dll + +Name: hal-sharp +Description: hal-sharp - HAL C# Bindings +Version: @VERSION@ +Libs: -r:@libdir@/hal-sharp/hal-sharp.dll + diff --git a/src/AssemblyInfo.cs.in b/src/AssemblyInfo.cs.in new file mode 100644 index 0000000..99d33e9 --- /dev/null +++ b/src/AssemblyInfo.cs.in @@ -0,0 +1,9 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +[assembly: AssemblyVersion("@VERSION@")] +[assembly: AssemblyTitle ("hal-sharp")] +[assembly: AssemblyDescription ("HAL API Bindings")] +[assembly: AssemblyCopyright ("Copyright (c) 2005 Novell, Inc.")] +[assembly: AssemblyCompany ("Novell, Inc.")] + diff --git a/src/HalContext.cs b/src/HalContext.cs new file mode 100644 index 0000000..5013fbf --- /dev/null +++ b/src/HalContext.cs @@ -0,0 +1,135 @@ +/*************************************************************************** + * HalContext.cs + * + * Copyright (C) 2005 Novell + * Written by Aaron Bockover (aaron@aaronbock.net) + ****************************************************************************/ + +/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: + * + * 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; +using System.Runtime.InteropServices; + +namespace Hal +{ + public class Context : IDisposable + { + private HandleRef ctx_handle; + private IntPtr dbus_conn; + private bool initialized; + + public Context() + { + IntPtr ctx = Unmanaged.libhal_ctx_init_direct(IntPtr.Zero); + if(ctx == IntPtr.Zero) + throw new HalException("Could not create Direct HAL Context"); + + ctx_handle = new HandleRef(this, ctx); + } + + public Context(IntPtr dbus_conn) + { + IntPtr ctx = Unmanaged.libhal_ctx_new(); + if(ctx == IntPtr.Zero) + throw new HalException("Could not create HAL Context"); + + ctx_handle = new HandleRef(this, ctx); + DbusConnection = dbus_conn; + } + + public Context(DbusBusType type) : + this(Unmanaged.dbus_bus_get(type, IntPtr.Zero)) + { + + } + + public Context(DbusBusType type, bool initialize) : this(type) + { + Initialize(); + } + + ~Context() + { + Cleanup(); + } + + public void Dispose() + { + Cleanup(); + } + + private void Cleanup() + { + ContextShutdown(); + ContextFree(); + } + + private bool ContextShutdown() + { + if(ctx_handle.Handle == IntPtr.Zero || !initialized) + return false; + + return Unmanaged.libhal_ctx_shutdown(ctx_handle, IntPtr.Zero); + } + + private bool ContextFree() + { + if(ctx_handle.Handle == IntPtr.Zero) + return false; + + return Unmanaged.libhal_ctx_free(ctx_handle); + } + + public void Initialize() + { + if(!Unmanaged.libhal_ctx_init(ctx_handle, IntPtr.Zero)) + throw new HalException("Could not initialize HAL Context"); + + initialized = true; + } + + public IntPtr DbusConnection + { + set { + dbus_conn = value; + if(!Unmanaged.libhal_ctx_set_dbus_connection(ctx_handle, dbus_conn)) + throw new HalException("Could not set D-Bus Connection for HAL"); + } + } + + public bool UseCache + { + set { + if(!Unmanaged.libhal_ctx_set_cache(ctx_handle, value)) + throw new HalException("Could not set D-Bus Use Cache to '" + + value + "'"); + } + } + + public HandleRef Raw + { + get { + return ctx_handle; + } + } + } +} diff --git a/src/HalDefines.cs b/src/HalDefines.cs new file mode 100644 index 0000000..23f8b19 --- /dev/null +++ b/src/HalDefines.cs @@ -0,0 +1,46 @@ +/*************************************************************************** + * HalDefines.cs + * + * Copyright (C) 2005 Novell + * Written by Aaron Bockover (aaron@aaronbock.net) + ****************************************************************************/ + +/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: + * + * 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. + */ + +namespace Hal +{ + public enum DbusBusType : uint { + Session, + System, + Starter + }; + + public enum PropertyType : int { + Invalid = (int)'\0', + Boolean = (int)'b', + Int32 = (int)'i', + Uint64 = (int)'t', + Double = (int)'d', + String = (int)'s', + StringList = ((int)(PropertyType.String << 8) + ('l')) + }; +} diff --git a/src/HalDevice.cs b/src/HalDevice.cs new file mode 100644 index 0000000..68fffba --- /dev/null +++ b/src/HalDevice.cs @@ -0,0 +1,327 @@ +/*************************************************************************** + * HalDevice.cs + * + * Copyright (C) 2005 Novell + * Written by Aaron Bockover (aaron@aaronbock.net) + ****************************************************************************/ + +/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: + * + * 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; +using System.Runtime.InteropServices; +using Mono.Unix; + +namespace Hal +{ + public class Device + { + public enum FindBy : uint { + Capability, + StringMatch, + MatchAll + }; + + private string udi; + private Context ctx; + + public Device(Context ctx, string udi) + { + this.ctx = ctx; + this.udi = udi; + } + + public void Print() + { + Unmanaged.libhal_device_print(ctx.Raw, udi, IntPtr.Zero); + } + + public bool PropertyExists(string key) + { + return Unmanaged.libhal_device_property_exists(ctx.Raw, + udi, key, IntPtr.Zero); + } + + public string [] GetPropertyStringList(string key) + { + IntPtr ptr; + string [] properties; + + ptr = Unmanaged.libhal_device_get_property_strlist(ctx.Raw, + udi, key, IntPtr.Zero); + properties = UnixMarshal.PtrToStringArray(ptr); + Unmanaged.libhal_free_string_array(ptr); + + return properties; + } + + public bool PropertyStringListAppend(string key, string val) + { + return Unmanaged.libhal_device_property_strlist_append(ctx.Raw, + udi, key, val, IntPtr.Zero); + } + + public bool PropertyStringListPrepend(string key, string val) + { + return Unmanaged.libhal_device_property_strlist_append(ctx.Raw, + udi, key, val, IntPtr.Zero); + } + + public bool PropertyStringListRemove(string key, string val) + { + return Unmanaged.libhal_device_property_strlist_remove(ctx.Raw, + udi, key, val, IntPtr.Zero); + } + + public bool PropertyStringListRemoveIndex(string key, uint index) + { + return Unmanaged.libhal_device_property_strlist_remove_index(ctx.Raw, + udi, key, index, IntPtr.Zero); + } + + public string GetPropertyString(string key) + { + IntPtr ptr = Unmanaged.libhal_device_get_property_string(ctx.Raw, + udi, key, IntPtr.Zero); + string str = Marshal.PtrToStringAnsi(ptr); + Unmanaged.libhal_free_string(ptr); + return str; + } + + public bool SetPropertyString(string key, string val) + { + return Unmanaged.libhal_device_set_property_string(ctx.Raw, + udi, key, val, IntPtr.Zero); + } + + public int GetPropertyInt(string key) + { + return Unmanaged.libhal_device_get_property_int(ctx.Raw, + udi, key, IntPtr.Zero); + } + + public bool SetPropertyInt(string key, int val) + { + return Unmanaged.libhal_device_set_property_int(ctx.Raw, + udi, key, val, IntPtr.Zero); + } + + public UInt64 GetPropertyUint64(string key) + { + return Unmanaged.libhal_device_get_property_uint64(ctx.Raw, + udi, key, IntPtr.Zero); + } + + public bool SetPropertyString(string key, UInt64 val) + { + return Unmanaged.libhal_device_set_property_uint64(ctx.Raw, + udi, key, val, IntPtr.Zero); + } + + public double GetPropertyDouble(string key) + { + return Unmanaged.libhal_device_get_property_double(ctx.Raw, + udi, key, IntPtr.Zero); + } + + public bool SetPropertyDouble(string key, double val) + { + return Unmanaged.libhal_device_set_property_double(ctx.Raw, + udi, key, val, IntPtr.Zero); + } + + public bool GetPropertyBool(string key) + { + return Unmanaged.libhal_device_get_property_bool(ctx.Raw, + udi, key, IntPtr.Zero); + } + + public bool SetPropertyBool(string key, bool val) + { + return Unmanaged.libhal_device_set_property_bool(ctx.Raw, + udi, key, val, IntPtr.Zero); + } + + public bool AddCapability(string capability) + { + return Unmanaged.libhal_device_add_capability(ctx.Raw, + udi, capability, IntPtr.Zero); + } + + public bool QueryCapability(string capability) + { + return Unmanaged.libhal_device_query_capability(ctx.Raw, + udi, capability, IntPtr.Zero); + } + + public void Lock(string reason) + { + string reason_why_locked; + if(!Unmanaged.libhal_device_lock(ctx.Raw, udi, reason, + out reason_why_locked, IntPtr.Zero)) + throw new HalException("Could not lock device: " + + reason_why_locked); + } + + public bool Unlock() + { + return Unmanaged.libhal_device_unlock(ctx.Raw, udi, IntPtr.Zero); + } + + public bool EmitCondition(string conditionName, string conditionDetails) + { + return Unmanaged.libhal_device_emit_condition(ctx.Raw, udi, + conditionName, conditionDetails, IntPtr.Zero); + } + + public bool Rescan() + { + return Unmanaged.libhal_device_rescan(ctx.Raw, udi, IntPtr.Zero); + } + + public bool Reprobe() + { + return Unmanaged.libhal_device_reprobe(ctx.Raw, udi, IntPtr.Zero); + } + + // Property Watching... Probably won't live here; will have to see + // when the callback wrapping is implemented + + public bool WatchProperties + { + set { + 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); + + if(!result) + throw new HalException("Could not " + (value ? "add" + : "remove") + " property watch"); + } + } + + public string this [string key] + { + get { + return GetPropertyString(key); + } + + set { + if(!SetPropertyString(key, value)) + throw new HalException("Could not set property '" + + key + "'"); + } + } + + public override string ToString() + { + return udi; + } + + public bool Exists + { + get { + return Unmanaged.libhal_device_exists(ctx.Raw, + udi, IntPtr.Zero); + } + } + + // static members + + public static bool DeviceExists(Context ctx, string udi) + { + return Unmanaged.libhal_device_exists(ctx.Raw, udi, IntPtr.Zero); + } + + public static string [] FindUdis(Context ctx, FindBy findMethod, + string key, string query) + { + IntPtr ptr; + string [] deviceUdis; + int device_count; + + switch(findMethod) { + case FindBy.StringMatch: + ptr = Unmanaged.libhal_manager_find_device_string_match( + ctx.Raw, key, query, out device_count, IntPtr.Zero); + break; + case FindBy.Capability: + ptr = Unmanaged.libhal_find_device_by_capability(ctx.Raw, + query, out device_count, IntPtr.Zero); + break; + case FindBy.MatchAll: + default: + ptr = Unmanaged.libhal_get_all_devices(ctx.Raw, + out device_count, IntPtr.Zero); + break; + } + + deviceUdis = UnixMarshal.PtrToStringArray(device_count, ptr); + Unmanaged.libhal_free_string_array(ptr); + + return deviceUdis; + } + + public static Device [] UdisToDevices(Context ctx, string [] udis) + { + Device [] devices = new Device[udis.Length]; + + for(int i = 0; i < udis.Length; i++) + devices[i] = new Device(ctx, udis[i]); + + return devices; + } + + public static string [] GetAllUdis(Context ctx) + { + return FindUdis(ctx, FindBy.MatchAll, null, null); + } + + public static Device [] GetAll(Context ctx) + { + return UdisToDevices(ctx, GetAllUdis(ctx)); + } + + public static string [] FindUdiByStringMatch(Context ctx, string key, + string val) + { + return FindUdis(ctx, FindBy.StringMatch, key, val); + } + + public static Device [] FindByStringMatch(Context ctx, string key, + string val) + { + return UdisToDevices(ctx, FindUdiByStringMatch(ctx, key, val)); + } + + public static string [] FindUdiByCapability(Context ctx, string cap) + { + return FindUdis(ctx, FindBy.Capability, null, cap); + } + + public static Device [] FindByCapability(Context ctx, string cap) + { + return UdisToDevices(ctx, FindUdiByCapability(ctx, cap)); + } + } +} diff --git a/src/HalExceptions.cs b/src/HalExceptions.cs new file mode 100644 index 0000000..8d95396 --- /dev/null +++ b/src/HalExceptions.cs @@ -0,0 +1,40 @@ +/*************************************************************************** + * HalExceptions.cs + * + * Copyright (C) 2005 Novell + * Written by Aaron Bockover (aaron@aaronbock.net) + ****************************************************************************/ + +/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: + * + * 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 Hal +{ + public class HalException : ApplicationException + { + public HalException(string message) : base(message) + { + + } + } +} diff --git a/src/HalTest.cs b/src/HalTest.cs new file mode 100644 index 0000000..6e97836 --- /dev/null +++ b/src/HalTest.cs @@ -0,0 +1,52 @@ +/*************************************************************************** + * HalTest.cs + * + * Copyright (C) 2005 Novell + * Written by Aaron Bockover (aaron@aaronbock.net) + ****************************************************************************/ + +/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: + * + * 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; +using Hal; + +public class Entry +{ + public static void Main() + { + Context ctx = new Context(DbusBusType.System, true); + + foreach(Device device in Device.FindByCapability(ctx, "net")) + device.Print(); + + /*foreach(Device device in Device.GetAll(ctx)) + device.Print();*/ + + /*foreach(Device device in Device.FindByStringMatch(ctx, "info.vendor", "Intel Corporation")) + device.Print();*/ + + /*Device device = new Device(ctx, "/org/freedesktop/Hal/devices/net_00_05_4e_42_57_6b"); + string [] capabilities = device.GetPropertyStringList("info.capabilities"); + foreach(string cap in capabilities) + Console.WriteLine(cap);*/ + } +} diff --git a/src/HalUnmanaged.cs b/src/HalUnmanaged.cs new file mode 100644 index 0000000..b21f528 --- /dev/null +++ b/src/HalUnmanaged.cs @@ -0,0 +1,229 @@ +/*************************************************************************** + * HalUnmanaged.cs + * + * Copyright (C) 2005 Novell + * Written by Aaron Bockover (aaron@aaronbock.net) + ****************************************************************************/ + +/* THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: + * + * 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; +using System.Runtime.InteropServices; + +namespace Hal +{ + internal sealed class Unmanaged + { + // Context Functions + + [DllImport("libhal")] + public static extern IntPtr libhal_ctx_new(); + + [DllImport("libhal")] + public static extern IntPtr libhal_ctx_init_direct(IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_ctx_set_dbus_connection(HandleRef ctx, + IntPtr conn); + + [DllImport("libhal")] + public static extern bool libhal_ctx_set_cache(HandleRef ctx, + bool use_cache); + + [DllImport("libhal")] + public static extern bool libhal_ctx_init(HandleRef ctx, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_ctx_shutdown(HandleRef ctx, + IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_ctx_free(HandleRef ctx); + + // String Functions + + [DllImport("libhal")] + public static extern void libhal_free_string_array(IntPtr array); + + [DllImport("libhal")] + public static extern void libhal_free_string(IntPtr str); + + // Device Functions + + [DllImport("libhal")] + public static extern IntPtr libhal_get_all_devices(HandleRef ctx, + out int count, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_exists(HandleRef ctx, + string udi, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_print(HandleRef ctx, string udi, + IntPtr error); + + // Property Get Functions + + [DllImport("libhal")] + public static extern IntPtr libhal_device_get_property_string( + HandleRef ctx, string udi, string key, IntPtr error); + + [DllImport("libhal")] + public static extern int libhal_device_get_property_int(HandleRef ctx, + string udi, string key, IntPtr error); + + [DllImport("libhal")] + public static extern UInt64 libhal_device_get_property_uint64( + HandleRef ctx, string udi, string key, IntPtr error); + + [DllImport("libhal")] + public static extern double libhal_device_get_property_double( + HandleRef ctx, string udi, string key, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_get_property_bool(HandleRef ctx, + string udi, string key, IntPtr error); + + // Property Set Functions + + [DllImport("libhal")] + public static extern bool libhal_device_set_property_string( + HandleRef ctx, string udi, string key, string value, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_set_property_int(HandleRef ctx, + string udi, string key, int value, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_set_property_uint64( + HandleRef ctx, string udi, string key, UInt64 value, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_set_property_double( + HandleRef ctx, string udi, string key, double value, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_set_property_bool(HandleRef ctx, + string udi, string key, bool value, IntPtr error); + + // String List Property Functions + + [DllImport("libhal")] + public static extern IntPtr libhal_device_get_property_strlist( + HandleRef ctx, string udi, string key, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_property_strlist_append( + HandleRef ctx, string udi, string key, string value, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_property_strlist_prepend( + HandleRef ctx, string udi, string key, string value, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_property_strlist_remove_index( + HandleRef ctx, string udi, string key, uint index, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_property_strlist_remove( + HandleRef ctx, string udi, string key, string value, IntPtr error); + + // Other Property Functions + + [DllImport("libhal")] + public static extern bool libhal_device_property_exists(HandleRef ctx, + string udi, string key, IntPtr error); + + [DllImport("libhal")] + public static extern PropertyType libhal_device_get_property_type( + HandleRef ctx, string udi, string key, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_remove_property(HandleRef ctx, + string udi, string key, IntPtr error); + + [DllImport("libhal")] + public static extern IntPtr libhal_manager_find_device_string_match( + HandleRef ctx, string key, string value, out int num_devices, + IntPtr error); + + // Capability Functions + + [DllImport("libhal")] + public static extern bool libhal_device_add_capability(HandleRef ctx, + string udi, string capability, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_query_capability(HandleRef ctx, + string udi, string capability, IntPtr error); + + [DllImport("libhal")] + public static extern IntPtr libhal_find_device_by_capability( + HandleRef ctx, string capability, out int num_deivces, + IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_property_watch_all( + HandleRef ctx, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_add_property_watch( + HandleRef ctx, string udi, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_remove_property_watch( + HandleRef ctx, string udi, IntPtr error); + + // Locking Functions + + [DllImport("libhal")] + public static extern bool libhal_device_lock(HandleRef ctx, string udi, + string reason_to_lock, out string reason_why_locked, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_unlock(HandleRef ctx, + string udi, IntPtr error); + + // Rescan/Reprobe Functions + + [DllImport("libhal")] + public static extern bool libhal_device_rescan(HandleRef ctx, + string udi, IntPtr error); + + [DllImport("libhal")] + public static extern bool libhal_device_reprobe(HandleRef ctx, + string udi, IntPtr error); + + // Condition Functions + + [DllImport("libhal")] + public static extern bool libhal_device_emit_condition(HandleRef ctx, + string udi, string condition_name, string condition_details, + IntPtr error); + + // D-Bus Functions + + [DllImport("libdbus-1")] + public static extern IntPtr dbus_bus_get(DbusBusType bus_typed, + IntPtr error); + } +} diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..a4cd67a --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,19 @@ +halsharpdir=$(pkglibdir) +halsharp_SCRIPTS = hal-sharp.dll +EXTRA_DIST = $(halsharp_sources) HalTest.cs +CLEANFILES = hal-sharp.dll AssemblyInfo.cs +DISTCLEANFILES = Makefile.in + +halsharp_sources = \ + HalContext.cs \ + HalDevice.cs \ + HalUnmanaged.cs \ + HalDefines.cs \ + HalExceptions.cs \ + AssemblyInfo.cs + +halsharp_build_sources = $(addprefix $(srcdir)/, $(halsharp_sources)) + +hal-sharp.dll: + $(MCS) -target:library -out:$@ -r:Mono.Posix $(halsharp_build_sources) +