Beispiel #1
0
 static void UnmanagedNetworkChanged(IntPtr monitorPtr, bool available)
 {
     try {
         var monitor = (INetworkMonitor)Object.GetInstance(monitorPtr, Transfer.None);
         monitor.OnNetworkChanged(available);
     }
     catch (Exception ex) {
         ex.LogUnhandledException();
     }
 }
Beispiel #2
0
 static void UnmanagedCanReachAsyncFinish(IntPtr monitorPtr, IntPtr result, ref IntPtr errorPtr)
 {
     try {
         var monitor = (INetworkMonitor)Object.GetInstance(monitorPtr, Transfer.None);
         monitor.CanReachFinish(result);
     } catch (GErrorException ex) {
         GMarshal.PropagateError(errorPtr, ex.Error);
     }
     catch (Exception ex) {
         // FIXME: convert managed exception to GError
         ex.LogUnhandledException();
     }
 }
Beispiel #3
0
 static void UnmanagedCanReachAsync(IntPtr monitorPtr, IntPtr connectablePtr, IntPtr cancellablePtr, Action <IntPtr, IntPtr, IntPtr> callback, IntPtr userData)
 {
     try {
         var             monitor         = (INetworkMonitor)Object.GetInstance(monitorPtr, Transfer.None);
         Action <IntPtr> managedCallback = (result) => {
             callback(monitorPtr, result, userData);
         };
         monitor.CanReachAsync(connectablePtr, cancellablePtr, managedCallback);
     }
     catch (Exception ex) {
         ex.LogUnhandledException();
     }
 }
Beispiel #4
0
        public static Object New(GType objectType, params object[] parameters)
        {
            IntPtr errorPtr;
            var    ret_ = g_initable_newv(objectType, 0, IntPtr.Zero, IntPtr.Zero, out errorPtr);

            if (errorPtr != IntPtr.Zero)
            {
                var error = Opaque.GetInstance <Error> (errorPtr, Transfer.Full);
                throw new GErrorException(error);
            }
            var ret = Object.GetInstance(ret_, Transfer.Full);

            return(ret);
        }
Beispiel #5
0
 static bool UnmanagedInit(IntPtr initablePtr, IntPtr cancellablePtr, ref IntPtr errorPtr)
 {
     try {
         var initable = (IInitable)Object.GetInstance(initablePtr, Transfer.None);
         var ret      = initable.Init(cancellablePtr);
         return(ret);
     }
     catch (GErrorException ex) {
         GMarshal.PropagateError(errorPtr, ex.Error);
     }
     catch (Exception ex) {
         // FIXME: we should convert managed exception to GError
         ex.LogUnhandledException();
     }
     return(false);
 }
Beispiel #6
0
 static bool UnmanagedCanReach(IntPtr monitorPtr, IntPtr connectablePtr, IntPtr cancellablePtr, ref IntPtr errorPtr)
 {
     try {
         var monitor = (INetworkMonitor)Object.GetInstance(monitorPtr, Transfer.None);
         var ret     = monitor.CanReach(connectablePtr, cancellablePtr);
         return(ret);
     }
     catch (GErrorException ex) {
         GMarshal.PropagateError(errorPtr, ex.Error);
     }
     catch (Exception ex) {
         // FIXME: convert managed exception to GError
         ex.LogUnhandledException();
     }
     return(false);
 }
Beispiel #7
0
        public void TestReferences()
        {
            using (var o1 = new Object()) {
                var handle = o1.Handle;

                // getting an object that already exists should return that object
                var o2 = Object.GetInstance(handle, Transfer.None);
                try {
                    Assert.That(ReferenceEquals(o1, o2), Is.True);

                    // Simulate unmanaged code taking a reference so that the handle is
                    // not freed when o1 is disposed.
                    g_object_ref(handle);

                    // After an object is disposed we should get a new object rather
                    // than the disposed object.
                    o1.Dispose();

                    // Normally, we would not dispose an object if there is a possibility
                    // that it could be used again because it will loose any state that
                    // is stored in the managed object. Instead, a GCHandle will keep
                    // the object alive as long as unmanaged code has a reference to the
                    // object.

                    // Transfer.All means the new object takes ownership of the reference
                    // from the manual call to g_object_ref(), so we don't need to call
                    // g_object_unref() manually.
                    o2 = Object.GetInstance(handle, Transfer.Full);
                    Assert.That(ReferenceEquals(o1, o2), Is.False);
                }
                finally {
                    o2.Dispose();
                }
            }

            Utility.AssertNoGLibLog();
        }