2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FBaseRtTimer.h
19 * @brief This is the header file for the %Timer class.
21 * This header file contains the declarations of the %Timer class.
24 #ifndef _FBASE_RT_TIMER_H_
25 #define _FBASE_RT_TIMER_H_
27 #include <FBaseString.h>
28 #include <FBaseResult.h>
29 #include <FBaseRtTypes.h>
30 #include <FBaseRtITimerEventListener.h>
32 namespace Tizen { namespace Base { namespace Runtime
36 * @brief This class provides the timer service.
40 * The %Timer class can activate the timer and notify the listeners.
41 * It supports the relative time and provides both repeatable and non-repeatable timers.
42 * Because %Timer is handled in an event-driven way, when the main loop gets blocked, even if the time is expired, the listener cannot get notified.
43 * Once the target goes into the sleep mode, %Timer does not work properly because the main loop gets stopped.
44 * You can use Alarm on behalf of the %Timer for the sleep mode.
45 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/timer.htm">Timer</a>.
46 * The following example demonstrates how to use the %Timer class.
52 * using namespace Tizen::Base;
53 * using namespace Tizen::Base::Runtime;
56 * : public ITimerEventListener
63 * void OnTimerExpired(Timer& timer);
64 * bool IsTimerExpired() const;
65 * int GetCount() {return __count;};
69 * bool __bTimerExpired;
74 * MyTimerApp::MyTimerApp()
75 * : __bTimerExpired(false)
78 * __timer.Construct(*this);
81 * MyTimerApp::~MyTimerApp()
86 * MyTimerApp::OnTimerExpired(Timer& timer)
91 * __bTimerExpired = true;
98 * AppLog("TimerApp: Current count: %d\n", __count);
102 * MyTimerApp::IsTimerExpired() const
104 * return __bTimerExpired;
108 * MyTimerApp::StartApp()
115 * @see ITimerEventListener
116 * @see Tizen::System::Alarm
119 class _OSP_EXPORT_ Timer
120 : public Tizen::Base::Object
124 * This is the default constructor for this class.
132 * This is the destructor for this class.
136 virtual ~Timer(void);
139 * Initializes this instance of %Timer with the specified listener.
143 * @return An error code
144 * @param[in] listener The event listener
145 * @exception E_SUCCESS The method is successful.
146 * @exception E_OUT_OF_MEMORY The memory is insufficient.
147 * @exception E_SYSTEM A system error has occurred.
149 result Construct(ITimerEventListener& listener);
155 * @brief <i> [Compatibility] </i>
161 * @compatibility This method has compatibility issues with Tizen API versions @b prior @b to @b 2.1. @n
162 * For more information, see @ref CompTimerStartPage "here".
165 * @return An error code
166 * @param[in] timeout The timeout interval in milliseconds
167 * @exception E_SUCCESS The method is successful.
168 * @exception E_INVALID_ARG The specified input parameter is invalid.
169 * @exception E_INVALID_STATE The timer cannot start as it is in an invalid state.
170 * @exception E_SYSTEM A system error has occurred.
171 * @remarks Once the timer has been started, it cannot be started again until it has expired.
174 result Start(int timeout);
177 * @page CompTimerStartPage Compatibility for Start(int timeout)
178 * @section CompTimerStartPageIssueSection Issues
179 * Implementation of this method in Tizen API versions prior to 2.1 has the following issue: @n
180 * -# The method returns @c E_INVALID_ARG if timeout is equal to zero.
182 * @section CompTimerStartPageSolutionSection Resolutions
183 * The issue mentioned above is resolved in Tizen API version 2.1, and it is recommended to use Tizen API version 2.1 or above.
184 * -# In case of zero, %Timer sets the timeout to the best possible minimum interval without returning @c E_INVALID_ARG.
188 * Starts the timer. @n
189 * The timer expires repeatedly until it is cancelled.
193 * @return An error code
194 * @param[in] interval The timeout interval in milliseconds
195 * @exception E_SUCCESS The method is successful.
196 * @exception E_INVALID_ARG The specified input parameter is invalid.
197 * @exception E_INVALID_STATE The timer cannot start as it is in an invalid state.
198 * @exception E_SYSTEM A system error has occurred.
199 * @remarks To stop the timer expiration or restart the timer, the timer must be cancelled.
202 result StartAsRepeatable(int interval);
209 * @return An error code
210 * @exception E_SUCCESS The method is successful.
211 * @exception E_SYSTEM A system error has occurred.
212 * @remarks The started timer can be cancelled when it does not get expired. @n
213 * If the timer has already expired, this method also returns @c E_SUCCESS which causes the same effect as when cancelled normally.
218 Timer(const Timer& rhs);
220 Timer& operator =(const Timer& rhs);
223 friend class _TimerImpl;
224 class _TimerImpl * __pTimerImpl;
228 } } } // Tizen::Runtime
230 #endif // _FBASE_RT_TIMER_H_