package libudev

  1. Overview
  2. Docs

Device monitoring.

type t

A Monitor.t monitor listens for changes to the device list. A monitor is created by connecting to the kernel daemon through netlink (see Monitor.create).

type filter =
  1. | Tag of string
    (*

    Tag tag matches devices which have the tag tag attached.

    *)
  2. | Subsystem_devtype of string * string option
    (*

    Subsystem_devtype (subsystem, devtype) matches devices of subsystem, with optionally device type devtype.

    *)

Once the monitor is created, the devices that it listens to can be filtered using Monitor.set_filter, specifying a list of filter values.

Netlink source from which to listen to. See Monitor.create.

val create : ?source:netlink_source -> Context.t -> t

Create a monitor by connecting to the kernel daemon through netlink.

By default, source is Udev: the monitor listens to the events emitted after udev has registered and configured the device. This is the absolutely recommended source for applications.

A source of Kernel means that the monitor receives the events directly after the kernel has seen the device. The device has not yet been configured by udev and might not be usable at all. Do not use this, unless you know what you are doing.

Filtering & listening for devices

val set_filter : t -> filter list -> unit

Filter the devices that are listened by a monitor.

val start : t -> unit

Start a monitor. A monitor m will not receive events until Monitor.start m is called. This function does nothing if called on an already started monitor.

exception Timeout

See Monitor.receive_device.

val receive_device : ?timeout:float -> t -> Device.t

Poll for a device event. Monitor.receive_device ~timeout m will block until a device event is received, or after timeout seconds, in which case the Timeout exception is raised.

If no timeout value is specified, the function blocks until a device event is available. A timeout of 0. means that the function just polls and will never block.

Utilities

val context : t -> Context.t

The context to which a monitor is bound.

val set_receive_buffer_size : t -> int -> unit

Set the receive buffer size, in bytes.

val fd : t -> Unix.file_descr

Return the file descriptor associated with the monitor.