1 #ifndef DALI_INTERNAL_APPLICATION_H
2 #define DALI_INTERNAL_APPLICATION_H
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/math/rect.h>
23 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/adaptor-framework/application.h>
27 #include <dali/devel-api/adaptor-framework/singleton-service.h>
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>
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.
54 NONE, ///< The default state
55 PRE_INITIALIZED ///< Application is pre-initialized.
58 } // namespace Launchpad
60 class CommandLineOptions;
63 typedef Dali::Rect<int> PositionSize;
66 typedef IntrusivePtr<Application> ApplicationPtr;
69 * Implementation of the Application class.
71 class Application : public BaseObject, public Framework::Observer
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;
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
90 static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet,
91 WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
94 * @copydoc Dali::DevelApplication::PreInitialize()
96 static void PreInitialize( int* argc, char** argv[] );
101 * @copydoc Dali::Application::MainLoop()
103 void MainLoop(Dali::Configuration::ContextLoss configuration);
106 * @copydoc Dali::Application::Lower()
111 * @copydoc Dali::Application::Quit()
116 * @copydoc Dali::Application::AddIdle()
118 bool AddIdle( CallbackBase* callback, bool hasReturnValue );
121 * @copydoc Dali::Application::GetAdaptor();
123 Dali::Adaptor& GetAdaptor();
126 * @copydoc Dali::Application::GetWindow();
128 Dali::Window GetWindow();
131 * @copydoc Dali::Application::GetRegion();
133 std::string GetRegion() const;
136 * @copydoc Dali::Application::GetLanguage();
138 std::string GetLanguage() const;
141 * @copydoc Dali::Application::ReplaceWindow();
143 void ReplaceWindow( const PositionSize& positionSize, const std::string& name);
146 * @copydoc Dali::Application::GetResourcePath();
148 static std::string GetResourcePath();
151 * Retrieves the pre-initialized application.
153 * @return A pointer to the pre-initialized application
155 static ApplicationPtr GetPreInitializedApplication();
157 public: // Stereoscopy
160 * @copydoc Dali::Application::SetViewMode()
162 void SetViewMode( ViewMode viewMode );
165 * @copydoc Dali::Application::GetViewMode()
167 ViewMode GetViewMode() const;
170 * @copydoc Dali::Application::SetStereoBase()
172 void SetStereoBase( float stereoBase );
175 * @copydoc Dali::Application::GetStereoBase()
177 float GetStereoBase() const;
179 public: // Lifecycle functionality
182 * Called when OnInit is called or the framework is initialised.
187 * Called after OnInit is called or the framework is started.
192 * Called when OnTerminate is called or the framework is terminated.
197 * Called when OnPause is called or the framework is paused.
202 * Called when OnResume is called or the framework resumes from a paused state.
207 * Called when OnLanguageChanged is called or the framework informs the application that the language of the device has changed.
209 void DoLanguageChange();
211 public: // From Framework::Observer
214 * Called when the framework is initialised.
216 virtual void OnInit();
219 * Called when the framework is terminated.
221 virtual void OnTerminate();
224 * Called when the framework is paused.
226 virtual void OnPause();
229 * Called when the framework resumes from a paused state.
231 virtual void OnResume();
234 * Called when the framework received AppControlSignal.
235 * @param[in] The bundle data of AppControl event.
237 virtual void OnAppControl(void *data);
240 * Called when the framework informs the application that it should reset itself.
242 virtual void OnReset();
245 * Called when the framework informs the application that the language of the device has changed.
247 virtual void OnLanguageChanged();
250 * Called when the framework informs the application that the region of the device has changed.
252 virtual void OnRegionChanged();
255 * Called when the framework informs the application that the battery level of the device is low.
257 virtual void OnBatteryLow( Dali::DeviceStatus::Battery::Status status );
260 * Called when the framework informs the application that the memory level of the device is low.
262 virtual void OnMemoryLow( Dali::DeviceStatus::Memory::Status status );
267 * Signal handler when the adaptor's window resizes itself.
268 * @param[in] adaptor The adaptor
270 void OnResize(Dali::Adaptor& adaptor);
273 * Sets a user defined theme file.
274 * This should be called before initialization.
275 * @param[in] stylesheet The path to user defined theme file
277 void SetStyleSheet( const std::string& stylesheet );
282 * @copydoc Dali::Application::InitSignal()
284 Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
287 * @copydoc Dali::Application::TerminateSignal()
289 Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
292 * @copydoc Dali::Application::PauseSignal()
294 Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
297 * @copydoc Dali::Application::ResumeSignal()
299 Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
302 * @copydoc Dali::Application::ResetSignal()
304 Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
307 * @copydoc Dali::Application::AppControlSignal()
309 Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
312 * @copydoc Dali::Application::ResizeSignal()
314 Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
317 * @copydoc Dali::Application::LanguageChangedSignal()
319 Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
322 * @copydoc Dali::Application::RegionChangedSignal()
324 Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
327 * @copydoc Dali::Application::BatteryLowSignal()
329 Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
332 * @copydoc Dali::Application::MemoryLowSignal()
334 Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
337 * @copydoc Dali::Application::LowBatterySignal()
339 Dali::Application::LowBatterySignalType& LowBatterySignal() { return mLowBatterySignal; }
342 * @copydoc Dali::Application:::LowMemorySignal()
344 Dali::Application::LowMemorySignalType& LowMemorySignal() { return mLowMemorySignal; }
349 * Private Constructor
350 * @param[in] argc A pointer to the number of arguments
351 * @param[in] argv A pointer to the argument list
352 * @param[in] stylesheet The path to user defined theme file
353 * @param[in] windowMode A member of Dali::Application::WINDOW_MODE
354 * @param[in] positionSize A position and a size of the window
355 * @param[in] applicationType A member of Dali::Framework::Type
357 Application( int* argc, char **argv[], const std::string& stylesheet,
358 WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
363 virtual ~Application();
366 Application(const Application&);
367 Application& operator=(Application&);
375 * Creates the adaptor
377 void CreateAdaptor();
380 * Creates the adaptor builder
382 void CreateAdaptorBuilder();
385 * Quits from the main loop
387 void QuitFromMainLoop();
391 AppSignalType mInitSignal;
392 AppSignalType mTerminateSignal;
393 AppSignalType mPauseSignal;
394 AppSignalType mResumeSignal;
395 AppSignalType mResetSignal;
396 AppSignalType mResizeSignal;
397 AppControlSignalType mAppControlSignal;
398 AppSignalType mLanguageChangedSignal;
399 AppSignalType mRegionChangedSignal;
400 AppSignalType mBatteryLowSignal;
401 AppSignalType mMemoryLowSignal;
402 LowBatterySignalType mLowBatterySignal;
403 LowMemorySignalType mLowMemorySignal;
405 EventLoop* mEventLoop;
406 Framework* mFramework;
408 Dali::Configuration::ContextLoss mContextLossConfiguration;
409 CommandLineOptions* mCommandLineOptions;
411 Dali::SingletonService mSingletonService;
412 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder; ///< The adaptor builder
413 Dali::Adaptor* mAdaptor;
415 // The Main Window is that window created by the Application during initial startup
416 // (previously this was the only window)
417 Dali::Window mMainWindow; ///< Main Window instance
418 Dali::Application::WINDOW_MODE mMainWindowMode; ///< Window mode of the main window
419 std::string mMainWindowName; ///< Name of the main window as obtained from environment options
421 std::string mStylesheet;
422 EnvironmentOptions mEnvironmentOptions;
423 PositionSize mWindowPositionSize;
424 Launchpad::State mLaunchpadState;
425 bool mUseRemoteSurface;
427 SlotDelegate< Application > mSlotDelegate;
432 static ApplicationPtr gPreInitializedApplication;
435 inline Application& GetImplementation(Dali::Application& application)
437 DALI_ASSERT_ALWAYS(application && "application handle is empty");
439 BaseObject& handle = application.GetBaseObject();
441 return static_cast<Internal::Adaptor::Application&>(handle);
444 inline const Application& GetImplementation(const Dali::Application& application)
446 DALI_ASSERT_ALWAYS(application && "application handle is empty");
448 const BaseObject& handle = application.GetBaseObject();
450 return static_cast<const Internal::Adaptor::Application&>(handle);
454 } // namespace Adaptor
456 } // namespace Internal
460 #endif // DALI_INTERNAL_APPLICATION_H