2 * Copyright (c) 2018 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>
36 bool TimerSourceFunc (void *data)
38 Timer* timer = static_cast<Timer*>(data);
44 * Struct to hide away Windows implementation details
48 Impl( unsigned int milliSec ) :
56 unsigned int mInterval;
59 TimerPtr Timer::New( unsigned int milliSec )
61 TimerPtr timer( new Timer( milliSec ) );
65 Timer::Timer( unsigned int milliSec )
66 : mImpl(new Impl(milliSec))
83 mImpl->mId = WindowsPlatformImplementation::SetTimer( mImpl->mInterval, TimerSourceFunc, this );
91 WindowsPlatformImplementation::KillTimer( mImpl->mId );
106 void Timer::SetInterval( unsigned int interval, bool restart )
108 if( true == restart )
110 // stop existing timer
112 mImpl->mInterval = interval;
118 mImpl->mInterval = interval;
122 unsigned int Timer::GetInterval() const
124 return mImpl->mInterval;
129 // Guard against destruction during signal emission
130 Dali::Timer handle( this );
132 bool retVal( false );
134 // Override with new signal if used
135 if( !mTickSignal.Empty() )
137 retVal = mTickSignal.Emit();
139 // Timer stops if return value is false
146 retVal = true; // continue emission
149 else // no callbacks registered
151 // periodic timer is started but nobody listens, continue
158 Dali::Timer::TimerSignalType& Timer::TickSignal()
163 bool Timer::IsRunning() const
165 return 0 <= mImpl->mId;
168 } // namespace Adaptor
170 } // namespace Internal