htc: free ourselves from the tyranny of numerical enums

This commit is contained in:
Michael Scire
2021-02-08 06:48:30 -08:00
committed by SciresM
parent 2341f18edd
commit e40eece74e
6 changed files with 131 additions and 87 deletions

View File

@@ -42,7 +42,7 @@ namespace ams::htclow::ctrl {
}
HtcctrlStateMachine::HtcctrlStateMachine() : m_map(), m_state(HtcctrlState_11), m_prev_state(HtcctrlState_11), m_mutex() {
HtcctrlStateMachine::HtcctrlStateMachine() : m_map(), m_state(HtcctrlState_DriverDisconnected), m_prev_state(HtcctrlState_DriverDisconnected), m_mutex() {
/* Lock ourselves. */
std::scoped_lock lk(m_mutex);
@@ -153,28 +153,25 @@ namespace ams::htclow::ctrl {
/* Lock ourselves. */
std::scoped_lock lk(m_mutex);
/* TODO: What do these values mean? */
auto it = m_map.find(channel);
return it != m_map.end() && it->second._04 == 2 && it->second._00 == 2;
return it != m_map.end() && it->second.connect == ServiceChannelConnect_ConnectingChecked && it->second.support == ServiceChannelSupport_Unsupported;
}
bool HtcctrlStateMachine::IsConnectable(const impl::ChannelInternalType &channel) {
/* Lock ourselves. */
std::scoped_lock lk(m_mutex);
/* TODO: What do these values mean? */
auto it = m_map.find(channel);
return ctrl::IsConnected(m_state) && (!(it != m_map.end()) || it->second._04 != 2);
return ctrl::IsConnected(m_state) && (it == m_map.end() || it->second.connect != ServiceChannelConnect_ConnectingChecked);
}
void HtcctrlStateMachine::SetNotConnecting(const impl::ChannelInternalType &channel) {
/* Lock ourselves. */
std::scoped_lock lk(m_mutex);
/* TODO: What do these values mean? */
auto it = m_map.find(channel);
if (it != m_map.end() && it->second._04 != 2) {
it->second._04 = 0;
if (it != m_map.end() && it->second.connect != ServiceChannelConnect_ConnectingChecked) {
it->second.connect = ServiceChannelConnect_NotConnecting;
}
}