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