Added SingletonService, removed Singleton APIs from Adaptor & removed Application...
[platform/core/uifw/dali-adaptor.git] / adaptors / common / application-impl.h
1 #ifndef __DALI_INTERNAL_APPLICATION_H__
2 #define __DALI_INTERNAL_APPLICATION_H__
3
4 /*
5  * Copyright (c) 2014 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 <boost/bind.hpp>
23 #include <boost/function.hpp>
24 #include <boost/thread.hpp>
25
26 #include <dali/public-api/math/rect.h>
27 #include <dali/public-api/object/base-object.h>
28
29 // INTERNAL INCLUDES
30 #include <application.h>
31 #include <singleton-service.h>
32
33 #include <framework.h>
34 #include <window-impl.h>
35
36 namespace Dali
37 {
38 class Adaptor;
39 class Window;
40
41 namespace Internal
42 {
43
44 namespace Adaptor
45 {
46 class CommandLineOptions;
47 class EventLoop;
48
49 typedef Dali::Rect<int> PositionSize;
50
51 class Application;
52 typedef IntrusivePtr<Application> ApplicationPtr;
53
54 /**
55  * Implementation of the Application class.
56  */
57 class Application : public BaseObject, public Framework::Observer
58 {
59 public:
60
61   typedef Dali::Application::AppSignalV2 AppSignalV2;
62
63   /**
64    * Constructor
65    * @param[in]  app         The public instance of the Application
66    * @param[in]  argc        A pointer to the number of arguments
67    * @param[in]  argv        A pointer to the argument list
68    * @param[in]  name        A name of application
69    * @param[in]  baseLayout  The base layout that the application has been written for
70    * @param[in]  windowMode  A member of Dali::Application::WINDOW_MODE
71    */
72   static ApplicationPtr New(int* argc, char **argv[], const std::string& name,
73                             const DeviceLayout& baseLayout,
74                             Dali::Application::WINDOW_MODE windowMode);
75
76   Application( int* argc, char **argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode );
77
78   /**
79    * Destructor
80    */
81   virtual ~Application();
82
83 public:
84
85   /**
86    * @copydoc Dali::Application::MainLoop()
87    */
88   void MainLoop();
89
90   /**
91    * @copydoc Dali::Application::Lower()
92    */
93   void Lower();
94
95   /**
96    * @copydoc Dali::Application::Quit()
97    */
98   void Quit();
99
100   /**
101    * @copydoc Dali::Application::AddIdle()
102    */
103   bool AddIdle(boost::function<void(void)> callBack);
104
105   /**
106    * @copydoc Dali::Application::GetAdaptor();
107    */
108   Dali::Adaptor& GetAdaptor();
109
110   /**
111    * @copydoc Dali::Application::GetWindow();
112    */
113   Dali::Window GetWindow();
114
115   /**
116    * @copydoc Dali::Application::GetTheme();
117    */
118   const std::string& GetTheme();
119
120   /**
121    * @copydoc Dali::Application::SetTheme();
122    */
123   void SetTheme(const std::string& themeFilePath);
124
125 public: // Stereoscopy
126
127   /**
128    * @copydoc Dali::Application::SetViewMode()
129    */
130   void SetViewMode( ViewMode viewMode );
131
132   /**
133    * @copydoc Dali::Application::GetViewMode()
134    */
135   ViewMode GetViewMode() const;
136
137   /**
138    * @copydoc Dali::Application::SetStereoBase()
139    */
140   void SetStereoBase( float stereoBase );
141
142   /**
143    * @copydoc Dali::Application::GetStereoBase()
144    */
145   float GetStereoBase() const;
146
147 public: // From Framework::Observer
148
149   /**
150    * Called when the framework is initialised.
151    */
152   virtual void OnInit();
153
154   /**
155    * Called when the framework is terminated.
156    */
157   virtual void OnTerminate();
158
159   /**
160    * Called when the framework is paused.
161    */
162   virtual void OnPause();
163
164   /**
165    * Called when the framework resumes from a paused state.
166    */
167   virtual void OnResume();
168
169   /**
170    * Called when the framework informs the application that it should reset itself.
171    */
172   virtual void OnReset();
173
174   /**
175    * Called when the framework informs the application that the language of the device has changed.
176    */
177   virtual void OnLanguageChanged();
178
179 public:
180
181   /**
182    * Signal handler when the adaptor's window resizes itself.
183    * @param[in]  adaptor  The adaptor
184    */
185   void OnResize(Dali::Adaptor& adaptor);
186
187 public:  // Signals
188
189   /**
190    * @copydoc Dali::Application::InitSignal()
191    */
192   Dali::Application::AppSignalV2& InitSignal() { return mInitSignalV2; }
193
194   /**
195    * @copydoc Dali::Application::TerminateSignal()
196    */
197   Dali::Application::AppSignalV2& TerminateSignal() { return mTerminateSignalV2; }
198
199   /**
200    * @copydoc Dali::Application::PauseSignal()
201    */
202   Dali::Application::AppSignalV2& PauseSignal() { return mPauseSignalV2; }
203
204   /**
205    * @copydoc Dali::Application::ResumeSignal()
206    */
207   Dali::Application::AppSignalV2& ResumeSignal() { return mResumeSignalV2; }
208
209   /**
210    * @copydoc Dali::Application::ResetSignal()
211    */
212   Dali::Application::AppSignalV2& ResetSignal() { return mResetSignalV2; }
213
214   /**
215    * @copydoc Dali::Application::ResizeSignal()
216    */
217   Dali::Application::AppSignalV2& ResizeSignal() { return mResizeSignalV2; }
218
219   /**
220    * @copydoc Dali::Application::LanguageChangedSignal()
221    */
222   Dali::Application::AppSignalV2& LanguageChangedSignal() { return mLanguageChangedSignalV2; }
223
224 private:
225
226   // Undefined
227   Application(const Application&);
228   Application& operator=(Application&);
229
230 private:
231   /**
232    * Creates the window
233    */
234   void CreateWindow();
235
236   /**
237    * Creates the adaptor
238    */
239   void CreateAdaptor();
240
241   /**
242    * Quits from the main loop
243    */
244   void QuitFromMainLoop();
245
246 private:
247
248   AppSignalV2                           mInitSignalV2;
249   AppSignalV2                           mTerminateSignalV2;
250   AppSignalV2                           mPauseSignalV2;
251   AppSignalV2                           mResumeSignalV2;
252   AppSignalV2                           mResetSignalV2;
253   AppSignalV2                           mResizeSignalV2;
254   AppSignalV2                           mLanguageChangedSignalV2;
255
256   EventLoop*                            mEventLoop;
257   Framework*                            mFramework;
258
259   CommandLineOptions*                   mCommandLineOptions;
260
261   Dali::SingletonService                mSingletonService;
262   Dali::Adaptor*                        mAdaptor;
263   Dali::Window                          mWindow;
264   Dali::Application::WINDOW_MODE        mWindowMode;
265   std::string                           mName;
266
267   bool                                  mInitialized;
268   DeviceLayout                          mBaseLayout;
269
270   SlotDelegate< Application >           mSlotDelegate;
271 };
272
273 inline Application& GetImplementation(Dali::Application& application)
274 {
275   DALI_ASSERT_ALWAYS(application && "application handle is empty");
276
277   BaseObject& handle = application.GetBaseObject();
278
279   return static_cast<Internal::Adaptor::Application&>(handle);
280 }
281
282 inline const Application& GetImplementation(const Dali::Application& application)
283 {
284   DALI_ASSERT_ALWAYS(application && "Timre handle is empty");
285
286   const BaseObject& handle = application.GetBaseObject();
287
288   return static_cast<const Internal::Adaptor::Application&>(handle);
289 }
290
291
292 } // namespace Adaptor
293
294 } // namespace Internal
295
296 } // namespace Dali
297
298 #endif // __DALI_INTERNAL_APPLICATION_H__