From 38d155f9932c9666ac08b7fea1aabb72a7222361 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 9 Jun 2018 15:37:05 -0400 Subject: [PATCH] WiimoteDevice: Make ConnectionState enum an enum class Avoids polluting class scope and makes it strongly typed. --- .../Core/IOS/USB/Bluetooth/WiimoteDevice.cpp | 21 ++++++++----------- .../Core/IOS/USB/Bluetooth/WiimoteDevice.h | 17 ++++++++------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp b/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp index 3ea20a85b3..bf5f600372 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp @@ -56,7 +56,7 @@ WiimoteDevice::WiimoteDevice(Device::BluetoothEmu* host, int number, bdaddr_t bd { INFO_LOG(IOS_WIIMOTE, "Wiimote: #%i Constructed", number); - m_ConnectionState = (ready) ? CONN_READY : CONN_INACTIVE; + m_ConnectionState = ready ? ConnectionState::Ready : ConnectionState::Inactive; m_ConnectionHandle = 0x100 + number; memset(m_LinkKey, 0xA0 + number, HCI_KEY_SIZE); @@ -130,7 +130,7 @@ void WiimoteDevice::DoState(PointerWrap& p) bool WiimoteDevice::LinkChannel() { - if (m_ConnectionState != CONN_LINKING) + if (m_ConnectionState != ConnectionState::Linking) return false; // try to connect L2CAP_PSM_HID_CNTL @@ -178,7 +178,7 @@ bool WiimoteDevice::LinkChannel() } DEBUG_LOG(IOS_WIIMOTE, "ConnectionState CONN_LINKING -> CONN_COMPLETE"); - m_ConnectionState = CONN_COMPLETE; + m_ConnectionState = ConnectionState::Complete; return false; } @@ -195,9 +195,9 @@ bool WiimoteDevice::LinkChannel() // void WiimoteDevice::Activate(bool ready) { - if (ready && (m_ConnectionState == CONN_INACTIVE)) + if (ready && (m_ConnectionState == ConnectionState::Inactive)) { - m_ConnectionState = CONN_READY; + m_ConnectionState = ConnectionState::Ready; } else if (!ready) { @@ -209,7 +209,7 @@ void WiimoteDevice::Activate(bool ready) void WiimoteDevice::EventConnectionAccepted() { DEBUG_LOG(IOS_WIIMOTE, "ConnectionState %x -> CONN_LINKING", m_ConnectionState); - m_ConnectionState = CONN_LINKING; + m_ConnectionState = ConnectionState::Linking; } void WiimoteDevice::EventDisconnect() @@ -217,17 +217,14 @@ void WiimoteDevice::EventDisconnect() // Send disconnect message to plugin Wiimote::ControlChannel(m_ConnectionHandle & 0xFF, 99, nullptr, 0); - m_ConnectionState = CONN_INACTIVE; + m_ConnectionState = ConnectionState::Inactive; // Clear channel flags ResetChannels(); } -bool WiimoteDevice::EventPagingChanged(u8 _pageMode) +bool WiimoteDevice::EventPagingChanged(u8 page_mode) { - if ((m_ConnectionState == CONN_READY) && (_pageMode & HCI_PAGE_SCAN_ENABLE)) - return true; - - return false; + return (m_ConnectionState == ConnectionState::Ready) && (page_mode & HCI_PAGE_SCAN_ENABLE); } void WiimoteDevice::ResetChannels() diff --git a/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.h b/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.h index 439b01dae6..6614fb3281 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.h +++ b/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.h @@ -30,8 +30,8 @@ public: // ugly Host handling.... // we really have to clean all this code - bool IsConnected() const { return m_ConnectionState == CONN_COMPLETE; } - bool IsInactive() const { return m_ConnectionState == CONN_INACTIVE; } + bool IsConnected() const { return m_ConnectionState == ConnectionState::Complete; } + bool IsInactive() const { return m_ConnectionState == ConnectionState::Inactive; } bool LinkChannel(); void ResetChannels(); void Activate(bool ready); @@ -40,7 +40,7 @@ public: void EventConnectionAccepted(); void EventDisconnect(); - bool EventPagingChanged(u8 _pageMode); + bool EventPagingChanged(u8 page_mode); const bdaddr_t& GetBD() const { return m_BD; } const uint8_t* GetClass() const { return uclass; } @@ -53,13 +53,14 @@ public: const u8* GetLinkKey() const { return m_LinkKey; } private: - enum ConnectionState + enum class ConnectionState { - CONN_INACTIVE = -1, - CONN_READY, - CONN_LINKING, - CONN_COMPLETE + Inactive = -1, + Ready, + Linking, + Complete }; + ConnectionState m_ConnectionState; bool m_HIDControlChannel_Connected = false;