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.
16 // This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts
17 //------------------------------------------------------------------------------
20 // This file was automatically generated by SWIG (http://www.swig.org).
23 // Do not make changes to this file unless you know what you are doing--modify
24 // the SWIG interface file instead.
25 //------------------------------------------------------------------------------
31 using System.Runtime.InteropServices;
34 /// Mechanism to issue simple periodic or one-shot events.
35 /// Timer is provided for application developers to be able to issue
36 /// simple periodic or one-shot events. Please note that timer
37 /// callback functions should return as soon as possible, because they
38 /// block the next SignalTick. Please note that timer signals are not
39 /// in sync with Dali's render timer.
40 /// This class is a handle class so it can be stack allocated and used
43 public class Timer : BaseHandle
45 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
47 internal Timer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Timer_SWIGUpcast(cPtr), cMemoryOwn)
49 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
52 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Timer obj)
54 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
59 DisposeQueue.Instance.Add(this);
62 public override void Dispose()
64 if (!Stage.IsInstalled())
66 DisposeQueue.Instance.Add(this);
72 if (swigCPtr.Handle != global::System.IntPtr.Zero)
77 NDalicPINVOKE.delete_Timer(swigCPtr);
79 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
81 global::System.GC.SuppressFinalize(this);
88 /// Event arguments that passed via Tick event
90 public class TickEventArgs : EventArgs
94 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
95 private delegate bool TickCallbackDelegate(IntPtr data);
96 private EventHandlerWithReturnType<object, TickEventArgs, bool> _timerTickEventHandler;
97 private TickCallbackDelegate _timerTickCallbackDelegate;
100 /// brief Event for Ticked signal which can be used to subscribe/unsubscribe the event handler
101 /// (in the type of TickEventHandler-DaliEventHandlerWithReturnType<object,TickEventArgs,bool>)
102 /// provided by the user. Ticked signal is emitted after specified time interval.
104 public event EventHandlerWithReturnType<object, TickEventArgs, bool> Tick
108 if (_timerTickEventHandler == null)
110 _timerTickCallbackDelegate = (OnTick);
111 TickSignal().Connect(_timerTickCallbackDelegate);
113 _timerTickEventHandler += value;
117 _timerTickEventHandler -= value;
118 if (_timerTickEventHandler == null && _timerTickCallbackDelegate != null)
120 TickSignal().Disconnect(_timerTickCallbackDelegate);
125 private bool OnTick(IntPtr data)
127 TickEventArgs e = new TickEventArgs();
129 if (_timerTickEventHandler != null)
131 //here we send all data to user event handlers
132 return _timerTickEventHandler(this, e);
138 /// Creates a tick Timer that emits periodic signal.
140 /// <param name="millSec">Interval in milliseconds</param>
141 /// <returns>A new timer</returns>
142 public Timer(uint milliSec) : this(NDalicPINVOKE.Timer_New(milliSec), true)
144 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147 internal Timer(Timer timer) : this(NDalicPINVOKE.new_Timer__SWIG_1(Timer.getCPtr(timer)), true)
149 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152 internal Timer Assign(Timer timer)
154 Timer ret = new Timer(NDalicPINVOKE.Timer_Assign(swigCPtr, Timer.getCPtr(timer)), false);
155 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160 /// Downcasts a handle to Timer handle.
162 /// <param name="handle">handle to An object</param>
163 /// <returns>handle to a Timer object or an uninitialized handle</returns>
164 public static Timer DownCast(BaseHandle handle)
166 Timer ret = new Timer(NDalicPINVOKE.Timer_DownCast(BaseHandle.getCPtr(handle)), true);
167 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173 /// In case a Timer is already running, its time is reset and timer is restarted.
177 NDalicPINVOKE.Timer_Start(swigCPtr);
178 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186 NDalicPINVOKE.Timer_Stop(swigCPtr);
187 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191 /// Sets a new interval on the timer and starts the timer.
192 /// Cancels the previous timer.
194 /// <param name="milliSec">milliSec Interval in milliseconds</param>
195 internal void SetInterval(uint milliSec)
197 NDalicPINVOKE.Timer_SetInterval(swigCPtr, milliSec);
198 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201 internal uint GetInterval()
203 uint ret = NDalicPINVOKE.Timer_GetInterval(swigCPtr);
204 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209 /// Tells whether timer is running.
211 /// <returns>Whether Timer is started or not</returns>
212 public bool IsRunning()
214 bool ret = NDalicPINVOKE.Timer_IsRunning(swigCPtr);
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219 internal TimerSignalType TickSignal()
221 TimerSignalType ret = new TimerSignalType(NDalicPINVOKE.Timer_TickSignal(swigCPtr), false);
222 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();