#include "ehs/io/Usb_LNX.h" #include #include namespace ehs { Usb::~Usb() { } Usb::Usb() : hdl(-1) { } Usb::Usb(const UInt_32 bus, const UInt_32 address) : UsbBase(bus, address), hdl(-1) { Initialize(); } Usb::Usb(Usb&& usb) noexcept : UsbBase((UsbBase&&)usb), hdl(usb.hdl) { usb.hdl = -1; } Usb::Usb(const Usb& usb) : UsbBase(usb), hdl(-1) { Initialize(); } Usb& Usb::operator=(Usb&& usb) noexcept { if (this == &usb) return *this; UsbBase::operator=((UsbBase&&)usb); hdl = usb.hdl; usb.hdl = -1; return *this; } Usb& Usb::operator=(const Usb& usb) { if (this == &usb) return *this; UsbBase::operator=(usb); hdl = -1; Initialize(); return *this; } void Usb::Initialize() { if (!IsValid()) { EHS_LOG_INT(LogType::ERR, 0, "Cannot initialize with an invalid object."); return; } if (IsInitialized()) { EHS_LOG_INT(LogType::WARN, 1, "Object is already initialized."); return; } hdl = open("/dev/bus/usb/" + Str_8::FromNum(GetBus()) + "/" + Str_8::FromNum(GetAddress()), O_RDWR); if (hdl == -1) EHS_LOG_INT(LogType::ERR, 2, "Failed to connect to USB device."); } void Usb::Release() { if (!IsValid()) { EHS_LOG_INT(LogType::ERR, 0, "Cannot release with an invalid object."); return; } if (!IsInitialized()) { EHS_LOG_INT(LogType::WARN, 1, "Object is already released."); return; } close(hdl); hdl = -1; } bool Usb::IsInitialized() const { return hdl != -1; } }