From 37da2899f40661e3e9631e497da8dc59b971cbd0 Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 22 Dec 2006 17:07:39 +0000 Subject: 20060303a --- emu/MacOSX/deveia.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 emu/MacOSX/deveia.c (limited to 'emu/MacOSX/deveia.c') diff --git a/emu/MacOSX/deveia.c b/emu/MacOSX/deveia.c new file mode 100644 index 00000000..bb7a01c6 --- /dev/null +++ b/emu/MacOSX/deveia.c @@ -0,0 +1,154 @@ +/* + * Darwin serial port definitions, uses IOKit to build sysdev + * Loosely based on FreeBSD/deveia.c + * Copyright © 1998, 1999 Lucent Technologies Inc. All rights reserved. + * Revisions Copyright © 1999, 2000 Vita Nuova Limited. All rights reserved. + * Revisions Copyright © 2003 Corpus Callosum Corporation. All rights reserved. +*/ + +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include + +#define B14400 14400 +#define B28800 28800 +#define B57600 57600 +#define B76800 76800 +#define B115200 115200 +#define B230400 230400 + +extern int vflag; + +#define MAXDEV 8 +static char *sysdev[MAXDEV]; + +#include +#include + +static void _buildsysdev(void); +#define buildsysdev() _buildsysdev() /* for devfs-posix.c */ + +static void +_buildsysdev(void) +{ + kern_return_t kernResult; + mach_port_t masterPort; + CFMutableDictionaryRef classesToMatch; + io_iterator_t serialPortIterator; + io_object_t serialDevice; + CFMutableArrayRef array; + CFIndex idx; + + kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort); + if (KERN_SUCCESS != kernResult) + { + printf("IOMasterPort returned %d\n", kernResult); + } else { + classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue); + if (classesToMatch == NULL) + { + printf("IOServiceMatching returned a NULL dictionary.\n"); + } else { + CFDictionarySetValue(classesToMatch, + CFSTR(kIOSerialBSDTypeKey), + CFSTR(kIOSerialBSDAllTypes)); + } + + kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, &serialPortIterator); + if (KERN_SUCCESS != kernResult) + { + printf("IOServiceGetMatchingServices returned %d\n", kernResult); + } else { + array = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); + + while ((serialDevice = IOIteratorNext(serialPortIterator))) { + CFTypeRef bsdPathAsCFString; + bsdPathAsCFString = IORegistryEntryCreateCFProperty(serialDevice, + CFSTR(kIOCalloutDeviceKey), + kCFAllocatorDefault, + 0); + if (bsdPathAsCFString) { + CFArrayAppendValue(array, bsdPathAsCFString); + } + + (void) IOObjectRelease(serialDevice); + } + + idx = CFArrayGetCount(array); + if (idx > 0) { + Boolean result; + char bsdPath[MAXPATHLEN]; + char *tmpsysdev[idx+1]; + CFIndex i; + + for (i=0; i