[4.0] Create Widget Application
[platform/core/uifw/dali-adaptor.git] / adaptors / common / framework.h
1 #ifndef __DALI_INTERNAL_FRAMEWORK_H__
2 #define __DALI_INTERNAL_FRAMEWORK_H__
3
4 /*
5  * Copyright (c) 2016 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 <string>
23 #include <dali/public-api/signals/callback.h>
24 #ifdef APPCORE_WATCH_AVAILABLE
25 #include "wearable/watch/watch-application.h"
26 #endif
27
28 // INTERNAL INCLUDES
29 #include <abort-handler.h>
30 #include <device-status.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40
41 /**
42  * The Framework class is ideally placed to provide key API required by Applications.
43  *
44  * The class is also used to register callbacks with the TIZEN platform so that
45  * we know when any of the application lifecycle events occur.  This includes events
46  * like when our application is to be initialised, terminated, paused, resumed etc.
47  *
48  */
49 class Framework
50 {
51 public:
52
53   enum Type
54   {
55     NORMAL,       ///< normal appFramework
56     WATCH,        ///< watch appFramework
57     WIDGET,       ///< widget appFramework
58   };
59
60   /**
61    * Observer class for the framework.
62    */
63   class Observer
64   {
65   public:
66
67     /**
68      * Invoked when the application is to be initialised.
69      */
70     virtual void OnInit() {}
71
72     /**
73      * Invoked when the application is to be terminated.
74      */
75     virtual void OnTerminate() {}
76
77     /**
78      * Invoked when the application is to be paused.
79      */
80     virtual void OnPause() {}
81
82     /**
83      * Invoked when the application is to be resumed.
84      */
85     virtual void OnResume() {}
86
87     /**
88      * Invoked when the application is to be reset.
89      */
90     virtual void OnReset() {}
91
92     /**
93     * Invoked when the AppControl message is received.
94     * @param[in] The bundle data of AppControl message.
95     */
96     virtual void OnAppControl(void *) {}
97
98 #ifdef APPCORE_WATCH_AVAILABLE
99     /**
100      * Invoked at every second
101      */
102     virtual void OnTimeTick(WatchTime&) {}
103
104     /**
105      * Invoked at every second in ambient mode
106      */
107     virtual void OnAmbientTick(WatchTime&) {}
108
109     /**
110      * Invoked when the device enters or exits ambient mode
111      */
112     virtual void OnAmbientChanged(bool ambient) {}
113 #endif
114
115     /**
116      * Invoked when the language of the device is changed.
117      */
118     virtual void OnLanguageChanged() {}
119
120     /**
121     * Invoked when the region is changed.
122     */
123     virtual void OnRegionChanged() {}
124
125     /**
126     * Invoked when the battery level of the device is low.
127     */
128     virtual void OnBatteryLow( Dali::DeviceStatus::Battery::Status status ) {}
129
130     /**
131     * Invoked when the memory level of the device is low.
132     */
133     virtual void OnMemoryLow( Dali::DeviceStatus::Memory::Status status ) {}
134   };
135
136 public:
137
138   /**
139    * Constructor
140    * @param[in]  observer  The observer of the Framework.
141    * @param[in]  argc      A pointer to the number of arguments.
142    * @param[in]  argv      A pointer the the argument list.
143    * @param[in]  type      The type of application
144    */
145   Framework( Observer& observer, int* argc, char ***argv, Type type = NORMAL );
146
147   /**
148    * Destructor
149    */
150   ~Framework();
151
152 public:
153
154   /**
155    * Runs the main loop of framework
156    */
157   void Run();
158
159   /**
160    * Quits the main loop
161    */
162   void Quit();
163
164   /**
165    * Checks whether the main loop of the framework is running.
166    * @return true, if the main loop is running, false otherwise.
167    */
168   bool IsMainLoopRunning();
169
170   /**
171    * If the main loop aborts unexpectedly, then the connected callback function is called.
172    * @param[in]  callBack  The function to call.
173    * @note Only one callback can be registered.  The last callback to be set will be called on abort.
174    * @note The ownership of callback is passed onto this class.
175    */
176   void AddAbortCallback( CallbackBase* callback );
177
178   /**
179    * Gets bundle name which was passed in app_reset callback.
180    */
181   std::string GetBundleName() const;
182
183   /**
184    * Gets bundle id which was passed in app_reset callback.
185    */
186   std::string GetBundleId() const;
187
188   /**
189    *  Gets the path at which application resources are stored.
190    */
191   static std::string GetResourcePath();
192
193   /**
194    * Sets system language.
195    */
196   void SetLanguage( const std::string& language );
197
198   /**
199    * Sets system region.
200    */
201   void SetRegion( const std::string& region );
202
203   /**
204    * Gets system language.
205    */
206   std::string GetLanguage() const;
207
208   /**
209    * Gets system region.
210    */
211   std::string GetRegion() const;
212
213 private:
214
215   // Undefined
216   Framework(const Framework&);
217   Framework& operator=(Framework&);
218
219 private:
220
221   /**
222    * Called when the application is created.
223    */
224   bool Create();
225
226   /**
227    * Called by the App framework when an application lifecycle event occurs.
228    * @param[in] type The type of event occurred.
229    * @param[in] bundleData The bundle data of event occurred.
230    */
231   bool AppStatusHandler(int type, void *bundleData);
232
233   /**
234    * Called app_reset callback was called with bundle.
235    */
236   void SetBundleName(const std::string& name);
237
238   /**
239    * Called app_reset callback was called with bundle.
240    */
241   void SetBundleId(const std::string& id);
242
243   /**
244    * Called if the application is aborted.
245    */
246   void AbortCallback();
247
248   /**
249    * Called for initializing on specified backend. (X11 or Wayland)
250    */
251   void InitThreads();
252
253 private:
254   Observer&          mObserver;
255   bool               mInitialised;
256   bool               mRunning;
257   int*               mArgc;
258   char***            mArgv;
259   std::string        mBundleName;
260   std::string        mBundleId;
261   AbortHandler       mAbortHandler;
262
263 private: // impl members
264
265   struct Impl;
266   Impl* mImpl;
267 };
268
269 } // namespace Adaptor
270
271 } // namespace Internal
272
273 } // namespace Dali
274
275 #endif // __DALI_INTERNAL_FRAMEWORK_H__