2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
17 #include "toolkit-timer.h"
20 #include <dali/public-api/common/dali-common.h>
21 #include <dali/public-api/object/base-object.h>
22 #include <dali/public-api/signals/dali-signal-v2.h>
34 typedef IntrusivePtr<Timer> TimerPtr;
37 * Implementation of the timer
39 class Timer : public BaseObject
42 static TimerPtr New( unsigned int milliSec );
43 Timer( unsigned int milliSec );
48 void SetInterval( unsigned int interval );
49 unsigned int GetInterval() const;
50 bool IsRunning() const;
55 Dali::Timer::TimerSignalV2& TickSignal();
57 private: // Implementation
60 Timer( const Timer& );
61 Timer& operator=( const Timer& );
65 Dali::Timer::TimerSignalV2 mTickSignal;
66 unsigned int mInterval;
69 inline Timer& GetImplementation(Dali::Timer& timer)
71 DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
73 BaseObject& handle = timer.GetBaseObject();
75 return static_cast<Internal::Adaptor::Timer&>(handle);
78 inline const Timer& GetImplementation(const Dali::Timer& timer)
80 DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
82 const BaseObject& handle = timer.GetBaseObject();
84 return static_cast<const Internal::Adaptor::Timer&>(handle);
87 TimerPtr Timer::New( unsigned int milliSec )
89 TimerPtr timerImpl = new Timer(10);
93 Timer::Timer( unsigned int milliSec )
94 : mInterval( milliSec )
110 void Timer::SetInterval( unsigned int interval )
112 mInterval = interval;
115 unsigned int Timer::GetInterval() const
120 bool Timer::IsRunning() const
130 Dali::Timer::TimerSignalV2& Timer::TickSignal()
135 } // namespace Adaptor
137 } // namespace Internal
139 /********************************************************************************/
140 /********************************* PUBLIC CLASS *******************************/
141 /********************************************************************************/
148 Timer Timer::New( unsigned int milliSec )
150 Internal::Adaptor::TimerPtr internal = Internal::Adaptor::Timer::New( milliSec );
151 return Timer(internal.Get());
154 Timer::Timer( const Timer& timer )
159 Timer& Timer::operator=( const Timer& timer )
161 // check self assignment
164 BaseHandle::operator=(timer);
175 Internal::Adaptor::GetImplementation( *this ).Start();
180 Internal::Adaptor::GetImplementation( *this ).Stop();
183 void Timer::SetInterval( unsigned int milliSec )
185 Internal::Adaptor::GetImplementation( *this ).SetInterval( milliSec );
188 unsigned int Timer::GetInterval() const
190 return Internal::Adaptor::GetImplementation( *this ).GetInterval();
193 bool Timer::IsRunning() const
198 Timer::TimerSignalV2& Timer::TickSignal()
200 return Internal::Adaptor::GetImplementation( *this ).TickSignal();
203 Timer::Timer(Internal::Adaptor::Timer* timer)