1 #ifndef DALI_INTERNAL_APPLICATION_H
2 #define DALI_INTERNAL_APPLICATION_H
5 * Copyright (c) 2022 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;
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
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;
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.
86 static ApplicationPtr New(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType, WindowType type);
89 * @copydoc Dali::DevelApplication::PreInitialize()
91 static void PreInitialize(int* argc, char** argv[]);
95 * @copydoc Dali::Application::MainLoop()
100 * @copydoc Dali::Application::Lower()
105 * @copydoc Dali::Application::Quit()
110 * @copydoc Dali::Application::AddIdle()
112 bool AddIdle(CallbackBase* callback, bool hasReturnValue);
115 * @copydoc Dali::Application::GetAdaptor();
117 Dali::Adaptor& GetAdaptor();
120 * @copydoc Dali::Application::GetWindow();
122 Dali::Window GetWindow();
125 * @copydoc Dali::Application::GetRegion();
127 std::string GetRegion() const;
130 * @copydoc Dali::Application::GetLanguage();
132 std::string GetLanguage() const;
135 * @copydoc Dali::Application::GetObjectRegistry();
137 Dali::ObjectRegistry GetObjectRegistry() const;
140 * @copydoc Dali::Application::GetResourcePath();
142 static std::string GetResourcePath();
145 * @copydoc Dali::DevelApplication::GetDataPath()
147 static std::string GetDataPath();
150 * Retrieves the pre-initialized application.
152 * @return A pointer to the pre-initialized application
154 static ApplicationPtr GetPreInitializedApplication();
157 * Stores PositionSize of window
159 void StoreWindowPositionSize(PositionSize positionSize);
161 public: // From Framework::Observer
163 * Called when the framework is initialised.
165 void OnInit() override;
168 * Called when the framework is terminated.
170 void OnTerminate() override;
173 * Called when the framework is paused.
175 void OnPause() override;
178 * Called when the framework resumes from a paused state.
180 void OnResume() override;
183 * Called when the framework received AppControlSignal.
184 * @param[in] The bundle data of AppControl event.
186 void OnAppControl(void* data) override;
189 * Called when the framework informs the application that it should reset itself.
191 void OnReset() override;
194 * Called when the framework informs the application that the language of the device has changed.
196 void OnLanguageChanged() override;
199 * Called when the framework informs the application that the region of the device has changed.
201 void OnRegionChanged() override;
204 * Called when the framework informs the application that the battery level of the device is low.
206 void OnBatteryLow(Dali::DeviceStatus::Battery::Status status) override;
209 * Called when the framework informs the application that the memory level of the device is low.
211 void OnMemoryLow(Dali::DeviceStatus::Memory::Status status) override;
214 * Called when the framework informs the application that the platform surface is created.
216 void OnSurfaceCreated(Any newSurface) override;
219 * Called when the framework informs the application that the platform surface is destroyed.
221 void OnSurfaceDestroyed(Any newSurface) override;
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
229 void SetStyleSheet(const std::string& stylesheet);
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
237 void SetCommandLineOptions(int* argc, char** argv[]);
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
244 void SetDefaultWindowType(WindowType type);
248 * @copydoc Dali::Application::InitSignal()
250 Dali::Application::AppSignalType& InitSignal()
256 * @copydoc Dali::Application::TerminateSignal()
258 Dali::Application::AppSignalType& TerminateSignal()
260 return mTerminateSignal;
264 * @copydoc Dali::Application::PauseSignal()
266 Dali::Application::AppSignalType& PauseSignal()
272 * @copydoc Dali::Application::ResumeSignal()
274 Dali::Application::AppSignalType& ResumeSignal()
276 return mResumeSignal;
280 * @copydoc Dali::Application::ResetSignal()
282 Dali::Application::AppSignalType& ResetSignal()
288 * @copydoc Dali::Application::AppControlSignal()
290 Dali::Application::AppControlSignalType& AppControlSignal()
292 return mAppControlSignal;
296 * @copydoc Dali::Application::LanguageChangedSignal()
298 Dali::Application::AppSignalType& LanguageChangedSignal()
300 return mLanguageChangedSignal;
304 * @copydoc Dali::Application::RegionChangedSignal()
306 Dali::Application::AppSignalType& RegionChangedSignal()
308 return mRegionChangedSignal;
312 * @copydoc Dali::Application::LowBatterySignal()
314 Dali::Application::LowBatterySignalType& LowBatterySignal()
316 return mLowBatterySignal;
320 * @copydoc Dali::Application:::LowMemorySignal()
322 Dali::Application::LowMemorySignalType& LowMemorySignal()
324 return mLowMemorySignal;
329 * Private Constructor
330 * @param[in] argc A pointer to the number of arguments
331 * @param[in] argv A pointer to the argument list
332 * @param[in] stylesheet The path to user defined theme file
333 * @param[in] windowMode A member of Dali::Application::WINDOW_MODE
334 * @param[in] positionSize A position and a size of the window
335 * @param[in] applicationType A member of Dali::Framework::Type
336 * @param[in] type The default window's type.
338 Application(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType, WindowType type);
343 ~Application() override;
346 Application(const Application&);
347 Application& operator=(Application&);
350 * Creates the default window
355 * Creates the adaptor
357 void CreateAdaptor();
360 * Creates the adaptor builder
362 void CreateAdaptorBuilder();
365 * Quits from the main loop
367 void QuitFromMainLoop();
370 * Changes size of preInitialized window
372 void ChangePreInitializedWindowSize();
375 AppSignalType mInitSignal;
376 AppSignalType mTerminateSignal;
377 AppSignalType mPauseSignal;
378 AppSignalType mResumeSignal;
379 AppSignalType mResetSignal;
380 AppControlSignalType mAppControlSignal;
381 AppSignalType mLanguageChangedSignal;
382 AppSignalType mRegionChangedSignal;
383 LowBatterySignalType mLowBatterySignal;
384 LowMemorySignalType mLowMemorySignal;
386 EventLoop* mEventLoop;
387 Framework* mFramework;
389 CommandLineOptions* mCommandLineOptions;
391 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder; ///< The adaptor builder
392 Dali::Adaptor* mAdaptor;
394 // The Main Window is that window created by the Application during initial startup
395 // (previously this was the only window)
396 Dali::Window mMainWindow; ///< Main Window instance
397 Dali::Application::WINDOW_MODE mMainWindowMode; ///< Window mode of the main window
398 std::string mMainWindowName; ///< Name of the main window as obtained from environment options
400 std::string mStylesheet;
401 EnvironmentOptions mEnvironmentOptions;
402 PositionSize mWindowPositionSize;
403 Launchpad::State mLaunchpadState;
404 bool mUseRemoteSurface;
405 WindowType mDefaultWindowType; ///< Default window's type. It is used when Application is created.
407 SlotDelegate<Application> mSlotDelegate;
409 static ApplicationPtr gPreInitializedApplication;
412 inline Application& GetImplementation(Dali::Application& application)
414 DALI_ASSERT_ALWAYS(application && "application handle is empty");
416 BaseObject& handle = application.GetBaseObject();
418 return static_cast<Internal::Adaptor::Application&>(handle);
421 inline const Application& GetImplementation(const Dali::Application& application)
423 DALI_ASSERT_ALWAYS(application && "application handle is empty");
425 const BaseObject& handle = application.GetBaseObject();
427 return static_cast<const Internal::Adaptor::Application&>(handle);
430 } // namespace Adaptor
432 } // namespace Internal
436 #endif // DALI_INTERNAL_APPLICATION_H