[NUI] Add Obsolete attributes for EditorBrowsable apis
[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 using System;
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         [Obsolete("Please do not use! This will be deprecated!")]
309         [EditorBrowsable(EditorBrowsableState.Never)]
310         public override bool Equals(object o)
311         {
312             return base.Equals(o);
313         }
314
315         /// <summary>
316         /// Gets the the hash code of this baseHandle.
317         /// </summary>
318         /// <returns>The Hash Code.</returns>
319         /// <since_tizen> 4 </since_tizen>
320         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
321         [Obsolete("Please do not use! This will be deprecated!")]
322         [EditorBrowsable(EditorBrowsableState.Never)]
323         public override int GetHashCode()
324         {
325             return base.GetHashCode();
326         }
327
328         /// <summary>
329         /// Create an instance of BaseHandle.
330         /// </summary>
331         /// <since_tizen> 3 </since_tizen>
332         public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
333         {
334             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335         }
336
337         /// <summary>
338         /// Create an instance of BaseHandle.
339         /// </summary>
340         /// <param name="handle">The BaseHandle instance.</param>
341         /// <since_tizen> 3 </since_tizen>
342         public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
343         {
344             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345         }
346
347
348         /// <summary>
349         /// Performs an action on this object with the given action name and attributes.
350         /// </summary>
351         /// <param name="actionName">The command for the action.</param>
352         /// <param name="attributes">The list of attributes for the action.</param>
353         /// <returns>The action is performed by the object or not.</returns>
354         /// <since_tizen> 3 </since_tizen>
355         public bool DoAction(string actionName, PropertyMap attributes)
356         {
357             bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
358             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359             return ret;
360         }
361
362         /// <summary>
363         /// Returns the type name for the Handle.<br />
364         /// Will return an empty string if the typename does not exist. This will happen for types that
365         /// have not registered with type-registry.
366         /// </summary>
367         /// <returns>The type name. Empty string if the typename does not exist.</returns>
368         /// <since_tizen> 3 </since_tizen>
369         public string GetTypeName()
370         {
371             string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
372             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373             return ret;
374         }
375
376         /// <summary>
377         /// Returns the type info for the Handle.<br />
378         /// </summary>
379         /// <param name="info">The type information.</param>
380         /// <returns>True If get the type info.</returns>
381         /// <since_tizen> 3 </since_tizen>
382         public bool GetTypeInfo(TypeInfo info)
383         {
384             bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
385             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386             return ret;
387         }
388
389         /// <summary>
390         /// Resets the handle.
391         /// </summary>
392         /// <since_tizen> 3 </since_tizen>
393         public void Reset()
394         {
395             NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
396             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397         }
398
399         /// <summary>
400         /// To check the BaseHandle instance is equal or not.
401         /// </summary>
402         /// <param name="rhs">The baseHandle instance.</param>
403         /// <returns>True If equal.</returns>
404         /// <since_tizen> 3 </since_tizen>
405         public bool EqualTo(BaseHandle rhs)
406         {
407             bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
408             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409             return ret;
410         }
411
412         /// <summary>
413         /// To check the BaseHandle instance is equal or not.
414         /// </summary>
415         /// <param name="rhs">The baseHandle instance.</param>
416         /// <returns>True If not equal.</returns>
417         /// <since_tizen> 3 </since_tizen>
418         public bool NotEqualTo(BaseHandle rhs)
419         {
420             bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
421             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
422             return ret;
423         }
424
425         internal RefObject GetObjectPtr()
426         {
427             global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
428             RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
429             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
430             return ret;
431         }
432
433         /// <summary>
434         /// To check the BaseHandle instance has body or not.
435         /// </summary>
436         /// <returns>True If the baseHandle instance has body.</returns>
437         /// <since_tizen> 3 </since_tizen>
438         public bool HasBody()
439         {
440             if (disposed == true)
441             {
442                 return false;
443             }
444
445             bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
446             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
447             return ret;
448         }
449
450         /// <summary>
451         /// To check the BaseHandle instance is equal or not.
452         /// </summary>
453         /// <param name="rhs">The baseHandle instance.</param>
454         /// <returns>True If equal.</returns>
455         /// <since_tizen> 3 </since_tizen>
456         public bool IsEqual(BaseHandle rhs)
457         {
458             if (disposed == true)
459             {
460                 return false;
461             }
462
463             bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
464             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
465             return ret;
466         }
467
468         internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef
469         {
470             get
471             {
472                 return swigCPtr;
473             }
474         }
475
476     }
477
478 }