FuDeviceLocker

FuDeviceLocker — a device helper object

Functions

Types and Values

Description

An object that makes it easy to close a device when an object goes out of scope.

See also: FuDevice

Functions

FuDeviceLockerFunc ()

gboolean
(*FuDeviceLockerFunc) (GObject *device,
                       GError **error);

fu_device_locker_new ()

FuDeviceLocker *
fu_device_locker_new (gpointer device,
                      GError **error);

Opens the device for use. When the FuDeviceLocker is deallocated the device will be closed and any error will just be directed to the console. This object is typically called using g_autoptr() but the device can also be manually closed using g_clear_object().

The functions used for opening and closing the device are set automatically. If the device is not a type or supertype of GUsbDevice or FuDevice then this function will not work.

For custom objects please use fu_device_locker_new_full().

NOTE: If the open_func failed then the close_func will not be called.

Think of this object as the device ownership.

Parameters

device

A GObject

 

error

A GError, or NULL

 

Returns

a FuDeviceLocker, or NULL if the open_func failed.

Since: 1.0.0


fu_device_locker_new_full ()

FuDeviceLocker *
fu_device_locker_new_full (gpointer device,
                           FuDeviceLockerFunc open_func,
                           FuDeviceLockerFunc close_func,
                           GError **error);

Opens the device for use. When the FuDeviceLocker is deallocated the device will be closed and any error will just be directed to the console. This object is typically called using g_autoptr() but the device can also be manually closed using g_clear_object().

NOTE: If the open_func failed then the close_func will not be called.

Think of this object as the device ownership.

Parameters

device

A GObject

 

open_func

A function to open the device.

[scope async]

close_func

A function to close the device.

[scope async]

error

A GError, or NULL

 

Returns

a FuDeviceLocker, or NULL if the open_func failed.

Since: 1.0.0


fu_device_locker_close ()

gboolean
fu_device_locker_close (FuDeviceLocker *self,
                        GError **error);

Closes the locker before it gets cleaned up.

This function can be used to manually close a device managed by a locker, and allows the caller to properly handle the error.

Parameters

self

A FuDeviceLocker

 

error

A GError, or NULL

 

Returns

TRUE for success

Since: 1.4.0

Types and Values

FU_TYPE_DEVICE_LOCKER

#define FU_TYPE_DEVICE_LOCKER (fu_device_locker_get_type ())

FuDeviceLocker

typedef struct _FuDeviceLocker FuDeviceLocker;