Using SingletonService instead of Adaptor
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / 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 #define __DALI_ADAPTOR_H__
19 #define __DALI_ACCESSIBILITY_MANAGER_H__
20 #define __DALI_TIMER_H__
21 #define __DALI_CLIPBOARD_H__
22 #define __DALI_IMF_MANAGER_H__
23
24 #include "toolkit-adaptor.h"
25 #include <map>
26 #include <dali/public-api/common/dali-common.h>
27 #include <dali/public-api/signals/dali-signal-v2.h>
28
29 namespace Dali
30 {
31
32 ////////////////////////////////////////////////////////////////////////////////////////////////////
33
34 class TestRenderSurface : public RenderSurface
35 {
36 public:
37   TestRenderSurface(){}
38   virtual ~TestRenderSurface(){}
39   virtual SurfaceType GetType() { return RenderSurface::WINDOW; }
40   virtual Dali::Any GetSurface() { return Dali::Any(); }
41   virtual Dali::Any GetDisplay() { return Dali::Any(); }
42   virtual PositionSize GetPositionSize() const { return PositionSize(0, 0, 640, 480);}
43   virtual void SetRenderMode(RenderMode mode){}
44   virtual RenderMode GetRenderMode() const { return RenderSurface::RENDER_60FPS; }
45 };
46
47 typedef Dali::Rect<int> PositionSize;
48
49 /**
50  * Stub for the Adaptor
51  */
52 class Adaptor
53 {
54 public:
55
56   typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2;
57
58 public:
59
60   Adaptor(ToolkitAdaptor& toolkitAdaptor);
61   ~Adaptor();
62
63 public:
64
65   void Start();
66   void Pause();
67   void Resume();
68   void Stop();
69   bool AddIdle(boost::function<void(void)> callBack);
70   void FeedEvent(TouchPoint& point, int timeStamp);
71   bool MoveResize(const PositionSize& positionSize);
72   void SurfaceResized(const PositionSize& positionSize);
73   void ReplaceSurface(RenderSurface& surface);
74   void RenderSync();
75   RenderSurface& GetSurface();
76
77 public: // static methods
78   static Adaptor& Get();
79   static bool IsAvailable();
80
81 public:  // Signals
82
83   AdaptorSignalV2& SignalResize();
84
85   void EmitSignalResize()
86   {
87     mResizeSignal.Emit( *this );
88   }
89
90 private:
91
92   // Undefined
93   Adaptor(const Adaptor&);
94   Adaptor& operator=(Adaptor&);
95
96   AdaptorSignalV2 mResizeSignal;
97   TestRenderSurface mRenderSurface;
98   ToolkitAdaptor& mToolkitAdaptor;
99 };
100
101 namespace
102 {
103 Adaptor* gAdaptor = NULL;
104
105 }
106
107 Adaptor::Adaptor(ToolkitAdaptor& toolkitAdaptor)
108 : mToolkitAdaptor(toolkitAdaptor)
109 {
110 }
111
112 Adaptor::~Adaptor()
113 {
114
115 }
116
117 void Adaptor::Start()
118 {
119   mToolkitAdaptor.mFunctionsCalled.Start = true;
120 }
121
122 void Adaptor::Pause()
123 {
124   mToolkitAdaptor.mFunctionsCalled.Pause = true;
125 }
126
127 void Adaptor::Resume()
128 {
129   mToolkitAdaptor.mFunctionsCalled.Resume = true;
130 }
131
132 void Adaptor::Stop()
133 {
134   mToolkitAdaptor.mFunctionsCalled.Stop = true;
135 }
136
137 bool Adaptor::AddIdle(boost::function<void(void)> callBack)
138 {
139   mToolkitAdaptor.mFunctionsCalled.AddIdle = true;
140   mToolkitAdaptor.mLastIdleAdded = callBack;
141   return true;
142 }
143
144 void Adaptor::FeedEvent(TouchPoint& point, int timeStamp)
145 {
146   mToolkitAdaptor.mFunctionsCalled.FeedEvent = true;
147   mToolkitAdaptor.mLastTouchPointFed = point;
148   mToolkitAdaptor.mLastTimeStampFed = timeStamp;
149 }
150
151 bool Adaptor::MoveResize(const PositionSize& positionSize)
152 {
153   mToolkitAdaptor.mFunctionsCalled.MoveResize = true;
154   mToolkitAdaptor.mLastSizeSet = positionSize;
155   return true;
156 }
157
158 void Adaptor::SurfaceResized(const PositionSize& positionSize)
159 {
160   mToolkitAdaptor.mFunctionsCalled.SurfaceResized = true;
161   mToolkitAdaptor.mLastSizeSet = positionSize;
162 }
163
164 void Adaptor::ReplaceSurface(RenderSurface& surface)
165 {
166   mToolkitAdaptor.mFunctionsCalled.ReplaceSurface = true;
167 }
168
169 void Adaptor::RenderSync()
170 {
171   mToolkitAdaptor.mFunctionsCalled.RenderSync = true;
172 }
173
174 RenderSurface& Adaptor::GetSurface()
175 {
176   mToolkitAdaptor.mFunctionsCalled.GetSurface = true;
177   return mRenderSurface;
178 }
179
180 Adaptor& Adaptor::Get()
181 {
182   DALI_ASSERT_ALWAYS(gAdaptor);
183   gAdaptor->mToolkitAdaptor.mFunctionsCalled.Get = true;
184   return *gAdaptor;
185 }
186
187 bool Adaptor::IsAvailable()
188 {
189   bool available(false);
190
191   if (gAdaptor)
192   {
193     gAdaptor->mToolkitAdaptor.mFunctionsCalled.IsAvailable = true;
194     available = true;
195   }
196
197   return available;
198 }
199
200 Adaptor::AdaptorSignalV2& Adaptor::SignalResize()
201 {
202   mToolkitAdaptor.mFunctionsCalled.SignalResize = true;
203   return mResizeSignal;
204 }
205
206 ////////////////////////////////////////////////////////////////////////////////////////////////////
207
208 ToolkitAdaptor::ToolkitAdaptor()
209 : mLastTouchPointFed(0, TouchPoint::Down, 0.0f, 0.0f),
210   mLastTimeStampFed(0),
211   mStyleMonitor(StyleMonitor::Get()),
212   mAccessibilityManager(AccessibilityManager::Get()),
213   mImfManager(ImfManager::Get()),
214   mAdaptorStub(new Adaptor(*this))
215 {
216   gAdaptor = mAdaptorStub;
217 }
218
219 ToolkitAdaptor::~ToolkitAdaptor()
220 {
221   delete mAdaptorStub;
222   gAdaptor = NULL;
223 }
224
225 void ToolkitAdaptor::EmitSignalResize()
226 {
227   mAdaptorStub->EmitSignalResize();
228 }
229
230 } // namespace Dali