Exemple #1
0
        /// <summary>
        /// Move the iterator to point to the next element in the colleciton.
        /// </summary>
        /// <typeparam name="T">The type of objects being iterated over.</typeparam>
        /// <returns>The iterator to the next element, <c>null</c> if there isn't a next element.</returns>
        public T Next <T>() where T : IOKitObject, new()
        {
            T   ioKitObject       = null;
            var ioKitObjectHandle = NativeMethods.IOIteratorNext(Handle);

            if (ioKitObjectHandle != System.IntPtr.Zero)
            {
                ioKitObject = IOKitObject.CreateIOKitObject <T>(ioKitObjectHandle);
            }
            return(ioKitObject);
        }
Exemple #2
0
        private static IOConnect IORegisterForSystemPower(IOServiceInterestCallback systemPowerDelegate, NSObject refcon)
        {
            var ioNotificationPort = System.IntPtr.Zero;
            var notifierHandle     = System.IntPtr.Zero;
            var callback           = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(systemPowerDelegate);
            var nativeIOConnect    = NativeMethods.IORegisterForSystemPower(refcon.Handle, out ioNotificationPort, callback, out notifierHandle);

            var ioConnect = IOKitObject.CreateIOKitObject <IOConnect>(nativeIOConnect);

            ioConnect.NotificationPort = new IONotificationPort(ioNotificationPort);
            ioConnect.Notifier         = IOKitObject.CreateIOKitObject <IOKitObject>(notifierHandle, n => IODeregisterForSystemPower(n));
            return(ioConnect);
        }