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/common/singleton-service.h>
29 #include <dali/internal/adaptor/common/framework.h>
30 #include <dali/internal/system/common/environment-options.h>
31 #include <dali/internal/adaptor/common/adaptor-builder-impl.h>
48 * @brief Launchpad is used to improve application launch performance.
49 * When an application is pre-initialized, so files are preloaded, some functions are initialized and a window is made in advance.
53 NONE, ///< The default state
54 PRE_INITIALIZED ///< Application is pre-initialized.
57 } // namespace Launchpad
59 class CommandLineOptions;
62 typedef Dali::Rect<int> PositionSize;
65 typedef IntrusivePtr<Application> ApplicationPtr;
68 * Implementation of the Application class.
70 class Application : public BaseObject, public Framework::Observer
74 typedef Dali::Application::LowBatterySignalType LowBatterySignalType;
75 typedef Dali::Application::LowMemorySignalType LowMemorySignalType;
76 typedef Dali::Application::AppSignalType AppSignalType;
77 typedef Dali::Application::AppControlSignalType AppControlSignalType;
78 typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
81 * Create a new application
82 * @param[in] argc A pointer to the number of arguments
83 * @param[in] argv A pointer to the argument list
84 * @param[in] stylesheet The path to user defined theme file
85 * @param[in] windowMode A member of Dali::Application::WINDOW_MODE
86 * @param[in] positionSize A position and a size of the window
87 * @param[in] applicationType A member of Dali::Framework::Type
89 static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet,
90 WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
93 * @copydoc Dali::DevelApplication::PreInitialize()
95 static void PreInitialize( int* argc, char** argv[] );
100 * @copydoc Dali::Application::MainLoop()
102 void MainLoop(Dali::Configuration::ContextLoss configuration);
105 * @copydoc Dali::Application::Lower()
110 * @copydoc Dali::Application::Quit()
115 * @copydoc Dali::Application::AddIdle()
117 bool AddIdle( CallbackBase* callback, bool hasReturnValue );
120 * @copydoc Dali::Application::GetAdaptor();
122 Dali::Adaptor& GetAdaptor();
125 * @copydoc Dali::Application::GetWindow();
127 Dali::Window GetWindow();
130 * @copydoc Dali::Application::GetRegion();
132 std::string GetRegion() const;
135 * @copydoc Dali::Application::GetLanguage();
137 std::string GetLanguage() const;
140 * @copydoc Dali::Application::ReplaceWindow();
142 void ReplaceWindow( const PositionSize& positionSize, const std::string& name);
145 * @copydoc Dali::Application::GetResourcePath();
147 static std::string GetResourcePath();
150 * @copydoc Dali::DevelApplication::GetDataPath()
152 static std::string GetDataPath();
155 * Retrieves the pre-initialized application.
157 * @return A pointer to the pre-initialized application
159 static ApplicationPtr GetPreInitializedApplication();
161 public: // Stereoscopy
164 * @copydoc Dali::Application::SetViewMode()
166 void SetViewMode( ViewMode viewMode );
169 * @copydoc Dali::Application::GetViewMode()
171 ViewMode GetViewMode() const;
174 * @copydoc Dali::Application::SetStereoBase()
176 void SetStereoBase( float stereoBase );
179 * @copydoc Dali::Application::GetStereoBase()
181 float GetStereoBase() const;
183 public: // From Framework::Observer
186 * Called when the framework is initialised.
188 virtual void OnInit();
191 * Called when the framework is terminated.
193 virtual void OnTerminate();
196 * Called when the framework is paused.
198 virtual void OnPause();
201 * Called when the framework resumes from a paused state.
203 virtual void OnResume();
206 * Called when the framework received AppControlSignal.
207 * @param[in] The bundle data of AppControl event.
209 virtual void OnAppControl(void *data);
212 * Called when the framework informs the application that it should reset itself.
214 virtual void OnReset();
217 * Called when the framework informs the application that the language of the device has changed.
219 virtual void OnLanguageChanged();
222 * Called when the framework informs the application that the region of the device has changed.
224 virtual void OnRegionChanged();
227 * Called when the framework informs the application that the battery level of the device is low.
229 virtual void OnBatteryLow( Dali::DeviceStatus::Battery::Status status );
232 * Called when the framework informs the application that the memory level of the device is low.
234 virtual void OnMemoryLow( Dali::DeviceStatus::Memory::Status status );
237 * Called when the framework informs the application that the platform surface is created.
239 virtual void OnSurfaceCreated( Any newSurface );
242 * Called when the framework informs the application that the platform surface is destroyed.
244 virtual void OnSurfaceDestroyed( Any newSurface );
249 * Signal handler when the adaptor's window resizes itself.
250 * @param[in] adaptor The adaptor
252 void OnResize(Dali::Adaptor& adaptor);
255 * Sets a user defined theme file.
256 * This should be called before initialization.
257 * @param[in] stylesheet The path to user defined theme file
259 void SetStyleSheet( const std::string& stylesheet );
262 * Sets a command line options.
263 * This is used in case of the preinitialized application.
264 * @param[in] argc A pointer to the number of arguments
265 * @param[in] argv A pointer to the argument list
267 void SetCommandLineOptions( int* argc, char **argv[] );
272 * @copydoc Dali::Application::InitSignal()
274 Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
277 * @copydoc Dali::Application::TerminateSignal()
279 Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
282 * @copydoc Dali::Application::PauseSignal()
284 Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
287 * @copydoc Dali::Application::ResumeSignal()
289 Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
292 * @copydoc Dali::Application::ResetSignal()
294 Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
297 * @copydoc Dali::Application::AppControlSignal()
299 Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
302 * @copydoc Dali::Application::ResizeSignal()
304 Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
307 * @copydoc Dali::Application::LanguageChangedSignal()
309 Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
312 * @copydoc Dali::Application::RegionChangedSignal()
314 Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
317 * @copydoc Dali::Application::BatteryLowSignal()
319 Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
322 * @copydoc Dali::Application::MemoryLowSignal()
324 Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
327 * @copydoc Dali::Application::LowBatterySignal()
329 Dali::Application::LowBatterySignalType& LowBatterySignal() { return mLowBatterySignal; }
332 * @copydoc Dali::Application:::LowMemorySignal()
334 Dali::Application::LowMemorySignalType& LowMemorySignal() { return mLowMemorySignal; }
339 * Private Constructor
340 * @param[in] argc A pointer to the number of arguments
341 * @param[in] argv A pointer to the argument list
342 * @param[in] stylesheet The path to user defined theme file
343 * @param[in] windowMode A member of Dali::Application::WINDOW_MODE
344 * @param[in] positionSize A position and a size of the window
345 * @param[in] applicationType A member of Dali::Framework::Type
347 Application( int* argc, char **argv[], const std::string& stylesheet,
348 WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
353 virtual ~Application();
356 Application(const Application&);
357 Application& operator=(Application&);
365 * Creates the adaptor
367 void CreateAdaptor();
370 * Creates the adaptor builder
372 void CreateAdaptorBuilder();
375 * Quits from the main loop
377 void QuitFromMainLoop();
381 AppSignalType mInitSignal;
382 AppSignalType mTerminateSignal;
383 AppSignalType mPauseSignal;
384 AppSignalType mResumeSignal;
385 AppSignalType mResetSignal;
386 AppSignalType mResizeSignal;
387 AppControlSignalType mAppControlSignal;
388 AppSignalType mLanguageChangedSignal;
389 AppSignalType mRegionChangedSignal;
390 AppSignalType mBatteryLowSignal;
391 AppSignalType mMemoryLowSignal;
392 LowBatterySignalType mLowBatterySignal;
393 LowMemorySignalType mLowMemorySignal;
395 EventLoop* mEventLoop;
396 Framework* mFramework;
398 Dali::Configuration::ContextLoss mContextLossConfiguration;
399 CommandLineOptions* mCommandLineOptions;
401 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder; ///< The adaptor builder
402 Dali::Adaptor* mAdaptor;
404 // The Main Window is that window created by the Application during initial startup
405 // (previously this was the only window)
406 Dali::Window mMainWindow; ///< Main Window instance
407 Dali::Application::WINDOW_MODE mMainWindowMode; ///< Window mode of the main window
408 std::string mMainWindowName; ///< Name of the main window as obtained from environment options
410 bool mMainWindowReplaced; ///< Whether the main window has been replaced
412 std::string mStylesheet;
413 EnvironmentOptions mEnvironmentOptions;
414 PositionSize mWindowPositionSize;
415 Launchpad::State mLaunchpadState;
416 bool mUseRemoteSurface;
418 SlotDelegate< Application > mSlotDelegate;
423 static ApplicationPtr gPreInitializedApplication;
426 inline Application& GetImplementation(Dali::Application& application)
428 DALI_ASSERT_ALWAYS(application && "application handle is empty");
430 BaseObject& handle = application.GetBaseObject();
432 return static_cast<Internal::Adaptor::Application&>(handle);
435 inline const Application& GetImplementation(const Dali::Application& application)
437 DALI_ASSERT_ALWAYS(application && "application handle is empty");
439 const BaseObject& handle = application.GetBaseObject();
441 return static_cast<const Internal::Adaptor::Application&>(handle);
445 } // namespace Adaptor
447 } // namespace Internal
451 #endif // DALI_INTERNAL_APPLICATION_H