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.
21 /// BaseHandle is a handle to an internal Dali resource.
23 /// <since_tizen> 3 </since_tizen>
24 public class BaseHandle : global::System.IDisposable
26 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30 /// <since_tizen> 3 </since_tizen>
31 protected bool swigCMemOwn;
32 private bool _registerMe;
34 internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
36 //to catch derived classes dali native exceptions
37 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
39 _registerMe = swigCMemOwn = cMemoryOwn;
41 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
43 // using copy constructor to create another native handle so Registry.Unregister works fine.
44 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
45 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
49 // Register this instance of BaseHandle in the registry.
50 Registry.Register(this);
54 internal BaseHandle(global::System.IntPtr cPtr)
56 _registerMe = swigCMemOwn = true;
58 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
60 // using copy constructor to create another native handle so Registry.Unregister works fine.
61 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
62 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
66 // Register this instance of BaseHandle in the registry.
67 Registry.Register(this);
71 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
73 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
76 //A Flag to check who called Dispose(). (By User or DisposeQueue)
77 private bool isDisposeQueued = false;
80 /// A Flat to check if it is already disposed.
82 /// <since_tizen> 3 </since_tizen>
83 protected bool disposed = false;
88 /// <since_tizen> 3 </since_tizen>
93 isDisposeQueued = true;
94 DisposeQueue.Instance.Add(this);
101 /// <since_tizen> 3 </since_tizen>
102 public void Dispose()
104 //Throw excpetion if Dispose() is called in separate thread.
105 if (!Window.IsInstalled())
107 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
112 Dispose(DisposeTypes.Implicit);
116 Dispose(DisposeTypes.Explicit);
117 System.GC.SuppressFinalize(this);
124 /// <since_tizen> 3 </since_tizen>
125 protected virtual void Dispose(DisposeTypes type)
132 if (type == DisposeTypes.Explicit)
135 //Release your own managed resources here.
136 //You should release all of your own disposable objects here.
140 //Release your own unmanaged resources here.
141 //You should not access any managed member here except static instance.
142 //because the execution order of Finalizes is non-deterministic.
144 //Unreference this instance from Registry.
147 Registry.Unregister(this);
150 if (swigCPtr.Handle != global::System.IntPtr.Zero)
153 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
154 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
161 /// Returns the bool value true to indicate that an operand is true and returns false otherwise.
163 /// <since_tizen> 3 </since_tizen>
164 public static bool operator true(BaseHandle handle)
166 // if the C# object is null, return false
167 if (BaseHandle.ReferenceEquals(handle, null))
171 // returns true if the handle has a body, false otherwise
172 return handle.HasBody();
176 /// Returns the bool false to indicate that an operand is false and returns true otherwise.
178 /// <since_tizen> 3 </since_tizen>
179 public static bool operator false(BaseHandle handle)
181 // if the C# object is null, return true
182 if (BaseHandle.ReferenceEquals(handle, null))
186 return !handle.HasBody();
190 /// Explicit conversion from Handle to bool.
192 /// <since_tizen> 3 </since_tizen>
193 public static explicit operator bool(BaseHandle handle)
195 // if the C# object is null, return false
196 if (BaseHandle.ReferenceEquals(handle, null))
200 // returns true if the handle has a body, false otherwise
201 return handle.HasBody();
205 /// Equality operator
207 /// <since_tizen> 3 </since_tizen>
208 public static bool operator ==(BaseHandle x, BaseHandle y)
210 // if the C# objects are the same return true
211 if (BaseHandle.ReferenceEquals(x, y))
215 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
217 // drop into native code to see if both handles point to the same body
221 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
223 if (y.HasBody()) return false;
226 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
228 if (x.HasBody()) return false;
236 /// Inequality operator. Returns Null if either operand is Null
238 /// <since_tizen> 3 </since_tizen>
239 public static bool operator !=(BaseHandle x, BaseHandle y)
245 /// Logical AND operator.<br />
246 /// It's possible when doing a operator this function (opBitwiseAnd) is never called due to short circuiting.<br />
248 /// <since_tizen> 3 </since_tizen>
249 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
259 /// Logical OR operator for ||.<br />
260 /// It's possible when doing a || this function (opBitwiseOr) is never called due to short circuiting.<br />
262 /// <since_tizen> 3 </since_tizen>
263 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
265 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
281 /// Logical ! operator
283 /// <since_tizen> 3 </since_tizen>
284 public static bool operator !(BaseHandle x)
286 // if the C# object is null, return true
287 if (BaseHandle.ReferenceEquals(x, null))
301 /// <param name="o">The object should be compared.</param>
302 /// <returns>True if equal.</returns>
303 /// <since_tizen> 5 </since_tizen>
304 public override bool Equals(object o)
306 return base.Equals(o);
310 /// Gets the the hash code of this baseHandle.
312 /// <returns>The Hash Code.</returns>
313 /// <since_tizen> 5 </since_tizen>
314 public override int GetHashCode()
316 return base.GetHashCode();
320 /// Create an instance of BaseHandle.
322 /// <since_tizen> 3 </since_tizen>
323 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
325 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329 /// Create an instance of BaseHandle.
331 /// <param name="handle">The BaseHandle instance.</param>
332 /// <since_tizen> 3 </since_tizen>
333 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
335 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340 /// Performs an action on this object with the given action name and attributes.
342 /// <param name="actionName">The command for the action.</param>
343 /// <param name="attributes">The list of attributes for the action.</param>
344 /// <returns>The action is performed by the object or not.</returns>
345 /// <since_tizen> 3 </since_tizen>
346 public bool DoAction(string actionName, PropertyMap attributes)
348 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
349 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354 /// Returns the type name for the Handle.<br />
355 /// Will return an empty string if the typename does not exist. This will happen for types that
356 /// have not registered with type-registry.
358 /// <returns>The type name. Empty string if the typename does not exist.</returns>
359 /// <since_tizen> 3 </since_tizen>
360 public string GetTypeName()
362 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 /// Returns the type info for the Handle.<br />
370 /// <param name="info">The type information.</param>
371 /// <returns>True If get the type info.</returns>
372 /// <since_tizen> 3 </since_tizen>
373 public bool GetTypeInfo(TypeInfo info)
375 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
376 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381 /// Resets the handle.
383 /// <since_tizen> 3 </since_tizen>
386 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
387 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 /// To check the BaseHandle instance is equal or not.
393 /// <param name="rhs">The baseHandle instance.</param>
394 /// <returns>True If equal.</returns>
395 /// <since_tizen> 3 </since_tizen>
396 public bool EqualTo(BaseHandle rhs)
398 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
399 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
404 /// To check the BaseHandle instance is equal or not.
406 /// <param name="rhs">The baseHandle instance.</param>
407 /// <returns>True If not equal.</returns>
408 /// <since_tizen> 3 </since_tizen>
409 public bool NotEqualTo(BaseHandle rhs)
411 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
412 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
416 internal RefObject GetObjectPtr()
418 global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
419 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
420 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425 /// To check the BaseHandle instance has body or not.
427 /// <returns>True If the baseHandle instance has body.</returns>
428 /// <since_tizen> 3 </since_tizen>
429 public bool HasBody()
431 if (disposed == true)
436 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
437 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
442 /// To check the BaseHandle instance is equal or not.
444 /// <param name="rhs">The baseHandle instance.</param>
445 /// <returns>True If equal.</returns>
446 /// <since_tizen> 3 </since_tizen>
447 public bool IsEqual(BaseHandle rhs)
449 if (disposed == true)
454 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
455 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
459 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef