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))
300 /// Create an instance of BaseHandle.
302 /// <since_tizen> 3 </since_tizen>
303 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
305 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309 /// Create an instance of BaseHandle.
311 /// <param name="handle">The BaseHandle instance.</param>
312 /// <since_tizen> 3 </since_tizen>
313 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
315 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 /// Performs an action on this object with the given action name and attributes.
322 /// <param name="actionName">The command for the action.</param>
323 /// <param name="attributes">The list of attributes for the action.</param>
324 /// <returns>The action is performed by the object or not.</returns>
325 /// <since_tizen> 3 </since_tizen>
326 public bool DoAction(string actionName, PropertyMap attributes)
328 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 /// Returns the type name for the Handle.<br />
335 /// Will return an empty string if the typename does not exist. This will happen for types that
336 /// have not registered with type-registry.
338 /// <returns>The type name. Empty string if the typename does not exist.</returns>
339 /// <since_tizen> 3 </since_tizen>
340 public string GetTypeName()
342 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 /// Returns the type info for the Handle.<br />
350 /// <param name="info">The type information.</param>
351 /// <returns>True If get the type info.</returns>
352 /// <since_tizen> 3 </since_tizen>
353 public bool GetTypeInfo(TypeInfo info)
355 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361 /// Resets the handle.
363 /// <since_tizen> 3 </since_tizen>
366 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
367 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
371 /// To check the BaseHandle instance is equal or not.
373 /// <param name="rhs">The baseHandle instance.</param>
374 /// <returns>True If equal.</returns>
375 /// <since_tizen> 3 </since_tizen>
376 public bool EqualTo(BaseHandle rhs)
378 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384 /// To check the BaseHandle instance is equal or not.
386 /// <param name="rhs">The baseHandle instance.</param>
387 /// <returns>True If not equal.</returns>
388 /// <since_tizen> 3 </since_tizen>
389 public bool NotEqualTo(BaseHandle rhs)
391 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
392 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396 internal RefObject GetObjectPtr()
398 global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
399 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
400 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405 /// To check the BaseHandle instance has body or not.
407 /// <returns>True If the baseHandle instance has body.</returns>
408 /// <since_tizen> 3 </since_tizen>
409 public bool HasBody()
411 if (disposed == true)
416 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
417 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
422 /// To check the BaseHandle instance is equal or not.
424 /// <param name="rhs">The baseHandle instance.</param>
425 /// <returns>True If equal.</returns>
426 /// <since_tizen> 3 </since_tizen>
427 public bool IsEqual(BaseHandle rhs)
429 if (disposed == true)
434 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
435 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
439 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef