2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 "timer-impl.h"
35 Eina_Bool TimerSourceFunc (void *data)
37 Timer* timer = static_cast<Timer*>(data);
39 bool keepRunning = timer->Tick();
41 return keepRunning ? EINA_TRUE : EINA_FALSE;
43 } // unnamed namespace
46 * Struct to hide away Ecore implementation details
50 Impl( unsigned int milliSec )
57 unsigned int mInterval;
60 TimerPtr Timer::New( unsigned int milliSec )
62 TimerPtr timer( new Timer( milliSec ) );
66 Timer::Timer( unsigned int milliSec )
67 : mImpl(new Impl(milliSec))
85 mImpl->mId = ecore_timer_add( (double)mImpl->mInterval/1000.0f, (Ecore_Task_Cb)TimerSourceFunc, this );
90 if (mImpl->mId != NULL)
92 ecore_timer_del(mImpl->mId);
97 void Timer::SetInterval( unsigned int interval )
99 // stop existing timer
101 mImpl->mInterval = interval;
106 unsigned int Timer::GetInterval() const
108 return mImpl->mInterval;
113 // Guard against destruction during signal emission
114 Dali::Timer handle( this );
116 bool retVal( false );
118 // Override with new signal if used
119 if( !mTickSignal.Empty() )
121 retVal = mTickSignal.Emit();
123 // Timer stops if return value is false
130 retVal = true; // continue emission
133 else // no callbacks registered
135 // periodic timer is started but nobody listens, continue
142 Dali::Timer::TimerSignalV2& Timer::TickSignal()
147 bool Timer::IsRunning() const
149 return mImpl->mId != NULL;
152 } // namespace Adaptor
154 } // namespace Internal