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