2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FApp_AppImpl.h
19 * @brief This is the header file for the _AppImpl class.
22 #ifndef _FAPP_INTERNAL_APP_IMPL_H_
23 #define _FAPP_INTERNAL_APP_IMPL_H_
28 #include <FSysBattery.h>
29 #include <FBaseRtIEventListener.h>
31 #include "FApp_Types.h"
32 #include "FApp_AppUserEvent.h"
33 #include "FApp_IAppUserEventListener.h"
35 namespace Tizen { namespace Base { namespace Runtime
40 namespace Tizen { namespace App { namespace Package
45 namespace Tizen { namespace App
48 class IAppCheckpointEventListener;
49 class ISqlDataControlProviderEventListener;
50 class IMapDataControlProviderEventListener;
51 class IAppControlProviderEventListener;
52 class IAppLaunchConditionEventListener;
58 * @brief This class is the Impl class of a App class.
61 * This class is the Impl class of a App class.
63 class _OSP_EXPORT_ _AppImpl
64 : public Tizen::Base::Object
65 , public _IAppUserEventListener
66 , virtual public Tizen::Base::Runtime::IEventListener
69 typedef result (_AppImpl::*AppRequestHandlerType)(service_s*, int, _AppHandler);
72 * Initializes this instance of _AppImpl with the specified arguments
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.
81 result Construct(const Tizen::Base::Collection::IList* pArgs);
84 * Executes an application implemented by inheriting App class.
85 * This method must be called from the UiApp or ServiceApp.
88 * @return An error code
89 * @exception E_SUCCESS The method is successful.
90 * @exception E_INVALID_ARG A specified input parameter is invalid.
91 * @exception E_OUT_OF_MEMORY Insufficient memory.
92 * @exception E_INIT_FAILED The initialization failure during OnAppInitializing().
93 * @exception E_SYSTEM A system error has occurred.
95 result Execute(_IAppImpl* pIAppImpl);
98 * Returns the _AppImpl's instance pointer.
101 * @return A pointer to the %_AppImpl instance, @n
102 * else @c null if it fails
104 static _AppImpl* GetInstance();
107 * Returns the App's instance pointer.
110 * @return A pointer to the %App instance, @n
111 * else @c null if it fails
113 App* GetAppInstance();
116 * Returns the status of the termination request
119 * @return @c true if the termination is requested, @n
122 static bool IsTerminationRequested(void);
125 * Called when the application is started
128 * @return @c true if the method is successful, @n
130 * @param[in] user_data The user data passed from the callback registration function
131 * @remarks This is a system dependent callback function
133 static bool OnCreate(void* user_data);
136 * Called when other application send the launch request to the application
139 * @param[in] service The handle to the service
140 * @param[in] user_data The user data passed from the callback registration function
141 * @remarks This is a system dependent callback function
143 static void OnService(service_s* service, void* user_data);
146 * Called when the application is completely obscured by another application and becomes invisible
149 * @param[in] user_data The user data passed from the callback registration function
150 * @remarks This is a system dependent callback function
152 static void OnPause(void* user_data);
155 * Called when the application becomes visible
158 * @param[in] user_data The user data passed from the callback registration function
159 * @remarks This is a system dependent callback function
161 static void OnResume(void* user_data);
164 * Called once after the main loop of application exits
167 * @param[in] user_data The user data passed from the callback registration function
168 * @remarks This is a system dependent callback function
170 static void OnTerminate(void* user_data);
173 * Called when the system memory is running low
176 * @param[in] user_data The user data passed from the callback registration function
177 * @remarks This is a system dependent callback function
179 static void OnLowMemory(void* user_data);
182 * Called when language setting changes
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 OnLanguageChanged(void* user_data);
191 * Called when region format setting changes
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 OnRegionFormatChanged(void* user_data);
203 * @return An error code
204 * @param[in] appEvent _AppEvent event type
205 * @param[in] pListener Listener to set
206 * @exception E_SUCCESS The method is successful.
207 * @exception E_INVALID_STATE This instance is in an invalid state.
209 result SetListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
211 result SetSqlDataControlProviderEventListener(ISqlDataControlProviderEventListener* pListener);
213 result SetMapDataControlProviderEventListener(IMapDataControlProviderEventListener* pListener);
215 result SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener);
217 result SetAppControlProviderInternalEventListener(IAppControlProviderEventListener* pListener);
219 result SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener);
222 * Called when the application's initialization is finished. @n
223 * After this method succeeds, the application's state changes to Tizen::App::AppState::RUNNING.
224 * If the method fails, the application's state changes to Tizen::App::AppState::TERMINATING and call OnAppTerminating() subsequently.
227 * @return @c true if the method is successful, @n
230 bool OnAppInitialized(void);
233 * Called when a checkpoint event occurs
237 void OnAppCheckpoint(void);
240 * Registers app request
243 * @return An error code
244 * @param[in] service service handle
245 * @param[out] req request number
246 * @param[out] reason launch reason
247 * @exception E_SUCCESS The method is successful.
249 result RegisterAppRequest(service_s* service, int& req, _AppHandler& reason);
252 * Gets the window handle if exists.
256 long GetWindowHandle(void) const;
259 void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel);
261 bool IsForcedTermination(void);
263 static void OnPowerOffNotiReceived(void* pData);
267 * This is the default constructor for this class.
274 * This is the constructor for this class.
281 * This is the copy constructor for the this class.
283 _AppImpl(const _AppImpl& value);
286 * This is the assignment operator for this class.
288 _AppImpl& operator =(const _AppImpl& source);
291 * This is the destructor for this class.
295 virtual ~_AppImpl(void);
298 * Gets the list of the launch arguments. @n
301 * @return A pointer to the list that contains the String instances of launch arguments
303 Tizen::Base::Collection::IList* GetAppArgumentListN(void) const;
306 * Terminates the application while it is running. @n
307 * The OnAppTerminating() method is called after this method is executed successfully.
310 * @return An error code
311 * @exception E_SUCCESS The method is successful.
312 * @exception E_INVALID_STATE This instance is in an invalid state.
314 result Terminate(void);
317 * Calles the application's initialization routine. @n
318 * After this method succeeds, the application's state changes to Tizen::App::AppState::RUNNING.
319 * If the method fails, the application's state changes to Tizen::App::AppState::TERMINATING and call OnAppTerminating() subsequently.
322 * @return @c true if the method is successful, @n
325 bool OnAppInitializing(void);
328 * Called when the application is requested to terminate. @n
329 * Return @c false if you don't want your application to terminate. @n
330 * If the method returns @c true, the application's state changes to Tizen::App::AppState::TERMINATING and call OnAppTerminating() subsequently.
333 * @return @c true if the method is successful, @n
336 bool OnAppWillTerminate(void);
339 * Sends the user event to the application itself and not to other application.
342 * @return An error code
343 * @param[in] requestId The user defined event ID
344 * @param[in] pArgs A pointer to an argument list of type String
345 * @exception E_SUCCESS The method is successful.
347 result SendUserEvent(RequestId requestId, const Tizen::Base::Collection::IList* pArgs);
350 * Called asynchronously when the user event is sent by the SendUserEvent() method. @n
351 * The request ID and argument format for the user event can be defined as per the requirement.
354 * @param[in] requestId The user defined event ID
355 * @param[in] pArgs A pointer to an argument list of type String
357 virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs);
360 * Called asynchronously when AppControl provider event is received.
364 void OnAppControlRequestReceived(const _AppArg& arg, RequestId reqId);
367 * Called asynchronously when DataControl provider event is received.
370 * @param[in] arg The launch argument
372 void OnDataControlRequestReceived(const _AppArg& arg, RequestId reqId);
375 * Called asynchronously when conditional app launch event is received.
379 void OnConditionRequestReceived(const _AppArg& arg, RequestId reqId);
382 * Handles AppControl/DataControl request
385 * @return An error code
386 * @exception E_SUCCESS The method is succesful.
388 result HandleAppRequest(service_s* service, int req, _AppHandler reason);
391 * Handles legacy UserEvent request
394 * @return An error code
395 * @exception E_SUCCESS The method is succesful.
397 result HandleLegacyAppRequest(service_s* service, int req, _AppHandler reason);
400 * Dummy implementation for app event request
403 * @return An error code
404 * @exception E_SUCCESS The method is successful.
406 result HandleDummyAppRequest(service_s* service, int req, _AppHandler reason);
409 * Set legacy app service handler
412 * @return An error code
413 * @exception E_SUCCESS The method is successful.
415 result SetLegacyRequestHandler(void);
417 static bool ConfirmAppService(void);
420 static _AppImpl* __pAppImpl;
422 _AppUserEvent __appUserEvent;
424 IAppCheckpointEventListener* __pCheckpointEventListener;
426 ISqlDataControlProviderEventListener* __pSqlDataControlProviderEventListener;
428 IMapDataControlProviderEventListener* __pMapDataControlProviderEventListener;
430 IAppControlProviderEventListener* __pAppControlProviderEventListener;
431 IAppControlProviderEventListener* __pAppControlProviderInternalEventListener;
433 IAppLaunchConditionEventListener* __pAppLaunchConditionEventListener;
437 _IAppImpl* __pIAppImpl;
439 AppRequestHandlerType __pRequestHandler;
441 AppRequestHandlerType __pLegacyRequestHandler;
443 bool __forcedTermination;
445 static bool __isTerminationRequested;
452 #endif // _FAPP_INTERNAL_APP_IMPL_H_