co_usb
Loading...
Searching...
No Matches
co_usb::device_ref Struct Reference

Wrapper for nullable libusb_device that increments ref count on ctor and decrements on dtor. More...

#include <device_ref.hpp>

Public Member Functions

 device_ref () noexcept
 constructs a null ref
 
 device_ref (libusb_device *dev) noexcept
 constructs a new ref object and increments ref count of underlying device
 
 ~device_ref () noexcept
 
 device_ref (device_ref const &other) noexcept
 
device_refoperator= (device_ref const &other) noexcept
 
auto valid () const noexcept -> bool
 Checks if a device reference is valid.
 
auto get () const noexcept -> libusb_device *
 
auto release () noexcept -> libusb_device *
 Releases the device from a ref.
 

Detailed Description

Wrapper for nullable libusb_device that increments ref count on ctor and decrements on dtor.

Objects of this type must be used for returning devices from hotplug callbacks since normally devices obtained through this callback will expire unless their ref count was incremented.

Constructor & Destructor Documentation

◆ device_ref() [1/3]

co_usb::device_ref::device_ref ( )
inlinenoexcept

constructs a null ref

◆ device_ref() [2/3]

co_usb::device_ref::device_ref ( libusb_device *  dev)
inlineexplicitnoexcept

constructs a new ref object and increments ref count of underlying device

◆ ~device_ref()

co_usb::device_ref::~device_ref ( )
inlinenoexcept

◆ device_ref() [3/3]

co_usb::device_ref::device_ref ( device_ref const &  other)
inlinenoexcept

Member Function Documentation

◆ get()

auto co_usb::device_ref::get ( ) const -> libusb_device *
inlinenoexcept
Returns
underlying pointer to libusb_device

◆ operator=()

device_ref & co_usb::device_ref::operator= ( device_ref const &  other)
inlinenoexcept

◆ release()

auto co_usb::device_ref::release ( ) -> libusb_device *
inlinenoexcept

Releases the device from a ref.

Note
Does not decrement ref counter on release to maintain device lifetime in ambigious cases.
Returns
underlying pointer to libusb_device

◆ valid()

auto co_usb::device_ref::valid ( ) const -> bool
inlinenoexcept

Checks if a device reference is valid.

Returns
true if reference is valid.

The documentation for this struct was generated from the following file: