2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FBaseRtTimer.h
20 * @brief This is the header file for the %Timer class.
22 * This header file contains the declarations of the %Timer class.
25 #ifndef _FBASE_RT_TIMER_H_
26 #define _FBASE_RT_TIMER_H_
28 #include <FBaseString.h>
29 #include <FBaseResult.h>
30 #include <FBaseRtTypes.h>
31 #include <FBaseRtITimerEventListener.h>
33 namespace Tizen { namespace Base { namespace Runtime
37 * @brief This class provides the timer service.
41 * The %Timer class can activate the timer and notify the listeners.
42 * Once the target goes into sleep mode, Timer does not work properly because the main loop gets stopped.
43 * You can use Alarm on behalf of Timer for sleep mode.
44 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/timer.htm">Timer</a>.
45 * The following example demonstrates how to use the %Timer class.
51 * using namespace Tizen::Base;
52 * using namespace Tizen::Base::Runtime;
55 * : public ITimerEventListener
62 * void OnTimerExpired(Timer& timer);
63 * bool IsTimerExpired() const;
64 * int GetCount() {return __count;};
68 * bool __bTimerExpired;
73 * MyTimerApp::MyTimerApp()
74 * : __bTimerExpired(false)
77 * __timer.Construct(*this);
80 * MyTimerApp::~MyTimerApp()
85 * MyTimerApp::OnTimerExpired(Timer& timer)
90 * __bTimerExpired = true;
97 * AppLog("TimerApp: Current count: %d\n", __count);
101 * MyTimerApp::IsTimerExpired() const
103 * return __bTimerExpired;
107 * MyTimerApp::StartApp()
114 * @see ITimerEventListener
115 * @see Tizen::System::Alarm
118 class _OSP_EXPORT_ Timer
119 : public Tizen::Base::Object
123 * This is the default constructor for this class.
131 * This is the destructor for this class.
135 virtual ~Timer(void);
138 * Initializes this instance of %Timer with the specified listener.
142 * @return An error code
143 * @param[in] listener The event listener
144 * @exception E_SUCCESS The method is successful.
145 * @exception E_OUT_OF_MEMORY The memory is insufficient.
146 * @exception E_SYSTEM A system error has occurred.
148 result Construct(ITimerEventListener& listener);
154 * @brief <i> [Compatibility] </i>
160 * @compatibility This method has compatibility issues with Tizen API versions @b prior @b to @b 2.1. @n
161 * For more information, see @ref CompTimerStartPage "here".
164 * @return An error code
165 * @param[in] timeout A timeout interval in milliseconds
166 * @exception E_SUCCESS The method is successful.
167 * @exception E_INVALID_ARG The specified input parameter is invalid.
168 * @exception E_SYSTEM A system error has occurred.
169 * @remarks Once it has been started, it cannot be started again until it expires. @n
170 * You must cancel it if you want to re-start the timer.
173 result Start(int timeout);
176 * @page CompTimerStartPage Compatibility for Start(int timeout)
177 * @section CompTimerStartPageIssueSection Issues
178 * Implementation of this method in Tizen API versions prior to 2.1 has the following issue: @n
179 * -# The method returns E_INVALID_ARG if timeout is equal to zero.
181 * @section CompTimerStartPageSolutionSection Resolutions
182 * 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.
183 * -# In case of zero, Timer sets timeout to the best-effort minimum interval without returning E_INVALID_ARG.
187 * Starts the timer. @n
188 * The timer is expired repeatedly until it is canceled.
192 * @return An error code
193 * @param[in] interval A timeout interval in milliseconds
194 * @exception E_SUCCESS The method is successful.
195 * @exception E_INVALID_ARG The specified input parameter is invalid.
196 * @exception E_SYSTEM A system error has occurred.
197 * @remarks To stop timer expiration or restart a timer, the timer must be canceled.
200 result StartAsRepeatable(int interval);
207 * @return An error code
208 * @exception E_SUCCESS The method is successful.
209 * @exception E_SYSTEM A system error has occurred.
210 * @remarks The timer cannot be canceled if it is not started.
215 Timer(const Timer& rhs);
217 Timer& operator =(const Timer& rhs);
220 friend class _TimerImpl;
221 class _TimerImpl * __pTimerImpl;
225 } } } // Tizen::Runtime
227 #endif // _FBASE_RT_TIMER_H_