Exemplo n.º 1
0
        static public StatusCode TryGetSupportedInterfaces(out string[] supportedInterfaces)
        {
            IntPtr array = CNCopySupportedInterfaces();

            if (array == IntPtr.Zero)
            {
                supportedInterfaces = null;
                return(StatusCodeError.SCError());
            }

            supportedInterfaces = NSArray.StringArrayFromHandle(array);
            CFObject.CFRelease(array);
            return(StatusCode.OK);
        }
Exemplo n.º 2
0
        static public StatusCode TryCopyCurrentNetworkInfo(string interfaceName, out NSDictionary currentNetworkInfo)
        {
            using (var nss = new NSString(interfaceName)) {
                var ni = CNCopyCurrentNetworkInfo(nss.Handle);
                if (ni == IntPtr.Zero)
                {
                    currentNetworkInfo = null;
                    return(StatusCodeError.SCError());
                }

                currentNetworkInfo = new NSDictionary(ni);

                // Must release since the IntPtr constructor calls Retain
                currentNetworkInfo.DangerousRelease();
                return(StatusCode.OK);
            }
        }
        public StatusCode SetNotification(Notification callback)
        {
            if (notification == null)
            {
                if (callback == null)
                {
                    return(StatusCode.OK);
                }

                gch = GCHandle.Alloc(this);
                var ctx = new SCNetworkReachabilityContext(GCHandle.ToIntPtr(gch));

                lock (typeof(NetworkReachability)){
                    if (callouth == null)
                    {
                        callouth = Callback;
                    }
                }

                if (!SCNetworkReachabilitySetCallback(handle, callouth, ref ctx))
                {
                    return(StatusCodeError.SCError());
                }
            }
            else
            {
                if (callback == null)
                {
                    this.notification = null;
                    callouth          = null;
                    if (!SCNetworkReachabilitySetCallback(handle, null, IntPtr.Zero))
                    {
                        return(StatusCodeError.SCError());
                    }

                    return(StatusCode.OK);
                }
            }

            this.notification = callback;
            return(StatusCode.OK);
        }
        internal static SystemConfigurationException FromMostRecentCall()
        {
            var code = StatusCodeError.SCError();

            return(new SystemConfigurationException(code));
        }
 public SystemConfigurationException(StatusCode statusErrorCode)
     : base(StatusCodeError.GetErrorDescription(statusErrorCode))
 {
     StatusErrorCode = statusErrorCode;
 }
 public StatusCode GetFlags(out NetworkReachabilityFlags flags)
 {
     return(SCNetworkReachabilityGetFlags(handle, out flags) == 0 ?
            StatusCodeError.SCError() : StatusCode.OK);
 }