Add move semantics to BaseHandle derived classes in Adaptor public API
[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 Move constructor.
217    *
218    * @SINCE_1_9.24
219    * @param[in] rhs A reference to the moved handle
220    */
221   Application( Application&& rhs );
222
223   /**
224    * @brief Move assignment operator.
225    *
226    * @SINCE_1_9.24
227    * @param[in] rhs A reference to the moved handle
228    * @return A reference to this handle
229    */
230   Application& operator=( Application&& rhs );
231
232   /**
233    * @brief Destructor.
234    *
235    * This is non-virtual since derived Handle types must not contain data or virtual methods.
236    * @SINCE_1_0.0
237    */
238   ~Application();
239
240 public:
241   /**
242    * @brief This starts the application.
243    *
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.
248    * @SINCE_1_0.0
249    */
250   void MainLoop();
251
252   /**
253    * @brief This starts the application, and allows the app to choose a different configuration.
254    *
255    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
256    * @SINCE_1_0.0
257    * @param[in] configuration The context loss configuration
258    */
259   void MainLoop(Configuration::ContextLoss configuration);
260
261   /**
262    * @brief This lowers the application to bottom without actually quitting it.
263    * @SINCE_1_0.0
264    */
265   void Lower();
266
267   /**
268    * @brief This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
269    * @SINCE_1_0.0
270    */
271   void Quit();
272
273   /**
274    * @brief Ensures that the function passed in is called from the main loop when it is idle.
275    * @SINCE_1_0.0
276    * @param[in] callback The function to call
277    * @return @c true if added successfully, @c false otherwise
278    *
279    * @note Function must be called from main event thread only
280    *
281    * A callback of the following type may be used:
282    * @code
283    *   void MyFunction();
284    * @endcode
285    * This callback will be deleted once it is called.
286    *
287    * @note Ownership of the callback is passed onto this class.
288    */
289   bool AddIdle( CallbackBase* callback );
290
291   /**
292    * @brief Retrieves the main window used by the Application class.
293    *
294    * The application writer can use the window to change indicator and orientation
295    * properties.
296    * @SINCE_1_0.0
297    * @return A handle to the window
298    */
299   Window GetWindow();
300
301   /**
302    * @brief Get path application resources are stored at
303    *
304    * @SINCE_1_2.2
305    * @return the full path of the resources
306    */
307   static std::string GetResourcePath();
308
309   /**
310    * @brief This is used to get region information from device.
311    *
312    * @SINCE_1_2.62
313    * @return Region information
314    */
315   std::string GetRegion() const;
316
317   /**
318    * @brief This is used to get language information from device.
319    *
320    * @SINCE_1_2.62
321    * @return Language information
322    */
323   std::string GetLanguage() const;
324
325   /**
326    * @brief Gets the Object registry.
327    *
328    * @SINCE_1_9.21
329    * @return The object registry
330    * @note This will only be a valid handle after the InitSignal has been emitted.
331    */
332   ObjectRegistry GetObjectRegistry() const;
333
334 public:  // Signals
335
336   /**
337    * @brief The user should connect to this signal to determine when they should initialize
338    * their application.
339    * @SINCE_1_0.0
340    * @return The signal to connect to
341    */
342   AppSignalType& InitSignal();
343
344   /**
345    * @brief The user should connect to this signal to determine when they should terminate
346    * their application.
347    * @SINCE_1_0.0
348    * @return The signal to connect to
349    */
350   AppSignalType& TerminateSignal();
351
352   /**
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.
355    * @SINCE_1_0.0
356    * @return The signal to connect to
357    */
358   AppSignalType& PauseSignal();
359
360   /**
361    * @brief The user should connect to this signal if they need to perform any special
362    * activities when the application has resumed.
363    * @SINCE_1_0.0
364    * @return The signal to connect to
365    */
366   AppSignalType& ResumeSignal();
367
368   /**
369    * @brief This signal is sent when the system requires the user to reinitialize itself.
370    * @SINCE_1_0.0
371    * @return The signal to connect to
372    */
373   AppSignalType& ResetSignal();
374
375   /**
376   * @brief This signal is emitted when another application sends a launch request to the application.
377   *
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.
380   * @SINCE_1_0.0
381   * @return The signal to connect to
382   */
383   AppControlSignalType& AppControlSignal();
384
385   /**
386    * @brief This signal is emitted when the language is changed on the device.
387    * @SINCE_1_0.0
388    * @return The signal to connect to
389    */
390   AppSignalType& LanguageChangedSignal();
391
392   /**
393   * @brief This signal is emitted when the region of the device is changed.
394   * @SINCE_1_0.0
395   * @return The signal to connect to
396   */
397   AppSignalType& RegionChangedSignal();
398
399   /**
400    * @brief This signal is emitted when the battery level of the device is low.
401    * @SINCE_1_2.62
402    * @return The signal to connect to
403    */
404   LowBatterySignalType& LowBatterySignal();
405
406   /**
407    * @brief This signal is emitted when the memory level of the device is low.
408    * @SINCE_1_2.62
409    * @return The signal to connect to
410    */
411   LowMemorySignalType& LowMemorySignal();
412
413 public: // Not intended for application developers
414   /// @cond internal
415   /**
416    * @brief Internal constructor.
417    * @SINCE_1_0.0
418    */
419   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
420   /// @endcond
421 };
422
423 /**
424  * @}
425  */
426 } // namespace Dali
427
428 #endif // DALI_APPLICATION_H