[NUI] Fix IsEqual
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Common / BaseHandle.cs
1 /*
2  * Copyright(c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using System.ComponentModel;
19 using System.Runtime.CompilerServices;
20 using Tizen.NUI.Binding;
21 using global::System.Diagnostics;
22
23 namespace Tizen.NUI
24 {
25     /// <summary>
26     /// BaseHandle is a handle to an internal Dali resource.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public class BaseHandle : Element, global::System.IDisposable
30     {
31         /// <summary>
32         /// swigCMemOwn
33         /// </summary>
34         /// <since_tizen> 3 </since_tizen>
35         [Obsolete("Deprecated in API9, will be removed in API11, Use SwigCMemOwn")]
36         [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
37         protected bool swigCMemOwn;
38
39         /// <summary>
40         /// The flag to check if it is already disposed of.
41         /// </summary>
42         /// <since_tizen> 3 </since_tizen>
43         [Obsolete("Deprecated in API9, will be removed in API11, Use Disposed")]
44         [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "<Pending>")]
45         protected bool disposed = false;
46
47         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
48         private global::System.Runtime.InteropServices.HandleRef swigCPtrCopy;
49         private bool registerMe;
50
51         //The flag to check who called Dispose(). (By User or DisposeQueue)
52         private bool isDisposeQueued = false;
53
54         /// <summary>
55         /// Create an instance of BaseHandle.
56         /// </summary>
57         /// <since_tizen> 3 </since_tizen>
58         public BaseHandle() : this(Interop.BaseHandle.NewBaseHandle())
59         {
60             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
61         }
62
63         /// <summary>
64         /// Create an instance of BaseHandle.
65         /// </summary>
66         /// <param name="handle">The BaseHandle instance.</param>
67         /// <since_tizen> 3 </since_tizen>
68         public BaseHandle(BaseHandle handle) : this(Interop.BaseHandle.NewBaseHandle(BaseHandle.getCPtr(handle)))
69         {
70             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
71         }
72
73         internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
74         {
75             //to catch derived classes dali native exceptions
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77
78             DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor with cMemeryOwn:{cMemoryOwn} START");
79
80             registerMe = swigCMemOwn = cMemoryOwn;
81             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
82             // using copy constructor to create another native handle so Registry.Unregister works fine.
83             swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(this, Interop.BaseHandle.NewBaseHandle(swigCPtr));
84             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
85
86             if (registerMe)
87             {
88                 // Register this instance of BaseHandle in the registry.
89                 Registry.Register(this);
90             }
91
92             disposeDebuggingCtor();
93             DebugFileLogging.Instance.WriteLog($" BaseHandle.contructor with cMemeryOwn END");
94             DebugFileLogging.Instance.WriteLog($"=============================");
95         }
96
97         internal BaseHandle(global::System.IntPtr cPtr)
98         {
99             DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor START");
100
101             registerMe = swigCMemOwn = true;
102
103             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
104
105             // using copy constructor to create another native handle so Registry.Unregister works fine.
106             swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(this, Interop.BaseHandle.NewBaseHandle(SwigCPtr));
107             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108
109             if (registerMe)
110             {
111                 // Register this instance of BaseHandle in the registry.
112                 Registry.Register(this);
113             }
114
115             disposeDebuggingCtor();
116             DebugFileLogging.Instance.WriteLog($"BaseHandle.contructor END");
117             DebugFileLogging.Instance.WriteLog($"=============================");
118         }
119
120         /// <summary>
121         /// Dispose.
122         /// </summary>
123         /// <since_tizen> 3 </since_tizen>
124         // following this guide: https://docs.microsoft.com/ko-kr/dotnet/fundamentals/code-analysis/quality-rules/ca1063?view=vs-2019 (CA1063)
125         ~BaseHandle() => Dispose(false);
126
127         /// <summary>
128         /// Event when a property is set.
129         /// </summary>
130         /// <since_tizen> 5 </since_tizen>
131         /// <seealso cref="BindableObject.PropertyChanged"/>
132         [Obsolete("Deprecated in API9, will be removed in API11, Use BindableObject.PropertyChanged instead.")]
133         public event PropertyChangedEventHandler PropertySet;
134
135         internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
136         {
137             get
138             {
139                 return swigCPtrCopy;
140             }
141         }
142
143         /// <summary>
144         /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
145         /// </summary>
146         /// <since_tizen> 3 </since_tizen>
147         public static bool operator true(BaseHandle handle)
148         {
149             // if the C# object is null, return false
150             if (BaseHandle.ReferenceEquals(handle, null))
151             {
152                 return false;
153             }
154             // returns true if the handle has a body, false otherwise
155             return handle.HasBody();
156         }
157
158         /// <summary>
159         /// Returns the bool false  to indicate that an operand is false and returns true otherwise.
160         /// </summary>
161         /// <since_tizen> 3 </since_tizen>
162         public static bool operator false(BaseHandle handle)
163         {
164             // if the C# object is null, return true
165             if (BaseHandle.ReferenceEquals(handle, null))
166             {
167                 return true;
168             }
169             return !handle.HasBody();
170         }
171
172         /// <summary>
173         /// Explicit conversion from Handle to bool.
174         /// </summary>
175         /// <since_tizen> 3 </since_tizen>
176         public static explicit operator bool(BaseHandle handle)
177         {
178             // if the C# object is null, return false
179             if (BaseHandle.ReferenceEquals(handle, null))
180             {
181                 return false;
182             }
183             // returns true if the handle has a body, false otherwise
184             return handle.HasBody();
185         }
186
187         /// <summary>
188         /// Equality operator
189         /// </summary>
190         /// <since_tizen> 3 </since_tizen>
191         public static bool operator ==(BaseHandle x, BaseHandle y)
192         {
193             // if the C# objects are the same return true
194             if (BaseHandle.ReferenceEquals(x, y))
195             {
196                 return true;
197             }
198             if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
199             {
200                 // drop into native code to see if both handles point to the same body
201                 return x.IsEqual(y);
202             }
203
204             if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
205             {
206                 if (y.HasBody()) return false;
207                 else return true;
208             }
209             if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
210             {
211                 if (x.HasBody()) return false;
212                 else return true;
213             }
214
215             return false;
216         }
217
218         /// <summary>
219         /// Inequality operator. Returns Null if either operand is Null
220         /// </summary>
221         /// <since_tizen> 3 </since_tizen>
222         public static bool operator !=(BaseHandle x, BaseHandle y)
223         {
224             return !(x == y);
225         }
226
227         /// <summary>
228         /// Logical AND operator.<br />
229         /// It's possible when doing a  operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
230         /// </summary>
231         /// <since_tizen> 3 </since_tizen>
232         public static BaseHandle operator &(BaseHandle x, BaseHandle y)
233         {
234             if (x == y)
235             {
236                 return x;
237             }
238             return null;
239         }
240
241         /// <summary>
242         /// Logical OR operator for ||.<br />
243         /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
244         /// </summary>
245         /// <since_tizen> 3 </since_tizen>
246         public static BaseHandle operator |(BaseHandle x, BaseHandle y)
247         {
248             if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
249             {
250                 if (x != null && x.HasBody())
251                 {
252                     return x;
253                 }
254                 if (y != null && y.HasBody())
255                 {
256                     return y;
257                 }
258                 return null;
259             }
260             return null;
261         }
262
263         /// <summary>
264         /// Logical ! operator
265         /// </summary>
266         /// <since_tizen> 3 </since_tizen>
267         public static bool operator !(BaseHandle x)
268         {
269             // if the C# object is null, return true
270             if (BaseHandle.ReferenceEquals(x, null))
271             {
272                 return true;
273             }
274             if (x.HasBody())
275             {
276                 return false;
277             }
278             return true;
279         }
280
281         /// <summary>
282         /// Equals
283         /// </summary>
284         /// <param name="o">The object should be compared.</param>
285         /// <returns>True if equal.</returns>
286         /// <since_tizen> 5 </since_tizen>
287         public override bool Equals(object o)
288         {
289             return base.Equals(o);
290         }
291
292         /// <summary>
293         /// Gets the hash code of this baseHandle.
294         /// </summary>
295         /// <returns>The hash code.</returns>
296         /// <since_tizen> 5 </since_tizen>
297         public override int GetHashCode()
298         {
299             return base.GetHashCode();
300         }
301
302         /// <summary>
303         /// Dispose.
304         /// </summary>
305         /// <since_tizen> 3 </since_tizen>
306         public void Dispose()
307         {
308             if (isDisposeQueued)
309             {
310                 Dispose(DisposeTypes.Implicit);
311             }
312             else
313             {
314                 Dispose(true);
315             }
316             GC.SuppressFinalize(this);
317         }
318
319         /// <summary>
320         /// Hidden API (Inhouse API).
321         /// Dispose. 
322         /// </summary>
323         /// <remarks>
324         /// Following the guide of https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose.
325         /// This will replace "protected virtual void Dispose(DisposeTypes type)" which is exactly same in functionality.
326         /// </remarks>
327         /// <param name="disposing">true in order to free managed objects</param>
328         // Protected implementation of Dispose pattern.
329         [EditorBrowsable(EditorBrowsableState.Never)]
330         protected virtual void Dispose(bool disposing)
331         {
332             if (disposed)
333             {
334                 return;
335             }
336
337             if (disposing)
338             {
339                 // TODO: dispose managed state (managed objects).
340                 // Explicit call. user calls Dispose()
341
342                 //Throw exception if Dispose() is called in separate thread.
343                 if (!Window.IsInstalled())
344                 {
345                     var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
346                     var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
347                     var me = this.GetType().FullName;
348
349                     DebugFileLogging.Instance.WriteLog("[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
350                         $" process:{process} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
351
352                     Tizen.Log.Fatal("NUI", $"[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
353                         $" process:{process} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
354
355                     //to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
356                     // throw new global::System.InvalidOperationException("[NUI][BaseHandle] This API called from separate thread. This API must be called from MainThread. \n" +
357                     //     $" process:{process} thread:{thread}, disposing:{disposing}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
358                 }
359
360                 if (isDisposeQueued)
361                 {
362                     DebugFileLogging.Instance.WriteLog($"should not be here! (dead code) this will be removed!");
363
364                     Tizen.Log.Fatal("NUI", $"[NUI] should not be here! (dead code) this will be removed!");
365
366                     //to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
367                     // throw new global::System.Exception($"[NUI] should not be here! (dead code) this will be removed!");
368                     Dispose(DisposeTypes.Implicit);
369                 }
370                 else
371                 {
372                     Dispose(DisposeTypes.Explicit);
373                 }
374             }
375             else
376             {
377                 // Implicit call. user doesn't call Dispose(), so this object is added into DisposeQueue to be disposed automatically.
378                 if (!isDisposeQueued)
379                 {
380                     isDisposeQueued = true;
381                     DisposeQueue.Instance.Add(this);
382                 }
383             }
384
385             // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
386             // TODO: set large fields to null.
387         }
388
389
390         /// <summary>
391         /// Performs an action on this object with the given action name and attributes.
392         /// </summary>
393         /// <param name="actionName">The command for the action.</param>
394         /// <param name="attributes">The list of attributes for the action.</param>
395         /// <returns>The action is performed by the object or not.</returns>
396         /// <since_tizen> 3 </since_tizen>
397         public bool DoAction(string actionName, PropertyMap attributes)
398         {
399             bool ret = Interop.BaseHandle.DoAction(swigCPtrCopy, actionName, PropertyMap.getCPtr(attributes));
400             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
401             return ret;
402         }
403
404         /// <summary>
405         /// Returns the type name for the Handle.<br />
406         /// Will return an empty string if the typename does not exist. This will happen for types that
407         /// have not registered with type-registry.
408         /// </summary>
409         /// <returns>The type name. Empty string if the typename does not exist.</returns>
410         /// <since_tizen> 3 </since_tizen>
411         public string GetTypeName()
412         {
413             string ret = Interop.BaseHandle.GetTypeName(swigCPtrCopy);
414             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
415             return ret;
416         }
417
418         /// <summary>
419         /// Returns the type info for the Handle.<br />
420         /// </summary>
421         /// <param name="info">The type information.</param>
422         /// <returns>True If get the type info.</returns>
423         /// <since_tizen> 3 </since_tizen>
424         public bool GetTypeInfo(Tizen.NUI.TypeInfo info)
425         {
426             bool ret = Interop.BaseHandle.GetTypeInfo(swigCPtrCopy, Tizen.NUI.TypeInfo.getCPtr(info));
427             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
428             return ret;
429         }
430
431         /// <summary>
432         /// Resets the handle.
433         /// </summary>
434         /// <since_tizen> 3 </since_tizen>
435         public void Reset()
436         {
437             Interop.BaseHandle.Reset(swigCPtrCopy);
438             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
439         }
440
441         /// <summary>
442         /// To check the BaseHandle instance is equal or not.
443         /// </summary>
444         /// <param name="rhs">The baseHandle instance.</param>
445         /// <returns>True If equal.</returns>
446         /// <since_tizen> 3 </since_tizen>
447         public bool EqualTo(BaseHandle rhs)
448         {
449             bool ret = Interop.BaseHandle.EqualTo(swigCPtrCopy, BaseHandle.getCPtr(rhs));
450             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
451             return ret;
452         }
453
454         /// <summary>
455         /// To check the BaseHandle instance is equal or not.
456         /// </summary>
457         /// <param name="rhs">The baseHandle instance.</param>
458         /// <returns>True If not equal.</returns>
459         /// <since_tizen> 3 </since_tizen>
460         public bool NotEqualTo(BaseHandle rhs)
461         {
462             bool ret = Interop.BaseHandle.NotEqualTo(swigCPtrCopy, BaseHandle.getCPtr(rhs));
463             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
464             return ret;
465         }
466
467         /// <summary>
468         /// To check the BaseHandle instance has body or not.
469         /// </summary>
470         /// <returns>True If the baseHandle instance has body.</returns>
471         /// <since_tizen> 3 </since_tizen>
472         public bool HasBody()
473         {
474             if (swigCPtrCopy.Handle == IntPtr.Zero)
475             {
476                 return false;
477             }
478
479             if (disposed == true)
480             {
481                 return false;
482             }
483             bool ret = Interop.BaseHandle.HasBody(swigCPtrCopy);
484             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
485             return ret;
486         }
487
488         /// <summary>
489         /// To check the BaseHandle instance is equal or not.
490         /// </summary>
491         /// <param name="rhs">The baseHandle instance.</param>
492         /// <returns>True If equal.</returns>
493         /// <since_tizen> 3 </since_tizen>
494         public bool IsEqual(BaseHandle rhs)
495         {
496             if (disposed == true || rhs == null || !rhs.HasBody())
497             {
498                 return false;
499             }
500
501             bool ret = Interop.BaseHandle.IsEqual(swigCPtrCopy, BaseHandle.getCPtr(rhs));
502             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
503             return ret;
504         }
505
506         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
507         {
508             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtrCopy;
509         }
510
511         internal void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
512         {
513             PropertySet?.Invoke(this, new PropertyChangedEventArgs(propertyName));
514         }
515
516         /// <summary>
517         /// Dispose.
518         /// </summary>
519         /// <since_tizen> 3 </since_tizen>
520         protected virtual void Dispose(DisposeTypes type)
521         {
522             if (disposed)
523             {
524                 return;
525             }
526
527             DebugFileLogging.Instance.WriteLog($"BaseHandle.Dispose({type}) START");
528
529             if (type == DisposeTypes.Explicit)
530             {
531                 //Called by User
532                 //Release your own managed resources here.
533                 //You should release all of your own disposable objects here.
534
535             }
536
537             //Release your own unmanaged resources here.
538             //You should not access any managed member here except static instance.
539             //because the execution order of Finalizes is non-deterministic.
540
541             //Unreference this instance from Registry.
542             if (registerMe)
543             {
544                 Registry.Unregister(this);
545             }
546
547             disposeDebuggingDispose(type);
548
549             if (SwigCPtr.Handle != IntPtr.Zero)
550             {
551                 if (swigCMemOwn)
552                 {
553                     swigCMemOwn = false;
554                     ReleaseSwigCPtr(SwigCPtr);
555                 }
556                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
557             }
558             else
559             {
560                 var me = this.GetType().FullName;
561                 DebugFileLogging.Instance.WriteLog($"[ERR] SwigCPtr is NULL, need to check! me:{me}");
562                 Log.Error("NUI", $"[ERR] SwigCPtr is NULL, need to check! me:{me}");
563             }
564
565             if (swigCPtrCopy.Handle != global::System.IntPtr.Zero)
566             {
567                 swigCMemOwn = false;
568                 Interop.BaseHandle.DeleteBaseHandle(swigCPtrCopy);
569                 swigCPtrCopy = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
570             }
571             else
572             {
573                 var me = this.GetType().FullName;
574                 DebugFileLogging.Instance.WriteLog($"[ERR] swigCPtrCopy is NULL, need to check! me:{me}");
575                 Log.Error("NUI", $"[ERR] swigCPtrCopy is NULL, need to check! me:{me}");
576             }
577
578             disposed = true;
579             DebugFileLogging.Instance.WriteLog($"BaseHandle.Dispose({type}) END");
580             DebugFileLogging.Instance.WriteLog($"=============================");
581             NUILog.Debug($"BaseHandle.Dispose({type}) END");
582             NUILog.Debug($"=============================");
583         }
584
585         /// <summary>
586         /// Release swigCPtr.
587         /// </summary>
588         /// <since_tizen> 6 </since_tizen>
589         /// This will not be public opened.
590         [EditorBrowsable(EditorBrowsableState.Never)]
591         protected virtual void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
592         {
593         }
594
595         /// <summary>
596         /// Contains event arguments for the FocusChangeRequested event.
597         /// </summary>
598         [Obsolete("Deprecated in API9; Will be removed in API11.")]
599         public class FocusRequestArgs : EventArgs
600         {
601
602             /// <summary>
603             /// Gets or sets a value that indicates the starting focus state of the element for which a focus change is requested.
604             /// </summary>
605             public bool Focus { get; set; }
606
607             /// <summary>
608             /// Gets or sets a value that indicates the ending focus state of the element for which a focus change is requested.
609             /// </summary>
610             public bool Result { get; set; }
611         }
612
613         internal global::System.Runtime.InteropServices.HandleRef SwigCPtr
614         {
615             get
616             {
617                 if (swigCPtr.Handle == IntPtr.Zero)
618                 {
619                     var process = global::System.Diagnostics.Process.GetCurrentProcess().Id;
620                     var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
621                     var me = this.GetType().FullName;
622
623                     Tizen.Log.Fatal("NUI", $"SwigCPtr Error! NUI's native dali object is already disposed. " +
624                         $"OR the native dali object handle of NUI becomes null! \n" +
625                         $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
626
627                     //to fix ArtApp black screen issue. this will be enabled after talking with ArtApp team and fixing it.
628                     // throw new ObjectDisposedException(nameof(SwigCPtr), $"Error! NUI's native dali object is already disposed. " +
629                     //     $"OR the native dali object handle of NUI becomes null! \n" +
630                     //     $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me}\n");
631                 }
632                 return swigCPtr;
633             }
634         }
635
636         internal bool IsNativeHandleInvalid()
637         {
638             return swigCPtr.Handle == IntPtr.Zero;
639         }
640
641         /// <summary>
642         /// swigCMemOwn
643         /// </summary>
644         [EditorBrowsable(EditorBrowsableState.Never)]
645         protected internal bool SwigCMemOwn => swigCMemOwn;
646
647         /// <summary>
648         /// The flag to check if it is already disposed of.
649         /// </summary>
650         [EditorBrowsable(EditorBrowsableState.Never)]
651         protected internal bool Disposed => disposed;
652
653         /// <summary>
654         /// The flag to check if it is disposed by DisposeQueue.
655         /// </summary>
656         [EditorBrowsable(EditorBrowsableState.Never)]
657         protected internal bool IsDisposeQueued => isDisposeQueued;
658
659         [Conditional("NUI_DISPOSE_DEBUG_ON")]
660         private void disposeDebuggingCtor()
661         {
662             DebugFileLogging.Instance.WriteLog($"type:{GetType()} copyNativeHandle:{swigCPtrCopy.Handle.ToString("X8")}");
663             if (this is BaseComponents.View view)
664             {
665                 DebugFileLogging.Instance.WriteLog($"ID:{view.ID} Name:{view.Name}");
666                 //back trace
667                 global::System.Diagnostics.StackTrace st = new global::System.Diagnostics.StackTrace(true);
668                 for (int i = 0; i < st.FrameCount; i++)
669                 {
670                     global::System.Diagnostics.StackFrame sf = st.GetFrame(i);
671                     DebugFileLogging.Instance.WriteLog($"[{i}] {sf.GetMethod()}");
672                 }
673             }
674         }
675
676         [Conditional("NUI_DISPOSE_DEBUG_ON")]
677         private void disposeDebuggingDispose(DisposeTypes type)
678         {
679             DebugFileLogging.Instance.WriteLog($"swigCMemOwn:{swigCMemOwn} type:{GetType()} copyNativeHandle:{swigCPtrCopy.Handle.ToString("X8")} HasBody:{HasBody()}");
680
681             if (swigCPtr.Handle != IntPtr.Zero && swigCPtrCopy.Handle != IntPtr.Zero && HasBody())
682             {
683                 using var currentProcess = global::System.Diagnostics.Process.GetCurrentProcess();
684                 var process = currentProcess.Id;
685                 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
686                 var me = this.GetType().FullName;
687                 var daliId = "unknown";
688                 var hash = this.GetType().GetHashCode();
689                 var name = "unknown";
690
691                 if (this is BaseComponents.View)
692                 {
693                     daliId = Interop.Actor.GetId(swigCPtrCopy).ToString();
694                     name = Interop.Actor.GetName(swigCPtrCopy);
695                     BaseObject tmp = new BaseObject(Interop.BaseHandle.GetBaseObject(swigCPtrCopy), false);
696                     var refCnt = tmp.ReferenceCount();
697                     tmp.Dispose();
698                     if (refCnt > 2)
699                     {
700                         DebugFileLogging.Instance.WriteLog($"[ERR] reference count is over than 2. Could be a memory leak. Need to check! \n" +
701                             $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me} \n" +
702                             $" disposeType:{type}, name:{name}, daliID:{daliId}, hash:{hash}, refCnt:{refCnt}");
703
704                         Log.Error("NUI", $"[ERR] reference count is over than 2. Could be a memory leak. Need to check! \n" +
705                             $" process:{process} thread:{thread}, isDisposed:{this.disposed}, isDisposeQueued:{this.isDisposeQueued}, me:{me} \n" +
706                             $" disposeType:{type}, name:{name}, daliID:{daliId}, hash:{hash}, refCnt:{refCnt}");
707                     }
708                 }
709             }
710         }
711
712     }
713 }