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;
29 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
31 // using copy constructor to create another native handle so Registry.Unregister works fine.
32 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
36 // Register this instance of BaseHandle in the registry.
37 Registry.Register(this);
41 internal BaseHandle(global::System.IntPtr cPtr)
43 _registerMe = swigCMemOwn = true;
44 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
46 // using copy constructor to create another native handle so Registry.Unregister works fine.
47 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
49 // Register this instance of BaseHandle in the registry.
50 Registry.Register(this);
53 internal BaseHandle(global::System.IntPtr cPtr)
56 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
58 // Register this instance of BaseHandle in the registry.
59 Registry.Register(this);
62 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
64 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
67 //A Flag to check who called Dispose(). (By User or DisposeQueue)
68 private bool isDisposeQueued = false;
69 //A Flat to check if it is already disposed.
70 protected bool disposed = false;
76 isDisposeQueued = true;
77 DisposeQueue.Instance.Add(this);
83 //Throw excpetion if Dispose() is called in separate thread.
84 if (!Window.IsInstalled())
86 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
91 Dispose(DisposeTypes.Implicit);
95 Dispose(DisposeTypes.Explicit);
96 System.GC.SuppressFinalize(this);
100 protected virtual void Dispose(DisposeTypes type)
107 if (type == DisposeTypes.Explicit)
110 //Release your own managed resources here.
111 //You should release all of your own disposable objects here.
115 //Release your own unmanaged resources here.
116 //You should not access any managed member here except static instance.
117 //because the execution order of Finalizes is non-deterministic.
119 //Unreference this instance from Registry.
122 Registry.Unregister(this);
125 if (swigCPtr.Handle != global::System.IntPtr.Zero)
128 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
129 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
137 // Returns the bool value true to indicate that an operand is true and returns false otherwise.
138 public static bool operator true(BaseHandle handle)
140 // if the C# object is null, return false
141 if (BaseHandle.ReferenceEquals(handle, null))
145 // returns true if the handle has a body, false otherwise
146 return handle.HasBody();
149 // Returns the bool false to indicate that an operand is false and returns true otherwise.
150 public static bool operator false(BaseHandle handle)
152 // if the C# object is null, return true
153 if (BaseHandle.ReferenceEquals(handle, null))
157 return !handle.HasBody();
160 // Explicit conversion from Handle to bool.
161 public static explicit operator bool(BaseHandle handle)
163 // if the C# object is null, return false
164 if (BaseHandle.ReferenceEquals(handle, null))
168 // returns true if the handle has a body, false otherwise
169 return handle.HasBody();
173 public static bool operator ==(BaseHandle x, BaseHandle y)
175 // if the C# objects are the same return true
176 if (BaseHandle.ReferenceEquals(x, y))
180 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
182 // drop into native code to see if both handles point to the same body
186 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
188 if (y.HasBody()) return false;
191 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
193 if (x.HasBody()) return false;
200 // Inequality operator. Returns Null if either operand is Null
201 public static bool operator !=(BaseHandle x, BaseHandle y)
206 // Logical AND operator for &&
207 // It's possible when doing a && this function (opBitwiseAnd) is never called due
208 // to short circuiting. E.g.
209 // If you perform x && y What actually is called is
210 // BaseHandle.op_False( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseAnd(x,y) )
212 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
221 // Logical OR operator for ||
222 // It's possible when doing a || this function (opBitwiseOr) is never called due
223 // to short circuiting. E.g.
224 // If you perform x || y What actually is called is
225 // BaseHandle.op_True( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseOr(x,y) )
226 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
228 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
243 // Logical ! operator
244 public static bool operator !(BaseHandle x)
246 // if the C# object is null, return true
247 if (BaseHandle.ReferenceEquals(x, null))
259 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 public bool DoAction(string actionName, PropertyMap attributes)
272 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
273 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277 public string GetTypeName()
279 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
280 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284 public bool GetTypeInfo(TypeInfo info)
286 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
295 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298 public bool EqualTo(BaseHandle rhs)
300 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305 public bool NotEqualTo(BaseHandle rhs)
307 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312 internal RefObject GetObjectPtr()
314 global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
315 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 public bool HasBody()
322 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327 public bool IsEqual(BaseHandle rhs)
329 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();