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