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