61 lines
2.3 KiB
C++
61 lines
2.3 KiB
C++
/*
|
|
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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "libusbwrap/interface/IUsbDeviceFactory.hpp"
|
|
|
|
namespace libusbwrap {
|
|
class UsbDeviceFactory : public IUsbDeviceFactory {
|
|
public:
|
|
UsbDeviceFactory();
|
|
~UsbDeviceFactory();
|
|
|
|
// delete copy ctor and assignment
|
|
UsbDeviceFactory(const UsbDeviceFactory&) = delete;
|
|
UsbDeviceFactory& operator=(UsbDeviceFactory&) = delete;
|
|
|
|
bool init();
|
|
/**
|
|
* @brief Gets all devices that are detected by libusb. Will allocate a shared_ptr for each Device
|
|
*
|
|
* @return std::vector<std::shared_ptr<IUsbDevice>> Vector of all detected USB devices
|
|
*/
|
|
std::vector<std::shared_ptr<IUsbDevice>> findAllDevices() override;
|
|
/**
|
|
* @brief Gets all devices with certain vid/pid combination.
|
|
* If only one device of certain type is connected, vector is usually only one element
|
|
*
|
|
* @param vid VendorId of the devices to find
|
|
* @param pid ProductId of the devices to find
|
|
* @return std::vector<std::shared_ptr<IUsbDevice>> Vector of detected USB devices based on vid/pid
|
|
*/
|
|
std::vector<std::shared_ptr<IUsbDevice>> findDevices(uint16_t vid, uint16_t pid) override;
|
|
|
|
private:
|
|
// methods
|
|
int refreshDeviceList();
|
|
std::vector<std::shared_ptr<IUsbDevice>> buildMaskedDeviceVector(uint16_t vidMask,
|
|
uint16_t pidMask, uint16_t vid,
|
|
uint16_t pid);
|
|
// members
|
|
libusb_context* mLibusbCtx{nullptr};
|
|
libusb_device** mLibusbDeviceList;
|
|
};
|
|
} // namespace libusbwrap
|