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