2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FApp_AppImpl.h
20 * @brief This is the header file for the _AppImpl class.
23 #ifndef _FAPP_INTERNAL_APP_IMPL_H_
24 #define _FAPP_INTERNAL_APP_IMPL_H_
29 #include <FSysBattery.h>
30 #include <FBaseRtIEventListener.h>
32 #include "FApp_Types.h"
33 #include "FApp_AppUserEvent.h"
34 #include "FApp_IAppUserEventListener.h"
36 namespace Tizen { namespace Base { namespace Runtime
41 namespace Tizen { namespace App { namespace Package
46 namespace Tizen { namespace App
49 class IAppCheckpointEventListener;
50 class ISqlDataControlProviderEventListener;
51 class IMapDataControlProviderEventListener;
52 class IAppControlProviderEventListener;
53 class IAppLaunchConditionEventListener;
59 * @brief This class is the Impl class of a App class.
62 * This class is the Impl class of a App class.
64 class _OSP_EXPORT_ _AppImpl
65 : public Tizen::Base::Object
66 , public _IAppUserEventListener
67 , virtual public Tizen::Base::Runtime::IEventListener
70 typedef result (_AppImpl::*AppRequestHandlerType)(service_s*, int, _AppHandler);
73 * Initializes this instance of _AppImpl with the specified arguments
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.
82 result Construct(const Tizen::Base::Collection::IList* pArgs);
85 * Executes an application implemented by inheriting App class.
86 * This method must be called from the UiApp or ServiceApp.
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.
96 result Execute(_IAppImpl* pIAppImpl);
99 * Returns the _AppImpl's instance pointer.
102 * @return A pointer to the %_AppImpl instance, @n
103 * else @c null if it fails
105 static _AppImpl* GetInstance();
108 * Returns the App's instance pointer.
111 * @return A pointer to the %App instance, @n
112 * else @c null if it fails
114 App* GetAppInstance();
117 * Returns the status of the termination request
120 * @return @c true if the termination is requested, @n
123 static bool IsTerminationRequested(void);
126 * Called when the application is started
129 * @return @c true if the method is successful, @n
131 * @param[in] user_data The user data passed from the callback registration function
132 * @remarks This is a system dependent callback function
134 static bool OnCreate(void* user_data);
137 * Called when other application send the launch request to the application
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
144 static void OnService(service_s* service, void* user_data);
147 * Called when the application is completely obscured by another application and becomes invisible
150 * @param[in] user_data The user data passed from the callback registration function
151 * @remarks This is a system dependent callback function
153 static void OnPause(void* user_data);
156 * Called when the application becomes visible
159 * @param[in] user_data The user data passed from the callback registration function
160 * @remarks This is a system dependent callback function
162 static void OnResume(void* user_data);
165 * Called once after the main loop of application exits
168 * @param[in] user_data The user data passed from the callback registration function
169 * @remarks This is a system dependent callback function
171 static void OnTerminate(void* user_data);
174 * Called when an orintation event occurs.
177 * @param[in] orientation The information about the orientation event
179 static void OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data);
182 * Called when the system memory is running low
185 * @param[in] user_data The user data passed from the callback registration function
186 * @remarks This is a system dependent callback function
188 static void OnLowMemory(void* user_data);
191 * Called when the battery power is running low
194 * @param[in] user_data The user data passed from the callback registration function
195 * @remarks This is a system dependent callback function
197 static void OnLowBattery(void* user_data);
200 * Called when language setting changes
203 * @param[in] user_data The user data passed from the callback registration function
204 * @remarks This is a system dependent callback function
206 static void OnLanguageChanged(void* user_data);
209 * Called when region format setting changes
212 * @param[in] user_data The user data passed from the callback registration function
213 * @remarks This is a system dependent callback function
215 static void OnRegionFormatChanged(void* user_data);
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.
227 result SetListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
229 result SetSqlDataControlProviderEventListener(ISqlDataControlProviderEventListener* pListener);
231 result SetMapDataControlProviderEventListener(IMapDataControlProviderEventListener* pListener);
233 result SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener);
235 result SetAppControlProviderInternalEventListener(IAppControlProviderEventListener* pListener);
237 result SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener);
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.
245 * @return @c true if the method is successful, @n
248 bool OnAppInitialized(void);
251 * Called when a checkpoint event occurs
255 void OnAppCheckpoint(void);
258 * Registers app request
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.
267 result RegisterAppRequest(service_s* service, int& req, _AppHandler& reason);
270 * Gets the window handle if exists.
274 long GetWindowHandle(void) const;
277 void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel);
279 bool IsForcedTermination(void);
281 static void OnPowerOffNotiReceived(void* pData);
285 * This is the default constructor for this class.
292 * This is the constructor for this class.
299 * This is the copy constructor for the this class.
301 _AppImpl(const _AppImpl& value);
304 * This is the assignment operator for this class.
306 _AppImpl& operator =(const _AppImpl& source);
309 * This is the destructor for this class.
313 virtual ~_AppImpl(void);
316 * Gets the list of the launch arguments. @n
319 * @return A pointer to the list that contains the String instances of launch arguments
321 Tizen::Base::Collection::IList* GetAppArgumentListN(void) const;
324 * Terminates the application while it is running. @n
325 * The OnAppTerminating() method is called after this method is executed successfully.
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.
332 result Terminate(void);
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.
340 * @return @c true if the method is successful, @n
343 bool OnAppInitializing(void);
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.
351 * @return @c true if the method is successful, @n
354 bool OnAppWillTerminate(void);
357 * Sends the user event to the application itself and not to other application.
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.
365 result SendUserEvent(RequestId requestId, const Tizen::Base::Collection::IList* pArgs);
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.
372 * @param[in] requestId The user defined event ID
373 * @param[in] pArgs A pointer to an argument list of type String
375 virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs);
378 * Called asynchronously when AppControl provider event is received.
382 void OnAppControlRequestReceived(const _AppArg& arg, RequestId reqId);
385 * Called asynchronously when DataControl provider event is received.
388 * @param[in] arg The launch argument
390 void OnDataControlRequestReceived(const _AppArg& arg, RequestId reqId);
393 * Called asynchronously when conditional app launch event is received.
397 void OnConditionRequestReceived(const _AppArg& arg, RequestId reqId);
400 * Handles AppControl/DataControl request
403 * @return An error code
404 * @exception E_SUCCESS The method is succesful.
406 result HandleAppRequest(service_s* service, int req, _AppHandler reason);
409 * Handles legacy UserEvent request
412 * @return An error code
413 * @exception E_SUCCESS The method is succesful.
415 result HandleLegacyAppRequest(service_s* service, int req, _AppHandler reason);
418 * Dummy implementation for app event request
421 * @return An error code
422 * @exception E_SUCCESS The method is successful.
424 result HandleDummyAppRequest(service_s* service, int req, _AppHandler reason);
427 * Set legacy app service handler
430 * @return An error code
431 * @exception E_SUCCESS The method is successful.
433 result SetLegacyRequestHandler(void);
435 static bool ConfirmAppService(void);
438 static _AppImpl* __pAppImpl;
440 _AppUserEvent __appUserEvent;
442 IAppCheckpointEventListener* __pCheckpointEventListener;
444 ISqlDataControlProviderEventListener* __pSqlDataControlProviderEventListener;
446 IMapDataControlProviderEventListener* __pMapDataControlProviderEventListener;
448 IAppControlProviderEventListener* __pAppControlProviderEventListener;
449 IAppControlProviderEventListener* __pAppControlProviderInternalEventListener;
451 IAppLaunchConditionEventListener* __pAppLaunchConditionEventListener;
455 _IAppImpl* __pIAppImpl;
457 AppRequestHandlerType __pRequestHandler;
459 AppRequestHandlerType __pLegacyRequestHandler;
461 bool __forcedTermination;
463 static bool __isTerminationRequested;
470 #endif // _FAPP_INTERNAL_APP_IMPL_H_