diff --git a/include/boo/inputdev/DeviceBase.hpp b/include/boo/inputdev/DeviceBase.hpp index 2e7751e..4de7b5b 100644 --- a/include/boo/inputdev/DeviceBase.hpp +++ b/include/boo/inputdev/DeviceBase.hpp @@ -54,18 +54,18 @@ public: bool sendUSBInterruptTransfer(const uint8_t* data, size_t length); size_t receiveUSBInterruptTransfer(uint8_t* data, size_t length); - inline unsigned getVendorId(); - inline unsigned getProductId(); - inline std::string_view getVendorName(); - inline std::string_view getProductName(); + inline unsigned getVendorId() const; + inline unsigned getProductId() const; + inline std::string_view getVendorName() const; + inline std::string_view getProductName() const; /* High-Level API */ #if _WIN32 #if !WINDOWS_STORE - const PHIDP_PREPARSED_DATA getReportDescriptor(); + PHIDP_PREPARSED_DATA getReportDescriptor() const; #endif #else - std::vector getReportDescriptor(); + std::vector getReportDescriptor() const; #endif bool sendHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message = 0); size_t receiveHIDReport(uint8_t* data, size_t length, HIDReportType tp, diff --git a/include/boo/inputdev/DeviceFinder.hpp b/include/boo/inputdev/DeviceFinder.hpp index c3b633d..3acb551 100644 --- a/include/boo/inputdev/DeviceFinder.hpp +++ b/include/boo/inputdev/DeviceFinder.hpp @@ -41,11 +41,8 @@ private: /* Friend methods for platform-listener to find/insert/remove * tokens with type-filtering */ - bool _hasToken(const std::string& path) { - auto preCheck = m_tokens.find(path); - if (preCheck != m_tokens.end()) - return true; - return false; + bool _hasToken(const std::string& path) const { + return m_tokens.find(path) != m_tokens.end(); } bool _insertToken(std::unique_ptr&& token) { if (DeviceSignature::DeviceMatchToken(*token, m_types)) { @@ -77,8 +74,12 @@ public: public: CDeviceTokensHandle(DeviceFinder& finder) : m_finder(finder) { m_finder.m_tokensLock.lock(); } ~CDeviceTokensHandle() { m_finder.m_tokensLock.unlock(); } - TDeviceTokens::iterator begin() { return m_finder.m_tokens.begin(); } - TDeviceTokens::iterator end() { return m_finder.m_tokens.end(); } + + TDeviceTokens::iterator begin() noexcept { return m_finder.m_tokens.begin(); } + TDeviceTokens::iterator end() noexcept { return m_finder.m_tokens.end(); } + + TDeviceTokens::const_iterator begin() const noexcept { return m_finder.m_tokens.begin(); } + TDeviceTokens::const_iterator end() const noexcept { return m_finder.m_tokens.end(); } }; /* Application must specify its interested device-types */ diff --git a/include/boo/inputdev/DualshockPad.hpp b/include/boo/inputdev/DualshockPad.hpp index a98f6cb..b8b2ed4 100644 --- a/include/boo/inputdev/DualshockPad.hpp +++ b/include/boo/inputdev/DualshockPad.hpp @@ -136,7 +136,7 @@ public: void stopRumble(int motor) { m_rumbleRequest &= ~EDualshockMotor(motor); } - EDualshockLED getLED() { return m_led; } + EDualshockLED getLED() const { return m_led; } void setLED(EDualshockLED led, bool on = true) { if (on) diff --git a/include/boo/inputdev/NintendoPowerA.hpp b/include/boo/inputdev/NintendoPowerA.hpp index ac9f375..20096a1 100644 --- a/include/boo/inputdev/NintendoPowerA.hpp +++ b/include/boo/inputdev/NintendoPowerA.hpp @@ -23,8 +23,8 @@ struct NintendoPowerAState { uint8_t leftY; uint8_t rightX; uint8_t rightY; - bool operator==(const NintendoPowerAState& other); - bool operator!=(const NintendoPowerAState& other); + bool operator==(const NintendoPowerAState& other) const; + bool operator!=(const NintendoPowerAState& other) const; }; class NintendoPowerA; diff --git a/lib/graphicsdev/Common.hpp b/lib/graphicsdev/Common.hpp index 8471216..2fe8c93 100644 --- a/lib/graphicsdev/Common.hpp +++ b/lib/graphicsdev/Common.hpp @@ -249,7 +249,7 @@ public: m_backcv.wait(lk, [this]() { return m_outstandingTasks == 0 || !m_running; }); } - bool isReady() { + bool isReady() const { return m_outstandingTasks == 0 || !m_running; } diff --git a/lib/inputdev/DeviceBase.cpp b/lib/inputdev/DeviceBase.cpp index 01fe6da..29d4412 100644 --- a/lib/inputdev/DeviceBase.cpp +++ b/lib/inputdev/DeviceBase.cpp @@ -37,25 +37,25 @@ size_t DeviceBase::receiveUSBInterruptTransfer(uint8_t* data, size_t length) { return false; } -unsigned DeviceBase::getVendorId() { +unsigned DeviceBase::getVendorId() const { if (m_token) return m_token->getVendorId(); return -1; } -unsigned DeviceBase::getProductId() { +unsigned DeviceBase::getProductId() const { if (m_token) return m_token->getProductId(); return -1; } -std::string_view DeviceBase::getVendorName() { +std::string_view DeviceBase::getVendorName() const { if (m_token) return m_token->getVendorName(); return {}; } -std::string_view DeviceBase::getProductName() { +std::string_view DeviceBase::getProductName() const { if (m_token) return m_token->getProductName(); return {}; @@ -63,14 +63,14 @@ std::string_view DeviceBase::getProductName() { #if _WIN32 #if !WINDOWS_STORE -const PHIDP_PREPARSED_DATA DeviceBase::getReportDescriptor() { +PHIDP_PREPARSED_DATA DeviceBase::getReportDescriptor() const { if (m_hidDev) return m_hidDev->_getReportDescriptor(); return {}; } #endif #else -std::vector DeviceBase::getReportDescriptor() { +std::vector DeviceBase::getReportDescriptor() const { if (m_hidDev) return m_hidDev->_getReportDescriptor(); return {}; diff --git a/lib/inputdev/NintendoPowerA.cpp b/lib/inputdev/NintendoPowerA.cpp index 8a31d2d..0c1e944 100644 --- a/lib/inputdev/NintendoPowerA.cpp +++ b/lib/inputdev/NintendoPowerA.cpp @@ -33,12 +33,10 @@ void NintendoPowerA::finalCycle() {} void NintendoPowerA::receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) {} -bool NintendoPowerAState::operator==(const NintendoPowerAState& other) { - return !memcmp(this, &other, sizeof(NintendoPowerAState)); +bool NintendoPowerAState::operator==(const NintendoPowerAState& other) const { + return memcmp(this, &other, sizeof(NintendoPowerAState)) == 0; } -bool NintendoPowerAState::operator!=(const NintendoPowerAState& other) { - return memcmp(this, &other, sizeof(NintendoPowerAState)); -} +bool NintendoPowerAState::operator!=(const NintendoPowerAState& other) const { return !operator==(other); } } // namespace boo