Implement open() and close() for Usb class, added a lot of TODO's

This commit is contained in:
2022-11-13 21:28:28 +01:00
parent f09e4ab5c8
commit 38906dafef
11 changed files with 103 additions and 30 deletions

View File

@@ -7,6 +7,8 @@ namespace ptprnt::driver {
struct info {
std::string name{""};
std::string version{""};
uint32_t busNo{0};
uint32_t flags{0};
};
} // namespace ptprnt::driver

View File

@@ -12,6 +12,8 @@ class IUsb {
virtual ~IUsb() = default;
virtual std::optional<std::vector<UsbDevice>> getDevices() = 0;
virtual std::optional<UsbDevice> open(UsbDevice) = 0;
virtual bool close(UsbDevice) = 0;
};
} // namespace ptprnt::driver

View File

@@ -23,6 +23,7 @@ class P700Driver : public IDriver {
private:
std::shared_ptr<Usb> mUsbDriver{0};
UsbDevice mUsbDev{0};
driver::info mInfo{};
bool init();
};

View File

@@ -10,7 +10,7 @@ namespace ptprnt::printer {
class P700Printer : public IPrinter {
public:
P700Printer(std::unique_ptr<driver::P700Driver> driver);
P700Printer(std::shared_ptr<driver::P700Driver> driver);
~P700Printer() override;
printer::info getInfo() override;
@@ -19,7 +19,7 @@ class P700Printer : public IPrinter {
private:
static info mPrinterInfo;
std::unique_ptr<driver::P700Driver> mDriver;
std::shared_ptr<driver::P700Driver> mDriver;
};
} // namespace ptprnt::printer

View File

@@ -1,8 +1,6 @@
#include "IUsb.hpp"
#include "UsbTypes.hpp"
#include <libusb-1.0/libusb.h>
#pragma once
namespace ptprnt::driver {
@@ -13,9 +11,12 @@ class Usb : public IUsb {
~Usb() override;
std::optional<std::vector<UsbDevice>> getDevices() override;
std::optional<UsbDevice> open(UsbDevice) override;
bool close(UsbDevice) override;
private:
// TODO: This should be a std::map with handles & locking on access
std::vector<UsbDevice> mDevices{};
};
} // namespace ptprnt::driver
} // namespace ptprnt::driver

View File

@@ -8,7 +8,7 @@ namespace ptprnt::driver {
struct UsbDevice {
uint16_t vendorId{0};
uint16_t productId{0};
libusb_device* dev{nullptr};
libusb_device* device{nullptr};
libusb_device_handle* hndl{nullptr};
};