Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A rather specific newbie question



Thanks to everyone who replied. I found the IORegistry documentation and sort of came up with something. There may be a memory leak or three in here, but it at least appears to work.

The one thing that appears magical is the need to go up two parents. Without doing that, the bundle ID winds up being com.apple.iokit.IOSerialFamily rather than the bundle ID for the actual USB-to-serial kext for the device.

char *getBundleNameForDevice(char *fname) {
static char retval[1024]; // that really ought to be enough. I'm too lazy to alloc and release.
mach_port_t masterPort;
io_iterator_t matchingServices;
CFMutableDictionaryRef classesToMatch;
kern_return_t kernResult;
io_object_t device;
CFStringRef CFfname;


    kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
    if (KERN_SUCCESS != kernResult)
    {
        return NULL;
    }

// We want to find the BSD serial device with the given name.
classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue);
CFfname = CFStringCreateWithCString(NULL, fname, kCFStringEncodingASCII);
CFDictionarySetValue(classesToMatch,
CFSTR(kIODialinDeviceKey),
CFfname);
CFRelease(CFfname);


kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, &matchingServices);
if (KERN_SUCCESS != kernResult)
{
return NULL;
}


    while((device = IOIteratorNext(matchingServices))) {
        CFTypeRef bundleIDAsCFString;
        Boolean result;
        io_object_t parent, superParent;

// Now we go up two levels and look for the bundle ID.
if (IORegistryEntryGetParentEntry(device, kIOServicePlane, &parent) != KERN_SUCCESS)
continue;
if (IORegistryEntryGetParentEntry(parent, kIOServicePlane, &superParent) != KERN_SUCCESS)
continue;
bundleIDAsCFString = IORegistryEntryCreateCFProperty(superParent,
kIOBundleIdentifierKey,
kCFAllocatorDefault,
0);


        if (bundleIDAsCFString == NULL)
            continue;

        result = CFStringGetCString(bundleIDAsCFString,
                                    retval,
                                    sizeof(retval) - 1,
                                    kCFStringEncodingASCII);

        CFRelease(bundleIDAsCFString);

        if (result)
            return retval;
    }

    return NULL;
}
_______________________________________________
usb mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/usb
Do not post admin requests to the list. They will be ignored.

References: 
 >A rather specific newbie question (From: Nick Sayer <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.