1 #ifndef __DALI_INTERNAL_APPLICATION_H__
2 #define __DALI_INTERNAL_APPLICATION_H__
5 * Copyright (c) 2017 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>
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 );
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 * Retrieves the pre-initialized application.
152 * @return A pointer to the pre-initialized application
154 static ApplicationPtr GetPreInitializedApplication();
156 public: // Stereoscopy
159 * @copydoc Dali::Application::SetViewMode()
161 void SetViewMode( ViewMode viewMode );
164 * @copydoc Dali::Application::GetViewMode()
166 ViewMode GetViewMode() const;
169 * @copydoc Dali::Application::SetStereoBase()
171 void SetStereoBase( float stereoBase );
174 * @copydoc Dali::Application::GetStereoBase()
176 float GetStereoBase() const;
178 public: // Lifecycle functionality
181 * Called when OnInit is called or the framework is initialised.
186 * Called after OnInit is called or the framework is started.
191 * Called when OnTerminate is called or the framework is terminated.
196 * Called when OnPause is called or the framework is paused.
201 * Called when OnResume is called or the framework resumes from a paused state.
206 * Called when OnLanguageChanged is called or the framework informs the application that the language of the device has changed.
208 void DoLanguageChange();
210 public: // From Framework::Observer
213 * Called when the framework is initialised.
215 virtual void OnInit();
218 * Called when the framework is terminated.
220 virtual void OnTerminate();
223 * Called when the framework is paused.
225 virtual void OnPause();
228 * Called when the framework resumes from a paused state.
230 virtual void OnResume();
233 * Called when the framework received AppControlSignal.
234 * @param[in] The bundle data of AppControl event.
236 virtual void OnAppControl(void *data);
239 * Called when the framework informs the application that it should reset itself.
241 virtual void OnReset();
244 * Called when the framework informs the application that the language of the device has changed.
246 virtual void OnLanguageChanged();
249 * Called when the framework informs the application that the region of the device has changed.
251 virtual void OnRegionChanged();
254 * Called when the framework informs the application that the battery level of the device is low.
256 virtual void OnBatteryLow( Dali::DeviceStatus::Battery::Status status );
259 * Called when the framework informs the application that the memory level of the device is low.
261 virtual void OnMemoryLow( Dali::DeviceStatus::Memory::Status status );
266 * Signal handler when the adaptor's window resizes itself.
267 * @param[in] adaptor The adaptor
269 void OnResize(Dali::Adaptor& adaptor);
272 * Sets a user defined theme file.
273 * This should be called before initialization.
274 * @param[in] stylesheet The path to user defined theme file
276 void SetStyleSheet( const std::string& stylesheet );
281 * @copydoc Dali::Application::InitSignal()
283 Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
286 * @copydoc Dali::Application::TerminateSignal()
288 Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
291 * @copydoc Dali::Application::PauseSignal()
293 Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
296 * @copydoc Dali::Application::ResumeSignal()
298 Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
301 * @copydoc Dali::Application::ResetSignal()
303 Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
306 * @copydoc Dali::Application::AppControlSignal()
308 Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
311 * @copydoc Dali::Application::ResizeSignal()
313 Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
316 * @copydoc Dali::Application::LanguageChangedSignal()
318 Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
321 * @copydoc Dali::Application::RegionChangedSignal()
323 Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
326 * @copydoc Dali::Application::BatteryLowSignal()
328 Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
331 * @copydoc Dali::Application::MemoryLowSignal()
333 Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
336 * @copydoc Dali::Application::LowBatterySignal()
338 Dali::Application::LowBatterySignalType& LowBatterySignal() { return mLowBatterySignal; }
341 * @copydoc Dali::Application:::LowMemorySignal()
343 Dali::Application::LowMemorySignalType& LowMemorySignal() { return mLowMemorySignal; }
348 * Private Constructor
349 * @param[in] argc A pointer to the number of arguments
350 * @param[in] argv A pointer to the argument list
351 * @param[in] stylesheet The path to user defined theme file
352 * @param[in] windowMode A member of Dali::Application::WINDOW_MODE
353 * @param[in] positionSize A position and a size of the window
354 * @param[in] applicationType A member of Dali::Framework::Type
356 Application( int* argc, char **argv[], const std::string& stylesheet,
357 WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
362 virtual ~Application();
365 Application(const Application&);
366 Application& operator=(Application&);
374 * Creates the adaptor
376 void CreateAdaptor();
379 * Quits from the main loop
381 void QuitFromMainLoop();
385 AppSignalType mInitSignal;
386 AppSignalType mTerminateSignal;
387 AppSignalType mPauseSignal;
388 AppSignalType mResumeSignal;
389 AppSignalType mResetSignal;
390 AppSignalType mResizeSignal;
391 AppControlSignalType mAppControlSignal;
392 AppSignalType mLanguageChangedSignal;
393 AppSignalType mRegionChangedSignal;
394 AppSignalType mBatteryLowSignal;
395 AppSignalType mMemoryLowSignal;
396 LowBatterySignalType mLowBatterySignal;
397 LowMemorySignalType mLowMemorySignal;
399 EventLoop* mEventLoop;
400 Framework* mFramework;
402 Dali::Configuration::ContextLoss mContextLossConfiguration;
403 CommandLineOptions* mCommandLineOptions;
405 Dali::SingletonService mSingletonService;
406 Dali::Adaptor* mAdaptor;
407 Dali::Window mWindow;
408 Dali::Application::WINDOW_MODE mWindowMode;
410 std::string mStylesheet;
411 EnvironmentOptions mEnvironmentOptions;
412 PositionSize mWindowPositionSize;
413 Launchpad::State mLaunchpadState;
414 bool mUseRemoteSurface;
416 SlotDelegate< Application > mSlotDelegate;
418 static ApplicationPtr gPreInitializedApplication;
421 inline Application& GetImplementation(Dali::Application& application)
423 DALI_ASSERT_ALWAYS(application && "application handle is empty");
425 BaseObject& handle = application.GetBaseObject();
427 return static_cast<Internal::Adaptor::Application&>(handle);
430 inline const Application& GetImplementation(const Dali::Application& application)
432 DALI_ASSERT_ALWAYS(application && "Timre handle is empty");
434 const BaseObject& handle = application.GetBaseObject();
436 return static_cast<const Internal::Adaptor::Application&>(handle);
440 } // namespace Adaptor
442 } // namespace Internal
446 #endif // __DALI_INTERNAL_APPLICATION_H__