public static CleanupNotifier.RegistrationToken RegisterForCleanup(IntPtr cleanupObjectCPtr, IntPtr notifyObjectCPtr, object notifyObject, Type notifyObjectType, CleanupNotifier.DisposeObjectDelegate disposeObjectDelegate, CleanupNotifier.DeleteObjectDelegate deleteObjectDelegate) { object obj = CleanupNotifier.cleanupIdToContext; CleanupNotifier.RegistrationToken result; lock (obj) { result = CleanupNotifier.RegistrationToken.Create(CleanupNotifier.cleanupIdToContext); CleanupNotifier.cleanupIdToContext[result.Identifier] = new CleanupNotifier.ObjectCleanupContext { NotifyObjectType = notifyObjectType, NotifyObject = notifyObject, DisposeObject = disposeObjectDelegate, DeleteObject = deleteObjectDelegate, CleanupObjectCPtr = cleanupObjectCPtr, NotifyObjectCPtr = notifyObjectCPtr }; if (CleanupNotifier.f__mgcache0 == null) { CleanupNotifier.f__mgcache0 = new CleanupNotifierBridge.CleanupDelegate(CleanupNotifier.PerformCleanup); } if (!CleanupNotifierBridge.RegisterCleanupDelegate(cleanupObjectCPtr, notifyObjectCPtr, CleanupNotifier.f__mgcache0, (IntPtr)result.Identifier)) { CleanupNotifier.cleanupIdToContext.Remove(result.Identifier); throw new NullReferenceException(string.Format("{0} (instance 0x{1:X}) can't be registered for cleanup with 0x{2:X}.", notifyObjectType, notifyObjectCPtr, cleanupObjectCPtr)); } FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) registered for cleanup when 0x{2:X} is destroyed", notifyObjectType, (long)notifyObjectCPtr, (long)cleanupObjectCPtr)); } return(result); }
public static void UnregisterForCleanup(ref CleanupNotifier.RegistrationToken token) { object obj = CleanupNotifier.cleanupIdToContext; lock (obj) { CleanupNotifier.ObjectCleanupContext objectCleanupContext; if (CleanupNotifier.cleanupIdToContext.TryGetValue(token.Identifier, out objectCleanupContext)) { CleanupNotifierBridge.UnregisterCleanupDelegate(objectCleanupContext.CleanupObjectCPtr, objectCleanupContext.NotifyObjectCPtr); CleanupNotifier.DeleteContext(ref token); FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) unregistered for cleanup when 0x{2:X} is destroyed", objectCleanupContext.NotifyObjectType, (long)objectCleanupContext.NotifyObjectCPtr, (long)objectCleanupContext.CleanupObjectCPtr)); } } }
public static void DisposeObject(ref CleanupNotifier.RegistrationToken token, object owner, bool delete) { object obj = CleanupNotifier.cleanupIdToContext; lock (obj) { CleanupNotifier.ObjectCleanupContext objectCleanupContext; if (CleanupNotifier.cleanupIdToContext.TryGetValue(token.Identifier, out objectCleanupContext)) { CleanupNotifier.DeleteContext(ref token); if (!CleanupNotifierBridge.GetAndDestroyNotifiedFlag(objectCleanupContext.NotifyObjectCPtr) && delete) { FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) being deleted", objectCleanupContext.NotifyObjectType, (long)objectCleanupContext.NotifyObjectCPtr)); objectCleanupContext.DeleteObject(new HandleRef(owner, objectCleanupContext.NotifyObjectCPtr)); FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) deleted", objectCleanupContext.NotifyObjectType, (long)objectCleanupContext.NotifyObjectCPtr)); } } } }
private static void PerformCleanup(IntPtr cleanupObjectCPtr, IntPtr notifyObjectCPtr, IntPtr context) { object obj = CleanupNotifier.cleanupIdToContext; lock (obj) { CleanupNotifier.ObjectCleanupContext objectCleanupContext; if (CleanupNotifier.cleanupIdToContext.TryGetValue((long)context, out objectCleanupContext)) { object notifyObject = objectCleanupContext.NotifyObject; if (notifyObject != null) { FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) will be disposed", objectCleanupContext.NotifyObjectType, (long)objectCleanupContext.NotifyObjectCPtr)); CleanupNotifierBridge.GetAndDestroyNotifiedFlag(notifyObjectCPtr); objectCleanupContext.DisposeObject(notifyObject); } else { FirebaseApp.LogMessage(LogLevel.Debug, string.Format("{0} (instance 0x{1:X}) is being finalized, deleting object now", objectCleanupContext.NotifyObjectType, (long)objectCleanupContext.NotifyObjectCPtr)); objectCleanupContext.DeleteObject(new HandleRef(objectCleanupContext.NotifyObjectType, notifyObjectCPtr)); } } } }
internal static HandleRef getCPtr(CleanupNotifierBridge obj) { return((obj != null) ? obj.swigCPtr : new HandleRef(null, IntPtr.Zero)); }