2005-11-18 Aaron Bockover <aaron@aaronbock.net>

* src/Makefile.am: Added rule to build HalTest.cs
    * src/HalContext.cs: Removed destructor, must use Dispose()
    * src/*.cs: Tabs->Spaces, reformatted code a little


svn path=/trunk/hal-sharp/; revision=53248
This commit is contained in:
Aaron Bockover 2005-11-18 21:11:50 +00:00
Родитель fcf32b6dca
Коммит 9f380a670b
11 изменённых файлов: 906 добавлений и 1034 удалений

Просмотреть файл

@ -1,3 +1,9 @@
2005-11-18 Aaron Bockover <aaron@aaronbock.net>
* src/Makefile.am: Added rule to build HalTest.cs
* src/HalContext.cs: Removed destructor, must use Dispose()
* src/*.cs: Tabs->Spaces, reformatted code a little
2005-07-17 Aaron Bockover <aaron@aaronbock.net>
* HalTest.cs: GTK test for events using main context

Просмотреть файл

@ -1,5 +1,5 @@
<Project name="hal-sharp" fileversion="2.0" language="C#" ctype="DotNetProject">
<Configurations>
<Configurations active="Debug">
<Configuration name="Debug" ctype="DotNetProjectConfiguration">
<Output directory="./src" assembly="hal-sharp" />
<Build debugmode="True" target="Exe" />
@ -13,11 +13,6 @@
<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" />
<ProjectReference type="Gac" localcopy="True" refto="gtk-sharp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
<ProjectReference type="Gac" localcopy="True" refto="glib-sharp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
</References>
<DeploymentInformation strategy="File">
<excludeFiles />
</DeploymentInformation>
@ -31,4 +26,8 @@
<File name="./src/HalDefines.cs" subtype="Code" buildaction="Compile" />
<File name="./src/HalCallbacks.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
<ProjectReference type="Gac" localcopy="True" refto="gtk-sharp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
</References>
</Project>

Просмотреть файл

@ -1,10 +1,10 @@
<Combine name="Hal" fileversion="2.0">
<Configurations>
<Configurations active="Debug">
<Configuration name="Debug" ctype="CombineConfiguration">
<Entry build="True" name="hal-sharp" />
<Entry configuration="Debug" build="True" name="hal-sharp" />
</Configuration>
<Configuration name="Release" ctype="CombineConfiguration">
<Entry build="True" name="hal-sharp" />
<Entry configuration="Release" build="True" name="hal-sharp" />
</Configuration>
</Configurations>
<StartMode startupentry="hal-sharp" single="True">

Просмотреть файл

@ -31,64 +31,58 @@ using System.Runtime.InteropServices;
namespace Hal
{
// Raw HAL Callbacks
public delegate void DeviceAddedCallback(IntPtr ctx, IntPtr udi);
public delegate void DeviceRemovedCallback(IntPtr ctx, IntPtr udi);
public delegate void DeviceNewCapabilityCallback(IntPtr ctx, IntPtr udi,
IntPtr capability);
public delegate void DeviceLostCapabilityCallback(IntPtr ctx, IntPtr udi,
IntPtr capability);
public delegate void DevicePropertyModifiedCallback(IntPtr ctx, IntPtr udi,
IntPtr key, bool is_removed, bool is_added);
public delegate void DeviceConditionCallback(IntPtr ctx, IntPtr udi,
IntPtr condition_name, IntPtr condition_details);
// Managed Event Handlers
// Raw HAL Callbacks
internal delegate void DeviceAddedCallback(IntPtr ctx, IntPtr udi);
internal delegate void DeviceRemovedCallback(IntPtr ctx, IntPtr udi);
internal delegate void DeviceNewCapabilityCallback(IntPtr ctx, IntPtr udi, IntPtr capability);
internal delegate void DeviceLostCapabilityCallback(IntPtr ctx, IntPtr udi, IntPtr capability);
internal delegate void DevicePropertyModifiedCallback(IntPtr ctx, IntPtr udi,
IntPtr key, bool is_removed, bool is_added);
internal delegate void DeviceConditionCallback(IntPtr ctx, IntPtr udi,
IntPtr condition_name, IntPtr condition_details);
// Managed Event Handlers
public delegate void DeviceAddedHandler(object o, DeviceAddedArgs args);
public delegate void DeviceRemovedHandler(object o, DeviceRemovedArgs args);
public delegate void DeviceNewCapabilityHandler(object o,
DeviceNewCapabilityArgs args);
public delegate void DeviceLostCapabilityHandler(object o,
DeviceLostCapabilityArgs args);
public delegate void DevicePropertyModifiedHandler(object o,
DevicePropertyModifiedArgs args);
public delegate void DeviceConditionHandler(object o,
DeviceConditionArgs args);
public class DeviceAddedArgs : EventArgs
{
public Device Device;
}
public class DeviceRemovedArgs : EventArgs
{
public Device Device;
public delegate void DeviceNewCapabilityHandler(object o, DeviceNewCapabilityArgs args);
public delegate void DeviceLostCapabilityHandler(object o, DeviceLostCapabilityArgs args);
public delegate void DevicePropertyModifiedHandler(object o, DevicePropertyModifiedArgs args);
public delegate void DeviceConditionHandler(object o, DeviceConditionArgs args);
public class DeviceAddedArgs : EventArgs
{
public Device Device;
}
public class DeviceNewCapabilityArgs : EventArgs
{
public Device Device;
public string Capability;
}
public class DeviceRemovedArgs : EventArgs
{
public Device Device;
}
public class DeviceLostCapabilityArgs : EventArgs
{
public Device Device;
public string Capability;
}
public class DevicePropertyModifiedArgs : EventArgs
{
public Device Device;
public string Key;
public bool IsRemoved;
public bool IsAdded;
}
public class DeviceConditionArgs : EventArgs
{
public Device Device;
public string ConditionName;
public string ConditionDetails;
}
public class DeviceNewCapabilityArgs : EventArgs
{
public Device Device;
public string Capability;
}
public class DeviceLostCapabilityArgs : EventArgs
{
public Device Device;
public string Capability;
}
public class DevicePropertyModifiedArgs : EventArgs
{
public Device Device;
public string Key;
public bool IsRemoved;
public bool IsAdded;
}
public class DeviceConditionArgs : EventArgs
{
public Device Device;
public string ConditionName;
public string ConditionDetails;
}
}

Просмотреть файл

@ -32,336 +32,323 @@ using System.Runtime.InteropServices;
namespace Hal
{
public class Context : IDisposable
{
private HandleRef ctx_handle;
private IntPtr dbus_conn;
private bool initialized;
private bool mainLoopIntegrated;
public Context() : this(DbusBusType.System)
{
}
protected 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))
{
Initialize();
}
public Context(DbusBusType type, bool initialize) : this(type)
{
Initialize();
}
~Context()
{
Cleanup();
}
public void Dispose()
{
Cleanup();
}
private void Cleanup()
{
ContextShutdown();
ContextFree();
}
public class Context : IDisposable
{
private HandleRef ctx_handle;
private IntPtr dbus_conn;
private bool initialized;
private bool mainLoopIntegrated;
public Context() : this(DbusBusType.System)
{
}
protected 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))
{
Initialize();
}
public Context(DbusBusType type, bool initialize) : this(type)
{
Initialize();
}
private bool ContextShutdown()
{
if(ctx_handle.Handle == IntPtr.Zero || !initialized)
return false;
return Unmanaged.libhal_ctx_shutdown(ctx_handle, IntPtr.Zero);
}
public void Dispose()
{
ContextShutdown();
ContextFree();
}
private bool ContextFree()
{
if(ctx_handle.Handle == IntPtr.Zero)
return false;
private bool ContextShutdown()
{
if(ctx_handle.Handle == IntPtr.Zero || !initialized) {
return false;
}
return Unmanaged.libhal_ctx_shutdown(ctx_handle, IntPtr.Zero);
}
return Unmanaged.libhal_ctx_free(ctx_handle);
}
public void IntegrateMainLoop()
{
// would be nice to let user specify an optional GMainContext
Unmanaged.dbus_connection_setup_with_g_main(dbus_conn,
Unmanaged.g_main_context_default());
mainLoopIntegrated = true;
}
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;
}
}
// Events
private Hashtable EventTable = new Hashtable();
private bool AddEvent(Type evType, object ev)
{
if(EventTable[evType] == null)
EventTable[evType] = new ArrayList();
(EventTable[evType] as ArrayList).Add(ev);
if(!mainLoopIntegrated)
IntegrateMainLoop();
return (EventTable[evType] as ArrayList).Count == 1;
}
private void RemoveEvent(Type evType, object ev)
{
if(EventTable[evType] == null)
return;
(EventTable[evType] as ArrayList).Remove(ev);
}
private ArrayList GetEvents(Type evType)
{
if(EventTable[evType] == null)
return null;
return EventTable[evType] as ArrayList;
}
public event DeviceAddedHandler DeviceAdded
{
add {
if(AddEvent(typeof(DeviceAddedHandler), value))
Unmanaged.libhal_ctx_set_device_added(ctx_handle,
new DeviceAddedCallback(OnHalDeviceAdded));
}
remove {
RemoveEvent(typeof(DeviceAddedHandler), value);
}
}
public event DeviceRemovedHandler DeviceRemoved
{
add {
if(AddEvent(typeof(DeviceRemovedHandler), value))
Unmanaged.libhal_ctx_set_device_removed(ctx_handle,
new DeviceRemovedCallback(OnHalDeviceRemoved));
}
remove {
RemoveEvent(typeof(DeviceRemovedHandler), value);
}
}
public event DeviceNewCapabilityHandler DeviceNewCapability
{
add {
if(AddEvent(typeof(DeviceNewCapabilityHandler), value))
Unmanaged.libhal_ctx_set_device_new_capability(ctx_handle,
new DeviceNewCapabilityCallback(
OnHalDeviceNewCapability));
}
remove {
RemoveEvent(typeof(DeviceNewCapabilityHandler), value);
}
}
public event DeviceLostCapabilityHandler DeviceLostCapability
{
add {
if(AddEvent(typeof(DeviceLostCapabilityHandler), value))
Unmanaged.libhal_ctx_set_device_lost_capability(ctx_handle,
new DeviceLostCapabilityCallback(
OnHalDeviceLostCapability));
}
remove {
RemoveEvent(typeof(DeviceLostCapabilityHandler), value);
}
}
public event DevicePropertyModifiedHandler DevicePropertyModified
{
add {
if(AddEvent(typeof(DevicePropertyModifiedHandler), value))
Unmanaged.libhal_ctx_set_device_property_modified(
ctx_handle, new DevicePropertyModifiedCallback(
OnHalDevicePropertyModified));
}
remove {
RemoveEvent(typeof(DevicePropertyModifiedHandler), value);
}
}
public event DeviceConditionHandler DeviceCondition
{
add {
if(AddEvent(typeof(DeviceConditionHandler), value))
Unmanaged.libhal_ctx_set_device_condition(ctx_handle,
new DeviceConditionCallback(OnHalDeviceCondition));
}
remove {
RemoveEvent(typeof(DeviceConditionHandler), value);
}
}
private void OnHalDeviceAdded(IntPtr ctx, IntPtr udiPtr)
{
foreach(DeviceAddedHandler addedHandler in
GetEvents(typeof(DeviceAddedHandler))) {
DeviceAddedHandler handler = addedHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
DeviceAddedArgs args = new DeviceAddedArgs();
args.Device = new Device(this, udi);
handler(this, args);
}
}
}
private void OnHalDeviceRemoved(IntPtr ctx, IntPtr udiPtr)
{
foreach(DeviceRemovedHandler removedHandler in
GetEvents(typeof(DeviceRemovedHandler))) {
DeviceRemovedHandler handler = removedHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
DeviceRemovedArgs args = new DeviceRemovedArgs();
args.Device = new Device(this, udi);
handler(this, args);
}
}
}
private void OnHalDeviceNewCapability(IntPtr ctx, IntPtr udiPtr,
IntPtr capPtr)
{
foreach(DeviceNewCapabilityHandler newCapHandler in
GetEvents(typeof(DeviceNewCapabilityHandler))) {
DeviceNewCapabilityHandler handler = newCapHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
string cap = Marshal.PtrToStringAnsi(capPtr);
DeviceNewCapabilityArgs args =
new DeviceNewCapabilityArgs();
args.Device = new Device(this, udi);
args.Capability = cap;
handler(this, args);
}
}
}
private void OnHalDeviceLostCapability(IntPtr ctx, IntPtr udiPtr,
IntPtr capPtr)
{
foreach(DeviceLostCapabilityHandler lostCapHandler in
GetEvents(typeof(DeviceLostCapabilityHandler))) {
DeviceLostCapabilityHandler handler = lostCapHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
string cap = Marshal.PtrToStringAnsi(capPtr);
DeviceLostCapabilityArgs args =
new DeviceLostCapabilityArgs();
args.Device = new Device(this, udi);
args.Capability = cap;
handler(this, args);
}
}
}
private void OnHalDevicePropertyModified(IntPtr ctx, IntPtr udiPtr,
IntPtr keyPtr, bool isRemoved, bool isAdded)
{
foreach(DevicePropertyModifiedHandler propModHandler in
GetEvents(typeof(DevicePropertyModifiedHandler))) {
DevicePropertyModifiedHandler handler = propModHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
string key = Marshal.PtrToStringAnsi(keyPtr);
DevicePropertyModifiedArgs args =
new DevicePropertyModifiedArgs();
args.Device = new Device(this, udi);
args.Key = key;
args.IsRemoved = isRemoved;
args.IsAdded = isAdded;
handler(this, args);
}
}
}
private void OnHalDeviceCondition(IntPtr ctx, IntPtr udiPtr,
IntPtr namePtr, IntPtr detailsPtr)
{
foreach(DeviceConditionHandler condHandler in
GetEvents(typeof(DeviceConditionHandler))) {
DeviceConditionHandler handler = condHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
string name = Marshal.PtrToStringAnsi(namePtr);
string details = Marshal.PtrToStringAnsi(detailsPtr);
DeviceConditionArgs args = new DeviceConditionArgs();
args.Device = new Device(this, udi);
args.ConditionName = name;
args.ConditionDetails = details;
handler(this, args);
}
}
}
}
private bool ContextFree()
{
if(ctx_handle.Handle == IntPtr.Zero)
return false;
return Unmanaged.libhal_ctx_free(ctx_handle);
}
public void IntegrateMainLoop()
{
// would be nice to let user specify an optional GMainContext
Unmanaged.dbus_connection_setup_with_g_main(dbus_conn, Unmanaged.g_main_context_default());
mainLoopIntegrated = true;
}
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;
}
}
// Events
private Hashtable EventTable = new Hashtable();
private bool AddEvent(Type evType, object ev)
{
if(EventTable[evType] == null) {
EventTable[evType] = new ArrayList();
}
(EventTable[evType] as ArrayList).Add(ev);
if(!mainLoopIntegrated) {
IntegrateMainLoop();
}
return (EventTable[evType] as ArrayList).Count == 1;
}
private void RemoveEvent(Type evType, object ev)
{
if(EventTable[evType] == null) {
return;
}
(EventTable[evType] as ArrayList).Remove(ev);
}
private ArrayList GetEvents(Type evType)
{
if(EventTable[evType] == null) {
return null;
}
return EventTable[evType] as ArrayList;
}
public event DeviceAddedHandler DeviceAdded
{
add {
if(AddEvent(typeof(DeviceAddedHandler), value)) {
Unmanaged.libhal_ctx_set_device_added(ctx_handle,
new DeviceAddedCallback(OnHalDeviceAdded));
}
}
remove {
RemoveEvent(typeof(DeviceAddedHandler), value);
}
}
public event DeviceRemovedHandler DeviceRemoved
{
add {
if(AddEvent(typeof(DeviceRemovedHandler), value)) {
Unmanaged.libhal_ctx_set_device_removed(ctx_handle,
new DeviceRemovedCallback(OnHalDeviceRemoved));
}
}
remove {
RemoveEvent(typeof(DeviceRemovedHandler), value);
}
}
public event DeviceNewCapabilityHandler DeviceNewCapability
{
add {
if(AddEvent(typeof(DeviceNewCapabilityHandler), value)) {
Unmanaged.libhal_ctx_set_device_new_capability(ctx_handle,
new DeviceNewCapabilityCallback(OnHalDeviceNewCapability));
}
}
remove {
RemoveEvent(typeof(DeviceNewCapabilityHandler), value);
}
}
public event DeviceLostCapabilityHandler DeviceLostCapability
{
add {
if(AddEvent(typeof(DeviceLostCapabilityHandler), value)) {
Unmanaged.libhal_ctx_set_device_lost_capability(ctx_handle,
new DeviceLostCapabilityCallback(OnHalDeviceLostCapability));
}
}
remove {
RemoveEvent(typeof(DeviceLostCapabilityHandler), value);
}
}
public event DevicePropertyModifiedHandler DevicePropertyModified
{
add {
if(AddEvent(typeof(DevicePropertyModifiedHandler), value)) {
Unmanaged.libhal_ctx_set_device_property_modified(
ctx_handle, new DevicePropertyModifiedCallback(OnHalDevicePropertyModified));
}
}
remove {
RemoveEvent(typeof(DevicePropertyModifiedHandler), value);
}
}
public event DeviceConditionHandler DeviceCondition
{
add {
if(AddEvent(typeof(DeviceConditionHandler), value)) {
Unmanaged.libhal_ctx_set_device_condition(ctx_handle,
new DeviceConditionCallback(OnHalDeviceCondition));
}
}
remove {
RemoveEvent(typeof(DeviceConditionHandler), value);
}
}
private void OnHalDeviceAdded(IntPtr ctx, IntPtr udiPtr)
{
foreach(DeviceAddedHandler addedHandler in GetEvents(typeof(DeviceAddedHandler))) {
DeviceAddedHandler handler = addedHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
DeviceAddedArgs args = new DeviceAddedArgs();
args.Device = new Device(this, udi);
handler(this, args);
}
}
}
private void OnHalDeviceRemoved(IntPtr ctx, IntPtr udiPtr)
{
foreach(DeviceRemovedHandler removedHandler in GetEvents(typeof(DeviceRemovedHandler))) {
DeviceRemovedHandler handler = removedHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
DeviceRemovedArgs args = new DeviceRemovedArgs();
args.Device = new Device(this, udi);
handler(this, args);
}
}
}
private void OnHalDeviceNewCapability(IntPtr ctx, IntPtr udiPtr,
IntPtr capPtr)
{
foreach(DeviceNewCapabilityHandler newCapHandler in GetEvents(typeof(DeviceNewCapabilityHandler))) {
DeviceNewCapabilityHandler handler = newCapHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
string cap = Marshal.PtrToStringAnsi(capPtr);
DeviceNewCapabilityArgs args =
new DeviceNewCapabilityArgs();
args.Device = new Device(this, udi);
args.Capability = cap;
handler(this, args);
}
}
}
private void OnHalDeviceLostCapability(IntPtr ctx, IntPtr udiPtr,
IntPtr capPtr)
{
foreach(DeviceLostCapabilityHandler lostCapHandler in GetEvents(typeof(DeviceLostCapabilityHandler))) {
DeviceLostCapabilityHandler handler = lostCapHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
string cap = Marshal.PtrToStringAnsi(capPtr);
DeviceLostCapabilityArgs args =
new DeviceLostCapabilityArgs();
args.Device = new Device(this, udi);
args.Capability = cap;
handler(this, args);
}
}
}
private void OnHalDevicePropertyModified(IntPtr ctx, IntPtr udiPtr,
IntPtr keyPtr, bool isRemoved, bool isAdded)
{
foreach(DevicePropertyModifiedHandler propModHandler in GetEvents(typeof(DevicePropertyModifiedHandler))) {
DevicePropertyModifiedHandler handler = propModHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
string key = Marshal.PtrToStringAnsi(keyPtr);
DevicePropertyModifiedArgs args =
new DevicePropertyModifiedArgs();
args.Device = new Device(this, udi);
args.Key = key;
args.IsRemoved = isRemoved;
args.IsAdded = isAdded;
handler(this, args);
}
}
}
private void OnHalDeviceCondition(IntPtr ctx, IntPtr udiPtr,
IntPtr namePtr, IntPtr detailsPtr)
{
foreach(DeviceConditionHandler condHandler in GetEvents(typeof(DeviceConditionHandler))) {
DeviceConditionHandler handler = condHandler;
if(handler != null) {
string udi = Marshal.PtrToStringAnsi(udiPtr);
string name = Marshal.PtrToStringAnsi(namePtr);
string details = Marshal.PtrToStringAnsi(detailsPtr);
DeviceConditionArgs args = new DeviceConditionArgs();
args.Device = new Device(this, udi);
args.ConditionName = name;
args.ConditionDetails = details;
handler(this, args);
}
}
}
}
}

Просмотреть файл

@ -28,19 +28,19 @@
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'))
};
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'))
};
}

Просмотреть файл

@ -32,303 +32,279 @@ 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 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 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;
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);
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);
}
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 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 string Udi
{
get {
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 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 string Udi {
get {
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));
}
}
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));
}
}
}

Просмотреть файл

@ -30,11 +30,11 @@ using System;
namespace Hal
{
public class HalException : ApplicationException
{
public HalException(string message) : base(message)
{
public class HalException : ApplicationException
{
public HalException(string message) : base(message)
{
}
}
}
}
}

Просмотреть файл

@ -28,127 +28,13 @@
using System;
using Hal;
using Gtk;
using System.Collections;
public class Entry
{
public static void Main()
{
Application.Init();
new CdromTest();
//new GtkTest();
Application.Run();
/* Context ctx = new Context(); */
/*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);*/
}
}
public class CdromTest
{
private Context ctx;
private ArrayList disks = new ArrayList();
public CdromTest()
{
ctx = new Context();
ctx.DeviceAdded += OnDeviceAdded;
ctx.DeviceRemoved += OnDeviceRemoved;
}
private void OnDeviceAdded(object o, DeviceAddedArgs args)
{
Device parentDevice = new Device(ctx, args.Device["info.parent"]);
if(parentDevice["storage.drive_type"].Equals("cdrom")) {
Console.WriteLine("Found drive with disk: {0} ({1})",
parentDevice,
parentDevice["storage.model"]);
}
}
private void OnDeviceRemoved(object o, DeviceRemovedArgs args)
{
if(disks.IndexOf(args.Device.Udi) >= 0) {
Console.WriteLine("Disk removed: {0}", args.Device);
disks.Remove(args.Device.Udi);
}
}
}
public class GtkTest
{
private Window win;
private Context ctx;
public GtkTest()
{
ctx = new Context();
ctx.DeviceAdded += OnHalDeviceAdded;
ctx.DeviceRemoved += OnHalDeviceRemoved;
ctx.DeviceCondition += OnHalDeviceCondition;
ctx.DeviceLostCapability += OnHalDeviceLostCapability;
ctx.DeviceNewCapability += OnHalDeviceNewCapability;
ctx.DevicePropertyModified += OnHalDevicePropertyModified;
win = new Window("HAL Event Loop Test");
win.DeleteEvent += OnWindowDeleteEvent;
win.ShowAll();
}
public void OnHalDeviceAdded(object o, DeviceAddedArgs args)
{
Console.WriteLine("Device Added: " + args.Device);
args.Device.WatchProperties = true;
}
public void OnHalDeviceRemoved(object o, DeviceRemovedArgs args)
{
Console.WriteLine("Device Removed: " + args.Device);
}
public void OnHalDeviceCondition(object o, DeviceConditionArgs args)
{
Console.WriteLine("Device Condition: " + args.Device);
}
public void OnHalDeviceLostCapability(object o,
DeviceLostCapabilityArgs args)
{
Console.WriteLine("Device Lost Capability: " + args.Device);
}
public void OnHalDeviceNewCapability(object o,
DeviceNewCapabilityArgs args)
{
Console.WriteLine("Device New Capability: " + args.Device);
}
public void OnHalDevicePropertyModified(object o,
DevicePropertyModifiedArgs args)
{
Console.WriteLine("Device Property Modified: " + args.Device +
", Key: " + args.Key + ", Is Removed: " + args.IsRemoved +
", Is Added: " + args.IsAdded);
}
public void OnWindowDeleteEvent(object o, EventArgs args)
{
Application.Quit();
}
public static void Main()
{
Context ctx = new Context();
ctx.Dispose();
}
}

