2 * Copyright (c) 2014 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 #include "toolkit-timer.h"
21 #include <dali/public-api/common/dali-common.h>
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/public-api/signals/dali-signal.h>
35 typedef IntrusivePtr<Timer> TimerPtr;
38 * Implementation of the timer
40 class Timer : public BaseObject
43 static TimerPtr New( unsigned int milliSec );
44 Timer( unsigned int milliSec );
49 void SetInterval( unsigned int interval );
50 unsigned int GetInterval() const;
51 bool IsRunning() const;
56 Dali::Timer::TimerSignalType& TickSignal();
58 private: // Implementation
61 Timer( const Timer& );
62 Timer& operator=( const Timer& );
66 Dali::Timer::TimerSignalType mTickSignal;
67 unsigned int mInterval;
70 inline Timer& GetImplementation(Dali::Timer& timer)
72 DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
74 BaseObject& handle = timer.GetBaseObject();
76 return static_cast<Internal::Adaptor::Timer&>(handle);
79 inline const Timer& GetImplementation(const Dali::Timer& timer)
81 DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
83 const BaseObject& handle = timer.GetBaseObject();
85 return static_cast<const Internal::Adaptor::Timer&>(handle);
88 TimerPtr Timer::New( unsigned int milliSec )
90 TimerPtr timerImpl = new Timer(10);
94 Timer::Timer( unsigned int milliSec )
95 : mInterval( milliSec )
111 void Timer::SetInterval( unsigned int interval )
113 mInterval = interval;
116 unsigned int Timer::GetInterval() const
121 bool Timer::IsRunning() const
131 Dali::Timer::TimerSignalType& Timer::TickSignal()
136 } // namespace Adaptor
138 } // namespace Internal
140 /********************************************************************************/
141 /********************************* PUBLIC CLASS *******************************/
142 /********************************************************************************/
149 Timer Timer::New( unsigned int milliSec )
151 Internal::Adaptor::TimerPtr internal = Internal::Adaptor::Timer::New( milliSec );
152 return Timer(internal.Get());
155 Timer::Timer( const Timer& timer )
160 Timer& Timer::operator=( const Timer& timer )
162 // check self assignment
165 BaseHandle::operator=(timer);
176 Internal::Adaptor::GetImplementation( *this ).Start();
181 Internal::Adaptor::GetImplementation( *this ).Stop();
184 void Timer::SetInterval( unsigned int milliSec )
186 Internal::Adaptor::GetImplementation( *this ).SetInterval( milliSec );
189 unsigned int Timer::GetInterval() const
191 return Internal::Adaptor::GetImplementation( *this ).GetInterval();
194 bool Timer::IsRunning() const
199 Timer::TimerSignalType& Timer::TickSignal()
201 return Internal::Adaptor::GetImplementation( *this ).TickSignal();
204 Timer::Timer(Internal::Adaptor::Timer* timer)