5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/signals/dali-signal.h>
27 #include <dali/public-api/dali-adaptor-common.h>
32 * @addtogroup dali_adaptor_framework
36 namespace Internal DALI_INTERNAL
42 } // namespace DALI_INTERNAL
45 * @brief Mechanism to issue simple periodic or one-shot events.
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.
53 * This class is a handle class so it can be stack allocated and used
57 class DALI_ADAPTOR_API Timer : public BaseHandle
59 public: // Signal typedefs
60 typedef Signal<bool()> TimerSignalType; ///< Timer finished signal callback type @SINCE_1_0.0
64 * @brief Constructor, creates an uninitialized timer.
66 * Call New to fully construct a timer.
72 * @brief Creates a tick Timer that emits periodic signal.
75 * @param[in] milliSec Interval in milliseconds
78 static Timer New(unsigned int milliSec);
81 * @brief Copy constructor.
84 * @param[in] timer The handle to copy. The copied handle will point at the same implementation
86 Timer(const Timer& timer);
89 * @brief Assignment operator.
92 * @param[in] timer The handle to copy. This handle will point at the same implementation
93 * as the copied handle
94 * @return Reference to this timer handle
96 Timer& operator=(const Timer& timer);
99 * @brief Move constructor.
102 * @param[in] rhs A reference to the moved handle
107 * @brief Move assignment operator.
110 * @param[in] rhs A reference to the moved handle
111 * @return A reference to this handle
113 Timer& operator=(Timer&& rhs);
118 * This is non-virtual since derived Handle types must not contain data or virtual methods.
124 * @brief Downcasts a handle to Timer handle.
126 * If handle points to a Timer object, the downcast produces a valid handle.
127 * If not, the returned handle is left uninitialized.
130 * @param[in] handle to An object
131 * @return handle to a Timer object or an uninitialized handle
133 static Timer DownCast(BaseHandle handle);
136 * @brief Starts timer.
138 * In case a Timer is already running, its time is reset and timer is restarted.
144 * @brief Stops timer.
150 * @brief Pauses timer.
156 * @brief Resumes timer.
162 * @brief Sets a new interval on the timer and starts the timer.
164 * Cancels the previous timer.
166 * @param[in] milliSec Interval in milliseconds
168 void SetInterval(unsigned int milliSec);
171 * @brief Sets a new interval on the timer with option to restart the timer.
173 * Cancels the previous timer.
175 * @param[in] milliSec Interval in milliseconds
176 * @param[in] restart Flag to set enabled to restart or not.
178 void SetInterval(unsigned int milliSec, bool restart);
181 * @brief Gets the interval of timer.
184 * @return Interval in milliseconds
186 unsigned int GetInterval() const;
189 * @brief Tells whether timer is running.
191 * @return Whether Timer is started or not
193 bool IsRunning() const;
197 * @brief Signal emitted after specified time interval.
199 * The return of the callback decides whether signal emission stops or continues.
200 * If the callback function returns false, emission will stop and if true, it will continue.
201 * This return value is ignored for one-shot events, which will always stop after the first execution.
202 * @return The signal to Connect() with
205 TimerSignalType& TickSignal();
207 public: // Not intended for application developers
208 explicit DALI_INTERNAL Timer(Internal::Adaptor::Timer* timer);
216 #endif // DALI_TIMER_H