6f53534e7835271220f95a126b29139aab8cc9da
[platform/core/uifw/dali-adaptor.git] / adaptors / common / widget-application-impl.h
1 #ifndef __DALI_INTERNAL_WIDGET_APPLICATION_H__
2 #define __DALI_INTERNAL_WIDGET_APPLICATION_H__
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-object.h>
23 #include <widget_base.h>
24 #include <bundle.h>
25
26 // INTERNAL INCLUDES
27 #include <widget-application.h>
28 #include <singleton-service.h>
29
30 #include <framework.h>
31 #include <window.h>
32 #include <base/environment-options.h>
33
34 namespace Dali
35 {
36 class Adaptor;
37
38 namespace Internal
39 {
40
41 namespace Adaptor
42 {
43 class CommandLineOptions;
44 class EventLoop;
45
46 class WidgetApplication;
47 typedef IntrusivePtr<WidgetApplication> WidgetApplicationPtr;
48
49 /**
50  * Implementation of the WidgetApplication class.
51  */
52 class WidgetApplication : public BaseObject, public Framework::Observer
53 {
54 public:
55   typedef Dali::WidgetApplication::AppSignalType AppSignalType;
56   typedef Dali::WidgetApplication::LowBatterySignalType LowBatterySignalType;
57   typedef Dali::WidgetApplication::LowMemorySignalType LowMemorySignalType;
58
59   /**
60    * Create a new widget application
61    * @param[in]  argc         A pointer to the number of arguments
62    * @param[in]  argv         A pointer to the argument list
63    * @param[in]  stylesheet   The path to user defined theme file
64    */
65   static WidgetApplicationPtr New( int* argc, char **argv[], const std::string& stylesheet );
66
67 public:
68
69   /**
70    * @copydoc Dali::WidgetApplication::MainLoop()
71    */
72   void MainLoop();
73
74   /**
75    * @copydoc Dali::WidgetApplication::Quit()
76    */
77   void Quit();
78
79   /**
80    * @copydoc Dali::WidgetApplication::GetAdaptor();
81    */
82   Dali::Adaptor& GetAdaptor();
83
84   /**
85    * @copydoc Dali::WidgetApplication::GetResourcePath();
86    */
87   static std::string GetResourcePath();
88
89   /**
90    * @copydoc Dali::WidgetApplication::GetRegion();
91    */
92   std::string GetRegion();
93
94   /**
95    * @copydoc Dali::WidgetApplication::GetLanguage();
96    */
97   std::string GetLanguage();
98
99 public: // Lifecycle functionality
100
101   /**
102    * Called when OnInit is called or the framework is initialised.
103    */
104   void DoInit();
105
106   /**
107    * Called after OnInit is called or the framework is started.
108    */
109   void DoStart();
110
111   /**
112    * Called when OnTerminate is called or the framework is terminated.
113    */
114   void DoTerminate();
115
116   /**
117    * Called when OnLanguageChanged is called or the framework informs the application that the language of the device has changed.
118    */
119   void DoLanguageChange();
120
121 public: // From Framework::Observer
122
123   /**
124    * Called when the framework is initialised.
125    */
126   virtual void OnInit();
127
128   /**
129    * Called when the framework is terminated.
130    */
131   virtual void OnTerminate();
132
133   /**
134    * Called when the framework informs the application that the language of the device has changed.
135    */
136   virtual void OnLanguageChanged();
137
138   /**
139   * Called when the framework informs the application that the region of the device has changed.
140   */
141   virtual void OnRegionChanged();
142
143   /**
144   * Called when the framework informs the application that the battery level of the device is low.
145   */
146   virtual void OnBatteryLow( Dali::DeviceStatus::Battery::Status status );
147
148   /**
149   * Called when the framework informs the application that the memory level of the device is low.
150   */
151   virtual void OnMemoryLow( Dali::DeviceStatus::Memory::Status status );
152
153 public:  // Signals
154
155   /**
156    * @copydoc Dali::WidgetApplication::InitSignal()
157    */
158    Dali::WidgetApplication::AppSignalType& InitSignal() { return mInitSignal; }
159
160   /**
161    * @copydoc Dali::WidgetApplication::TerminateSignal()
162    */
163   Dali::WidgetApplication::AppSignalType& TerminateSignal() { return mTerminateSignal; }
164
165   /**
166    * @copydoc Dali::WidgetApplication::LanguageChangedSignal()
167    */
168   Dali::WidgetApplication::AppSignalType& LanguageChangedSignal() { return mLanguageChangedSignal; }
169
170   /**
171   * @copydoc Dali::WidgetApplication::RegionChangedSignal()
172   */
173   Dali::WidgetApplication::AppSignalType& RegionChangedSignal() { return mRegionChangedSignal; }
174
175   /**
176   * @copydoc Dali::WidgetApplication::LowBatterySignal()
177   */
178   Dali::WidgetApplication::LowBatterySignalType& LowBatterySignal() { return mLowBatterySignal; }
179
180   /**
181   * @copydoc Dali::WidgetApplication::LowMemorySignal()
182   */
183   Dali::WidgetApplication::LowMemorySignalType& LowMemorySignal() { return mLowMemorySignal; }
184
185 protected:
186
187   /**
188    * Private Constructor
189    * @param[in]  argc         A pointer to the number of arguments
190    * @param[in]  argv         A pointer to the argument list
191    * @param[in]  stylesheet   The path to user defined theme file
192    */
193   WidgetApplication( int* argc, char **argv[], const std::string& stylesheet );
194
195   /**
196    * Destructor
197    */
198   virtual ~WidgetApplication();
199
200   // Undefined
201   WidgetApplication(const Application&);
202   WidgetApplication& operator=(Application&);
203
204   /**
205    * Creates the adaptor
206    */
207   void CreateAdaptor();
208
209   /**
210    * Quits from the main loop
211    */
212   void QuitFromMainLoop();
213
214   /**
215    * Add idle
216    */
217   bool AddIdle( CallbackBase* callback );
218
219 private:
220
221   AppSignalType                         mInitSignal;
222   AppSignalType                         mTerminateSignal;
223   AppSignalType                         mLanguageChangedSignal;
224   AppSignalType                         mRegionChangedSignal;
225   LowBatterySignalType                  mLowBatterySignal;
226   LowMemorySignalType                   mLowMemorySignal;
227
228   Framework*                            mFramework;
229
230   Dali::Configuration::ContextLoss      mContextLossConfiguration;
231   CommandLineOptions*                   mCommandLineOptions;
232
233   Dali::SingletonService                mSingletonService;
234   Dali::Adaptor*                        mAdaptor;
235   Dali::Window                          mWindow;
236   std::string                           mName;
237   std::string                           mStylesheet;
238   EnvironmentOptions                    mEnvironmentOptions;
239
240   SlotDelegate< WidgetApplication >     mSlotDelegate;
241 };
242
243 inline WidgetApplication& GetImplementation(Dali::WidgetApplication& widgetApplication)
244 {
245   DALI_ASSERT_ALWAYS(widgetApplication && "widget application handle is empty");
246
247   BaseObject& handle = widgetApplication.GetBaseObject();
248
249   return static_cast<Internal::Adaptor::WidgetApplication&>(handle);
250 }
251
252 inline const WidgetApplication& GetImplementation(const Dali::WidgetApplication& widgetApplication)
253 {
254   DALI_ASSERT_ALWAYS(widgetApplication && "widget application handle is empty");
255
256   const BaseObject& handle = widgetApplication.GetBaseObject();
257
258   return static_cast<const Internal::Adaptor::WidgetApplication&>(handle);
259 }
260
261 } // namespace Adaptor
262
263 } // namespace Internal
264
265 } // namespace Dali
266
267 #endif // __DALI_INTERNAL_WIDGET_APPLICATION_H__