Top |
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.
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 loopof the thread that you call this constructor from.
subsystems |
A |
[array zero-terminated=1][element-type utf8][transfer none][allow-none] |
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 |
[allow-none] |
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]
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. |
A GUdevDevice object or NULL
if the device was not found. Free with g_object_unref()
.
[nullable][transfer full]
GUdevDevice * g_udev_client_query_by_device_file (GUdevClient *client
,const gchar *device_file
);
Looks up a device for a device file.
A GUdevDevice object or NULL
if the device was not found. Free with g_object_unref()
.
[nullable][transfer full]
GUdevDevice * g_udev_client_query_by_sysfs_path (GUdevClient *client
,const gchar *sysfs_path
);
Looks up a device for a sysfs path.
A GUdevDevice object or NULL
if the device was not found. Free with g_object_unref()
.
[nullable][transfer full]
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.
A GUdevDevice object or NULL
if the device was not found. Free with g_object_unref()
.
[nullable][transfer full]
typedef struct _GUdevClient GUdevClient;
The GUdevClient struct is opaque and should not be accessed directly.
struct GUdevClientClass { GObjectClass parent_class; /* signals */ void (*uevent) (GUdevClient *client, const gchar *action, GUdevDevice *device); };
Class structure for GUdevClient.
“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
“uevent”
signalvoid 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 loopof 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", "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