Example #1
0
        public IOObject AddInterestNotification(IONotificationPort notifyPort, InterestType interestType, InterestCallback callback)
        {
            ThrowIfDisposed();
            var interestTypeString = interestType.GetKey();
            IOServiceInterestCallback nativeCallback = (refCon, service, messageType, messageArgument) =>
            {
                if (service != Handle)
                {
                    return;
                }
                callback.Invoke(this, messageType, messageArgument);
            };

            callbackStore.Add(nativeCallback);
            IntPtr notification;
            var    result = IOServiceAddInterestNotification(notifyPort.Handle, Handle, interestTypeString,
                                                             nativeCallback, IntPtr.Zero, out notification);

            ThrowIfError(result);
            return(new IOObject(notification, true));
        }
Example #2
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);
        }