nui 0.2.32 manual merge, mapping to dali 1.2.32
[platform/core/csapi/tizenfx.git] / NUISamples / 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.
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
41     /// as a member.
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         ~Timer()
58         {
59             DisposeQueue.Instance.Add(this);
60         }
61
62         public override void Dispose()
63         {
64             if (!Stage.IsInstalled())
65             {
66                 DisposeQueue.Instance.Add(this);
67                 return;
68             }
69
70             lock (this)
71             {
72                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
73                 {
74                     if (swigCMemOwn)
75                     {
76                         swigCMemOwn = false;
77                         NDalicPINVOKE.delete_Timer(swigCPtr);
78                     }
79                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
80                 }
81                 global::System.GC.SuppressFinalize(this);
82                 base.Dispose();
83             }
84         }
85
86
87         /// <summary>
88         /// Event arguments that passed via Tick event
89         /// </summary>
90         public class TickEventArgs : EventArgs
91         {
92         }
93
94         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
95         private delegate bool TickCallbackDelegate(IntPtr data);
96         private EventHandlerWithReturnType<object, TickEventArgs, bool> _timerTickEventHandler;
97         private TickCallbackDelegate _timerTickCallbackDelegate;
98
99         /// <summary>
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.
103         /// </summary>
104         public event EventHandlerWithReturnType<object, TickEventArgs, bool> Tick
105         {
106             add
107             {
108                 if (_timerTickEventHandler == null)
109                 {
110                     _timerTickCallbackDelegate = (OnTick);
111                     TickSignal().Connect(_timerTickCallbackDelegate);
112                 }
113                 _timerTickEventHandler += value;
114             }
115             remove
116             {
117                 _timerTickEventHandler -= value;
118                 if (_timerTickEventHandler == null && _timerTickCallbackDelegate != null)
119                 {
120                     TickSignal().Disconnect(_timerTickCallbackDelegate);
121                 }
122             }
123         }
124
125         private bool OnTick(IntPtr data)
126         {
127             TickEventArgs e = new TickEventArgs();
128
129             if (_timerTickEventHandler != null)
130             {
131                 //here we send all data to user event handlers
132                 return _timerTickEventHandler(this, e);
133             }
134             return false;
135         }
136
137         /// <summary>
138         /// Creates a tick Timer that emits periodic signal.
139         /// </summary>
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)
143         {
144             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
145
146         }
147         internal Timer(Timer timer) : this(NDalicPINVOKE.new_Timer__SWIG_1(Timer.getCPtr(timer)), true)
148         {
149             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150         }
151
152         internal Timer Assign(Timer timer)
153         {
154             Timer ret = new Timer(NDalicPINVOKE.Timer_Assign(swigCPtr, Timer.getCPtr(timer)), false);
155             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156             return ret;
157         }
158
159         /// <summary>
160         /// Downcasts a handle to Timer handle.
161         /// </summary>
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)
165         {
166             Timer ret = new Timer(NDalicPINVOKE.Timer_DownCast(BaseHandle.getCPtr(handle)), true);
167             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168             return ret;
169         }
170
171         /// <summary>
172         /// Starts timer
173         /// In case a Timer is already running, its time is reset and timer is restarted.
174         /// </summary>
175         public void Start()
176         {
177             NDalicPINVOKE.Timer_Start(swigCPtr);
178             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179         }
180
181         /// <summary>
182         /// Stops timer.
183         /// </summary>
184         public void Stop()
185         {
186             NDalicPINVOKE.Timer_Stop(swigCPtr);
187             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188         }
189
190         /// <summary>
191         /// Sets a new interval on the timer and starts the timer.
192         /// Cancels the previous timer.
193         /// </summary>
194         /// <param name="milliSec">milliSec Interval in milliseconds</param>
195         internal void SetInterval(uint milliSec)
196         {
197             NDalicPINVOKE.Timer_SetInterval(swigCPtr, milliSec);
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199         }
200
201         internal uint GetInterval()
202         {
203             uint ret = NDalicPINVOKE.Timer_GetInterval(swigCPtr);
204             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205             return ret;
206         }
207
208         /// <summary>
209         /// Tells whether timer is running.
210         /// </summary>
211         /// <returns>Whether Timer is started or not</returns>
212         public bool IsRunning()
213         {
214             bool ret = NDalicPINVOKE.Timer_IsRunning(swigCPtr);
215             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216             return ret;
217         }
218
219         internal TimerSignalType TickSignal()
220         {
221             TimerSignalType ret = new TimerSignalType(NDalicPINVOKE.Timer_TickSignal(swigCPtr), false);
222             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223             return ret;
224         }
225
226     }
227
228 }