Permalink
Browse files

WiimoteDevice: Make ConnectionState enum an enum class

Avoids polluting class scope and makes it strongly typed.
  • Loading branch information...
lioncash committed Jun 9, 2018
1 parent f564c28 commit 38d155f9932c9666ac08b7fea1aabb72a7222361
@@ -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,25 +209,22 @@ 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()
{
// 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()
@@ -30,8 +30,8 @@ class WiimoteDevice
// 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 @@ class WiimoteDevice
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 @@ class WiimoteDevice
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;

0 comments on commit 38d155f

Please sign in to comment.