2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
24 /// BaseHandle is a handle to an internal Dali resource.
26 /// <since_tizen> 3 </since_tizen>
27 public class BaseHandle : global::System.IDisposable
29 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
33 /// <since_tizen> 3 </since_tizen>
34 protected bool swigCMemOwn;
35 private bool _registerMe;
37 internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
39 //to catch derived classes dali native exceptions
40 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
42 _registerMe = swigCMemOwn = cMemoryOwn;
44 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
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();
52 // Register this instance of BaseHandle in the registry.
53 Registry.Register(this);
57 internal BaseHandle(global::System.IntPtr cPtr)
59 _registerMe = swigCMemOwn = true;
61 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
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();
69 // Register this instance of BaseHandle in the registry.
70 Registry.Register(this);
74 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
76 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
79 //A Flag to check who called Dispose(). (By User or DisposeQueue)
80 private bool isDisposeQueued = false;
83 /// A Flat to check if it is already disposed.
85 /// <since_tizen> 3 </since_tizen>
86 protected bool disposed = false;
91 /// <since_tizen> 3 </since_tizen>
96 isDisposeQueued = true;
97 DisposeQueue.Instance.Add(this);
104 /// <since_tizen> 3 </since_tizen>
105 public void Dispose()
107 //Throw excpetion if Dispose() is called in separate thread.
108 if (!Window.IsInstalled())
110 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
115 Dispose(DisposeTypes.Implicit);
119 Dispose(DisposeTypes.Explicit);
120 System.GC.SuppressFinalize(this);
127 /// <since_tizen> 3 </since_tizen>
128 protected virtual void Dispose(DisposeTypes type)
135 if (type == DisposeTypes.Explicit)
138 //Release your own managed resources here.
139 //You should release all of your own disposable objects here.
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.
147 //Unreference this instance from Registry.
150 Registry.Unregister(this);
153 if (swigCPtr.Handle != global::System.IntPtr.Zero)
156 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
157 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
164 /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
166 /// <since_tizen> 3 </since_tizen>
167 public static bool operator true(BaseHandle handle)
169 // if the C# object is null, return false
170 if (BaseHandle.ReferenceEquals(handle, null))
174 // returns true if the handle has a body, false otherwise
175 return handle.HasBody();
179 /// Returns the bool false to indicate that an operand is false and returns true otherwise.
181 /// <since_tizen> 3 </since_tizen>
182 public static bool operator false(BaseHandle handle)
184 // if the C# object is null, return true
185 if (BaseHandle.ReferenceEquals(handle, null))
189 return !handle.HasBody();
193 /// Explicit conversion from Handle to bool.
195 /// <since_tizen> 3 </since_tizen>
196 public static explicit operator bool(BaseHandle handle)
198 // if the C# object is null, return false
199 if (BaseHandle.ReferenceEquals(handle, null))
203 // returns true if the handle has a body, false otherwise
204 return handle.HasBody();
208 /// Equality operator
210 /// <since_tizen> 3 </since_tizen>
211 public static bool operator ==(BaseHandle x, BaseHandle y)
213 // if the C# objects are the same return true
214 if (BaseHandle.ReferenceEquals(x, y))
218 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
220 // drop into native code to see if both handles point to the same body
224 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
226 if (y.HasBody()) return false;
229 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
231 if (x.HasBody()) return false;
239 /// Inequality operator. Returns Null if either operand is Null
241 /// <since_tizen> 3 </since_tizen>
242 public static bool operator !=(BaseHandle x, BaseHandle y)
248 /// Logical AND operator.<br />
249 /// It's possible when doing a operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
251 /// <since_tizen> 3 </since_tizen>
252 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
262 /// Logical OR operator for ||.<br />
263 /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
265 /// <since_tizen> 3 </since_tizen>
266 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
268 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
284 /// Logical ! operator
286 /// <since_tizen> 3 </since_tizen>
287 public static bool operator !(BaseHandle x)
289 // if the C# object is null, return true
290 if (BaseHandle.ReferenceEquals(x, null))
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)
312 return base.Equals(o);
316 /// Gets the the hash code of this baseHandle.
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()
325 return base.GetHashCode();
329 /// Create an instance of BaseHandle.
331 /// <since_tizen> 3 </since_tizen>
332 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
334 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338 /// Create an instance of BaseHandle.
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)))
344 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349 /// Performs an action on this object with the given action name and attributes.
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)
357 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
367 /// <returns>The type name. Empty string if the typename does not exist.</returns>
368 /// <since_tizen> 3 </since_tizen>
369 public string GetTypeName()
371 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377 /// Returns the type info for the Handle.<br />
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)
384 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
385 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
390 /// Resets the handle.
392 /// <since_tizen> 3 </since_tizen>
395 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
396 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 /// To check the BaseHandle instance is equal or not.
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)
407 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
408 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
413 /// To check the BaseHandle instance is equal or not.
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)
420 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
421 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425 internal RefObject GetObjectPtr()
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();
434 /// To check the BaseHandle instance has body or not.
436 /// <returns>True If the baseHandle instance has body.</returns>
437 /// <since_tizen> 3 </since_tizen>
438 public bool HasBody()
440 if (disposed == true)
445 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
446 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
451 /// To check the BaseHandle instance is equal or not.
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)
458 if (disposed == true)
463 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
464 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef