Merge "Fixed JSON output for Stagehand" into devel/master
[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) 2018 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 <string>
23 #include <dali/public-api/common/view-mode.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/signals/callback.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/public-api/adaptor-framework/application-configuration.h>
29 #include <dali/public-api/adaptor-framework/device-status.h>
30 #include <dali/public-api/adaptor-framework/window.h>
31
32 namespace Dali
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 }
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  *     --no-vsync       Disable VSync on Render
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    * If the application plans on using the ReplaceSurface or ReplaceWindow API, then this will
239    * trigger context loss & regain.
240    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
241    * @SINCE_1_0.0
242    * @param[in] configuration The context loss configuration
243    */
244   void MainLoop(Configuration::ContextLoss configuration);
245
246   /**
247    * @brief This lowers the application to bottom without actually quitting it.
248    * @SINCE_1_0.0
249    */
250   void Lower();
251
252   /**
253    * @brief This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
254    * @SINCE_1_0.0
255    */
256   void Quit();
257
258   /**
259    * @brief Ensures that the function passed in is called from the main loop when it is idle.
260    * @SINCE_1_0.0
261    * @param[in] callback The function to call
262    * @return @c true if added successfully, @c false otherwise
263    *
264    * @note Function must be called from main event thread only
265    *
266    * A callback of the following type may be used:
267    * @code
268    *   void MyFunction();
269    * @endcode
270    * This callback will be deleted once it is called.
271    *
272    * @note Ownership of the callback is passed onto this class.
273    */
274   bool AddIdle( CallbackBase* callback );
275
276   /**
277    * @brief Retrieves the window used by the Application class.
278    *
279    * The application writer can use the window to change indicator and orientation
280    * properties.
281    * @SINCE_1_0.0
282    * @return A handle to the window
283    */
284   Window GetWindow();
285
286   /**
287    * @brief Replaces the current window.
288    *
289    * This will force context loss.
290    * If you plan on using this API in your application, then you should configure
291    * it to prevent discard behavior when handling the Init signal.
292    * @SINCE_1_0.0
293    * @param[in] windowPosition The position and size parameters of the new window
294    * @param[in] name The name of the new window
295    */
296   void ReplaceWindow(PositionSize windowPosition, const std::string& name);
297
298   /**
299    * @brief Get path application resources are stored at
300    *
301    * @SINCE_1_2.2
302    * @return the full path of the resources
303    */
304   static std::string GetResourcePath();
305
306   /**
307    * @brief This is used to get region information from device.
308    *
309    * @SINCE_1_2.62
310    * @return Region information
311    */
312   std::string GetRegion() const;
313
314   /**
315    * @brief This is used to get language information from device.
316    *
317    * @SINCE_1_2.62
318    * @return Language information
319    */
320   std::string GetLanguage() const;
321
322 public: // Stereoscopy
323
324   /**
325    * @brief Sets the viewing mode for the application.
326    * @SINCE_1_0.0
327    * @param[in] viewMode The new viewing mode
328    */
329   void SetViewMode( ViewMode viewMode );
330
331   /**
332    * @brief Gets the current viewing mode.
333    * @SINCE_1_0.0
334    * @return The current viewing mode
335    */
336   ViewMode GetViewMode() const;
337
338   /**
339    * @brief Sets the stereo base (eye separation) for Stereoscopic 3D.
340    *
341    * The stereo base is the distance in millimetres between the eyes. Typical values are
342    * between 50mm and 70mm. The default value is 65mm.
343    * @SINCE_1_0.0
344    * @param[in] stereoBase The stereo base (eye separation) for Stereoscopic 3D
345    */
346   void SetStereoBase( float stereoBase );
347
348   /**
349    * @brief Gets the stereo base (eye separation) for Stereoscopic 3D.
350    *
351    * @SINCE_1_0.0
352    * @return The stereo base (eye separation) for Stereoscopic 3D
353    */
354   float GetStereoBase() const;
355
356 public:  // Signals
357
358   /**
359    * @brief The user should connect to this signal to determine when they should initialize
360    * their application.
361    * @SINCE_1_0.0
362    * @return The signal to connect to
363    */
364   AppSignalType& InitSignal();
365
366   /**
367    * @brief The user should connect to this signal to determine when they should terminate
368    * their application.
369    * @SINCE_1_0.0
370    * @return The signal to connect to
371    */
372   AppSignalType& TerminateSignal();
373
374   /**
375    * @brief The user should connect to this signal if they need to perform any special
376    * activities when the application is about to be paused.
377    * @SINCE_1_0.0
378    * @return The signal to connect to
379    */
380   AppSignalType& PauseSignal();
381
382   /**
383    * @brief The user should connect to this signal if they need to perform any special
384    * activities when the application has resumed.
385    * @SINCE_1_0.0
386    * @return The signal to connect to
387    */
388   AppSignalType& ResumeSignal();
389
390   /**
391    * @brief This signal is sent when the system requires the user to reinitialize itself.
392    * @SINCE_1_0.0
393    * @return The signal to connect to
394    */
395   AppSignalType& ResetSignal();
396
397   /**
398    * @DEPRECATED_1_1.43 Use Window::ResizedSignal() instead.
399    * @brief This signal is emitted when the window application rendering on is resized.
400    * @SINCE_1_0.0
401    * @return The signal to connect to
402    */
403   AppSignalType& ResizeSignal() DALI_DEPRECATED_API;
404
405   /**
406   * @brief This signal is emitted when another application sends a launch request to the application.
407   *
408   * When the application is launched, this signal is emitted after the main loop of the application starts up.
409   * The passed parameter describes the launch request and contains the information about why the application is launched.
410   * @SINCE_1_0.0
411   * @return The signal to connect to
412   */
413   AppControlSignalType& AppControlSignal();
414
415   /**
416    * @brief This signal is emitted when the language is changed on the device.
417    * @SINCE_1_0.0
418    * @return The signal to connect to
419    */
420   AppSignalType& LanguageChangedSignal();
421
422   /**
423   * @brief This signal is emitted when the region of the device is changed.
424   * @SINCE_1_0.0
425   * @return The signal to connect to
426   */
427   AppSignalType& RegionChangedSignal();
428
429   /**
430   * @DEPRECATED_1_2.62 Use LowBatterySignal() instead.
431   * @brief This signal is emitted when the battery level of the device is low.
432   * @SINCE_1_0.0
433   * @return The signal to connect to
434   */
435   AppSignalType& BatteryLowSignal() DALI_DEPRECATED_API;
436
437   /**
438   * @DEPRECATED_1_2.62 Use LowMemorySignal() instead.
439   * @brief This signal is emitted when the memory level of the device is low.
440   * @SINCE_1_0.0
441   * @return The signal to connect to
442   */
443   AppSignalType& MemoryLowSignal() DALI_DEPRECATED_API;
444
445   /**
446    * @brief This signal is emitted when the battery level of the device is low.
447    * @SINCE_1_2.62
448    * @return The signal to connect to
449    */
450   LowBatterySignalType& LowBatterySignal();
451
452   /**
453    * @brief This signal is emitted when the memory level of the device is low.
454    * @SINCE_1_2.62
455    * @return The signal to connect to
456    */
457   LowMemorySignalType& LowMemorySignal();
458
459 public: // Not intended for application developers
460   /// @cond internal
461   /**
462    * @brief Internal constructor.
463    * @SINCE_1_0.0
464    */
465   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
466   /// @endcond
467 };
468
469 /**
470  * @}
471  */
472 } // namespace Dali
473
474 #endif // __DALI_APPLICATION_H__