Merge "[ElmSharp] Fixed the crash issue of Calendar"
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / SlotObserver.cs
1 /*
2  * Copyright(c) 2017 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.Runtime.InteropServices;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI
22 {
23     internal class SlotObserver : global::System.IDisposable
24     {
25         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26         /// <summary>swigCMemOwn.</summary>
27         /// <since_tizen> 4 </since_tizen>
28         protected bool swigCMemOwn;
29
30         internal SlotObserver(global::System.IntPtr cPtr, bool cMemoryOwn)
31         {
32             swigCMemOwn = cMemoryOwn;
33             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34         }
35
36         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SlotObserver obj)
37         {
38             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39         }
40
41         //A Flag to check who called Dispose(). (By User or DisposeQueue)
42         private bool isDisposeQueued = false;
43         /// <summary>
44         /// A Flat to check if it is already disposed.
45         /// </summary>
46         /// <since_tizen> 4 </since_tizen>
47         protected bool disposed = false;
48
49         /// <summary>
50         /// Dispose.
51         /// </summary>
52         /// <since_tizen> 3 </since_tizen>
53         ~SlotObserver()
54         {
55             if (!isDisposeQueued)
56             {
57                 isDisposeQueued = true;
58                 DisposeQueue.Instance.Add(this);
59             }
60         }
61
62         /// <summary>
63         /// Dispose.
64         /// </summary>
65         /// <since_tizen> 4 </since_tizen>
66         public void Dispose()
67         {
68             //Throw excpetion if Dispose() is called in separate thread.
69             if (!Window.IsInstalled())
70             {
71                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
72             }
73
74             if (isDisposeQueued)
75             {
76                 Dispose(DisposeTypes.Implicit);
77             }
78             else
79             {
80                 Dispose(DisposeTypes.Explicit);
81                 System.GC.SuppressFinalize(this);
82             }
83         }
84
85         /// <summary>
86         /// Dispose.
87         /// </summary>
88         /// <since_tizen> 4 </since_tizen>
89         protected virtual void Dispose(DisposeTypes type)
90         {
91             if (disposed)
92             {
93                 return;
94             }
95
96             if (type == DisposeTypes.Explicit)
97             {
98                 //Called by User
99                 //Release your own managed resources here.
100                 //You should release all of your own disposable objects here.
101
102             }
103
104             //Release your own unmanaged resources here.
105             //You should not access any managed member here except static instance.
106             //because the execution order of Finalizes is non-deterministic.
107
108             if (swigCPtr.Handle != global::System.IntPtr.Zero)
109             {
110                 if (swigCMemOwn)
111                 {
112                     swigCMemOwn = false;
113                     NDalicPINVOKE.delete_SlotObserver(swigCPtr);
114                 }
115                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
116             }
117
118             disposed = true;
119         }
120
121         /// <summary>
122         /// This method is called when the slot is disconnecting.
123         /// </summary>
124         /// <param name="callback">The callback attached to the signal disconnected.</param>
125         /// <since_tizen> 4 </since_tizen>
126         public virtual void SlotDisconnected(SWIGTYPE_p_Dali__CallbackBase callback)
127         {
128             NDalicPINVOKE.SlotObserver_SlotDisconnected(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
129             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130         }
131
132     }
133
134 }