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