2 * Copyright (c) 2019 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 <dali/internal/system/common/timer-impl.h>
22 #include <dali/internal/adaptor/common/adaptor-impl.h>
23 #include <dali/public-api/dali-adaptor-common.h>
25 #include <dali/internal/system/linux/dali-ecore.h>
39 Eina_Bool TimerSourceFunc (void *data)
41 Timer* timer = static_cast<Timer*>(data);
43 bool keepRunning = timer->Tick();
45 return keepRunning ? EINA_TRUE : EINA_FALSE;
47 } // unnamed namespace
50 * Struct to hide away Ecore implementation details
54 Impl( unsigned int milliSec )
61 unsigned int mInterval;
64 TimerPtr Timer::New( unsigned int milliSec )
66 TimerPtr timer( new Timer( milliSec ) );
70 Timer::Timer( unsigned int milliSec )
71 : mImpl(new Impl(milliSec))
83 // Timer should be used in the event thread
84 DALI_ASSERT_DEBUG( Adaptor::IsAvailable() );
86 if(mImpl->mId != NULL)
90 double interval = static_cast<double> ( mImpl->mInterval ) / 1000.0f;
91 mImpl->mId = ecore_timer_add( interval, reinterpret_cast<Ecore_Task_Cb>( TimerSourceFunc ), this );
96 // Timer should be used in the event thread
97 DALI_ASSERT_DEBUG( Adaptor::IsAvailable() );
104 // Timer should be used in the event thread
105 DALI_ASSERT_DEBUG( Adaptor::IsAvailable() );
107 if( mImpl->mId != NULL )
109 ecore_timer_freeze( mImpl->mId );
115 // Timer should be used in the event thread
116 DALI_ASSERT_DEBUG( Adaptor::IsAvailable() );
118 if( mImpl->mId != NULL )
120 ecore_timer_thaw( mImpl->mId );
124 void Timer::SetInterval( unsigned int interval, bool restart )
126 // stop existing timer
128 mImpl->mInterval = interval;
137 unsigned int Timer::GetInterval() const
139 return mImpl->mInterval;
144 // Guard against destruction during signal emission
145 Dali::Timer handle( this );
147 bool retVal( false );
149 // Override with new signal if used
150 if( !mTickSignal.Empty() )
152 retVal = mTickSignal.Emit();
154 // Timer stops if return value is false
161 retVal = true; // continue emission
164 else // no callbacks registered
166 // periodic timer is started but nobody listens, continue
173 Dali::Timer::TimerSignalType& Timer::TickSignal()
178 void Timer::ResetTimerData()
180 if (mImpl->mId != NULL)
182 ecore_timer_del(mImpl->mId);
187 bool Timer::IsRunning() const
189 return mImpl->mId != NULL;
192 } // namespace Adaptor
194 } // namespace Internal