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.<br>
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.<br>
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;
57 protected override void Dispose(DisposeTypes type)
64 if(type == DisposeTypes.Explicit)
67 //Release your own managed resources here.
68 //You should release all of your own disposable objects here.
71 //Release your own unmanaged resources here.
72 //You should not access any managed member here except static instance.
73 //because the execution order of Finalizes is non-deterministic.
75 if (swigCPtr.Handle != global::System.IntPtr.Zero)
80 NDalicPINVOKE.delete_Timer(swigCPtr);
82 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
90 /// Event arguments that passed via Tick event.
92 public class TickEventArgs : EventArgs
96 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
97 private delegate bool TickCallbackDelegate(IntPtr data);
98 private EventHandlerWithReturnType<object, TickEventArgs, bool> _timerTickEventHandler;
99 private TickCallbackDelegate _timerTickCallbackDelegate;
102 /// brief Event for Ticked signal which can be used to subscribe/unsubscribe the event handler
103 /// (in the type of TickEventHandler-DaliEventHandlerWithReturnType<object,TickEventArgs,bool>).<br>
104 /// provided by the user. Ticked signal is emitted after specified time interval.<br>
106 public event EventHandlerWithReturnType<object, TickEventArgs, bool> Tick
110 if (_timerTickEventHandler == null)
112 _timerTickCallbackDelegate = (OnTick);
113 TickSignal().Connect(_timerTickCallbackDelegate);
115 _timerTickEventHandler += value;
119 _timerTickEventHandler -= value;
120 if (_timerTickEventHandler == null && TickSignal().Empty() == false)
122 TickSignal().Disconnect(_timerTickCallbackDelegate);
127 private bool OnTick(IntPtr data)
129 TickEventArgs e = new TickEventArgs();
131 if (_timerTickEventHandler != null)
133 //here we send all data to user event handlers
134 return _timerTickEventHandler(this, e);
140 /// Creates a tick Timer that emits periodic signal.
142 /// <param name="millSec">Interval in milliseconds</param>
143 /// <returns>A new timer</returns>
144 public Timer(uint milliSec) : this(NDalicPINVOKE.Timer_New(milliSec), true)
146 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149 internal Timer(Timer timer) : this(NDalicPINVOKE.new_Timer__SWIG_1(Timer.getCPtr(timer)), true)
151 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154 internal Timer Assign(Timer timer)
156 Timer ret = new Timer(NDalicPINVOKE.Timer_Assign(swigCPtr, Timer.getCPtr(timer)), false);
157 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162 /// Downcasts a handle to Timer handle.
164 /// <param name="handle">handle to An object</param>
165 /// <returns>handle to a Timer object or an uninitialized handle</returns>
166 public static Timer DownCast(BaseHandle handle)
168 Timer ret = new Timer(NDalicPINVOKE.Timer_DownCast(BaseHandle.getCPtr(handle)), true);
169 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
174 /// Starts timer.<br>
175 /// In case a Timer is already running, its time is reset and timer is restarted.<br>
179 NDalicPINVOKE.Timer_Start(swigCPtr);
180 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188 NDalicPINVOKE.Timer_Stop(swigCPtr);
189 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193 /// Sets a new interval on the timer and starts the timer.<br>
194 /// Cancels the previous timer.<br>
196 /// <param name="milliSec">milliSec Interval in milliseconds</param>
197 internal void SetInterval(uint milliSec)
199 NDalicPINVOKE.Timer_SetInterval(swigCPtr, milliSec);
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203 internal uint GetInterval()
205 uint ret = NDalicPINVOKE.Timer_GetInterval(swigCPtr);
206 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211 /// Tells whether timer is running.
213 /// <returns>Whether Timer is started or not</returns>
214 public bool IsRunning()
216 bool ret = NDalicPINVOKE.Timer_IsRunning(swigCPtr);
217 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221 internal TimerSignalType TickSignal()
223 TimerSignalType ret = new TimerSignalType(NDalicPINVOKE.Timer_TickSignal(swigCPtr), false);
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();