Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / common / application-impl.h
1 #ifndef __DALI_INTERNAL_APPLICATION_H__
2 #define __DALI_INTERNAL_APPLICATION_H__
3
4 /*
5  * Copyright (c) 2017 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/math/rect.h>
23 #include <dali/public-api/object/base-object.h>
24
25 // INTERNAL INCLUDES
26 #include <application.h>
27 #include <singleton-service.h>
28
29 #include <framework.h>
30 #include <window-impl.h>
31 #include <base/environment-options.h>
32
33 namespace Dali
34 {
35 class Adaptor;
36 class Window;
37
38 namespace Internal
39 {
40
41 namespace Adaptor
42 {
43 class CommandLineOptions;
44 class EventLoop;
45
46 typedef Dali::Rect<int> PositionSize;
47
48 class Application;
49 typedef IntrusivePtr<Application> ApplicationPtr;
50
51 /**
52  * Implementation of the Application class.
53  */
54 class Application : public BaseObject, public Framework::Observer
55 {
56 public:
57   typedef Dali::Application::AppSignalType AppSignalType;
58   typedef Dali::Application::AppControlSignalType AppControlSignalType;
59   typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
60
61   /**
62    * Create a new application
63    * @param[in]  argc         A pointer to the number of arguments
64    * @param[in]  argv         A pointer to the argument list
65    * @param[in]  stylesheet   The path to user defined theme file
66    * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
67    * @param[in]  positionSize A position and a size of the window
68    * @param[in]  applicationType  A member of Dali::Framework::Type
69    */
70   static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet,
71     WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
72
73 public:
74
75   /**
76    * @copydoc Dali::Application::MainLoop()
77    */
78   void MainLoop(Dali::Configuration::ContextLoss configuration);
79
80   /**
81    * @copydoc Dali::Application::Lower()
82    */
83   void Lower();
84
85   /**
86    * @copydoc Dali::Application::Quit()
87    */
88   void Quit();
89
90   /**
91    * @copydoc Dali::Application::AddIdle()
92    */
93   bool AddIdle( CallbackBase* callback );
94
95   /**
96    * @copydoc Dali::Application::GetAdaptor();
97    */
98   Dali::Adaptor& GetAdaptor();
99
100   /**
101    * @copydoc Dali::Application::GetWindow();
102    */
103   Dali::Window GetWindow();
104
105   /**
106    * @copydoc Dali::Application::ReplaceWindow();
107    */
108   void ReplaceWindow( const PositionSize& positionSize, const std::string& name);
109
110   /**
111    * @copydoc Dali::Application::GetResourcePath();
112    */
113   static std::string GetResourcePath();
114
115 public: // Stereoscopy
116
117   /**
118    * @copydoc Dali::Application::SetViewMode()
119    */
120   void SetViewMode( ViewMode viewMode );
121
122   /**
123    * @copydoc Dali::Application::GetViewMode()
124    */
125   ViewMode GetViewMode() const;
126
127   /**
128    * @copydoc Dali::Application::SetStereoBase()
129    */
130   void SetStereoBase( float stereoBase );
131
132   /**
133    * @copydoc Dali::Application::GetStereoBase()
134    */
135   float GetStereoBase() const;
136
137 public: // Lifecycle functionality
138
139   /**
140    * Called when OnInit is called or the framework is initialised.
141    */
142   void DoInit();
143
144   /**
145    * Called after OnInit is called or the framework is started.
146    */
147   void DoStart();
148
149   /**
150    * Called when OnTerminate is called or the framework is terminated.
151    */
152   void DoTerminate();
153
154   /**
155    * Called when OnPause is called or the framework is paused.
156    */
157   void DoPause();
158
159   /**
160    * Called when OnResume is called or the framework resumes from a paused state.
161    */
162   void DoResume();
163
164   /**
165    * Called when OnLanguageChanged is called or the framework informs the application that the language of the device has changed.
166    */
167   void DoLanguageChange();
168
169 public: // From Framework::Observer
170
171   /**
172    * Called when the framework is initialised.
173    */
174   virtual void OnInit();
175
176   /**
177    * Called when the framework is terminated.
178    */
179   virtual void OnTerminate();
180
181   /**
182    * Called when the framework is paused.
183    */
184   virtual void OnPause();
185
186   /**
187    * Called when the framework resumes from a paused state.
188    */
189   virtual void OnResume();
190
191   /**
192   * Called when the framework received AppControlSignal.
193   * @param[in] The bundle data of AppControl event.
194   */
195   virtual void OnAppControl(void *data);
196
197   /**
198    * Called when the framework informs the application that it should reset itself.
199    */
200   virtual void OnReset();
201
202   /**
203    * Called when the framework informs the application that the language of the device has changed.
204    */
205   virtual void OnLanguageChanged();
206
207   /**
208   * Called when the framework informs the application that the region of the device has changed.
209   */
210   virtual void OnRegionChanged();
211
212   /**
213   * Called when the framework informs the application that the battery level of the device is low.
214   */
215   virtual void OnBatteryLow();
216
217   /**
218   * Called when the framework informs the application that the memory level of the device is low.
219   */
220   virtual void OnMemoryLow();
221
222 public:
223
224   /**
225    * Signal handler when the adaptor's window resizes itself.
226    * @param[in]  adaptor  The adaptor
227    */
228   void OnResize(Dali::Adaptor& adaptor);
229
230 public:  // Signals
231
232   /**
233    * @copydoc Dali::Application::InitSignal()
234    */
235   Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
236
237   /**
238    * @copydoc Dali::Application::TerminateSignal()
239    */
240   Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
241
242   /**
243    * @copydoc Dali::Application::PauseSignal()
244    */
245   Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
246
247   /**
248    * @copydoc Dali::Application::ResumeSignal()
249    */
250   Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
251
252   /**
253    * @copydoc Dali::Application::ResetSignal()
254    */
255   Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
256
257   /**
258   * @copydoc Dali::Application::AppControlSignal()
259   */
260   Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
261
262   /**
263    * @copydoc Dali::Application::ResizeSignal()
264    */
265   Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
266
267   /**
268    * @copydoc Dali::Application::LanguageChangedSignal()
269    */
270   Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
271
272   /**
273   * @copydoc Dali::Application::RegionChangedSignal()
274   */
275   Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
276
277   /**
278   * @copydoc Dali::Application::BatteryLowSignal()
279   */
280   Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
281
282   /**
283   * @copydoc Dali::Application::MemoryLowSignal()
284   */
285   Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
286
287 protected:
288
289   /**
290    * Private Constructor
291    * @param[in]  argc         A pointer to the number of arguments
292    * @param[in]  argv         A pointer to the argument list
293    * @param[in]  stylesheet   The path to user defined theme file
294    * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
295    * @param[in]  positionSize A position and a size of the window
296    * @param[in]  applicationType  A member of Dali::Framework::Type
297    */
298   Application( int* argc, char **argv[], const std::string& stylesheet,
299       WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
300
301   /**
302    * Destructor
303    */
304   virtual ~Application();
305
306   // Undefined
307   Application(const Application&);
308   Application& operator=(Application&);
309
310   /**
311    * Creates the window
312    */
313   void CreateWindow();
314
315   /**
316    * Creates the adaptor
317    */
318   void CreateAdaptor();
319
320   /**
321    * Quits from the main loop
322    */
323   void QuitFromMainLoop();
324
325 private:
326
327   AppSignalType                           mInitSignal;
328   AppSignalType                           mTerminateSignal;
329   AppSignalType                           mPauseSignal;
330   AppSignalType                           mResumeSignal;
331   AppSignalType                           mResetSignal;
332   AppSignalType                           mResizeSignal;
333   AppControlSignalType                    mAppControlSignal;
334   AppSignalType                           mLanguageChangedSignal;
335   AppSignalType                           mRegionChangedSignal;
336   AppSignalType                           mBatteryLowSignal;
337   AppSignalType                           mMemoryLowSignal;
338
339   EventLoop*                            mEventLoop;
340   Framework*                            mFramework;
341
342   Dali::Configuration::ContextLoss      mContextLossConfiguration;
343   CommandLineOptions*                   mCommandLineOptions;
344
345   Dali::SingletonService                mSingletonService;
346   Dali::Adaptor*                        mAdaptor;
347   Dali::Window                          mWindow;
348   Dali::Application::WINDOW_MODE        mWindowMode;
349   std::string                           mName;
350   std::string                           mStylesheet;
351   EnvironmentOptions                    mEnvironmentOptions;
352   PositionSize                          mWindowPositionSize;
353   bool                                  mUseRemoteSurface;
354
355   SlotDelegate< Application >           mSlotDelegate;
356 };
357
358 inline Application& GetImplementation(Dali::Application& application)
359 {
360   DALI_ASSERT_ALWAYS(application && "application handle is empty");
361
362   BaseObject& handle = application.GetBaseObject();
363
364   return static_cast<Internal::Adaptor::Application&>(handle);
365 }
366
367 inline const Application& GetImplementation(const Dali::Application& application)
368 {
369   DALI_ASSERT_ALWAYS(application && "Timre handle is empty");
370
371   const BaseObject& handle = application.GetBaseObject();
372
373   return static_cast<const Internal::Adaptor::Application&>(handle);
374 }
375
376
377 } // namespace Adaptor
378
379 } // namespace Internal
380
381 } // namespace Dali
382
383 #endif // __DALI_INTERNAL_APPLICATION_H__