示例#1
0
        public static IOIterator <T> AddMatchingNotification <T> (IONotificationPort notifyPort, NotificationType notificationType,
                                                                  NSDictionary matchingDictionary, MatchingCallback <T> callback) where T : IOService
        {
            var notificationTypeString = notificationType.GetKey();
            IOServiceMatchingCallback nativeCallback = (refCon, iteratorRef) =>
            {
                var iterator = MarshalNativeObject <IOIterator <T> > (iteratorRef, false);
                callback.Invoke(iterator);
            };

            callbackStore.Add(nativeCallback);
            IntPtr iteratorRef2;

            CFType.Retain(matchingDictionary.Handle);
            var result = IOServiceAddMatchingNotification(notifyPort.Handle, notificationTypeString, matchingDictionary.Handle,
                                                          nativeCallback, IntPtr.Zero, out iteratorRef2);

            ThrowIfError(result);
            var iterator2 = new IOIterator <T> (iteratorRef2, true);

            iterator2.Disposed += (sender, e) => callbackStore.Remove(nativeCallback);
            return(iterator2);
        }