b7e4bb2627cf23453b21b7b34e0014b28e586232
[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) 2017 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 <application-devel.h>
28 #include <singleton-service.h>
29
30 #include <framework.h>
31 #include <window-impl.h>
32 #include <base/environment-options.h>
33
34 namespace Dali
35 {
36 class Adaptor;
37 class Window;
38
39 namespace Internal
40 {
41
42 namespace Adaptor
43 {
44
45 namespace Launchpad
46 {
47
48 /**
49  * @brief Launchpad is used to improve application launch performance.
50  * When an application is pre-initialized, so files are preloaded, some functions are initialized and a window is made in advance.
51  */
52 enum State
53 {
54   NONE,              ///< The default state
55   PRE_INITIALIZED    ///< Application is pre-initialized.
56 };
57
58 } // namespace Launchpad
59
60 class CommandLineOptions;
61 class EventLoop;
62
63 typedef Dali::Rect<int> PositionSize;
64
65 class Application;
66 typedef IntrusivePtr<Application> ApplicationPtr;
67
68 /**
69  * Implementation of the Application class.
70  */
71 class Application : public BaseObject, public Framework::Observer
72 {
73 public:
74
75   typedef Dali::Application::AppSignalType AppSignalType;
76   typedef Dali::Application::AppControlSignalType AppControlSignalType;
77   typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
78
79   /**
80    * Create a new application
81    * @param[in]  argc         A pointer to the number of arguments
82    * @param[in]  argv         A pointer to the argument list
83    * @param[in]  stylesheet   The path to user defined theme file
84    * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
85    * @param[in]  positionSize A position and a size of the window
86    * @param[in]  applicationType  A member of Dali::Framework::Type
87    */
88   static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet,
89     WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
90
91   /**
92    * @copydoc Dali::DevelApplication::PreInitialize()
93    */
94   static void PreInitialize( int* argc, char** argv[] );
95
96 public:
97
98   /**
99    * @copydoc Dali::Application::MainLoop()
100    */
101   void MainLoop(Dali::Configuration::ContextLoss configuration);
102
103   /**
104    * @copydoc Dali::Application::Lower()
105    */
106   void Lower();
107
108   /**
109    * @copydoc Dali::Application::Quit()
110    */
111   void Quit();
112
113   /**
114    * @copydoc Dali::Application::AddIdle()
115    */
116   bool AddIdle( CallbackBase* callback );
117
118   /**
119    * @copydoc Dali::Application::GetAdaptor();
120    */
121   Dali::Adaptor& GetAdaptor();
122
123   /**
124    * @copydoc Dali::Application::GetWindow();
125    */
126   Dali::Window GetWindow();
127
128   /**
129    * @copydoc Dali::DevelApplication::GetRegion();
130    */
131   std::string GetRegion();
132
133   /**
134    * @copydoc Dali::DevelApplication::GetLanguage();
135    */
136   std::string GetLanguage();
137
138   /**
139    * @copydoc Dali::Application::ReplaceWindow();
140    */
141   void ReplaceWindow( const PositionSize& positionSize, const std::string& name);
142
143   /**
144    * @copydoc Dali::Application::GetResourcePath();
145    */
146   static std::string GetResourcePath();
147
148   /**
149    * Retrieves the pre-initialized application.
150    *
151    * @return A pointer to the pre-initialized application
152    */
153   static ApplicationPtr GetPreInitializedApplication();
154
155 public: // Stereoscopy
156
157   /**
158    * @copydoc Dali::Application::SetViewMode()
159    */
160   void SetViewMode( ViewMode viewMode );
161
162   /**
163    * @copydoc Dali::Application::GetViewMode()
164    */
165   ViewMode GetViewMode() const;
166
167   /**
168    * @copydoc Dali::Application::SetStereoBase()
169    */
170   void SetStereoBase( float stereoBase );
171
172   /**
173    * @copydoc Dali::Application::GetStereoBase()
174    */
175   float GetStereoBase() const;
176
177 public: // Lifecycle functionality
178
179   /**
180    * Called when OnInit is called or the framework is initialised.
181    */
182   void DoInit();
183
184   /**
185    * Called after OnInit is called or the framework is started.
186    */
187   void DoStart();
188
189   /**
190    * Called when OnTerminate is called or the framework is terminated.
191    */
192   void DoTerminate();
193
194   /**
195    * Called when OnPause is called or the framework is paused.
196    */
197   void DoPause();
198
199   /**
200    * Called when OnResume is called or the framework resumes from a paused state.
201    */
202   void DoResume();
203
204   /**
205    * Called when OnLanguageChanged is called or the framework informs the application that the language of the device has changed.
206    */
207   void DoLanguageChange();
208
209 public: // From Framework::Observer
210
211   /**
212    * Called when the framework is initialised.
213    */
214   virtual void OnInit();
215
216   /**
217    * Called when the framework is terminated.
218    */
219   virtual void OnTerminate();
220
221   /**
222    * Called when the framework is paused.
223    */
224   virtual void OnPause();
225
226   /**
227    * Called when the framework resumes from a paused state.
228    */
229   virtual void OnResume();
230
231   /**
232   * Called when the framework received AppControlSignal.
233   * @param[in] The bundle data of AppControl event.
234   */
235   virtual void OnAppControl(void *data);
236
237   /**
238    * Called when the framework informs the application that it should reset itself.
239    */
240   virtual void OnReset();
241
242   /**
243    * Called when the framework informs the application that the language of the device has changed.
244    */
245   virtual void OnLanguageChanged( const std::string& language );
246
247   /**
248   * Called when the framework informs the application that the region of the device has changed.
249   */
250   virtual void OnRegionChanged( const std::string& region );
251
252   /**
253   * Called when the framework informs the application that the battery level of the device is low.
254   */
255   virtual void OnBatteryLow( Dali::DevelApplication::BatteryStatus::Type status );
256
257   /**
258   * Called when the framework informs the application that the memory level of the device is low.
259   */
260   virtual void OnMemoryLow( Dali::DevelApplication::MemoryStatus::Type status );
261
262 public:
263
264   /**
265    * Signal handler when the adaptor's window resizes itself.
266    * @param[in]  adaptor  The adaptor
267    */
268   void OnResize(Dali::Adaptor& adaptor);
269
270   /**
271    * Sets a user defined theme file.
272    * This should be called before initialization.
273    * @param[in] stylesheet The path to user defined theme file
274    */
275   void SetStyleSheet( const std::string& stylesheet );
276
277 public:  // Signals
278
279   /**
280    * @copydoc Dali::Application::InitSignal()
281    */
282   Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
283
284   /**
285    * @copydoc Dali::Application::TerminateSignal()
286    */
287   Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
288
289   /**
290    * @copydoc Dali::Application::PauseSignal()
291    */
292   Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
293
294   /**
295    * @copydoc Dali::Application::ResumeSignal()
296    */
297   Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
298
299   /**
300    * @copydoc Dali::Application::ResetSignal()
301    */
302   Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
303
304   /**
305   * @copydoc Dali::Application::AppControlSignal()
306   */
307   Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
308
309   /**
310    * @copydoc Dali::Application::ResizeSignal()
311    */
312   Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
313
314   /**
315    * @copydoc Dali::Application::LanguageChangedSignal()
316    */
317   Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
318
319   /**
320   * @copydoc Dali::Application::RegionChangedSignal()
321   */
322   Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
323
324   /**
325   * @copydoc Dali::Application::BatteryLowSignal()
326   */
327   Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
328
329   /**
330   * @copydoc Dali::Application::MemoryLowSignal()
331   */
332   Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
333
334   /**
335   * @copydoc Dali::DevelApplication::LowBatterySignal()
336   */
337   Dali::DevelApplication::LowBatterySignalType& LowBatterySignal() { return mLowBatterySignal; }
338
339   /**
340   * @copydoc Dali::DevelApplication:::LowMemorySignal()
341   */
342   Dali::DevelApplication::LowMemorySignalType& LowMemorySignal() { return mLowMemorySignal; }
343
344 protected:
345
346   /**
347    * Private Constructor
348    * @param[in]  argc         A pointer to the number of arguments
349    * @param[in]  argv         A pointer to the argument list
350    * @param[in]  stylesheet   The path to user defined theme file
351    * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
352    * @param[in]  positionSize A position and a size of the window
353    * @param[in]  applicationType  A member of Dali::Framework::Type
354    */
355   Application( int* argc, char **argv[], const std::string& stylesheet,
356       WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
357
358   /**
359    * Destructor
360    */
361   virtual ~Application();
362
363   // Undefined
364   Application(const Application&);
365   Application& operator=(Application&);
366
367   /**
368    * Creates the window
369    */
370   void CreateWindow();
371
372   /**
373    * Creates the adaptor
374    */
375   void CreateAdaptor();
376
377   /**
378    * Quits from the main loop
379    */
380   void QuitFromMainLoop();
381
382 private:
383
384   AppSignalType                                 mInitSignal;
385   AppSignalType                                 mTerminateSignal;
386   AppSignalType                                 mPauseSignal;
387   AppSignalType                                 mResumeSignal;
388   AppSignalType                                 mResetSignal;
389   AppSignalType                                 mResizeSignal;
390   AppControlSignalType                          mAppControlSignal;
391   AppSignalType                                 mLanguageChangedSignal;
392   AppSignalType                                 mRegionChangedSignal;
393   AppSignalType                                 mBatteryLowSignal;
394   AppSignalType                                 mMemoryLowSignal;
395   Dali::DevelApplication::LowBatterySignalType  mLowBatterySignal;
396   Dali::DevelApplication::LowMemorySignalType   mLowMemorySignal;
397
398   EventLoop*                            mEventLoop;
399   Framework*                            mFramework;
400
401   Dali::Configuration::ContextLoss      mContextLossConfiguration;
402   CommandLineOptions*                   mCommandLineOptions;
403
404   Dali::SingletonService                        mSingletonService;
405   Dali::Adaptor*                                mAdaptor;
406   Dali::Window                                  mWindow;
407   Dali::Application::WINDOW_MODE                mWindowMode;
408   std::string                                   mName;
409   std::string                                   mStylesheet;
410   std::string                                   mLanguage;
411   std::string                                   mRegion;
412   EnvironmentOptions                            mEnvironmentOptions;
413   PositionSize                                  mWindowPositionSize;
414   Launchpad::State                              mLaunchpadState;
415   bool                                          mUseRemoteSurface;
416
417   SlotDelegate< Application >           mSlotDelegate;
418
419   static ApplicationPtr                 gPreInitializedApplication;
420 };
421
422 inline Application& GetImplementation(Dali::Application& application)
423 {
424   DALI_ASSERT_ALWAYS(application && "application handle is empty");
425
426   BaseObject& handle = application.GetBaseObject();
427
428   return static_cast<Internal::Adaptor::Application&>(handle);
429 }
430
431 inline const Application& GetImplementation(const Dali::Application& application)
432 {
433   DALI_ASSERT_ALWAYS(application && "Timre handle is empty");
434
435   const BaseObject& handle = application.GetBaseObject();
436
437   return static_cast<const Internal::Adaptor::Application&>(handle);
438 }
439
440
441 } // namespace Adaptor
442
443 } // namespace Internal
444
445 } // namespace Dali
446
447 #endif // __DALI_INTERNAL_APPLICATION_H__