Пример #1
0
        private static System.IntPtr Initialize(IOMachPort masterPort, NSMutableDictionary serialServices)
        {
            System.IntPtr iterator;
            var           result = NativeMethods.IOServicesMatchingDictionary(masterPort.Handle, serialServices, out iterator);

            if (result != NativeMethods.Success)
            {
                throw new System.InvalidOperationException();
            }
            return(iterator);
        }
Пример #2
0
            /// <inheritdoc/>
            internal override void StartInThread()
            {
                NotificationPort = new IONotificationPort();
                Interop.NativeMethods.CFRunLoopAddSource(CFRunLoop.Current, NotificationPort.RunLoopSource, (NSString)CFRunLoop.ModeDefault);

                var systemPowerDelegate = new IOServiceInterestCallback(SystemPowerInterestCallback);

                IOConnectionPort = IOConnect.CreateSystemPowerMonitorConnection(systemPowerDelegate, this);
                Interop.NativeMethods.CFRunLoopAddSource(CFRunLoop.Current, IOConnectionPort.NotificationPort.RunLoopSource, (NSString)CFRunLoop.ModeCommon);

                var servicesDictionary = IOMachPort.GetRS232SerialMatchDictionary();

#if __UNIFIED__
                servicesDictionary.DangerousRetain(); // retain an extra time because we're using it twice
#else
                servicesDictionary.Retain();          // retain an extra time because we're using it twice
#endif // __UNIFIED__
                var publishDelegate = new IONotificationPortCallback(FirstMatchNotification);
                var callback        = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(publishDelegate);

                IntPtr iterator;
                var    result = NativeMethods.IOServiceAddMatchingNotification(NotificationPort.Handle, KIOFirstMatchNotification, servicesDictionary.Handle, callback, IntPtr.Zero, out iterator);
                System.Diagnostics.Debug.Assert(result == NativeMethods.Success, "IOService.IOKitNotificationPort: Failed to add notification.");

                if (result == NativeMethods.Success)
                {
                    PublishNotificationIterator = new IOIterator(iterator);

                    var terminateDelegate = new IONotificationPortCallback(TerminateNotification);
                    callback = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(terminateDelegate);
                    result   = NativeMethods.IOServiceAddMatchingNotification(NotificationPort.Handle, KIOTerminatedNotification, servicesDictionary.Handle, callback, IntPtr.Zero, out iterator);
                    TerminateNotificationIterator = new IOIterator(iterator);

                    // The iterators returned when adding the matching notifications must be iterated to
                    // completion in order to arm the notifications. Otherwise, they will never fire.
                    PublishNotificationIterator.EnumerateSerialPorts(null);
                    TerminateNotificationIterator.EnumerateSerialPorts(null);
                }
            }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="INTV.Shared.Interop.IOKit.IOIterator"/> class.
 /// </summary>
 /// <param name="masterPort">The master port.</param>
 /// <param name="serialServices">The serial services.</param>
 public IOIterator(IOMachPort masterPort, NSMutableDictionary serialServices)
     : base(() => Initialize(masterPort, serialServices))
 {
 }