Add move semantics to BaseHandle derived classes in Adaptor public API
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / timer.h
1 #ifndef DALI_TIMER_H
2 #define DALI_TIMER_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/signals/dali-signal.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/dali-adaptor-common.h>
28
29 namespace Dali
30 {
31 /**
32  * @addtogroup dali_adaptor_framework
33  * @{
34  */
35
36 namespace Internal DALI_INTERNAL
37 {
38 namespace Adaptor
39 {
40 class Timer;
41 }
42 }
43
44 /**
45  * @brief Mechanism to issue simple periodic or one-shot events.
46  *
47  * Timer is provided for application developers to be able to issue
48  * simple periodic or one-shot events.  Please note that timer
49  * callback functions should return as soon as possible, because they
50  * block the next SignalTick.  Please note that timer signals are not
51  * in sync with Dali's render timer.
52  *
53  * This class is a handle class so it can be stack allocated and used
54  * as a member.
55  * @SINCE_1_0.0
56  */
57 class DALI_ADAPTOR_API Timer : public BaseHandle
58 {
59 public: // Signal typedefs
60
61   typedef Signal< bool () > TimerSignalType; ///< Timer finished signal callback type @SINCE_1_0.0
62
63 public: // API
64
65   /**
66    * @brief Constructor, creates an uninitialized timer.
67    *
68    * Call New to fully construct a timer.
69    * @SINCE_1_0.0
70    */
71   Timer();
72
73   /**
74    * @brief Creates a tick Timer that emits periodic signal.
75    *
76    * @SINCE_1_0.0
77    * @param[in] milliSec Interval in milliseconds
78    * @return A new timer
79    */
80   static Timer New( unsigned int milliSec );
81
82   /**
83    * @brief Copy constructor.
84    *
85    * @SINCE_1_0.0
86    * @param[in] timer The handle to copy. The copied handle will point at the same implementation
87    */
88   Timer( const Timer& timer );
89
90   /**
91    * @brief Assignment operator.
92    *
93    * @SINCE_1_0.0
94    * @param[in] timer The handle to copy. This handle will point at the same implementation
95    * as the copied handle
96    * @return Reference to this timer handle
97    */
98   Timer& operator=( const Timer& timer );
99
100   /**
101    * @brief Move constructor.
102    *
103    * @SINCE_1_9.24
104    * @param[in] rhs A reference to the moved handle
105    */
106   Timer( Timer&& rhs );
107
108   /**
109    * @brief Move assignment operator.
110    *
111    * @SINCE_1_9.24
112    * @param[in] rhs A reference to the moved handle
113    * @return A reference to this handle
114    */
115   Timer& operator=( Timer&& rhs );
116
117   /**
118    * @brief Destructor.
119    *
120    * This is non-virtual since derived Handle types must not contain data or virtual methods.
121    * @SINCE_1_0.0
122    */
123   ~Timer();
124
125   /**
126    * @brief Downcasts a handle to Timer handle.
127    *
128    * If handle points to a Timer object, the downcast produces a valid handle.
129    * If not, the returned handle is left uninitialized.
130    *
131    * @SINCE_1_0.0
132    * @param[in] handle to An object
133    * @return handle to a Timer object or an uninitialized handle
134    */
135   static Timer DownCast( BaseHandle handle );
136
137   /**
138    * @brief Starts timer.
139    *
140    * In case a Timer is already running, its time is reset and timer is restarted.
141    * @SINCE_1_0.0
142    */
143   void Start();
144
145   /**
146    * @brief Stops timer.
147    * @SINCE_1_0.0
148    */
149   void Stop();
150
151   /**
152    * @brief Pauses timer.
153    * @SINCE_1_3.41
154    */
155   void Pause();
156
157   /**
158    * @brief Resumes timer.
159    * @SINCE_1_3.41
160    */
161   void Resume();
162
163   /**
164    * @brief Sets a new interval on the timer and starts the timer.
165    *
166    * Cancels the previous timer.
167    * @SINCE_1_0.0
168    * @param[in] milliSec Interval in milliseconds
169    */
170   void SetInterval( unsigned int milliSec );
171
172   /**
173    * @brief Sets a new interval on the timer with option to restart the timer.
174    *
175    * Cancels the previous timer.
176    * @SINCE_1_3.41
177    * @param[in] milliSec Interval in milliseconds
178    * @param[in] restart Flag to set enabled to restart or not.
179    */
180   void SetInterval( unsigned int milliSec, bool restart );
181
182   /**
183    * @brief Gets the interval of timer.
184    *
185    * @SINCE_1_0.0
186    * @return Interval in milliseconds
187    */
188   unsigned int GetInterval() const;
189
190   /**
191    * @brief Tells whether timer is running.
192    * @SINCE_1_0.0
193    * @return Whether Timer is started or not
194    */
195   bool IsRunning() const;
196
197 public: // Signals
198
199   /**
200    * @brief Signal emitted after specified time interval.
201    *
202    * The return of the callback decides whether signal emission stops or continues.
203    * If the callback function returns false, emission will stop and if true, it will continue.
204    * This return value is ignored for one-shot events, which will always stop after the first execution.
205    * @return The signal to Connect() with
206    * @SINCE_1_0.0
207    */
208   TimerSignalType& TickSignal();
209
210 public: // Not intended for application developers
211   explicit DALI_INTERNAL Timer(Internal::Adaptor::Timer* timer);
212 };
213
214 /**
215  * @}
216  */
217 } // namespace Dali
218
219 #endif // DALI_TIMER_H