d95388c3b4795247352741ee401ab87bb0150682
[platform/core/uifw/dali-adaptor-legacy.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      * Invoked when the platform surface is created.
137      */
138     virtual void OnSurfaceCreated( Any newSurface ) {}
139
140     /**
141      * Invoked when the platform surface is destroyed.
142      */
143     virtual void OnSurfaceDestroyed( Any newSurface ) {}
144   };
145
146 public:
147
148   /**
149    * Constructor
150    * @param[in]  observer  The observer of the Framework.
151    * @param[in]  argc      A pointer to the number of arguments.
152    * @param[in]  argv      A pointer the the argument list.
153    * @param[in]  type      The type of application
154    */
155   Framework( Observer& observer, int* argc, char ***argv, Type type = NORMAL );
156
157   /**
158    * Destructor
159    */
160   ~Framework();
161
162 public:
163
164   /**
165    * Runs the main loop of framework
166    */
167   void Run();
168
169   /**
170    * Quits the main loop
171    */
172   void Quit();
173
174   /**
175    * Checks whether the main loop of the framework is running.
176    * @return true, if the main loop is running, false otherwise.
177    */
178   bool IsMainLoopRunning();
179
180   /**
181    * If the main loop aborts unexpectedly, then the connected callback function is called.
182    * @param[in]  callBack  The function to call.
183    * @note Only one callback can be registered.  The last callback to be set will be called on abort.
184    * @note The ownership of callback is passed onto this class.
185    */
186   void AddAbortCallback( CallbackBase* callback );
187
188   /**
189    * Gets bundle name which was passed in app_reset callback.
190    */
191   std::string GetBundleName() const;
192
193   /**
194    * Gets bundle id which was passed in app_reset callback.
195    */
196   std::string GetBundleId() const;
197
198   /**
199    * Sets a command line options.
200    * This is used in case of the preinitialized application.
201    * @param[in] argc A pointer to the number of arguments
202    * @param[in] argv A pointer to the argument list
203    */
204   void SetCommandLineOptions( int* argc, char **argv[] )
205   {
206     mArgc = argc;
207     mArgv = argv;
208   }
209
210
211   /**
212    *  Gets the path at which application resources are stored.
213    */
214   static std::string GetResourcePath();
215
216   /**
217    *  Gets the path at which application data are stored.
218    */
219   static std::string GetDataPath();
220
221   /**
222    * Sets system language.
223    */
224   void SetLanguage( const std::string& language );
225
226   /**
227    * Sets system region.
228    */
229   void SetRegion( const std::string& region );
230
231   /**
232    * Gets system language.
233    */
234   std::string GetLanguage() const;
235
236   /**
237    * Gets system region.
238    */
239   std::string GetRegion() const;
240
241   /**
242    * Called by the App framework when an application lifecycle event occurs.
243    * @param[in] type The type of event occurred.
244    * @param[in] data The data of event occurred.
245    */
246   bool AppStatusHandler(int type, void* data);
247
248   /**
249    * Called by the adaptor when an idle callback is added.
250    * @param[in] timeout The timeout of the callback.
251    * @param[in] data The data of of the callback.
252    * @param[in] callback The callback.
253    * @return The callback id.
254    */
255   unsigned int AddIdle( int timeout, void* data, bool ( *callback )( void *data ) );
256
257   /**
258    * Called by the adaptor when an idle callback is removed.
259    * @param[in] id The callback id.
260    */
261   void RemoveIdle( unsigned int id );
262
263 private:
264
265   // Undefined
266   Framework(const Framework&);
267   Framework& operator=(Framework&);
268
269 private:
270
271   /**
272    * Called when the application is created.
273    */
274   bool Create();
275
276   /**
277    * Called app_reset callback was called with bundle.
278    */
279   void SetBundleName(const std::string& name);
280
281   /**
282    * Called app_reset callback was called with bundle.
283    */
284   void SetBundleId(const std::string& id);
285
286   /**
287    * Called if the application is aborted.
288    */
289   void AbortCallback();
290
291   /**
292    * Called for initializing on specified backend. (X11 or Wayland)
293    */
294   void InitThreads();
295
296 private:
297   Observer&          mObserver;
298   bool               mInitialised;
299   bool               mPaused;
300   bool               mRunning;
301   int*               mArgc;
302   char***            mArgv;
303   std::string        mBundleName;
304   std::string        mBundleId;
305   AbortHandler       mAbortHandler;
306
307 private: // impl members
308
309   struct Impl;
310   Impl* mImpl;
311 };
312
313 } // namespace Adaptor
314
315 } // namespace Internal
316
317 } // namespace Dali
318
319 #endif // DALI_INTERNAL_FRAMEWORK_H