2 * Copyright (c) 2021 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>
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))
80 // Timer should be used in the event thread
81 DALI_ASSERT_ALWAYS(Adaptor::IsAvailable());
83 if(mImpl->mId != NULL)
87 double interval = static_cast<double>(mImpl->mInterval) / 1000.0f;
88 mImpl->mId = ecore_timer_add(interval, reinterpret_cast<Ecore_Task_Cb>(TimerSourceFunc), this);
93 // Timer should be used in the event thread
94 DALI_ASSERT_ALWAYS(Adaptor::IsAvailable());
101 // Timer should be used in the event thread
102 DALI_ASSERT_ALWAYS(Adaptor::IsAvailable());
104 if(mImpl->mId != NULL)
106 ecore_timer_freeze(mImpl->mId);
112 // Timer should be used in the event thread
113 DALI_ASSERT_ALWAYS(Adaptor::IsAvailable());
115 if(mImpl->mId != NULL)
117 ecore_timer_thaw(mImpl->mId);
121 void Timer::SetInterval(unsigned int interval, bool restart)
123 // stop existing timer
125 mImpl->mInterval = interval;
134 unsigned int Timer::GetInterval() const
136 return mImpl->mInterval;
141 // Guard against destruction during signal emission
142 Dali::Timer handle(this);
146 // Override with new signal if used
147 if(!mTickSignal.Empty())
149 retVal = mTickSignal.Emit();
151 // Timer stops if return value is false
158 retVal = true; // continue emission
161 else // no callbacks registered
163 // periodic timer is started but nobody listens, continue
170 Dali::Timer::TimerSignalType& Timer::TickSignal()
175 void Timer::ResetTimerData()
177 if(mImpl->mId != NULL)
179 ecore_timer_del(mImpl->mId);
184 bool Timer::IsRunning() const
186 return mImpl->mId != NULL;
189 } // namespace Adaptor
191 } // namespace Internal