2 * Copyright (c) 2016 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;
41 * Implementation of the timer
43 class Timer : public BaseObject
46 void MockEmitSignal();
49 static TimerPtr New( unsigned int milliSec );
50 Timer( unsigned int milliSec );
55 void SetInterval( unsigned int interval );
56 unsigned int GetInterval() const;
57 bool IsRunning() const;
62 Dali::Timer::TimerSignalType& TickSignal();
64 private: // Implementation
67 Timer( const Timer& );
68 Timer& operator=( const Timer& );
72 unsigned int mInterval;
75 inline Timer& GetImplementation(Dali::Timer& timer)
77 DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
79 BaseObject& handle = timer.GetBaseObject();
81 return static_cast<Internal::Adaptor::Timer&>(handle);
84 inline const Timer& GetImplementation(const Dali::Timer& timer)
86 DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
88 const BaseObject& handle = timer.GetBaseObject();
90 return static_cast<const Internal::Adaptor::Timer&>(handle);
93 TimerPtr Timer::New( unsigned int milliSec )
95 TimerPtr timerImpl = new Timer( milliSec );
99 Timer::Timer( unsigned int milliSec )
100 : mInterval( milliSec )
118 void Timer::SetInterval( unsigned int interval )
120 mInterval = interval;
123 unsigned int Timer::GetInterval() const
128 bool Timer::IsRunning() const
138 Dali::Timer::TimerSignalType& Timer::TickSignal()
143 // Mock setup functions:
145 void Timer::MockEmitSignal()
147 if( gTimerCount > 1 )
149 // Only emit the signal if we have more than just the timer created in the test function
155 } // namespace Adaptor
157 } // namespace Internal
159 /********************************************************************************/
160 /********************************* PUBLIC CLASS *******************************/
161 /********************************************************************************/
168 Timer Timer::New( unsigned int milliSec )
170 Internal::Adaptor::TimerPtr internal = Internal::Adaptor::Timer::New( milliSec );
171 return Timer(internal.Get());
174 Timer::Timer( const Timer& timer )
179 Timer& Timer::operator=( const Timer& timer )
181 // check self assignment
184 BaseHandle::operator=(timer);
195 Internal::Adaptor::GetImplementation( *this ).Start();
200 Internal::Adaptor::GetImplementation( *this ).Stop();
203 void Timer::SetInterval( unsigned int milliSec )
205 Internal::Adaptor::GetImplementation( *this ).SetInterval( milliSec );
208 unsigned int Timer::GetInterval() const
210 return Internal::Adaptor::GetImplementation( *this ).GetInterval();
213 bool Timer::IsRunning() const
218 Timer::TimerSignalType& Timer::TickSignal()
220 return Internal::Adaptor::GetImplementation( *this ).TickSignal();
223 Timer::Timer(Internal::Adaptor::Timer* timer)
228 // Mock setup functions:
230 void Timer::MockEmitSignal()
232 Internal::Adaptor::GetImplementation( *this ).MockEmitSignal();