2 * Copyright (c) 2017 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;
22 internal class WatchApplication : Application
24 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26 internal WatchApplication(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
28 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
31 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WatchApplication obj)
33 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
36 protected virtual void Dispose(DisposeTypes type)
43 if (type == DisposeTypes.Explicit)
46 //Release your own managed resources here.
47 //You should release all of your own disposable objects here.
51 //Release your own unmanaged resources here.
52 //You should not access any managed member here except static instance.
53 //because the execution order of Finalizes is non-deterministic.
54 DisConnectFromSignals();
56 if (swigCPtr.Handle != global::System.IntPtr.Zero)
61 NDalicManualPINVOKE.delete_WatchApplication(swigCPtr);
63 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
69 private void DisConnectFromSignals()
71 if (_timeTickCallback != null)
73 this.TimeTickSignal().Disconnect(_timeTickCallback);
75 if (_ambientTickCallback != null)
77 this.AmbientTickSignal().Disconnect(_ambientTickCallback);
79 if (_ambientChangedCallback != null)
81 this.AmbientChangedSignal().Disconnect(_ambientChangedCallback);
85 public static WatchApplication Instance
93 public static WatchApplication NewWatchApplication()
95 WatchApplication ret = New();
96 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97 // we've got an application now connect the signals
102 public static WatchApplication NewWatchApplication(string[] args)
104 WatchApplication ret = New(args);
105 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 public static WatchApplication NewWatchApplication(string[] args, string stylesheet)
112 WatchApplication ret = New(args, stylesheet);
113 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
118 public new static WatchApplication New()
120 WatchApplication ret = new WatchApplication(NDalicManualPINVOKE.WatchApplication_New__SWIG_0(), true);
121 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125 public static WatchApplication New(string[] args)
127 int argc = args.Length;
128 string argvStr = string.Join(" ", args);
130 WatchApplication ret = new WatchApplication(NDalicManualPINVOKE.WatchApplication_New__SWIG_1(argc, argvStr), true);
131 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
135 public static WatchApplication New(string[] args, string stylesheet)
137 int argc = args.Length;
138 string argvStr = string.Join(" ", args);
140 WatchApplication ret = new WatchApplication(NDalicManualPINVOKE.WatchApplication_New__SWIG_2(argc, argvStr, stylesheet), true);
141 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145 internal WatchApplication(WatchApplication implementation) : this(NDalicManualPINVOKE.new_WatchApplication__SWIG_1(WatchApplication.getCPtr(implementation)), true)
147 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151 /// Event arguments that passed via time tick event signal.
153 public class TimeTickEventArgs : EventArgs
158 public Application Application
167 public WatchTime WatchTime
174 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
175 private delegate void TimeTickCallbackType(IntPtr application, IntPtr watchTime);
176 private TimeTickCallbackType _timeTickCallback;
177 private DaliEventHandler<object,TimeTickEventArgs> _timeTickEventHandler;
182 public event DaliEventHandler<object, TimeTickEventArgs> TimeTick
186 if (_timeTickEventHandler == null)
188 _timeTickCallback = new TimeTickCallbackType( OnTimeTick);
189 TimeTickSignal().Connect(_timeTickCallback);
192 _timeTickEventHandler += value;
197 _timeTickEventHandler -= value;
199 if (_timeTickEventHandler == null && TimeTickSignal().Empty() == false)
201 TimeTickSignal().Disconnect(_timeTickCallback);
206 private void OnTimeTick(IntPtr application, IntPtr watchTime)
208 TimeTickEventArgs e = new TimeTickEventArgs();
209 if (application != null)
211 e.Application = Application.GetApplicationFromPtr(application);
213 if(watchTime != null)
215 e.WatchTime = WatchTime.GetWatchTimeFromPtr(watchTime);
218 _timeTickEventHandler?.Invoke(this, e);
221 internal WatchTimeSignal TimeTickSignal()
223 WatchTimeSignal ret = new WatchTimeSignal(NDalicManualPINVOKE.WatchApplication_TimeTickSignal(swigCPtr), false);
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 /// Event arguments that passed via ambient tick event signal.
231 public class AmbientTickEventArgs : EventArgs
236 public Application Application
245 public WatchTime WatchTime
252 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
253 private delegate void AmbientTickCallbackType(IntPtr application, IntPtr watchTime);
254 private AmbientTickCallbackType _ambientTickCallback;
255 private DaliEventHandler<object,AmbientTickEventArgs> _ambientTickEventHandler;
258 /// AmbientTick event.
260 public event DaliEventHandler<object, AmbientTickEventArgs> AmbientTick
264 if (_ambientTickEventHandler == null)
266 _ambientTickCallback = new AmbientTickCallbackType( OnAmbientTick);
267 AmbientTickSignal().Connect(_ambientTickCallback);
270 _ambientTickEventHandler += value;
275 _ambientTickEventHandler -= value;
277 if (_ambientTickEventHandler == null && AmbientTickSignal().Empty() == false)
279 AmbientTickSignal().Disconnect(_ambientTickCallback);
284 private void OnAmbientTick(IntPtr application, IntPtr watchTime)
286 AmbientTickEventArgs e = new AmbientTickEventArgs();
287 if (application != null)
289 e.Application = Application.GetApplicationFromPtr(application);
291 if (watchTime != null)
293 e.WatchTime = WatchTime.GetWatchTimeFromPtr(watchTime);
296 _ambientTickEventHandler?.Invoke(this, e);
299 internal WatchTimeSignal AmbientTickSignal()
301 WatchTimeSignal ret = new WatchTimeSignal(NDalicManualPINVOKE.WatchApplication_AmbientTickSignal(swigCPtr), false);
302 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307 /// Event arguments that passed via ambient tick event signal.
309 public class AmbientChangedEventArgs : EventArgs
314 public Application Application
330 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
331 private delegate void AmbientChangedCallbackType(IntPtr application, bool changed);
332 private AmbientChangedCallbackType _ambientChangedCallback;
333 private DaliEventHandler<object,AmbientChangedEventArgs> _ambientChangedEventHandler;
336 /// AmbientChanged event.
338 public event DaliEventHandler<object, AmbientChangedEventArgs> AmbientChanged
342 if (_ambientChangedEventHandler == null)
344 _ambientChangedCallback = new AmbientChangedCallbackType( OnAmbientChanged);
345 AmbientChangedSignal().Connect(_ambientChangedCallback);
348 _ambientChangedEventHandler += value;
353 _ambientChangedEventHandler -= value;
355 if (_ambientChangedEventHandler == null && AmbientChangedSignal().Empty() == false)
357 AmbientChangedSignal().Disconnect(_ambientChangedCallback);
362 private void OnAmbientChanged(IntPtr application, bool changed)
364 AmbientChangedEventArgs e = new AmbientChangedEventArgs();
365 if (application != null)
367 e.Application = Application.GetApplicationFromPtr(application);
371 _ambientChangedEventHandler?.Invoke(this, e);
374 internal WatchBoolSignal AmbientChangedSignal()
376 WatchBoolSignal ret = new WatchBoolSignal(NDalicManualPINVOKE.WatchApplication_AmbientChangedSignal(swigCPtr), false);
377 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381 private static WatchApplication _instance; //singleton