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_AppControlProviderManagerImpl.cpp
19 * @brief This is the implementation for the %_AppControlProviderManagerImpl class.
22 #include <FBaseDataType.h>
23 #include <FBaseString.h>
24 #include <FBaseColArrayList.h>
25 #include <FBaseColIListT.h>
26 #include <FBaseErrors.h>
27 #include <FAppAppManager.h>
28 #include <FAppAppControl.h>
29 #include <FAppAppControlProviderManager.h>
30 #include <FAppIAppControlProviderEventListener.h>
32 #include <FBaseSysLog.h>
35 #include "FApp_AppArg.h"
36 #include "FApp_AppImpl.h"
37 #include "FApp_AppInfo.h"
38 #include "FApp_AppControlManager.h"
39 #include "FApp_AppControlProviderManagerImpl.h"
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
45 namespace Tizen { namespace App
48 _AppControlProviderManagerImpl::_AppControlProviderManagerImpl(void)
52 _AppControlProviderManagerImpl::~_AppControlProviderManagerImpl(void)
57 _AppControlProviderManagerImpl::SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener)
59 _AppImpl* pAppImpl = _AppImpl::GetInstance();
60 SysTryReturn(NID_APP, pAppImpl, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting _AppImpl instance failed.");
62 return pAppImpl->SetAppControlProviderEventListener(pListener);
66 _AppControlProviderManagerImpl::SendAppControlResult(RequestId reqId, const IList* pResultList)
68 SysTryReturnResult(NID_APP, reqId != -1, E_OBJ_NOT_FOUND, "The application request %d is not found.", reqId);
70 _AppControlManager* pAppMgr = _AppControlManager::GetInstance();
72 _ResultInfo* pInfo = pAppMgr->__resultManager.FindItem(reqId);
73 SysTryReturnResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "The application request %d is not found.", reqId);
75 const _AppArg& arg = pInfo->arg;
78 result r = resArg.ConstructResult(arg, pResultList);
81 // erase _AppArg after sending the result back to the caller
82 pAppMgr->__resultManager.RemoveItem(reqId);
84 SysPropagate(NID_APP, r);
88 r = SendAppControlResultPrimitive(reqId, resArg, 0);
90 // erase _AppArg after sending the result back to the caller
91 pAppMgr->__resultManager.RemoveItem(reqId);
97 _AppControlProviderManagerImpl::SendAppControlResult(RequestId reqId, AppCtrlResult appControlResult, const IMap* pResultMap)
99 SysTryReturnResult(NID_APP, reqId != -1, E_OBJ_NOT_FOUND, "The application request %d is not found.", reqId);
101 _AppControlManager* pAppMgr = _AppControlManager::GetInstance();
103 _ResultInfo* pInfo = pAppMgr->__resultManager.FindItem(reqId);
104 SysTryReturnResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "The application request %d is not found.", reqId);
106 const _AppArg& arg = pInfo->arg;
109 result r = resArg.ConstructResult(arg, pResultMap);
112 // erase _AppArg after sending the result back to the caller
113 pAppMgr->__resultManager.RemoveItem(reqId);
115 SysPropagate(NID_APP, r);
119 const int code = appControlResult;
120 int res = APPSVC_RES_NOT_OK;
123 case APP_CTRL_RESULT_SUCCEEDED:
126 case APP_CTRL_RESULT_FAILED:
127 res = APPSVC_OSP_RES_FAIL;
129 case APP_CTRL_RESULT_CANCELED:
130 res = APPSVC_RES_NOT_OK;
132 case APP_CTRL_RESULT_TERMINATED:
133 res = APPSVC_OSP_RES_TERMINATE;
135 case APP_CTRL_RESULT_ABORTED:
136 res = APPSVC_RES_CANCEL;
139 res = APPSVC_RES_NOT_OK;
143 r = SendAppControlResultPrimitive(reqId, resArg, res);
145 // erase _AppArg after sending the result back to the caller
146 pAppMgr->__resultManager.RemoveItem(reqId);
153 _AppControlProviderManagerImpl::SendAppControlResultPrimitive(RequestId reqId, _AppArg& arg, int ret)
155 static bool firstRequestSent = false;
157 if (reqId == 0 && firstRequestSent)
159 SysLog(NID_APP, "Sent main AppControl request already.");
165 const bool isSubMode = _AppInfo::IsSubMode();
166 const bool isService = _AppInfo::GetAppType() & _APP_TYPE_SERVICE_APP;
167 bool isRaiseMode = true;
171 firstRequestSent = true;
174 if (isSubMode || isService)
180 result r = _Aul::SendResult(arg.GetBundle(), static_cast<appsvc_result_val>(ret), isRaiseMode);
181 SysLog(NID_APP, "Sent AppControl event for %d.", reqId);
189 _AppControlProviderManagerImpl::GetClientAppId(RequestId reqId) const
191 SysTryReturn(NID_APP, reqId != -1, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The application control request %d is not found.", reqId);
193 _ResultInfo* pInfo = _AppControlManager::GetInstance()->__resultManager.FindItem(reqId);
194 SysTryReturn(NID_APP, pInfo != null, L"", E_OBJ_NOT_FOUND, "[E_OB_NOT_FOUND] The application control request %d is not found.", reqId);
196 const _AppArg& arg = pInfo->arg;
198 return arg.GetCallerAppId();
201 const _AppControlProviderManagerImpl*
202 _AppControlProviderManagerImpl::GetInstance(const AppControlProviderManager& ac)
204 return ac.__pAppControlProviderManagerImpl;
207 _AppControlProviderManagerImpl*
208 _AppControlProviderManagerImpl::GetInstance(AppControlProviderManager& ac)
210 return ac.__pAppControlProviderManagerImpl;