Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-toolkit-test-utils / toolkit-timer.cpp
1 /*
2  * Copyright (c) 2014 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 // INTERNAL INCLUDES
20
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-v2.h>
24
25 namespace Dali
26 {
27
28 namespace
29 {
30
31 Timer gTimer;
32
33 /*
34  * This is a global signal that all users of this stub will connect to.
35  * If we were to use a timer stub with real ticks we may wish to have this as a member variable created with each New Timer.
36  * Currently unable to get the boost singal connect to work with the stub timer when using a member hence this global.
37  */
38 Dali::Timer::TimerSignalV2 gTimerTick;
39 }
40
41 /**
42  * Stub for the Timer
43  */
44
45 Timer Timer::New( unsigned int milliSec )
46 {
47   DALI_ASSERT_ALWAYS( gTimer );
48
49   return gTimer;
50 }
51
52 Timer::TimerSignalV2& Timer::TickSignal()
53 {
54    return gTimerTick;
55 }
56
57 bool Timer::IsRunning() const
58 {
59   return true;
60 }
61
62 Timer::Timer( const Timer& timer )
63 : BaseHandle(timer)
64 {
65 }
66
67 Timer::~Timer()
68 {
69 }
70
71
72 void Timer::Start()
73 {
74 }
75
76 void Timer::Stop()
77 {
78 }
79
80 namespace Internal
81 {
82
83 namespace Adaptor
84 {
85
86 /**
87  * Stub for the Internal Timer
88  */
89 class Timer : public BaseObject
90 {
91 public: // Creation & Destruction
92
93   Timer();
94   Timer(ToolkitTimer *timer);
95   ~Timer();
96
97   void Start();
98
99   void Stop();
100
101   bool IsRunning() const;
102
103 public: // Signals
104
105 private:
106
107   ToolkitTimer* mToolkitTimer;
108   bool mRunning;
109 };
110
111 Timer::Timer()
112 : mToolkitTimer(NULL),
113   mRunning( true )
114 {
115 }
116
117 Timer::Timer(ToolkitTimer *timer)
118 : mToolkitTimer(timer),
119   mRunning( true )
120 {
121 }
122
123 Timer::~Timer()
124 {
125 }
126
127 void Timer::Start()
128 {
129   DALI_ASSERT_ALWAYS( gTimer );
130 }
131
132 void Timer::Stop()
133 {
134   DALI_ASSERT_ALWAYS( gTimer );
135 }
136
137 bool Timer::IsRunning() const
138 {
139   DALI_ASSERT_ALWAYS( gTimer );
140   return mRunning;
141 }
142
143 } // namespace Adaptor
144
145 } // namespace Internal
146
147 ////////////////////////////////////////////////////////////////////////////////////////////////////
148
149 ToolkitTimer::ToolkitTimer()
150 : mTimerStub(new Internal::Adaptor::Timer(this)),
151   mTimer( mTimerStub )
152 {
153   if ( mTimer )
154   {
155     gTimer = mTimer;
156   }
157 }
158
159 ToolkitTimer::~ToolkitTimer()
160 {
161   gTimer.Reset();
162 }
163
164 Timer ToolkitTimer::GetTimer()
165 {
166   return mTimer;
167 }
168
169 } // namespace Dali