GUdevClient

GUdevClient — Query devices and listen to uevents

Synopsis

                    GUdevClient;
struct              GUdevClientClass;
enum                GUdevDeviceType;
typedef             GUdevDeviceNumber;
GUdevClient *       g_udev_client_new                   (const gchar * const *subsystems);
GList *             g_udev_client_query_by_subsystem    (GUdevClient *client,
                                                         const gchar *subsystem);
GUdevDevice *       g_udev_client_query_by_device_number
                                                        (GUdevClient *client,
                                                         GUdevDeviceType type,
                                                         GUdevDeviceNumber number);
GUdevDevice *       g_udev_client_query_by_device_file  (GUdevClient *client,
                                                         const gchar *device_file);
GUdevDevice *       g_udev_client_query_by_sysfs_path   (GUdevClient *client,
                                                         const gchar *sysfs_path);
GUdevDevice *       g_udev_client_query_by_subsystem_and_name
                                                        (GUdevClient *client,
                                                         const gchar *subsystem,
                                                         const gchar *name);

Object Hierarchy

  GObject
   +----GUdevClient
  GEnum
   +----GUdevDeviceType

Properties

  "subsystems"               GStrv                 : Read / Write / Construct Only

Signals

  "uevent"                                         : Run Last

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.

Details

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.

GObjectClass parent_class;

Parent class.

uevent ()

Signal class handler for the "uevent" signal.

enum GUdevDeviceType

typedef enum {
  G_UDEV_DEVICE_TYPE_NONE = 0,
  G_UDEV_DEVICE_TYPE_BLOCK = 'b',
  G_UDEV_DEVICE_TYPE_CHAR = 'c',
} GUdevDeviceType;

Enumeration used to specify a the type of a device.

G_UDEV_DEVICE_TYPE_NONE

Device does not have a device file.

G_UDEV_DEVICE_TYPE_BLOCK

Device is a block device.

G_UDEV_DEVICE_TYPE_CHAR

Device is a character device.

GUdevDeviceNumber

typedef guint64 GUdevDeviceNumber; /* __UQUAD_TYPE */

Corresponds to the standard dev_t type as defined by POSIX (Until bug 584517 is resolved this work-around is needed).


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.

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.

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

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(). [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.

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(). [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.

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(). [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.

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(). [transfer full]

Property Details

The "subsystems" property

  "subsystems"               GStrv                 : Read / Write / Construct Only

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.

Signal Details

The "uevent" signal

void                user_function                      (GUdevClient *client,
                                                        gchar       *action,
                                                        GUdevDevice *device,
                                                        gpointer     user_data)      : Run Last

Emitted when client receives an uevent.

This signal is emitted in the thread-default main loop of the thread that client was created in.

client :

The GUdevClient receiving the event.

action :

The action for the uevent e.g. "add", "remove", "change", "move", etc.

device :

Details about the GUdevDevice the event is for.

user_data :

user data set when the signal handler was connected.