1b349b1b7316a61d4afbd9c656ff9c97f5775f65
[platform/core/uifw/dali-adaptor.git] / dali / public-api / adaptor-framework / application.h
1 #ifndef DALI_APPLICATION_H
2 #define DALI_APPLICATION_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
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>
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/adaptor-framework/device-status.h>
28 #include <dali/public-api/adaptor-framework/window.h>
29
30 namespace Dali
31 {
32 class ObjectRegistry;
33
34 /**
35  * @addtogroup dali_adaptor_framework
36  * @{
37  */
38
39 namespace Internal DALI_INTERNAL
40 {
41 namespace Adaptor
42 {
43 class Application;
44 }
45 } // namespace DALI_INTERNAL
46 /**
47  * @brief An Application class object should be created by every application
48  * that wishes to use Dali.
49  *
50  * It provides a means for initializing the
51  * resources required by the Dali::Core.
52  *
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.
57  *
58  * Applications should follow the example below:
59  *
60  * @code
61  * class ExampleController: public ConnectionTracker
62  * {
63  * public:
64  *   ExampleController( Application& application )
65  *   : mApplication( application )
66  *   {
67  *     mApplication.InitSignal().Connect( this, &ExampleController::Create );
68  *   }
69  *
70  *   void Create( Application& application )
71  *   {
72  *     // Create Dali components...
73  *   }
74  *  ...
75  * private:
76  *   Application& mApplication;
77  * };
78  *
79  * int main (int argc, char **argv)
80  * {
81  *   Application app = Application::New(&argc, &argv);
82  *   ExampleController example( app );
83  *   app.MainLoop();
84  * }
85  * @endcode
86  *
87  * If required, you can also connect class member functions to a signal:
88  *
89  * @code
90  * MyApplication app;
91  * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
92  * @endcode
93  *
94  * This class accepts command line arguments as well. The following options are supported:
95  *
96  * @code
97  *  -w|--width          Stage Width
98  *  -h|--height         Stage Height
99  *  -d|--dpi            Emulated DPI
100  *     --help           Help
101  * @endcode
102  *
103  * When the above options are found, they are stripped from argv, and argc is updated appropriately.
104  * @SINCE_1_0.0
105  */
106 class DALI_ADAPTOR_API Application : public BaseHandle
107 {
108 public:
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
113
114   /**
115    * @brief Enumeration for deciding whether a Dali application window is opaque or transparent.
116    * @SINCE_1_0.0
117    */
118   enum WINDOW_MODE
119   {
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
122   };
123
124 public:
125   /**
126    * @brief This is the constructor for applications without an argument list.
127    * @SINCE_1_0.0
128    * @PRIVLEVEL_PUBLIC
129    * @PRIVILEGE_DISPLAY
130    * @return A handle to the Application
131    */
132   static Application New();
133
134   /**
135    * @brief This is the constructor for applications.
136    *
137    * @SINCE_1_0.0
138    * @PRIVLEVEL_PUBLIC
139    * @PRIVILEGE_DISPLAY
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
143    */
144   static Application New(int* argc, char** argv[]);
145
146   /**
147    * @brief This is the constructor for applications with a name.
148    *
149    * @SINCE_1_0.0
150    * @PRIVLEVEL_PUBLIC
151    * @PRIVILEGE_DISPLAY
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.
157    */
158   static Application New(int* argc, char** argv[], const std::string& stylesheet);
159
160   /**
161    * @brief This is the constructor for applications with a name.
162    *
163    * @SINCE_1_0.0
164    * @PRIVLEVEL_PUBLIC
165    * @PRIVILEGE_DISPLAY
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.
172    */
173   static Application New(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode);
174
175   /**
176    * @brief This is the constructor for applications.
177    *
178    * @SINCE_1_2.60
179    * @PRIVLEVEL_PUBLIC
180    * @PRIVILEGE_DISPLAY
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.
188    */
189   static Application New(int* argc, char** argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize);
190
191   /**
192    * @brief Constructs an empty handle.
193    * @SINCE_1_0.0
194    */
195   Application();
196
197   /**
198    * @brief Copy Constructor.
199    * @SINCE_1_0.0
200    * @param[in] application Handle to an object
201    */
202   Application(const Application& application);
203
204   /**
205    * @brief Assignment operator.
206    * @SINCE_1_0.0
207    * @param[in] application Handle to an object
208    * @return A reference to this
209    */
210   Application& operator=(const Application& application);
211
212   /**
213    * @brief Move constructor.
214    *
215    * @SINCE_1_9.24
216    * @param[in] rhs A reference to the moved handle
217    */
218   Application(Application&& rhs);
219
220   /**
221    * @brief Move assignment operator.
222    *
223    * @SINCE_1_9.24
224    * @param[in] rhs A reference to the moved handle
225    * @return A reference to this handle
226    */
227   Application& operator=(Application&& rhs);
228
229   /**
230    * @brief Destructor.
231    *
232    * This is non-virtual since derived Handle types must not contain data or virtual methods.
233    * @SINCE_1_0.0
234    */
235   ~Application();
236
237 public:
238   /**
239    * @brief This starts the application.
240    *
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.
244    *
245    * @SINCE_1_0.0
246    */
247   void MainLoop();
248
249   /**
250    * @brief This lowers the application to bottom without actually quitting it.
251    * @SINCE_1_0.0
252    */
253   void Lower();
254
255   /**
256    * @brief This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
257    * @SINCE_1_0.0
258    */
259   void Quit();
260
261   /**
262    * @brief Ensures that the function passed in is called from the main loop when it is idle.
263    * @SINCE_1_0.0
264    * @param[in] callback The function to call
265    * @return @c true if added successfully, @c false otherwise
266    *
267    * @note Function must be called from main event thread only
268    *
269    * A callback of the following type may be used:
270    * @code
271    *   void MyFunction();
272    * @endcode
273    * This callback will be deleted once it is called.
274    *
275    * @note Ownership of the callback is passed onto this class.
276    */
277   bool AddIdle(CallbackBase* callback);
278
279   /**
280    * @brief Retrieves the main window used by the Application class.
281    *
282    * The application writer can use the window to change indicator and orientation
283    * properties.
284    * @SINCE_1_0.0
285    * @return A handle to the window
286    */
287   Window GetWindow();
288
289   /**
290    * @brief Get path application resources are stored at
291    *
292    * @SINCE_1_2.2
293    * @return the full path of the resources
294    */
295   static std::string GetResourcePath();
296
297   /**
298    * @brief This is used to get region information from device.
299    *
300    * @SINCE_1_2.62
301    * @return Region information
302    */
303   std::string GetRegion() const;
304
305   /**
306    * @brief This is used to get language information from device.
307    *
308    * @SINCE_1_2.62
309    * @return Language information
310    */
311   std::string GetLanguage() const;
312
313   /**
314    * @brief Gets the Object registry.
315    *
316    * @SINCE_1_9.21
317    * @return The object registry
318    * @note This will only be a valid handle after the InitSignal has been emitted.
319    */
320   ObjectRegistry GetObjectRegistry() const;
321
322 public: // Signals
323   /**
324    * @brief The user should connect to this signal to determine when they should initialize
325    * their application.
326    * @SINCE_1_0.0
327    * @return The signal to connect to
328    */
329   AppSignalType& InitSignal();
330
331   /**
332    * @brief The user should connect to this signal to determine when they should terminate
333    * their application.
334    * @SINCE_1_0.0
335    * @return The signal to connect to
336    */
337   AppSignalType& TerminateSignal();
338
339   /**
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.
342    * @SINCE_1_0.0
343    * @return The signal to connect to
344    */
345   AppSignalType& PauseSignal();
346
347   /**
348    * @brief The user should connect to this signal if they need to perform any special
349    * activities when the application has resumed.
350    * @SINCE_1_0.0
351    * @return The signal to connect to
352    */
353   AppSignalType& ResumeSignal();
354
355   /**
356    * @brief This signal is sent when the system requires the user to reinitialize itself.
357    * @SINCE_1_0.0
358    * @return The signal to connect to
359    */
360   AppSignalType& ResetSignal();
361
362   /**
363   * @brief This signal is emitted when another application sends a launch request to the application.
364   *
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.
367   * @SINCE_1_0.0
368   * @return The signal to connect to
369   */
370   AppControlSignalType& AppControlSignal();
371
372   /**
373    * @brief This signal is emitted when the language is changed on the device.
374    * @SINCE_1_0.0
375    * @return The signal to connect to
376    */
377   AppSignalType& LanguageChangedSignal();
378
379   /**
380   * @brief This signal is emitted when the region of the device is changed.
381   * @SINCE_1_0.0
382   * @return The signal to connect to
383   */
384   AppSignalType& RegionChangedSignal();
385
386   /**
387    * @brief This signal is emitted when the battery level of the device is low.
388    * @SINCE_1_2.62
389    * @return The signal to connect to
390    */
391   LowBatterySignalType& LowBatterySignal();
392
393   /**
394    * @brief This signal is emitted when the memory level of the device is low.
395    * @SINCE_1_2.62
396    * @return The signal to connect to
397    */
398   LowMemorySignalType& LowMemorySignal();
399
400   // TEMPORARY TO TEST GFXAPI
401   Graphics::Controller& GetController();
402
403 public: // Not intended for application developers
404   /// @cond internal
405   /**
406    * @brief Internal constructor.
407    * @SINCE_1_0.0
408    */
409   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
410   /// @endcond
411 };
412
413 /**
414  * @}
415  */
416 } // namespace Dali
417
418 #endif // DALI_APPLICATION_H