Revert "[Tizen] Disable indicator"
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / windows / timer-impl-win.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/system/common/timer-impl.h>
20
21 // EXTERNAL INCLUDES
22 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
25 #include <Win32WindowSystem.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Adaptor
34 {
35
36 // LOCAL STUFF
37 namespace
38 {
39 void TimerSourceFunc (void *data)
40 {
41   Timer* timer = static_cast<Timer*>(data);
42
43   bool keepRunning = timer->Tick();
44 }
45 }
46
47 /**
48  * Struct to hide away Ecore implementation details
49  */
50 struct Timer::Impl
51 {
52   Impl( unsigned int milliSec ) :
53     mId(-1),
54     mInterval(milliSec)
55   {
56   }
57
58   int mId;
59
60   unsigned int mInterval;
61 };
62
63 TimerPtr Timer::New( unsigned int milliSec )
64 {
65   TimerPtr timer( new Timer( milliSec ) );
66   return timer;
67 }
68
69 Timer::Timer( unsigned int milliSec )
70 : mImpl(new Impl(milliSec))
71 {
72 }
73
74 Timer::~Timer()
75 {
76   // stop timers
77   Stop();
78
79   delete mImpl;
80   mImpl = NULL;
81 }
82
83 void Timer::Start()
84 {
85   if( 0 > mImpl->mId )
86   {
87     mImpl->mId = Win32WindowSystem::SetTimer( mImpl->mInterval, TimerSourceFunc, this );
88   }
89 }
90
91 void Timer::Stop()
92 {
93   if( 0 <= mImpl->mId )
94   {
95     Win32WindowSystem::KillTimer( mImpl->mId );
96     mImpl->mId = -1;
97   }
98 }
99
100 void Timer::SetInterval( unsigned int interval )
101 {
102   // stop existing timer
103   Stop();
104   mImpl->mInterval = interval;
105   // start new tick
106   Start();
107 }
108
109 unsigned int Timer::GetInterval() const
110 {
111   return mImpl->mInterval;
112 }
113
114 bool Timer::Tick()
115 {
116   // Guard against destruction during signal emission
117   Dali::Timer handle( this );
118
119   bool retVal( false );
120
121   // Override with new signal if used
122   if( !mTickSignal.Empty() )
123   {
124     retVal = mTickSignal.Emit();
125
126     // Timer stops if return value is false
127     if (retVal == false)
128     {
129       Stop();
130     }
131     else
132     {
133       retVal = true;   // continue emission
134     }
135   }
136   else // no callbacks registered
137   {
138     // periodic timer is started but nobody listens, continue
139     retVal = true;
140   }
141
142   return retVal;
143 }
144
145 Dali::Timer::TimerSignalType& Timer::TickSignal()
146 {
147   return mTickSignal;
148 }
149
150 bool Timer::IsRunning() const
151 {
152   return 0 <= mImpl->mId;
153 }
154
155 } // namespace Adaptor
156
157 } // namespace Internal
158
159 } // namespace Dali
160
161 #pragma GCC diagnostic pop