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.
22 /// BaseHandle is a handle to an internal Dali resource.
24 /// <since_tizen> 3 </since_tizen>
25 public class BaseHandle : global::System.IDisposable
27 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 /// <since_tizen> 3 </since_tizen>
32 protected bool swigCMemOwn;
33 private bool _registerMe;
35 internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
37 //to catch derived classes dali native exceptions
38 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
40 _registerMe = swigCMemOwn = cMemoryOwn;
42 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
44 // using copy constructor to create another native handle so Registry.Unregister works fine.
45 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
46 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
50 // Register this instance of BaseHandle in the registry.
51 Registry.Register(this);
55 internal BaseHandle(global::System.IntPtr cPtr)
57 _registerMe = swigCMemOwn = true;
59 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
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();
67 // Register this instance of BaseHandle in the registry.
68 Registry.Register(this);
72 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
74 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
77 //A Flag to check who called Dispose(). (By User or DisposeQueue)
78 private bool isDisposeQueued = false;
81 /// A Flat to check if it is already disposed.
83 /// <since_tizen> 3 </since_tizen>
84 protected bool disposed = false;
89 /// <since_tizen> 3 </since_tizen>
94 isDisposeQueued = true;
95 DisposeQueue.Instance.Add(this);
102 /// <since_tizen> 3 </since_tizen>
103 public void Dispose()
105 //Throw excpetion if Dispose() is called in separate thread.
106 if (!Window.IsInstalled())
108 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
113 Dispose(DisposeTypes.Implicit);
117 Dispose(DisposeTypes.Explicit);
118 System.GC.SuppressFinalize(this);
125 /// <since_tizen> 3 </since_tizen>
126 protected virtual void Dispose(DisposeTypes type)
133 if (type == DisposeTypes.Explicit)
136 //Release your own managed resources here.
137 //You should release all of your own disposable objects here.
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.
145 //Unreference this instance from Registry.
148 Registry.Unregister(this);
151 if (swigCPtr.Handle != global::System.IntPtr.Zero)
154 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
155 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
162 /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
164 /// <since_tizen> 3 </since_tizen>
165 public static bool operator true(BaseHandle handle)
167 // if the C# object is null, return false
168 if (BaseHandle.ReferenceEquals(handle, null))
172 // returns true if the handle has a body, false otherwise
173 return handle.HasBody();
177 /// Returns the bool false to indicate that an operand is false and returns true otherwise.
179 /// <since_tizen> 3 </since_tizen>
180 public static bool operator false(BaseHandle handle)
182 // if the C# object is null, return true
183 if (BaseHandle.ReferenceEquals(handle, null))
187 return !handle.HasBody();
191 /// Explicit conversion from Handle to bool.
193 /// <since_tizen> 3 </since_tizen>
194 public static explicit operator bool(BaseHandle handle)
196 // if the C# object is null, return false
197 if (BaseHandle.ReferenceEquals(handle, null))
201 // returns true if the handle has a body, false otherwise
202 return handle.HasBody();
206 /// Equality operator
208 /// <since_tizen> 3 </since_tizen>
209 public static bool operator ==(BaseHandle x, BaseHandle y)
211 // if the C# objects are the same return true
212 if (BaseHandle.ReferenceEquals(x, y))
216 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
218 // drop into native code to see if both handles point to the same body
222 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
224 if (y.HasBody()) return false;
227 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
229 if (x.HasBody()) return false;
237 /// Inequality operator. Returns Null if either operand is Null
239 /// <since_tizen> 3 </since_tizen>
240 public static bool operator !=(BaseHandle x, BaseHandle y)
246 /// Logical AND operator.<br />
247 /// It's possible when doing a operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
249 /// <since_tizen> 3 </since_tizen>
250 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
260 /// Logical OR operator for ||.<br />
261 /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
263 /// <since_tizen> 3 </since_tizen>
264 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
266 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
282 /// Logical ! operator
284 /// <since_tizen> 3 </since_tizen>
285 public static bool operator !(BaseHandle x)
287 // if the C# object is null, return true
288 if (BaseHandle.ReferenceEquals(x, null))
302 /// <param name="o">The object should be compared.</param>
303 /// <returns>True if equal.</returns>
304 /// <since_tizen> 4 </since_tizen>
305 public override bool Equals(object o)
307 return base.Equals(o);
311 /// Gets the the hash code of this baseHandle.
313 /// <returns>The Hash Code.</returns>
314 /// <since_tizen> 4 </since_tizen>
315 public override int GetHashCode()
317 return base.GetHashCode();
321 /// Create an instance of BaseHandle.
323 /// <since_tizen> 3 </since_tizen>
324 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330 /// Create an instance of BaseHandle.
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)))
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341 /// Performs an action on this object with the given action name and attributes.
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)
349 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
350 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
359 /// <returns>The type name. Empty string if the typename does not exist.</returns>
360 /// <since_tizen> 3 </since_tizen>
361 public string GetTypeName()
363 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
364 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
369 /// Returns the type info for the Handle.<br />
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)
376 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
377 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
382 /// Resets the handle.
384 /// <since_tizen> 3 </since_tizen>
387 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
388 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392 /// To check the BaseHandle instance is equal or not.
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)
399 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
400 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405 /// To check the BaseHandle instance is equal or not.
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)
412 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
413 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417 internal RefObject GetObjectPtr()
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();
426 /// To check the BaseHandle instance has body or not.
428 /// <returns>True If the baseHandle instance has body.</returns>
429 /// <since_tizen> 3 </since_tizen>
430 public bool HasBody()
432 if (disposed == true)
437 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
438 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443 /// To check the BaseHandle instance is equal or not.
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)
450 if (disposed == true)
455 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
456 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
460 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef