Merge "Add protect code for curl handle" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / application-impl.h
1 #ifndef DALI_INTERNAL_APPLICATION_H
2 #define DALI_INTERNAL_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 <dali/public-api/math/rect.h>
23 #include <dali/public-api/object/base-object.h>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/adaptor-framework/application.h>
27 #include <dali/devel-api/adaptor-framework/singleton-service.h>
28
29 #include <dali/internal/adaptor/common/framework.h>
30 #include <dali/internal/window-system/common/window-impl.h>
31 #include <dali/internal/system/common/environment-options.h>
32 #include <dali/internal/adaptor/common/adaptor-builder-impl.h>
33
34 namespace Dali
35 {
36 class Adaptor;
37 class Window;
38
39 namespace Internal
40 {
41
42 namespace Adaptor
43 {
44
45 namespace Launchpad
46 {
47
48 /**
49  * @brief Launchpad is used to improve application launch performance.
50  * When an application is pre-initialized, so files are preloaded, some functions are initialized and a window is made in advance.
51  */
52 enum State
53 {
54   NONE,              ///< The default state
55   PRE_INITIALIZED    ///< Application is pre-initialized.
56 };
57
58 } // namespace Launchpad
59
60 class CommandLineOptions;
61 class EventLoop;
62
63 typedef Dali::Rect<int> PositionSize;
64
65 class Application;
66 typedef IntrusivePtr<Application> ApplicationPtr;
67
68 /**
69  * Implementation of the Application class.
70  */
71 class Application : public BaseObject, public Framework::Observer
72 {
73 public:
74
75   typedef Dali::Application::LowBatterySignalType LowBatterySignalType;
76   typedef Dali::Application::LowMemorySignalType LowMemorySignalType;
77   typedef Dali::Application::AppSignalType AppSignalType;
78   typedef Dali::Application::AppControlSignalType AppControlSignalType;
79   typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
80
81   /**
82    * Create a new application
83    * @param[in]  argc         A pointer to the number of arguments
84    * @param[in]  argv         A pointer to the argument list
85    * @param[in]  stylesheet   The path to user defined theme file
86    * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
87    * @param[in]  positionSize A position and a size of the window
88    * @param[in]  applicationType  A member of Dali::Framework::Type
89    */
90   static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet,
91     WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
92
93   /**
94    * @copydoc Dali::DevelApplication::PreInitialize()
95    */
96   static void PreInitialize( int* argc, char** argv[] );
97
98 public:
99
100   /**
101    * @copydoc Dali::Application::MainLoop()
102    */
103   void MainLoop(Dali::Configuration::ContextLoss configuration);
104
105   /**
106    * @copydoc Dali::Application::Lower()
107    */
108   void Lower();
109
110   /**
111    * @copydoc Dali::Application::Quit()
112    */
113   void Quit();
114
115   /**
116    * @copydoc Dali::Application::AddIdle()
117    */
118   bool AddIdle( CallbackBase* callback, bool hasReturnValue );
119
120   /**
121    * @copydoc Dali::Application::GetAdaptor();
122    */
123   Dali::Adaptor& GetAdaptor();
124
125   /**
126    * @copydoc Dali::Application::GetWindow();
127    */
128   Dali::Window GetWindow();
129
130   /**
131    * @copydoc Dali::Application::GetRegion();
132    */
133   std::string GetRegion() const;
134
135   /**
136    * @copydoc Dali::Application::GetLanguage();
137    */
138   std::string GetLanguage() const;
139
140   /**
141    * @copydoc Dali::Application::ReplaceWindow();
142    */
143   void ReplaceWindow( const PositionSize& positionSize, const std::string& name);
144
145   /**
146    * @copydoc Dali::Application::GetResourcePath();
147    */
148   static std::string GetResourcePath();
149
150   /**
151    * @copydoc Dali::DevelApplication::GetDataPath()
152    */
153   static std::string GetDataPath();
154
155   /**
156    * Retrieves the pre-initialized application.
157    *
158    * @return A pointer to the pre-initialized application
159    */
160   static ApplicationPtr GetPreInitializedApplication();
161
162 public: // Stereoscopy
163
164   /**
165    * @copydoc Dali::Application::SetViewMode()
166    */
167   void SetViewMode( ViewMode viewMode );
168
169   /**
170    * @copydoc Dali::Application::GetViewMode()
171    */
172   ViewMode GetViewMode() const;
173
174   /**
175    * @copydoc Dali::Application::SetStereoBase()
176    */
177   void SetStereoBase( float stereoBase );
178
179   /**
180    * @copydoc Dali::Application::GetStereoBase()
181    */
182   float GetStereoBase() const;
183
184 public: // Lifecycle functionality
185
186   /**
187    * Called when OnInit is called or the framework is initialised.
188    */
189   void DoInit();
190
191   /**
192    * Called after OnInit is called or the framework is started.
193    */
194   void DoStart();
195
196   /**
197    * Called when OnTerminate is called or the framework is terminated.
198    */
199   void DoTerminate();
200
201   /**
202    * Called when OnPause is called or the framework is paused.
203    */
204   void DoPause();
205
206   /**
207    * Called when OnResume is called or the framework resumes from a paused state.
208    */
209   void DoResume();
210
211   /**
212    * Called when OnLanguageChanged is called or the framework informs the application that the language of the device has changed.
213    */
214   void DoLanguageChange();
215
216 public: // From Framework::Observer
217
218   /**
219    * Called when the framework is initialised.
220    */
221   virtual void OnInit();
222
223   /**
224    * Called when the framework is terminated.
225    */
226   virtual void OnTerminate();
227
228   /**
229    * Called when the framework is paused.
230    */
231   virtual void OnPause();
232
233   /**
234    * Called when the framework resumes from a paused state.
235    */
236   virtual void OnResume();
237
238   /**
239   * Called when the framework received AppControlSignal.
240   * @param[in] The bundle data of AppControl event.
241   */
242   virtual void OnAppControl(void *data);
243
244   /**
245    * Called when the framework informs the application that it should reset itself.
246    */
247   virtual void OnReset();
248
249   /**
250    * Called when the framework informs the application that the language of the device has changed.
251    */
252   virtual void OnLanguageChanged();
253
254   /**
255   * Called when the framework informs the application that the region of the device has changed.
256   */
257   virtual void OnRegionChanged();
258
259   /**
260   * Called when the framework informs the application that the battery level of the device is low.
261   */
262   virtual void OnBatteryLow( Dali::DeviceStatus::Battery::Status status );
263
264   /**
265   * Called when the framework informs the application that the memory level of the device is low.
266   */
267   virtual void OnMemoryLow( Dali::DeviceStatus::Memory::Status status );
268
269 public:
270
271   /**
272    * Signal handler when the adaptor's window resizes itself.
273    * @param[in]  adaptor  The adaptor
274    */
275   void OnResize(Dali::Adaptor& adaptor);
276
277   /**
278    * Sets a user defined theme file.
279    * This should be called before initialization.
280    * @param[in] stylesheet The path to user defined theme file
281    */
282   void SetStyleSheet( const std::string& stylesheet );
283
284 public:  // Signals
285
286   /**
287    * @copydoc Dali::Application::InitSignal()
288    */
289   Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
290
291   /**
292    * @copydoc Dali::Application::TerminateSignal()
293    */
294   Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
295
296   /**
297    * @copydoc Dali::Application::PauseSignal()
298    */
299   Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
300
301   /**
302    * @copydoc Dali::Application::ResumeSignal()
303    */
304   Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
305
306   /**
307    * @copydoc Dali::Application::ResetSignal()
308    */
309   Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
310
311   /**
312   * @copydoc Dali::Application::AppControlSignal()
313   */
314   Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
315
316   /**
317    * @copydoc Dali::Application::ResizeSignal()
318    */
319   Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
320
321   /**
322    * @copydoc Dali::Application::LanguageChangedSignal()
323    */
324   Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
325
326   /**
327   * @copydoc Dali::Application::RegionChangedSignal()
328   */
329   Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
330
331   /**
332   * @copydoc Dali::Application::BatteryLowSignal()
333   */
334   Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
335
336   /**
337   * @copydoc Dali::Application::MemoryLowSignal()
338   */
339   Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
340
341   /**
342   * @copydoc Dali::Application::LowBatterySignal()
343   */
344   Dali::Application::LowBatterySignalType& LowBatterySignal() { return mLowBatterySignal; }
345
346   /**
347   * @copydoc Dali::Application:::LowMemorySignal()
348   */
349   Dali::Application::LowMemorySignalType& LowMemorySignal() { return mLowMemorySignal; }
350
351 protected:
352
353   /**
354    * Private Constructor
355    * @param[in]  argc         A pointer to the number of arguments
356    * @param[in]  argv         A pointer to the argument list
357    * @param[in]  stylesheet   The path to user defined theme file
358    * @param[in]  windowMode   A member of Dali::Application::WINDOW_MODE
359    * @param[in]  positionSize A position and a size of the window
360    * @param[in]  applicationType  A member of Dali::Framework::Type
361    */
362   Application( int* argc, char **argv[], const std::string& stylesheet,
363       WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
364
365   /**
366    * Destructor
367    */
368   virtual ~Application();
369
370   // Undefined
371   Application(const Application&);
372   Application& operator=(Application&);
373
374   /**
375    * Creates the window
376    */
377   void CreateWindow();
378
379   /**
380    * Creates the adaptor
381    */
382   void CreateAdaptor();
383
384   /**
385    * Creates the adaptor builder
386    */
387   void CreateAdaptorBuilder();
388
389   /**
390    * Quits from the main loop
391    */
392   void QuitFromMainLoop();
393
394 private:
395
396   AppSignalType                         mInitSignal;
397   AppSignalType                         mTerminateSignal;
398   AppSignalType                         mPauseSignal;
399   AppSignalType                         mResumeSignal;
400   AppSignalType                         mResetSignal;
401   AppSignalType                         mResizeSignal;
402   AppControlSignalType                  mAppControlSignal;
403   AppSignalType                         mLanguageChangedSignal;
404   AppSignalType                         mRegionChangedSignal;
405   AppSignalType                         mBatteryLowSignal;
406   AppSignalType                         mMemoryLowSignal;
407   LowBatterySignalType                  mLowBatterySignal;
408   LowMemorySignalType                   mLowMemorySignal;
409
410   EventLoop*                            mEventLoop;
411   Framework*                            mFramework;
412
413   Dali::Configuration::ContextLoss      mContextLossConfiguration;
414   CommandLineOptions*                   mCommandLineOptions;
415
416   Dali::SingletonService                   mSingletonService;
417   Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder;   ///< The adaptor builder
418   Dali::Adaptor*                           mAdaptor;
419
420   // The Main Window is that window created by the Application during initial startup
421   // (previously this was the only window)
422   Dali::Window                             mMainWindow;       ///< Main Window instance
423   Dali::Application::WINDOW_MODE           mMainWindowMode;   ///< Window mode of the main window
424   std::string                              mMainWindowName;   ///< Name of the main window as obtained from environment options
425
426   std::string                              mStylesheet;
427   EnvironmentOptions                       mEnvironmentOptions;
428   PositionSize                             mWindowPositionSize;
429   Launchpad::State                         mLaunchpadState;
430   bool                                     mUseRemoteSurface;
431
432   SlotDelegate< Application >              mSlotDelegate;
433
434   ViewMode                                 mViewMode;
435   float                                    mStereoBase;
436
437   static ApplicationPtr                    gPreInitializedApplication;
438 };
439
440 inline Application& GetImplementation(Dali::Application& application)
441 {
442   DALI_ASSERT_ALWAYS(application && "application handle is empty");
443
444   BaseObject& handle = application.GetBaseObject();
445
446   return static_cast<Internal::Adaptor::Application&>(handle);
447 }
448
449 inline const Application& GetImplementation(const Dali::Application& application)
450 {
451   DALI_ASSERT_ALWAYS(application && "application handle is empty");
452
453   const BaseObject& handle = application.GetBaseObject();
454
455   return static_cast<const Internal::Adaptor::Application&>(handle);
456 }
457
458
459 } // namespace Adaptor
460
461 } // namespace Internal
462
463 } // namespace Dali
464
465 #endif // DALI_INTERNAL_APPLICATION_H