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