Re: grand central dispatch and notification port sources
Re: grand central dispatch and notification port sources
- Subject: Re: grand central dispatch and notification port sources
- From: Joel Reymont <email@hidden>
- Date: Wed, 10 Mar 2010 23:03:44 +0000
On Mar 10, 2010, at 10:55 PM, Damien Sorresso wrote:
> You could use DISPATCH_SOURCE_TYPE_MACH_RECV, but you'd end up being too clever for your own good. The fact that IOKit's notification ports are Mach ports isn't guaranteed in any API, as far as I know. Also, it'd be up to you to process the message sent to the port and invoke your callback routine. The structure of the messages sent from IOKit to userspace clients is definitely not public.
All I care is getting notified when a USB device is plugged or unplugged, e.g. right now
---
void RawDeviceAdded(void *refCon, io_iterator_t iterator)
{
...
}
// Now set up two notifications, one to be called when a raw device is first matched by I/O Kit, and the other to be
// called when the device is terminated.
kr = IOServiceAddMatchingNotification( gNotifyPort,
kIOFirstMatchNotification,
matchingDict,
RawDeviceAdded,
NULL,
&gRawAddedIter );
---
Assuming I set up the dispatch source thusly
---
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV,
gNotifyPort, 0, myQueue);
dispatch_source_set_event_handler(source, ^{
...
});
dispatch_resume(source);
---
Are you saying that the handler won't be invoked or are you saying that it will be up to me to pull refCon and iterator from the IOKit message?
Thanks, Joel
---
http://es.linkedin.com/in/joelreymont
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden