2 * Copyright (c) 2018 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-toolkit/public-api/dali-toolkit-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;
39 bool gKeepTimersRunning = false;
42 * Implementation of the timer
44 class Timer : public BaseObject
47 void MockEmitSignal();
50 static TimerPtr New( unsigned int milliSec );
51 Timer( unsigned int milliSec );
56 void SetInterval( unsigned int interval );
57 unsigned int GetInterval() const;
58 bool IsRunning() const;
63 Dali::Timer::TimerSignalType& TickSignal();
65 private: // Implementation
68 Timer( const Timer& );
69 Timer& operator=( const Timer& );
73 unsigned int mInterval;
77 inline Timer& GetImplementation(Dali::Timer& timer)
79 DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
81 BaseObject& handle = timer.GetBaseObject();
83 return static_cast<Internal::Adaptor::Timer&>(handle);
86 inline const Timer& GetImplementation(const Dali::Timer& timer)
88 DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
90 const BaseObject& handle = timer.GetBaseObject();
92 return static_cast<const Internal::Adaptor::Timer&>(handle);
95 TimerPtr Timer::New( unsigned int milliSec )
97 TimerPtr timerImpl = new Timer( milliSec );
101 Timer::Timer( unsigned int milliSec )
102 : mInterval( milliSec ),
123 void Timer::SetInterval( unsigned int interval )
125 mInterval = interval;
128 unsigned int Timer::GetInterval() const
133 bool Timer::IsRunning() const
143 Dali::Timer::TimerSignalType& Timer::TickSignal()
148 // Mock setup functions:
150 void Timer::MockEmitSignal()
152 if( gTimerCount > 1 )
154 // Only emit the signal if we have more than just the timer created in the test function
159 } // namespace Adaptor
161 } // namespace Internal
163 /********************************************************************************/
164 /********************************* PUBLIC CLASS *******************************/
165 /********************************************************************************/
172 Timer Timer::New( unsigned int milliSec )
174 Internal::Adaptor::TimerPtr internal = Internal::Adaptor::Timer::New( milliSec );
175 return Timer(internal.Get());
178 Timer::Timer( const Timer& timer )
183 Timer& Timer::operator=( const Timer& timer )
185 // check self assignment
188 BaseHandle::operator=(timer);
199 Internal::Adaptor::GetImplementation( *this ).Start();
200 Dali::Internal::Adaptor::gKeepTimersRunning = true;
205 Internal::Adaptor::GetImplementation( *this ).Stop();
208 void Timer::SetInterval( unsigned int milliSec )
210 Internal::Adaptor::GetImplementation( *this ).SetInterval( milliSec );
213 unsigned int Timer::GetInterval() const
215 return Internal::Adaptor::GetImplementation( *this ).GetInterval();
218 bool Timer::IsRunning() const
223 Timer::TimerSignalType& Timer::TickSignal()
225 return Internal::Adaptor::GetImplementation( *this ).TickSignal();
228 Timer::Timer(Internal::Adaptor::Timer* timer)
233 // Mock setup functions:
235 void Timer::MockEmitSignal()
237 Internal::Adaptor::GetImplementation( *this ).MockEmitSignal();
248 return Dali::Internal::Adaptor::gTimerCount;
251 void EmitGlobalTimerSignal()
253 // @todo Multiplex timers properly.
254 Dali::Internal::Adaptor::gKeepTimersRunning = Dali::Internal::Adaptor::gTickSignal.Emit();
257 bool AreTimersRunning()
259 return Dali::Internal::Adaptor::gKeepTimersRunning;