Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / scenes / FUiScenesSceneManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        FUiScenesSceneManager.cpp
19  * @brief       This is the implementation file of the SceneManager class.
20  *
21  */
22
23 #include <cstdlib>
24 #include <new>
25 #include <pthread.h>
26 #include <FUiScenesSceneManager.h>
27 #include <FBaseSysLog.h>
28 #include "FUiScenes_SceneImpl.h"
29 #include "FUiScenes_SceneManagerImpl.h"
30
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::App;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Animations;
37
38
39 namespace Tizen { namespace Ui { namespace Scenes
40 {
41
42 SceneManager* SceneManager::__pSceneManagerInstance = null;
43
44 SceneManager::SceneManager(void)
45         : __pSceneManagerImpl(null)
46 {
47
48 }
49
50 SceneManager::~SceneManager(void)
51 {
52         delete __pSceneManagerImpl;
53 }
54
55 SceneManager*
56 SceneManager::GetInstance(void)
57 {
58         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
59
60         if (!__pSceneManagerInstance)
61         {
62                 ClearLastResult();
63                 pthread_once(&onceBlock, InitSingleton);
64                 result r = GetLastResult();
65                 if (IsFailed(r))
66                 {
67                         onceBlock = PTHREAD_ONCE_INIT;
68                 }
69         }
70
71         return __pSceneManagerInstance;
72 }
73
74 result
75 SceneManager::Construct(void)
76 {
77         result r = E_SUCCESS;
78
79         __pSceneManagerImpl = new (std::nothrow) _SceneManagerImpl;
80         SysTryReturnResult(NID_UI_SCENES, __pSceneManagerImpl != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
81                                            GetErrorMessage(E_OUT_OF_MEMORY));
82
83         r = __pSceneManagerImpl->Construct();
84         SysTryReturn(NID_UI_SCENES, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
85         return r;
86 }
87
88 result
89 SceneManager::RegisterFormFactory(const IFormFactory& formFactory)
90 {
91         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
92         __pSceneManagerImpl->RegisterFormFactory(formFactory);
93         return E_SUCCESS;
94
95 }
96
97 result
98 SceneManager::RegisterPanelFactory(const IPanelFactory& panelFactory)
99 {
100         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
101         __pSceneManagerImpl->RegisterPanelFactory(panelFactory);
102         return E_SUCCESS;
103 }
104
105 result
106 SceneManager::RegisterScene(const SceneId& sceneId, const String& formId, const String& panelId)
107 {
108         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
109         return __pSceneManagerImpl->RegisterScene(sceneId, formId, panelId);
110 }
111
112 result
113 SceneManager::RegisterScene(const String& resourceId)
114 {
115         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
116         return __pSceneManagerImpl->RegisterScene(resourceId);
117 }
118
119 result
120 SceneManager::UnregisterScene(const SceneId& sceneId)
121 {
122         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
123         return __pSceneManagerImpl->UnregisterScene(sceneId);
124 }
125
126 result
127 SceneManager::AddSceneManagerEventListener(ISceneManagerEventListener& sceneManagerEventListener)
128 {
129         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
130         return __pSceneManagerImpl->AddSceneManagerEventListener(sceneManagerEventListener);
131 }
132
133 result
134 SceneManager::RemoveSceneManagerEventListener(ISceneManagerEventListener& sceneManagerEventListener)
135 {
136         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
137         return __pSceneManagerImpl->RemoveSceneManagerEventListener(sceneManagerEventListener);
138 }
139
140 result
141 SceneManager::AddSceneEventListener(const SceneId& sceneId, ISceneEventListener& sceneEventListener)
142 {
143         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
144         return __pSceneManagerImpl->AddSceneEventListener(sceneId, sceneEventListener);
145 }
146
147 result
148 SceneManager::RemoveSceneEventListener(const SceneId& sceneId, ISceneEventListener& sceneEventListener)
149 {
150         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
151         return __pSceneManagerImpl->RemoveSceneEventListener(sceneId, sceneEventListener);
152 }
153
154 result
155 SceneManager::SetSceneAnimationProvider(const SceneId& sceneId, ISceneAnimationProvider* pSceneAnimationProvider)
156 {
157         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
158         return __pSceneManagerImpl->SetSceneAnimationProvider(sceneId, pSceneAnimationProvider);
159 }
160
161 result
162 SceneManager::SetSceneTransitionPolicyProvider(ISceneTransitionPolicyProvider* pSceneTransitionPolicyProvider)
163 {
164         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
165         return __pSceneManagerImpl->SetSceneTransitionPolicyProvider(pSceneTransitionPolicyProvider);
166 }
167
168 result
169 SceneManager::SetFormTransitionAnimationDefaultValues(SceneTransitionAnimationType animationType, long duration,
170                                                                                                           AnimationInterpolatorType interpolatorType)
171 {
172         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
173         return __pSceneManagerImpl->SetFormTransitionAnimationDefaultValues(animationType, duration, interpolatorType);
174 }
175
176 result
177 SceneManager::GoForward(const ForwardSceneTransition& sceneTransition, const Tizen::Base::Collection::IList* pArgs)
178 {
179         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
180         return __pSceneManagerImpl->GoForward(sceneTransition, pArgs);
181 }
182
183 result
184 SceneManager::GoForward(const SceneTransitionId& transitionId, const Tizen::Base::Collection::IList* pArgs)
185 {
186         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
187         return __pSceneManagerImpl->GoForward(transitionId, pArgs);
188 }
189
190 result
191 SceneManager::GoBackward(const BackwardSceneTransition& sceneTransition, const Tizen::Base::Collection::IList* pArgs)
192 {
193         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
194         return __pSceneManagerImpl->GoBackward(sceneTransition, pArgs);
195 }
196
197 result
198 SceneManager::GoBackward(const SceneTransitionId& transitionId, const Tizen::Base::Collection::IList* pArgs)
199 {
200         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
201         return __pSceneManagerImpl->GoBackward(transitionId, pArgs);
202 }
203
204 Scene*
205 SceneManager::GetCurrentScene(void) const
206 {
207         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
208         return __pSceneManagerImpl->GetCurrentScene();
209 }
210
211 SceneId
212 SceneManager::GetCurrentSceneId(void) const
213 {
214         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
215         return __pSceneManagerImpl->GetCurrentSceneId();
216 }
217
218 bool
219 SceneManager::IsSceneAlive(const SceneId& sceneId) const
220 {
221         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
222         return __pSceneManagerImpl->IsSceneAlive(sceneId);
223 }
224
225 result
226 SceneManager::DestroyScene(const SceneId& sceneId)
227 {
228         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
229         return __pSceneManagerImpl->DestroyScene(sceneId);
230 }
231
232 result
233 SceneManager::BringCurrentSceneToTop(void)
234 {
235         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
236         return __pSceneManagerImpl->BringCurrentSceneToTop();
237 }
238
239 result
240 SceneManager::ClearSceneHistory(void)
241 {
242         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
243         return __pSceneManagerImpl->ClearSceneHistory();
244 }
245
246 result
247 SceneManager::AddToSceneHistory(const SceneId& sceneId)
248 {
249         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
250         return __pSceneManagerImpl->AddToSceneHistory(sceneId);
251 }
252
253 IListT<String>*
254 SceneManager::GetSceneHistoryN(void) const
255 {
256         ClearLastResult();
257         SysAssertf(__pSceneManagerImpl != null, "Not yet constructed! Construct() should be called before use");
258         return __pSceneManagerImpl->GetSceneHistoryN();
259 }
260
261 void
262 SceneManager::InitSingleton(void)
263 {
264         SceneManager* pInst = new (std::nothrow) SceneManager();
265         SysTryReturnVoidResult(NID_UI_SCENES, pInst, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
266                                                    GetErrorMessage(E_OUT_OF_MEMORY));
267
268         result r = pInst->Construct();
269         SysTryCatch(NID_UI_SCENES, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
270
271         __pSceneManagerInstance = pInst;
272         std::atexit(DestroySingleton);
273         return;
274
275 CATCH:
276         delete pInst;
277 }
278
279 void
280 SceneManager::DestroySingleton(void)
281 {
282         delete __pSceneManagerInstance;
283 }
284
285
286 } } } // Tizen::Ui::Scenes