Merge "Add new Tizen.Security.PrivacyPrivilegeManager API PS1: Review Tizen.Security...
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseHandle.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     /// BaseHandle is a handle to an internal Dali resource.
23     /// </summary>
24     public class BaseHandle : global::System.IDisposable
25     {
26         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27         /// <summary>
28         /// swigCMemOwn
29         /// </summary>
30         /// <since_tizen> 3 </since_tizen>
31         protected bool swigCMemOwn;
32         private bool _registerMe;
33
34         internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
35         {
36             //to catch derived classes dali native exceptions
37             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
38
39             _registerMe = swigCMemOwn = cMemoryOwn;
40
41             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
42
43             // using copy constructor to create another native handle so Registry.Unregister works fine.
44             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
45             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
46
47             if (_registerMe)
48             {
49                 // Register this instance of BaseHandle in the registry.
50                 Registry.Register(this);
51             }
52         }
53
54         internal BaseHandle(global::System.IntPtr cPtr)
55         {
56             _registerMe = swigCMemOwn = true;
57
58             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
59
60             // using copy constructor to create another native handle so Registry.Unregister works fine.
61             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
62             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
63
64             if (_registerMe)
65             {
66                 // Register this instance of BaseHandle in the registry.
67                 Registry.Register(this);
68             }
69         }
70
71         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
72         {
73             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
74         }
75
76         //A Flag to check who called Dispose(). (By User or DisposeQueue)
77         private bool isDisposeQueued = false;
78
79         /// <summary>
80         /// A Flat to check if it is already disposed.
81         /// </summary>
82         /// <since_tizen> 3 </since_tizen>
83         protected bool disposed = false;
84
85         /// <summary>
86         /// Dispose.
87         /// </summary>
88         /// <since_tizen> 3 </since_tizen>
89         ~BaseHandle()
90         {
91             if (!isDisposeQueued)
92             {
93                 isDisposeQueued = true;
94                 DisposeQueue.Instance.Add(this);
95             }
96         }
97
98         /// <summary>
99         /// Dispose.
100         /// </summary>
101         /// <since_tizen> 3 </since_tizen>
102         public void Dispose()
103         {
104             //Throw excpetion if Dispose() is called in separate thread.
105             if (!Window.IsInstalled())
106             {
107                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
108             }
109
110             if (isDisposeQueued)
111             {
112                 Dispose(DisposeTypes.Implicit);
113             }
114             else
115             {
116                 Dispose(DisposeTypes.Explicit);
117                 System.GC.SuppressFinalize(this);
118             }
119         }
120
121         /// <summary>
122         /// Dispose.
123         /// </summary>
124         /// <since_tizen> 3 </since_tizen>
125         protected virtual void Dispose(DisposeTypes type)
126         {
127             if (disposed)
128             {
129                 return;
130             }
131
132             if (type == DisposeTypes.Explicit)
133             {
134                 //Called by User
135                 //Release your own managed resources here.
136                 //You should release all of your own disposable objects here.
137
138             }
139
140             //Release your own unmanaged resources here.
141             //You should not access any managed member here except static instance.
142             //because the execution order of Finalizes is non-deterministic.
143
144             //Unreference this instance from Registry.
145             if (_registerMe)
146             {
147                 Registry.Unregister(this);
148             }
149
150             if (swigCPtr.Handle != global::System.IntPtr.Zero)
151             {
152                 swigCMemOwn = false;
153                 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
154                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
155             }
156
157             disposed = true;
158         }
159
160         /// <summary>
161         /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
162         /// </summary>
163         /// <since_tizen> 3 </since_tizen>
164         public static bool operator true(BaseHandle handle)
165         {
166             // if the C# object is null, return false
167             if (BaseHandle.ReferenceEquals(handle, null))
168             {
169                 return false;
170             }
171             // returns true if the handle has a body, false otherwise
172             return handle.HasBody();
173         }
174
175         /// <summary>
176         /// Returns the bool false  to indicate that an operand is false and returns true otherwise.
177         /// </summary>
178         /// <since_tizen> 3 </since_tizen>
179         public static bool operator false(BaseHandle handle)
180         {
181             // if the C# object is null, return true
182             if (BaseHandle.ReferenceEquals(handle, null))
183             {
184                 return true;
185             }
186             return !handle.HasBody();
187         }
188
189         /// <summary>
190         /// Explicit conversion from Handle to bool.
191         /// </summary>
192         /// <since_tizen> 3 </since_tizen>
193         public static explicit operator bool(BaseHandle handle)
194         {
195             // if the C# object is null, return false
196             if (BaseHandle.ReferenceEquals(handle, null))
197             {
198                 return false;
199             }
200             // returns true if the handle has a body, false otherwise
201             return handle.HasBody();
202         }
203
204         /// <summary>
205         /// Equality operator
206         /// </summary>
207         /// <since_tizen> 3 </since_tizen>
208         public static bool operator ==(BaseHandle x, BaseHandle y)
209         {
210             // if the C# objects are the same return true
211             if (BaseHandle.ReferenceEquals(x, y))
212             {
213                 return true;
214             }
215             if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
216             {
217                 // drop into native code to see if both handles point to the same body
218                 return x.IsEqual(y);
219             }
220
221             if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
222             {
223                 if (y.HasBody()) return false;
224                 else return true;
225             }
226             if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
227             {
228                 if (x.HasBody()) return false;
229                 else return true;
230             }
231
232             return false;
233         }
234
235         /// <summary>
236         /// Inequality operator. Returns Null if either operand is Null
237         /// </summary>
238         /// <since_tizen> 3 </since_tizen>
239         public static bool operator !=(BaseHandle x, BaseHandle y)
240         {
241             return !(x == y);
242         }
243
244         /// <summary>
245         /// Logical AND operator.<br />
246         /// It's possible when doing a  operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
247         /// </summary>
248         /// <since_tizen> 3 </since_tizen>
249         public static BaseHandle operator &(BaseHandle x, BaseHandle y)
250         {
251             if (x == y)
252             {
253                 return x;
254             }
255             return null;
256         }
257
258         /// <summary>
259         /// Logical OR operator for ||.<br />
260         /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
261         /// </summary>
262         /// <since_tizen> 3 </since_tizen>
263         public static BaseHandle operator |(BaseHandle x, BaseHandle y)
264         {
265             if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
266             {
267                 if (x.HasBody())
268                 {
269                     return x;
270                 }
271                 if (y.HasBody())
272                 {
273                     return y;
274                 }
275                 return null;
276             }
277             return null;
278         }
279
280         /// <summary>
281         /// Logical ! operator
282         /// </summary>
283         /// <since_tizen> 3 </since_tizen>
284         public static bool operator !(BaseHandle x)
285         {
286             // if the C# object is null, return true
287             if (BaseHandle.ReferenceEquals(x, null))
288             {
289                 return true;
290             }
291             if (x.HasBody())
292             {
293                 return false;
294             }
295             return true;
296         }
297
298         /// <summary>
299         /// Create an instance of BaseHandle.
300         /// </summary>
301         /// <since_tizen> 3 </since_tizen>
302         public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
303         {
304             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305         }
306
307         /// <summary>
308         /// Create an instance of BaseHandle.
309         /// </summary>
310         /// <param name="handle">The BaseHandle instance.</param>
311         /// <since_tizen> 3 </since_tizen>
312         public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
313         {
314             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315         }
316
317
318         /// <summary>
319         /// Performs an action on this object with the given action name and attributes.
320         /// </summary>
321         /// <param name="actionName">The command for the action.</param>
322         /// <param name="attributes">The list of attributes for the action.</param>
323         /// <returns>The action is performed by the object or not.</returns>
324         /// <since_tizen> 3 </since_tizen>
325         public bool DoAction(string actionName, PropertyMap attributes)
326         {
327             bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
328             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329             return ret;
330         }
331
332         /// <summary>
333         /// Returns the type name for the Handle.<br />
334         /// Will return an empty string if the typename does not exist. This will happen for types that
335         /// have not registered with type-registry.
336         /// </summary>
337         /// <returns>The type name. Empty string if the typename does not exist.</returns>
338         /// <since_tizen> 3 </since_tizen>
339         public string GetTypeName()
340         {
341             string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
342             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343             return ret;
344         }
345
346         /// <summary>
347         /// Returns the type info for the Handle.<br />
348         /// </summary>
349         /// <param name="info">The type information.</param>
350         /// <returns>True If get the type info.</returns>
351         /// <since_tizen> 3 </since_tizen>
352         public bool GetTypeInfo(TypeInfo info)
353         {
354             bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
355             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356             return ret;
357         }
358
359         /// <summary>
360         /// Resets the handle.
361         /// </summary>
362         /// <since_tizen> 3 </since_tizen>
363         public void Reset()
364         {
365             NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
366             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367         }
368
369         /// <summary>
370         /// To check the BaseHandle instance is equal or not.
371         /// </summary>
372         /// <param name="rhs">The baseHandle instance.</param>
373         /// <returns>True If equal.</returns>
374         /// <since_tizen> 3 </since_tizen>
375         public bool EqualTo(BaseHandle rhs)
376         {
377             bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
378             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
379             return ret;
380         }
381
382         /// <summary>
383         /// To check the BaseHandle instance is equal or not.
384         /// </summary>
385         /// <param name="rhs">The baseHandle instance.</param>
386         /// <returns>True If not equal.</returns>
387         /// <since_tizen> 3 </since_tizen>
388         public bool NotEqualTo(BaseHandle rhs)
389         {
390             bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
391             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392             return ret;
393         }
394
395         internal RefObject GetObjectPtr()
396         {
397             global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
398             RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
399             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400             return ret;
401         }
402
403         /// <summary>
404         /// To check the BaseHandle instance has body or not.
405         /// </summary>
406         /// <returns>True If the baseHandle instance has body.</returns>
407         /// <since_tizen> 3 </since_tizen>
408         public bool HasBody()
409         {
410             if (disposed == true)
411             {
412                 return false;
413             }
414
415             bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
416             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417             return ret;
418         }
419
420         /// <summary>
421         /// To check the BaseHandle instance is equal or not.
422         /// </summary>
423         /// <param name="rhs">The baseHandle instance.</param>
424         /// <returns>True If equal.</returns>
425         /// <since_tizen> 3 </since_tizen>
426         public bool IsEqual(BaseHandle rhs)
427         {
428             if (disposed == true)
429             {
430                 return false;
431             }
432
433             bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
434             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435             return ret;
436         }
437
438         internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
439         {
440             get
441             {
442                 return swigCPtr;
443             }
444         }
445
446     }
447
448 }