3867fca69c69e0b3c9fba218ba6bfe2a9da3d77e
[platform/framework/native/appfw.git] / src / app / inc / FApp_AppImpl.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        FApp_AppImpl.h
19  * @brief       This is the header file for the _AppImpl class.
20  */
21
22 #ifndef _FAPP_INTERNAL_APP_IMPL_H_
23 #define _FAPP_INTERNAL_APP_IMPL_H_
24
25 #include <FAppApp.h>
26 #include <FSysBattery.h>
27 #include <FBaseRtIEventListener.h>
28
29 #include "FApp_Types.h"
30 #include "FApp_AppUserEvent.h"
31 #include "FApp_IAppUserEventListener.h"
32
33 struct service_s;
34
35
36 namespace Tizen { namespace Base { namespace Runtime
37 {
38 class IEventListener;
39 }}}
40
41 namespace Tizen { namespace App { namespace Package
42 {
43 class PackageInfo;
44 }}}
45
46 namespace Tizen { namespace App
47 {
48
49 class IAppCheckpointEventListener;
50 class ISqlDataControlProviderEventListener;
51 class IMapDataControlProviderEventListener;
52 class IAppControlProviderEventListener;
53 class IAppLaunchConditionEventListener;
54 class _AppArg;
55 class _IAppImpl;
56
57 /**
58  * @class       _AppImpl
59  * @brief       This class is the Impl class of a App class.
60  *
61  * This class is the Impl class of a App class.
62  */
63 class _OSP_EXPORT_ _AppImpl
64         : public Tizen::Base::Object
65         , public _IAppUserEventListener
66         , virtual public Tizen::Base::Runtime::IEventListener
67 {
68 public:
69         typedef result (_AppImpl::*AppRequestHandlerType)(service_s*, int, _AppHandler);
70
71         /**
72          * Initializes this instance of _AppImpl with the specified arguments
73          *
74          * @return      An error code
75          * @param[in]   pArgs   A pointer to the list that contains the String instances of launch arguments
76          * @exception   E_SUCCESS           The method is successful.
77          * @exception   E_INVALID_STATE     This instance is in an invalid state.
78          * @exception   E_INVALID_ARG       The specified input parameter is invalid.
79          */
80         result Construct(const Tizen::Base::Collection::IList* pArgs);
81
82         /**
83          * Executes an application implemented by inheriting App class.
84          * This method must be called from the UiApp or ServiceApp.
85          *
86          * @return      An error code
87          * @exception   E_SUCCESS           The method is successful.
88          * @exception   E_INVALID_ARG       A specified input parameter is invalid.
89          * @exception   E_OUT_OF_MEMORY     Insufficient memory.
90          * @exception   E_INIT_FAILED       The initialization failure during OnAppInitializing().
91          * @exception   E_SYSTEM            A system error has occurred.
92          */
93         result Execute(_IAppImpl* pIAppImpl);
94
95         /**
96         * Returns the _AppImpl's instance pointer.
97         *
98         * @return       A pointer to the %_AppImpl instance, @n
99         *                       else @c null if it fails
100         */
101         static _AppImpl* GetInstance();
102
103         /**
104         * Returns the App's instance pointer.
105         *
106         * @return       A pointer to the %App instance, @n
107         *                       else @c null if it fails
108         */
109         App* GetAppInstance();
110
111         /**
112          * Returns the status of the termination request
113          *
114          * @return      @c true if the termination is requested, @n
115          *              else @c false
116          */
117         static bool IsTerminationRequested(void);
118
119         /**
120          * Called when the application is started
121          *
122          * @return      @c true if the method is successful, @n
123          *              else @c false
124          * @param[in]   user_data       The user data passed from the callback registration function
125          * @remarks     This is a system dependent callback function
126          */
127         static bool OnCreate(void* user_data);
128
129         /**
130          * Called when other application send the launch request to the application
131          *
132          * @param[in]   service The handle to the service
133          * @param[in]   user_data       The user data passed from the callback registration function
134          * @remarks     This is a system dependent callback function
135          */
136         static void OnService(service_s* service, void* user_data);
137
138         /**
139          * Called when the application is completely obscured by another application and becomes invisible
140          *
141          * @param[in]   user_data       The user data passed from the callback registration function
142          * @remarks     This is a system dependent callback function
143          */
144         static void OnPause(void* user_data);
145
146         /**
147          * Called when the application becomes visible
148          *
149          * @param[in]   user_data       The user data passed from the callback registration function
150          * @remarks     This is a system dependent callback function
151          */
152         static void OnResume(void* user_data);
153
154         /**
155          * Called once after the main loop of application exits
156          *
157          * @param[in]   user_data       The user data passed from the callback registration function
158          * @remarks     This is a system dependent callback function
159          */
160         static void OnTerminate(void* user_data);
161
162         /**
163          * Called when the system memory is running low
164          *
165          * @param[in]   user_data       The user data passed from the callback registration function
166          * @remarks     This is a system dependent callback function
167          */
168         static void OnLowMemory(void* user_data);
169
170         /**
171          * Called when language setting changes
172          *
173          * @param[in]   user_data       The user data passed from the callback registration function
174          * @remarks     This is a system dependent callback function
175          */
176         static void OnLanguageChanged(void* user_data);
177
178         /**
179          * Set Listener
180          *
181          * @return      An error code
182          * @param[in]   appEvent        _AppEvent event type
183          * @param[in]   pListener       Listener to set
184          * @exception   E_SUCCESS           The method is successful.
185          * @exception   E_INVALID_STATE     This instance is in an invalid state.
186          */
187         result SetListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
188
189         result SetSqlDataControlProviderEventListener(ISqlDataControlProviderEventListener* pListener);
190
191         result SetMapDataControlProviderEventListener(IMapDataControlProviderEventListener* pListener);
192
193         result SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener);
194
195         result SetAppControlProviderInternalEventListener(IAppControlProviderEventListener* pListener);
196
197         result SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener);
198
199         /**
200          * Called when the application's initialization is finished. @n
201          * After this method succeeds, the application's state changes to Tizen::App::AppState::RUNNING.
202          * If the method fails, the application's state changes to Tizen::App::AppState::TERMINATING and call OnAppTerminating() subsequently.
203          *
204          * @return      @c true if the method is successful, @n
205          *                      else @c false
206          */
207         bool OnAppInitialized(void);
208
209         /**
210         * Called when a checkpoint event occurs
211         */
212         void OnAppCheckpoint(void);
213
214         /**
215          * Sends the user event to the application itself and not to other application.
216          *
217          * @return              An error code
218          * @param[in]   requestId   The user defined event ID
219          * @param[in]   pArgs       A pointer to an argument list of type String
220          * @param[in]   isPublic        public flag
221          * @exception   E_SUCCESS   The method is successful.
222          */
223         result SendUserEvent(RequestId requestId, const Tizen::Base::Collection::IList* pArgs, bool isPublic);
224
225         /**
226          * Registers app request
227          *
228          * @return      An error code
229          * @param[in]   service service handle
230          * @param[out]  req     request number
231          * @param[out]  reason  launch reason
232          * @exception   E_SUCCESS       The method is successful.
233          */
234         result RegisterAppRequest(service_s* service, int& req, _AppHandler& reason);
235
236         /**
237          * Gets the window handle if exists.
238          */
239         long GetWindowHandle(void) const;
240
241         /**
242          * Raises the window if possible
243          */
244         void RaiseWindow(void);
245
246         void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel);
247
248         bool IsForcedTermination(void);
249
250         static void OnPowerOffNotiReceived(void* pData);
251
252 private:
253         /**
254          * This is the default constructor for this class.
255          */
256         _AppImpl(void);
257
258         /**
259          * This is the constructor for this class.
260          */
261         _AppImpl(App* pApp);
262
263         /**
264          * This is the copy constructor for the this class.
265          */
266         _AppImpl(const _AppImpl& value);
267
268         /**
269          * This is the assignment operator for this class.
270          */
271         _AppImpl& operator =(const _AppImpl& source);
272
273         /**
274          * This is the destructor for this class.
275          */
276         virtual ~_AppImpl(void);
277
278         /**
279          * Gets the list of the launch arguments. @n
280          *
281          * @return      A pointer to the list that contains the String instances of launch arguments
282          */
283         Tizen::Base::Collection::IList* GetAppArgumentListN(void) const;
284
285         /**
286          * Terminates the application while it is running. @n
287          * The OnAppTerminating() method is called after this method is executed successfully.
288          *
289          * @return      An error code
290          * @exception   E_SUCCESS           The method is successful.
291          * @exception   E_INVALID_STATE     This instance is in an invalid state.
292          */
293         result Terminate(void);
294
295         /**
296          * Calles the application's initialization routine. @n
297          * After this method succeeds, the application's state changes to Tizen::App::AppState::RUNNING.
298          * If the method fails, the application's state changes to Tizen::App::AppState::TERMINATING and call OnAppTerminating() subsequently.
299          *
300          * @return      @c true if the method is successful, @n
301          *              else @c false
302          */
303         bool OnAppInitializing(void);
304
305         /**
306          * Called when the application is requested to terminate. @n
307          * Return @c false if you don't want your application to terminate. @n
308          * If the method returns @c true, the application's state changes to Tizen::App::AppState::TERMINATING and call OnAppTerminating() subsequently.
309          *
310          * @return      @c true if the method is successful, @n
311          *                      else @c false
312          */
313         bool OnAppWillTerminate(void);
314
315         /**
316          * Called asynchronously when the user event is sent by the SendUserEvent() method. @n
317          * The request ID and argument format for the user event can be defined as per the requirement.
318          *
319          * @param[in]   requestId   The user defined event ID
320          * @param[in]   pArgs       A pointer to an argument list of type String
321          */
322         virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs, bool isPublic);
323
324         /**
325          * Called asynchronously when AppControl provider event is received.
326          */
327         void OnAppControlRequestReceived(const _AppArg& arg, RequestId reqId);
328
329         /**
330          * Called asynchronously when DataControl provider event is received.
331          *
332          * @param[in]   arg     The launch argument
333          */
334         void OnDataControlRequestReceived(const _AppArg& arg, RequestId reqId);
335
336         /**
337          * Called asynchronously when conditional app launch event is received.
338          */
339         void OnConditionRequestReceived(const _AppArg& arg, RequestId reqId);
340
341         /**
342          * Handles AppControl/DataControl request
343          *
344          * @return      An error code
345          * @exception   E_SUCCESS       The method is succesful.
346          */
347         result HandleAppRequest(service_s* service, int req, _AppHandler reason);
348
349         /**
350          * Handles legacy UserEvent request
351          *
352          * @return      An error code
353          * @exception   E_SUCCESS       The method is succesful.
354          */
355         result HandleLegacyAppRequest(service_s* service, int req, _AppHandler reason);
356
357         /**
358          * Dummy implementation for app event request
359          *
360          * @return An error code
361          * @exception   E_SUCCESS       The method is successful.
362          */
363         result HandleDummyAppRequest(service_s* service, int req, _AppHandler reason);
364
365         /**
366          * Set legacy app service handler
367          *
368          * @return An error code
369          * @exception   E_SUCCESS       The method is successful.
370          */
371         result SetLegacyRequestHandler(void);
372
373         static bool ConfirmAppService(void);
374
375 private:
376         static _AppImpl* __pAppImpl;
377
378         _AppUserEvent   __appUserEvent;
379
380         IAppCheckpointEventListener* __pCheckpointEventListener;
381
382         ISqlDataControlProviderEventListener* __pSqlDataControlProviderEventListener;
383
384         IMapDataControlProviderEventListener* __pMapDataControlProviderEventListener;
385
386         IAppControlProviderEventListener* __pAppControlProviderEventListener;
387         IAppControlProviderEventListener* __pAppControlProviderInternalEventListener;
388
389         IAppLaunchConditionEventListener* __pAppLaunchConditionEventListener;
390
391         App* __pApp;
392
393         _IAppImpl* __pIAppImpl;
394
395         AppRequestHandlerType __pRequestHandler;
396
397         AppRequestHandlerType __pLegacyRequestHandler;
398
399         bool __forcedTermination;
400
401         static bool __isTerminationRequested;
402
403         friend class App;
404 }; // _AppImpl
405
406 } } //Tizen::App
407
408 #endif // _FAPP_INTERNAL_APP_IMPL_H_