• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: IOKit notifications
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IOKit notifications


  • Subject: Re: IOKit notifications
  • From: Florent Pillet <email@hidden>
  • Date: Fri, 24 Nov 2006 09:39:07 +0100

I do it slightly differently in my code. Though the thread I use for USB is not using Cocoa, I think the code below should work for you:

NSNumber* usbVendor = [NSNumber numberWithInt:1027];
NSNumber* usbProduct = [NSNumber numberWithInt:24592];

NSMutableDictionary* matchingDict =
    IOServiceMatching(kIOUSBDeviceClassName);
[matchingDict takeValue:usbVendor forKey:@"kUSBVendorID"];
[matchingDict takeValue:usbProduct forKey:@"kUSBProductID"];

mach_port_t masterPort;
kern_return_t kr;
CFRunLoopSourceRef runLoopSource;

kr = IOMasterPort (MACH_PORT_NULL, &masterPort);
if (!kr && masterPort) {
    notifyPort = IONotificationPortCreate (masterPort);
    runLoopSource = IONotificationPortGetRunLoopSource (notifyPort);

    CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCurrentRunLoop],
                       runLoopSource,
                       kCFRunLoopDefaultMode);

    kr = IOServiceAddMatchingNotification(
                       notifyPort,
                       kIOFirstMatchNotification,
                       matchingDict,
                       DeviceAdded,
                       NULL,
                       &gAddedIter);

    DeviceAdded(NULL, gAddedIter);     // arm the notification

    mach_port_deallocate (mach_task_self(), masterPort);
}
	

I believe this may work better in your context. If this doesn't, you may want to join Apple's USB mailing list and ask the question to the experts there.

HTH,
Florent


ed despard wrote:
I apologize for the other two empty body messages with the same title, Im not sure what was happening with my mail client.

Hi, Im trying to receive notifications of usb device connection and termination from within my cocoa apps. Apples CF based example code works fine, but when I converted their code to work in my application, i never receive any notifications. The relevent code is provided below


- (void) awakeFromNib
{
kern_return_t kr;
NSMutableDictionary* matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
NSNumber* usbVendor = [NSNumber numberWithInt:1027];
NSNumber* usbProduct = [NSNumber numberWithInt:24592];
[matchingDict takeValue:usbVendor forKey:@"kUSBVendorID"];
[matchingDict takeValue:usbProduct forKey:@"kUSBProductID"];
notifyPort = IONotificationPortCreate(kIOMasterPortDefault);
CFRunLoopSourceRef runLoopSource;
runLoopSource = IONotificationPortGetRunLoopSource(notifyPort);
NSRunLoop* currentRunLoop = [NSRunLoop currentRunLoop];
CFRunLoopRef CFRunLoop = [currentRunLoop getCFRunLoop];
CFRunLoopAddSource(CFRunLoop, runLoopSource, kCFRunLoopDefaultMode);
kr = IOServiceAddMatchingNotification( notifyPort, // notifyPort
kIOFirstMatchNotification, // notificationType
matchingDict, // matching
DeviceAdded, // callback
NULL, // refCon
&gAddedIter ); DeviceAdded(NULL,gAddedIter);
}


the usbVendor and USBProduct ids are correct for my device.
notifyport is a member of the class
IOServiceAddMatchingNotification does return KERN_SUCCESS


thanks,
Ed Despard
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:


This email sent to email@hidden

-- Florent Pillet http://www.florentpillet.com Software consultant - Mac OS X, Palm OS, Windows Mobile Skype callto://florent.pillet

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins (at) lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >IOKit notifications (From: ed despard <email@hidden>)

  • Prev by Date: Re: ObjectAlloc tool and framework debugging
  • Next by Date: Re: Localized numbers 1000 and over not returned
  • Previous by thread: IOKit notifications
  • Next by thread: Reusing HTTP connections
  • Index(es):
    • Date
    • Thread