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