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