04525be5384986304c9c81b73f9da971baad876f
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Timer.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
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
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 *
15 */
16 // This File has been auto-generated by SWIG and then modified using DALi Ruby Scripts
17 //------------------------------------------------------------------------------
18 // <auto-generated />
19 //
20 // This file was automatically generated by SWIG (http://www.swig.org).
21 // Version 3.0.9
22 //
23 // Do not make changes to this file unless you know what you are doing--modify
24 // the SWIG interface file instead.
25 //------------------------------------------------------------------------------
26
27 namespace Tizen.NUI
28 {
29
30     using System;
31     using System.Runtime.InteropServices;
32
33     /// <summary>
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
41     /// as a member.<br>
42     /// </summary>
43     public class Timer : BaseHandle
44     {
45         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
46
47         internal Timer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Timer_SWIGUpcast(cPtr), cMemoryOwn)
48         {
49             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
50         }
51
52         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Timer obj)
53         {
54             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
55         }
56
57         protected override void Dispose(DisposeTypes type)
58         {
59             if(disposed)
60             {
61                 return;
62             }
63
64             if(type == DisposeTypes.Explicit)
65             {
66                 //Called by User
67                 //Release your own managed resources here.
68                 //You should release all of your own disposable objects here.
69             }
70
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.
74
75             if (swigCPtr.Handle != global::System.IntPtr.Zero)
76             {
77                 if (swigCMemOwn)
78                 {
79                     swigCMemOwn = false;
80                     NDalicPINVOKE.delete_Timer(swigCPtr);
81                 }
82                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
83             }
84
85             base.Dispose(type);
86         }
87
88
89         /// <summary>
90         /// Event arguments that passed via Tick event.
91         /// </summary>
92         public class TickEventArgs : EventArgs
93         {
94         }
95
96         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
97         private delegate bool TickCallbackDelegate(IntPtr data);
98         private EventHandlerWithReturnType<object, TickEventArgs, bool> _timerTickEventHandler;
99         private TickCallbackDelegate _timerTickCallbackDelegate;
100
101         /// <summary>
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>
105         /// </summary>
106         public event EventHandlerWithReturnType<object, TickEventArgs, bool> Tick
107         {
108             add
109             {
110                 if (_timerTickEventHandler == null)
111                 {
112                     _timerTickCallbackDelegate = (OnTick);
113                     TickSignal().Connect(_timerTickCallbackDelegate);
114                 }
115                 _timerTickEventHandler += value;
116             }
117             remove
118             {
119                 _timerTickEventHandler -= value;
120                 if (_timerTickEventHandler == null && TickSignal().Empty() == false)
121                 {
122                     TickSignal().Disconnect(_timerTickCallbackDelegate);
123                 }
124             }
125         }
126
127         private bool OnTick(IntPtr data)
128         {
129             TickEventArgs e = new TickEventArgs();
130
131             if (_timerTickEventHandler != null)
132             {
133                 //here we send all data to user event handlers
134                 return _timerTickEventHandler(this, e);
135             }
136             return false;
137         }
138
139         /// <summary>
140         /// Creates a tick Timer that emits periodic signal.
141         /// </summary>
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)
145         {
146             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147
148         }
149         internal Timer(Timer timer) : this(NDalicPINVOKE.new_Timer__SWIG_1(Timer.getCPtr(timer)), true)
150         {
151             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152         }
153
154         internal Timer Assign(Timer timer)
155         {
156             Timer ret = new Timer(NDalicPINVOKE.Timer_Assign(swigCPtr, Timer.getCPtr(timer)), false);
157             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158             return ret;
159         }
160
161         /// <summary>
162         /// Downcasts a handle to Timer handle.
163         /// </summary>
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)
167         {
168             Timer ret = new Timer(NDalicPINVOKE.Timer_DownCast(BaseHandle.getCPtr(handle)), true);
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170             return ret;
171         }
172
173         /// <summary>
174         /// Starts timer.<br>
175         /// In case a Timer is already running, its time is reset and timer is restarted.<br>
176         /// </summary>
177         public void Start()
178         {
179             NDalicPINVOKE.Timer_Start(swigCPtr);
180             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181         }
182
183         /// <summary>
184         /// Stops timer.
185         /// </summary>
186         public void Stop()
187         {
188             NDalicPINVOKE.Timer_Stop(swigCPtr);
189             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190         }
191
192         /// <summary>
193         /// Sets a new interval on the timer and starts the timer.<br>
194         /// Cancels the previous timer.<br>
195         /// </summary>
196         /// <param name="milliSec">milliSec Interval in milliseconds</param>
197         internal void SetInterval(uint milliSec)
198         {
199             NDalicPINVOKE.Timer_SetInterval(swigCPtr, milliSec);
200             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201         }
202
203         internal uint GetInterval()
204         {
205             uint ret = NDalicPINVOKE.Timer_GetInterval(swigCPtr);
206             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207             return ret;
208         }
209
210         /// <summary>
211         /// Tells whether timer is running.
212         /// </summary>
213         /// <returns>Whether Timer is started or not</returns>
214         public bool IsRunning()
215         {
216             bool ret = NDalicPINVOKE.Timer_IsRunning(swigCPtr);
217             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218             return ret;
219         }
220
221         internal TimerSignalType TickSignal()
222         {
223             TimerSignalType ret = new TimerSignalType(NDalicPINVOKE.Timer_TickSignal(swigCPtr), false);
224             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225             return ret;
226         }
227
228     }
229
230 }