8 #ifndef META_OCEAN_SYSTEM_USB_DEVICE_H
9 #define META_OCEAN_SYSTEM_USB_DEVICE_H
62 using UsageMap = std::unordered_map<int, unsigned int>;
201 inline libusb_device* usbDevice();
208 inline libusb_device_handle* usbDeviceHandle();
229 inline bool isValid()
const;
237 inline bool isOpen()
const;
243 inline bool isWrapped()
const;
250 inline libusb_class_code classCode()
const;
265 static std::string
stringDescriptor(libusb_device_handle* usbDeviceHandle,
const uint8_t index);
324 static int determineIsochronousTransferLayout(libusb_context* usbContext,
const libusb_interface& interface,
const uint8_t endpointAddress,
const uint32_t maxVideoFrameSize,
const uint32_t maxPayloadTransferSize,
size_t& transferSize,
size_t& packetsPerTransfer,
size_t& bytesPerPacket);
332 int64_t systemDeviceHandle_ = 0;
335 libusb_device* usbDevice_ =
nullptr;
338 libusb_device_handle* usbDeviceHandle_ =
nullptr;
341 libusb_device_descriptor usbDeviceDescriptor_ = {};
355 *
this = std::move(device);
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements a scoped lock object for recursive lock objects.
Definition: Lock.h:135
This class implements a subscription object which can be used unique subscriptions to e....
Definition: ScopedSubscription.h:28
This class wraps a libusb device.
Definition: system/usb/Device.h:49
SharedContext context() const
The context which is associated with this device.
Definition: system/usb/Device.h:372
Device & operator=(Device &&device)
Move operator.
bool isValid() const
Returns whether this device is valid.
Definition: system/usb/Device.h:377
int64_t systemDeviceHandle_
Optional system device handle in case this object is wrapped (e.g., on Android platforms).
Definition: system/usb/Device.h:332
void releaseInterface(const int interfaceIndex)
Releases a claimed interface.
Device & operator=(const Device &)=delete
Disabled copy operator.
SharedContext context_
The context which is associated with this device, nullptr if the default context is used.
Definition: system/usb/Device.h:329
UsageMap detachedInterfaceUsageMap_
The usage counter for detached kernel drivers.
Definition: system/usb/Device.h:344
uint16_t vendorId() const
Returns the vendor id of the device.
std::string serialNumber() const
Returns the serial number of this device.
Device(const Device &)=delete
Disabled copy constructor.
static std::string stringDescriptor(libusb_device_handle *usbDeviceHandle, const uint8_t index)
Returns a string descriptor of an opened device.
Device(SharedContext context, const int64_t systemDeviceHandle)
Creates a new device object (for an already opened device) based on a given system handle.
bool isOpen() const
Returns whether this device is open.
Definition: system/usb/Device.h:384
std::string manufacturerName() const
Returns the manufacturer name of this device.
std::string productName() const
Returns the product name of the device.
std::string name() const
Returns the name of the device (not the product name).
static bool extractPayload(struct libusb_transfer &usbTransfer, BufferPointers &bufferPointers)
Extracts the payload buffers from a given USB transfer object.
static int determineIsochronousTransferLayout(libusb_context *usbContext, const libusb_interface &interface, const uint8_t endpointAddress, const uint32_t maxVideoFrameSize, const uint32_t maxPayloadTransferSize, size_t &transferSize, size_t &packetsPerTransfer, size_t &bytesPerPacket)
Determines the layout of an isochronous transfer.
void reattachKernelDriver(const int interfaceIndex)
Re-attaches a detached kernel driver for a specified interface.
ScopedSubscription claimInterface(const int interfaceIndex)
Claims an interface of the device.
bool isWrapped() const
Returns whether this device is wrapping a device based on a given system device handle.
Definition: system/usb/Device.h:391
std::unordered_map< int, unsigned int > UsageMap
Definition of an unordered map mapping interface indices to usages.
Definition: system/usb/Device.h:62
ScopedSubscription detachKernelDriver(const int interfaceIndex, bool *driverWasNotActive=nullptr)
Detaches the kernel driver for the device.
std::pair< const void *, size_t > BufferPointer
Definition of a pair combining a pointer to a buffer and the size of this buffer.
Definition: system/usb/Device.h:67
libusb_device * usbDevice_
The actual libusb device.
Definition: system/usb/Device.h:335
UsageMap claimedInterfaceUsageMap_
The usage counter for claimed interfaces.
Definition: system/usb/Device.h:347
libusb_device_handle * usbDeviceHandle()
Returns the handle to the wrapped libusb device.
Definition: system/usb/Device.h:365
virtual ~Device()
Destructs the device and releases all resources.
Device()=default
Default constructor creating an invalid device.
bool close()
Closes an opened device.
Lock lock_
The device's lock.
Definition: system/usb/Device.h:350
Device(SharedContext context, libusb_device *usbDevice, libusb_device_handle *usbDeviceHandle)
Creates a new device object based on a given (already opened) libusb device and its device handle.
libusb_class_code classCode() const
Returns the class code of this device.
Definition: system/usb/Device.h:400
Device(SharedContext context, libusb_device_handle *usbDeviceHandle)
Creates a new device object based on a given libusb device handle (which means that the devices is al...
libusb_device_handle * usbDeviceHandle_
The handle to the opened libusb device.
Definition: system/usb/Device.h:338
void release()
Explicitly releases the device.
Device(SharedContext context, libusb_device *usbDevice)
Creates a new device object based on a given (not yet opened) libusb device.
libusb_device_descriptor usbDeviceDescriptor_
The device descriptor of this device.
Definition: system/usb/Device.h:341
std::vector< BufferPointer > BufferPointers
Definition of a vector holding buffer pointers.
Definition: system/usb/Device.h:72
bool initialize(SharedContext context, libusb_device *usbDevice, libusb_device_handle *usbDeviceHandle)
Initializes this device with a given opened libusb device.
libusb_device * usbDevice()
Returns the wrapped libusb device.
Definition: system/usb/Device.h:358
uint16_t productId() const
Returns the product id of the device.
bool open()
Opens the device.
std::shared_ptr< Device > SharedDevice
Definition of a shared pointer holding a device.
Definition: system/usb/Device.h:34
std::vector< SharedDevice > SharedDevices
Definition of a vector holding SharedDevice objects.
Definition: system/usb/Device.h:41
std::shared_ptr< Context > SharedContext
Definition of a shared pointer holding a context.
Definition: system/usb/Context.h:32
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15