1 #ifndef DALI_INTERNAL_APPLICATION_H
2 #define DALI_INTERNAL_APPLICATION_H
5 * Copyright (c) 2020 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::GetResourcePath();
142 static std::string GetResourcePath();
145 * @copydoc Dali::DevelApplication::GetDataPath()
147 static std::string GetDataPath();
150 * Retrieves the pre-initialized application.
152 * @return A pointer to the pre-initialized application
154 static ApplicationPtr GetPreInitializedApplication();
156 public: // From Framework::Observer
159 * Called when the framework is initialised.
161 virtual void OnInit();
164 * Called when the framework is terminated.
166 virtual void OnTerminate();
169 * Called when the framework is paused.
171 virtual void OnPause();
174 * Called when the framework resumes from a paused state.
176 virtual void OnResume();
179 * Called when the framework received AppControlSignal.
180 * @param[in] The bundle data of AppControl event.
182 virtual void OnAppControl(void *data);
185 * Called when the framework informs the application that it should reset itself.
187 virtual void OnReset();
190 * Called when the framework informs the application that the language of the device has changed.
192 virtual void OnLanguageChanged();
195 * Called when the framework informs the application that the region of the device has changed.
197 virtual void OnRegionChanged();
200 * Called when the framework informs the application that the battery level of the device is low.
202 virtual void OnBatteryLow( Dali::DeviceStatus::Battery::Status status );
205 * Called when the framework informs the application that the memory level of the device is low.
207 virtual void OnMemoryLow( Dali::DeviceStatus::Memory::Status status );
210 * Called when the framework informs the application that the platform surface is created.
212 virtual void OnSurfaceCreated( Any newSurface );
215 * Called when the framework informs the application that the platform surface is destroyed.
217 virtual void OnSurfaceDestroyed( Any newSurface );
222 * Sets a user defined theme file.
223 * This should be called before initialization.
224 * @param[in] stylesheet The path to user defined theme file
226 void SetStyleSheet( const std::string& stylesheet );
229 * Sets a command line options.
230 * This is used in case of the preinitialized application.
231 * @param[in] argc A pointer to the number of arguments
232 * @param[in] argv A pointer to the argument list
234 void SetCommandLineOptions( int* argc, char **argv[] );
239 * @copydoc Dali::Application::InitSignal()
241 Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
244 * @copydoc Dali::Application::TerminateSignal()
246 Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
249 * @copydoc Dali::Application::PauseSignal()
251 Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
254 * @copydoc Dali::Application::ResumeSignal()
256 Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
259 * @copydoc Dali::Application::ResetSignal()
261 Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
264 * @copydoc Dali::Application::AppControlSignal()
266 Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
269 * @copydoc Dali::Application::LanguageChangedSignal()
271 Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
274 * @copydoc Dali::Application::RegionChangedSignal()
276 Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
279 * @copydoc Dali::Application::LowBatterySignal()
281 Dali::Application::LowBatterySignalType& LowBatterySignal() { return mLowBatterySignal; }
284 * @copydoc Dali::Application:::LowMemorySignal()
286 Dali::Application::LowMemorySignalType& LowMemorySignal() { return mLowMemorySignal; }
291 * Private Constructor
292 * @param[in] argc A pointer to the number of arguments
293 * @param[in] argv A pointer to the argument list
294 * @param[in] stylesheet The path to user defined theme file
295 * @param[in] windowMode A member of Dali::Application::WINDOW_MODE
296 * @param[in] positionSize A position and a size of the window
297 * @param[in] applicationType A member of Dali::Framework::Type
299 Application( int* argc, char **argv[], const std::string& stylesheet,
300 WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
305 virtual ~Application();
308 Application(const Application&);
309 Application& operator=(Application&);
317 * Creates the adaptor
319 void CreateAdaptor();
322 * Creates the adaptor builder
324 void CreateAdaptorBuilder();
327 * Quits from the main loop
329 void QuitFromMainLoop();
333 AppSignalType mInitSignal;
334 AppSignalType mTerminateSignal;
335 AppSignalType mPauseSignal;
336 AppSignalType mResumeSignal;
337 AppSignalType mResetSignal;
338 AppControlSignalType mAppControlSignal;
339 AppSignalType mLanguageChangedSignal;
340 AppSignalType mRegionChangedSignal;
341 LowBatterySignalType mLowBatterySignal;
342 LowMemorySignalType mLowMemorySignal;
344 EventLoop* mEventLoop;
345 Framework* mFramework;
347 Dali::Configuration::ContextLoss mContextLossConfiguration;
348 CommandLineOptions* mCommandLineOptions;
350 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder; ///< The adaptor builder
351 Dali::Adaptor* mAdaptor;
353 // The Main Window is that window created by the Application during initial startup
354 // (previously this was the only window)
355 Dali::Window mMainWindow; ///< Main Window instance
356 Dali::Application::WINDOW_MODE mMainWindowMode; ///< Window mode of the main window
357 std::string mMainWindowName; ///< Name of the main window as obtained from environment options
359 std::string mStylesheet;
360 EnvironmentOptions mEnvironmentOptions;
361 PositionSize mWindowPositionSize;
362 Launchpad::State mLaunchpadState;
363 bool mUseRemoteSurface;
365 SlotDelegate< Application > mSlotDelegate;
367 static ApplicationPtr gPreInitializedApplication;
370 inline Application& GetImplementation(Dali::Application& application)
372 DALI_ASSERT_ALWAYS(application && "application handle is empty");
374 BaseObject& handle = application.GetBaseObject();
376 return static_cast<Internal::Adaptor::Application&>(handle);
379 inline const Application& GetImplementation(const Dali::Application& application)
381 DALI_ASSERT_ALWAYS(application && "application handle is empty");
383 const BaseObject& handle = application.GetBaseObject();
385 return static_cast<const Internal::Adaptor::Application&>(handle);
389 } // namespace Adaptor
391 } // namespace Internal
395 #endif // DALI_INTERNAL_APPLICATION_H