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