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"
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.
60 * This class is the Impl class of a App class.
62 class _OSP_EXPORT_ _AppImpl
63 : public Tizen::Base::Object
64 , public _IAppUserEventListener
65 , virtual public Tizen::Base::Runtime::IEventListener
68 typedef result (_AppImpl::*AppRequestHandlerType)(service_s*, int, _AppHandler);
71 * Initializes this instance of _AppImpl with the specified arguments
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.
79 result Construct(const Tizen::Base::Collection::IList* pArgs);
82 * Executes an application implemented by inheriting App class.
83 * This method must be called from the UiApp or ServiceApp.
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.
92 result Execute(_IAppImpl* pIAppImpl);
95 * Returns the _AppImpl's instance pointer.
97 * @return A pointer to the %_AppImpl instance, @n
98 * else @c null if it fails
100 static _AppImpl* GetInstance();
103 * Returns the App's instance pointer.
105 * @return A pointer to the %App instance, @n
106 * else @c null if it fails
108 App* GetAppInstance();
111 * Returns the status of the termination request
113 * @return @c true if the termination is requested, @n
116 static bool IsTerminationRequested(void);
119 * Called when the application is started
121 * @return @c true if the method is successful, @n
123 * @param[in] user_data The user data passed from the callback registration function
124 * @remarks This is a system dependent callback function
126 static bool OnCreate(void* user_data);
129 * Called when other application send the launch request to the application
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
135 static void OnService(service_s* service, void* user_data);
138 * Called when the application is completely obscured by another application and becomes invisible
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 OnPause(void* user_data);
146 * Called when the application becomes visible
148 * @param[in] user_data The user data passed from the callback registration function
149 * @remarks This is a system dependent callback function
151 static void OnResume(void* user_data);
154 * Called once after the main loop of application exits
156 * @param[in] user_data The user data passed from the callback registration function
157 * @remarks This is a system dependent callback function
159 static void OnTerminate(void* user_data);
162 * Called when the system memory is running low
164 * @param[in] user_data The user data passed from the callback registration function
165 * @remarks This is a system dependent callback function
167 static void OnLowMemory(void* user_data);
170 * Called when language setting changes
172 * @param[in] user_data The user data passed from the callback registration function
173 * @remarks This is a system dependent callback function
175 static void OnLanguageChanged(void* user_data);
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.
186 result SetListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
188 result SetSqlDataControlProviderEventListener(ISqlDataControlProviderEventListener* pListener);
190 result SetMapDataControlProviderEventListener(IMapDataControlProviderEventListener* pListener);
192 result SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener);
194 result SetAppControlProviderInternalEventListener(IAppControlProviderEventListener* pListener);
196 result SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener);
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.
203 * @return @c true if the method is successful, @n
206 bool OnAppInitialized(void);
209 * Called when a checkpoint event occurs
211 void OnAppCheckpoint(void);
214 * Sends the user event to the application itself and not to other application.
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.
222 result SendUserEvent(RequestId requestId, const Tizen::Base::Collection::IList* pArgs, bool isPublic);
225 * Registers app request
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.
233 result RegisterAppRequest(service_s* service, int& req, _AppHandler& reason);
236 * Gets the window handle if exists.
238 long GetWindowHandle(void) const;
241 * Raises the window if possible
243 void RaiseWindow(void);
245 void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel);
247 bool IsForcedTermination(void);
249 static void OnPowerOffNotiReceived(void* node, void* pData);
253 * This is the default constructor for this class.
258 * This is the constructor for this class.
263 * This is the copy constructor for the this class.
265 _AppImpl(const _AppImpl& value);
268 * This is the assignment operator for this class.
270 _AppImpl& operator =(const _AppImpl& source);
273 * This is the destructor for this class.
275 virtual ~_AppImpl(void);
278 * Gets the list of the launch arguments. @n
280 * @return A pointer to the list that contains the String instances of launch arguments
282 Tizen::Base::Collection::IList* GetAppArgumentListN(void) const;
285 * Terminates the application while it is running. @n
286 * The OnAppTerminating() method is called after this method is executed successfully.
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.
292 result Terminate(void);
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.
299 * @return @c true if the method is successful, @n
302 bool OnAppInitializing(void);
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.
309 * @return @c true if the method is successful, @n
312 bool OnAppWillTerminate(void);
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.
318 * @param[in] requestId The user defined event ID
319 * @param[in] pArgs A pointer to an argument list of type String
321 virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs, bool isPublic);
324 * Called asynchronously when AppControl provider event is received.
326 void OnAppControlRequestReceived(const _AppArg& arg, RequestId reqId);
329 * Called asynchronously when DataControl provider event is received.
331 * @param[in] arg The launch argument
333 void OnDataControlRequestReceived(const _AppArg& arg, RequestId reqId);
336 * Called asynchronously when conditional app launch event is received.
338 void OnConditionRequestReceived(const _AppArg& arg, RequestId reqId);
341 * Handles AppControl/DataControl request
343 * @return An error code
344 * @exception E_SUCCESS The method is succesful.
346 result HandleAppRequest(service_s* service, int req, _AppHandler reason);
349 * Handles legacy UserEvent request
351 * @return An error code
352 * @exception E_SUCCESS The method is succesful.
354 result HandleLegacyAppRequest(service_s* service, int req, _AppHandler reason);
357 * Dummy implementation for app event request
359 * @return An error code
360 * @exception E_SUCCESS The method is successful.
362 result HandleDummyAppRequest(service_s* service, int req, _AppHandler reason);
365 * Set legacy app service handler
367 * @return An error code
368 * @exception E_SUCCESS The method is successful.
370 result SetLegacyRequestHandler(void);
372 static bool ConfirmAppService(void);
375 static _AppImpl* __pAppImpl;
377 _AppUserEvent __appUserEvent;
379 IAppCheckpointEventListener* __pCheckpointEventListener;
381 ISqlDataControlProviderEventListener* __pSqlDataControlProviderEventListener;
383 IMapDataControlProviderEventListener* __pMapDataControlProviderEventListener;
385 IAppControlProviderEventListener* __pAppControlProviderEventListener;
386 IAppControlProviderEventListener* __pAppControlProviderInternalEventListener;
388 IAppLaunchConditionEventListener* __pAppLaunchConditionEventListener;
392 _IAppImpl* __pIAppImpl;
394 AppRequestHandlerType __pRequestHandler;
396 AppRequestHandlerType __pLegacyRequestHandler;
398 bool __forcedTermination;
400 static bool __isTerminationRequested;
407 #endif // _FAPP_INTERNAL_APP_IMPL_H_