mirror of
git://sigrok.org/libserialport
synced 2023-08-10 21:13:24 +03:00
Simplify Mac OS implementation of sp_list_ports().
This commit is contained in:
parent
f095f84164
commit
073c86bd07
26
serialport.c
26
serialport.c
@ -418,49 +418,35 @@ out_close:
|
|||||||
out_done:
|
out_done:
|
||||||
#endif
|
#endif
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
mach_port_t master;
|
|
||||||
CFMutableDictionaryRef classes;
|
CFMutableDictionaryRef classes;
|
||||||
io_iterator_t iter;
|
io_iterator_t iter;
|
||||||
char *path;
|
char path[PATH_MAX];
|
||||||
io_object_t port;
|
io_object_t port;
|
||||||
CFTypeRef cf_path;
|
CFTypeRef cf_path;
|
||||||
Boolean result;
|
Boolean result;
|
||||||
|
|
||||||
ret = SP_OK;
|
ret = SP_OK;
|
||||||
|
|
||||||
DEBUG("Getting IOKit master port");
|
|
||||||
if (IOMasterPort(MACH_PORT_NULL, &master) != KERN_SUCCESS) {
|
|
||||||
SET_FAIL(ret, "IOMasterPort() failed");
|
|
||||||
goto out_done;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG("Creating matching dictionary");
|
DEBUG("Creating matching dictionary");
|
||||||
if (!(classes = IOServiceMatching(kIOSerialBSDServiceValue))) {
|
if (!(classes = IOServiceMatching(kIOSerialBSDServiceValue))) {
|
||||||
SET_FAIL(ret, "IOServiceMatching() failed");
|
SET_FAIL(ret, "IOServiceMatching() failed");
|
||||||
goto out_done;
|
goto out_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFDictionarySetValue(classes,
|
|
||||||
CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDAllTypes));
|
|
||||||
|
|
||||||
DEBUG("Getting matching services");
|
DEBUG("Getting matching services");
|
||||||
if (IOServiceGetMatchingServices(master, classes, &iter) != KERN_SUCCESS) {
|
if (IOServiceGetMatchingServices(kIOMasterPortDefault, classes,
|
||||||
|
&iter) != KERN_SUCCESS) {
|
||||||
SET_FAIL(ret, "IOServiceGetMatchingServices() failed");
|
SET_FAIL(ret, "IOServiceGetMatchingServices() failed");
|
||||||
goto out_done;
|
goto out_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(path = malloc(PATH_MAX))) {
|
|
||||||
SET_ERROR(ret, SP_ERR_MEM, "device path malloc failed");
|
|
||||||
goto out_release;
|
|
||||||
}
|
|
||||||
|
|
||||||
DEBUG("Iterating over results");
|
DEBUG("Iterating over results");
|
||||||
while ((port = IOIteratorNext(iter))) {
|
while ((port = IOIteratorNext(iter))) {
|
||||||
cf_path = IORegistryEntryCreateCFProperty(port,
|
cf_path = IORegistryEntryCreateCFProperty(port,
|
||||||
CFSTR(kIOCalloutDeviceKey), kCFAllocatorDefault, 0);
|
CFSTR(kIOCalloutDeviceKey), kCFAllocatorDefault, 0);
|
||||||
if (cf_path) {
|
if (cf_path) {
|
||||||
result = CFStringGetCString(cf_path,
|
result = CFStringGetCString(cf_path, path, sizeof(path),
|
||||||
path, PATH_MAX, kCFStringEncodingASCII);
|
kCFStringEncodingASCII);
|
||||||
CFRelease(cf_path);
|
CFRelease(cf_path);
|
||||||
if (result) {
|
if (result) {
|
||||||
DEBUG("Found port %s", path);
|
DEBUG("Found port %s", path);
|
||||||
@ -474,8 +460,6 @@ out_done:
|
|||||||
IOObjectRelease(port);
|
IOObjectRelease(port);
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
free(path);
|
|
||||||
out_release:
|
|
||||||
IOObjectRelease(iter);
|
IOObjectRelease(iter);
|
||||||
out_done:
|
out_done:
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user