Idle callback boost removal and tidy up
[platform/core/uifw/dali-adaptor.git] / adaptors / public-api / adaptor-framework / application.h
1 #ifndef __DALI_APPLICATION_H__
2 #define __DALI_APPLICATION_H__
3
4 /*
5  * Copyright (c) 2015 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
28 // INTERNAL INCLUDES
29 #include "application-configuration.h"
30 #include "window.h"
31
32 namespace Dali
33 {
34
35 namespace Internal DALI_INTERNAL
36 {
37 namespace Adaptor
38 {
39 class Application;
40 }
41 }
42
43 /**
44  * An Application class object should be created by every application
45  * that wishes to use Dali.  It provides a means for initialising the
46  * resources required by the Dali::Core.
47  *
48  * The Application class emits several signals which the user can
49  * connect to.  The user should not create any Dali objects in the main
50  * function and instead should connect to the Init signal of the
51  * Application and create the Dali objects in the connected callback.
52  *
53  * Applications should follow the example below:
54  *
55  * @code
56  * void CreateProgram(Application app)
57  * {
58  *   // Create Dali components...
59  *   // Can instantiate here, if required
60  * }
61  *
62  * int main (int argc, char **argv)
63  * {
64  *   Application app = Application::New(&argc, &argv);
65  *   app.InitSignal().Connect(&CreateProgram);
66  *   app.MainLoop();
67  * }
68  * @endcode
69  *
70  * If required, you can also connect class member functions to a signal:
71  *
72  * @code
73  * MyApplication app;
74  * app.ResumeSignal().Connect(&app, &MyApplication::Resume);
75  * @endcode
76  *
77  * This class accepts command line arguments as well. The following options are supported:
78  *
79  * @code
80  *     --no-vsync       Disable VSync on Render
81  *  -w|--width          Stage Width
82  *  -h|--height         Stage Height
83  *  -d|--dpi            Emulated DPI
84  *     --help           Help
85  * @endcode
86  *
87  * When the above options are found, they are stripped from argv, and argc is updated appropriately.
88  */
89 class DALI_IMPORT_API Application : public BaseHandle
90 {
91 public:
92
93   typedef Signal< void (Application&) > AppSignalType;
94   typedef Signal< void (Application&, void *) > AppControlSignalType;
95
96   /**
97    * Decides whether a Dali application window is opaque or transparent.
98    */
99   enum WINDOW_MODE
100   {
101     OPAQUE = 0,       ///< The window will be opaque
102     TRANSPARENT = 1   ///< The window transparency will match the alpha value set in Dali::Stage::SetBackgroundcolor()
103   };
104
105 public:
106
107   /**
108    * This is the constructor for applications without an argument list.
109    */
110   static Application New();
111
112   /**
113    * This is the constructor for applications.
114    *
115    * @param[in,out]  argc        A pointer to the number of arguments
116    * @param[in,out]  argv        A pointer the the argument list
117    */
118   static Application New( int* argc, char **argv[] );
119
120   /**
121    * This is the constructor for applications with a name
122    *
123    * @param[in,out]  argc        A pointer to the number of arguments
124    * @param[in,out]  argv        A pointer the the argument list
125    * @param[in]      stylesheet  The path to user defined theme file
126    */
127   static Application New( int* argc, char **argv[], const std::string& stylesheet );
128
129   /**
130    * This is the constructor for applications with a name
131    *
132    * @param[in,out]  argc        A pointer to the number of arguments
133    * @param[in,out]  argv        A pointer the the argument list
134    * @param[in]      stylesheet  The path to user defined theme file
135    * @param[in]      windowMode  A member of WINDOW_MODE
136    */
137   static Application New( int* argc, char **argv[], const std::string& stylesheet, WINDOW_MODE windowMode );
138
139   /**
140    * Construct an empty handle
141    */
142   Application();
143
144   /**
145    * Copy Constructor
146    */
147   Application( const Application& application );
148
149   /**
150    * Assignment operator
151    */
152   Application& operator=( const Application& applicaton );
153
154   /**
155    * @brief Destructor
156    *
157    * This is non-virtual since derived Handle types must not contain data or virtual methods.
158    */
159   ~Application();
160
161 public:
162   /**
163    * This starts the application. Choosing this form of main loop indicates that the default
164    * application configuration of APPLICATION_HANDLES_CONTEXT_LOSS is used. On platforms where
165    * context loss can occur, the application is responsible for tearing down and re-loading UI.
166    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
167    */
168   void MainLoop();
169
170   /**
171    * This starts the application, and allows the app to choose a different configuration.
172    * If the application plans on using the ReplaceSurface or ReplaceWindow API, then this will
173    * trigger context loss & regain.
174    * The application should listen to Stage::ContextLostSignal and Stage::ContextRegainedSignal.
175    */
176   void MainLoop(Configuration::ContextLoss configuration);
177
178   /**
179    * This lowers the application to bottom without actually quitting it
180    */
181   void Lower();
182
183   /**
184    * This quits the application.  Tizen applications should use Lower to improve re-start performance unless they need to Quit completely.
185    */
186   void Quit();
187
188   /**
189    * Ensures that the function passed in is called from the main loop when it is idle.
190    * @note Function must be called from main event thread only
191    *
192    * A callback of the following type may be used:
193    * @code
194    *   void MyFunction();
195    * @endcode
196    *
197    * @param[in]  callback  The function to call.
198    * @return true if added successfully, false otherwise
199    *
200    * @note Ownership of the callback is passed onto this class.
201    */
202   bool AddIdle( CallbackBase* callback );
203
204   /**
205    * Retrieves the window used by the Application class.
206    * The application writer can use the window to change indicator and orientation
207    * properties.
208    * @return A handle to the window
209    */
210   Window GetWindow();
211
212   /**
213    * Replace the current window.
214    * This will force context loss.
215    * If you plan on using this API in your application, then you should configure
216    * it to prevent discard behaviour when handling the Init signal.
217    * @param[in] windowPosition The position and size parameters of the new window
218    * @param[in] name The name of the new window
219    */
220   void ReplaceWindow(PositionSize windowPosition, const std::string& name);
221
222 public: // Stereoscopy
223
224   /**
225    * Set the viewing mode for the application.
226    * @param[in] viewMode The new viewing mode.
227    */
228   void SetViewMode( ViewMode viewMode );
229
230   /**
231    * Get the current viewing mode.
232    * @return The current viewing mode.
233    */
234   ViewMode GetViewMode() const;
235
236   /**
237    * Set the stereo base (eye separation) for Stereoscopic 3D
238    *
239    * @param[in] stereoBase The stereo base (eye separation) for Stereoscopic 3D
240    */
241   void SetStereoBase( float stereoBase );
242
243   /**
244    * Get the stereo base (eye separation) for Stereoscopic 3D
245    *
246    * @return The stereo base (eye separation) for Stereoscopic 3D
247    */
248   float GetStereoBase() const;
249
250 public:  // Signals
251
252   /**
253    * The user should connect to this signal to determine when they should initialise
254    * their application.
255    */
256   AppSignalType& InitSignal();
257
258   /**
259    * The user should connect to this signal to determine when they should terminate
260    * their application
261    */
262   AppSignalType& TerminateSignal();
263
264   /**
265    * The user should connect to this signal if they need to perform any special
266    * activities when the application is about to be paused.
267    */
268   AppSignalType& PauseSignal();
269
270   /**
271    * The user should connect to this signal if they need to perform any special
272    * activities when the application has resumed.
273    */
274   AppSignalType& ResumeSignal();
275
276   /**
277    * This signal is sent when the system requires the user to reinitialise itself.
278    */
279   AppSignalType& ResetSignal();
280
281   /**
282    * This signal is emitted when the window the application is rendering on is resized.
283    */
284   AppSignalType& ResizeSignal();
285
286   /**
287   * This signal is emitted when another application sends a launch request to the application.
288   * When the application is launched, this signal is emitted after the main loop of the application starts up.
289   * The passed parameter describes the launch request and contains the information about why the application is launched.
290   */
291   AppControlSignalType& AppControlSignal();
292
293   /**
294    * This signal is emitted when the language is changed on the device.
295    */
296   AppSignalType& LanguageChangedSignal();
297
298   /**
299   * This signal is emitted when the region of the device is changed.
300   */
301   AppSignalType& RegionChangedSignal();
302
303   /**
304   * This signal is emitted when the battery level of the device is low.
305   */
306   AppSignalType& BatteryLowSignal();
307
308   /**
309   * This signal is emitted when the memory level of the device is low.
310   */
311   AppSignalType& MemoryLowSignal();
312
313 public: // Not intended for application developers
314   /**
315    * Internal constructor
316    */
317   explicit DALI_INTERNAL Application(Internal::Adaptor::Application* application);
318 };
319
320 } // namespace Dali
321
322 #endif // __DALI_APPLICATION_H__