svn path=/trunk/hal-sharp/; revision=47360
This commit is contained in:
Aaron Bockover 2005-07-17 00:03:05 +00:00
Коммит 5b9337a20a
19 изменённых файлов: 1002 добавлений и 0 удалений

2
AUTHORS Normal file
Просмотреть файл

@ -0,0 +1,2 @@
Aaron Bockover <aaron@aaronbock.net>

5
COPYING Normal file
Просмотреть файл

@ -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.

10
ChangeLog Normal file
Просмотреть файл

@ -0,0 +1,10 @@
2005-07-16 Aaron Bockover <aaron@aaronbock.net>
* 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

9
Makefile.am Normal file
Просмотреть файл

@ -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

2
NEWS Normal file
Просмотреть файл

@ -0,0 +1,2 @@
2005-07-16: hal-sharp 0.1 Committed to Mono SVN

7
README Normal file
Просмотреть файл

@ -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

6
autogen.sh Executable file
Просмотреть файл

@ -0,0 +1,6 @@
#!/bin/sh
aclocal
automake -a
autoconf
./configure --enable-maintainer-mode $*

46
configure.ac Normal file
Просмотреть файл

@ -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
])

31
hal-sharp.mdp Normal file
Просмотреть файл

@ -0,0 +1,31 @@
<Project name="hal-sharp" fileversion="2.0" language="C#" ctype="DotNetProject">
<Configurations>
<Configuration name="Debug" ctype="DotNetProjectConfiguration">
<Output directory="./src" assembly="hal-sharp" />
<Build debugmode="True" target="Exe" />
<Execution runwithwarnings="True" consolepause="True" runtime="MsNet" />
<CodeGeneration compiler="Csc" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" mainclass="" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
</Configuration>
<Configuration name="Release" ctype="DotNetProjectConfiguration">
<Output directory="./src" assembly="hal-sharp" />
<Build debugmode="False" target="Exe" />
<Execution runwithwarnings="True" consolepause="True" runtime="MsNet" />
<CodeGeneration compiler="Csc" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
</Configuration>
</Configurations>
<References>
<ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
</References>
<DeploymentInformation strategy="File">
<excludeFiles />
</DeploymentInformation>
<Contents>
<File name="./src" subtype="Directory" buildaction="Compile" />
<File name="./src/HalExceptions.cs" subtype="Code" buildaction="Compile" />
<File name="./src/HalTest.cs" subtype="Code" buildaction="Compile" />
<File name="./src/HalDevice.cs" subtype="Code" buildaction="Compile" />
<File name="./src/HalUnmanaged.cs" subtype="Code" buildaction="Compile" />
<File name="./src/HalContext.cs" subtype="Code" buildaction="Compile" />
<File name="./src/HalDefines.cs" subtype="Code" buildaction="Compile" />
</Contents>
</Project>

16
hal-sharp.mds Normal file
Просмотреть файл

@ -0,0 +1,16 @@
<Combine name="Hal" fileversion="2.0">
<Configurations>
<Configuration name="Debug" ctype="CombineConfiguration">
<Entry build="True" name="hal-sharp" />
</Configuration>
<Configuration name="Release" ctype="CombineConfiguration">
<Entry build="True" name="hal-sharp" />
</Configuration>
</Configurations>
<StartMode startupentry="Hal" single="True">
<Execute type="None" entry="hal-sharp" />
</StartMode>
<Entries>
<Entry filename="./hal-sharp.mdp" />
</Entries>
</Combine>

11
hal-sharp.pc.in Normal file
Просмотреть файл

@ -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

9
src/AssemblyInfo.cs.in Normal file
Просмотреть файл

@ -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.")]

135
src/HalContext.cs Normal file
Просмотреть файл

@ -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;
}
}
}
}

46
src/HalDefines.cs Normal file
Просмотреть файл

@ -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'))
};
}

327
src/HalDevice.cs Normal file
Просмотреть файл

@ -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));
}
}
}

40
src/HalExceptions.cs Normal file
Просмотреть файл

@ -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)
{
}
}
}

52
src/HalTest.cs Normal file
Просмотреть файл

@ -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);*/
}
}

229
src/HalUnmanaged.cs Normal file
Просмотреть файл

@ -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);
}
}

19
src/Makefile.am Normal file
Просмотреть файл

@ -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)