haskus-system-0.7.0.0: Haskus system programming framework

Safe HaskellNone
LanguageHaskell2010

Haskus.System.Devices

Contents

Description

Devices management

This module allows the creation of a DeviceManager which:

  • maintains an up-to-date tree of connected devices
  • maintains device index by subsystem type
  • signals when tree changes through STM channels
  • allows query of devices
  • allows device property querying/setting

Internally, it relies on Linux's sysfs and on a socket to receive netlink kernel object events.

Synopsis

Documentation

data Device Source #

Device

Constructors

Device 

Fields

Device manager

data DeviceManager Source #

Device manager

Constructors

DeviceManager 

Fields

initDeviceManager :: Handle -> Handle -> Sys DeviceManager Source #

Init a device manager

deviceMove :: DeviceManager -> DevicePath -> KernelEvent -> Sys () Source #

Move a device

A device can be moved/renamed in the device tree (see kobject_rename in lib/kobject.c in the kernel sources)

deviceLookup :: DeviceManager -> DevicePath -> Sys (Maybe DeviceTree) Source #

Lookup a device by name

Device tree

data DeviceTree Source #

Device tree

It is expected that the device tree will not change much after the initialization phase (except when a device is (dis)connected, etc.), hence it is an immutable data structure. It is much easier to perform tree traversal with a single global lock thereafter.

Constructors

DeviceTree 

Fields

data SubsystemIndex Source #

Per-subsystem events

Constructors

SubsystemIndex 

Fields

Various

getDeviceHandle :: DeviceManager -> Device -> Flow Sys (Handle ': (ErrorCode ': OpenErrors)) Source #

Get a handle on a device

Linux doesn't provide an API to open a device directly from its major and minor numbers. Instead we must create a special device file with mknod in the VFS and open it. This is what this function does. Additionally, we remove the file once it is opened.

getDeviceHandleByName :: DeviceManager -> String -> Flow Sys (Handle ': (ErrorCode ': OpenErrors)) Source #

Get device handle by name (i.e., sysfs path)

releaseDeviceHandle :: Handle -> Sys () Source #

Release a device handle

openDeviceDir :: DeviceManager -> Device -> Flow Sys (Handle ': OpenErrors) Source #

Find device path by number (major, minor)

listDevicesWithClass :: DeviceManager -> String -> Sys [(DevicePath, DeviceTree)] Source #

List devices with the given class

TODO: support dynamic asynchronous device adding/removal

listDeviceClasses :: DeviceManager -> Sys [Text] Source #

List devices classes