Look up registered IOService objects that match a matching dictionary, and install a notification request of new IOServices that match.
SDKs
- macOS 10.0+
- Mac Catalyst 13.0+
Framework
- IOKit
Declaration
func IOServiceAddMatchingNotification(_ notifyPort: IONotification Port Ref!, _ notificationType: Unsafe Pointer<Int8>!, _ matching: CFDictionary!, _ callback: IOService Matching Callback!, _ refCon: Unsafe Mutable Raw Pointer!, _ notification: Unsafe Mutable Pointer<io _iterator _t>!) -> kern _return _t
Parameters
notifyPort
A IONotificationPortRef object that controls how messages will be sent when the armed notification is fired. When the notification is delivered, the io_iterator_t representing the notification should be iterated through to pick up all outstanding objects. When the iteration is finished the notification is rearmed. See IONotificationPortCreate.
notificationType
A notification type from IOKitKeys.h
kIOPublishNotification Delivered when an IOService is registered.
kIOFirstPublishNotification Delivered when an IOService is registered, but only once per IOService instance. Some IOService's may be reregistered when their state is changed.
kIOMatchedNotification Delivered when an IOService has had all matching drivers in the kernel probed and started.
kIOFirstMatchNotification Delivered when an IOService has had all matching drivers in the kernel probed and started, but only once per IOService instance. Some IOService's may be reregistered when their state is changed.
kIOTerminatedNotification Delivered after an IOService has been terminated.
matching
A CF dictionary containing matching information, of which one reference is always consumed by this function (Note prior to the Tiger release there was a small chance that the dictionary might not be released if there was an error attempting to serialize the dictionary). IOKitLib can construct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOServiceNameMatching, IOBSDNameMatching.
callback
A callback function called when the notification fires.
refCon
A reference constant for the callbacks use.
notification
An iterator handle is returned on success, and should be released by the caller when the notification is to be destroyed. The notification is armed when the iterator is emptied by calls to IOIteratorNext - when no more objects are returned, the notification is armed. Note the notification is not armed when first created.
Return Value
A kern_return_t error code.
Discussion
This is the preferred method of finding IOService objects that may arrive at any time. The type of notification specifies the state change the caller is interested in, on IOService's that match the match dictionary. Notification types are identified by name, and are defined in IOKitKeys.h. The matching information used in the matching dictionary may vary depending on the class of service being looked up.