Просмотреть файл

@ -31,234 +31,249 @@ using System.Runtime.InteropServices;
namespace Hal
{
internal sealed class Unmanaged
{
// Context Functions
[DllImport("libhal")]
public static extern IntPtr libhal_ctx_new();
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 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_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_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_shutdown(HandleRef ctx,
IntPtr error);
[DllImport("libhal")]
public static extern bool libhal_ctx_free(HandleRef ctx);
[DllImport("libhal")]
public static extern bool libhal_ctx_free(HandleRef ctx);
// Callback Set Functions
// Callback Set Functions
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_added(HandleRef ctx,
DeviceAddedCallback cb);
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_added(HandleRef ctx,
DeviceAddedCallback cb);
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_removed(HandleRef ctx,
DeviceRemovedCallback cb);
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_new_capability(
HandleRef ctx, DeviceNewCapabilityCallback cb);
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_removed(HandleRef ctx,
DeviceRemovedCallback cb);
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_new_capability(
HandleRef ctx, DeviceNewCapabilityCallback cb);
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_lost_capability(
HandleRef ctx, DeviceLostCapabilityCallback cb);
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_property_modified(
HandleRef ctx, DevicePropertyModifiedCallback cb);
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_condition(
HandleRef ctx, DeviceConditionCallback cb);
// String Functions
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_lost_capability(
HandleRef ctx, DeviceLostCapabilityCallback cb);
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_property_modified(
HandleRef ctx, DevicePropertyModifiedCallback cb);
[DllImport("libhal")]
public static extern bool libhal_ctx_set_device_condition(
HandleRef ctx, DeviceConditionCallback cb);
// String Functions
[DllImport("libhal")]
public static extern void libhal_free_string_array(IntPtr array);
[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 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_exists(HandleRef ctx,
string udi, IntPtr error);
[DllImport("libhal")]
public static extern bool libhal_device_print(HandleRef ctx, string udi,
IntPtr error);
[DllImport("libhal")]
public static extern bool libhal_device_print(HandleRef ctx, string udi,
IntPtr error);
// Property Get Functions
// 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 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 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 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);
[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);
// 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_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_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);
[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);
// 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);
[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);
[DllImport("libdbus-glib-1")]
public static extern void dbus_connection_setup_with_g_main(
IntPtr dbus_connection, IntPtr g_main_context);
// ughhh
[DllImport("libglib-2.0.so")]
public static extern IntPtr g_main_context_default();
}
// 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);
[DllImport("libdbus-glib-1")]
public static extern void dbus_connection_setup_with_g_main(
IntPtr dbus_connection, IntPtr g_main_context);
[DllImport("libdbus-glib-1")]
public static extern void dbus_g_thread_init();
// ughhh
[DllImport("libglib-2.0.so")]
public static extern IntPtr g_main_context_default();
[DllImport("libglib-2.0.so")]
public static extern IntPtr g_main_context_new();
[DllImport("libgobject-2.0.so")]
public static extern void g_type_init();
[DllImport("libglib-2.0.so")]
public static extern void g_main_context_iteration(IntPtr ctx,
bool mayblock);
[DllImport("libglib-2.0.so")]
public static extern bool g_main_context_pending(IntPtr ctx);
}
}

Просмотреть файл

@ -1,8 +1,9 @@
MCS_FLAGS=-debug
halsharpdir=$(pkglibdir)
halsharp_SCRIPTS = hal-sharp.dll
EXTRA_DIST = $(halsharp_sources) HalTest.cs
CLEANFILES = hal-sharp.dll AssemblyInfo.cs
DISTCLEANFILES = Makefile.in *.exe *.mdb
CLEANFILES = hal-sharp.dll hal-sharp.exe
DISTCLEANFILES = Makefile.in *.mdb AssemblyInfo.cs
halsharp_sources = \
HalContext.cs \
@ -15,6 +16,14 @@ halsharp_sources = \
halsharp_build_sources = $(addprefix $(srcdir)/, $(halsharp_sources))
hal-sharp.dll:
$(MCS) -target:library -out:$@ -r:Mono.Posix $(halsharp_build_sources)
all: hal-sharp.dll hal-sharp.exe
hal-sharp.dll:
$(MCS) $(MCS_FLAGS) -target:library -out:$@ -r:Mono.Posix $(halsharp_build_sources)
hal-sharp.exe:
$(MCS) $(MCS_FLAGS) -r:hal-sharp.dll -out:$@ HalTest.cs
run:
mono hal-sharp.exe