Revert "[Tizen] Implement partial update"
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / common / framework.h
1 #ifndef DALI_INTERNAL_FRAMEWORK_H
2 #define DALI_INTERNAL_FRAMEWORK_H
3
4 /*
5  * Copyright (c) 2019 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 <dali/public-api/watch/watch-application.h>
26 #endif
27
28 // INTERNAL INCLUDES
29 #include <dali/internal/system/common/abort-handler.h>
30 #include <dali/public-api/adaptor-framework/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    * Sets a command line options.
190    * This is used in case of the preinitialized application.
191    * @param[in] argc A pointer to the number of arguments
192    * @param[in] argv A pointer to the argument list
193    */
194   void SetCommandLineOptions( int* argc, char **argv[] )
195   {
196     mArgc = argc;
197     mArgv = argv;
198   }
199
200
201   /**
202    *  Gets the path at which application resources are stored.
203    */
204   static std::string GetResourcePath();
205
206   /**
207    *  Gets the path at which application data are stored.
208    */
209   static std::string GetDataPath();
210
211   /**
212    * Sets system language.
213    */
214   void SetLanguage( const std::string& language );
215
216   /**
217    * Sets system region.
218    */
219   void SetRegion( const std::string& region );
220
221   /**
222    * Gets system language.
223    */
224   std::string GetLanguage() const;
225
226   /**
227    * Gets system region.
228    */
229   std::string GetRegion() const;
230
231 private:
232
233   // Undefined
234   Framework(const Framework&);
235   Framework& operator=(Framework&);
236
237 private:
238
239   /**
240    * Called when the application is created.
241    */
242   bool Create();
243
244   /**
245    * Called by the App framework when an application lifecycle event occurs.
246    * @param[in] type The type of event occurred.
247    * @param[in] bundleData The bundle data of event occurred.
248    */
249   bool AppStatusHandler(int type, void *bundleData);
250
251   /**
252    * Called app_reset callback was called with bundle.
253    */
254   void SetBundleName(const std::string& name);
255
256   /**
257    * Called app_reset callback was called with bundle.
258    */
259   void SetBundleId(const std::string& id);
260
261   /**
262    * Called if the application is aborted.
263    */
264   void AbortCallback();
265
266   /**
267    * Called for initializing on specified backend. (X11 or Wayland)
268    */
269   void InitThreads();
270
271 private:
272   Observer&          mObserver;
273   bool               mInitialised;
274   bool               mRunning;
275   int*               mArgc;
276   char***            mArgv;
277   std::string        mBundleName;
278   std::string        mBundleId;
279   AbortHandler       mAbortHandler;
280
281 private: // impl members
282
283   struct Impl;
284   Impl* mImpl;
285 };
286
287 } // namespace Adaptor
288
289 } // namespace Internal
290
291 } // namespace Dali
292
293 #endif // DALI_INTERNAL_FRAMEWORK_H