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