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 // Register this instance of BaseHandle in the registry.
47 Registry.Register(this);
50 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
52 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
55 //A Flag to check who called Dispose(). (By User or DisposeQueue)
56 private bool isDisposeQueued = false;
57 //A Flat to check if it is already disposed.
58 protected bool disposed = false;
64 isDisposeQueued = true;
65 DisposeQueue.Instance.Add(this);
71 //Throw excpetion if Dispose() is called in separate thread.
72 if (!Window.IsInstalled())
74 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
79 Dispose(DisposeTypes.Implicit);
83 Dispose(DisposeTypes.Explicit);
84 System.GC.SuppressFinalize(this);
88 protected virtual void Dispose(DisposeTypes type)
95 if (type == DisposeTypes.Explicit)
98 //Release your own managed resources here.
99 //You should release all of your own disposable objects here.
103 //Release your own unmanaged resources here.
104 //You should not access any managed member here except static instance.
105 //because the execution order of Finalizes is non-deterministic.
107 //Unreference this instance from Registry.
110 Registry.Unregister(this);
113 if (swigCPtr.Handle != global::System.IntPtr.Zero)
116 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
117 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
125 // Returns the bool value true to indicate that an operand is true and returns false otherwise.
126 public static bool operator true(BaseHandle handle)
128 // if the C# object is null, return false
129 if (BaseHandle.ReferenceEquals(handle, null))
133 // returns true if the handle has a body, false otherwise
134 return handle.HasBody();
137 // Returns the bool false to indicate that an operand is false and returns true otherwise.
138 public static bool operator false(BaseHandle handle)
140 // if the C# object is null, return true
141 if (BaseHandle.ReferenceEquals(handle, null))
145 return !handle.HasBody();
148 // Explicit conversion from Handle to bool.
149 public static explicit operator bool(BaseHandle handle)
151 // if the C# object is null, return false
152 if (BaseHandle.ReferenceEquals(handle, null))
156 // returns true if the handle has a body, false otherwise
157 return handle.HasBody();
161 public static bool operator ==(BaseHandle x, BaseHandle y)
163 // if the C# objects are the same return true
164 if (BaseHandle.ReferenceEquals(x, y))
168 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
170 // drop into native code to see if both handles point to the same body
174 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
176 if (y.HasBody()) return false;
179 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
181 if (x.HasBody()) return false;
188 // Inequality operator. Returns Null if either operand is Null
189 public static bool operator !=(BaseHandle x, BaseHandle y)
194 // Logical AND operator for &&
195 // It's possible when doing a && this function (opBitwiseAnd) is never called due
196 // to short circuiting. E.g.
197 // If you perform x && y What actually is called is
198 // BaseHandle.op_False( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseAnd(x,y) )
200 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
209 // Logical OR operator for ||
210 // It's possible when doing a || this function (opBitwiseOr) is never called due
211 // to short circuiting. E.g.
212 // If you perform x || y What actually is called is
213 // BaseHandle.op_True( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseOr(x,y) )
214 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
216 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
231 // Logical ! operator
232 public static bool operator !(BaseHandle x)
234 // if the C# object is null, return true
235 if (BaseHandle.ReferenceEquals(x, null))
247 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
249 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
254 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 public bool DoAction(string actionName, PropertyMap attributes)
260 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 public string GetTypeName()
267 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
268 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272 public bool GetTypeInfo(TypeInfo info)
274 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
275 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 public bool EqualTo(BaseHandle rhs)
288 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
289 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293 public bool NotEqualTo(BaseHandle rhs)
295 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
296 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 internal RefObject GetObjectPtr()
302 global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
303 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 public bool HasBody()
310 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
311 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315 public bool IsEqual(BaseHandle rhs)
317 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
318 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();