2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
25 /// Issues a notification upon a condition of the property being met.
26 /// See PropertyCondition for available defined conditions.
28 /// <since_tizen> 4 </since_tizen>
29 public class PropertyNotification : BaseHandle
32 private DaliEventHandler<object, NotifyEventArgs> propertyNotificationNotifyEventHandler;
33 private NotifyEventCallbackDelegate propertyNotificationNotifyEventCallback;
36 /// Create a instance of PropertyNotification.
38 /// <since_tizen> 4 </since_tizen>
39 public PropertyNotification() : this(Interop.PropertyNotification.NewPropertyNotification(), true)
41 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
45 /// Create a instance of PropertyNotification.
47 /// <since_tizen> 4 </since_tizen>
48 public PropertyNotification(PropertyNotification handle) : this(Interop.PropertyNotification.NewPropertyNotification(PropertyNotification.getCPtr(handle)), true)
50 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53 internal PropertyNotification(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
57 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
58 private delegate void NotifyEventCallbackDelegate(IntPtr propertyNotification);
61 /// Event for Notified signal which can be used to subscribe/unsubscribe the event handler
62 /// Notified signal is emitted when the notification upon a condition of the property being met, has occurred.
64 /// <since_tizen> 4 </since_tizen>
65 public event DaliEventHandler<object, NotifyEventArgs> Notified
69 if (propertyNotificationNotifyEventHandler == null)
71 propertyNotificationNotifyEventCallback = OnPropertyNotificationNotify;
72 using PropertyNotifySignal signal = new PropertyNotifySignal(Interop.PropertyNotification.NotifySignal(SwigCPtr), false);
73 signal?.Connect(propertyNotificationNotifyEventCallback);
75 propertyNotificationNotifyEventHandler += value;
79 propertyNotificationNotifyEventHandler -= value;
80 if (propertyNotificationNotifyEventHandler == null)
82 using PropertyNotifySignal signal = new PropertyNotifySignal(Interop.PropertyNotification.NotifySignal(SwigCPtr), false);
83 if (signal?.Empty() == false)
85 signal?.Disconnect(propertyNotificationNotifyEventCallback);
86 if (signal?.Empty() == true)
88 propertyNotificationNotifyEventCallback = null;
96 /// Enumeration for description of how to check condition.
98 /// <since_tizen> 3 </since_tizen>
99 public enum NotifyMode
102 /// Don't notify, regardless of result of Condition
104 /// <since_tizen> 3 </since_tizen>
107 /// Notify whenever condition changes from false to true.
109 /// <since_tizen> 3 </since_tizen>
112 /// Notify whenever condition changes from true to false.
114 /// <since_tizen> 3 </since_tizen>
117 /// Notify whenever condition changes (false to true, and true to false)
119 /// <since_tizen> 3 </since_tizen>
124 /// Get property notification from Intptr.<br/>
125 /// This should be internal, do not use.
127 /// <param name="cPtr">An object of IntPtr type.</param>
128 /// <returns>An object of the PropertyNotification type.</returns>
129 internal static PropertyNotification GetPropertyNotificationFromPtr(global::System.IntPtr cPtr)
131 PropertyNotification ret = new PropertyNotification(cPtr, false);
132 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137 /// Downcast a PropertyNotification instance.
139 /// <param name="handle">Handle to an object of BaseHandle type.</param>
140 /// <returns>Handle to an object of the PropertyNotification type.</returns>
141 /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
142 /// <since_tizen> 4 </since_tizen>
143 public static PropertyNotification DownCast(BaseHandle handle)
147 throw new ArgumentNullException(nameof(handle));
149 PropertyNotification ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PropertyNotification;
150 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157 /// <param name="rhs">A reference to the copied handle.</param>
158 /// <returns>A reference to this.</returns>
159 internal PropertyNotification Assign(PropertyNotification rhs)
161 PropertyNotification ret = new PropertyNotification(Interop.PropertyNotification.Assign(SwigCPtr, PropertyNotification.getCPtr(rhs)), false);
162 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167 /// Gets the condition of this notification.
169 /// <returns>The condition is returned.</returns>
170 /// <since_tizen> 4 </since_tizen>
171 public PropertyCondition GetCondition()
173 PropertyCondition ret = new PropertyCondition(Interop.PropertyNotification.GetCondition(SwigCPtr), true);
174 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179 /// Gets the target handle that this notification is observing.
181 /// <since_tizen> 4 </since_tizen>
182 public Animatable GetTarget()
184 //to fix memory leak issue, match the handle count with native side.
185 Animatable ret = this.GetInstanceSafely<Animatable>(Interop.PropertyNotification.GetTarget(SwigCPtr));
186 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191 /// Gets the target handle's property index that this notification.
193 /// <returns>The target property index.</returns>
194 /// <since_tizen> 4 </since_tizen>
195 public int GetTargetProperty()
197 int ret = Interop.PropertyNotification.GetTargetProperty(SwigCPtr);
198 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203 /// Sets the Notification mode.
205 /// <param name="mode">mode Notification mode (Default is PropertyNotification::NotifyOnTrue).</param>
206 /// <since_tizen> 4 </since_tizen>
207 public void SetNotifyMode(PropertyNotification.NotifyMode mode)
209 Interop.PropertyNotification.SetNotifyMode(SwigCPtr, (int)mode);
210 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214 /// Retrieves the current Notification mode.
216 /// <returns>Notification mode.</returns>
217 /// <since_tizen> 4 </since_tizen>
218 public PropertyNotification.NotifyMode GetNotifyMode()
220 PropertyNotification.NotifyMode ret = (PropertyNotification.NotifyMode)Interop.PropertyNotification.GetNotifyMode(SwigCPtr);
221 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226 /// Gets the result of the last condition check that caused a signal emit,
227 /// useful when using NotifyOnChanged mode and need to know what it changed to.
229 /// <since_tizen> 4 </since_tizen>
230 public bool GetNotifyResult()
232 bool ret = Interop.PropertyNotification.GetNotifyResult(SwigCPtr);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// override it to clean-up your own resources.
240 /// <param name="type"></param>
241 [EditorBrowsable(EditorBrowsableState.Never)]
242 protected override void Dispose(DisposeTypes type)
249 if (type == DisposeTypes.Explicit)
252 //Release your own managed resources here.
253 //You should release all of your own disposable objects here.
256 //Release your own unmanaged resources here.
257 //You should not access any managed member here except static instance.
258 //because the execution order of Finalizes is non-deterministic.
262 if (propertyNotificationNotifyEventCallback != null)
264 using PropertyNotifySignal signal = new PropertyNotifySignal(Interop.PropertyNotification.NotifySignal(SwigCPtr), false);
265 signal?.Disconnect(propertyNotificationNotifyEventCallback);
266 propertyNotificationNotifyEventCallback = null;
272 /// This will not be public opened.
273 [EditorBrowsable(EditorBrowsableState.Never)]
274 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
276 Interop.PropertyNotification.DeletePropertyNotification(swigCPtr);
279 // Callback for PropertyNotification NotifySignal
280 private void OnPropertyNotificationNotify(IntPtr propertyNotification)
282 if (IsNativeHandleInvalid())
286 if (propertyNotificationNotifyEventHandler != null)
288 var process = global::System.Diagnostics.Process.GetCurrentProcess();
289 var processId = process?.Id ?? -1;
290 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
291 var me = this.GetType().FullName;
293 Tizen.Log.Error("NUI", $"Error! NUI's native dali object is already disposed. " +
294 $"OR the native dali object handle of NUI becomes null! \n" +
295 $" process:{processId} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
302 if (this.IsDisposeQueued)
304 var process = global::System.Diagnostics.Process.GetCurrentProcess();
305 var processId = process?.Id ?? -1;
306 var thread = global::System.Threading.Thread.CurrentThread.ManagedThreadId;
307 var me = this.GetType().FullName;
309 //in this case, this object is ready to be disposed waiting on DisposeQueue, so event callback should not be invoked!
310 Tizen.Log.Error("NUI", "in this case, the View object is ready to be disposed waiting on DisposeQueue, so event callback should not be invoked! just return here! \n" +
311 $"process:{processId} thread:{thread}, isDisposed:{this.Disposed}, isDisposeQueued:{this.IsDisposeQueued}, me:{me}\n");
319 if (propertyNotificationNotifyEventHandler != null)
321 NotifyEventArgs e = new NotifyEventArgs();
322 e.PropertyNotification = GetPropertyNotificationFromPtr(propertyNotification);
324 //here we send all data to user event handlers
325 propertyNotificationNotifyEventHandler(this, e);
330 /// Event arguments that passed via Notify signal
332 /// <since_tizen> 3 </since_tizen>
333 public class NotifyEventArgs : EventArgs
335 private PropertyNotification propertyNotification;
338 /// PropertyNotification - is the PropertyNotification handle that has the notification properties.
340 /// <since_tizen> 3 </since_tizen>
341 public PropertyNotification PropertyNotification
345 return propertyNotification;
349 propertyNotification = value;