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.cpp
20 * @brief This is the implementation for the _AppImpl class.
23 #include <unique_ptr.h>
25 #include <notification/notification.h>
26 #include <appsvc/appsvc.h>
29 #include <FBaseInteger.h>
30 #include <FBaseColArrayList.h>
31 #include <FBaseColHashMap.h>
32 #include <FBaseRtThread.h>
33 #include <FAppAppRegistry.h>
34 #include <FAppAppControl.h>
35 #include <FAppDataControlProviderManager.h>
36 #include <FAppIAppCheckPointEventListener.h>
37 #include <FAppISqlDataControlProviderEventListener.h>
38 #include <FAppIMapDataControlProviderEventListener.h>
39 #include <FAppIAppControlProviderEventListener.h>
40 #include <FAppIAppLaunchConditionEventListener.h>
43 #include <FBaseSysLog.h>
44 #include <FIo_RegistryImpl.h>
45 #include <FSys_EnvironmentImpl.h>
46 #include <FSys_PowerManagerImpl.h>
49 #include "FApp_IAppManager.h"
50 #include "FApp_AppManagerProxy.h"
51 #include "FApp_AppImpl.h"
52 #include "FApp_AppInfo.h"
53 #include "FApp_AppControlManager.h"
54 #include "FApp_AppArg.h"
55 #include "FApp_IAppImpl.h"
56 #include "FApp_AppResourceImpl.h"
58 using namespace Tizen::Base;
59 using namespace Tizen::Base::Collection;
60 using namespace Tizen::Base::Runtime;
61 using namespace Tizen::Io;
62 using namespace Tizen::System;
67 const int HEARTBEAT_WAIT_COUNT = 3;
68 const wchar_t SERVICE_APPID[] = L"aospd00043.osp-app-service";
69 const char SELECTOR_RESPONSE_KEY[] = "__APP_SVC_START_INFO__";
70 #ifndef VCONFKEY_APPSERVICE_STATUS
71 #define VCONFKEY_APPSERVICE_STATUS "memory/appservice/status"
76 namespace Tizen { namespace App
79 _AppImpl* _AppImpl::__pAppImpl = null;
80 bool _AppImpl::__isTerminationRequested = false;
81 static const int _DATACONTROL_PACKET_INDEX_APPID = 0;
82 static const int _DATACONTROL_PACKET_INDEX_REQUESTTYPE = 1;
83 static const int _DATACONTROL_PACKET_INDEX_REQID = 2;
84 static const int _DATACONTROL_PACKET_INDEX_PROVIDERID = 3;
85 static const int _DATACONTROL_PACKET_INDEX_DATAID = 4;
86 static const int _DATACONTROL_PACKET_INDEX_COLUMNCOUNT = 5;
87 static const int _DATACONTROL_PACKET_INDEX_DELETEWHERE = 5;
88 static const int _DATACONTROL_PACKET_INDEX_COLUMNLIST = 6;
89 static const int _DATACONTROL_PACKET_INDEX_INSERTMAP = 6;
90 static const int _DATACONTROL_PACKET_INDEX_UPDATEMAP = 6;
92 _AppImpl::_AppImpl(App* pApp)
93 : __pCheckpointEventListener(null)
94 , __pSqlDataControlProviderEventListener(null)
95 , __pMapDataControlProviderEventListener(null)
96 , __pAppControlProviderEventListener(null)
97 , __pAppControlProviderInternalEventListener(null)
98 , __pAppLaunchConditionEventListener(null)
101 , __pRequestHandler(&_AppImpl::HandleAppRequest)
102 , __pLegacyRequestHandler(&_AppImpl::HandleDummyAppRequest)
103 , __forcedTermination(false)
110 _AppImpl::Construct(const IList* pArgs)
112 SysTryReturnResult(NID_APP, pArgs != null, E_INVALID_ARG, "pArguments must not be null.");
113 SysAssertf(__pApp != null, "Getting App instance failed.");
115 result r = __appUserEvent.Construct();
116 SysTryLog(NID_APP, !IsFailed(r), "[%s] User event handler failure.", GetErrorMessage(r));
118 __appUserEvent.AddListener(*this);
120 _AppInfo::SetAppState(INITIALIZING);
127 _AppImpl::Execute(_IAppImpl* pIAppImpl)
129 SysLogTag(NID_APP, "LAUNCH","[%ls:<Initialize Application>:start]", _AppInfo::GetAppExecutableName().GetPointer());
130 result r = E_SUCCESS;
131 int eflResult = APP_ERROR_NONE;
132 int argc = _AppInfo::GetArgc();
133 char** pArgv = _AppInfo::GetArgv();
134 _IAppManager* pAppManager = null;
136 _AppImpl* pAppImpl = _AppImpl::GetInstance();
137 SysTryReturnResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
138 pAppImpl->__pIAppImpl = pIAppImpl;
140 // handle legacy version handling
141 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
143 pAppImpl->SetLegacyRequestHandler();
146 // clear previous notification
147 // [INFO] behavior change : platform does not clear previous notification
148 notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
150 app_event_callback_s state_handler;
151 memset(&state_handler, 0, sizeof(app_event_callback_s));
153 state_handler.create = &OnCreate;
154 state_handler.service = &OnService;
155 state_handler.terminate = &OnTerminate;
156 state_handler.pause = &OnPause;
157 state_handler.resume = &OnResume;
158 state_handler.device_orientation = &OnDeviceOrientationChanged;
160 state_handler.low_memory = &OnLowMemory;
161 state_handler.low_battery = &OnLowBattery;
162 state_handler.language_changed = &OnLanguageChanged;
163 state_handler.region_format_changed = &OnRegionFormatChanged;
165 _Aul::SetPowerOffNotiListener(OnPowerOffNotiReceived, this);
166 // if (pAppManager != null)
168 // r = pAppManager->RegisterApplication(_AppInfo::GetPackageId(), _AppInfo::GetAppExecutableName(), _AppInfo::GetAppType() , _AppInfo::GetProcessId());
169 // SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Application registration failed.", GetErrorMessage(r));
172 eflResult = app_efl_main(&argc, &pArgv, &state_handler, this);
174 SysTryLog(NID_APP, eflResult == APP_ERROR_NONE, "app_efl_main failed with error (%d): Unknown", eflResult);
176 // clear outstanding ongoing notification
177 notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
180 pAppManager = _AppManagerProxy::GetService();
182 if (pAppManager != null)
184 pAppManager->UnregisterApplication(_AppInfo::GetProcessId());
192 _AppImpl::OnCreate(void* user_data)
194 SysLog(NID_APP, "Platform creation event.");
196 _AppImpl* pAppImpl = static_cast<_AppImpl*>(user_data);
197 if (pAppImpl == null)
199 _AppInfo::SetAppState(TERMINATED);
200 SysLogException(NID_APP, E_INIT_FAILED, "[E_INIT_FAILED] Invalid platform state.");
204 _AppInfo::SetAppState(INITIALIZING);
206 if (!ConfirmAppService())
208 _AppInfo::SetAppState(TERMINATED);
209 SysLogException(NID_APP, E_INIT_FAILED, "[E_INIT_FAILED] Osp AppService is not running.");
213 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnAppInitializing>:start]", _AppInfo::GetAppExecutableName().GetPointer());
214 if (!pAppImpl->__pIAppImpl->OnAppInitializing())
216 _AppInfo::SetAppState(TERMINATED);
217 SysLogException(NID_APP, E_INIT_FAILED, "[E_INIT_FAILED] The initialization of your application failed.");
220 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnAppInitializing>:done]", _AppInfo::GetAppExecutableName().GetPointer());
222 SysLogTag(NID_APP, "LAUNCH","[%ls:<RegisterApplication>:start]", _AppInfo::GetAppExecutableName().GetPointer());
223 _IAppManager* pAppManager = _AppManagerProxy::GetService();
225 if (pAppManager != null)
227 result r = pAppManager->RegisterApplication(_AppInfo::GetPackageId(), _AppInfo::GetAppExecutableName(), static_cast<_AppType>(_AppInfo::GetAppType()), _AppInfo::GetProcessId());
228 SysTryLog(NID_APP, !IsFailed(r), "[%s] Application registration failed.", GetErrorMessage(r));
230 SysLogTag(NID_APP, "LAUNCH","[%ls:<RegisterApplication>:done]", _AppInfo::GetAppExecutableName().GetPointer());
231 // hide splash window
233 _PowerManagerImpl::InitBatteryEvent();
240 _AppImpl::OnService(service_s* service, void* user_data)
242 _AppImpl* pAppImpl = _AppImpl::GetInstance();
243 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
244 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
246 // ugly code for app selector event handling
247 bundle* pBundle = _AppArg::GetBundleFromSvc(service);
250 const char* pValue = appsvc_get_data(pBundle, SELECTOR_RESPONSE_KEY);
253 const int req = _AppArg::GetRequestIdFromBundle(pBundle);
255 const char* pOperation = appsvc_get_operation(pBundle);
257 SysLog(NID_APP, "App selector response [%s, %s], req(%d).", pValue, pOperation, req);
259 //_AppArg::Print(pBundle);
260 _AppControlManager::GetInstance()->SendAppControlStartResponse(req, pValue, pOperation);
265 //_AppArg::Print(pBundle);
267 _AppHandler handler = _APP_HANDLER_NONE;
268 pAppImpl->RegisterAppRequest(service, req, handler);
270 bool initialLaunch = false;
273 // (1) AppControl / DataControl provider listener
274 // (2) OnAppInitialized()
275 // (3) OnResume() (OnForeground()) (UiApp only)
276 // (4) OnUserEventReceivedN()
279 // (1) AppControl / DataControl provider listener
280 // (2) OnResume() (OnForeground()) (UiApp only)
281 // (3) OnUserEventReceivedN()
283 if (_AppInfo::GetAppState() == INITIALIZING)
285 initialLaunch = true;
287 unsigned int winId = 0;
288 service_get_window(service, &winId);
291 _AppInfo::GetAppInfo()->SetParentWindowHandle(winId);
292 SysLog(NID_APP, "Saving window handle 0x%x.", winId);
294 // call for callbacks
295 // ptr to member function
296 SysLogTag(NID_APP, "LAUNCH","[%ls:<RequestHandler and OnAppInitialized>:start]", _AppInfo::GetAppExecutableName().GetPointer());
297 (pAppImpl->*pAppImpl->__pRequestHandler)(service, req, handler);
299 if (!pAppImpl->__pIAppImpl->OnAppInitialized())
301 _AppInfo::SetAppState(TERMINATING);
302 SysLog(NID_APP, "[E_INIT_FAILED] The Initialization of your application failed.");
306 SysLogTag(NID_APP, "LAUNCH","[%ls:<RequestHandler and OnAppInitialized>:done]", _AppInfo::GetAppExecutableName().GetPointer());
308 _AppInfo::SetAppState(RUNNING);
310 SysLogTag(NID_APP, "LAUNCH","[%ls:<Initialize Application>:done]", _AppInfo::GetAppExecutableName().GetPointer());
316 // call for callbacks
317 // ptr to member function
318 (pAppImpl->*pAppImpl->__pRequestHandler)(service, req, handler);
321 pAppImpl->__pIAppImpl->OnService(service, initialLaunch);
323 // ptr to member function
324 (pAppImpl->*pAppImpl->__pLegacyRequestHandler)(service, req, handler);
329 _AppImpl::OnTerminate(void* user_data)
331 SysLog(NID_APP, "Termination event 0x%x state", _AppInfo::GetAppState());
333 _AppImpl* pAppImpl = _AppImpl::GetInstance();
334 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
335 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
337 __isTerminationRequested = true;
338 pAppImpl->__pIAppImpl->OnTerminate();
343 _AppImpl::OnResume(void* user_data)
345 SysLog(NID_APP, "System resume event on 0x%x state", _AppInfo::GetAppState());
346 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnResume>:start]", _AppInfo::GetAppExecutableName().GetPointer());
348 _AppImpl* pAppImpl = _AppImpl::GetInstance();
349 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
350 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
351 pAppImpl->__pIAppImpl->OnResume();
352 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnResume>:done]", _AppInfo::GetAppExecutableName().GetPointer());
357 _AppImpl::OnPause(void* user_data)
359 SysLog(NID_APP, "System pause event on 0x%x state", _AppInfo::GetAppState());
360 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnPause>:start]", _AppInfo::GetAppExecutableName().GetPointer());
362 _AppImpl* pAppImpl = _AppImpl::GetInstance();
363 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
364 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
365 pAppImpl->__pIAppImpl->OnPause();
366 pAppImpl->OnAppCheckpoint();
367 SysLogTag(NID_APP, "LAUNCH","[%ls:<OnPause>:done]", _AppInfo::GetAppExecutableName().GetPointer());
372 _AppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data)
374 _AppImpl* pAppImpl = _AppImpl::GetInstance();
375 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
376 SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
378 const AppState state = _AppInfo::GetAppState();
379 SysTryReturnVoidResult(NID_APP, state == INITIALIZING || state == RUNNING, E_INVALID_STATE, "[E_INVALID_STATE] Invalid application state : %d.", state);
381 pAppImpl->__pIAppImpl->OnDeviceOrientationChanged(orientation);
385 _AppImpl::~_AppImpl(void)
392 _AppImpl::GetInstance(void)
399 _AppImpl::GetAppInstance(void)
406 _AppImpl::GetAppArgumentListN(void) const
408 ArrayList* pList = null;
409 const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(0);
413 pList = pArg->GetArgListN(0);
418 pList = new (std::nothrow) ArrayList();
419 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
420 String* pData = new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL);
421 SysTryReturn(NID_APP, pData != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
422 String* pData2 = new (std::nothrow) String(L"osp.operation.MAIN");
423 SysTryReturn(NID_APP, pData2 != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
435 _AppImpl::Terminate(void)
437 result r = E_SUCCESS;
439 __isTerminationRequested = true;
447 _AppImpl::OnAppInitializing(void)
454 _AppImpl::OnAppWillTerminate(void)
456 SysTryReturn(NID_APP, __pApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
458 return __pApp->OnAppWillTerminate();
463 _AppImpl::RegisterAppRequest(service_s* service, int& req, _AppHandler& handler)
465 _AppControlManager* pManager = _AppControlManager::GetInstance();
466 SysTryReturnResult(NID_APP, pManager != null, E_SYSTEM, "Wrong system state.");
468 result r = pManager->RegisterRequest(service, req, handler);
469 SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
471 int providerType = _AppInfo::GetAppHandlerType();
472 providerType |= (_APP_HANDLER_LAUNCH_NORMAL | _APP_HANDLER_LAUNCH_COND);
474 SysTryLog(NID_APP, (handler & providerType) != 0, "Request 0x%x received for 0x%x.", handler,
475 _AppInfo::GetAppHandlerType());
481 _AppImpl::HandleAppRequest(service_s* service, int req, _AppHandler handler)
483 const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(req);
484 SysTryReturnResult(NID_APP, pArg != null, E_SYSTEM, "No argument found for %d.", req);
490 case _APP_HANDLER_DATACONTROL:
491 SysLog(NID_APP, "Handling DataControl request");
493 OnDataControlRequestReceived(*pArg, static_cast< RequestId >(req));
495 _AppControlManager::GetInstance()->RemoveResultRequest(req);
498 case _APP_HANDLER_LAUNCH_COND:
499 SysLog(NID_APP, "Handling conditional launch request");
501 OnConditionRequestReceived(*pArg, static_cast< RequestId >(req));
505 SysLog(NID_APP, "Handling AppControl request");
507 OnAppControlRequestReceived(*pArg, static_cast< RequestId >(req));
516 _AppImpl::HandleLegacyAppRequest(service_s* service, int req, _AppHandler handler)
518 const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(0);
519 SysTryReturnResult(NID_APP, pArg != null, E_SYSTEM, "No argument found for %d.", req);
525 case _APP_HANDLER_LAUNCH_NORMAL:
526 SysLog(NID_APP, "Handling normal launch request");
527 OnUserEventReceivedN(AppLaunchRequestId, pArg->GetArgListN(req));
529 // [TODO] request handle memory cleanup confirm
530 _AppControlManager::GetInstance()->RemoveResultRequest(req);
533 case _APP_HANDLER_LAUNCH_COND:
534 SysLog(NID_APP, "Handling conditional launch request");
536 OnUserEventReceivedN(AppLaunchRequestId, pArg->GetArgListN(req));
538 // [TODO] request handle memory cleanup confirm
539 _AppControlManager::GetInstance()->RemoveResultRequest(req);
551 _AppImpl::HandleDummyAppRequest(service_s* service, int req, _AppHandler handler)
553 SysLog(NID_APP, "Dummy handler");
560 _AppImpl::SetLegacyRequestHandler(void)
562 SysLog(NID_APP, "Setting request handler for legacy application.");
564 __pRequestHandler = &_AppImpl::HandleDummyAppRequest;
565 __pLegacyRequestHandler = &_AppImpl::HandleLegacyAppRequest;
572 _AppImpl::OnLowMemory(void* user_data)
574 _AppImpl* pAppImpl = _AppImpl::GetInstance();
576 SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
577 SysTryReturnVoidResult(NID_APP, pAppImpl->__pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
579 if (_AppInfo::GetAppState() == RUNNING)
581 pAppImpl->__pApp->OnLowMemory();
587 _AppImpl::OnLowBattery(void* user_data)
589 // Osp doesn't implement this callback.
593 _AppImpl::OnBatteryLevelChanged(BatteryLevel batteryLevel)
595 SysTryReturnVoidResult(NID_APP, __pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
597 __pApp->OnBatteryLevelChanged(batteryLevel);
601 _AppImpl::OnLanguageChanged(void* user_data)
604 _AppInfo::UpdatePackageInfo(true);
606 _AppResourceImpl::Reinitialize();
607 SysLog(NID_APP, "Language change done.");
611 _AppImpl::OnRegionFormatChanged(void* user_data)
613 // Osp doesn't implement this callback.
618 _AppImpl::SendUserEvent(RequestId requestId, const IList* pArgs)
620 _AppUserEventArg* pArg = new (std::nothrow) _AppUserEventArg(requestId, pArgs);
621 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "User event creation failure for %d.", requestId);
623 result r = __appUserEvent.FireAsync(*pArg);
630 _AppImpl::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
632 SysTryReturnVoidResult(NID_APP, __pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
634 __pApp->OnUserEventReceivedN(requestId, pArgs);
639 _AppImpl::OnAppControlRequestReceived(const _AppArg& arg, RequestId reqId)
641 IAppControlProviderEventListener* pAppControlProviderEventListener = null;
643 const String internalOperation = arg.GetValue(OSP_K_APPCONTROL_INTERNAL_OPERATION);
644 if( !internalOperation.IsEmpty() )
646 SysLog(NID_APP, "internalOperation:%ls", internalOperation.GetPointer() );
647 pAppControlProviderEventListener = __pAppControlProviderInternalEventListener;
651 pAppControlProviderEventListener = __pAppControlProviderEventListener;
654 if( pAppControlProviderEventListener == null)
656 SysLog(NID_APP, "No AppControl provider event listener set for request %d.", reqId);
660 const String& appId = _AppInfo::GetApplicationId();
662 const char* p = appsvc_get_operation(arg.GetBundle());
663 String operationId = (p) ? String(p) : TIZEN_OPERATION_MAIN;
664 if (operationId == L"http://tizen.org/appcontrol/operation/default")
666 operationId = TIZEN_OPERATION_MAIN;
669 SysLog(NID_APP, "AppControl (%ls, %ls).", appId.GetPointer(), operationId.GetPointer());
673 const String* pUri = null;
674 const String* pMime = null;
675 p = appsvc_get_uri(arg.GetBundle());
681 SysLog(NID_APP, "Delivered uri is [%ls].", pUri->GetPointer());
684 p = appsvc_get_mime(arg.GetBundle());
691 std::unique_ptr<HashMap> pMap(arg.GetArgMapN());
693 pAppControlProviderEventListener->OnAppControlRequestReceived(reqId, operationId, pUri, pMime, pMap.get());
695 SysLog(NID_APP, "AppControl (%ls, %ls) invocation finished.", appId.GetPointer(), operationId.GetPointer());
700 _AppImpl::OnDataControlRequestReceived(const _AppArg& arg, RequestId reqId)
703 ISqlDataControlProviderEventListener* pSqlListener = null;
704 IMapDataControlProviderEventListener* pMapListener = null;
705 ArrayList* pColumnList = null;
706 HashMap* pInsertMap = null;
707 HashMap* pUpdateMap = null;
708 String* pAppId = null;
709 String* pRequestType = null;
710 String* pProviderId = null;
711 String* pDataId = null;
712 String* pReqId = null;
713 String* pColumnCount = null;
714 String* pColumn = null;
715 String* pValue = null;
716 String* pWhere = null;
717 String* pOrder = null;
718 String* pErrorMsg = null;
720 String* pCount = null;
721 String empty(L"NULL");
723 _DataControlResultSetImpl* pResultSetImpl = null;
724 String* pResult = null;
725 String* pObject = null;
726 String* pTempObject = null;
727 String* pTempFilePath = null;
731 _DataControlRequestType requestType = _DATACONTROL_REQUEST_TYPE_UNDEFINED;
734 int countPerPage = 0;
737 //ArrayList* pResultArgList = null;
738 result r = E_SUCCESS;
739 result res = E_SUCCESS;
740 ArrayList* pList = null;
742 String* pNewValue = null;
743 String* pOldValue = null;
745 String* pResultCount = null;
746 String* pResultValue = null;
749 SysLog(NID_APP, "[DC_PROVIDER] Data control request is received.");
752 pList = arg.GetArgListN(0);
753 SysTryCatch(NID_APP, pList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
756 pAppId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_APPID)); // key(0)
757 SysTryCatch(NID_APP, pAppId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
759 pRequestType = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_REQUESTTYPE)); // key(1)
760 SysTryCatch(NID_APP, pRequestType, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
761 Integer::Parse(*pRequestType, type);
762 requestType = static_cast< _DataControlRequestType >(type);
764 pReqId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_REQID)); // key(2)
765 SysTryCatch(NID_APP, pReqId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
767 pProviderId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_PROVIDERID)); // key(3)
768 SysTryCatch(NID_APP, pProviderId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
771 pDataId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_DATAID));// list(0): data ID
772 SysTryCatch(NID_APP, pDataId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
774 if (requestType >= _DATACONTROL_REQUEST_TYPE_SQL_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_SQL_DELETE)
776 pSqlListener = __pSqlDataControlProviderEventListener;
777 SysTryCatch(NID_APP, pSqlListener != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
779 else if (requestType >= _DATACONTROL_REQUEST_TYPE_MAP_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_MAP_DELETE)
781 pKey = dynamic_cast< String* >(pList->GetAt(5)); // list[1]
782 SysTryCatch(NID_APP, pKey, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
784 pMapListener = __pMapDataControlProviderEventListener;
785 SysTryCatch(NID_APP, pMapListener != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
789 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid request");
795 case _DATACONTROL_REQUEST_TYPE_SQL_QUERY:
796 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl SELECT");
798 // list(1): selected column count
799 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
800 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
802 if (pColumnCount->Equals(empty) == true)
808 Integer::Parse(*pColumnCount, columnCount);
809 pColumnList = new (std::nothrow) ArrayList();
810 SysTryReturnVoidResult(NID_APP, pColumnList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
811 pColumnList->Construct();
812 SysLog(NID_APP, "[DC_PROVIDER] selected column count: %d", columnCount);
815 while (i < columnCount) // list(2): column list
817 pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNLIST + i));
818 SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
820 pColumnList->Add(*(new String(*pColumn)));
821 SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", i, pColumn->GetPointer());
826 i += _DATACONTROL_PACKET_INDEX_COLUMNLIST;
827 pWhere = dynamic_cast< String* >(pList->GetAt(i)); // list(3): where clause
828 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
830 if (pWhere->Equals(empty) == true)
836 SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
840 pOrder = dynamic_cast< String* >(pList->GetAt(i)); // list(4): order clause
841 SysTryCatch(NID_APP, pOrder, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
843 if (pOrder->Equals(empty) == true)
849 SysLog(NID_APP, "[DC_PROVIDER] pOrder: %ls", pOrder->GetPointer());
853 pNo = dynamic_cast <String*>(pList->GetAt(i)); // list(5): page number
854 SysTryCatch(NID_APP, pNo, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
855 Integer::Parse(*pNo, pageNo);
858 pCount = dynamic_cast <String*>(pList->GetAt(i)); // list(6): count per page
859 SysTryCatch(NID_APP, pCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
860 Integer::Parse(*pCount, countPerPage);
862 pSqlListener->OnSqlDataControlSelectRequestReceived(reqId, *pProviderId, *pDataId, pColumnList,
865 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pColumnList: 0x%0x, pWhere: 0x%x, pOrder: 0x%x, pageNo: %d, countPerPage: %d",
866 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
867 pDataId->GetPointer(), pColumnList, pWhere, pOrder, pageNo, countPerPage);
869 case _DATACONTROL_REQUEST_TYPE_SQL_INSERT:
870 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl INSERT");
872 // list(1): insert column count
873 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
874 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
876 Integer::Parse(*pColumnCount, columnCount);
877 SysLog(NID_APP, "[DC_PROVIDER] inserted column count: %d", columnCount);
879 pInsertMap = new (std::nothrow) HashMap();
880 SysTryReturnVoidResult(NID_APP, pInsertMap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
881 pInsertMap->Construct();
885 while (i < columnCount * 2) // list(2): column-value pairs
887 pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_INSERTMAP + i++));
888 SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
889 SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", index, pColumn->GetPointer());
891 pValue = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_INSERTMAP + i++));
892 SysTryCatch(NID_APP, pValue != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
893 SysLog(NID_APP, "[DC_PROVIDER] value[%d]: %ls", index, pValue->GetPointer());
895 pInsertMap->Add(*(new String(*pColumn)), *(new String(*pValue)));
899 pSqlListener->OnSqlDataControlInsertRequestReceived(reqId, *pProviderId, *pDataId, *pInsertMap);
901 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pInsertMap: 0x%x",
902 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
903 pDataId->GetPointer(), pInsertMap);
905 case _DATACONTROL_REQUEST_TYPE_SQL_UPDATE:
906 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl UPDATE");
908 // list(1): updated column count
909 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
910 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
912 Integer::Parse(*pColumnCount, columnCount);
913 SysLog(NID_APP, "[DC_PROVIDER] updated column count: %d", columnCount);
915 pUpdateMap = new (std::nothrow) HashMap();
916 SysTryReturnVoidResult(NID_APP, pUpdateMap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
917 pUpdateMap->Construct();
921 while (i < columnCount * 2) // list(2): column-value pairs
923 pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i++));
924 SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
925 SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", index, pColumn->GetPointer());
927 pValue = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i++));
928 SysTryCatch(NID_APP, pValue != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
929 SysLog(NID_APP, "[DC_PROVIDER] value[%d]: %ls", index, pValue->GetPointer());
931 pUpdateMap->Add(*(new String(*pColumn)), *(new String(*pValue)));
935 // list(3): where clause
936 pWhere = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i));
937 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
939 if (pWhere->Equals(empty) == true)
945 SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
948 pSqlListener->OnSqlDataControlUpdateRequestReceived(reqId, *pProviderId, *pDataId, *pUpdateMap, pWhere);
950 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pUpdateMap: 0x%x, pWhere: 0x%x",
951 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
952 pDataId->GetPointer(), pUpdateMap, pWhere);
954 case _DATACONTROL_REQUEST_TYPE_SQL_DELETE:
955 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl DELETE");
957 // list(1): where clause
958 pWhere = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_DELETEWHERE));
959 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
961 if (pWhere->Equals(empty) == true)
967 SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
970 pSqlListener->OnSqlDataControlDeleteRequestReceived(reqId, *pProviderId, *pDataId, pWhere);
972 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pWhere: 0x%x",
973 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
974 pDataId->GetPointer(), pWhere);
976 case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
977 pNo = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
978 SysTryCatch(NID_APP, pNo, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
979 Integer::Parse(*pNo, pageNo);
981 pCount = dynamic_cast <String*>(pList->GetAt(7)); //list[3]
982 SysTryCatch(NID_APP, pCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
983 Integer::Parse(*pCount, countPerPage);
985 pMapListener->OnMapDataControlGetValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey);
987 case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
988 pValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
989 SysTryCatch(NID_APP, pValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
991 pMapListener->OnMapDataControlAddValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pValue);
993 case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
994 pOldValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
995 SysTryCatch(NID_APP, pOldValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
997 pNewValue = dynamic_cast <String*>(pList->GetAt(7)); // list[3]
998 SysTryCatch(NID_APP, pNewValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1000 pMapListener->OnMapDataControlSetValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pOldValue, *pNewValue);
1002 case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
1003 pValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
1004 SysTryCatch(NID_APP, pValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1006 pMapListener->OnMapDataControlRemoveValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pValue);
1009 SysTryCatch(NID_APP, false, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
1013 if (requestType >= _DATACONTROL_REQUEST_TYPE_MAP_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_MAP_DELETE)
1015 SysLog(NID_APP, "caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, key: %ls",
1016 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
1017 pDataId->GetPointer(), pKey->GetPointer());
1022 pColumnList->RemoveAll(true);
1028 pInsertMap->RemoveAll(true);
1034 pUpdateMap->RemoveAll(true);
1043 pErrorMsg = new (std::nothrow) String("[E_SYSTEM] A system error has occurred.");
1045 else if (r == E_OUT_OF_MEMORY)
1047 pErrorMsg = new (std::nothrow) String("[E_OUT_OF_MEMORY] The memory was insufficient.");
1049 SysTryReturnVoidResult(NID_APP, pErrorMsg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory was insufficient.");
1051 res = DataControlProviderManager::GetInstance()->SendDataControlError(reqId, *pErrorMsg);
1055 pColumnList->RemoveAll(true);
1061 pInsertMap->RemoveAll(true);
1067 pUpdateMap->RemoveAll(true);
1078 _AppImpl::OnConditionRequestReceived(const _AppArg& arg, RequestId reqId)
1080 if (__pAppLaunchConditionEventListener == null)
1082 SysLog(NID_APP, "No App launch condition event listener");
1086 String condition = arg.GetValue(OSP_K_COND);
1087 //Object* pExtraData = null;//TODO: retrieve NFC extra data.
1088 HashMap* pExtraData = arg.GetArgMapN();
1089 ArrayList* pList = arg.GetArgListN();
1091 __pAppLaunchConditionEventListener->OnAppLaunchConditionMetN(condition, pExtraData, pList);
1096 _AppImpl::GetWindowHandle(void) const
1098 SysTryReturn(NID_APP, __pIAppImpl != null, -1, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
1100 return __pIAppImpl->OnWindowHandleRequest();
1105 _AppImpl::OnAppCheckpoint(void)
1107 if (__pCheckpointEventListener)
1109 __pCheckpointEventListener->OnAppCheckpointing(*(AppRegistry::GetInstance()));
1115 _AppImpl::ConfirmAppService(void)
1117 if (_AppInfo::GetApplicationId() == SERVICE_APPID)
1124 long interval = 100;
1128 int res = vconf_get_int(VCONFKEY_APPSERVICE_STATUS, &value);
1134 if (count >= HEARTBEAT_WAIT_COUNT)
1139 SysLog(NID_APP, "Waiting for app service %dth time(%d msec).", count, interval);
1141 Thread::Sleep(interval);
1149 _AppImpl::SetListener(_AppEvent appEvent, IEventListener* pListener)
1154 SysTryReturnResult(NID_APP, __pCheckpointEventListener == null, E_OBJ_ALREADY_EXIST, "Checkpoint listener is already set.");
1157 case AE_CLEAR_LISTENER:
1158 __pCheckpointEventListener = dynamic_cast <IAppCheckpointEventListener*>(pListener);
1170 _AppImpl::SetSqlDataControlProviderEventListener(ISqlDataControlProviderEventListener* pListener)
1172 __pSqlDataControlProviderEventListener = pListener;
1173 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1174 tmpAppHandlerType |= _APP_HANDLER_DATACONTROL;
1175 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1181 _AppImpl::SetMapDataControlProviderEventListener(IMapDataControlProviderEventListener* pListener)
1183 __pMapDataControlProviderEventListener = pListener;
1184 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1185 tmpAppHandlerType |= _APP_HANDLER_DATACONTROL;
1186 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1192 _AppImpl::SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener)
1194 __pAppControlProviderEventListener = pListener;
1195 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1196 tmpAppHandlerType |= _APP_HANDLER_APPCONTROL;
1197 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1202 _AppImpl::SetAppControlProviderInternalEventListener(IAppControlProviderEventListener* pListener)
1204 __pAppControlProviderInternalEventListener = pListener;
1205 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1206 tmpAppHandlerType |= _APP_HANDLER_APPCONTROL;
1207 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1213 _AppImpl::SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener)
1215 __pAppLaunchConditionEventListener = pListener;
1216 int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1217 tmpAppHandlerType |= _APP_HANDLER_LAUNCH_COND;
1218 _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1225 _AppImpl::IsTerminationRequested(void)
1227 return __isTerminationRequested;
1231 _AppImpl::OnPowerOffNotiReceived(void* user_data)
1233 SysLog(NID_APP, "Application is being terminated by power off.");
1235 _AppImpl* pAppImpl = _AppImpl::GetInstance();
1236 if (pAppImpl != null)
1238 pAppImpl->__forcedTermination = true;
1245 _AppImpl::IsForcedTermination(void)
1247 return __forcedTermination;