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