sync with tizen_2.0
[platform/framework/native/appfw.git] / src / app / FApp_AppImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FApp_AppImpl.cpp
20  * @brief       This is the implementation for the _AppImpl class.
21  */
22
23 #include <unique_ptr.h>
24
25 #include <notification/notification.h>
26 #include <appsvc/appsvc.h>
27
28 #include <FBaseInteger.h>
29 #include <FBaseColArrayList.h>
30 #include <FBaseColHashMap.h>
31 #include <FBaseRtThread.h>
32 #include <FAppAppRegistry.h>
33 #include <FAppAppControl.h>
34 #include <FAppDataControlProviderManager.h>
35 #include <FAppIAppCheckPointEventListener.h>
36 #include <FAppISqlDataControlProviderEventListener.h>
37 #include <FAppIMapDataControlProviderEventListener.h>
38 #include <FAppIAppControlProviderEventListener.h>
39 #include <FAppIAppLaunchConditionEventListener.h>
40 #include <FIoFile.h>
41
42 #include <FBaseSysLog.h>
43 #include <FIo_RegistryImpl.h>
44 #include <FSys_EnvironmentImpl.h>
45 #include <FSys_PowerManagerImpl.h>
46 #include <FApp_Aul.h>
47
48 #include "FApp_IAppManager.h"
49 #include "FApp_AppManagerProxy.h"
50 #include "FApp_AppImpl.h"
51 #include "FApp_AppInfo.h"
52 #include "FApp_AppControlManager.h"
53 #include "FApp_AppArg.h"
54 #include "FApp_IAppImpl.h"
55 #include "FApp_AppResourceImpl.h"
56
57 using namespace Tizen::Base;
58 using namespace Tizen::Base::Collection;
59 using namespace Tizen::Base::Runtime;
60 using namespace Tizen::Io;
61 using namespace Tizen::System;
62
63 namespace
64 {
65
66 const int HEARTBEAT_WAIT_COUNT = 20;
67 const char HEARBEAT_PATH[] = "/tmp/osp-initialized";
68 const wchar_t SERVICE_APPID[] = L"aospd00043.osp-app-service";
69 const char SELECTOR_RESPONSE_KEY[] = "__APP_SVC_START_INFO__";
70
71 }
72
73 namespace Tizen { namespace App
74 {
75
76 _AppImpl* _AppImpl::__pAppImpl = null;
77 bool _AppImpl::__isTerminationRequested = false;
78 static const int _DATACONTROL_PACKET_INDEX_APPID = 0;
79 static const int _DATACONTROL_PACKET_INDEX_REQUESTTYPE = 1;
80 static const int _DATACONTROL_PACKET_INDEX_REQID = 2;
81 static const int _DATACONTROL_PACKET_INDEX_PROVIDERID = 3;
82 static const int _DATACONTROL_PACKET_INDEX_DATAID = 4;
83 static const int _DATACONTROL_PACKET_INDEX_COLUMNCOUNT = 5;
84 static const int _DATACONTROL_PACKET_INDEX_DELETEWHERE = 5;
85 static const int _DATACONTROL_PACKET_INDEX_COLUMNLIST = 6;
86 static const int _DATACONTROL_PACKET_INDEX_INSERTMAP = 6;
87 static const int _DATACONTROL_PACKET_INDEX_UPDATEMAP = 6;
88
89 _AppImpl::_AppImpl(App* pApp)
90         : __pCheckpointEventListener(null)
91         , __pSqlDataControlProviderEventListener(null)
92         , __pMapDataControlProviderEventListener(null)
93         , __pAppControlProviderEventListener(null)
94         , __pAppControlProviderInternalEventListener(null)
95         , __pAppLaunchConditionEventListener(null)
96         , __pApp(pApp)
97         , __pIAppImpl(null)
98         , __pRequestHandler(&_AppImpl::HandleAppRequest)
99         , __pLegacyRequestHandler(&_AppImpl::HandleDummyAppRequest)
100 {
101         __pAppImpl = this;
102 }
103
104
105 result
106 _AppImpl::Construct(const IList* pArgs)
107 {
108         SysTryReturnResult(NID_APP, pArgs != null, E_INVALID_ARG, "pArguments must not be null.");
109         SysAssertf(__pApp != null, "Getting App instance failed.");
110
111         result r = __appUserEvent.Construct();
112         SysTryLog(NID_APP, !IsFailed(r), "[%s] User event handler failure.", GetErrorMessage(r));
113
114         __appUserEvent.AddListener(*this);
115
116         _AppInfo::SetAppState(INITIALIZING);
117
118         return E_SUCCESS;
119 }
120
121
122 result
123 _AppImpl::Execute(_IAppImpl* pIAppImpl)
124 {
125         result r = E_SUCCESS;
126         int eflResult = APP_ERROR_NONE;
127         int argc = _AppInfo::GetArgc();
128         char** pArgv = _AppInfo::GetArgv();
129         _IAppManager* pAppManager = null;
130
131         _AppImpl* pAppImpl = _AppImpl::GetInstance();
132         SysTryReturnResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
133         pAppImpl->__pIAppImpl = pIAppImpl;
134
135         // handle legacy version handling
136         if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
137         {
138                 pAppImpl->SetLegacyRequestHandler();
139         }
140
141         // clear previous notification
142         // [INFO] behavior change : platform does not clear previous notification
143         notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
144
145         app_event_callback_s state_handler;
146         memset(&state_handler, 0, sizeof(app_event_callback_s));
147
148         state_handler.create = &OnCreate;
149         state_handler.service = &OnService;
150         state_handler.terminate = &OnTerminate;
151         state_handler.pause = &OnPause;
152         state_handler.resume = &OnResume;
153         state_handler.device_orientation = &OnDeviceOrientationChanged;
154
155         state_handler.low_memory = &OnLowMemory;
156         state_handler.low_battery = &OnLowBattery;
157         state_handler.language_changed = &OnLanguageChanged;
158         state_handler.region_format_changed = &OnRegionFormatChanged;
159
160         _Aul::SetPowerOffNotiListener(OnPowerOffNotiReceived, this);
161 //      if (pAppManager != null)
162 //      {
163 //              r = pAppManager->RegisterApplication(_AppInfo::GetPackageId(), _AppInfo::GetAppExecutableName(), _AppInfo::GetAppType() , _AppInfo::GetProcessId());
164 //              SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Application registration failed.", GetErrorMessage(r));
165 //      }
166
167         eflResult = app_efl_main(&argc, &pArgv, &state_handler, this);
168
169         SysTryLog(NID_APP, eflResult == APP_ERROR_NONE, "app_efl_main failed with error (%d): Unknown", eflResult);
170
171         // clear outstanding ongoing notification
172         notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_ONGOING);
173
174 //CATCH:
175         pAppManager = _AppManagerProxy::GetService();
176
177         if (pAppManager != null)
178         {
179                 pAppManager->UnregisterApplication(_AppInfo::GetProcessId());
180         }
181
182         return r;
183 }
184
185
186 bool
187 _AppImpl::OnCreate(void* user_data)
188 {
189         SysLog(NID_APP, "Platform creation event.");
190
191         _AppInfo::SetAppState(INITIALIZING);
192
193         _PowerManagerImpl::InitBatteryEvent();
194
195         return true;
196 }
197
198
199 void
200 _AppImpl::OnService(service_s* service, void* user_data)
201 {
202         _AppImpl* pAppImpl = _AppImpl::GetInstance();
203         SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
204         SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
205
206         // ugly code for app selector event handling
207         bundle* pBundle = _AppArg::GetBundleFromSvc(service);
208         if (pBundle)
209         {
210                 const char* pValue = appsvc_get_data(pBundle, SELECTOR_RESPONSE_KEY);
211                 if (pValue)
212                 {
213                         const int req = _AppArg::GetRequestIdFromBundle(pBundle);
214
215                         const char* pOperation = appsvc_get_operation(pBundle);
216
217                         SysLog(NID_APP, "App selector response [%s, %s], req(%d).", pValue, pOperation, req);
218
219                         //_AppArg::Print(pBundle);
220                         _AppControlManager::GetInstance()->SendAppControlStartResponse(req, pValue, pOperation);
221                         return;
222                 }
223         }
224
225         int req = -1;
226         _AppHandler handler = _APP_HANDLER_NONE;
227         pAppImpl->RegisterAppRequest(service, req, handler);
228
229         bool initialLaunch = false;
230
231         // initial launch
232         // (1) OnAppInitializing()
233         // (2) OnAppInitialized()
234         // (3) AppControl / DataControl provider listener
235         // (4) OnResume() (OnForeground()) (UiApp only)
236         // (5) OnUserEventReceivedN()
237
238         // already launched
239         // (1) AppControl / DataControl provider listener
240         // (2) OnResume() (OnForeground()) (UiApp only)
241         // (3) OnUserEventReceivedN()
242
243         if (_AppInfo::GetAppState() == INITIALIZING)
244         {
245                 initialLaunch = true;
246
247                 unsigned int winId = 0;
248                 service_get_window(service, &winId);
249                 if (winId > 0)
250                 {
251                         _AppInfo::GetAppInfo()->SetParentWindowHandle(winId);
252                         SysLog(NID_APP, "Saving window handle 0x%x.", winId);
253                 }
254
255                 if (!ConfirmAppService())
256                 {
257                         _AppInfo::SetAppState(TERMINATED);
258                         SysLogException(NID_APP, E_INIT_FAILED, "[E_INIT_FAILED] Osp AppService is not running.");
259                         app_efl_exit();
260                         return;
261                 }
262
263                 if (!pAppImpl->__pIAppImpl->OnAppInitializing())
264                 {
265                         _AppInfo::SetAppState(TERMINATED);
266                         SysLogException(NID_APP, E_INIT_FAILED, "[E_INIT_FAILED] The initialization of your application failed.");
267                         app_efl_exit();
268                         return;
269                 }
270
271                 _IAppManager* pAppManager = _AppManagerProxy::GetService();
272
273                 if (pAppManager != null)
274                 {
275                         result r = pAppManager->RegisterApplication(_AppInfo::GetPackageId(), _AppInfo::GetAppExecutableName(), _AppInfo::GetAppType() , _AppInfo::GetProcessId());
276                         SysTryReturnVoidResult(NID_APP, !IsFailed(r), r, "[%s] Application registration failed.", GetErrorMessage(r));
277                 }
278
279                 // hide splash window
280
281                 // call for callbacks
282                 // ptr to member function
283                 (pAppImpl->*pAppImpl->__pRequestHandler)(service, req, handler);
284
285                 if (!pAppImpl->__pIAppImpl->OnAppInitialized())
286                 {
287                         _AppInfo::SetAppState(TERMINATING);
288                         SysLog(NID_APP, "[E_INIT_FAILED] The Initialization of your application failed.");
289                         app_efl_exit();
290                         return;
291                 }
292
293                 _AppInfo::SetAppState(RUNNING);
294         }
295         else
296         {
297                 // already running
298
299                 // call for callbacks
300                 // ptr to member function
301                 (pAppImpl->*pAppImpl->__pRequestHandler)(service, req, handler);
302         }
303
304         pAppImpl->__pIAppImpl->OnService(service, initialLaunch);
305
306         // ptr to member function
307         (pAppImpl->*pAppImpl->__pLegacyRequestHandler)(service, req, handler);
308 }
309
310
311 void
312 _AppImpl::OnTerminate(void* user_data)
313 {
314         SysLog(NID_APP, "Termination event 0x%x state", _AppInfo::GetAppState());
315
316         _AppImpl* pAppImpl = _AppImpl::GetInstance();
317         SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
318         SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
319
320         __isTerminationRequested = true;
321         pAppImpl->__pIAppImpl->OnTerminate();
322 }
323
324
325 void
326 _AppImpl::OnResume(void* user_data)
327 {
328         SysLog(NID_APP, "System resume event on 0x%x state", _AppInfo::GetAppState());
329
330         _AppImpl* pAppImpl = _AppImpl::GetInstance();
331         SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
332         SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
333         pAppImpl->__pIAppImpl->OnResume();
334 }
335
336
337 void
338 _AppImpl::OnPause(void* user_data)
339 {
340         SysLog(NID_APP, "System pause event on 0x%x state", _AppInfo::GetAppState());
341
342         _AppImpl* pAppImpl = _AppImpl::GetInstance();
343         SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
344         SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
345         pAppImpl->__pIAppImpl->OnPause();
346         pAppImpl->OnAppCheckpoint();
347 }
348
349
350 void
351 _AppImpl::OnDeviceOrientationChanged(app_device_orientation_e orientation, void* user_data)
352 {
353         _AppImpl* pAppImpl = _AppImpl::GetInstance();
354         SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
355         SysTryReturnVoidResult(NID_APP, pAppImpl->__pIAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
356
357         const AppState state = _AppInfo::GetAppState();
358         SysTryReturnVoidResult(NID_APP, state == INITIALIZING || state == RUNNING, E_INVALID_STATE, "[E_INVALID_STATE] Invalid application state : %d.", state);
359
360         pAppImpl->__pIAppImpl->OnDeviceOrientationChanged(orientation);
361 }
362
363
364 _AppImpl::~_AppImpl(void)
365 {
366         __pAppImpl = null;
367 }
368
369
370 _AppImpl*
371 _AppImpl::GetInstance(void)
372 {
373         return __pAppImpl;
374 }
375
376
377 App*
378 _AppImpl::GetAppInstance(void)
379 {
380         return __pApp;
381 }
382
383
384 IList*
385 _AppImpl::GetAppArgumentListN(void) const
386 {
387         ArrayList* pList = null;
388         const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(0);
389
390         if (pArg)
391         {
392                 pList = pArg->GetArgListN(0);
393         }
394         else
395         {
396                 // fallback
397                 pList = new (std::nothrow) ArrayList();
398                 SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
399                 String* pData = new (std::nothrow) String(LEGACY_LAUNCH_REASON_NORMAL);
400                 SysTryReturn(NID_APP, pData != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
401                 String* pData2 = new (std::nothrow) String(L"osp.operation.MAIN");
402                 SysTryReturn(NID_APP, pData2 != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
403
404                 pList->Construct();
405                 pList->Add(*pData);
406                 pList->Add(*pData2);
407         }
408
409         return pList;
410 }
411
412
413 result
414 _AppImpl::Terminate(void)
415 {
416         result r = E_SUCCESS;
417
418         __isTerminationRequested = true;
419
420         app_efl_exit();
421         return r;
422 }
423
424
425 bool
426 _AppImpl::OnAppInitializing(void)
427 {
428         return false;
429 }
430
431
432 bool
433 _AppImpl::OnAppWillTerminate(void)
434 {
435         SysTryReturn(NID_APP, __pApp != null, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
436
437         return __pApp->OnAppWillTerminate();
438 }
439
440
441 result
442 _AppImpl::RegisterAppRequest(service_s* service, int& req, _AppHandler& handler)
443 {
444         _AppControlManager* pManager = _AppControlManager::GetInstance();
445         SysTryReturnResult(NID_APP, pManager != null, E_SYSTEM, "Wrong system state.");
446
447         result r = pManager->RegisterRequest(service, req, handler);
448         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
449
450         int providerType = _AppInfo::GetAppHandlerType();
451         providerType |= (_APP_HANDLER_LAUNCH_NORMAL | _APP_HANDLER_LAUNCH_COND);
452
453         SysTryLog(NID_APP, (handler & providerType) != 0, "Request 0x%x received for 0x%x.", handler,
454                         _AppInfo::GetAppHandlerType());
455         return E_SUCCESS;
456 }
457
458
459 result
460 _AppImpl::HandleAppRequest(service_s* service, int req, _AppHandler handler)
461 {
462         const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(req);
463         SysTryReturnResult(NID_APP, pArg != null, E_SYSTEM, "No argument found for %d.", req);
464
465         pArg->Print();
466
467         switch (handler)
468         {
469         case _APP_HANDLER_DATACONTROL:
470                 SysLog(NID_APP, "Handling DataControl request");
471
472                 OnDataControlRequestReceived(*pArg, static_cast< RequestId >(req));
473
474                 _AppControlManager::GetInstance()->RemoveResultRequest(req);
475                 break;
476
477         case _APP_HANDLER_LAUNCH_COND:
478                 SysLog(NID_APP, "Handling conditional launch request");
479
480                 OnConditionRequestReceived(*pArg, static_cast< RequestId >(req));
481                 break;
482
483         default:
484                 SysLog(NID_APP, "Handling AppControl request");
485
486                 OnAppControlRequestReceived(*pArg, static_cast< RequestId >(req));
487                 break;
488         }
489
490         return E_SUCCESS;
491 }
492
493
494 result
495 _AppImpl::HandleLegacyAppRequest(service_s* service, int req, _AppHandler handler)
496 {
497         const _AppArg* pArg = _AppControlManager::GetInstance()->FindResultRequest(0);
498         SysTryReturnResult(NID_APP, pArg != null, E_SYSTEM, "No argument found for %d.", req);
499
500         //pArg->Print();
501
502         switch (handler)
503         {
504         case _APP_HANDLER_LAUNCH_NORMAL:
505                 SysLog(NID_APP, "Handling normal launch request");
506                 OnUserEventReceivedN(AppLaunchRequestId, pArg->GetArgListN(req));
507
508                 // [TODO] request handle memory cleanup confirm
509                 _AppControlManager::GetInstance()->RemoveResultRequest(req);
510                 break;
511
512         case _APP_HANDLER_LAUNCH_COND:
513                 SysLog(NID_APP, "Handling conditional launch request");
514
515                 OnUserEventReceivedN(AppLaunchRequestId, pArg->GetArgListN(req));
516
517                 // [TODO] request handle memory cleanup confirm
518                 _AppControlManager::GetInstance()->RemoveResultRequest(req);
519                 break;
520
521         default:
522                 break;
523         }
524
525         return E_SUCCESS;
526 }
527
528
529 result
530 _AppImpl::HandleDummyAppRequest(service_s* service, int req, _AppHandler handler)
531 {
532         SysLog(NID_APP, "Dummy handler");
533
534         return E_SUCCESS;
535 }
536
537
538 result
539 _AppImpl::SetLegacyRequestHandler(void)
540 {
541         SysLog(NID_APP, "Setting request handler for legacy application.");
542
543         __pRequestHandler = &_AppImpl::HandleDummyAppRequest;
544         __pLegacyRequestHandler = &_AppImpl::HandleLegacyAppRequest;
545
546         return E_SUCCESS;
547 }
548
549
550 void
551 _AppImpl::OnLowMemory(void* user_data)
552 {
553         _AppImpl* pAppImpl = _AppImpl::GetInstance();
554
555         SysTryReturnVoidResult(NID_APP, pAppImpl != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
556         SysTryReturnVoidResult(NID_APP, pAppImpl->__pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
557
558         if (_AppInfo::GetAppState() == RUNNING)
559         {
560                 pAppImpl->__pApp->OnLowMemory();
561         }
562 }
563
564
565 void
566 _AppImpl::OnLowBattery(void* user_data)
567 {
568         // Osp doesn't implement this callback.
569 }
570
571 void
572 _AppImpl::OnBatteryLevelChanged(BatteryLevel batteryLevel)
573 {
574         SysTryReturnVoidResult(NID_APP, __pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
575
576         __pApp->OnBatteryLevelChanged(batteryLevel);
577 }
578
579 void
580 _AppImpl::OnLanguageChanged(void* user_data)
581 {
582         SysLog(NID_APP, "");
583         _AppInfo::UpdatePackageInfo(true);
584         _AppResourceImpl::GetInstance()->Reinitialize();
585 }
586
587 void
588 _AppImpl::OnRegionFormatChanged(void* user_data)
589 {
590         // Osp doesn't implement this callback.
591 }
592
593
594 result
595 _AppImpl::SendUserEvent(RequestId requestId, const IList* pArgs)
596 {
597         _AppUserEventArg* pArg = new (std::nothrow) _AppUserEventArg(requestId, pArgs);
598         SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "User event creation failure for %d.", requestId);
599
600         result r = __appUserEvent.FireAsync(*pArg);
601
602         return r;
603 }
604
605
606 void
607 _AppImpl::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
608 {
609         SysTryReturnVoidResult(NID_APP, __pApp != null, E_INVALID_STATE, "[E_INVALID_STATE] Getting internal instance failed.");
610
611         __pApp->OnUserEventReceivedN(requestId, pArgs);
612 }
613
614
615 void
616 _AppImpl::OnAppControlRequestReceived(const _AppArg& arg, RequestId reqId)
617 {
618         const String& internalOperation = arg.GetValue(OSP_K_APPCONTROL_INTERNAL_OPERATION);
619         bool isInternalOperation = ( __pAppControlProviderInternalEventListener != null && internalOperation.IsEmpty() == false);
620
621         if (__pAppControlProviderEventListener == null && isInternalOperation == false)
622         {
623                 SysLog(NID_APP, "No AppControl provider event listener set for request %d.", reqId);
624                 return;
625         }
626
627         const String& appId = _AppInfo::GetApplicationId();
628
629         const char* p = appsvc_get_operation(arg.GetBundle());
630         String operationId = (p) ? String(p) : TIZEN_OPERATION_MAIN;
631         if (operationId == L"http://tizen.org/appcontrol/operation/default")
632         {
633                 operationId = TIZEN_OPERATION_MAIN;
634         }
635
636         SysLog(NID_APP, "AppControl (%ls, %ls).", appId.GetPointer(), operationId.GetPointer());
637
638         String uri;
639         String mime;
640         const String* pUri = null;
641         const String* pMime = null;
642         p = appsvc_get_uri(arg.GetBundle());
643         if (p)
644         {
645                 uri = p;
646                 pUri = &uri;
647
648                 SysLog(NID_APP, "Delivered uri is [%ls].", pUri->GetPointer());
649         }
650
651         p = appsvc_get_mime(arg.GetBundle());
652         if (p)
653         {
654                 mime = p;
655                 pMime = &mime;
656         }
657
658         std::unique_ptr<HashMap> pMap(arg.GetArgMapN());
659
660         if( isInternalOperation )
661         {
662                 __pAppControlProviderInternalEventListener->OnAppControlRequestReceived(reqId, operationId, pUri, pMime, pMap.get());
663         }
664         else
665         {
666                 __pAppControlProviderEventListener->OnAppControlRequestReceived(reqId, operationId, pUri, pMime, pMap.get());
667         }
668
669         SysLog(NID_APP, "AppControl (%ls, %ls) invocation finished.", appId.GetPointer(), operationId.GetPointer());
670 }
671
672
673 void
674 _AppImpl::OnDataControlRequestReceived(const _AppArg& arg, RequestId reqId)
675 {
676         String tempFilePath;
677         ISqlDataControlProviderEventListener* pSqlListener = null;
678         IMapDataControlProviderEventListener* pMapListener = null;
679         ArrayList* pColumnList = null;
680         HashMap* pInsertMap = null;
681         HashMap* pUpdateMap = null;
682         String* pAppId = null;
683         String* pRequestType = null;
684         String* pProviderId = null;
685         String* pDataId = null;
686         String* pReqId = null;
687         String* pColumnCount = null;
688         String* pColumn = null;
689         String* pValue = null;
690         String* pWhere = null;
691         String* pOrder = null;
692         String* pErrorMsg = null;
693         String* pNo = null;
694         String* pCount = null;
695         String empty(L"NULL");
696 #if 0
697         _DataControlResultSetImpl* pResultSetImpl = null;
698         String* pResult = null;
699         String* pObject = null;
700         String* pTempObject = null;
701         String* pTempFilePath = null;
702 #endif
703         _AppArg resultArg;
704         int type = 0;
705         _DataControlRequestType requestType = _DATACONTROL_REQUEST_TYPE_UNDEFINED;
706         int columnCount = 0;
707         int pageNo = 0;
708         int countPerPage = 0;
709         int i = 0;
710         int index = 0;
711         //ArrayList* pResultArgList = null;
712         result r = E_SUCCESS;
713         result res = E_SUCCESS;
714         ArrayList* pList = null;
715         String* pKey = null;
716         String* pNewValue = null;
717         String* pOldValue = null;
718 #if 0
719         String* pResultCount = null;
720         String* pResultValue = null;
721 #endif
722
723         SysLog(NID_APP, "[DC_PROVIDER] Data control request is received.");
724         //arg.Print();
725
726         pList = arg.GetArgListN(0);
727         SysTryCatch(NID_APP, pList, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
728
729         // key-based
730         pAppId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_APPID)); // key(0)
731         SysTryCatch(NID_APP, pAppId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
732
733         pRequestType = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_REQUESTTYPE)); // key(1)
734         SysTryCatch(NID_APP, pRequestType, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
735         Integer::Parse(*pRequestType, type);
736         requestType = static_cast< _DataControlRequestType >(type);
737
738         pReqId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_REQID)); // key(2)
739         SysTryCatch(NID_APP, pReqId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
740
741         pProviderId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_PROVIDERID)); // key(3)
742         SysTryCatch(NID_APP, pProviderId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
743
744         // list-based
745         pDataId = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_DATAID));// list(0): data ID
746         SysTryCatch(NID_APP, pDataId, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
747
748         if (requestType >= _DATACONTROL_REQUEST_TYPE_SQL_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_SQL_DELETE)
749         {
750                 pSqlListener = __pSqlDataControlProviderEventListener;
751                 SysTryCatch(NID_APP, pSqlListener != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
752         }
753         else if (requestType >= _DATACONTROL_REQUEST_TYPE_MAP_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_MAP_DELETE)
754         {
755                 pKey = dynamic_cast< String* >(pList->GetAt(5)); // list[1]
756                 SysTryCatch(NID_APP, pKey, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
757
758                 pMapListener = __pMapDataControlProviderEventListener;
759                 SysTryCatch(NID_APP, pMapListener != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
760         }
761         else
762         {
763                 SysLogException(NID_APP, E_SYSTEM, "[E_SYSTEM] invalid request");
764                 r = E_SYSTEM;
765         }
766
767         switch (requestType)
768         {
769         case _DATACONTROL_REQUEST_TYPE_SQL_QUERY:
770                 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl SELECT");
771
772                 // list(1): selected column count
773                 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
774                 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
775
776                 if (pColumnCount->Equals(empty) == true)
777                 {
778                         pColumnList = null;
779                 }
780                 else
781                 {
782                         Integer::Parse(*pColumnCount, columnCount);
783                         pColumnList = new (std::nothrow) ArrayList();
784                         SysTryReturnVoidResult(NID_APP, pColumnList, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
785                         pColumnList->Construct();
786                         SysLog(NID_APP, "[DC_PROVIDER] selected column count: %d", columnCount);
787
788                         i = 0;
789                         while (i < columnCount) // list(2): column list
790                         {
791                                 pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNLIST + i));
792                                 SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
793
794                                 pColumnList->Add(*(new String(*pColumn)));
795                                 SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", i, pColumn->GetPointer());
796                                 i++;
797                         }
798                 }
799
800                 i += _DATACONTROL_PACKET_INDEX_COLUMNLIST;
801                 pWhere = dynamic_cast< String* >(pList->GetAt(i)); // list(3): where clause
802                 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
803
804                 if (pWhere->Equals(empty) == true)
805                 {
806                         pWhere = null;
807                 }
808                 else
809                 {
810                         SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
811                 }
812
813                 i++;
814                 pOrder = dynamic_cast< String* >(pList->GetAt(i)); // list(4): order clause
815                 SysTryCatch(NID_APP, pOrder, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
816
817                 if (pOrder->Equals(empty) == true)
818                 {
819                         pOrder = null;
820                 }
821                 else
822                 {
823                         SysLog(NID_APP, "[DC_PROVIDER] pOrder: %ls", pOrder->GetPointer());
824                 }
825
826                 i++;
827                 pNo = dynamic_cast <String*>(pList->GetAt(i)); // list(5): page number
828                 SysTryCatch(NID_APP, pNo, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
829                 Integer::Parse(*pNo, pageNo);
830
831                 i++;
832                 pCount = dynamic_cast <String*>(pList->GetAt(i)); // list(6): count per page
833                 SysTryCatch(NID_APP, pCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
834                 Integer::Parse(*pCount, countPerPage);
835
836                 pSqlListener->OnSqlDataControlSelectRequestReceived(reqId, *pProviderId, *pDataId, pColumnList,
837                                 pWhere, pOrder);
838
839                 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",
840                                 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
841                                 pDataId->GetPointer(), pColumnList, pWhere, pOrder, pageNo, countPerPage);
842                 break;
843         case _DATACONTROL_REQUEST_TYPE_SQL_INSERT:
844                 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl INSERT");
845
846                 // list(1): insert column count
847                 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
848                 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
849
850                 Integer::Parse(*pColumnCount, columnCount);
851                 SysLog(NID_APP, "[DC_PROVIDER] inserted column count: %d", columnCount);
852
853                 pInsertMap = new (std::nothrow) HashMap();
854                 SysTryReturnVoidResult(NID_APP, pInsertMap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
855                 pInsertMap->Construct();
856
857                 i = 0;
858                 index = 0;
859                 while (i < columnCount * 2) // list(2): column-value pairs
860                 {
861                         pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_INSERTMAP + i++));
862                         SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
863                         SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", index, pColumn->GetPointer());
864
865                         pValue = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_INSERTMAP + i++));
866                         SysTryCatch(NID_APP, pValue != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
867                         SysLog(NID_APP, "[DC_PROVIDER] value[%d]: %ls", index, pValue->GetPointer());
868
869                         pInsertMap->Add(*(new String(*pColumn)), *(new String(*pValue)));
870                         index++;
871                 }
872
873                 pSqlListener->OnSqlDataControlInsertRequestReceived(reqId, *pProviderId, *pDataId, *pInsertMap);
874
875                 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pInsertMap: 0x%x",
876                                 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
877                                 pDataId->GetPointer(), pInsertMap);
878                 break;
879         case _DATACONTROL_REQUEST_TYPE_SQL_UPDATE:
880                 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl UPDATE");
881
882                 // list(1): updated column count
883                 pColumnCount = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_COLUMNCOUNT));
884                 SysTryCatch(NID_APP, pColumnCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
885
886                 Integer::Parse(*pColumnCount, columnCount);
887                 SysLog(NID_APP, "[DC_PROVIDER] updated column count: %d", columnCount);
888
889                 pUpdateMap = new (std::nothrow) HashMap();
890                 SysTryReturnVoidResult(NID_APP, pUpdateMap, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory.");
891                 pUpdateMap->Construct();
892
893                 i = 0;
894                 index = 0;
895                 while (i < columnCount * 2) // list(2): column-value pairs
896                 {
897                         pColumn = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i++));
898                         SysTryCatch(NID_APP, pColumn != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
899                         SysLog(NID_APP, "[DC_PROVIDER] column[%d]: %ls", index, pColumn->GetPointer());
900
901                         pValue = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i++));
902                         SysTryCatch(NID_APP, pValue != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
903                         SysLog(NID_APP, "[DC_PROVIDER] value[%d]: %ls", index, pValue->GetPointer());
904
905                         pUpdateMap->Add(*(new String(*pColumn)), *(new String(*pValue)));
906                         index++;
907                 }
908
909                 // list(3): where clause
910                 pWhere = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_UPDATEMAP + i));
911                 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
912
913                 if (pWhere->Equals(empty) == true)
914                 {
915                         pWhere = null;
916                 }
917                 else
918                 {
919                         SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
920                 }
921
922                 pSqlListener->OnSqlDataControlUpdateRequestReceived(reqId, *pProviderId, *pDataId, *pUpdateMap, pWhere);
923
924                 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pUpdateMap: 0x%x, pWhere: 0x%x",
925                                 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
926                                 pDataId->GetPointer(), pUpdateMap, pWhere);
927                 break;
928         case _DATACONTROL_REQUEST_TYPE_SQL_DELETE:
929                 SysLog(NID_APP, "[DC_PROVIDER] SqlDataControl DELETE");
930
931                 // list(1): where clause
932                 pWhere = dynamic_cast< String* >(pList->GetAt(_DATACONTROL_PACKET_INDEX_DELETEWHERE));
933                 SysTryCatch(NID_APP, pWhere, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
934
935                 if (pWhere->Equals(empty) == true)
936                 {
937                         pWhere = null;
938                 }
939                 else
940                 {
941                         SysLog(NID_APP, "[DC_PROVIDER] pWhere: %ls", pWhere->GetPointer());
942                 }
943
944                 pSqlListener->OnSqlDataControlDeleteRequestReceived(reqId, *pProviderId, *pDataId, pWhere);
945
946                 SysLog(NID_APP, "[DC_PROVIDER] caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, pWhere: 0x%x",
947                                 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
948                                 pDataId->GetPointer(), pWhere);
949                 break;
950         case _DATACONTROL_REQUEST_TYPE_MAP_QUERY:
951                 pNo = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
952                 SysTryCatch(NID_APP, pNo, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
953                 Integer::Parse(*pNo, pageNo);
954
955                 pCount = dynamic_cast <String*>(pList->GetAt(7)); //list[3]
956                 SysTryCatch(NID_APP, pCount, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
957                 Integer::Parse(*pCount, countPerPage);
958
959                 pMapListener->OnMapDataControlGetValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey);
960                 break;
961         case _DATACONTROL_REQUEST_TYPE_MAP_INSERT:
962                 pValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
963                 SysTryCatch(NID_APP, pValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
964
965                 pMapListener->OnMapDataControlAddValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pValue);
966                 break;
967         case _DATACONTROL_REQUEST_TYPE_MAP_UPDATE:
968                 pOldValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
969                 SysTryCatch(NID_APP, pOldValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
970
971                 pNewValue = dynamic_cast <String*>(pList->GetAt(7)); // list[3]
972                 SysTryCatch(NID_APP, pNewValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
973
974                 pMapListener->OnMapDataControlSetValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pOldValue, *pNewValue);
975                 break;
976         case _DATACONTROL_REQUEST_TYPE_MAP_DELETE:
977                 pValue = dynamic_cast <String*>(pList->GetAt(6)); // list[2]
978                 SysTryCatch(NID_APP, pValue, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
979
980                 pMapListener->OnMapDataControlRemoveValueRequestReceived(reqId, *pProviderId, *pDataId, *pKey, *pValue);
981                 break;
982         default:
983                 SysTryCatch(NID_APP, false, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request");
984                 break;
985         }
986
987         if (requestType >= _DATACONTROL_REQUEST_TYPE_MAP_QUERY && requestType <= _DATACONTROL_REQUEST_TYPE_MAP_DELETE)
988         {
989                 SysLog(NID_APP, "caller appId: %ls, requestType: %d, reqId: %ls, providerId: %ls, dataId: %ls, key: %ls",
990                                 pAppId->GetPointer(), requestType, pReqId->GetPointer(), pProviderId->GetPointer(),
991                                 pDataId->GetPointer(), pKey->GetPointer());
992         }
993
994         if (pColumnList)
995         {
996                 pColumnList->RemoveAll(true);
997                 delete pColumnList;
998         }
999
1000         if (pInsertMap)
1001         {
1002                 pInsertMap->RemoveAll(true);
1003                 delete pInsertMap;
1004         }
1005
1006         if (pUpdateMap)
1007         {
1008                 pUpdateMap->RemoveAll(true);
1009                 delete pUpdateMap;
1010         }
1011
1012         return;
1013
1014 CATCH:
1015         if (r == E_SYSTEM)
1016         {
1017                 pErrorMsg = new (std::nothrow) String("[E_SYSTEM] A system error has occurred.");
1018         }
1019         else if (r == E_OUT_OF_MEMORY)
1020         {
1021                 pErrorMsg = new (std::nothrow) String("[E_OUT_OF_MEMORY] The memory was insufficient.");
1022         }
1023         SysTryReturnVoidResult(NID_APP, pErrorMsg, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory was insufficient.");
1024
1025         res = DataControlProviderManager::GetInstance()->SendDataControlError(reqId, *pErrorMsg);
1026
1027         if (pColumnList)
1028         {
1029                 pColumnList->RemoveAll(true);
1030                 delete pColumnList;
1031         }
1032
1033         if (pInsertMap)
1034         {
1035                 pInsertMap->RemoveAll(true);
1036                 delete pInsertMap;
1037         }
1038
1039         if (pUpdateMap)
1040         {
1041                 pUpdateMap->RemoveAll(true);
1042                 delete pUpdateMap;
1043         }
1044
1045         delete pErrorMsg;
1046
1047         return;
1048 }
1049
1050
1051 void
1052 _AppImpl::OnConditionRequestReceived(const _AppArg& arg, RequestId reqId)
1053 {
1054         if (__pAppLaunchConditionEventListener == null)
1055         {
1056                 SysLog(NID_APP, "No App launch condition event listener");
1057                 return;
1058         }
1059
1060         String condition = arg.GetValue(OSP_K_COND);
1061         Object* pExtraData = null;//TODO: retrieve NFC extra data.
1062         ArrayList* pList = arg.GetArgListN();
1063
1064         __pAppLaunchConditionEventListener->OnAppLaunchConditionMetN(condition, pExtraData, pList);
1065 }
1066
1067
1068 long
1069 _AppImpl::GetWindowHandle(void) const
1070 {
1071         SysTryReturn(NID_APP, __pIAppImpl != null, -1, E_INVALID_STATE, "[E_INVALID_STATE] Getting App instance failed.");
1072
1073         return __pIAppImpl->OnWindowHandleRequest();
1074 }
1075
1076
1077 void
1078 _AppImpl::OnAppCheckpoint(void)
1079 {
1080         if (__pCheckpointEventListener)
1081         {
1082                 __pCheckpointEventListener->OnAppCheckpointing(*(AppRegistry::GetInstance()));
1083         }
1084 }
1085
1086
1087 bool
1088 _AppImpl::ConfirmAppService(void)
1089 {
1090         int count = 0;
1091         long interval = 100;
1092         const String tmpFile = HEARBEAT_PATH;
1093
1094         if (_AppInfo::GetApplicationId() == SERVICE_APPID)
1095         {
1096                 return true;
1097         }
1098
1099         while (true)
1100         {
1101                 if (File::IsFileExist(tmpFile))
1102                 {
1103                         return true;
1104                 }
1105
1106                 if (count >= HEARTBEAT_WAIT_COUNT)
1107                 {
1108                         return false;
1109                 }
1110
1111                 SysLog(NID_APP, "Waiting for app service %dth time(%d msec).", count, interval);
1112                 count++;
1113                 Thread::Sleep(interval);
1114         }
1115
1116         return false;
1117 }
1118
1119 result
1120 _AppImpl::SetListener(_AppEvent appEvent, IEventListener* pListener)
1121 {
1122         switch (appEvent)
1123         {
1124         case AE_CHECKPOINT:
1125                 SysTryReturnResult(NID_APP, __pCheckpointEventListener == null, E_OBJ_ALREADY_EXIST, "Checkpoint listener is already set.");
1126
1127                 // fall through
1128         case AE_CLEAR_LISTENER:
1129                 __pCheckpointEventListener = dynamic_cast <IAppCheckpointEventListener*>(pListener);
1130                 break;
1131
1132         default:
1133                 break;
1134         }
1135
1136         return E_SUCCESS;
1137 }
1138
1139
1140 result
1141 _AppImpl::SetSqlDataControlProviderEventListener(ISqlDataControlProviderEventListener* pListener)
1142 {
1143         __pSqlDataControlProviderEventListener = pListener;
1144         int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1145         tmpAppHandlerType |= _APP_HANDLER_DATACONTROL;
1146         _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1147         return E_SUCCESS;
1148 }
1149
1150
1151 result
1152 _AppImpl::SetMapDataControlProviderEventListener(IMapDataControlProviderEventListener* pListener)
1153 {
1154         __pMapDataControlProviderEventListener = pListener;
1155         int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1156         tmpAppHandlerType |= _APP_HANDLER_DATACONTROL;
1157         _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1158         return E_SUCCESS;
1159 }
1160
1161
1162 result
1163 _AppImpl::SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener)
1164 {
1165         __pAppControlProviderEventListener = pListener;
1166         int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1167         tmpAppHandlerType |= _APP_HANDLER_APPCONTROL;
1168         _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1169         return E_SUCCESS;
1170 }
1171
1172 result
1173 _AppImpl::SetAppControlProviderInternalEventListener(IAppControlProviderEventListener* pListener)
1174 {
1175         __pAppControlProviderInternalEventListener = pListener;
1176         int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1177         tmpAppHandlerType |= _APP_HANDLER_APPCONTROL;
1178         _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1179         return E_SUCCESS;
1180 }
1181
1182
1183 result
1184 _AppImpl::SetAppLaunchConditionEventListener(IAppLaunchConditionEventListener* pListener)
1185 {
1186         __pAppLaunchConditionEventListener = pListener;
1187         int tmpAppHandlerType = _AppInfo::GetAppHandlerType();
1188         tmpAppHandlerType |= _APP_HANDLER_LAUNCH_COND;
1189         _AppInfo::SetAppHandlerType(tmpAppHandlerType);
1190
1191         return E_SUCCESS;
1192 }
1193
1194
1195 bool
1196 _AppImpl::IsTerminationRequested(void)
1197 {
1198         return __isTerminationRequested;
1199 }
1200
1201 void
1202 _AppImpl::OnPowerOffNotiReceived(void* user_data)
1203 {
1204         SysLog(NID_APP, "Application is being terminated by power off.");
1205         
1206         app_efl_exit();
1207 }
1208
1209 }} //Tizen::App
1210