1 #ifndef DALI_APPLICATION_H
2 #define DALI_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/object/base-handle.h>
23 #include <dali/public-api/signals/callback.h>
26 #include <dali/public-api/adaptor-framework/device-status.h>
27 #include <dali/public-api/adaptor-framework/window-data.h>
28 #include <dali/public-api/adaptor-framework/window.h>
35 * @addtogroup dali_adaptor_framework
39 namespace Internal DALI_INTERNAL
45 } // namespace DALI_INTERNAL
47 * @brief An Application class object should be created by every application
48 * that wishes to use Dali.
50 * It provides a means for initializing the
51 * resources required by the Dali::Core.
53 * The Application class emits several signals which the user can
54 * connect to. The user should not create any Dali objects in the main
55 * function and instead should connect to the Init signal of the
56 * Application and create the Dali objects in the connected callback.
58 * Applications should follow the example below:
61 * class ExampleController: public ConnectionTracker
64 * ExampleController( Application& application )
65 * : mApplication( application )
67 * mApplication.InitSignal().Connect( this, &ExampleController::Create );
70 * void Create( Application& application )
72 * // Create Dali components...
76 * Application& mApplication;
79 * int main (int argc, char **argv)
81 * Application app = Application::New(&argc, &argv);
82 * ExampleController example( app );
87 * If required, you can also connect class member functions to a signal:
91 * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
96 * There is the UI thread feature.
97 * UI thread is an additional thread that an Application object creates. The thread is for UI events.
99 * When the UI thread feature is enabled, you can use the task signals(TaskInit, TaskTerminate, TaskAppControl, TaskLanguageChanged, TaskLowBattery, and TaskLowMemory).
100 * The task signals are emitted on the main thread,
101 * and the normal signals(Init, Terminate, Pause, Resume, Reset, AppControl, LanguageChanged, Region, LowBattery, and LowMemory) are emitted on the UI thread.
103 * If you want to handle windows or actors in cases like when the memory level of the device is low, you have to use the normal signals, not the task signals.
104 * Callbacks of all signals in DALi except the task signals are emitted on the UI thread. (e.g., Timer callbacks are emitted on the UI thread.)
106 * To enable the UI Thread, you can use this method. you have to set True to the useUiThread.
107 * Dali::Application::New(int *argc, char **argv[], const std::string &stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize, bool useUiThread)
110 * This class accepts command line arguments as well. The following options are supported:
113 * -w|--width Stage Width
114 * -h|--height Stage Height
115 * -d|--dpi Emulated DPI
119 * When the above options are found, they are stripped from argv, and argc is updated appropriately.
122 class DALI_ADAPTOR_API Application : public BaseHandle
125 typedef Signal<void(DeviceStatus::Battery::Status)> LowBatterySignalType; ///< Application device signal type @SINCE_1_2.62
126 typedef Signal<void(DeviceStatus::Memory::Status)> LowMemorySignalType; ///< Application device signal type @SINCE_1_2.62
127 typedef Signal<void(DeviceStatus::Orientation::Status)> DeviceOrientationChangedSignalType; ///< Application device orientation changed signal type @SINCE_2_2.1
128 typedef Signal<void(Application&)> AppSignalType; ///< Application lifecycle signal and system signal callback type @SINCE_1_0.0
129 typedef Signal<void(Application&, void*)> AppControlSignalType; ///< Application control signal callback type @SINCE_1_0.0
132 * @brief Enumeration for deciding whether a Dali application window is opaque or transparent.
137 OPAQUE = 0, ///< The window will be opaque @SINCE_1_0.0
138 TRANSPARENT = 1 ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor() @SINCE_1_0.0
143 * @brief This is the constructor for applications without an argument list.
147 * @return A handle to the Application
149 static Application New();
152 * @brief This is the constructor for applications.
157 * @param[in,out] argc A pointer to the number of arguments
158 * @param[in,out] argv A pointer to the argument list
159 * @return A handle to the Application
161 static Application New(int* argc, char** argv[]);
164 * @brief This is the constructor for applications with a name.
169 * @param[in,out] argc A pointer to the number of arguments
170 * @param[in,out] argv A pointer to the argument list
171 * @param[in] stylesheet The path to user defined theme file
172 * @return A handle to the Application
173 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
175 static Application New(int* argc, char** argv[], const std::string& stylesheet);
178 * @brief This is the constructor for applications with a name.
183 * @param[in,out] argc A pointer to the number of arguments
184 * @param[in,out] argv A pointer to the argument list
185 * @param[in] stylesheet The path to user defined theme file
186 * @param[in] windowMode A member of WINDOW_MODE
187 * @return A handle to the Application
188 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
190 static Application New(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode);
193 * @brief This is the constructor for applications.
198 * @param[in,out] argc A pointer to the number of arguments
199 * @param[in,out] argv A pointer to the argument list
200 * @param[in] stylesheet The path to user defined theme file
201 * @param[in] windowMode A member of WINDOW_MODE
202 * @param[in] positionSize A position and a size of the window
203 * @return A handle to the Application
204 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
206 static Application New(int* argc, char** argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize);
209 * @brief This is the constructor for applications.
214 * @param[in,out] argc A pointer to the number of arguments
215 * @param[in,out] argv A pointer to the argument list
216 * @param[in] stylesheet The path to user defined theme file
217 * @param[in] windowMode A member of WINDOW_MODE
218 * @param[in] positionSize A position and a size of the window
219 * @param[in] useUiThread True if the application would create a UI thread
220 * @return A handle to the Application
221 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.<BR>
222 * UI thread is an additional thread that DALi creates for UI events.
223 * The UI thread isn't blocked from the system events(AppControl, LanguageChanged, RegionChanged, LowMemory, LowBattery task signals).
225 static Application New(int* argc, char** argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize, bool useUiThread);
228 * @brief This is the constructor for applications.
233 * @param[in,out] argc A pointer to the number of arguments
234 * @param[in,out] argv A pointer to the argument list
235 * @param[in] stylesheet The path to user defined theme file
236 * @param[in] useUiThread True if the application would create a UI thread
237 * @param[in] windowData The window data for the application
238 * @return A handle to the Application
239 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.<BR>
240 * UI thread is an additional thread that DALi creates for UI events.
241 * The UI thread isn't blocked from the system events(AppControl, LanguageChanged, RegionChanged, LowMemory, LowBattery task signals).
243 static Application New(int* argc, char** argv[], const std::string& stylesheet, bool useUiThread, WindowData& windowData);
246 * @brief Constructs an empty handle.
252 * @brief Copy Constructor.
254 * @param[in] application Handle to an object
256 Application(const Application& application);
259 * @brief Assignment operator.
261 * @param[in] application Handle to an object
262 * @return A reference to this
264 Application& operator=(const Application& application);
267 * @brief Move constructor.
270 * @param[in] rhs A reference to the moved handle
272 Application(Application&& rhs) noexcept;
275 * @brief Move assignment operator.
278 * @param[in] rhs A reference to the moved handle
279 * @return A reference to this handle
281 Application& operator=(Application&& rhs) noexcept;
286 * This is non-virtual since derived Handle types must not contain data or virtual methods.
293 * @brief This starts the application.
295 * On platforms where context loss can occur, the application is responsible for tearing down and
296 * re-loading UI. The application should listen to Stage::ContextLostSignal and
297 * Stage::ContextRegainedSignal.
304 * @brief This lowers the application to bottom without actually quitting it.
310 * @brief This quits the application. Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
316 * @brief Ensures that the function passed in is called from the main loop when it is idle.
318 * @param[in] callback The function to call
319 * @return @c true if added successfully, @c false otherwise
321 * @note Function must be called from main event thread only
323 * A callback of the following type may be used:
327 * This callback will be deleted once it is called.
329 * @note Ownership of the callback is passed onto this class.
331 bool AddIdle(CallbackBase* callback);
334 * @brief Retrieves the main window used by the Application class.
336 * The application writer can use the window to change indicator and orientation
339 * @return A handle to the window
344 * @brief Get path application resources are stored at
347 * @return the full path of the resources
349 static std::string GetResourcePath();
352 * @brief This is used to get region information from device.
355 * @return Region information
357 std::string GetRegion() const;
360 * @brief This is used to get language information from device.
363 * @return Language information
365 std::string GetLanguage() const;
368 * @brief Gets the Object registry.
371 * @return The object registry
372 * @note This will only be a valid handle after the InitSignal has been emitted.
374 ObjectRegistry GetObjectRegistry() const;
378 * @brief The user should connect to this signal to determine when they should initialize
380 * Only when the user uses the UI thread, this signal is emitted on the UI thread.
381 * Otherwise, it is emitted on the main thread.
383 * @return The signal to connect to
385 AppSignalType& InitSignal();
388 * @brief The user should connect to this signal to determine when they should terminate
390 * Only when the user uses the UI thread, this signal is emitted on the UI thread.
391 * Otherwise, it is emitted on the main thread.
393 * @return The signal to connect to
395 AppSignalType& TerminateSignal();
398 * @brief The user should connect to this signal if they need to perform any special
399 * activities when the application is about to be paused.
400 * Only when the user uses the UI thread, this signal is emitted on the UI thread.
401 * Otherwise, it is emitted on the main thread.
403 * @return The signal to connect to
405 AppSignalType& PauseSignal();
408 * @brief The user should connect to this signal if they need to perform any special
409 * activities when the application has resumed.
410 * Only when the user uses the UI thread, this signal is emitted on the UI thread.
411 * Otherwise, it is emitted on the main thread.
413 * @return The signal to connect to
415 AppSignalType& ResumeSignal();
418 * @brief This signal is sent when the system requires the user to reinitialize itself.
419 * Only when the user uses the UI thread, this signal is emitted on the UI thread.
420 * Otherwise, it is emitted on the main thread.
422 * @return The signal to connect to
424 AppSignalType& ResetSignal();
427 * @brief This signal is emitted when another application sends a launch request to the application.
429 * When the application is launched, this signal is emitted after the main loop of the application starts up.
430 * The passed parameter describes the launch request and contains the information about why the application is launched.
431 * Only when the user uses the UI thread, this signal is emitted on the UI thread.
432 * Otherwise, it is emitted on the main thread.
434 * @return The signal to connect to
436 AppControlSignalType& AppControlSignal();
439 * @brief This signal is emitted when the language is changed on the device.
440 * Only when the user uses the UI thread, this signal is emitted on the UI thread.
441 * Otherwise, it is emitted on the main thread.
443 * @return The signal to connect to
445 AppSignalType& LanguageChangedSignal();
448 * @brief This signal is emitted when the region of the device is changed.
449 * Only when the user uses the UI thread, this signal is emitted on the UI thread.
450 * Otherwise, it is emitted on the main thread.
452 * @return The signal to connect to
454 AppSignalType& RegionChangedSignal();
457 * @brief This signal is emitted when the battery level of the device is low.
458 * Only when the user uses the UI thread, this signal is emitted on the UI thread.
459 * Otherwise, it is emitted on the main thread.
461 * @return The signal to connect to
463 LowBatterySignalType& LowBatterySignal();
466 * @brief This signal is emitted when the memory level of the device is low.
467 * Only when the user uses the UI thread, this signal is emitted on the UI thread.
468 * Otherwise, it is emitted on the main thread.
470 * @return The signal to connect to
472 LowMemorySignalType& LowMemorySignal();
475 * @brief This signal is emitted when the device orientation is changed
476 * Only when the user uses the UI thread, this signal is emitted on the UI thread.
477 * Otherwise, it is emitted on the main thread.
479 * This signal is only used in Application, it is different to Window's orientation signal.
481 * @return The signal to connect to
483 DeviceOrientationChangedSignalType& DeviceOrientationChangedSignal();
487 * @brief The user should connect to this signal to determine when they should initialize
489 * Only when the user uses the UI thread, this signal is emitted on the main thread.
490 * Otherwise, it is not emitted at all.
491 * @return The signal to connect to
493 AppSignalType& TaskInitSignal();
496 * @brief The user should connect to this signal to determine when they should terminate
498 * Only when the user uses the UI thread, this signal is emitted on the main thread.
499 * Otherwise, it is not emitted at all.
500 * @return The signal to connect to
502 AppSignalType& TaskTerminateSignal();
505 * @brief This signal is emitted when another application sends a launch request to the application.
507 * When the application is launched, this signal is emitted after the main loop of the application starts up.
508 * The passed parameter describes the launch request and contains the information about why the application is launched.
509 * Only when the user uses the UI thread, this signal is emitted on the main thread.
510 * Otherwise, it is not emitted at all.
511 * @return The signal to connect to
513 AppControlSignalType& TaskAppControlSignal();
516 * @brief This signal is emitted when the language is changed on the device.
517 * Only when the user uses the UI thread, this signal is emitted on the main thread.
518 * Otherwise, it is not emitted at all.
519 * @return The signal to connect to
521 AppSignalType& TaskLanguageChangedSignal();
524 * @brief This signal is emitted when the region of the device is changed.
525 * Only when the user uses the UI thread, this signal is emitted on the main thread.
526 * Otherwise, it is not emitted at all.
527 * @return The signal to connect to
529 AppSignalType& TaskRegionChangedSignal();
532 * @brief This signal is emitted when the battery level of the device is low.
533 * Only when the user uses the UI thread, this signal is emitted on the main thread.
534 * Otherwise, it is not emitted at all.
535 * @return The signal to connect to
537 LowBatterySignalType& TaskLowBatterySignal();
540 * @brief This signal is emitted when the memory level of the device is low.
541 * Only when the user uses the UI thread, this signal is emitted on the main thread.
542 * Otherwise, it is not emitted at all.
543 * @return The signal to connect to
545 LowMemorySignalType& TaskLowMemorySignal();
548 * @brief This signal is emitted when the device orientation is changed.
549 * Only when the user uses the UI thread, this signal is emitted on the main thread.
550 * Otherwise, it is not emitted at all.
552 * @return The signal to connect to
554 DeviceOrientationChangedSignalType& TaskDeviceOrientationChangedSignal();
556 public: // Not intended for application developers
559 * @brief Internal constructor.
562 explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
571 #endif // DALI_APPLICATION_H