1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
20 public class BaseHandle : global::System.IDisposable
22 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
23 protected bool swigCMemOwn;
24 private bool _registerMe;
26 internal BaseHandle(global::System.IntPtr cPtr, bool cMemoryOwn)
28 _registerMe = swigCMemOwn = cMemoryOwn;
30 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
32 // using copy constructor to create another native handle so Registry.Unregister works fine.
33 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
37 // Register this instance of BaseHandle in the registry.
38 Registry.Register(this);
42 internal BaseHandle(global::System.IntPtr cPtr)
44 _registerMe = swigCMemOwn = true;
46 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
48 // using copy constructor to create another native handle so Registry.Unregister works fine.
49 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
53 // Register this instance of BaseHandle in the registry.
54 Registry.Register(this);
58 internal BaseHandle(global::System.IntPtr cPtr)
60 _registerMe = swigCMemOwn = true;
61 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
63 // Register this instance of BaseHandle in the registry.
64 Registry.Register(this);
67 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
69 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
72 //A Flag to check who called Dispose(). (By User or DisposeQueue)
73 private bool isDisposeQueued = false;
74 //A Flat to check if it is already disposed.
75 protected bool disposed = false;
81 isDisposeQueued = true;
82 DisposeQueue.Instance.Add(this);
88 //Throw excpetion if Dispose() is called in separate thread.
89 if (!Window.IsInstalled())
91 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
96 Dispose(DisposeTypes.Implicit);
100 Dispose(DisposeTypes.Explicit);
101 System.GC.SuppressFinalize(this);
105 protected virtual void Dispose(DisposeTypes type)
112 if (type == DisposeTypes.Explicit)
115 //Release your own managed resources here.
116 //You should release all of your own disposable objects here.
120 //Release your own unmanaged resources here.
121 //You should not access any managed member here except static instance.
122 //because the execution order of Finalizes is non-deterministic.
124 //Unreference this instance from Registry.
127 Registry.Unregister(this);
130 if (swigCPtr.Handle != global::System.IntPtr.Zero)
133 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
134 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
142 // Returns the bool value true to indicate that an operand is true and returns false otherwise.
143 public static bool operator true(BaseHandle handle)
145 // if the C# object is null, return false
146 if (BaseHandle.ReferenceEquals(handle, null))
150 // returns true if the handle has a body, false otherwise
151 return handle.HasBody();
154 // Returns the bool false to indicate that an operand is false and returns true otherwise.
155 public static bool operator false(BaseHandle handle)
157 // if the C# object is null, return true
158 if (BaseHandle.ReferenceEquals(handle, null))
162 return !handle.HasBody();
165 // Explicit conversion from Handle to bool.
166 public static explicit operator bool(BaseHandle handle)
168 // if the C# object is null, return false
169 if (BaseHandle.ReferenceEquals(handle, null))
173 // returns true if the handle has a body, false otherwise
174 return handle.HasBody();
178 public static bool operator ==(BaseHandle x, BaseHandle y)
180 // if the C# objects are the same return true
181 if (BaseHandle.ReferenceEquals(x, y))
185 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
187 // drop into native code to see if both handles point to the same body
191 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
193 if (y.HasBody()) return false;
196 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
198 if (x.HasBody()) return false;
205 // Inequality operator. Returns Null if either operand is Null
206 public static bool operator !=(BaseHandle x, BaseHandle y)
211 // Logical AND operator for &&
212 // It's possible when doing a && this function (opBitwiseAnd) is never called due
213 // to short circuiting. E.g.
214 // If you perform x && y What actually is called is
215 // BaseHandle.op_False( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseAnd(x,y) )
217 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
226 // Logical OR operator for ||
227 // It's possible when doing a || this function (opBitwiseOr) is never called due
228 // to short circuiting. E.g.
229 // If you perform x || y What actually is called is
230 // BaseHandle.op_True( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseOr(x,y) )
231 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
233 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
248 // Logical ! operator
249 public static bool operator !(BaseHandle x)
251 // if the C# object is null, return true
252 if (BaseHandle.ReferenceEquals(x, null))
264 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 public bool DoAction(string actionName, PropertyMap attributes)
277 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
278 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282 public string GetTypeName()
284 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 public bool GetTypeInfo(TypeInfo info)
291 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
300 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
303 public bool EqualTo(BaseHandle rhs)
305 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
306 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 public bool NotEqualTo(BaseHandle rhs)
312 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 internal RefObject GetObjectPtr()
319 global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
320 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
321 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325 public bool HasBody()
327 if (disposed == true)
332 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337 public bool IsEqual(BaseHandle rhs)
339 if (disposed == true)
344 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
345 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();