Implement WatchApplication class
[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) 2016 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]  applicationType  A member of Dali::Framework::Type
68    */
69   static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet,
70     WINDOW_MODE windowMode, Framework::Type applicationType );
71
72 public:
73
74   /**
75    * @copydoc Dali::Application::MainLoop()
76    */
77   void MainLoop(Dali::Configuration::ContextLoss configuration);
78
79   /**
80    * @copydoc Dali::Application::Lower()
81    */
82   void Lower();
83
84   /**
85    * @copydoc Dali::Application::Quit()
86    */
87   void Quit();
88
89   /**
90    * @copydoc Dali::Application::AddIdle()
91    */
92   bool AddIdle( CallbackBase* callback );
93
94   /**
95    * @copydoc Dali::Application::GetAdaptor();
96    */
97   Dali::Adaptor& GetAdaptor();
98
99   /**
100    * @copydoc Dali::Application::GetWindow();
101    */
102   Dali::Window GetWindow();
103
104   /**
105    * @copydoc Dali::Application::ReplaceWindow();
106    */
107   void ReplaceWindow(PositionSize windowPosition, const std::string& name);
108
109 public: // Stereoscopy
110
111   /**
112    * @copydoc Dali::Application::SetViewMode()
113    */
114   void SetViewMode( ViewMode viewMode );
115
116   /**
117    * @copydoc Dali::Application::GetViewMode()
118    */
119   ViewMode GetViewMode() const;
120
121   /**
122    * @copydoc Dali::Application::SetStereoBase()
123    */
124   void SetStereoBase( float stereoBase );
125
126   /**
127    * @copydoc Dali::Application::GetStereoBase()
128    */
129   float GetStereoBase() const;
130
131 public: // From Framework::Observer
132
133   /**
134    * Called when the framework is initialised.
135    */
136   virtual void OnInit();
137
138   /**
139    * Called when the framework is terminated.
140    */
141   virtual void OnTerminate();
142
143   /**
144    * Called when the framework is paused.
145    */
146   virtual void OnPause();
147
148   /**
149    * Called when the framework resumes from a paused state.
150    */
151   virtual void OnResume();
152
153   /**
154   * Called when the framework received AppControlSignal.
155   * @param[in] The bundle data of AppControl event.
156   */
157   virtual void OnAppControl(void *data);
158
159   /**
160    * Called when the framework informs the application that it should reset itself.
161    */
162   virtual void OnReset();
163
164   /**
165    * Called when the framework informs the application that the language of the device has changed.
166    */
167   virtual void OnLanguageChanged();
168
169   /**
170   * Called when the framework informs the application that the region of the device has changed.
171   */
172   virtual void OnRegionChanged();
173
174   /**
175   * Called when the framework informs the application that the battery level of the device is low.
176   */
177   virtual void OnBatteryLow();
178
179   /**
180   * Called when the framework informs the application that the memory level of the device is low.
181   */
182   virtual void OnMemoryLow();
183
184 public:
185
186   /**
187    * Signal handler when the adaptor's window resizes itself.
188    * @param[in]  adaptor  The adaptor
189    */
190   void OnResize(Dali::Adaptor& adaptor);
191
192 public:  // Signals
193
194   /**
195    * @copydoc Dali::Application::InitSignal()
196    */
197   Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
198
199   /**
200    * @copydoc Dali::Application::TerminateSignal()
201    */
202   Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
203
204   /**
205    * @copydoc Dali::Application::PauseSignal()
206    */
207   Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
208
209   /**
210    * @copydoc Dali::Application::ResumeSignal()
211    */
212   Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
213
214   /**
215    * @copydoc Dali::Application::ResetSignal()
216    */
217   Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
218
219   /**
220   * @copydoc Dali::Application::AppControlSignal()
221   */
222   Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
223
224   /**
225    * @copydoc Dali::Application::ResizeSignal()
226    */
227   Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
228
229   /**
230    * @copydoc Dali::Application::LanguageChangedSignal()
231    */
232   Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
233
234   /**
235   * @copydoc Dali::Application::RegionChangedSignal()
236   */
237   Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
238
239   /**
240   * @copydoc Dali::Application::BatteryLowSignal()
241   */
242   Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
243
244   /**
245   * @copydoc Dali::Application::MemoryLowSignal()
246   */
247   Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
248
249 protected:
250
251   /**
252    * Private Constructor
253    * @param[in]  argc        A pointer to the number of arguments
254    * @param[in]  argv        A pointer to the argument list
255    * @param[in]  stylesheet  The path to user defined theme file
256    * @param[in]  windowMode  A member of Dali::Application::WINDOW_MODE
257    */
258   Application( int* argc, char **argv[], const std::string& stylesheet,
259       WINDOW_MODE windowMode, Framework::Type applicationType );
260
261   /**
262    * Destructor
263    */
264   virtual ~Application();
265
266   // Undefined
267   Application(const Application&);
268   Application& operator=(Application&);
269
270   /**
271    * Creates the window
272    */
273   void CreateWindow();
274
275   /**
276    * Creates the adaptor
277    */
278   void CreateAdaptor();
279
280   /**
281    * Quits from the main loop
282    */
283   void QuitFromMainLoop();
284
285 private:
286
287   AppSignalType                           mInitSignal;
288   AppSignalType                           mTerminateSignal;
289   AppSignalType                           mPauseSignal;
290   AppSignalType                           mResumeSignal;
291   AppSignalType                           mResetSignal;
292   AppSignalType                           mResizeSignal;
293   AppControlSignalType                    mAppControlSignal;
294   AppSignalType                           mLanguageChangedSignal;
295   AppSignalType                           mRegionChangedSignal;
296   AppSignalType                           mBatteryLowSignal;
297   AppSignalType                           mMemoryLowSignal;
298
299   EventLoop*                            mEventLoop;
300   Framework*                            mFramework;
301
302   Dali::Configuration::ContextLoss      mContextLossConfiguration;
303   CommandLineOptions*                   mCommandLineOptions;
304
305   Dali::SingletonService                mSingletonService;
306   Dali::Adaptor*                        mAdaptor;
307   Dali::Window                          mWindow;
308   Dali::Application::WINDOW_MODE        mWindowMode;
309   std::string                           mName;
310   std::string                           mStylesheet;
311   EnvironmentOptions                    mEnvironmentOptions;
312
313   SlotDelegate< Application >           mSlotDelegate;
314 };
315
316 inline Application& GetImplementation(Dali::Application& application)
317 {
318   DALI_ASSERT_ALWAYS(application && "application handle is empty");
319
320   BaseObject& handle = application.GetBaseObject();
321
322   return static_cast<Internal::Adaptor::Application&>(handle);
323 }
324
325 inline const Application& GetImplementation(const Dali::Application& application)
326 {
327   DALI_ASSERT_ALWAYS(application && "Timre handle is empty");
328
329   const BaseObject& handle = application.GetBaseObject();
330
331   return static_cast<const Internal::Adaptor::Application&>(handle);
332 }
333
334
335 } // namespace Adaptor
336
337 } // namespace Internal
338
339 } // namespace Dali
340
341 #endif // __DALI_INTERNAL_APPLICATION_H__