ControllerInterface: Make the ID assigning code common

This makes the device ID assigning code common to all backends, by
moving it to AddDevice() instead of copy-pasting or replicating
the logic in the backends.

Also, to prepare for hotplugging, instead of relying on a name usage
count, the new ID assigning system always starts from ID 0 and tries
to assign the first ID that is not used.
This commit is contained in:
Léo Lam
2016-07-14 10:25:52 +02:00
parent 89a03174cc
commit 788e19f54d
25 changed files with 41 additions and 112 deletions

View File

@ -21,7 +21,6 @@ namespace OSX
{
static IOHIDManagerRef HIDManager = nullptr;
static CFStringRef OurRunLoop = CFSTR("DolphinOSXInput");
static std::map<std::string, int> kbd_name_counts, joy_name_counts;
void DeviceElementDebugPrint(const void* value, void* context)
{
@ -145,17 +144,13 @@ static void DeviceMatching_callback(void* inContext, IOReturn inResult, void* in
// Add a device if it's of a type we want
if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard))
g_controller_interface.AddDevice(
std::make_shared<Keyboard>(inIOHIDDeviceRef, name, kbd_name_counts[name]++, g_window));
g_controller_interface.AddDevice(std::make_shared<Keyboard>(inIOHIDDeviceRef, name, g_window));
#if 0
else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef,
kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse))
g_controller_interface.AddDevice(new Mouse(inIOHIDDeviceRef,
name, mouse_name_counts[name]++));
else if (IOHIDDeviceConformsTo(inIOHIDDeviceRef, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse))
g_controller_interface.AddDevice(new Mouse(inIOHIDDeviceRef, name));
#endif
else
g_controller_interface.AddDevice(
std::make_shared<Joystick>(inIOHIDDeviceRef, name, joy_name_counts[name]++));
g_controller_interface.AddDevice(std::make_shared<Joystick>(inIOHIDDeviceRef, name));
}
void Init(void* window)
@ -176,9 +171,6 @@ void Init(void* window)
if (IOHIDManagerOpen(HIDManager, kIOHIDOptionsTypeNone) != kIOReturnSuccess)
NSLog(@"Failed to open HID Manager");
kbd_name_counts.clear();
joy_name_counts.clear();
// Wait while current devices are initialized
while (CFRunLoopRunInMode(OurRunLoop, 0, TRUE) == kCFRunLoopRunHandledSource)
{