/* ptrnt - print labels on linux Copyright (C) 2023 Moritz Martinius This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #pragma once #include #include #include "libusb.h" #include "libusbwrap/LibUsbTypes.hpp" #include "libusbwrap/interface/IUsbDevice.hpp" namespace libusbwrap { class UsbDevice : public IUsbDevice { public: UsbDevice(libusb_context* ctx, libusb_device* dev); ~UsbDevice(); // delete copy ctor and assignment UsbDevice(const UsbDevice&) = delete; UsbDevice& operator=(UsbDevice&) = delete; bool open() override; void close() override; // libusb wrappers bool detachKernelDriver(int interfaceNo) override; bool claimInterface(int interfaceNo) override; bool releaseInterface(int interfaceNo) override; bool bulkTransfer(uint8_t endpoint, std::vector& data, int* tx, unsigned int timeout) override; // getters const uint16_t getVid() override; const uint16_t getPid() override; const device::Speed getSpeed() override; const uint8_t getBusNumber() override; const uint8_t getPortNumber() override; // errors const Error getLastError() override; const std::string getLastErrorString() override; private: libusb_context* mLibusbCtx{nullptr}; libusb_device* mLibusbDev{nullptr}; libusb_device_handle* mLibusbDevHandle{nullptr}; libusb_device_descriptor mLibusbDevDesc; std::atomic mIsOpen = false; Error mLastError = Error::SUCCESS; }; } // namespace libusbwrap