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/window-system/windows/platform-implement-win.h>
33 bool TimerSourceFunc(void* data)
35 Timer* timer = static_cast<Timer*>(data);
41 * Struct to hide away Windows implementation details
45 Impl(unsigned int milliSec)
53 unsigned int mInterval;
56 TimerPtr Timer::New(unsigned int milliSec)
58 TimerPtr timer(new Timer(milliSec));
62 Timer::Timer(unsigned int milliSec)
63 : mImpl(new Impl(milliSec))
80 mImpl->mId = WindowsPlatform::SetTimer(mImpl->mInterval, TimerSourceFunc, this);
88 WindowsPlatform::KillTimer(mImpl->mId);
101 void Timer::SetInterval(unsigned int interval, bool restart)
105 // stop existing timer
107 mImpl->mInterval = interval;
113 mImpl->mInterval = interval;
117 unsigned int Timer::GetInterval() const
119 return mImpl->mInterval;
124 // Guard against destruction during signal emission
125 Dali::Timer handle(this);
129 // Override with new signal if used
130 if(!mTickSignal.Empty())
132 retVal = mTickSignal.Emit();
134 // Timer stops if return value is false
141 retVal = true; // continue emission
144 else // no callbacks registered
146 // periodic timer is started but nobody listens, continue
153 Dali::Timer::TimerSignalType& Timer::TickSignal()
158 bool Timer::IsRunning() const
160 return 0 <= mImpl->mId;
163 } // namespace Adaptor
165 } // namespace Internal