[NUI] Fix Svace issue (#949)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / ActivatedSignalType.cs
1 /*
2  * Copyright(c) 2018 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 ActivatedSignalType : 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 ActivatedSignalType(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(ActivatedSignalType 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         ~ActivatedSignalType()
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                     Interop.ActivatedSignalType.delete_ActivatedSignalType(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 = Interop.ActivatedSignalType.ActivatedSignalType_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 = Interop.ActivatedSignalType.ActivatedSignalType_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                 Interop.ActivatedSignalType.ActivatedSignalType_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                 Interop.ActivatedSignalType.ActivatedSignalType_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="arg">The first value to pass to callbacks</param>
179         /// <since_tizen> 5 </since_tizen>
180         public void Emit(InputMethodContext arg)
181         {
182             Interop.ActivatedSignalType.ActivatedSignalType_Emit(swigCPtr, InputMethodContext.getCPtr(arg));
183             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184         }
185
186         /// <summary>
187         /// The contructor.
188         /// </summary>
189         /// <since_tizen> 3 </since_tizen>
190         public ActivatedSignalType() : this(Interop.ActivatedSignalType.new_ActivatedSignalType(), true)
191         {
192             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193         }
194
195     }
196
197 }