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 <application.h>
27 #include <singleton-service.h>
29 #include <framework.h>
30 #include <window-impl.h>
31 #include <base/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::AppSignalType AppSignalType;
75 typedef Dali::Application::AppControlSignalType AppControlSignalType;
76 typedef Dali::Application::WINDOW_MODE WINDOW_MODE;
79 * Create a new application
80 * @param[in] argc A pointer to the number of arguments
81 * @param[in] argv A pointer to the argument list
82 * @param[in] stylesheet The path to user defined theme file
83 * @param[in] windowMode A member of Dali::Application::WINDOW_MODE
84 * @param[in] positionSize A position and a size of the window
85 * @param[in] applicationType A member of Dali::Framework::Type
87 static ApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet,
88 WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
91 * @copydoc Dali::DevelApplication::PreInitialize()
93 static void PreInitialize( int* argc, char** argv[] );
98 * @copydoc Dali::Application::MainLoop()
100 void MainLoop(Dali::Configuration::ContextLoss configuration);
103 * @copydoc Dali::Application::Lower()
108 * @copydoc Dali::Application::Quit()
113 * @copydoc Dali::Application::AddIdle()
115 bool AddIdle( CallbackBase* callback );
118 * @copydoc Dali::Application::GetAdaptor();
120 Dali::Adaptor& GetAdaptor();
123 * @copydoc Dali::Application::GetWindow();
125 Dali::Window GetWindow();
128 * @copydoc Dali::Application::ReplaceWindow();
130 void ReplaceWindow( const PositionSize& positionSize, const std::string& name);
133 * @copydoc Dali::Application::GetResourcePath();
135 static std::string GetResourcePath();
138 * Retrieves the pre-initialized application.
140 * @return A pointer to the pre-initialized application
142 static ApplicationPtr GetPreInitializedApplication();
144 public: // Stereoscopy
147 * @copydoc Dali::Application::SetViewMode()
149 void SetViewMode( ViewMode viewMode );
152 * @copydoc Dali::Application::GetViewMode()
154 ViewMode GetViewMode() const;
157 * @copydoc Dali::Application::SetStereoBase()
159 void SetStereoBase( float stereoBase );
162 * @copydoc Dali::Application::GetStereoBase()
164 float GetStereoBase() const;
166 public: // Lifecycle functionality
169 * Called when OnInit is called or the framework is initialised.
174 * Called after OnInit is called or the framework is started.
179 * Called when OnTerminate is called or the framework is terminated.
184 * Called when OnPause is called or the framework is paused.
189 * Called when OnResume is called or the framework resumes from a paused state.
194 * Called when OnLanguageChanged is called or the framework informs the application that the language of the device has changed.
196 void DoLanguageChange();
198 public: // From Framework::Observer
201 * Called when the framework is initialised.
203 virtual void OnInit();
206 * Called when the framework is terminated.
208 virtual void OnTerminate();
211 * Called when the framework is paused.
213 virtual void OnPause();
216 * Called when the framework resumes from a paused state.
218 virtual void OnResume();
221 * Called when the framework received AppControlSignal.
222 * @param[in] The bundle data of AppControl event.
224 virtual void OnAppControl(void *data);
227 * Called when the framework informs the application that it should reset itself.
229 virtual void OnReset();
232 * Called when the framework informs the application that the language of the device has changed.
234 virtual void OnLanguageChanged();
237 * Called when the framework informs the application that the region of the device has changed.
239 virtual void OnRegionChanged();
242 * Called when the framework informs the application that the battery level of the device is low.
244 virtual void OnBatteryLow();
247 * Called when the framework informs the application that the memory level of the device is low.
249 virtual void OnMemoryLow();
254 * Signal handler when the adaptor's window resizes itself.
255 * @param[in] adaptor The adaptor
257 void OnResize(Dali::Adaptor& adaptor);
260 * Sets a user defined theme file.
261 * This should be called before initialization.
262 * @param[in] stylesheet The path to user defined theme file
264 void SetStyleSheet( const std::string& stylesheet );
269 * @copydoc Dali::Application::InitSignal()
271 Dali::Application::AppSignalType& InitSignal() { return mInitSignal; }
274 * @copydoc Dali::Application::TerminateSignal()
276 Dali::Application::AppSignalType& TerminateSignal() { return mTerminateSignal; }
279 * @copydoc Dali::Application::PauseSignal()
281 Dali::Application::AppSignalType& PauseSignal() { return mPauseSignal; }
284 * @copydoc Dali::Application::ResumeSignal()
286 Dali::Application::AppSignalType& ResumeSignal() { return mResumeSignal; }
289 * @copydoc Dali::Application::ResetSignal()
291 Dali::Application::AppSignalType& ResetSignal() { return mResetSignal; }
294 * @copydoc Dali::Application::AppControlSignal()
296 Dali::Application::AppControlSignalType& AppControlSignal() { return mAppControlSignal; }
299 * @copydoc Dali::Application::ResizeSignal()
301 Dali::Application::AppSignalType& ResizeSignal() { return mResizeSignal; }
304 * @copydoc Dali::Application::LanguageChangedSignal()
306 Dali::Application::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
309 * @copydoc Dali::Application::RegionChangedSignal()
311 Dali::Application::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
314 * @copydoc Dali::Application::BatteryLowSignal()
316 Dali::Application::AppSignalType& BatteryLowSignal() { return mBatteryLowSignal; }
319 * @copydoc Dali::Application::MemoryLowSignal()
321 Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; }
326 * Private Constructor
327 * @param[in] argc A pointer to the number of arguments
328 * @param[in] argv A pointer to the argument list
329 * @param[in] stylesheet The path to user defined theme file
330 * @param[in] windowMode A member of Dali::Application::WINDOW_MODE
331 * @param[in] positionSize A position and a size of the window
332 * @param[in] applicationType A member of Dali::Framework::Type
334 Application( int* argc, char **argv[], const std::string& stylesheet,
335 WINDOW_MODE windowMode, const PositionSize& positionSize, Framework::Type applicationType );
340 virtual ~Application();
343 Application(const Application&);
344 Application& operator=(Application&);
352 * Creates the adaptor
354 void CreateAdaptor();
357 * Quits from the main loop
359 void QuitFromMainLoop();
363 AppSignalType mInitSignal;
364 AppSignalType mTerminateSignal;
365 AppSignalType mPauseSignal;
366 AppSignalType mResumeSignal;
367 AppSignalType mResetSignal;
368 AppSignalType mResizeSignal;
369 AppControlSignalType mAppControlSignal;
370 AppSignalType mLanguageChangedSignal;
371 AppSignalType mRegionChangedSignal;
372 AppSignalType mBatteryLowSignal;
373 AppSignalType mMemoryLowSignal;
375 EventLoop* mEventLoop;
376 Framework* mFramework;
378 Dali::Configuration::ContextLoss mContextLossConfiguration;
379 CommandLineOptions* mCommandLineOptions;
381 Dali::SingletonService mSingletonService;
382 Dali::Adaptor* mAdaptor;
383 Dali::Window mWindow;
384 Dali::Application::WINDOW_MODE mWindowMode;
386 std::string mStylesheet;
387 EnvironmentOptions mEnvironmentOptions;
388 PositionSize mWindowPositionSize;
389 Launchpad::State mLaunchpadState;
390 bool mUseRemoteSurface;
392 SlotDelegate< Application > mSlotDelegate;
394 static ApplicationPtr gPreInitializedApplication;
397 inline Application& GetImplementation(Dali::Application& application)
399 DALI_ASSERT_ALWAYS(application && "application handle is empty");
401 BaseObject& handle = application.GetBaseObject();
403 return static_cast<Internal::Adaptor::Application&>(handle);
406 inline const Application& GetImplementation(const Dali::Application& application)
408 DALI_ASSERT_ALWAYS(application && "Timre handle is empty");
410 const BaseObject& handle = application.GetBaseObject();
412 return static_cast<const Internal::Adaptor::Application&>(handle);
416 } // namespace Adaptor
418 } // namespace Internal
422 #endif // __DALI_INTERNAL_APPLICATION_H__