Merge "[MediaContent] Fixed possible deadlock issues of async methods."
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Radian.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI
18 {
19
20     /// <summary>
21     /// An angle in radians.
22     /// </summary>
23     public class Radian : global::System.IDisposable
24     {
25         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26         protected bool swigCMemOwn;
27
28         internal Radian(global::System.IntPtr cPtr, bool cMemoryOwn)
29         {
30             swigCMemOwn = cMemoryOwn;
31             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
32         }
33
34         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Radian obj)
35         {
36             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
37         }
38
39         //A Flag to check who called Dispose(). (By User or DisposeQueue)
40         private bool isDisposeQueued = false;
41         //A Flat to check if it is already disposed.
42         protected bool disposed = false;
43
44         ~Radian()
45         {
46             if(!isDisposeQueued)
47             {
48                 isDisposeQueued = true;
49                 DisposeQueue.Instance.Add(this);
50             }
51         }
52
53         public void Dispose()
54         {
55             //Throw excpetion if Dispose() is called in separate thread.
56             if (!Window.IsInstalled())
57             {
58                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
59             }
60
61             if (isDisposeQueued)
62             {
63                 Dispose(DisposeTypes.Implicit);
64             }
65             else
66             {
67                 Dispose(DisposeTypes.Explicit);
68                 System.GC.SuppressFinalize(this);
69             }
70         }
71
72         protected virtual void Dispose(DisposeTypes type)
73         {
74             if (disposed)
75             {
76                 return;
77             }
78
79             if(type == DisposeTypes.Explicit)
80             {
81                 //Called by User
82                 //Release your own managed resources here.
83                 //You should release all of your own disposable objects here.
84             }
85
86             //Release your own unmanaged resources here.
87             //You should not access any managed member here except static instance.
88             //because the execution order of Finalizes is non-deterministic.
89
90             if (swigCPtr.Handle != global::System.IntPtr.Zero)
91             {
92                 if (swigCMemOwn)
93                 {
94                     swigCMemOwn = false;
95                     NDalicPINVOKE.delete_Radian(swigCPtr);
96                 }
97                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
98             }
99             disposed = true;
100         }
101
102
103         /// <summary>
104         /// The default constructor, initializes to 0.
105         /// </summary>
106         /// <since_tizen> 3 </since_tizen>
107         public Radian() : this(NDalicPINVOKE.new_Radian__SWIG_0(), true)
108         {
109             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110         }
111
112         /// <summary>
113         /// Creates an angle in radians.
114         /// </summary>
115         /// <param name="value">The initial value in radians.</param>
116         /// <since_tizen> 3 </since_tizen>
117         public Radian(float value) : this(NDalicPINVOKE.new_Radian__SWIG_1(value), true)
118         {
119             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120         }
121
122         /// <summary>
123         /// Creates an angle in radians from an angle in degrees.
124         /// </summary>
125         /// <param name="degree">The initial value in degrees.</param>
126         /// <since_tizen> 3 </since_tizen>
127         public Radian(Degree degree) : this(NDalicPINVOKE.new_Radian__SWIG_2(Degree.getCPtr(degree)), true)
128         {
129             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
130         }
131
132         /// <summary>
133         /// Conversion to float.
134         /// </summary>
135         /// <returns>The float value of this radian.</returns>
136         /// <since_tizen> 3 </since_tizen>
137         public float ConvertToFloat()
138         {
139             float ret = NDalicPINVOKE.Radian_ConvertToFloat(swigCPtr);
140             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141             return ret;
142         }
143
144         /// <summary>
145         /// The value in radians.
146         /// </summary>
147         /// <since_tizen> 3 </since_tizen>
148         public float Value
149         {
150             set
151             {
152                 NDalicPINVOKE.Radian_radian_set(swigCPtr, value);
153                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154             }
155             get
156             {
157                 float ret = NDalicPINVOKE.Radian_radian_get(swigCPtr);
158                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159                 return ret;
160             }
161         }
162
163     }
164
165 }