libcamera
v0.4.0
Supporting cameras in Linux since 2019
|
unique_ptr-like wrapper for a file descriptor More...
Public Member Functions | |
UniqueFD () | |
Construct a UniqueFD that owns no file descriptor. | |
UniqueFD (int fd) | |
Construct a UniqueFD that owns fd. More... | |
UniqueFD (UniqueFD &&other) | |
Move constructor, create a UniqueFD by taking over other. More... | |
~UniqueFD () | |
Destroy the UniqueFD instance. More... | |
UniqueFD & | operator= (UniqueFD &&other) |
Move assignment operator, replace a UniqueFD by taking over other. More... | |
__nodiscard int | release () |
Release ownership of the file descriptor without closing it. More... | |
void | reset (int fd=-1) |
Replace the managed file descriptor. More... | |
void | swap (UniqueFD &other) |
Swap the managed file descriptors with another UniqueFD. More... | |
int | get () const |
Retrieve the managed file descriptor. More... | |
bool | isValid () const |
Check if the UniqueFD owns a valid file descriptor. More... | |
unique_ptr-like wrapper for a file descriptor
The UniqueFD is a wrapper that owns and manages the lifetime of a file descriptor. It is constructed from a numerical file descriptor, and takes over its ownership. The file descriptor is closed when the UniqueFD is destroyed, or when it is assigned another file descriptor with operator=() or reset().
|
inlineexplicit |
Construct a UniqueFD that owns fd.
[in] | fd | A file descriptor to manage |
|
inline |
|
inline |
Destroy the UniqueFD instance.
If a file descriptor is owned, it is closed.
|
inline |
Retrieve the managed file descriptor.
|
inline |
|
inline |
Move assignment operator, replace a UniqueFD by taking over other.
[in] | other | The other UniqueFD |
If this UniqueFD owns a file descriptor, the file descriptor is closed first. The file descriptor is then replaced by the one of other. Upon return, other is invalid.
|
inline |
Release ownership of the file descriptor without closing it.
This function releases and returns the owned file descriptor without closing it. The caller owns the returned value and must take care of handling its life time to avoid file descriptor leakages. Upon return this UniqueFD is invalid.
void libcamera::UniqueFD::reset | ( | int | fd = -1 | ) |
Replace the managed file descriptor.
[in] | fd | The new file descriptor to manage |
Close the managed file descriptor, if any, and replace it with the new fd.
Self-resetting (passing an fd already managed by this instance) is invalid and results in undefined behaviour.
|
inline |