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 static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
60 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
63 //A Flag to check who called Dispose(). (By User or DisposeQueue)
64 private bool isDisposeQueued = false;
65 //A Flat to check if it is already disposed.
66 protected bool disposed = false;
72 isDisposeQueued = true;
73 DisposeQueue.Instance.Add(this);
79 //Throw excpetion if Dispose() is called in separate thread.
80 if (!Window.IsInstalled())
82 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
87 Dispose(DisposeTypes.Implicit);
91 Dispose(DisposeTypes.Explicit);
92 System.GC.SuppressFinalize(this);
96 protected virtual void Dispose(DisposeTypes type)
103 if (type == DisposeTypes.Explicit)
106 //Release your own managed resources here.
107 //You should release all of your own disposable objects here.
111 //Release your own unmanaged resources here.
112 //You should not access any managed member here except static instance.
113 //because the execution order of Finalizes is non-deterministic.
115 //Unreference this instance from Registry.
118 Registry.Unregister(this);
121 if (swigCPtr.Handle != global::System.IntPtr.Zero)
124 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
125 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
133 // Returns the bool value true to indicate that an operand is true and returns false otherwise.
134 public static bool operator true(BaseHandle handle)
136 // if the C# object is null, return false
137 if (BaseHandle.ReferenceEquals(handle, null))
141 // returns true if the handle has a body, false otherwise
142 return handle.HasBody();
145 // Returns the bool false to indicate that an operand is false and returns true otherwise.
146 public static bool operator false(BaseHandle handle)
148 // if the C# object is null, return true
149 if (BaseHandle.ReferenceEquals(handle, null))
153 return !handle.HasBody();
156 // Explicit conversion from Handle to bool.
157 public static explicit operator bool(BaseHandle handle)
159 // if the C# object is null, return false
160 if (BaseHandle.ReferenceEquals(handle, null))
164 // returns true if the handle has a body, false otherwise
165 return handle.HasBody();
169 public static bool operator ==(BaseHandle x, BaseHandle y)
171 // if the C# objects are the same return true
172 if (BaseHandle.ReferenceEquals(x, y))
176 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
178 // drop into native code to see if both handles point to the same body
182 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
184 if (y.HasBody()) return false;
187 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
189 if (x.HasBody()) return false;
196 // Inequality operator. Returns Null if either operand is Null
197 public static bool operator !=(BaseHandle x, BaseHandle y)
202 // Logical AND operator for &&
203 // It's possible when doing a && this function (opBitwiseAnd) is never called due
204 // to short circuiting. E.g.
205 // If you perform x && y What actually is called is
206 // BaseHandle.op_False( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseAnd(x,y) )
208 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
217 // Logical OR operator for ||
218 // It's possible when doing a || this function (opBitwiseOr) is never called due
219 // to short circuiting. E.g.
220 // If you perform x || y What actually is called is
221 // BaseHandle.op_True( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseOr(x,y) )
222 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
224 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
239 // Logical ! operator
240 public static bool operator !(BaseHandle x)
242 // if the C# object is null, return true
243 if (BaseHandle.ReferenceEquals(x, null))
255 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266 public bool DoAction(string actionName, PropertyMap attributes)
268 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
269 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273 public string GetTypeName()
275 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280 public bool GetTypeInfo(TypeInfo info)
282 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
290 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294 public bool EqualTo(BaseHandle rhs)
296 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
297 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301 public bool NotEqualTo(BaseHandle rhs)
303 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 internal RefObject GetObjectPtr()
310 global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
311 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
312 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316 public bool HasBody()
318 if (disposed == true)
323 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
324 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328 public bool IsEqual(BaseHandle rhs)
330 if (disposed == true)
335 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();