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