## GUdevClient GUdevClient — Query devices and listen to uevents |

## Functions

GUdevClient * | g_udev_client_new ()
GList * | g_udev_client_query_by_subsystem ()
GUdevDevice * | g_udev_client_query_by_device_number ()
GUdevDevice * | g_udev_client_query_by_device_file ()
GUdevDevice * | g_udev_client_query_by_sysfs_path ()
GUdevDevice * | g_udev_client_query_by_subsystem_and_name ()

## Properties

GStrv | subsystems | Read / Write / Construct Only

## Signals

void | uevent | Run Last

## Types and Values

| GUdevClient
struct | GUdevClientClass
| GUdevClientPrivate

## Object Hierarchy

        GObject
        ╰── GUdevClient

## Description

GUdevClient is used to query information about devices on a Linux system from the Linux kernel and the udev device manager.

Device information is retrieved from the kernel (through the `sysfs` filesystem) and the udev daemon (through a `tmpfs` filesystem) and presented through GUdevDevice objects. This means that no blocking IO ever happens (in both cases, we are essentially just reading data from kernel memory) and as such there are no asynchronous versions of the provided methods.

To get GUdevDevice objects, use `g_udev_client_query_by_subsystem()`, `g_udev_client_query_by_device_number()`, `g_udev_client_query_by_device_file()`, `g_udev_client_query_by_sysfs_path()`, `g_udev_client_query_by_subsystem_and_name()` or the GUdevEnumerator type.

To listen to uevents, connect to the “uevent” signal.

## Functions

### g_udev_client_new ()

    GUdevClient *
    g_udev_client_new (const gchar * const *subsystems);

Constructs a GUdevClient object that can be used to query information about devices. Connect to the “uevent” signal to listen for uevents. Note that signals are emitted in the

thread-default main loop

of the thread that you call this constructor from.

#### Parameters

subsystems | A `NULL` terminated string array of subsystems to listen for uevents on, `NULL` to not listen on uevents at all, or an empty array to listen to uevents on all subsystems. See the documentation for the “subsystems” property for details on this parameter. | [array zero-terminated=1][element-type utf8][transfer none][allow-none]

#### Returns

A new GUdevClient object. Free with `g_object_unref()`.

### g_udev_client_query_by_subsystem ()

    GList *
    g_udev_client_query_by_subsystem (GUdevClient *client,
                                      const gchar *subsystem);

Gets all devices belonging to `subsystem` .

#### Parameters

client | A GUdevClient. |
subsystem | The subsystem to get devices for or `NULL` to get all devices. | [allow-none]

#### Returns

A list of GUdevDevice objects. The caller should free the result by using `g_object_unref()` on each element in the list and then `g_list_free()` on the list.

[nullable][element-type GUdevDevice][transfer full]

### g_udev_client_query_by_device_number ()

    GUdevDevice *
    g_udev_client_query_by_device_number (GUdevClient *client,
                                          GUdevDeviceType type,
                                          GUdevDeviceNumber number);

Looks up a device for a type and device number.

#### Parameters

client | A GUdevClient. |
type | A value from the GUdevDeviceType enumeration. |
number | A device number. |

#### Returns

A GUdevDevice object or `NULL` if the device was not found. Free with `g_object_unref()`.

[nullable][transfer full]

### g_udev_client_query_by_device_file ()

    GUdevDevice *
    g_udev_client_query_by_device_file (GUdevClient *client,
                                        const gchar *device_file);

Looks up a device for a device file.

#### Parameters

client | A GUdevClient. |
device_file | A device file. |

#### Returns

A GUdevDevice object or `NULL` if the device was not found. Free with `g_object_unref()`.

[nullable][transfer full]

### g_udev_client_query_by_sysfs_path ()

    GUdevDevice *
    g_udev_client_query_by_sysfs_path (GUdevClient *client,
                                       const gchar *sysfs_path);

Looks up a device for a sysfs path.

#### Parameters

client | A GUdevClient. |
sysfs_path | A sysfs path. |

#### Returns

A GUdevDevice object or `NULL` if the device was not found. Free with `g_object_unref()`.

[nullable][transfer full]

### g_udev_client_query_by_subsystem_and_name ()

    GUdevDevice *
    g_udev_client_query_by_subsystem_and_name
                                   (GUdevClient *client,
                                    const gchar *subsystem,
                                    const gchar *name);

Looks up a device for a subsystem and name.

#### Parameters

client | A GUdevClient. |
subsystem | A subsystem name. |
name | The name of the device. |

#### Returns

A GUdevDevice object or `NULL` if the device was not found. Free with `g_object_unref()`.

[nullable][transfer full]

## Types and Values

### GUdevClient

    typedef struct _GUdevClient GUdevClient;

The GUdevClient struct is opaque and should not be accessed directly.

### struct GUdevClientClass

    struct GUdevClientClass {
      GObjectClass   parent_class;

      /* signals */
      void (*uevent) (GUdevClient  *client,
                      const gchar  *action,
                      GUdevDevice  *device);
    };

Class structure for GUdevClient.

#### Members

`uevent` () | Signal class handler for the “uevent” signal. |

### GUdevClientPrivate

    typedef struct _GUdevClientPrivate GUdevClientPrivate;

## Property Details

### The `“subsystems”` property

      “subsystems”               GStrv

The subsystems to listen for uevents on.

To listen for only a specific DEVTYPE for a given SUBSYSTEM, use "subsystem/devtype". For example, to only listen for uevents where SUBSYSTEM is usb and DEVTYPE is usb_interface, use "usb/usb_interface".

If this property is `NULL`, then no events will be reported. If it's the empty array, events from all subsystems will be reported.

Owner: GUdevClient

Flags: Read / Write / Construct Only

## Signal Details

### The `“uevent”` signal

    void
    user_function (GUdevClient *client,
                   char        *action,
                   GUdevDevice *device,
                   gpointer     user_data)

Emitted when `client` receives an uevent.

Note that while you'll have access to all the device's properties and attributes for the majority of actions, only the sysfs path will be available when the device is removed.

Also note that the action is an arbitrary string, controlled by device drivers. Other values than those listed is possible, but unlikely.

This signal is emitted in the

thread-default main loop

of the thread that `client` was created in.

#### Parameters

client | The GUdevClient receiving the event. |
action | The action for the uevent e.g. "add", "remove", "change", "move", "online" or "offline" |
device | Details about the GUdevDevice the event is for. |
user_data | user data set when the signal handler was connected. |

Flags: Run Last