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_
26 #include <FSysBattery.h>
27 #include <FBaseRtIEventListener.h>
29 #include "FApp_Types.h"
30 #include "FApp_AppUserEvent.h"
31 #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.
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
74 * @return An error code
75 * @param[in] pArgs A pointer to the list that contains the String instances of launch arguments
76 * @exception E_SUCCESS The method is successful.
77 * @exception E_INVALID_STATE This instance is in an invalid state.
78 * @exception E_INVALID_ARG The specified input parameter is invalid.
80 result Construct(const Tizen::Base::Collection::IList* pArgs);
83 * Executes an application implemented by inheriting App class.
84 * This method must be called from the UiApp or ServiceApp.
86 * @return An error code
87 * @exception E_SUCCESS The method is successful.
88 * @exception E_INVALID_ARG A specified input parameter is invalid.
89 * @exception E_OUT_OF_MEMORY Insufficient memory.
90 * @exception E_INIT_FAILED The initialization failure during OnAppInitializing().
91 * @exception E_SYSTEM A system error has occurred.
93 result Execute(_IAppImpl* pIAppImpl);
96 * Returns the _AppImpl's instance pointer.
98 * @return A pointer to the %_AppImpl instance, @n
99 * else @c null if it fails
101 static _AppImpl* GetInstance();
104 * Returns the App's instance pointer.
106 * @return A pointer to the %App instance, @n
107 * else @c null if it fails
109 App* GetAppInstance();
112 * Returns the status of the termination request
114 * @return @c true if the termination is requested, @n
117 static bool IsTerminationRequested(void);
120 * Called when the application is started
122 * @return @c true if the method is successful, @n
124 * @param[in] user_data The user data passed from the callback registration function
125 * @remarks This is a system dependent callback function
127 static bool OnCreate(void* user_data);
130 * Called when other application send the launch request to the application
132 * @param[in] service The handle to the service
133 * @param[in] user_data The user data passed from the callback registration function
134 * @remarks This is a system dependent callback function
136 static void OnService(service_s* service, void* user_data);
139 * Called when the application is completely obscured by another application and becomes invisible
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 OnPause(void* user_data);
147 * Called when the application becomes visible
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 OnResume(void* user_data);
155 * Called once after the main loop of application exits
157 * @param[in] user_data The user data passed from the callback registration function
158 * @remarks This is a system dependent callback function
160 static void OnTerminate(void* user_data);
163 * Called when the system memory is running low
165 * @param[in] user_data The user data passed from the callback registration function
166 * @remarks This is a system dependent callback function
168 static void OnLowMemory(void* user_data);
171 * Called when language setting changes
173 * @param[in] user_data The user data passed from the callback registration function
174 * @remarks This is a system dependent callback function
176 static void OnLanguageChanged(void* user_data);
181 * @return An error code
182 * @param[in] appEvent _AppEvent event type
183 * @param[in] pListener Listener to set
184 * @exception E_SUCCESS The method is successful.
185 * @exception E_INVALID_STATE This instance is in an invalid state.
187 result SetListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
189 result SetSqlDataControlProviderEventListener(ISqlDataControlProviderEventListener* pListener);
191 result SetMapDataControlProviderEventListener(IMapDataControlProviderEventListener* pListener);
193 result SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener);
195 result SetAppControlProviderInternalEventListener(IAppControlProviderEventListener* pListener);
197 result SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener);
200 * Called when the application's initialization is finished. @n
201 * After this method succeeds, the application's state changes to Tizen::App::AppState::RUNNING.
202 * If the method fails, the application's state changes to Tizen::App::AppState::TERMINATING and call OnAppTerminating() subsequently.
204 * @return @c true if the method is successful, @n
207 bool OnAppInitialized(void);
210 * Called when a checkpoint event occurs
212 void OnAppCheckpoint(void);
215 * Sends the user event to the application itself and not to other application.
217 * @return An error code
218 * @param[in] requestId The user defined event ID
219 * @param[in] pArgs A pointer to an argument list of type String
220 * @param[in] isPublic public flag
221 * @exception E_SUCCESS The method is successful.
223 result SendUserEvent(RequestId requestId, const Tizen::Base::Collection::IList* pArgs, bool isPublic);
226 * Registers app request
228 * @return An error code
229 * @param[in] service service handle
230 * @param[out] req request number
231 * @param[out] reason launch reason
232 * @exception E_SUCCESS The method is successful.
234 result RegisterAppRequest(service_s* service, int& req, _AppHandler& reason);
237 * Gets the window handle if exists.
239 long GetWindowHandle(void) const;
242 * Raises the window if possible
244 void RaiseWindow(void);
246 void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel);
248 bool IsForcedTermination(void);
250 static void OnPowerOffNotiReceived(void* pData);
254 * This is the default constructor for this class.
259 * This is the constructor for this class.
264 * This is the copy constructor for the this class.
266 _AppImpl(const _AppImpl& value);
269 * This is the assignment operator for this class.
271 _AppImpl& operator =(const _AppImpl& source);
274 * This is the destructor for this class.
276 virtual ~_AppImpl(void);
279 * Gets the list of the launch arguments. @n
281 * @return A pointer to the list that contains the String instances of launch arguments
283 Tizen::Base::Collection::IList* GetAppArgumentListN(void) const;
286 * Terminates the application while it is running. @n
287 * The OnAppTerminating() method is called after this method is executed successfully.
289 * @return An error code
290 * @exception E_SUCCESS The method is successful.
291 * @exception E_INVALID_STATE This instance is in an invalid state.
293 result Terminate(void);
296 * Calles the application's initialization routine. @n
297 * After this method succeeds, the application's state changes to Tizen::App::AppState::RUNNING.
298 * If the method fails, the application's state changes to Tizen::App::AppState::TERMINATING and call OnAppTerminating() subsequently.
300 * @return @c true if the method is successful, @n
303 bool OnAppInitializing(void);
306 * Called when the application is requested to terminate. @n
307 * Return @c false if you don't want your application to terminate. @n
308 * If the method returns @c true, the application's state changes to Tizen::App::AppState::TERMINATING and call OnAppTerminating() subsequently.
310 * @return @c true if the method is successful, @n
313 bool OnAppWillTerminate(void);
316 * Called asynchronously when the user event is sent by the SendUserEvent() method. @n
317 * The request ID and argument format for the user event can be defined as per the requirement.
319 * @param[in] requestId The user defined event ID
320 * @param[in] pArgs A pointer to an argument list of type String
322 virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs, bool isPublic);
325 * Called asynchronously when AppControl provider event is received.
327 void OnAppControlRequestReceived(const _AppArg& arg, RequestId reqId);
330 * Called asynchronously when DataControl provider event is received.
332 * @param[in] arg The launch argument
334 void OnDataControlRequestReceived(const _AppArg& arg, RequestId reqId);
337 * Called asynchronously when conditional app launch event is received.
339 void OnConditionRequestReceived(const _AppArg& arg, RequestId reqId);
342 * Handles AppControl/DataControl request
344 * @return An error code
345 * @exception E_SUCCESS The method is succesful.
347 result HandleAppRequest(service_s* service, int req, _AppHandler reason);
350 * Handles legacy UserEvent request
352 * @return An error code
353 * @exception E_SUCCESS The method is succesful.
355 result HandleLegacyAppRequest(service_s* service, int req, _AppHandler reason);
358 * Dummy implementation for app event request
360 * @return An error code
361 * @exception E_SUCCESS The method is successful.
363 result HandleDummyAppRequest(service_s* service, int req, _AppHandler reason);
366 * Set legacy app service handler
368 * @return An error code
369 * @exception E_SUCCESS The method is successful.
371 result SetLegacyRequestHandler(void);
373 static bool ConfirmAppService(void);
376 static _AppImpl* __pAppImpl;
378 _AppUserEvent __appUserEvent;
380 IAppCheckpointEventListener* __pCheckpointEventListener;
382 ISqlDataControlProviderEventListener* __pSqlDataControlProviderEventListener;
384 IMapDataControlProviderEventListener* __pMapDataControlProviderEventListener;
386 IAppControlProviderEventListener* __pAppControlProviderEventListener;
387 IAppControlProviderEventListener* __pAppControlProviderInternalEventListener;
389 IAppLaunchConditionEventListener* __pAppLaunchConditionEventListener;
393 _IAppImpl* __pIAppImpl;
395 AppRequestHandlerType __pRequestHandler;
397 AppRequestHandlerType __pLegacyRequestHandler;
399 bool __forcedTermination;
401 static bool __isTerminationRequested;
408 #endif // _FAPP_INTERNAL_APP_IMPL_H_