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"
37 namespace Tizen { namespace Base { namespace Runtime
42 namespace Tizen { namespace App { namespace Package
47 namespace Tizen { namespace App
50 class IAppCheckpointEventListener;
51 class ISqlDataControlProviderEventListener;
52 class IMapDataControlProviderEventListener;
53 class IAppControlProviderEventListener;
54 class IAppLaunchConditionEventListener;
60 * @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
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.
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.
94 result Execute(_IAppImpl* pIAppImpl);
97 * Returns the _AppImpl's instance pointer.
99 * @return A pointer to the %_AppImpl instance, @n
100 * else @c null if it fails
102 static _AppImpl* GetInstance();
105 * Returns the App's instance pointer.
107 * @return A pointer to the %App instance, @n
108 * else @c null if it fails
110 App* GetAppInstance();
113 * Returns the status of the termination request
115 * @return @c true if the termination is requested, @n
118 static bool IsTerminationRequested(void);
121 * Called when the application is started
123 * @return @c true if the method is successful, @n
125 * @param[in] user_data The user data passed from the callback registration function
126 * @remarks This is a system dependent callback function
128 static bool OnCreate(void* user_data);
131 * Called when other application send the launch request to the application
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
137 static void OnService(service_s* service, void* user_data);
140 * Called when the application is completely obscured by another application and becomes invisible
142 * @param[in] user_data The user data passed from the callback registration function
143 * @remarks This is a system dependent callback function
145 static void OnPause(void* user_data);
148 * Called when the application becomes visible
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 OnResume(void* user_data);
156 * Called once after the main loop of application exits
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 OnTerminate(void* user_data);
164 * Called when the system memory is running low
166 * @param[in] user_data The user data passed from the callback registration function
167 * @remarks This is a system dependent callback function
169 static void OnLowMemory(void* user_data);
172 * Called when language setting changes
174 * @param[in] user_data The user data passed from the callback registration function
175 * @remarks This is a system dependent callback function
177 static void OnLanguageChanged(void* user_data);
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.
188 result SetListener(_AppEvent appEvent, Tizen::Base::Runtime::IEventListener* pListener);
190 result SetSqlDataControlProviderEventListener(ISqlDataControlProviderEventListener* pListener);
192 result SetMapDataControlProviderEventListener(IMapDataControlProviderEventListener* pListener);
194 result SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener);
196 result SetAppControlProviderInternalEventListener(IAppControlProviderEventListener* pListener);
198 result SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener);
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.
205 * @return @c true if the method is successful, @n
208 bool OnAppInitialized(void);
211 * Called when a checkpoint event occurs
213 void OnAppCheckpoint(void);
216 * Sends the user event to the application itself and not to other application.
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.
224 result SendUserEvent(RequestId requestId, const Tizen::Base::Collection::IList* pArgs, bool isPublic);
227 * Registers app request
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.
235 result RegisterAppRequest(service_s* service, int& req, _AppHandler& reason);
238 * Gets the window handle if exists.
240 long GetWindowHandle(void) const;
243 * Raises the window if possible
245 void RaiseWindow(void);
247 void OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel);
249 bool IsForcedTermination(void);
251 static void OnPowerOffNotiReceived(_keynode_t* node, void* pData);
255 * This is the default constructor for this class.
260 * This is the constructor for this class.
265 * This is the copy constructor for the this class.
267 _AppImpl(const _AppImpl& value);
270 * This is the assignment operator for this class.
272 _AppImpl& operator =(const _AppImpl& source);
275 * This is the destructor for this class.
277 virtual ~_AppImpl(void);
280 * Gets the list of the launch arguments. @n
282 * @return A pointer to the list that contains the String instances of launch arguments
284 Tizen::Base::Collection::IList* GetAppArgumentListN(void) const;
287 * Terminates the application while it is running. @n
288 * The OnAppTerminating() method is called after this method is executed successfully.
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.
294 result Terminate(void);
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.
301 * @return @c true if the method is successful, @n
304 bool OnAppInitializing(void);
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.
311 * @return @c true if the method is successful, @n
314 bool OnAppWillTerminate(void);
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.
320 * @param[in] requestId The user defined event ID
321 * @param[in] pArgs A pointer to an argument list of type String
323 virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs, bool isPublic);
326 * Called asynchronously when AppControl provider event is received.
328 void OnAppControlRequestReceived(const _AppArg& arg, RequestId reqId);
331 * Called asynchronously when DataControl provider event is received.
333 * @param[in] arg The launch argument
335 void OnDataControlRequestReceived(const _AppArg& arg, RequestId reqId);
338 * Called asynchronously when conditional app launch event is received.
340 void OnConditionRequestReceived(const _AppArg& arg, RequestId reqId);
343 * Handles AppControl/DataControl request
345 * @return An error code
346 * @exception E_SUCCESS The method is succesful.
348 result HandleAppRequest(service_s* service, int req, _AppHandler reason);
351 * Handles legacy UserEvent request
353 * @return An error code
354 * @exception E_SUCCESS The method is succesful.
356 result HandleLegacyAppRequest(service_s* service, int req, _AppHandler reason);
359 * Dummy implementation for app event request
361 * @return An error code
362 * @exception E_SUCCESS The method is successful.
364 result HandleDummyAppRequest(service_s* service, int req, _AppHandler reason);
367 * Set legacy app service handler
369 * @return An error code
370 * @exception E_SUCCESS The method is successful.
372 result SetLegacyRequestHandler(void);
374 static bool ConfirmAppService(void);
377 static _AppImpl* __pAppImpl;
379 _AppUserEvent __appUserEvent;
381 IAppCheckpointEventListener* __pCheckpointEventListener;
383 ISqlDataControlProviderEventListener* __pSqlDataControlProviderEventListener;
385 IMapDataControlProviderEventListener* __pMapDataControlProviderEventListener;
387 IAppControlProviderEventListener* __pAppControlProviderEventListener;
388 IAppControlProviderEventListener* __pAppControlProviderInternalEventListener;
390 IAppLaunchConditionEventListener* __pAppLaunchConditionEventListener;
394 _IAppImpl* __pIAppImpl;
396 AppRequestHandlerType __pRequestHandler;
398 AppRequestHandlerType __pLegacyRequestHandler;
400 bool __forcedTermination;
402 static bool __isTerminationRequested;
409 #endif // _FAPP_INTERNAL_APP_IMPL_H_