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.
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 // Ecore is littered with C style cast
26 #pragma GCC diagnostic push
27 #pragma GCC diagnostic ignored "-Wold-style-cast"
42 Eina_Bool TimerSourceFunc (void *data)
44 Timer* timer = static_cast<Timer*>(data);
46 bool keepRunning = timer->Tick();
48 return keepRunning ? EINA_TRUE : EINA_FALSE;
50 } // unnamed namespace
53 * Struct to hide away Ecore implementation details
57 Impl( unsigned int milliSec )
64 unsigned int mInterval;
67 TimerPtr Timer::New( unsigned int milliSec )
69 TimerPtr timer( new Timer( milliSec ) );
73 Timer::Timer( unsigned int milliSec )
74 : mImpl(new Impl(milliSec))
86 // Timer should be used in the event thread
87 DALI_ASSERT_DEBUG( Adaptor::IsAvailable() );
89 if(mImpl->mId != NULL)
93 mImpl->mId = ecore_timer_add( (double)mImpl->mInterval/1000.0f, (Ecore_Task_Cb)TimerSourceFunc, this );
98 // Timer should be used in the event thread
99 DALI_ASSERT_DEBUG( Adaptor::IsAvailable() );
106 // Timer should be used in the event thread
107 DALI_ASSERT_DEBUG( Adaptor::IsAvailable() );
109 if( mImpl->mId != NULL )
111 ecore_timer_freeze( mImpl->mId );
117 // Timer should be used in the event thread
118 DALI_ASSERT_DEBUG( Adaptor::IsAvailable() );
120 if( mImpl->mId != NULL )
122 ecore_timer_thaw( mImpl->mId );
126 void Timer::SetInterval( unsigned int interval, bool restart )
128 // stop existing timer
130 mImpl->mInterval = interval;
139 unsigned int Timer::GetInterval() const
141 return mImpl->mInterval;
146 // Guard against destruction during signal emission
147 Dali::Timer handle( this );
149 bool retVal( false );
151 // Override with new signal if used
152 if( !mTickSignal.Empty() )
154 retVal = mTickSignal.Emit();
156 // Timer stops if return value is false
163 retVal = true; // continue emission
166 else // no callbacks registered
168 // periodic timer is started but nobody listens, continue
175 Dali::Timer::TimerSignalType& Timer::TickSignal()
180 void Timer::ResetTimerData()
182 if (mImpl->mId != NULL)
184 ecore_timer_del(mImpl->mId);
189 bool Timer::IsRunning() const
191 return mImpl->mId != NULL;
194 } // namespace Adaptor
196 } // namespace Internal
200 #pragma GCC diagnostic pop