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