2 * Copyright (c) 2017 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.
19 #include "timer-impl.h"
22 #include <adaptor-impl.h>
25 #include <dali/public-api/common/dali-common.h>
27 // Ecore is littered with C style cast
28 #pragma GCC diagnostic push
29 #pragma GCC diagnostic ignored "-Wold-style-cast"
44 Eina_Bool TimerSourceFunc (void *data)
46 Timer* timer = static_cast<Timer*>(data);
48 bool keepRunning = timer->Tick();
50 return keepRunning ? EINA_TRUE : EINA_FALSE;
52 } // unnamed namespace
55 * Struct to hide away Ecore implementation details
59 Impl( unsigned int milliSec )
66 unsigned int mInterval;
69 TimerPtr Timer::New( unsigned int milliSec )
71 TimerPtr timer( new Timer( milliSec ) );
72 DALI_LOG_ERROR("Timer::New: called [%p]\n", timer.Get());
76 Timer::Timer( unsigned int milliSec )
77 : mImpl(new Impl(milliSec))
89 // Timer should be used in the event thread
90 DALI_ASSERT_DEBUG( Adaptor::IsAvailable() );
92 DALI_LOG_ERROR("Timer::Start: called [%p]\n", this);
94 if(mImpl->mId != NULL)
98 mImpl->mId = ecore_timer_add( (double)mImpl->mInterval/1000.0f, (Ecore_Task_Cb)TimerSourceFunc, this );
103 // Timer should be used in the event thread
104 DALI_ASSERT_DEBUG( Adaptor::IsAvailable() );
106 DALI_LOG_ERROR("Timer::Stop: called [%p]\n", this);
111 void Timer::SetInterval( unsigned int interval )
113 // stop existing timer
115 mImpl->mInterval = interval;
120 unsigned int Timer::GetInterval() const
122 return mImpl->mInterval;
127 // Guard against destruction during signal emission
128 Dali::Timer handle( this );
130 bool retVal( false );
132 DALI_LOG_ERROR("Timer::Tick: called [%p]\n", this);
134 // Override with new signal if used
135 if( !mTickSignal.Empty() )
137 retVal = mTickSignal.Emit();
139 // Timer stops if return value is false
146 retVal = true; // continue emission
149 else // no callbacks registered
151 // periodic timer is started but nobody listens, continue
158 Dali::Timer::TimerSignalType& Timer::TickSignal()
163 void Timer::ResetTimerData()
165 if (mImpl->mId != NULL)
167 ecore_timer_del(mImpl->mId);
172 bool Timer::IsRunning() const
174 return mImpl->mId != NULL;
177 } // namespace Adaptor
179 } // namespace Internal
183 #pragma GCC diagnostic pop