WiimoteDevice: Make ConnectionState enum an enum class

Avoids polluting class scope and makes it strongly typed.
This commit is contained in:
Lioncash 2018-06-09 15:37:05 -04:00
parent f564c28040
commit 38d155f993
2 changed files with 18 additions and 20 deletions

View File

@ -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()

View File

@ -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;