macOS: STM32: Fix device finding for newer versions of the OS

pull/32/head
Paul Hollinsky 2021-03-19 13:02:53 -04:00
parent 7f27b30954
commit 92790330f1
1 changed files with 4 additions and 6 deletions

View File

@ -3,6 +3,7 @@
#include <vector>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/usb/IOUSBLib.h>
#include <IOKit/serial/IOSerialKeys.h>
using namespace icsneo;
@ -104,15 +105,12 @@ std::vector<neodevice_t> STM32::FindByProduct(int product) {
io_object_t usb = 0;
// Need to release every parent we find in the chain, but we should defer that until later
std::vector<IOReleaser> releasers;
const std::string usbClass = "IOUSBDevice";
while(IORegistryEntryGetParentEntry(current, kIOServicePlane, &parent) == KERN_SUCCESS) {
releasers.emplace_back(parent);
current = parent;
io_name_t className;
// io_name_t does not need to be freed, it's just a stack char[128]
if(IOObjectGetClass(parent, className) != KERN_SUCCESS)
continue;
if(std::string(className) == usbClass) {
// On old macOSes, IOUSBDevice is the type of the class we want
// On newer macOSes, IOUSBDevice may further be subclassed as IOUSBHostDevice
if(IOObjectConformsTo(parent, kIOUSBDeviceClassName)) {
usb = parent;
break;
}