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