Conversion to Apache 2.0 license
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-toolkit-test-utils / toolkit-adaptor.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-adaptor.h"
19
20 #include <dali/public-api/common/dali-common.h>
21 #include <dali/public-api/common/map-wrapper.h>
22 #include <dali/public-api/signals/dali-signal-v2.h>
23
24 namespace Dali
25 {
26
27 ////////////////////////////////////////////////////////////////////////////////////////////////////
28
29 /**
30  * Stub for RenderSurface
31  */
32 class RenderSurface
33 {
34 };
35
36 typedef Dali::Rect<int> PositionSize;
37
38 /**
39  * Stub for the Adaptor
40  */
41 class Adaptor
42 {
43 public:
44
45   typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2;
46
47   typedef std::pair<std::string, Dali::BaseHandle> SingletonPair;
48   typedef std::map<std::string, Dali::BaseHandle>  SingletonContainer;
49   typedef SingletonContainer::const_iterator       SingletonConstIter;
50
51 public:
52
53   Adaptor(ToolkitAdaptor& toolkitAdaptor);
54   ~Adaptor();
55
56 public:
57
58   void Start();
59   void Pause();
60   void Resume();
61   void Stop();
62   bool AddIdle(boost::function<void(void)> callBack);
63   void FeedEvent(TouchPoint& point, int timeStamp);
64   bool MoveResize(const PositionSize& positionSize);
65   void SurfaceResized(const PositionSize& positionSize);
66   void ReplaceSurface(RenderSurface& surface);
67   void RenderSync();
68   RenderSurface& GetSurface();
69
70   void RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton);
71   Dali::BaseHandle GetSingleton(const std::type_info& info) const;
72
73 public: // static methods
74   static Adaptor& Get();
75   static bool IsAvailable();
76
77 public:  // Signals
78
79   AdaptorSignalV2& SignalResize();
80
81   void EmitSignalResize()
82   {
83     mResizeSignal.Emit( *this );
84   }
85
86 private:
87
88    // Undefined
89    Adaptor(const Adaptor&);
90    Adaptor& operator=(Adaptor&);
91
92    AdaptorSignalV2 mResizeSignal;
93    RenderSurface mRenderSurface;
94    ToolkitAdaptor& mToolkitAdaptor;
95
96    SingletonContainer mSingletonContainer;
97 };
98
99 namespace
100 {
101 Adaptor* gAdaptor = NULL;
102
103 }
104
105 Adaptor::Adaptor(ToolkitAdaptor& toolkitAdaptor)
106 : mToolkitAdaptor(toolkitAdaptor)
107 {
108 }
109
110 Adaptor::~Adaptor()
111 {
112
113 }
114
115 void Adaptor::Start()
116 {
117   mToolkitAdaptor.mFunctionsCalled.Start = true;
118 }
119
120 void Adaptor::Pause()
121 {
122   mToolkitAdaptor.mFunctionsCalled.Pause = true;
123 }
124
125 void Adaptor::Resume()
126 {
127   mToolkitAdaptor.mFunctionsCalled.Resume = true;
128 }
129
130 void Adaptor::Stop()
131 {
132   mToolkitAdaptor.mFunctionsCalled.Stop = true;
133 }
134
135 bool Adaptor::AddIdle(boost::function<void(void)> callBack)
136 {
137   mToolkitAdaptor.mFunctionsCalled.AddIdle = true;
138   mToolkitAdaptor.mLastIdleAdded = callBack;
139   return true;
140 }
141
142 void Adaptor::FeedEvent(TouchPoint& point, int timeStamp)
143 {
144   mToolkitAdaptor.mFunctionsCalled.FeedEvent = true;
145   mToolkitAdaptor.mLastTouchPointFed = point;
146   mToolkitAdaptor.mLastTimeStampFed = timeStamp;
147 }
148
149 bool Adaptor::MoveResize(const PositionSize& positionSize)
150 {
151   mToolkitAdaptor.mFunctionsCalled.MoveResize = true;
152   mToolkitAdaptor.mLastSizeSet = positionSize;
153   return true;
154 }
155
156 void Adaptor::SurfaceResized(const PositionSize& positionSize)
157 {
158   mToolkitAdaptor.mFunctionsCalled.SurfaceResized = true;
159   mToolkitAdaptor.mLastSizeSet = positionSize;
160 }
161
162 void Adaptor::ReplaceSurface(RenderSurface& surface)
163 {
164   mToolkitAdaptor.mFunctionsCalled.ReplaceSurface = true;
165 }
166
167 void Adaptor::RenderSync()
168 {
169   mToolkitAdaptor.mFunctionsCalled.RenderSync = true;
170 }
171
172 RenderSurface& Adaptor::GetSurface()
173 {
174   mToolkitAdaptor.mFunctionsCalled.GetSurface = true;
175   return mRenderSurface;
176 }
177
178 Adaptor& Adaptor::Get()
179 {
180   DALI_ASSERT_ALWAYS(gAdaptor);
181   gAdaptor->mToolkitAdaptor.mFunctionsCalled.Get = true;
182   return *gAdaptor;
183 }
184
185 bool Adaptor::IsAvailable()
186 {
187   bool available(false);
188
189   if (gAdaptor)
190   {
191     gAdaptor->mToolkitAdaptor.mFunctionsCalled.IsAvailable = true;
192     available = true;
193   }
194
195   return available;
196 }
197
198 void Adaptor::RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton)
199 {
200   mToolkitAdaptor.mFunctionsCalled.RegisterSingleton = true;
201
202   if(singleton)
203   {
204     mSingletonContainer.insert(SingletonPair(info.name(), singleton));
205   }
206 }
207
208 Dali::BaseHandle Adaptor::GetSingleton(const std::type_info& info) const
209 {
210   mToolkitAdaptor.mFunctionsCalled.GetSingleton = true;
211
212   Dali::BaseHandle object = Dali::BaseHandle();
213
214   SingletonConstIter iter = mSingletonContainer.find(info.name());
215   if(iter != mSingletonContainer.end())
216   {
217     object = (*iter).second;
218   }
219
220   return object;
221 }
222
223 Adaptor::AdaptorSignalV2& Adaptor::SignalResize()
224 {
225   mToolkitAdaptor.mFunctionsCalled.SignalResize = true;
226   return mResizeSignal;
227 }
228
229 ////////////////////////////////////////////////////////////////////////////////////////////////////
230
231 ToolkitAdaptor::ToolkitAdaptor()
232 : mLastTouchPointFed(0, TouchPoint::Down, 0.0f, 0.0f),
233   mLastTimeStampFed(0),
234   mAdaptorStub(new Adaptor(*this))
235 {
236   gAdaptor = mAdaptorStub;
237 }
238
239 ToolkitAdaptor::~ToolkitAdaptor()
240 {
241   delete mAdaptorStub;
242   gAdaptor = NULL;
243 }
244
245 void ToolkitAdaptor::EmitSignalResize()
246 {
247   mAdaptorStub->EmitSignalResize();
248 }
249
250 } // namespace Dali