1 #ifndef __DALI_TIMER_H__
2 #define __DALI_TIMER_H__
5 * Copyright (c) 2015 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>
29 * @addtogroup dali_adaptor_framework
33 namespace Internal DALI_INTERNAL
42 * @brief Mechanism to issue simple periodic or one-shot events.
44 * Timer is provided for application developers to be able to issue
45 * simple periodic or one-shot events. Please note that timer
46 * callback functions should return as soon as possible, because they
47 * block the next SignalTick. Please note that timer signals are not
48 * in sync with Dali's render timer.
50 * This class is a handle class so it can be stack allocated and used
53 class DALI_IMPORT_API Timer : public BaseHandle
55 public: // Signal typedefs
57 typedef Signal< bool () > TimerSignalType; ///< Timer finished signal callback type
62 * @brief Constructor, creates an uninitialized timer.
64 * Call New to fully construct a timer.
69 * @brief Create an tick Timer that emits periodic signal.
71 * @param[in] milliSec Interval in milliseconds.
74 static Timer New( unsigned int milliSec );
77 * @brief Copy constructor.
79 * @param[in] timer The handle to copy. The copied handle will point at the same implementation
81 Timer( const Timer& timer );
84 * @brief Assignment operator.
86 * @param[in] timer The handle to copy. This handle will point at the same implementation
87 * as the copied handle.
88 * @return Reference to this timer handle
90 Timer& operator=( const Timer& timer );
95 * This is non-virtual since derived Handle types must not contain data or virtual methods.
100 * @brief Downcast an Object handle to Timer handle.
102 * If handle points to a Timer object the downcast produces a valid
103 * handle. If not the returned handle is left uninitialized.
105 * @param[in] handle to An object
106 * @return handle to a Timer object or an uninitialized handle
108 static Timer DownCast( BaseHandle handle );
111 * @brief Start timer.
113 * In case a Timer is already running it's time is reset and timer is restarted.
123 * @brief Sets a new interval on the timer and starts the timer.
125 * Cancels the previous timer.
126 * @param milliSec Interval in milliseconds.
128 void SetInterval( unsigned int milliSec );
131 * @brief Get the interval of timer.
132 * @returns Interval in milliseconds.
134 unsigned int GetInterval() const;
137 * @brief Tells whether timer is running.
138 * @return Whether Timer is started or not.
140 bool IsRunning() const;
145 * @brief Signal emitted after specified time interval.
147 * The return of the callback decides whether signal emission stops or continues.
148 * If the callback function returns false emission will stop, if true it will continue
149 * This return value is ignored for one-shot events, which will always stop after the first execution.
150 * @returns The signal to Connect() with.
152 TimerSignalType& TickSignal();
154 public: // Not intended for application developers
155 explicit DALI_INTERNAL Timer(Internal::Adaptor::Timer* timer);
163 #endif // __DALI_TIMER_H__