Merge "Remove RenderThread::mSurface pointer before mWindow.Reset()" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / common / application-impl.h
1 #ifndef __DALI_INTERNAL_APPLICATION_H__
2 #define __DALI_INTERNAL_APPLICATION_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/math/rect.h>
23 #include <dali/public-api/object/base-object.h>
24
25 // INTERNAL INCLUDES
26 #include <application.h>
27 #include <singleton-service.h>
28
29 #include <framework.h>
30 #include <window-impl.h>
31 #include <base/environment-options.h>
32
33 namespace Dali
34 {
35 class Adaptor;
36 class Window;
37
38 namespace Internal
39 {
40
41 namespace Adaptor
42 {
43 class CommandLineOptions;
44 class EventLoop;
45
46 typedef Dali::Rect<int> PositionSize;
47
48 class Application;
49 typedef IntrusivePtr<Application> ApplicationPtr;
50
51 /**
52  * Implementation of the Application class.
53  */
54 class Application : public BaseObject, public Framework::Observer
55 {
56 public:
57
58   typedef Dali::Application::AppSignalType AppSignalType;
59   typedef Dali::Application::AppControlSignalType AppControlSignalType;
60   typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
61
62   /**
63    * Create a new application
64    * @param[in]  argc        A pointer to the number of arguments
65    * @param[in]  argv        A pointer to the argument list
66    * @param[in]  stylesheet  The path to user defined theme file
67    * @param[in]  windowMode  A member of Dali::Application::WINDOW_MODE
68    */
69   static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode );
70
71 public:
72
73   /**
74    * @copydoc Dali::Application::MainLoop()
75    */
76   void MainLoop(Dali::Configuration::ContextLoss configuration);
77
78   /**
79    * @copydoc Dali::Application::Lower()
80    */
81   void Lower();
82
83   /**
84    * @copydoc Dali::Application::Quit()
85    */
86   void Quit();
87
88   /**
89    * @copydoc Dali::Application::AddIdle()
90    */
91   bool AddIdle( CallbackBase* callback );
92
93   /**
94    * @copydoc Dali::Application::GetAdaptor();
95    */
96   Dali::Adaptor& GetAdaptor();
97
98   /**
99    * @copydoc Dali::Application::GetWindow();
100    */
101   Dali::Window GetWindow();
102
103   /**
104    * @copydoc Dali::Application::ReplaceWindow();
105    */
106   void ReplaceWindow(PositionSize windowPosition, const std::string& name);
107
108 public: // Stereoscopy
109
110   /**
111    * @copydoc Dali::Application::SetViewMode()
112    */
113   void SetViewMode( ViewMode viewMode );
114
115   /**
116    * @copydoc Dali::Application::GetViewMode()
117    */
118   ViewMode GetViewMode() const;
119
120   /**
121    * @copydoc Dali::Application::SetStereoBase()
122    */
123   void SetStereoBase( float stereoBase );
124
125   /**
126    * @copydoc Dali::Application::GetStereoBase()
127    */
128   float GetStereoBase() const;
129
130 public: // From Framework::Observer
131
132   /**
133    * Called when the framework is initialised.
134    */
135   virtual void OnInit();
136
137   /**
138    * Called when the framework is terminated.
139    */
140   virtual void OnTerminate();
141
142   /**
143    * Called when the framework is paused.
144    */
145   virtual void OnPause();
146
147   /**
148    * Called when the framework resumes from a paused state.
149    */
150   virtual void OnResume();
151
152   /**
153   * Called when the framework received AppControlSignal.
154   * @param[in] The bundle data of AppControl event.
155   */
156   virtual void OnAppControl(void *data);
157
158   /**
159    * Called when the framework informs the application that it should reset itself.
160    */
161   virtual void OnReset();
162
163   /**
164    * Called when the framework informs the application that the language of the device has changed.
165    */
166   virtual void OnLanguageChanged();
167
168   /**
169   * Called when the framework informs the application that the region of the device has changed.
170   */
171   virtual void OnRegionChanged();
172
173   /**
174   * Called when the framework informs the application that the battery level of the device is low.
175   */
176   virtual void OnBatteryLow();
177
178   /**
179   * Called when the framework informs the application that the memory level of the device is low.
180   */
181   virtual void OnMemoryLow();
182
183 public:
184
185   /**
186    * Signal handler when the adaptor's window resizes itself.
187    * @param[in]  adaptor  The adaptor
188    */
189   void OnResize(Dali::Adaptor& adaptor);
190
191 public:  // Signals
192
193   /**
194    * @copydoc Dali::Application::InitSignal()
195    */
196   Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
197
198   /**
199    * @copydoc Dali::Application::TerminateSignal()
200    */
201   Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
202
203   /**
204    * @copydoc Dali::Application::PauseSignal()
205    */
206   Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
207
208   /**
209    * @copydoc Dali::Application::ResumeSignal()
210    */
211   Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
212
213   /**
214    * @copydoc Dali::Application::ResetSignal()
215    */
216   Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
217
218   /**
219   * @copydoc Dali::Application::AppControlSignal()
220   */
221   Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
222
223   /**
224    * @copydoc Dali::Application::ResizeSignal()
225    */
226   Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
227
228   /**
229    * @copydoc Dali::Application::LanguageChangedSignal()
230    */
231   Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
232
233   /**
234   * @copydoc Dali::Application::RegionChangedSignal()
235   */
236   Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
237
238   /**
239   * @copydoc Dali::Application::BatteryLowSignal()
240   */
241   Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
242
243   /**
244   * @copydoc Dali::Application::MemoryLowSignal()
245   */
246   Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
247
248 private:
249
250   /**
251    * Private Constructor
252    * @param[in]  argc        A pointer to the number of arguments
253    * @param[in]  argv        A pointer to the argument list
254    * @param[in]  stylesheet  The path to user defined theme file
255    * @param[in]  windowMode  A member of Dali::Application::WINDOW_MODE
256    */
257   Application( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode );
258
259   /**
260    * Destructor
261    */
262   virtual ~Application();
263
264   // Undefined
265   Application(const Application&);
266   Application& operator=(Application&);
267
268 private:
269   /**
270    * Creates the window
271    */
272   void CreateWindow();
273
274   /**
275    * Creates the adaptor
276    */
277   void CreateAdaptor();
278
279   /**
280    * Quits from the main loop
281    */
282   void QuitFromMainLoop();
283
284 private:
285
286   AppSignalType                           mInitSignal;
287   AppSignalType                           mTerminateSignal;
288   AppSignalType                           mPauseSignal;
289   AppSignalType                           mResumeSignal;
290   AppSignalType                           mResetSignal;
291   AppSignalType                           mResizeSignal;
292   AppControlSignalType                    mAppControlSignal;
293   AppSignalType                           mLanguageChangedSignal;
294   AppSignalType                           mRegionChangedSignal;
295   AppSignalType                           mBatteryLowSignal;
296   AppSignalType                           mMemoryLowSignal;
297
298   EventLoop*                            mEventLoop;
299   Framework*                            mFramework;
300
301   Dali::Configuration::ContextLoss      mContextLossConfiguration;
302   CommandLineOptions*                   mCommandLineOptions;
303
304   Dali::SingletonService                mSingletonService;
305   Dali::Adaptor*                        mAdaptor;
306   Dali::Window                          mWindow;
307   Dali::Application::WINDOW_MODE        mWindowMode;
308   std::string                           mName;
309   std::string                           mStylesheet;
310   EnvironmentOptions                    mEnvironmentOptions;
311
312   SlotDelegate< Application >           mSlotDelegate;
313 };
314
315 inline Application& GetImplementation(Dali::Application& application)
316 {
317   DALI_ASSERT_ALWAYS(application && "application handle is empty");
318
319   BaseObject& handle = application.GetBaseObject();
320
321   return static_cast<Internal::Adaptor::Application&>(handle);
322 }
323
324 inline const Application& GetImplementation(const Dali::Application& application)
325 {
326   DALI_ASSERT_ALWAYS(application && "Timre handle is empty");
327
328   const BaseObject& handle = application.GetBaseObject();
329
330   return static_cast<const Internal::Adaptor::Application&>(handle);
331 }
332
333
334 } // namespace Adaptor
335
336 } // namespace Internal
337
338 } // namespace Dali
339
340 #endif // __DALI_INTERNAL_APPLICATION_H__