1 #ifndef DALI_APPLICATION_H
2 #define DALI_APPLICATION_H
5 * Copyright (c) 2020 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/application-configuration.h>
27 #include <dali/public-api/adaptor-framework/device-status.h>
28 #include <dali/public-api/adaptor-framework/window.h>
36 * @addtogroup dali_adaptor_framework
40 namespace Internal DALI_INTERNAL
48 * @brief An Application class object should be created by every application
49 * that wishes to use Dali.
51 * It provides a means for initializing the
52 * resources required by the Dali::Core.
54 * The Application class emits several signals which the user can
55 * connect to. The user should not create any Dali objects in the main
56 * function and instead should connect to the Init signal of the
57 * Application and create the Dali objects in the connected callback.
59 * Applications should follow the example below:
62 * class ExampleController: public ConnectionTracker
65 * ExampleController( Application& application )
66 * : mApplication( application )
68 * mApplication.InitSignal().Connect( this, &ExampleController::Create );
71 * void Create( Application& application )
73 * // Create Dali components...
77 * Application& mApplication;
80 * int main (int argc, char **argv)
82 * Application app = Application::New(&argc, &argv);
83 * ExampleController example( app );
88 * If required, you can also connect class member functions to a signal:
92 * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
95 * This class accepts command line arguments as well. The following options are supported:
98 * -w|--width Stage Width
99 * -h|--height Stage Height
100 * -d|--dpi Emulated DPI
104 * When the above options are found, they are stripped from argv, and argc is updated appropriately.
107 class DALI_ADAPTOR_API Application : public BaseHandle
111 typedef Signal< void (DeviceStatus::Battery::Status) > LowBatterySignalType; ///< Application device signal type @SINCE_1_2.62
112 typedef Signal< void (DeviceStatus::Memory::Status) > LowMemorySignalType; ///< Application device signal type @SINCE_1_2.62
113 typedef Signal< void (Application&) > AppSignalType; ///< Application lifecycle signal and system signal callback type @SINCE_1_0.0
114 typedef Signal< void (Application&, void *) > AppControlSignalType; ///< Application control signal callback type @SINCE_1_0.0
117 * @brief Enumeration for deciding whether a Dali application window is opaque or transparent.
122 OPAQUE = 0, ///< The window will be opaque @SINCE_1_0.0
123 TRANSPARENT = 1 ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor() @SINCE_1_0.0
129 * @brief This is the constructor for applications without an argument list.
133 * @return A handle to the Application
135 static Application New();
138 * @brief This is the constructor for applications.
143 * @param[in,out] argc A pointer to the number of arguments
144 * @param[in,out] argv A pointer to the argument list
145 * @return A handle to the Application
147 static Application New( int* argc, char **argv[] );
150 * @brief This is the constructor for applications with a name.
155 * @param[in,out] argc A pointer to the number of arguments
156 * @param[in,out] argv A pointer to the argument list
157 * @param[in] stylesheet The path to user defined theme file
158 * @return A handle to the Application
159 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
161 static Application New( int* argc, char **argv[], const std::string& stylesheet );
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 * @param[in] windowMode A member of WINDOW_MODE
173 * @return A handle to the Application
174 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
176 static Application New( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode );
179 * @brief This is the constructor for applications.
184 * @param[in,out] argc A pointer to the number of arguments
185 * @param[in,out] argv A pointer to the argument list
186 * @param[in] stylesheet The path to user defined theme file
187 * @param[in] windowMode A member of WINDOW_MODE
188 * @param[in] positionSize A position and a size of the window
189 * @return A handle to the Application
190 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
192 static Application New( int* argc, char **argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize );
195 * @brief Constructs an empty handle.
201 * @brief Copy Constructor.
203 * @param[in] application Handle to an object
205 Application( const Application& application );
208 * @brief Assignment operator.
210 * @param[in] application Handle to an object
211 * @return A reference to this
213 Application& operator=( const Application& application );
216 * @brief Move constructor.
219 * @param[in] rhs A reference to the moved handle
221 Application( Application&& rhs );
224 * @brief Move assignment operator.
227 * @param[in] rhs A reference to the moved handle
228 * @return A reference to this handle
230 Application& operator=( Application&& rhs );
235 * This is non-virtual since derived Handle types must not contain data or virtual methods.
242 * @brief This starts the application.
244 * Choosing this form of main loop indicates that the default
245 * application configuration of APPLICATION_HANDLES_CONTEXT_LOSS is used. On platforms where
246 * context loss can occur, the application is responsible for tearing down and re-loading UI.
247 * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
253 * @brief This starts the application, and allows the app to choose a different configuration.
255 * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
257 * @param[in] configuration The context loss configuration
259 void MainLoop(Configuration::ContextLoss configuration);
262 * @brief This lowers the application to bottom without actually quitting it.
268 * @brief This quits the application. Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
274 * @brief Ensures that the function passed in is called from the main loop when it is idle.
276 * @param[in] callback The function to call
277 * @return @c true if added successfully, @c false otherwise
279 * @note Function must be called from main event thread only
281 * A callback of the following type may be used:
285 * This callback will be deleted once it is called.
287 * @note Ownership of the callback is passed onto this class.
289 bool AddIdle( CallbackBase* callback );
292 * @brief Retrieves the main window used by the Application class.
294 * The application writer can use the window to change indicator and orientation
297 * @return A handle to the window
302 * @brief Get path application resources are stored at
305 * @return the full path of the resources
307 static std::string GetResourcePath();
310 * @brief This is used to get region information from device.
313 * @return Region information
315 std::string GetRegion() const;
318 * @brief This is used to get language information from device.
321 * @return Language information
323 std::string GetLanguage() const;
326 * @brief Gets the Object registry.
329 * @return The object registry
330 * @note This will only be a valid handle after the InitSignal has been emitted.
332 ObjectRegistry GetObjectRegistry() const;
337 * @brief The user should connect to this signal to determine when they should initialize
340 * @return The signal to connect to
342 AppSignalType& InitSignal();
345 * @brief The user should connect to this signal to determine when they should terminate
348 * @return The signal to connect to
350 AppSignalType& TerminateSignal();
353 * @brief The user should connect to this signal if they need to perform any special
354 * activities when the application is about to be paused.
356 * @return The signal to connect to
358 AppSignalType& PauseSignal();
361 * @brief The user should connect to this signal if they need to perform any special
362 * activities when the application has resumed.
364 * @return The signal to connect to
366 AppSignalType& ResumeSignal();
369 * @brief This signal is sent when the system requires the user to reinitialize itself.
371 * @return The signal to connect to
373 AppSignalType& ResetSignal();
376 * @brief This signal is emitted when another application sends a launch request to the application.
378 * When the application is launched, this signal is emitted after the main loop of the application starts up.
379 * The passed parameter describes the launch request and contains the information about why the application is launched.
381 * @return The signal to connect to
383 AppControlSignalType& AppControlSignal();
386 * @brief This signal is emitted when the language is changed on the device.
388 * @return The signal to connect to
390 AppSignalType& LanguageChangedSignal();
393 * @brief This signal is emitted when the region of the device is changed.
395 * @return The signal to connect to
397 AppSignalType& RegionChangedSignal();
400 * @brief This signal is emitted when the battery level of the device is low.
402 * @return The signal to connect to
404 LowBatterySignalType& LowBatterySignal();
407 * @brief This signal is emitted when the memory level of the device is low.
409 * @return The signal to connect to
411 LowMemorySignalType& LowMemorySignal();
413 public: // Not intended for application developers
416 * @brief Internal constructor.
419 explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
428 #endif // DALI_APPLICATION_H