2f1ce14ab3032c492b1529101ae577d550a6af0f
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-timer.cpp
1 /*
2  * Copyright (c) 2015 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 #include "toolkit-timer.h"
19
20 // INTERNAL INCLUDES
21 #include <dali/public-api/common/dali-common.h>
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/public-api/signals/dali-signal.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 namespace Adaptor
32 {
33 class Timer;
34
35 typedef IntrusivePtr<Timer> TimerPtr;
36
37 Dali::Timer::TimerSignalType gTickSignal;
38
39 /**
40  * Implementation of the timer
41  */
42 class Timer : public BaseObject
43 {
44 public:
45   void MockEmitSignal();
46
47 public:
48   static TimerPtr New( unsigned int milliSec );
49   Timer( unsigned int milliSec );
50   virtual ~Timer();
51
52   void Start();
53   void Stop();
54   void SetInterval( unsigned int interval );
55   unsigned int GetInterval() const;
56   bool IsRunning() const;
57   bool Tick();
58
59 public: // Signals
60
61   Dali::Timer::TimerSignalType& TickSignal();
62
63 private: // Implementation
64
65   // not implemented
66   Timer( const Timer& );
67   Timer& operator=( const Timer& );
68
69 private: // Data
70
71   unsigned int mInterval;
72 };
73
74 inline Timer& GetImplementation(Dali::Timer& timer)
75 {
76   DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
77
78   BaseObject& handle = timer.GetBaseObject();
79
80   return static_cast<Internal::Adaptor::Timer&>(handle);
81 }
82
83 inline const Timer& GetImplementation(const Dali::Timer& timer)
84 {
85   DALI_ASSERT_ALWAYS(timer && "Timer handle is empty");
86
87   const BaseObject& handle = timer.GetBaseObject();
88
89   return static_cast<const Internal::Adaptor::Timer&>(handle);
90 }
91
92 TimerPtr Timer::New( unsigned int milliSec )
93 {
94   TimerPtr timerImpl = new Timer( milliSec );
95   return timerImpl;
96 }
97
98 Timer::Timer( unsigned int milliSec )
99 : mInterval( milliSec )
100 {
101 }
102
103 Timer::~Timer()
104 {
105 }
106
107 void Timer::Start()
108 {
109 }
110
111 void Timer::Stop()
112 {
113 }
114
115 void Timer::SetInterval( unsigned int interval )
116 {
117   mInterval = interval;
118 }
119
120 unsigned int Timer::GetInterval() const
121 {
122   return mInterval;
123 }
124
125 bool Timer::IsRunning() const
126 {
127   return true;
128 }
129
130 bool Timer::Tick()
131 {
132   return false;
133 }
134
135 Dali::Timer::TimerSignalType& Timer::TickSignal()
136 {
137   return gTickSignal;
138 }
139
140 // Mock setup functions:
141
142 void Timer::MockEmitSignal()
143 {
144   gTickSignal.Emit();
145 }
146
147
148 } // namespace Adaptor
149
150 } // namespace Internal
151
152 /********************************************************************************/
153 /*********************************  PUBLIC CLASS  *******************************/
154 /********************************************************************************/
155
156 Timer::Timer()
157 {
158
159 }
160
161 Timer Timer::New( unsigned int milliSec )
162 {
163   Internal::Adaptor::TimerPtr internal = Internal::Adaptor::Timer::New( milliSec );
164   return Timer(internal.Get());
165 }
166
167 Timer::Timer( const Timer& timer )
168 :BaseHandle( timer )
169 {
170 }
171
172 Timer& Timer::operator=( const Timer& timer )
173 {
174   // check self assignment
175   if( *this != timer )
176   {
177     BaseHandle::operator=(timer);
178   }
179   return *this;
180 }
181
182 Timer::~Timer()
183 {
184 }
185
186 void Timer::Start()
187 {
188   Internal::Adaptor::GetImplementation( *this ).Start();
189 }
190
191 void Timer::Stop()
192 {
193   Internal::Adaptor::GetImplementation( *this ).Stop();
194 }
195
196 void Timer::SetInterval( unsigned int milliSec )
197 {
198   Internal::Adaptor::GetImplementation( *this ).SetInterval( milliSec );
199 }
200
201 unsigned int Timer::GetInterval() const
202 {
203   return Internal::Adaptor::GetImplementation( *this ).GetInterval();
204 }
205
206 bool Timer::IsRunning() const
207 {
208   return true;
209 }
210
211 Timer::TimerSignalType& Timer::TickSignal()
212 {
213   return Internal::Adaptor::GetImplementation( *this ).TickSignal();
214 }
215
216 Timer::Timer(Internal::Adaptor::Timer* timer)
217 : BaseHandle(timer)
218 {
219 }
220
221 // Mock setup functions:
222
223 void Timer::MockEmitSignal()
224 {
225   Internal::Adaptor::GetImplementation( *this ).MockEmitSignal();
226 }
227
228 } // namespace Dali
229