b8ebcf43bbab10f48232741565ac28493233a08b
[platform/core/uifw/dali-adaptor.git] / adaptors / public-api / timer.h
1 #ifndef __DALI_TIMER_H__
2 #define __DALI_TIMER_H__
3
4 /*
5  * Copyright (c) 2014 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 /**
22  * @addtogroup CAPI_DALI_ADAPTOR_MODULE
23  * @{
24  */
25
26 // EXTERNAL INCLUDES
27
28 #include <dali/public-api/object/base-handle.h>
29 #include <dali/public-api/signals/dali-signal-v2.h>
30
31 namespace Dali DALI_IMPORT_API
32 {
33
34 namespace Internal DALI_INTERNAL
35 {
36 namespace Adaptor
37 {
38 class Timer;
39 }
40 }
41
42 /**
43  * @brief Mechanism to issue simple periodic or one-shot events.
44  *
45  * Timer is provided for application developers to be able to issue
46  * simple periodic or one-shot events.  Please note that timer
47  * callback functions should return as soon as possible, because they
48  * block the next SignalTick.  Please note that timer signals are not
49  * in sync with Dali's render timer.
50  *
51  * This class is a handle class so it can be stack allocated and used
52  * as a member.
53  */
54 class Timer : public BaseHandle
55 {
56 public: // Signal typedefs
57
58   typedef SignalV2< bool () > TimerSignalV2; ///< Timer finished signal callback type
59
60 public: // API
61
62   /**
63    * @brief Constructor, creates an uninitialized timer.
64    *
65    * Call New to fully construct a timer.
66    */
67   Timer();
68
69   /**
70    * @brief Create an tick Timer that emits periodic signal.
71    *
72    * @param[in] milliSec Interval in milliseconds.
73    * @return a new timer
74    */
75   static Timer New( unsigned int milliSec );
76
77   /**
78    * @brief Copy constructor.
79    *
80    * @param[in] timer The handle to copy. The copied handle will point at the same implementation
81    */
82   Timer( const Timer& timer );
83
84   /**
85    * @brief Assignment operator.
86    *
87    * @param[in] timer The handle to copy. This handle will point at the same implementation
88    * as the copied handle.
89    * @return Reference to this timer handle
90    */
91   Timer& operator=( const Timer& timer );
92
93   /**
94    * @brief Destructor
95    *
96    * This is non-virtual since derived Handle types must not contain data or virtual methods.
97    */
98   ~Timer();
99
100   /**
101    * @brief Downcast an Object handle to Timer handle.
102    *
103    * If handle points to a Timer object the downcast produces a valid
104    * handle. If not the returned handle is left uninitialized.
105    *
106    * @param[in] handle to An object
107    * @return handle to a Timer object or an uninitialized handle
108    */
109   static Timer DownCast( BaseHandle handle );
110
111   /**
112    * @copydoc Dali::BaseHandle::operator=
113    */
114   using BaseHandle::operator=;
115
116   /**
117    * @brief Start timer.
118    *
119    * In case a Timer is already running it's time is reset and timer is restarted.
120    */
121   void Start();
122
123   /**
124    * @brief Stop timer.
125    */
126   void Stop();
127
128   /**
129    * @brief Sets a new interval on the timer and starts the timer.
130    *
131    * Cancels the previous timer.
132    * @param  milliSec Interval in milliseconds.
133    */
134   void SetInterval( unsigned int milliSec );
135
136   /**
137    * @brief Get the interval of timer.
138    * @returns  Interval in milliseconds.
139    */
140   unsigned int GetInterval() const;
141
142   /**
143    * @brief  Tells whether timer is running.
144    * @return Whether Timer is started or not.
145    */
146   bool IsRunning() const;
147
148 public: // Signals
149
150   /**
151    * @brief Signal emitted after specified time interval.
152    *
153    * The return of the callback decides whether signal emission stops or continues.
154    * If the callback function returns false emission will stop, if true it will continue
155    * This return value is ignored for one-shot events, which will always stop after the first execution.
156    * @returns The signal to Connect() with.
157    */
158   TimerSignalV2& TickSignal();
159
160 public: // Not intended for application developers
161   explicit DALI_INTERNAL Timer(Internal::Adaptor::Timer* timer);
162 };
163
164 } // namespace Dali
165
166 /**
167  * @}
168  */
169 #endif // __DALI_TIMER_H__