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