1 #ifndef DALI_APPLICATION_H
2 #define DALI_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/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.h>
34 * @addtogroup dali_adaptor_framework
38 namespace Internal DALI_INTERNAL
44 } // namespace DALI_INTERNAL
46 * @brief An Application class object should be created by every application
47 * that wishes to use Dali.
49 * It provides a means for initializing the
50 * resources required by the Dali::Core.
52 * The Application class emits several signals which the user can
53 * connect to. The user should not create any Dali objects in the main
54 * function and instead should connect to the Init signal of the
55 * Application and create the Dali objects in the connected callback.
57 * Applications should follow the example below:
60 * class ExampleController: public ConnectionTracker
63 * ExampleController( Application& application )
64 * : mApplication( application )
66 * mApplication.InitSignal().Connect( this, &ExampleController::Create );
69 * void Create( Application& application )
71 * // Create Dali components...
75 * Application& mApplication;
78 * int main (int argc, char **argv)
80 * Application app = Application::New(&argc, &argv);
81 * ExampleController example( app );
86 * If required, you can also connect class member functions to a signal:
90 * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
93 * This class accepts command line arguments as well. The following options are supported:
96 * -w|--width Stage Width
97 * -h|--height Stage Height
98 * -d|--dpi Emulated DPI
102 * When the above options are found, they are stripped from argv, and argc is updated appropriately.
105 class DALI_ADAPTOR_API Application : public BaseHandle
108 typedef Signal<void(DeviceStatus::Battery::Status)> LowBatterySignalType; ///< Application device signal type @SINCE_1_2.62
109 typedef Signal<void(DeviceStatus::Memory::Status)> LowMemorySignalType; ///< Application device signal type @SINCE_1_2.62
110 typedef Signal<void(Application&)> AppSignalType; ///< Application lifecycle signal and system signal callback type @SINCE_1_0.0
111 typedef Signal<void(Application&, void*)> AppControlSignalType; ///< Application control signal callback type @SINCE_1_0.0
114 * @brief Enumeration for deciding whether a Dali application window is opaque or transparent.
119 OPAQUE = 0, ///< The window will be opaque @SINCE_1_0.0
120 TRANSPARENT = 1 ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor() @SINCE_1_0.0
125 * @brief This is the constructor for applications without an argument list.
129 * @return A handle to the Application
131 static Application New();
134 * @brief This is the constructor for applications.
139 * @param[in,out] argc A pointer to the number of arguments
140 * @param[in,out] argv A pointer to the argument list
141 * @return A handle to the Application
143 static Application New(int* argc, char** argv[]);
146 * @brief This is the constructor for applications with a name.
151 * @param[in,out] argc A pointer to the number of arguments
152 * @param[in,out] argv A pointer to the argument list
153 * @param[in] stylesheet The path to user defined theme file
154 * @return A handle to the Application
155 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
157 static Application New(int* argc, char** argv[], const std::string& stylesheet);
160 * @brief This is the constructor for applications with a name.
165 * @param[in,out] argc A pointer to the number of arguments
166 * @param[in,out] argv A pointer to the argument list
167 * @param[in] stylesheet The path to user defined theme file
168 * @param[in] windowMode A member of WINDOW_MODE
169 * @return A handle to the Application
170 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
172 static Application New(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode);
175 * @brief This is the constructor for applications.
180 * @param[in,out] argc A pointer to the number of arguments
181 * @param[in,out] argv A pointer to the argument list
182 * @param[in] stylesheet The path to user defined theme file
183 * @param[in] windowMode A member of WINDOW_MODE
184 * @param[in] positionSize A position and a size of the window
185 * @return A handle to the Application
186 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
188 static Application New(int* argc, char** argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize);
191 * @brief Constructs an empty handle.
197 * @brief Copy Constructor.
199 * @param[in] application Handle to an object
201 Application(const Application& application);
204 * @brief Assignment operator.
206 * @param[in] application Handle to an object
207 * @return A reference to this
209 Application& operator=(const Application& application);
212 * @brief Move constructor.
215 * @param[in] rhs A reference to the moved handle
217 Application(Application&& rhs);
220 * @brief Move assignment operator.
223 * @param[in] rhs A reference to the moved handle
224 * @return A reference to this handle
226 Application& operator=(Application&& rhs);
231 * This is non-virtual since derived Handle types must not contain data or virtual methods.
238 * @brief This starts the application.
240 * On platforms where context loss can occur, the application is responsible for tearing down and
241 * re-loading UI. The application should listen to Stage::ContextLostSignal and
242 * Stage::ContextRegainedSignal.
249 * @brief This lowers the application to bottom without actually quitting it.
255 * @brief This quits the application. Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
261 * @brief Ensures that the function passed in is called from the main loop when it is idle.
263 * @param[in] callback The function to call
264 * @return @c true if added successfully, @c false otherwise
266 * @note Function must be called from main event thread only
268 * A callback of the following type may be used:
272 * This callback will be deleted once it is called.
274 * @note Ownership of the callback is passed onto this class.
276 bool AddIdle(CallbackBase* callback);
279 * @brief Retrieves the main window used by the Application class.
281 * The application writer can use the window to change indicator and orientation
284 * @return A handle to the window
289 * @brief Get path application resources are stored at
292 * @return the full path of the resources
294 static std::string GetResourcePath();
297 * @brief This is used to get region information from device.
300 * @return Region information
302 std::string GetRegion() const;
305 * @brief This is used to get language information from device.
308 * @return Language information
310 std::string GetLanguage() const;
313 * @brief Gets the Object registry.
316 * @return The object registry
317 * @note This will only be a valid handle after the InitSignal has been emitted.
319 ObjectRegistry GetObjectRegistry() const;
323 * @brief The user should connect to this signal to determine when they should initialize
326 * @return The signal to connect to
328 AppSignalType& InitSignal();
331 * @brief The user should connect to this signal to determine when they should terminate
334 * @return The signal to connect to
336 AppSignalType& TerminateSignal();
339 * @brief The user should connect to this signal if they need to perform any special
340 * activities when the application is about to be paused.
342 * @return The signal to connect to
344 AppSignalType& PauseSignal();
347 * @brief The user should connect to this signal if they need to perform any special
348 * activities when the application has resumed.
350 * @return The signal to connect to
352 AppSignalType& ResumeSignal();
355 * @brief This signal is sent when the system requires the user to reinitialize itself.
357 * @return The signal to connect to
359 AppSignalType& ResetSignal();
362 * @brief This signal is emitted when another application sends a launch request to the application.
364 * When the application is launched, this signal is emitted after the main loop of the application starts up.
365 * The passed parameter describes the launch request and contains the information about why the application is launched.
367 * @return The signal to connect to
369 AppControlSignalType& AppControlSignal();
372 * @brief This signal is emitted when the language is changed on the device.
374 * @return The signal to connect to
376 AppSignalType& LanguageChangedSignal();
379 * @brief This signal is emitted when the region of the device is changed.
381 * @return The signal to connect to
383 AppSignalType& RegionChangedSignal();
386 * @brief This signal is emitted when the battery level of the device is low.
388 * @return The signal to connect to
390 LowBatterySignalType& LowBatterySignal();
393 * @brief This signal is emitted when the memory level of the device is low.
395 * @return The signal to connect to
397 LowMemorySignalType& LowMemorySignal();
399 public: // Not intended for application developers
402 * @brief Internal constructor.
405 explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
414 #endif // DALI_APPLICATION_H