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