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 //to catch derived classes dali native exceptions
29 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
31 _registerMe = swigCMemOwn = cMemoryOwn;
33 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35 // using copy constructor to create another native handle so Registry.Unregister works fine.
36 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
37 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
41 // Register this instance of BaseHandle in the registry.
42 Registry.Register(this);
46 internal BaseHandle(global::System.IntPtr cPtr)
48 _registerMe = swigCMemOwn = true;
50 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
52 // using copy constructor to create another native handle so Registry.Unregister works fine.
53 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.new_BaseHandle__SWIG_2(swigCPtr));
54 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
58 // Register this instance of BaseHandle in the registry.
59 Registry.Register(this);
63 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(BaseHandle obj)
65 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
68 //A Flag to check who called Dispose(). (By User or DisposeQueue)
69 private bool isDisposeQueued = false;
70 //A Flat to check if it is already disposed.
71 protected bool disposed = false;
77 isDisposeQueued = true;
78 DisposeQueue.Instance.Add(this);
84 //Throw excpetion if Dispose() is called in separate thread.
85 if (!Window.IsInstalled())
87 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
92 Dispose(DisposeTypes.Implicit);
96 Dispose(DisposeTypes.Explicit);
97 System.GC.SuppressFinalize(this);
101 protected virtual void Dispose(DisposeTypes type)
108 if (type == DisposeTypes.Explicit)
111 //Release your own managed resources here.
112 //You should release all of your own disposable objects here.
116 //Release your own unmanaged resources here.
117 //You should not access any managed member here except static instance.
118 //because the execution order of Finalizes is non-deterministic.
120 //Unreference this instance from Registry.
123 Registry.Unregister(this);
126 if (swigCPtr.Handle != global::System.IntPtr.Zero)
129 NDalicPINVOKE.delete_BaseHandle(swigCPtr);
130 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
138 // Returns the bool value true to indicate that an operand is true and returns false otherwise.
139 public static bool operator true(BaseHandle handle)
141 // if the C# object is null, return false
142 if (BaseHandle.ReferenceEquals(handle, null))
146 // returns true if the handle has a body, false otherwise
147 return handle.HasBody();
150 // Returns the bool false to indicate that an operand is false and returns true otherwise.
151 public static bool operator false(BaseHandle handle)
153 // if the C# object is null, return true
154 if (BaseHandle.ReferenceEquals(handle, null))
158 return !handle.HasBody();
161 // Explicit conversion from Handle to bool.
162 public static explicit operator bool(BaseHandle handle)
164 // if the C# object is null, return false
165 if (BaseHandle.ReferenceEquals(handle, null))
169 // returns true if the handle has a body, false otherwise
170 return handle.HasBody();
174 public static bool operator ==(BaseHandle x, BaseHandle y)
176 // if the C# objects are the same return true
177 if (BaseHandle.ReferenceEquals(x, y))
181 if (!BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
183 // drop into native code to see if both handles point to the same body
187 if (BaseHandle.ReferenceEquals(x, null) && !BaseHandle.ReferenceEquals(y, null))
189 if (y.HasBody()) return false;
192 if (!BaseHandle.ReferenceEquals(x, null) && BaseHandle.ReferenceEquals(y, null))
194 if (x.HasBody()) return false;
201 // Inequality operator. Returns Null if either operand is Null
202 public static bool operator !=(BaseHandle x, BaseHandle y)
207 // Logical AND operator for &&
208 // It's possible when doing a && this function (opBitwiseAnd) is never called due
209 // to short circuiting. E.g.
210 // If you perform x && y What actually is called is
211 // BaseHandle.op_False( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseAnd(x,y) )
213 public static BaseHandle operator &(BaseHandle x, BaseHandle y)
222 // Logical OR operator for ||
223 // It's possible when doing a || this function (opBitwiseOr) is never called due
224 // to short circuiting. E.g.
225 // If you perform x || y What actually is called is
226 // BaseHandle.op_True( x ) ? BaseHandle.op_True( x ) : BaseHandle.opTrue( BaseHandle.opBitwiseOr(x,y) )
227 public static BaseHandle operator |(BaseHandle x, BaseHandle y)
229 if (!BaseHandle.ReferenceEquals(x, null) || !BaseHandle.ReferenceEquals(y, null))
244 // Logical ! operator
245 public static bool operator !(BaseHandle x)
247 // if the C# object is null, return true
248 if (BaseHandle.ReferenceEquals(x, null))
259 public override bool Equals(object o)
265 if(!(o is BaseHandle))
269 BaseHandle b = (BaseHandle)o;
270 if (!BaseHandle.ReferenceEquals(this, null) && !BaseHandle.ReferenceEquals(b, null))
272 // drop into native code to see if both handles point to the same body
273 return this.IsEqual(b);
276 if (BaseHandle.ReferenceEquals(this, null) && !BaseHandle.ReferenceEquals(b, null))
278 if (b.HasBody()) return false;
281 if (!BaseHandle.ReferenceEquals(this, null) && BaseHandle.ReferenceEquals(b, null))
283 if (this.HasBody()) return false;
290 public override int GetHashCode()
292 return base.GetHashCode();
295 public BaseHandle() : this(NDalicPINVOKE.new_BaseHandle__SWIG_1())
297 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 public BaseHandle(BaseHandle handle) : this(NDalicPINVOKE.new_BaseHandle__SWIG_2(BaseHandle.getCPtr(handle)))
302 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306 public bool DoAction(string actionName, PropertyMap attributes)
308 bool ret = NDalicPINVOKE.BaseHandle_DoAction(swigCPtr, actionName, PropertyMap.getCPtr(attributes));
309 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313 public string GetTypeName()
315 string ret = NDalicPINVOKE.BaseHandle_GetTypeName(swigCPtr);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 public bool GetTypeInfo(TypeInfo info)
322 bool ret = NDalicPINVOKE.BaseHandle_GetTypeInfo(swigCPtr, TypeInfo.getCPtr(info));
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330 NDalicPINVOKE.BaseHandle_Reset(swigCPtr);
331 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 public bool EqualTo(BaseHandle rhs)
336 bool ret = NDalicPINVOKE.BaseHandle_EqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341 public bool NotEqualTo(BaseHandle rhs)
343 bool ret = NDalicPINVOKE.BaseHandle_NotEqualTo(swigCPtr, BaseHandle.getCPtr(rhs));
344 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 internal RefObject GetObjectPtr()
350 global::System.IntPtr cPtr = NDalicPINVOKE.BaseHandle_GetObjectPtr(swigCPtr);
351 RefObject ret = (cPtr == global::System.IntPtr.Zero) ? null : new RefObject(cPtr, false);
352 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356 public bool HasBody()
358 if (disposed == true)
363 bool ret = NDalicPINVOKE.BaseHandle_HasBody(swigCPtr);
364 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 public bool IsEqual(BaseHandle rhs)
370 if (disposed == true)
375 bool ret = NDalicPINVOKE.BaseHandle_IsEqual(swigCPtr, BaseHandle.getCPtr(rhs));
376 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380 internal global::System.Runtime.InteropServices.HandleRef GetBaseHandleCPtrHandleRef