/* * Copyright(c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using global::System; using System.Runtime.InteropServices; namespace Tizen.NUI { internal class VisualEventSignal : IDisposable { public VisualEventSignal() : this(Interop.VisualEventSignal.New(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } ~VisualEventSignal() { if (!isDisposeQueued) { isDisposeQueued = true; DisposeQueue.Instance.Add(this); } } public void Dispose() { if (!Window.IsInstalled()) { throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread."); } if (isDisposeQueued) { Dispose(DisposeTypes.Implicit); } else { Dispose(DisposeTypes.Explicit); GC.SuppressFinalize(this); } } protected virtual void Dispose(DisposeTypes type) { if (disposed) { return; } if (type == DisposeTypes.Explicit) { //Called by User //Release your own managed resources here. //You should release all of your own disposable objects here. } //Release your own unmanaged resources here. //You should not access any managed member here except static instance. //because the execution order of Finalizes is non-deterministic. if (swigCPtr.Handle != IntPtr.Zero) { if (swigCMemOwn) { swigCMemOwn = false; Interop.VisualEventSignal.Delete(swigCPtr); } swigCPtr = new HandleRef(null, IntPtr.Zero); } disposed = true; } public bool Empty() { bool ret = Interop.VisualEventSignal.Empty(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } public uint GetConnectionCount() { uint ret = Interop.VisualEventSignal.GetConnectionCount(swigCPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } public void Connect(Delegate func) { NUILog.Debug("VisualEventSignal.Connect()!"); IntPtr ip = Marshal.GetFunctionPointerForDelegate(func); { Interop.VisualEventSignal.Connect(swigCPtr, new HandleRef(this, ip)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } public void Disconnect(Delegate func) { NUILog.Debug("VisualEventSignal.Disconnect()!"); IntPtr ip = Marshal.GetFunctionPointerForDelegate(func); { Interop.VisualEventSignal.Disconnect(swigCPtr, new HandleRef(this, ip)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } public void Emit(BaseComponents.View target, int visualIndex, int signalId) { Interop.VisualEventSignal.Emit(swigCPtr, BaseComponents.View.getCPtr(target), visualIndex, signalId); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal VisualEventSignal(IntPtr cPtr, bool cMemoryOwn) { swigCMemOwn = cMemoryOwn; swigCPtr = new HandleRef(this, cPtr); } internal static HandleRef getCPtr(VisualEventSignal obj) { return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr; } private HandleRef swigCPtr; protected bool swigCMemOwn; private bool isDisposeQueued = false; protected bool disposed = false; } }