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