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