2 * Copyright (c) 2015 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;
37 Dali::Timer::TimerSignalType gTickSignal;
40 * Implementation of the timer
42 class Timer : public BaseObject
45 void MockEmitSignal();
48 static TimerPtr New( unsigned int milliSec );
49 Timer( unsigned int milliSec );
54 void SetInterval( unsigned int interval );
55 unsigned int GetInterval() const;
56 bool IsRunning() const;
61 Dali::Timer::TimerSignalType& TickSignal();
63 private: // Implementation
66 Timer( const Timer& );
67 Timer& operator=( const Timer& );
71 unsigned int mInterval;
74 inline Timer& GetImplementation(Dali::Timer& timer)
76 DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
78 BaseObject& handle = timer.GetBaseObject();
80 return static_cast<Internal::Adaptor::Timer&>(handle);
83 inline const Timer& GetImplementation(const Dali::Timer& timer)
85 DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
87 const BaseObject& handle = timer.GetBaseObject();
89 return static_cast<const Internal::Adaptor::Timer&>(handle);
92 TimerPtr Timer::New( unsigned int milliSec )
94 TimerPtr timerImpl = new Timer( milliSec );
98 Timer::Timer( unsigned int milliSec )
99 : mInterval( milliSec )
115 void Timer::SetInterval( unsigned int interval )
117 mInterval = interval;
120 unsigned int Timer::GetInterval() const
125 bool Timer::IsRunning() const
135 Dali::Timer::TimerSignalType& Timer::TickSignal()
140 // Mock setup functions:
142 void Timer::MockEmitSignal()
148 } // namespace Adaptor
150 } // namespace Internal
152 /********************************************************************************/
153 /********************************* PUBLIC CLASS *******************************/
154 /********************************************************************************/
161 Timer Timer::New( unsigned int milliSec )
163 Internal::Adaptor::TimerPtr internal = Internal::Adaptor::Timer::New( milliSec );
164 return Timer(internal.Get());
167 Timer::Timer( const Timer& timer )
172 Timer& Timer::operator=( const Timer& timer )
174 // check self assignment
177 BaseHandle::operator=(timer);
188 Internal::Adaptor::GetImplementation( *this ).Start();
193 Internal::Adaptor::GetImplementation( *this ).Stop();
196 void Timer::SetInterval( unsigned int milliSec )
198 Internal::Adaptor::GetImplementation( *this ).SetInterval( milliSec );
201 unsigned int Timer::GetInterval() const
203 return Internal::Adaptor::GetImplementation( *this ).GetInterval();
206 bool Timer::IsRunning() const
211 Timer::TimerSignalType& Timer::TickSignal()
213 return Internal::Adaptor::GetImplementation( *this ).TickSignal();
216 Timer::Timer(Internal::Adaptor::Timer* timer)
221 // Mock setup functions:
223 void Timer::MockEmitSignal()
225 Internal::Adaptor::GetImplementation( *this ).MockEmitSignal();