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 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))
299 /// Create an instance of BaseHandle.
301 /// <since_tizen> 3 </since_tizen>
302 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 /// Create an instance of BaseHandle.
310 /// <param name="handle">The BaseHandle instance.</param>
311 /// <since_tizen> 3 </since_tizen>
312 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319 /// Performs an action on this object with the given action name and attributes.
321 /// <param name="actionName">The command for the action.</param>
322 /// <param name="attributes">The list of attributes for the action.</param>
323 /// <returns>The action is performed by the object or not.</returns>
324 /// <since_tizen> 3 </since_tizen>
325 public bool DoAction(string actionName, PropertyMap attributes)
327 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333 /// Returns the type name for the Handle.<br />
334 /// Will return an empty string if the typename does not exist. This will happen for types that
335 /// have not registered with type-registry.
337 /// <returns>The type name. Empty string if the typename does not exist.</returns>
338 /// <since_tizen> 3 </since_tizen>
339 public string GetTypeName()
341 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
342 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347 /// Returns the type info for the Handle.<br />
349 /// <param name="info">The type information.</param>
350 /// <returns>True If get the type info.</returns>
351 /// <since_tizen> 3 </since_tizen>
352 public bool GetTypeInfo(TypeInfo info)
354 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
355 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360 /// Resets the handle.
362 /// <since_tizen> 3 </since_tizen>
365 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
366 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370 /// To check the BaseHandle instance is equal or not.
372 /// <param name="rhs">The baseHandle instance.</param>
373 /// <returns>True If equal.</returns>
374 /// <since_tizen> 3 </since_tizen>
375 public bool EqualTo(BaseHandle rhs)
377 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
378 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
383 /// To check the BaseHandle instance is equal or not.
385 /// <param name="rhs">The baseHandle instance.</param>
386 /// <returns>True If not equal.</returns>
387 /// <since_tizen> 3 </since_tizen>
388 public bool NotEqualTo(BaseHandle rhs)
390 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
391 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
395 internal RefObject GetObjectPtr()
397 global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
398 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
399 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
404 /// To check the BaseHandle instance has body or not.
406 /// <returns>True If the baseHandle instance has body.</returns>
407 /// <since_tizen> 3 </since_tizen>
408 public bool HasBody()
410 if (disposed == true)
415 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
416 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
421 /// To check the BaseHandle instance is equal or not.
423 /// <param name="rhs">The baseHandle instance.</param>
424 /// <returns>True If equal.</returns>
425 /// <since_tizen> 3 </since_tizen>
426 public bool IsEqual(BaseHandle rhs)
428 if (disposed == true)
433 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
434 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
438 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef