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);
        }
Esempio n. 2
0
        public MacNetworkChange()
        {
            var sockaddr = sockaddr_in.Create();

            handle = SCNetworkReachabilityCreateWithAddress(IntPtr.Zero, ref sockaddr);
            if (handle == IntPtr.Zero)
            {
                throw new Exception("SCNetworkReachabilityCreateWithAddress returned NULL");
            }

            callback = new SCNetworkReachabilityCallback(HandleCallback);
            var info = new SCNetworkReachabilityContext {
                info = GCHandle.ToIntPtr(GCHandle.Alloc(this))
            };

            SCNetworkReachabilitySetCallback(handle, callback, ref info);

            scheduledWithRunLoop =
                LoadRunLoopMode() &&
                SCNetworkReachabilityScheduleWithRunLoop(handle, CFRunLoopGetMain(), runLoopMode);

            SCNetworkReachabilityGetFlags(handle, out flags);
        }
Esempio n. 3
0
 static extern bool SCNetworkReachabilitySetCallback(IntPtr reachability, SCNetworkReachabilityCallback callback, ref SCNetworkReachabilityContext context);
Esempio n. 4
0
		public MacNetworkChange ()
		{
			var sockaddr = sockaddr_in.Create ();
			handle = SCNetworkReachabilityCreateWithAddress (IntPtr.Zero, ref sockaddr);
			if (handle == IntPtr.Zero)
				throw new Exception ("SCNetworkReachabilityCreateWithAddress returned NULL");

			callback = new SCNetworkReachabilityCallback (HandleCallback);
			var info = new SCNetworkReachabilityContext {
				info = GCHandle.ToIntPtr (GCHandle.Alloc (this))
			};

			SCNetworkReachabilitySetCallback (handle, callback, ref info);

			scheduledWithRunLoop =
			LoadRunLoopMode () &&
				SCNetworkReachabilityScheduleWithRunLoop (handle, CFRunLoopGetMain (), runLoopMode);

			SCNetworkReachabilityGetFlags (handle, out flags);
		}
Esempio n. 5
0
		static extern bool SCNetworkReachabilitySetCallback (IntPtr reachability, SCNetworkReachabilityCallback callback, ref SCNetworkReachabilityContext context);
 static extern /* Boolean */ bool SCNetworkReachabilitySetCallback(
     /* SCNetworkReachabilityRef __nonnull */ IntPtr handle,
     /* __nullable */ SCNetworkReachabilityCallBack callout,
     /* __nullable */ ref SCNetworkReachabilityContext context);
Esempio n. 7
0
		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;
		}
Esempio n. 8
0
		static extern /* Boolean */ bool SCNetworkReachabilitySetCallback (
			/* SCNetworkReachabilityRef __nonnull */ IntPtr handle, 
			/* __nullable */ SCNetworkReachabilityCallBack callout,
			/* __nullable */ ref SCNetworkReachabilityContext context);