1 #ifndef DALI_APPLICATION_H
2 #define DALI_APPLICATION_H
5 * Copyright (c) 2021 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/graphics-api/graphics-controller.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/signals/callback.h>
27 #include <dali/public-api/adaptor-framework/device-status.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);
94 * This class accepts command line arguments as well. The following options are supported:
97 * -w|--width Stage Width
98 * -h|--height Stage Height
99 * -d|--dpi Emulated DPI
103 * When the above options are found, they are stripped from argv, and argc is updated appropriately.
106 class DALI_ADAPTOR_API Application : public BaseHandle
109 typedef Signal<void(DeviceStatus::Battery::Status)> LowBatterySignalType; ///< Application device signal type @SINCE_1_2.62
110 typedef Signal<void(DeviceStatus::Memory::Status)> LowMemorySignalType; ///< Application device signal type @SINCE_1_2.62
111 typedef Signal<void(Application&)> AppSignalType; ///< Application lifecycle signal and system signal callback type @SINCE_1_0.0
112 typedef Signal<void(Application&, void*)> AppControlSignalType; ///< Application control signal callback type @SINCE_1_0.0
115 * @brief Enumeration for deciding whether a Dali application window is opaque or transparent.
120 OPAQUE = 0, ///< The window will be opaque @SINCE_1_0.0
121 TRANSPARENT = 1 ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor() @SINCE_1_0.0
126 * @brief This is the constructor for applications without an argument list.
130 * @return A handle to the Application
132 static Application New();
135 * @brief This is the constructor for applications.
140 * @param[in,out] argc A pointer to the number of arguments
141 * @param[in,out] argv A pointer to the argument list
142 * @return A handle to the Application
144 static Application New(int* argc, char** argv[]);
147 * @brief This is the constructor for applications with a name.
152 * @param[in,out] argc A pointer to the number of arguments
153 * @param[in,out] argv A pointer to the argument list
154 * @param[in] stylesheet The path to user defined theme file
155 * @return A handle to the Application
156 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
158 static Application New(int* argc, char** argv[], const std::string& stylesheet);
161 * @brief This is the constructor for applications with a name.
166 * @param[in,out] argc A pointer to the number of arguments
167 * @param[in,out] argv A pointer to the argument list
168 * @param[in] stylesheet The path to user defined theme file
169 * @param[in] windowMode A member of WINDOW_MODE
170 * @return A handle to the Application
171 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
173 static Application New(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode);
176 * @brief This is the constructor for applications.
181 * @param[in,out] argc A pointer to the number of arguments
182 * @param[in,out] argv A pointer to the argument list
183 * @param[in] stylesheet The path to user defined theme file
184 * @param[in] windowMode A member of WINDOW_MODE
185 * @param[in] positionSize A position and a size of the window
186 * @return A handle to the Application
187 * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.
189 static Application New(int* argc, char** argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize);
192 * @brief Constructs an empty handle.
198 * @brief Copy Constructor.
200 * @param[in] application Handle to an object
202 Application(const Application& application);
205 * @brief Assignment operator.
207 * @param[in] application Handle to an object
208 * @return A reference to this
210 Application& operator=(const Application& application);
213 * @brief Move constructor.
216 * @param[in] rhs A reference to the moved handle
218 Application(Application&& rhs);
221 * @brief Move assignment operator.
224 * @param[in] rhs A reference to the moved handle
225 * @return A reference to this handle
227 Application& operator=(Application&& rhs);
232 * This is non-virtual since derived Handle types must not contain data or virtual methods.
239 * @brief This starts the application.
241 * On platforms where context loss can occur, the application is responsible for tearing down and
242 * re-loading UI. The application should listen to Stage::ContextLostSignal and
243 * Stage::ContextRegainedSignal.
250 * @brief This lowers the application to bottom without actually quitting it.
256 * @brief This quits the application. Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
262 * @brief Ensures that the function passed in is called from the main loop when it is idle.
264 * @param[in] callback The function to call
265 * @return @c true if added successfully, @c false otherwise
267 * @note Function must be called from main event thread only
269 * A callback of the following type may be used:
273 * This callback will be deleted once it is called.
275 * @note Ownership of the callback is passed onto this class.
277 bool AddIdle(CallbackBase* callback);
280 * @brief Retrieves the main window used by the Application class.
282 * The application writer can use the window to change indicator and orientation
285 * @return A handle to the window
290 * @brief Get path application resources are stored at
293 * @return the full path of the resources
295 static std::string GetResourcePath();
298 * @brief This is used to get region information from device.
301 * @return Region information
303 std::string GetRegion() const;
306 * @brief This is used to get language information from device.
309 * @return Language information
311 std::string GetLanguage() const;
314 * @brief Gets the Object registry.
317 * @return The object registry
318 * @note This will only be a valid handle after the InitSignal has been emitted.
320 ObjectRegistry GetObjectRegistry() const;
324 * @brief The user should connect to this signal to determine when they should initialize
327 * @return The signal to connect to
329 AppSignalType& InitSignal();
332 * @brief The user should connect to this signal to determine when they should terminate
335 * @return The signal to connect to
337 AppSignalType& TerminateSignal();
340 * @brief The user should connect to this signal if they need to perform any special
341 * activities when the application is about to be paused.
343 * @return The signal to connect to
345 AppSignalType& PauseSignal();
348 * @brief The user should connect to this signal if they need to perform any special
349 * activities when the application has resumed.
351 * @return The signal to connect to
353 AppSignalType& ResumeSignal();
356 * @brief This signal is sent when the system requires the user to reinitialize itself.
358 * @return The signal to connect to
360 AppSignalType& ResetSignal();
363 * @brief This signal is emitted when another application sends a launch request to the application.
365 * When the application is launched, this signal is emitted after the main loop of the application starts up.
366 * The passed parameter describes the launch request and contains the information about why the application is launched.
368 * @return The signal to connect to
370 AppControlSignalType& AppControlSignal();
373 * @brief This signal is emitted when the language is changed on the device.
375 * @return The signal to connect to
377 AppSignalType& LanguageChangedSignal();
380 * @brief This signal is emitted when the region of the device is changed.
382 * @return The signal to connect to
384 AppSignalType& RegionChangedSignal();
387 * @brief This signal is emitted when the battery level of the device is low.
389 * @return The signal to connect to
391 LowBatterySignalType& LowBatterySignal();
394 * @brief This signal is emitted when the memory level of the device is low.
396 * @return The signal to connect to
398 LowMemorySignalType& LowMemorySignal();
400 // TEMPORARY TO TEST GFXAPI
401 Graphics::Controller& GetController();
403 public: // Not intended for application developers
406 * @brief Internal constructor.
409 explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
418 #endif // DALI_APPLICATION_H