1 #ifndef DALI_INTERNAL_APPLICATION_H
2 #define DALI_INTERNAL_APPLICATION_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/math/rect.h>
23 #include <dali/public-api/object/base-object.h>
26 #include <dali/devel-api/common/singleton-service.h>
27 #include <dali/public-api/adaptor-framework/application.h>
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>
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.
50 NONE, ///< The default state
51 PRE_INITIALIZED ///< Application is pre-initialized.
54 } // namespace Launchpad
56 class CommandLineOptions;
57 class FrameworkFactory;
59 typedef Dali::Rect<int> PositionSize;
62 typedef IntrusivePtr<Application> ApplicationPtr;
65 * Implementation of the Application class.
67 class Application : public BaseObject, public Framework::Observer, public Framework::TaskObserver
70 typedef Dali::Application::LowBatterySignalType LowBatterySignalType;
71 typedef Dali::Application::LowMemorySignalType LowMemorySignalType;
72 typedef Dali::Application::DeviceOrientationChangedSignalType DeviceOrientationChangedSignalType;
73 typedef Dali::Application::AppSignalType AppSignalType;
74 typedef Dali::Application::AppControlSignalType AppControlSignalType;
75 typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
78 * Create a new application
79 * @param[in] argc A pointer to the number of arguments
80 * @param[in] argv A pointer to the argument list
81 * @param[in] stylesheet The path to user defined theme file
82 * @param[in] applicationType A member of Dali::Framework::Type
83 * @param[in] useUiThread True if the application would create a UI thread
84 * @param[in] windowData The window data
87 static ApplicationPtr New(int* argc, char** argv[], const std::string& stylesheet, Framework::Type applicationType, bool useUiThread, const WindowData& windowData);
90 * @copydoc Dali::DevelApplication::PreInitialize()
92 static void PreInitialize(int* argc, char** argv[]);
96 * @copydoc Dali::Application::MainLoop()
101 * @copydoc Dali::Application::Lower()
106 * @copydoc Dali::Application::Quit()
111 * @copydoc Dali::Application::AddIdle()
113 bool AddIdle(CallbackBase* callback, bool hasReturnValue);
116 * @copydoc Dali::Application::GetAdaptor();
118 Dali::Adaptor& GetAdaptor();
121 * @copydoc Dali::Application::GetWindow();
123 Dali::Window GetWindow();
126 * @copydoc Dali::Application::GetRegion();
128 std::string GetRegion() const;
131 * @copydoc Dali::Application::GetLanguage();
133 std::string GetLanguage() const;
136 * @copydoc Dali::Application::GetObjectRegistry();
138 Dali::ObjectRegistry GetObjectRegistry() const;
141 * @copydoc Dali::Application::GetResourcePath();
143 static std::string GetResourcePath();
146 * @copydoc Dali::DevelApplication::GetDataPath()
148 static std::string GetDataPath();
151 * Retrieves the pre-initialized application.
153 * @return A pointer to the pre-initialized application
155 static ApplicationPtr GetPreInitializedApplication();
158 * Stores PositionSize of window
160 void StoreWindowPositionSize(PositionSize positionSize);
163 * @copydoc Dali::DevelApplication::GetRenderThreadId()
165 int32_t GetRenderThreadId() const;
167 public: // From Framework::Observer
169 * Called when the framework is initialised.
171 void OnInit() override;
174 * Called when the framework is terminated.
176 void OnTerminate() override;
179 * Called when the framework is paused.
181 void OnPause() override;
184 * Called when the framework resumes from a paused state.
186 void OnResume() override;
189 * Called when the framework received AppControlSignal.
190 * @param[in] The bundle data of AppControl event.
192 void OnAppControl(void* data) override;
195 * Called when the framework informs the application that it should reset itself.
197 void OnReset() override;
200 * Called when the framework informs the application that the language of the device has changed.
202 void OnLanguageChanged() override;
205 * Called when the framework informs the application that the region of the device has changed.
207 void OnRegionChanged() override;
210 * Called when the framework informs the application that the battery level of the device is low.
212 void OnBatteryLow(Dali::DeviceStatus::Battery::Status status) override;
215 * Called when the framework informs the application that the memory level of the device is low.
217 void OnMemoryLow(Dali::DeviceStatus::Memory::Status status) override;
220 * Called when the framework informs the application that device orientation is changed.
222 void OnDeviceOrientationChanged(Dali::DeviceStatus::Orientation::Status status) override;
225 * Called when the framework informs the application that the platform surface is created.
227 void OnSurfaceCreated(Any newSurface) override;
230 * Called when the framework informs the application that the platform surface is destroyed.
232 void OnSurfaceDestroyed(Any newSurface) override;
234 public: // From Framework::TaskObserver
236 * Called when the framework is initialised.
238 void OnTaskInit() override;
241 * Called when the framework is terminated.
243 void OnTaskTerminate() override;
246 * Called when the framework received AppControlSignal.
247 * @param[in] The bundle data of AppControl event.
249 void OnTaskAppControl(void* data) override;
252 * Called when the framework informs the application that the language of the device has changed.
254 void OnTaskLanguageChanged() override;
257 * Called when the framework informs the application that the region of the device has changed.
259 void OnTaskRegionChanged() override;
262 * Called when the framework informs the application that the battery level of the device is low.
264 void OnTaskBatteryLow(Dali::DeviceStatus::Battery::Status status) override;
267 * Called when the framework informs the application that the memory level of the device is low.
269 void OnTaskMemoryLow(Dali::DeviceStatus::Memory::Status status) override;
272 * Called when the framework informs the application that the device orientation is changed.
274 * Device orientation changed event is from Application Framework(Sensor Framework), it means it is system event.
275 * If UIThreading is enable, DALI application has the main thread and UI thread.
276 * This event is emitted in main thread, then it is posted to the UI thread in this callback function.
278 void OnTaskDeviceOrientationChanged(Dali::DeviceStatus::Orientation::Status status) override;
282 * Sets a user defined theme file.
283 * This should be called before initialization.
284 * @param[in] stylesheet The path to user defined theme file
286 void SetStyleSheet(const std::string& stylesheet);
289 * Sets a command line options.
290 * This is used in case of the preinitialized application.
291 * @param[in] argc A pointer to the number of arguments
292 * @param[in] argv A pointer to the argument list
294 void SetCommandLineOptions(int* argc, char** argv[]);
297 * Sets default window type.
298 * This is used in case of the preinitialized application.
299 * @param[in] type the window type for default window
301 void SetDefaultWindowType(WindowType type);
304 * @brief Relayout the application and ensure all pending operations are flushed to the update thread.
306 void FlushUpdateMessages();
310 * @copydoc Dali::Application::InitSignal()
312 Dali::Application::AppSignalType& InitSignal()
318 * @copydoc Dali::Application::TerminateSignal()
320 Dali::Application::AppSignalType& TerminateSignal()
322 return mTerminateSignal;
326 * @copydoc Dali::Application::PauseSignal()
328 Dali::Application::AppSignalType& PauseSignal()
334 * @copydoc Dali::Application::ResumeSignal()
336 Dali::Application::AppSignalType& ResumeSignal()
338 return mResumeSignal;
342 * @copydoc Dali::Application::ResetSignal()
344 Dali::Application::AppSignalType& ResetSignal()
350 * @copydoc Dali::Application::AppControlSignal()
352 Dali::Application::AppControlSignalType& AppControlSignal()
354 return mAppControlSignal;
358 * @copydoc Dali::Application::LanguageChangedSignal()
360 Dali::Application::AppSignalType& LanguageChangedSignal()
362 return mLanguageChangedSignal;
366 * @copydoc Dali::Application::RegionChangedSignal()
368 Dali::Application::AppSignalType& RegionChangedSignal()
370 return mRegionChangedSignal;
374 * @copydoc Dali::Application::LowBatterySignal()
376 Dali::Application::LowBatterySignalType& LowBatterySignal()
378 return mLowBatterySignal;
382 * @copydoc Dali::Application:::LowMemorySignal()
384 Dali::Application::LowMemorySignalType& LowMemorySignal()
386 return mLowMemorySignal;
390 * @copydoc Dali::Application:::DeviceOrientationChangedSignalType()
392 Dali::Application::DeviceOrientationChangedSignalType& DeviceOrientationChangedSignal()
394 return mDeviceOrientationChangedSignal;
398 * @copydoc Dali::Application::TaskInitSignal()
400 Dali::Application::AppSignalType& TaskInitSignal()
402 return mTaskInitSignal;
406 * @copydoc Dali::Application::TaskTerminateSignal()
408 Dali::Application::AppSignalType& TaskTerminateSignal()
410 return mTaskTerminateSignal;
414 * @copydoc Dali::Application::TaskAppControlSignal()
416 Dali::Application::AppControlSignalType& TaskAppControlSignal()
418 return mTaskAppControlSignal;
422 * @copydoc Dali::Application::TaskLanguageChangedSignal()
424 Dali::Application::AppSignalType& TaskLanguageChangedSignal()
426 return mTaskLanguageChangedSignal;
430 * @copydoc Dali::Application::TaskRegionChangedSignal()
432 Dali::Application::AppSignalType& TaskRegionChangedSignal()
434 return mTaskRegionChangedSignal;
438 * @copydoc Dali::Application::TaskLowBatterySignal()
440 Dali::Application::LowBatterySignalType& TaskLowBatterySignal()
442 return mTaskLowBatterySignal;
446 * @copydoc Dali::Application::TaskLowMemorySignal()
448 Dali::Application::LowMemorySignalType& TaskLowMemorySignal()
450 return mTaskLowMemorySignal;
454 * @copydoc Dali::Application::TaskDeviceOrientationChangedSignal()
456 Dali::Application::DeviceOrientationChangedSignalType& TaskDeviceOrientationChangedSignal()
458 return mTaskDeviceOrientationChangedSignal;
463 * Private Constructor
464 * @param[in] argc A pointer to the number of arguments
465 * @param[in] argv A pointer to the argument list
466 * @param[in] stylesheet The path to user defined theme file
467 * @param[in] applicationType A member of Dali::Framework::Type
468 * @param[in] useUiThread True if the application would create UI thread
469 * @param[in] windowData The WindowData
471 Application(int* argc, char** argv[], const std::string& stylesheet, Framework::Type applicationType, bool useUiThread, const WindowData& windowData);
476 virtual ~Application() override;
479 Application(const Application&);
480 Application& operator=(Application&);
483 * Creates the default window
488 * Creates the adaptor
490 void CreateAdaptor();
493 * Creates the adaptor builder
495 void CreateAdaptorBuilder();
498 * Quits from the main loop
500 void QuitFromMainLoop();
503 * Changes information of preInitialized window
505 void ChangePreInitializedWindowInfo();
508 AppSignalType mInitSignal;
509 AppSignalType mTerminateSignal;
510 AppSignalType mPauseSignal;
511 AppSignalType mResumeSignal;
512 AppSignalType mResetSignal;
513 AppControlSignalType mAppControlSignal;
514 AppSignalType mLanguageChangedSignal;
515 AppSignalType mRegionChangedSignal;
516 LowBatterySignalType mLowBatterySignal;
517 LowMemorySignalType mLowMemorySignal;
518 DeviceOrientationChangedSignalType mDeviceOrientationChangedSignal;
520 AppSignalType mTaskInitSignal;
521 AppSignalType mTaskTerminateSignal;
522 AppControlSignalType mTaskAppControlSignal;
523 AppSignalType mTaskLanguageChangedSignal;
524 AppSignalType mTaskRegionChangedSignal;
525 LowBatterySignalType mTaskLowBatterySignal;
526 LowMemorySignalType mTaskLowMemorySignal;
527 DeviceOrientationChangedSignalType mTaskDeviceOrientationChangedSignal;
529 std::unique_ptr<Framework> mFramework;
530 std::unique_ptr<FrameworkFactory> mFrameworkFactory;
532 CommandLineOptions* mCommandLineOptions;
534 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder; ///< The adaptor builder
535 Dali::Adaptor* mAdaptor;
536 std::unique_ptr<EnvironmentOptions> mEnvironmentOptions;
538 // The Main Window is that window created by the Application during initial startup
539 // (previously this was the only window)
540 Dali::Window mMainWindow; ///< Main Window instance
541 Dali::Application::WINDOW_MODE mMainWindowMode; ///< Window mode of the main window
542 std::string mMainWindowName; ///< Name of the main window as obtained from environment options
544 std::string mStylesheet;
545 PositionSize mWindowPositionSize;
546 Launchpad::State mLaunchpadState;
547 WindowType mDefaultWindowType; ///< Default window's type. It is used when Application is created.
548 bool mUseRemoteSurface;
550 bool mIsSystemInitialized;
552 SlotDelegate<Application> mSlotDelegate;
554 UIThreadLoader* mUIThreadLoader;
555 static ApplicationPtr gPreInitializedApplication;
558 inline Application& GetImplementation(Dali::Application& application)
560 DALI_ASSERT_ALWAYS(application && "application handle is empty");
562 BaseObject& handle = application.GetBaseObject();
564 return static_cast<Internal::Adaptor::Application&>(handle);
567 inline const Application& GetImplementation(const Dali::Application& application)
569 DALI_ASSERT_ALWAYS(application && "application handle is empty");
571 const BaseObject& handle = application.GetBaseObject();
573 return static_cast<const Internal::Adaptor::Application&>(handle);
576 } // namespace Adaptor
578 } // namespace Internal
582 #endif // DALI_INTERNAL_APPLICATION_H