ControllerInterface: Remove OSX window handle

also make it more thread safe (avoid rare deadlock)
and fix it trying to add devices before the CI has init
This commit is contained in:
Filoppi
2021-05-15 12:08:38 +03:00
parent 2376aec135
commit c238e49119
4 changed files with 29 additions and 22 deletions

View File

@ -135,8 +135,6 @@ static void DeviceDebugPrint(IOHIDDeviceRef device)
#endif
}
static void* g_window;
static std::string GetDeviceRefName(IOHIDDeviceRef inIOHIDDeviceRef)
{
const NSString* name = reinterpret_cast<const NSString*>(
@ -172,10 +170,8 @@ static void DeviceMatchingCallback(void* inContext, IOReturn inResult, void* inS
}
}
void Init(void* window)
void Init()
{
g_window = window;
HIDManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);
if (!HIDManager)
ERROR_LOG_FMT(CONTROLLERINTERFACE, "Failed to create HID Manager reference");
@ -210,19 +206,17 @@ void Init(void* window)
});
}
void PopulateDevices(void* window)
{
DeInit();
Init(window);
}
void DeInit()
{
s_stopper.Signal();
s_hotplug_thread.join();
if (HIDManager)
{
s_stopper.Signal();
s_hotplug_thread.join();
// This closes all devices as well
IOHIDManagerClose(HIDManager, kIOHIDOptionsTypeNone);
CFRelease(HIDManager);
// This closes all devices as well
IOHIDManagerClose(HIDManager, kIOHIDOptionsTypeNone);
CFRelease(HIDManager);
HIDManager = nullptr;
}
}
} // namespace ciface::OSX