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;
23 internal class WatchApplication : Application
26 internal WatchApplication(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
30 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WatchApplication obj)
32 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
35 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
37 Interop.Watch.DeleteWatchApplication(swigCPtr);
40 private void DisConnectFromSignals()
42 if (_timeTickCallback != null)
44 this.TimeTickSignal().Disconnect(_timeTickCallback);
46 if (_ambientTickCallback != null)
48 this.AmbientTickSignal().Disconnect(_ambientTickCallback);
50 if (_ambientChangedCallback != null)
52 this.AmbientChangedSignal().Disconnect(_ambientChangedCallback);
56 public static WatchApplication NewWatchApplication()
58 WatchApplication ret = New();
59 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
60 // we've got an application now connect the signals
65 public static WatchApplication NewWatchApplication(string[] args)
67 WatchApplication ret = New(args);
68 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
73 public static WatchApplication NewWatchApplication(string[] args, string stylesheet)
75 WatchApplication ret = New(args, stylesheet);
76 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
81 public new static WatchApplication New()
83 WatchApplication ret = new WatchApplication(Interop.Watch.WatchApplicationNew(), true);
84 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88 public static WatchApplication New(string[] args)
90 int argc = args.Length;
91 string argvStr = string.Join(" ", args);
93 WatchApplication ret = new WatchApplication(Interop.Watch.WatchApplicationNew(argc, argvStr), true);
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98 public static WatchApplication New(string[] args, string stylesheet)
100 int argc = args.Length;
101 string argvStr = string.Join(" ", args);
103 WatchApplication ret = new WatchApplication(Interop.Watch.WatchApplicationNew(argc, argvStr, stylesheet), true);
104 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108 internal WatchApplication(WatchApplication implementation) : this(Interop.Watch.NewWatchApplication(WatchApplication.getCPtr(implementation)), true)
110 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114 /// Event arguments that passed via time tick event signal.
116 public class TimeTickEventArgs : EventArgs
121 public Application Application
130 public WatchTime WatchTime
137 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
138 private delegate void TimeTickCallbackType(IntPtr application, IntPtr watchTime);
139 private TimeTickCallbackType _timeTickCallback;
140 private DaliEventHandler<object, TimeTickEventArgs> _timeTickEventHandler;
145 public event DaliEventHandler<object, TimeTickEventArgs> TimeTick
149 if (_timeTickEventHandler == null)
151 _timeTickCallback = new TimeTickCallbackType(OnTimeTick);
152 TimeTickSignal().Connect(_timeTickCallback);
155 _timeTickEventHandler += value;
160 _timeTickEventHandler -= value;
162 if (_timeTickEventHandler == null && TimeTickSignal().Empty() == false)
164 TimeTickSignal().Disconnect(_timeTickCallback);
169 private void OnTimeTick(IntPtr application, IntPtr watchTime)
171 TimeTickEventArgs e = new TimeTickEventArgs();
172 e.Application = this;
173 e.WatchTime = WatchTime.GetWatchTimeFromPtr(watchTime);
175 _timeTickEventHandler?.Invoke(this, e);
179 internal WatchTimeSignal TimeTickSignal()
181 WatchTimeSignal ret = new WatchTimeSignal(Interop.Watch.WatchApplicationTimeTickSignal(SwigCPtr), false);
182 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187 /// Event arguments that passed via ambient tick event signal.
189 public class AmbientTickEventArgs : EventArgs
194 public Application Application
203 public WatchTime WatchTime
210 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
211 private delegate void AmbientTickCallbackType(IntPtr application, IntPtr watchTime);
212 private AmbientTickCallbackType _ambientTickCallback;
213 private DaliEventHandler<object, AmbientTickEventArgs> _ambientTickEventHandler;
216 /// AmbientTick event.
218 public event DaliEventHandler<object, AmbientTickEventArgs> AmbientTick
222 if (_ambientTickEventHandler == null)
224 _ambientTickCallback = new AmbientTickCallbackType(OnAmbientTick);
225 AmbientTickSignal().Connect(_ambientTickCallback);
228 _ambientTickEventHandler += value;
233 _ambientTickEventHandler -= value;
235 if (_ambientTickEventHandler == null && AmbientTickSignal().Empty() == false)
237 AmbientTickSignal().Disconnect(_ambientTickCallback);
242 private void OnAmbientTick(IntPtr application, IntPtr watchTime)
244 AmbientTickEventArgs e = new AmbientTickEventArgs();
246 e.Application = this;
247 e.WatchTime = WatchTime.GetWatchTimeFromPtr(watchTime);
248 _ambientTickEventHandler?.Invoke(this, e);
251 internal WatchTimeSignal AmbientTickSignal()
253 WatchTimeSignal ret = new WatchTimeSignal(Interop.Watch.WatchApplicationAmbientTickSignal(SwigCPtr), false);
254 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 /// Event arguments that passed via ambient tick event signal.
261 public class AmbientChangedEventArgs : EventArgs
266 public Application Application
282 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
283 private delegate void AmbientChangedCallbackType(IntPtr application, bool changed);
284 private AmbientChangedCallbackType _ambientChangedCallback;
285 private DaliEventHandler<object, AmbientChangedEventArgs> _ambientChangedEventHandler;
288 /// AmbientChanged event.
290 public event DaliEventHandler<object, AmbientChangedEventArgs> AmbientChanged
294 if (_ambientChangedEventHandler == null)
296 _ambientChangedCallback = new AmbientChangedCallbackType(OnAmbientChanged);
297 AmbientChangedSignal().Connect(_ambientChangedCallback);
300 _ambientChangedEventHandler += value;
305 _ambientChangedEventHandler -= value;
307 if (_ambientChangedEventHandler == null && AmbientChangedSignal().Empty() == false)
309 AmbientChangedSignal().Disconnect(_ambientChangedCallback);
314 private void OnAmbientChanged(IntPtr application, bool changed)
316 AmbientChangedEventArgs e = new AmbientChangedEventArgs();
317 e.Application = this;
319 _ambientChangedEventHandler?.Invoke(this, e);
322 internal WatchBoolSignal AmbientChangedSignal()
324 WatchBoolSignal ret = new WatchBoolSignal(Interop.Watch.WatchApplicationAmbientChangedSignal(SwigCPtr), false);
325 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();