1 #ifndef DALI_INTERNAL_APPLICATION_H
2 #define DALI_INTERNAL_APPLICATION_H
5 * Copyright (c) 2021 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/devel-api/common/singleton-service.h>
27 #include <dali/public-api/adaptor-framework/application.h>
29 #include <dali/internal/adaptor/common/adaptor-builder-impl.h>
30 #include <dali/internal/adaptor/common/framework.h>
31 #include <dali/internal/system/common/environment-options.h>
45 * @brief Launchpad is used to improve application launch performance.
46 * When an application is pre-initialized, so files are preloaded, some functions are initialized and a window is made in advance.
50 NONE, ///< The default state
51 PRE_INITIALIZED ///< Application is pre-initialized.
54 } // namespace Launchpad
56 class CommandLineOptions;
59 typedef Dali::Rect<int> PositionSize;
62 typedef IntrusivePtr<Application> ApplicationPtr;
65 * Implementation of the Application class.
67 class Application : public BaseObject, public Framework::Observer
70 typedef Dali::Application::LowBatterySignalType LowBatterySignalType;
71 typedef Dali::Application::LowMemorySignalType LowMemorySignalType;
72 typedef Dali::Application::AppSignalType AppSignalType;
73 typedef Dali::Application::AppControlSignalType AppControlSignalType;
74 typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
77 * Create a new application
78 * @param[in] argc A pointer to the number of arguments
79 * @param[in] argv A pointer to the argument list
80 * @param[in] stylesheet The path to user defined theme file
81 * @param[in] windowMode A member of Dali::Application::WINDOW_MODE
82 * @param[in] positionSize A position and a size of the window
83 * @param[in] applicationType A member of Dali::Framework::Type
85 static ApplicationPtr New(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType);
88 * @copydoc Dali::DevelApplication::PreInitialize()
90 static void PreInitialize(int* argc, char** argv[]);
94 * @copydoc Dali::Application::MainLoop()
99 * @copydoc Dali::Application::Lower()
104 * @copydoc Dali::Application::Quit()
109 * @copydoc Dali::Application::AddIdle()
111 bool AddIdle(CallbackBase* callback, bool hasReturnValue);
114 * @copydoc Dali::Application::GetAdaptor();
116 Dali::Adaptor& GetAdaptor();
119 * @copydoc Dali::Application::GetWindow();
121 Dali::Window GetWindow();
124 * @copydoc Dali::Application::GetRegion();
126 std::string GetRegion() const;
129 * @copydoc Dali::Application::GetLanguage();
131 std::string GetLanguage() const;
134 * @copydoc Dali::Application::GetObjectRegistry();
136 Dali::ObjectRegistry GetObjectRegistry() const;
139 * @copydoc Dali::Application::GetResourcePath();
141 static std::string GetResourcePath();
144 * @copydoc Dali::DevelApplication::GetDataPath()
146 static std::string GetDataPath();
149 * Retrieves the pre-initialized application.
151 * @return A pointer to the pre-initialized application
153 static ApplicationPtr GetPreInitializedApplication();
155 public: // From Framework::Observer
157 * Called when the framework is initialised.
159 void OnInit() override;
162 * Called when the framework is terminated.
164 void OnTerminate() override;
167 * Called when the framework is paused.
169 void OnPause() override;
172 * Called when the framework resumes from a paused state.
174 void OnResume() override;
177 * Called when the framework received AppControlSignal.
178 * @param[in] The bundle data of AppControl event.
180 void OnAppControl(void* data) override;
183 * Called when the framework informs the application that it should reset itself.
185 void OnReset() override;
188 * Called when the framework informs the application that the language of the device has changed.
190 void OnLanguageChanged() override;
193 * Called when the framework informs the application that the region of the device has changed.
195 void OnRegionChanged() override;
198 * Called when the framework informs the application that the battery level of the device is low.
200 void OnBatteryLow(Dali::DeviceStatus::Battery::Status status) override;
203 * Called when the framework informs the application that the memory level of the device is low.
205 void OnMemoryLow(Dali::DeviceStatus::Memory::Status status) override;
208 * Called when the framework informs the application that the platform surface is created.
210 void OnSurfaceCreated(Any newSurface) override;
213 * Called when the framework informs the application that the platform surface is destroyed.
215 void OnSurfaceDestroyed(Any newSurface) override;
219 * Sets a user defined theme file.
220 * This should be called before initialization.
221 * @param[in] stylesheet The path to user defined theme file
223 void SetStyleSheet(const std::string& stylesheet);
226 * Sets a command line options.
227 * This is used in case of the preinitialized application.
228 * @param[in] argc A pointer to the number of arguments
229 * @param[in] argv A pointer to the argument list
231 void SetCommandLineOptions(int* argc, char** argv[]);
235 * @copydoc Dali::Application::InitSignal()
237 Dali::Application::AppSignalType& InitSignal()
243 * @copydoc Dali::Application::TerminateSignal()
245 Dali::Application::AppSignalType& TerminateSignal()
247 return mTerminateSignal;
251 * @copydoc Dali::Application::PauseSignal()
253 Dali::Application::AppSignalType& PauseSignal()
259 * @copydoc Dali::Application::ResumeSignal()
261 Dali::Application::AppSignalType& ResumeSignal()
263 return mResumeSignal;
267 * @copydoc Dali::Application::ResetSignal()
269 Dali::Application::AppSignalType& ResetSignal()
275 * @copydoc Dali::Application::AppControlSignal()
277 Dali::Application::AppControlSignalType& AppControlSignal()
279 return mAppControlSignal;
283 * @copydoc Dali::Application::LanguageChangedSignal()
285 Dali::Application::AppSignalType& LanguageChangedSignal()
287 return mLanguageChangedSignal;
291 * @copydoc Dali::Application::RegionChangedSignal()
293 Dali::Application::AppSignalType& RegionChangedSignal()
295 return mRegionChangedSignal;
299 * @copydoc Dali::Application::LowBatterySignal()
301 Dali::Application::LowBatterySignalType& LowBatterySignal()
303 return mLowBatterySignal;
307 * @copydoc Dali::Application:::LowMemorySignal()
309 Dali::Application::LowMemorySignalType& LowMemorySignal()
311 return mLowMemorySignal;
314 // Temporary to test GFXApi
315 Graphics::Controller& GetController();
319 * Private Constructor
320 * @param[in] argc A pointer to the number of arguments
321 * @param[in] argv A pointer to the argument list
322 * @param[in] stylesheet The path to user defined theme file
323 * @param[in] windowMode A member of Dali::Application::WINDOW_MODE
324 * @param[in] positionSize A position and a size of the window
325 * @param[in] applicationType A member of Dali::Framework::Type
327 Application(int* argc, char** argv[], const std::string& stylesheet, WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType);
332 ~Application() override;
335 Application(const Application&);
336 Application& operator=(Application&);
344 * Creates the adaptor
346 void CreateAdaptor();
349 * Creates the adaptor builder
351 void CreateAdaptorBuilder();
354 * Quits from the main loop
356 void QuitFromMainLoop();
359 AppSignalType mInitSignal;
360 AppSignalType mTerminateSignal;
361 AppSignalType mPauseSignal;
362 AppSignalType mResumeSignal;
363 AppSignalType mResetSignal;
364 AppControlSignalType mAppControlSignal;
365 AppSignalType mLanguageChangedSignal;
366 AppSignalType mRegionChangedSignal;
367 LowBatterySignalType mLowBatterySignal;
368 LowMemorySignalType mLowMemorySignal;
370 EventLoop* mEventLoop;
371 Framework* mFramework;
373 CommandLineOptions* mCommandLineOptions;
375 Dali::Internal::Adaptor::AdaptorBuilder* mAdaptorBuilder; ///< The adaptor builder
376 Dali::Adaptor* mAdaptor;
378 // The Main Window is that window created by the Application during initial startup
379 // (previously this was the only window)
380 Dali::Window mMainWindow; ///< Main Window instance
381 Dali::Application::WINDOW_MODE mMainWindowMode; ///< Window mode of the main window
382 std::string mMainWindowName; ///< Name of the main window as obtained from environment options
384 std::string mStylesheet;
385 EnvironmentOptions mEnvironmentOptions;
386 PositionSize mWindowPositionSize;
387 Launchpad::State mLaunchpadState;
388 bool mUseRemoteSurface;
390 SlotDelegate<Application> mSlotDelegate;
392 static ApplicationPtr gPreInitializedApplication;
395 inline Application& GetImplementation(Dali::Application& application)
397 DALI_ASSERT_ALWAYS(application && "application handle is empty");
399 BaseObject& handle = application.GetBaseObject();
401 return static_cast<Internal::Adaptor::Application&>(handle);
404 inline const Application& GetImplementation(const Dali::Application& application)
406 DALI_ASSERT_ALWAYS(application && "application handle is empty");
408 const BaseObject& handle = application.GetBaseObject();
410 return static_cast<const Internal::Adaptor::Application&>(handle);
413 } // namespace Adaptor
415 } // namespace Internal
419 #endif // DALI_INTERNAL_APPLICATION_H