[Tizen] Remove to call key consumed event in ATSPI bridge
[platform/core/uifw/dali-adaptor.git] / dali / internal / system / linux / timer-impl-ecore.cpp
1 /*
2  * Copyright (c) 2021 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 // INTERNAL INCLUDES
22 #include <dali/internal/adaptor/common/adaptor-impl.h>
23 #include <dali/public-api/dali-adaptor-common.h>
24
25 #include <dali/internal/system/linux/dali-ecore.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace Adaptor
32 {
33 // LOCAL STUFF
34 namespace
35 {
36 Eina_Bool TimerSourceFunc(void* data)
37 {
38   Timer* timer = static_cast<Timer*>(data);
39
40   bool keepRunning = timer->Tick();
41
42   return keepRunning ? EINA_TRUE : EINA_FALSE;
43 }
44 } // unnamed namespace
45
46 /**
47  * Struct to hide away Ecore implementation details
48  */
49 struct Timer::Impl
50 {
51   Impl(unsigned int milliSec)
52   : mId(NULL),
53     mInterval(milliSec)
54   {
55   }
56
57   Ecore_Timer* mId;
58   unsigned int mInterval;
59 };
60
61 TimerPtr Timer::New(unsigned int milliSec)
62 {
63   TimerPtr timer(new Timer(milliSec));
64   return timer;
65 }
66
67 Timer::Timer(unsigned int milliSec)
68 : mImpl(new Impl(milliSec))
69 {
70 }
71
72 Timer::~Timer()
73 {
74   ResetTimerData();
75   delete mImpl;
76 }
77
78 void Timer::Start()
79 {
80   // Timer should be used in the event thread
81   DALI_ASSERT_ALWAYS(Adaptor::IsAvailable());
82
83   if(mImpl->mId != NULL)
84   {
85     Stop();
86   }
87   double interval = static_cast<double>(mImpl->mInterval) / 1000.0f;
88   mImpl->mId      = ecore_timer_add(interval, reinterpret_cast<Ecore_Task_Cb>(TimerSourceFunc), this);
89 }
90
91 void Timer::Stop()
92 {
93   // Timer should be used in the event thread
94   DALI_ASSERT_ALWAYS(Adaptor::IsAvailable());
95
96   ResetTimerData();
97 }
98
99 void Timer::Pause()
100 {
101   // Timer should be used in the event thread
102   DALI_ASSERT_ALWAYS(Adaptor::IsAvailable());
103
104   if(mImpl->mId != NULL)
105   {
106     ecore_timer_freeze(mImpl->mId);
107   }
108 }
109
110 void Timer::Resume()
111 {
112   // Timer should be used in the event thread
113   DALI_ASSERT_ALWAYS(Adaptor::IsAvailable());
114
115   if(mImpl->mId != NULL)
116   {
117     ecore_timer_thaw(mImpl->mId);
118   }
119 }
120
121 void Timer::SetInterval(unsigned int interval, bool restart)
122 {
123   // stop existing timer
124   Stop();
125   mImpl->mInterval = interval;
126
127   if(restart)
128   {
129     // start new tick
130     Start();
131   }
132 }
133
134 unsigned int Timer::GetInterval() const
135 {
136   return mImpl->mInterval;
137 }
138
139 bool Timer::Tick()
140 {
141   // Guard against destruction during signal emission
142   Dali::Timer handle(this);
143
144   bool retVal(false);
145
146   // Override with new signal if used
147   if(!mTickSignal.Empty())
148   {
149     retVal = mTickSignal.Emit();
150
151     // Timer stops if return value is false
152     if(retVal == false)
153     {
154       Stop();
155     }
156     else
157     {
158       retVal = true; // continue emission
159     }
160   }
161   else // no callbacks registered
162   {
163     // periodic timer is started but nobody listens, continue
164     retVal = true;
165   }
166
167   return retVal;
168 }
169
170 Dali::Timer::TimerSignalType& Timer::TickSignal()
171 {
172   return mTickSignal;
173 }
174
175 void Timer::ResetTimerData()
176 {
177   if(mImpl->mId != NULL)
178   {
179     ecore_timer_del(mImpl->mId);
180     mImpl->mId = NULL;
181   }
182 }
183
184 bool Timer::IsRunning() const
185 {
186   return mImpl->mId != NULL;
187 }
188
189 } // namespace Adaptor
190
191 } // namespace Internal
192
193 } // namespace Dali