Skip to content
Permalink
Browse files

IOS/USB_KBD: Make the message type enum an enum class

Avoids polluting the surrounding scope with enum values. We can also
make use of it in MessageData's constructor to enforce proper type
passing.
  • Loading branch information...
lioncash committed May 31, 2019
1 parent d89ea8b commit 7f5ca64c4d1b307f90cf26054502da95ee3b952e
Showing with 11 additions and 10 deletions.
  1. +5 −4 Source/Core/Core/IOS/USB/USB_KBD.cpp
  2. +6 −6 Source/Core/Core/IOS/USB/USB_KBD.h
@@ -176,8 +176,9 @@ constexpr std::array<u8, 256> s_key_codes_azerty{};
#endif
} // Anonymous namespace

USB_KBD::MessageData::MessageData(u32 type, u8 modifiers, PressedKeyData pressed_keys)
: MsgType{Common::swap32(type)}, Modifiers{modifiers}, PressedKeys{pressed_keys}
USB_KBD::MessageData::MessageData(MessageType type, u8 modifiers, PressedKeyData pressed_keys)
: MsgType{Common::swap32(static_cast<u32>(type))}, Modifiers{modifiers}, PressedKeys{
pressed_keys}
{
}

@@ -198,7 +199,7 @@ IPCCommandResult USB_KBD::Open(const OpenRequest& request)
m_OldKeyBuffer.fill(false);
m_OldModifiers = 0x00;

// m_MessageQueue.emplace(MSG_KBD_CONNECT, 0, PressedKeyData{});
// m_MessageQueue.emplace(MessageType::KeyboardConnect, 0, PressedKeyData{});
return Device::Open(request);
}

@@ -304,6 +305,6 @@ void USB_KBD::Update()
}

if (GotEvent)
m_MessageQueue.emplace(MSG_EVENT, Modifiers, PressedKeys);
m_MessageQueue.emplace(MessageType::Event, Modifiers, PressedKeys);
}
} // namespace IOS::HLE::Device
@@ -26,25 +26,25 @@ class USB_KBD : public Device
void Update() override;

private:
enum
enum class MessageType : u32
{
MSG_KBD_CONNECT = 0,
MSG_KBD_DISCONNECT = 1,
MSG_EVENT = 2
KeyboardConnect = 0,
KeyboardDisconnect = 1,
Event = 2
};

using PressedKeyData = std::array<u8, 6>;

#pragma pack(push, 1)
struct MessageData
{
u32 MsgType = 0;
MessageType MsgType{};
u32 Unk1 = 0;
u8 Modifiers = 0;
u8 Unk2 = 0;
PressedKeyData PressedKeys{};

MessageData(u32 msg_type, u8 modifiers, PressedKeyData pressed_keys);
MessageData(MessageType msg_type, u8 modifiers, PressedKeyData pressed_keys);
};
static_assert(std::is_trivially_copyable_v<MessageData>,
"MessageData must be trivially copyable, as it's copied into emulated memory.");

0 comments on commit 7f5ca64

Please sign in to comment.
You can’t perform that action at this time.