2 * Copyright (c) 2014 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"
36 Eina_Bool TimerSourceFunc (void *data)
38 Timer* timer = static_cast<Timer*>(data);
40 bool keepRunning = timer->Tick();
42 return keepRunning ? EINA_TRUE : EINA_FALSE;
44 } // unnamed namespace
47 * Struct to hide away Ecore implementation details
51 Impl( unsigned int milliSec )
58 unsigned int mInterval;
61 TimerPtr Timer::New( unsigned int milliSec )
63 TimerPtr timer( new Timer( milliSec ) );
67 Timer::Timer( unsigned int milliSec )
68 : mImpl(new Impl(milliSec))
82 if(mImpl->mId != NULL)
86 mImpl->mId = ecore_timer_add( (double)mImpl->mInterval/1000.0f, (Ecore_Task_Cb)TimerSourceFunc, this );
91 if (mImpl->mId != NULL)
93 ecore_timer_del(mImpl->mId);
98 void Timer::SetInterval( unsigned int interval )
100 // stop existing timer
102 mImpl->mInterval = interval;
107 unsigned int Timer::GetInterval() const
109 return mImpl->mInterval;
114 // Guard against destruction during signal emission
115 Dali::Timer handle( this );
117 bool retVal( false );
119 // Override with new signal if used
120 if( !mTickSignal.Empty() )
122 retVal = mTickSignal.Emit();
124 // Timer stops if return value is false
131 retVal = true; // continue emission
134 else // no callbacks registered
136 // periodic timer is started but nobody listens, continue
143 Dali::Timer::TimerSignalType& Timer::TickSignal()
148 bool Timer::IsRunning() const
150 return mImpl->mId != NULL;
153 } // namespace Adaptor
155 } // namespace Internal