[NUI] Reduce code duplication - refactor dispose codes (#1010)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / StatusSignalType.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 StatusSignalType : Disposable
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 StatusSignalType(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(StatusSignalType obj)
39         {
40             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
41         }
42
43         /// <summary>
44         /// Dispose
45         /// </summary>
46         /// <since_tizen> 3 </since_tizen>
47         protected override void Dispose(DisposeTypes type)
48         {
49             if (disposed)
50             {
51                 return;
52             }
53
54             //Release your own unmanaged resources here.
55             //You should not access any managed member here except static instance.
56             //because the execution order of Finalizes is non-deterministic.
57
58             if (swigCPtr.Handle != global::System.IntPtr.Zero)
59             {
60                 if (swigCMemOwn)
61                 {
62                     swigCMemOwn = false;
63                     Interop.StatusSignalType.delete_StatusSignalType(swigCPtr);
64                 }
65                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
66             }
67
68             base.Dispose(type);
69         }
70
71         /// <summary>
72         /// Queries whether there are any connected slots.
73         /// </summary>
74         /// <returns>True if there are any slots connected to the signal</returns>
75         /// <since_tizen> 3 </since_tizen>
76         public bool Empty()
77         {
78             bool ret = Interop.StatusSignalType.StatusSignalType_Empty(swigCPtr);
79             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80             return ret;
81         }
82
83         /// <summary>
84         /// Queries the number of slots.
85         /// </summary>
86         /// <returns>The number of slots connected to this signal</returns>
87         /// <since_tizen> 3 </since_tizen>
88         public uint GetConnectionCount()
89         {
90             uint ret = Interop.StatusSignalType.StatusSignalType_GetConnectionCount(swigCPtr);
91             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92             return ret;
93         }
94
95         /// <summary>
96         /// Connects a function.
97         /// </summary>
98         /// <param name="func">The function to connect</param>
99         /// <since_tizen> 3 </since_tizen>
100         public void Connect(System.Delegate func)
101         {
102             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
103             {
104                 Interop.StatusSignalType.StatusSignalType_Connect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
105                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
106             }
107         }
108
109         /// <summary>
110         /// Disconnects a function.
111         /// </summary>
112         /// <param name="func">The function to disconnect</param>
113         /// <since_tizen> 3 </since_tizen>
114         public void Disconnect(System.Delegate func)
115         {
116             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
117             {
118                 Interop.StatusSignalType.StatusSignalType_Disconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip));
119                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120             }
121         }
122
123         /// <summary>
124         /// Connects a member function.
125         /// </summary>
126         /// <param name="arg">The member function to connect</param>
127         /// <since_tizen> 3 </since_tizen>
128         public void Emit(bool arg)
129         {
130             Interop.StatusSignalType.StatusSignalType_Emit(swigCPtr, arg);
131             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
132         }
133
134         /// <summary>
135         /// The constructor.
136         /// </summary>
137         /// <since_tizen> 3 </since_tizen>
138         public StatusSignalType() : this(Interop.StatusSignalType.new_StatusSignalType(), true)
139         {
140             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141         }
142     }
143 }