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_AppControlManager.cpp
19 * @brief This is the implementation for the _AppControlManager class.
24 #include <unique_ptr.h>
26 #include <appsvc/appsvc.h>
29 #include <content/mime_type.h>
32 #include <FBaseInteger.h>
33 #include <FBaseObject.h>
34 #include <FBaseString.h>
35 #include <FBaseColIListT.h>
36 #include <FBaseColArrayList.h>
37 #include <FBaseErrors.h>
38 #include <FAppAppControl.h>
39 #include <FAppAppManager.h>
40 #include <FAppIAppControlListener.h>
41 #include <FAppIAppControlResponseListener.h>
42 #include <FAppIAppFrame.h>
43 #include <FAppSqlDataControl.h>
44 #include <FAppMapDataControl.h>
45 #include <FAppPkgPackageInfo.h>
46 #include <FBaseSysLog.h>
48 #include <FBase_StringConverter.h>
49 #include <FIo_DataControlResultSetImpl.h>
51 #include "FApp_AppArg.h"
52 #include "FApp_AppControlEventArg.h"
53 #include "FApp_AppControlRegistry.h"
54 #include "FApp_AppControlImpl.h"
55 #include "FApp_AppImpl.h"
56 #include "FApp_AppInfo.h"
58 #include "FApp_AppControlManager.h"
59 #include "FApp_AppManagerProxy.h"
60 #include "FApp_ConditionManagerProxy.h"
61 #include "FApp_MapDataControlImpl.h"
62 #include "FApp_SqlDataControlImpl.h"
63 #include "FAppPkg_PackageManagerImpl.h"
64 #include "FAppPkg_PackageInfoImpl.h"
65 #include "FApp_AppMessageImpl.h"
66 #include "FApp_AppManagerImpl.h"
67 #include "FApp_AppControlResponseEvent.h"
68 #include "FApp_IAppControlPluginProvider.h"
71 using namespace Tizen::App::Package;
72 using namespace Tizen::Base;
73 using namespace Tizen::Base::Collection;
74 using namespace Tizen::Base::Runtime;
75 using namespace Tizen::Base::Utility;
76 using namespace Tizen::Io;
79 namespace Tizen { namespace App
82 const wchar_t TIZEN_OPERATION_PICK[] = L"http://tizen.org/appcontrol/operation/pick";
83 const wchar_t TIZEN_OPERATION_MAIN[] = L"http://tizen.org/appcontrol/operation/main";
84 const wchar_t LEGACY_OPERATION_MAIN[] = L"osp.operation.MAIN";
85 const char TIZEN_NOTIFICATION_DATA[] = "http://tizen.org/appcontrol/data/notification";
87 _AppControlManager::_AppControlManager(void)
91 // AppControl event handling is expected to be performed in the main thread.
92 __appControlEvent.Construct();
93 __appControlEvent.AddListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
94 __appControlResponseEventContainer.Construct();
95 __appControlResponseEventList.Construct();
98 _AppControlManager::~_AppControlManager(void)
101 __appControlEvent.RemoveListener(*dynamic_cast<_IAppControlSysEventListener*>(this));
102 IEnumeratorT<int>* pEnum = __appControlResponseEventList.GetEnumeratorN();
106 while(pEnum->MoveNext() == E_SUCCESS)
109 pEnum->GetCurrent(reqId);
110 _AppControlResponseEvent* pResponseEvent = null;
111 __appControlResponseEventContainer.GetValue(reqId, pResponseEvent);
112 delete pResponseEvent;
114 __appControlResponseEventContainer.Remove(reqId);
115 SysLog(NID_APP, "pResponseEvent gets deleted. reqId(%d)", reqId);
122 _AppControlManager::GetInstance(void)
124 static _AppControlManager inst;
130 _AppControlManager::GetMimeFromExt(const String& ext, String& out)
132 std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(ext));
133 SysTryReturnResult(NID_APP, pExtension != null, E_OUT_OF_MEMORY, "String allocation failure.");
136 mime_type_get_mime_type(pExtension.get(), &mime);
138 SysTryReturnResult(NID_APP, mime != NULL, E_UNSUPPORTED_FORMAT, "MIME type conversion failure for %ls.", ext.GetPointer());
148 _AppControlManager::GetMimeTypeFromDataType(const String& data)
150 // Data type is either MIME type or .[extension]
152 if (data.IsEmpty() || data[0] != L'.')
159 data.SubString(1, ext);
162 result r = _AppControlManager::GetMimeFromExt(ext, res);
163 SysTryReturn(NID_APP, !IsFailed(r), L"", r, "[%s] MIME type conversion failed for %ls.", GetErrorMessage(r), ext.GetPointer());
165 SysLog(NID_APP, "Conversion from %ls into %ls.", data.GetPointer(), res.GetPointer());
171 _AppControlManager::OnAppControlEventReceivedN(int reqId, _AppArg* pAppArg, int res)
173 SysLog(NID_APP, "Received request Id %d, arg 0x%x", reqId, pAppArg);
176 // get launch info from request Id
177 _DataControlInfo* pInfo = __launchManager.FindItem(reqId);
178 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with response %d", reqId,
184 if (pInfo->magic == LAUNCH_INFO_MAGIC)
186 SysLog(NID_APP, "Invoking callback 0x%x", pInfo->launchCb);
189 if (pInfo->pUserData)
191 (*pInfo->launchCb)(pInfo->pUserData, pInfo->pArg, pAppArg, static_cast<service_result_e>(res), pInfo->property, reqId);
196 SysLogException(NID_APP, E_SYSTEM, "Corrupted data structure.");
201 __launchManager.RemoveItem(reqId);
205 // callback for AppControl start event
207 _AppControlManager::OnAppControlEventReceivedN(int reqId, const AppId& appId, const String& operationId)
209 SysLog(NID_APP, "Received request Id %d, app %ls, operationId %ls", reqId, appId.GetPointer(), operationId.GetPointer());
211 // get launch info from request Id
212 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
213 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found.", reqId);
216 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
217 SysTryReturnVoidResult(NID_APP, pListener != null, E_SYSTEM, "[E_SYSTEM] Invalid result callback for req %d, app %ls.", reqId, appId.GetPointer());
219 result r = E_SUCCESS;
223 AppId actualAppId = appId;
227 r = E_OPERATION_CANCELED;
229 SysLog(NID_APP, "Invoking callback 0x%x.", pListener);
231 _AppControlResponseEvent* pResponseEvent = null;
232 __appControlResponseEventContainer.GetValue(reqId, pResponseEvent);
233 SysLog(NID_APP, "StartResponseReceived Request Id(%d), ResponseEvent 0x%x.", reqId, pResponseEvent);
234 if (pResponseEvent != null)
236 String oId(operationId);
237 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_START, actualAppId, oId, r, APP_CTRL_RESULT_SUCCEEDED, null, reqId, false);
239 if (pResponseEventArg != null)
241 pResponseEvent->Fire(*pResponseEventArg);
242 SysLog(NID_APP, "pResponseEvent is Fired");
247 pListener->OnAppControlStartResponseReceived(actualAppId, operationId, r);
248 SysLog(NID_APP, "OnAppControlStartResponseReceived called directly");
253 SysLog(NID_APP, "No listener registered.");
256 if (r == E_OPERATION_CANCELED)
258 SysLog(NID_APP, "Removed start listener as operation is canceled.");
259 __inAppManager.RemoveItem(reqId);
265 _AppControlManager::InvokeAppControlCompleteListener(IAppControlResponseListener& listener, const AppId& appId, const String& op, AppCtrlResult res, const IMap* pExtraData, bool noRaise)
267 listener.OnAppControlCompleteResponseReceived(appId, op, res, pExtraData);
271 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
274 SysLog(NID_APP, "AppControl response finished.");
279 _AppControlManager::InvokeLegacyAppControlCompleteListener(IAppControlEventListener& listener, const AppId& appId, const String& op, const IList* pList, bool noRaise)
281 listener.OnAppControlCompleted(appId, op, pList);
285 _AppImpl::GetInstance()->SendUserEvent(_APP_EVENT_RAISE, null, false);
288 SysLog(NID_APP, "Legacy AppControl response finished.");
292 // callback for in-process event handling
294 _AppControlManager::OnAppControlPluginEventReceivedN(int reqId, int res, const AppId& optAppId, const String& optOperation, const IMap* pArgs, int property)
296 SysLog(NID_APP, "Received request Id %d, res %d, args 0x%x", reqId, res, pArgs);
298 // process proper callback
299 _InProcessInfo* pInfo = __inAppManager.FindItem(reqId);
300 SysTryReturnVoidResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] request Id %d not found with args 0x%x", reqId,
303 if (pInfo->pListener)
308 if (optAppId.IsEmpty())
310 aId = pInfo->providerId;
311 oId = pInfo->operationId;
315 // implicit launch only
319 SysLog(NID_APP, "Changing appId/operation for implicit launch.");
322 SysLog(NID_APP, "Invoking callback 0x%x for (%ls, %ls).", pInfo->pListener, aId.GetPointer(), oId.GetPointer());
324 const bool isSubMode = (property & _APPCONTROL_PROPERTY_SUBMODE);
325 const bool isServiceCallee = (property & _APPCONTROL_PROPERTY_SERVICE_CALLEE);
329 IAppControlEventListener* pListener = dynamic_cast<IAppControlEventListener*>(pInfo->pListener);
332 ArrayList list(SingleObjectDeleter);
333 _AppArg::FillLegacyAppControlResult(list, res, pArgs, aId);
335 InvokeLegacyAppControlCompleteListener(*pListener, aId, oId, &list, isSubMode | isServiceCallee);
339 SysLog(NID_APP, "Wrong AppControl listener type.");
344 IAppControlResponseListener* pListener = dynamic_cast<IAppControlResponseListener*>(pInfo->pListener);
347 _AppControlResponseEvent* pResponseEvent = null;
348 int responseEventRequestId = RESPONSE_EVENT_REQID_MAGIC + reqId;
349 __appControlResponseEventContainer.GetValue(responseEventRequestId, pResponseEvent);
351 if (pResponseEvent != null)
353 _AppControlResponseEventArg* pResponseEventArg = new (std::nothrow) _AppControlResponseEventArg(pListener, _APPCONTROL_RESPONSETYPE_COMPLETE, aId, oId, E_SUCCESS, static_cast<AppCtrlResult>(res), const_cast<IMap*> (pArgs), responseEventRequestId, isSubMode);
354 if (pResponseEventArg != null)
356 pResponseEvent->Fire(*pResponseEventArg);
357 SysLog(NID_APP, "pResponseEvent is Fired");
362 InvokeAppControlCompleteListener(*pListener, aId, oId, ConvertAppControlResultCode(res), pArgs, isSubMode | isServiceCallee);
363 SysLog(NID_APP, "Listener called directly");
369 SysLog(NID_APP, "Wrong AppControl listener type.");
375 SysLogException(NID_APP, E_SYSTEM, "Invalid AppControl listener.");
379 // remove from list and unload dll
380 __inAppManager.RemoveItem(reqId);
385 _AppControlManager::SendAppControlEvent(IEventArg& arg)
387 return __appControlEvent.FireAsync(arg);
390 Tizen::Base::Collection::IMapT<int,_AppControlResponseEvent*>*
391 _AppControlManager::GetAppControlResponseEventContainer(void)
393 return &__appControlResponseEventContainer;
398 IsMatchingProcListener(const _InProcessInfo& info, IEventListener* pListener)
400 return (info.pListener == pListener);
405 _AppControlManager::StopAppControlResponseListener(IAppControlResponseListener* pListener)
407 // __inAppManager, __launchManager
408 _InProcessInfo* pProcInfo = __inAppManager.FindItemWithListener(IsMatchingProcListener, pListener);
411 __inAppManager.RemoveItem(pProcInfo);
412 SysLog(NID_APP, "Listener 0x%x is removed from in-process stub list.", pListener);
417 // generic launch callback
419 LaunchResultCb(bundle* b, int request_code, appsvc_result_val res, void* data)
421 SysLog(NID_APP, "SLP callee result: %d", res);
423 _AppControlManager* pImpl = static_cast<_AppControlManager*>(data);
429 _AppArg* pAppArg = new (std::nothrow) _AppArg;
430 SysTryReturnVoidResult(NID_APP, pAppArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
432 _AppControlEventArg* pArg = null;
433 result r = pAppArg->Construct(b);
434 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] AppControl event argument creation failure.", GetErrorMessage(r));
436 pArg = new (std::nothrow) _AppControlEventArg(request_code, pAppArg, res);
437 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, r, "[E_OUT_OF_MEMORY] AppControl event argument creation failure.");
440 pImpl->SendAppControlEvent(*pArg);
450 _AppControlManager::SendAppControlStartResponse(int req, const char* pValue, const char* pOp)
452 _AppControlStartEventArg* pArg = new (std::nothrow) _AppControlStartEventArg(req, AppId(pValue), String(pOp));
453 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "AppControl start event creation failure.");
455 SendAppControlEvent(*pArg);
462 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
464 bundle* kb = msg.GetBundle();
468 appsvc_set_pkgname(kb, pkg_name);
471 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
475 appsvc_set_mime(kb, mime);
480 appsvc_set_uri(kb, uri);
483 int pid = LaunchPkg(msg, pCb, data);
485 result r = E_SUCCESS;
496 _AppControlManager::Launch(_AppMessageImpl& msg, const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
498 bundle* kb = msg.GetBundle();
499 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
503 appsvc_set_pkgname(kb, pkg_name);
506 appsvc_set_operation(kb, (op) ? op : APPSVC_OPERATION_DEFAULT);
510 appsvc_set_mime(kb, mime);
515 appsvc_set_uri(kb, uri);
518 if (_AppImpl::GetInstance() != null)
520 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
521 _AppArg::UpdateWindowHandle(kb, handle);
524 SysLog(NID_APP, "MIME(%s), URI(%s).", appsvc_get_mime(kb), appsvc_get_uri(kb));
525 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
527 result r = E_SUCCESS;
532 case APPSVC_RET_EILLACC:
533 r = E_ILLEGAL_ACCESS;
535 case APPSVC_RET_EINVAL:
542 SysLog(NID_APP, "[%s]Launching service %s failure", GetErrorMessage(r), pkg_name);
551 _AppControlManager::LaunchPkg(_AppMessageImpl& msg, AppSvcResFn pCb, void* data)
553 bundle* kb = msg.GetBundle();
554 SysTryReturn(NID_APP, kb != NULL, -1, E_OUT_OF_MEMORY, "Bundle allocation failure.");
556 if (_AppImpl::GetInstance() != null)
558 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
559 _AppArg::UpdateWindowHandle(kb, handle);
562 int pid = appsvc_run_service(kb, 0, reinterpret_cast<appsvc_res_fn>(pCb), this);
564 result r = E_SUCCESS;
569 case APPSVC_RET_EILLACC:
570 r = E_ILLEGAL_ACCESS;
572 case APPSVC_RET_EINVAL:
579 SysLog(NID_APP, "[%s] Launching service %s failure", GetErrorMessage(r), appsvc_get_appid(kb));
588 _AppControlManager::LaunchPkg(const char* pkg_name, const char* op, const char* mime, const char* uri, AppSvcResFn pCb, void* data)
592 return LaunchPkg(msg, pkg_name, op, mime, uri, pCb, data);
596 _AppControlManager::LaunchAppWithCondition(const AppId& appId, const String& condition, IList* pArrayArgs)
598 result r = E_SUCCESS;
599 _AppArg * pArg = new (std::nothrow) _AppArg();
600 SysTryCatch(NID_APP, pArg != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
602 r = pArg->ConstructForAppLaunchCondition(condition, pArrayArgs);
603 SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] ConstructForAppLaunchCondition(%ls, .. ) fails", GetErrorMessage(r), condition.GetPointer());
605 r = _AppControlManager::LaunchApp(appId, pArg);
612 _AppControlManager::LaunchApp(const AppId& appId, _AppArg* pArg, int req)
614 SysTryReturnResult(NID_APP, pArg != null, E_INVALID_ARG, "Invalid launch argument");
615 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
617 String actualAppId = appId;
618 if (appId.GetLength() == 10)
620 const String& name = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(appId);
624 actualAppId.Append(L'.');
625 actualAppId.Append(name);
629 pArg->UpdateRequestId(req);
631 if (_AppImpl::GetInstance() != null)
633 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
634 pArg->UpdateWindowHandle(handle);
640 actualAppId.SubString(0, 10, tempId);
642 tempId += String(SUBMODE_NAME);
644 // [INFO] Ugly solution for submode support
645 pArg->UpdateAppId(tempId);
646 kb = pArg->GetBundle();
648 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
651 SysLog(NID_APP, "Submode launch successful");
654 else if (pid == APPSVC_RET_EINVAL)
656 SysLog(NID_APP, "Argument overflow");
657 return E_MAX_EXCEEDED;
660 pArg->UpdateAppId(actualAppId);
662 // retry for possible failure
664 const int TRY_COUNT = 3;
665 const int TRY_SLEEP_TIME = 65;
668 kb = pArg->GetBundle();
669 pid = appsvc_run_service(kb, req, LaunchResultCb, this);
672 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
675 else if (pid == APPSVC_RET_EINVAL)
677 SysLog(NID_APP, "Argument overflow");
678 return E_MAX_EXCEEDED;
682 SysLog(NID_APP, "Waiting %dth time.", count);
683 Thread::Sleep(TRY_SLEEP_TIME);
685 while (count < TRY_COUNT);
687 result r = E_SUCCESS;
690 case APPSVC_RET_EILLACC:
691 r = E_ILLEGAL_ACCESS;
698 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
704 _IsDefaultApplication(const AppId& packageId, const String& appId)
706 const String& execName = _PackageManagerImpl::GetInstance()->GetDefaultAppExecutableName(packageId);
709 result r = appId.IndexOf(L'.', 0, index);
716 appId.SubString(index + 1, tmp);
719 SysLog(NID_APP, "Default application %ls", tmp.GetPointer());
728 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, int req)
730 return Launch(appId, pArg, reinterpret_cast<AppSvcResFn>(LaunchResultCb), this, req);
735 _AppControlManager::Launch(const _AppMessageImpl& msg, AppSvcResFn pCb, void* pData, int req)
737 const bundle* pBundle = msg.GetBundle();
740 arg.Construct(pBundle);
742 return Launch(_AppMessageImpl::GetApplicationId(pBundle), &arg, pCb, pData, req);
747 _AppControlManager::Launch(const AppId& appId, _AppArg* pArg, AppSvcResFn pCb, void* pData, int req)
749 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Invalid launch argument");
750 SysLog(NID_APP, "App: %ls.", appId.GetPointer());
752 String actualAppId = appId;
754 pArg->UpdateRequestId(req);
756 if (_AppImpl::GetInstance() != null)
758 const long handle = _AppImpl::GetInstance()->GetWindowHandle();
759 pArg->UpdateWindowHandle(handle);
766 actualAppId.SubString(0, 10, tempId);
768 const int type = _AppInfo::GetAppType();
769 if ((!(type & _APP_TYPE_SERVICE_APP)) && _IsDefaultApplication(tempId, appId))
772 tempId += String(SUBMODE_NAME);
774 // [INFO] Ugly solution for submode support
775 pArg->UpdateAppId(tempId);
776 kb = pArg->GetBundle();
778 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
781 SysLog(NID_APP, "Submode launch successful");
782 SetLastResult(E_SUCCESS);
785 else if (pid == APPSVC_RET_EINVAL)
787 SetLastResult(E_MAX_EXCEEDED);
792 pArg->UpdateAppId(actualAppId);
794 // retry for possible failure
796 const int TRY_COUNT = 3;
797 const int TRY_SLEEP_TIME = 65;
800 kb = pArg->GetBundle();
801 pid = appsvc_run_service(kb, req, reinterpret_cast<appsvc_res_fn>(pCb), pData);
804 SysLog(NID_APP, "Application(%d) launched with reqId(%d) and arg(0x%x).", pid, req, pArg);
805 SetLastResult(E_SUCCESS);
808 else if (pid == APPSVC_RET_EINVAL)
810 SetLastResult(E_MAX_EXCEEDED);
815 SysLog(NID_APP, "Waiting %dth time with %d.", count, pid);
816 Thread::Sleep(TRY_SLEEP_TIME);
818 while (count < TRY_COUNT);
820 result r = E_SUCCESS;
823 case APPSVC_RET_EILLACC:
824 r = E_ILLEGAL_ACCESS;
831 SysLogException(NID_APP, r, "[%s] Launching service failure for %ls", GetErrorMessage(r), appId.GetPointer());
840 _AppControlManager::FinishAppControl(int reqId, int res, IMap* pMap)
842 SysLog(NID_APP, "req %d, res %d.", reqId, res);
843 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, pMap, _APPCONTROL_PROPERTY_SUBMODE);
844 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
846 SendAppControlEvent(*pArg);
851 _AppControlManager::FinishAppControl(int reqId, int res, const AppId& appId, const String& oId, IMap* pMap, int prop)
853 SysLog(NID_APP, "req %d, res %d, appId(%ls), oId(%ls).", reqId, res, appId.GetPointer(), oId.GetPointer());
854 _NativeAppControlEventArg* pArg = new (std::nothrow) _NativeAppControlEventArg(reqId, res, appId, oId, pMap, prop);
855 SysTryReturnVoidResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Return argument allocation failure.");
857 SendAppControlEvent(*pArg);
862 _AppControlManager::RemoveResultRequest(int reqId)
864 __resultManager.RemoveItem(reqId);
868 _AppControlManager::FindResultRequest(int reqId) const
870 const _ResultInfo* pInfo = __resultManager.FindItem(reqId);
871 return (pInfo) ? &(pInfo->arg) : null;
875 _AppControlManager::AddLaunchRequest(_AppArg* pArg, LaunchCbType pCb, void* pData, int prop)
877 SysTryReturn(NID_APP, pArg != null, -1, E_INVALID_ARG, "[E_INVALID_ARG] Empty argument.");
879 _DataControlInfo* pItem = new (std::nothrow) _DataControlInfo(pArg, pCb, pData, prop);
880 SysTryReturn(NID_APP, pItem != null, -1, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
882 SysLog(NID_APP, "Registering callback 0x%x, 0x%x", pCb, pData);
884 return __launchManager.InsertItem(pItem);
888 _AppControlManager::RemoveLaunchRequest(int req)
890 __launchManager.RemoveItem(req);
894 _AppControlManager::RegisterRequest(service_s* service, int& req, _AppHandler& handler)
896 bundle* b = _AppArg::GetBundleFromSvc(service);
898 _AppArg* pArg = new (std::nothrow) _AppArg();
899 SysTryReturnResult(NID_APP, pArg != null, E_OUT_OF_MEMORY, "ArrayList creation failure.");
902 result r = E_SUCCESS;
904 // ownership is transfered to RequestManager
905 _ResultInfo* pItem = new (std::nothrow) _ResultInfo(*pArg);
906 SysTryCatch(NID_APP, pItem != null, , r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Empty argument.");
908 req = __resultManager.InsertItem(pItem);
909 SysTryCatch(NID_APP, req != -1, , r = E_INVALID_STATE, "[E_INVALID_STATE] Invalid argument handling state.");
911 handler = _AppArg::GetHandler(b);
923 _AppControlManager::ConvertAppControlResultCode(int resCode)
925 AppCtrlResult ret = APP_CTRL_RESULT_FAILED;
929 case SERVICE_RESULT_SUCCEEDED:
930 ret = APP_CTRL_RESULT_SUCCEEDED;
932 case SERVICE_RESULT_FAILED:
933 ret = APP_CTRL_RESULT_CANCELED;
935 case SERVICE_RESULT_CANCELED:
936 ret = APP_CTRL_RESULT_ABORTED;
938 case APPSVC_OSP_RES_FAIL:
939 ret = APP_CTRL_RESULT_FAILED;
941 case APPSVC_OSP_RES_TERMINATE:
942 ret = APP_CTRL_RESULT_TERMINATED;
945 ret = APP_CTRL_RESULT_FAILED;
954 _AppControlManager::OnAppControlResponseEventReceivedN(const Tizen::Base::Runtime::IEventArg* arg)
956 const _AppControlResponseEventArg* pEventArg = dynamic_cast<const _AppControlResponseEventArg*>(arg);
958 if (pEventArg != null)
960 IAppControlResponseListener* pResponseListener = pEventArg->GetListener();
962 if(pResponseListener != null)
964 if(pEventArg->GetType() == _APPCONTROL_RESPONSETYPE_START)
966 pResponseListener->OnAppControlStartResponseReceived(pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetResult());
967 SysLog(NID_APP, "OnAppControlStartResponseReceived called");
971 InvokeAppControlCompleteListener(*pResponseListener, pEventArg->GetAppId(), pEventArg->GetOperationId(), pEventArg->GetAppControlResult(), pEventArg->GetExtraData(), pEventArg->IsSubMode());
972 SysLog(NID_APP, "Listener called");
974 _AppControlResponseEvent* pResponseEvent = null;
975 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->GetValue(pEventArg->GetRequestId(), pResponseEvent);
976 _AppControlManager::GetInstance()->GetAppControlResponseEventContainer()->Remove(pEventArg->GetRequestId());
978 delete pResponseEvent;
979 SysLog(NID_APP, "pResponseEvent gets deleted, reqId(%d)", pEventArg->GetRequestId());
984 SysLog(NID_APP, "Invalid ResponseListener");
989 SysLog(NID_APP, "Invalid AppControl arguments : arg(0x%x)", &arg);