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 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
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))
85 if(mImpl->mId != NULL)
89 mImpl->mId = ecore_timer_add( (double)mImpl->mInterval/1000.0f, (Ecore_Task_Cb)TimerSourceFunc, this );
94 if (mImpl->mId != NULL)
96 ecore_timer_del(mImpl->mId);
101 void Timer::SetInterval( unsigned int interval )
103 // stop existing timer
105 mImpl->mInterval = interval;
110 unsigned int Timer::GetInterval() const
112 return mImpl->mInterval;
117 // Guard against destruction during signal emission
118 Dali::Timer handle( this );
120 bool retVal( false );
122 // Override with new signal if used
123 if( !mTickSignal.Empty() )
125 retVal = mTickSignal.Emit();
127 // Timer stops if return value is false
134 retVal = true; // continue emission
137 else // no callbacks registered
139 // periodic timer is started but nobody listens, continue
146 Dali::Timer::TimerSignalType& Timer::TickSignal()
151 bool Timer::IsRunning() const
153 return mImpl->mId != NULL;
156 } // namespace Adaptor
158 } // namespace Internal
162 #pragma GCC diagnostic pop