Merge "[ElmSharp] Fixed the crash issue of Calendar"
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / ImfEventSignalType.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 ImfEventSignalType : global::System.IDisposable
24     {
25         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26         /// <summary>
27         /// swigCMemOwn
28         /// </summary>
29         /// <since_tizen> 3 </since_tizen>
30         protected bool swigCMemOwn;
31
32         internal ImfEventSignalType(global::System.IntPtr cPtr, bool cMemoryOwn)
33         {
34             swigCMemOwn = cMemoryOwn;
35             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
36         }
37
38         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ImfEventSignalType obj)
39         {
40             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
41         }
42
43         //A Flag to check who called Dispose(). (By User or DisposeQueue)
44         private bool isDisposeQueued = false;
45         /// <summary>
46         /// A Flat to check if it is already disposed.
47         /// </summary>
48         /// <since_tizen> 3 </since_tizen>
49         protected bool disposed = false;
50
51         /// <summary>
52         /// Dispose
53         /// </summary>
54         /// <since_tizen> 3 </since_tizen>
55         ~ImfEventSignalType()
56         {
57             if (!isDisposeQueued)
58             {
59                 isDisposeQueued = true;
60                 DisposeQueue.Instance.Add(this);
61             }
62         }
63
64         /// <summary>
65         /// Dispose
66         /// </summary>
67         /// <since_tizen> 3 </since_tizen>
68         public void Dispose()
69         {
70             //Throw excpetion if Dispose() is called in separate thread.
71             if (!Window.IsInstalled())
72             {
73                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
74             }
75
76             if (isDisposeQueued)
77             {
78                 Dispose(DisposeTypes.Implicit);
79             }
80             else
81             {
82                 Dispose(DisposeTypes.Explicit);
83                 System.GC.SuppressFinalize(this);
84             }
85         }
86
87         /// <summary>
88         /// Dispose
89         /// </summary>
90         /// <since_tizen> 3 </since_tizen>
91         protected virtual void Dispose(DisposeTypes type)
92         {
93             if (disposed)
94             {
95                 return;
96             }
97
98             if (type == DisposeTypes.Explicit)
99             {
100                 //Called by User
101                 //Release your own managed resources here.
102                 //You should release all of your own disposable objects here.
103
104             }
105
106             //Release your own unmanaged resources here.
107             //You should not access any managed member here except static instance.
108             //because the execution order of Finalizes is non-deterministic.
109
110             if (swigCPtr.Handle != global::System.IntPtr.Zero)
111             {
112                 if (swigCMemOwn)
113                 {
114                     swigCMemOwn = false;
115                     NDalicManualPINVOKE.delete_ImfEventSignalType(swigCPtr);
116                 }
117                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
118             }
119
120             disposed = true;
121         }
122
123         /// <summary>
124         /// Queries whether there are any connected slots.
125         /// </summary>
126         /// <returns>True if there are any slots connected to the signal</returns>
127         /// <since_tizen> 3 </since_tizen>
128         public bool Empty()
129         {
130             bool ret = NDalicManualPINVOKE.ImfEventSignalType_Empty(swigCPtr);
131             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
132             return ret;
133         }
134
135         /// <summary>
136         /// Queries the number of slots.
137         /// </summary>
138         /// <returns>The number of slots connected to this signal</returns>
139         /// <since_tizen> 3 </since_tizen>
140         public uint GetConnectionCount()
141         {
142             uint ret = NDalicManualPINVOKE.ImfEventSignalType_GetConnectionCount(swigCPtr);
143             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144             return ret;
145         }
146
147         /// <summary>
148         /// Connects a function.
149         /// </summary>
150         /// <param name="func">The function to connect</param>
151         /// <since_tizen> 3 </since_tizen>
152         public void Connect(System.Delegate func)
153         {
154             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
155             {
156                 NDalicManualPINVOKE.ImfEventSignalType_Connect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
157                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158             }
159         }
160
161         /// <summary>
162         /// Disconnects a function.
163         /// </summary>
164         /// <param name="func">The function to disconnect</param>
165         /// <since_tizen> 3 </since_tizen>
166         public void Disconnect(System.Delegate func)
167         {
168             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
169             {
170                 NDalicManualPINVOKE.ImfEventSignalType_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
171                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172             }
173         }
174
175         /// <summary>
176         /// Emits the signal.
177         /// </summary>
178         /// <param name="arg1">The first value to pass to callbacks</param>
179         /// <param name="arg2">The second value to pass to callbacks</param>
180         /// <returns>The value returned by the last callback, or a default constructed value if no callbacks are connected</returns>
181         /// <since_tizen> 4 </since_tizen>
182         public ImfManager.ImfCallbackData Emit(ImfManager arg1, ImfManager.ImfEventData arg2)
183         {
184             ImfManager.ImfCallbackData ret = new ImfManager.ImfCallbackData(NDalicManualPINVOKE.ImfEventSignalType_Emit(swigCPtr, ImfManager.getCPtr(arg1), ImfManager.ImfEventData.getCPtr(arg2)), true);
185             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186             return ret;
187         }
188
189         /// <summary>
190         /// The contructor.
191         /// </summary>
192         /// <since_tizen> 3 </since_tizen>
193         public ImfEventSignalType() : this(NDalicManualPINVOKE.new_ImfEventSignalType(), true)
194         {
195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196         }
197
198     }
199
200 }