sync with tizen_2.0
[platform/framework/native/appfw.git] / src / app / FApp_AppControlProviderManagerImpl.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_AppControlProviderManagerImpl.cpp
20  * @brief       This is the implementation for the %_AppControlProviderManagerImpl class.
21  */
22
23 #include <FBaseDataType.h>
24 #include <FBaseString.h>
25 #include <FBaseColArrayList.h>
26 #include <FBaseColIListT.h>
27 #include <FBaseErrors.h>
28 #include <FAppAppManager.h>
29 #include <FAppAppControl.h>
30 #include <FAppAppControlProviderManager.h>
31 #include <FAppIAppControlProviderEventListener.h>
32
33 #include <FBaseSysLog.h>
34
35 #include "FApp_Aul.h"
36 #include "FApp_AppArg.h"
37 #include "FApp_AppImpl.h"
38 #include "FApp_AppControlManager.h"
39 #include "FApp_AppControlProviderManagerImpl.h"
40
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
43
44
45 namespace Tizen { namespace App
46 {
47
48 _AppControlProviderManagerImpl::_AppControlProviderManagerImpl(void)
49 {
50 }
51
52 _AppControlProviderManagerImpl::~_AppControlProviderManagerImpl(void)
53 {
54 }
55
56 result
57 _AppControlProviderManagerImpl::SetAppControlProviderEventListener(IAppControlProviderEventListener* pListener)
58 {
59         _AppImpl* pAppImpl = _AppImpl::GetInstance();
60         SysTryReturn(NID_APP, pAppImpl, false, E_INVALID_STATE, "[E_INVALID_STATE] Getting _AppImpl instance failed.");
61
62         return pAppImpl->SetAppControlProviderEventListener(pListener);
63 }
64
65 result
66 _AppControlProviderManagerImpl::SendAppControlResult(RequestId reqId, const IList* pResultList)
67 {
68         SysTryReturnResult(NID_APP, reqId != -1, E_OBJ_NOT_FOUND, "The application request %d is not found.", reqId);
69
70         _AppControlManager* pAppMgr = _AppControlManager::GetInstance();
71
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);
74
75         const _AppArg& arg = pInfo->arg;
76
77         _AppArg resArg;
78         result r = resArg.ConstructResult(arg, pResultList);
79         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
80
81         //resArg.Print();
82         r = _Aul::SendResult(resArg.GetBundle(), static_cast<appsvc_result_val>(0));
83         SysLog(NID_APP, "Sent AppControl event for %d.", reqId);
84
85         // erase _AppArg after sending the result back to the caller
86         pAppMgr->__resultManager.RemoveItem(reqId);
87
88         return r;
89 }
90
91 result
92 _AppControlProviderManagerImpl::SendAppControlResult(RequestId reqId, AppCtrlResult appControlResult, const IMap* pResultMap)
93 {
94         SysTryReturnResult(NID_APP, reqId != -1, E_OBJ_NOT_FOUND, "The application request %d is not found.", reqId);
95
96         _AppControlManager* pAppMgr = _AppControlManager::GetInstance();
97
98         _ResultInfo* pInfo = pAppMgr->__resultManager.FindItem(reqId);
99         SysTryReturnResult(NID_APP, pInfo != null, E_OBJ_NOT_FOUND, "The application request %d is not found.", reqId);
100
101         const _AppArg& arg = pInfo->arg;
102
103         _AppArg resArg;
104         result r = resArg.ConstructResult(arg, pResultMap);
105         SysTryReturn(NID_APP, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
106
107         const int code = appControlResult;
108         int res = APPSVC_RES_NOT_OK;
109         switch (code)
110         {
111         case APP_CTRL_RESULT_SUCCEEDED:
112                 res = APPSVC_RES_OK;
113                 break;
114         case APP_CTRL_RESULT_FAILED:
115                 res = APPSVC_OSP_RES_FAIL;
116                 break;
117         case APP_CTRL_RESULT_CANCELED:
118                 res = APPSVC_RES_NOT_OK;
119                 break;
120         case APP_CTRL_RESULT_TERMINATED:
121                 res = APPSVC_OSP_RES_TERMINATE;
122                 break;
123         case APP_CTRL_RESULT_ABORTED:
124                 res = APPSVC_RES_CANCEL;
125                 break;
126         default:
127                 res = APPSVC_RES_NOT_OK;
128                 break;
129         }
130
131         //resArg.Print();
132         r = _Aul::SendResult(resArg.GetBundle(), static_cast<appsvc_result_val>(res));
133         SysLog(NID_APP, "Sent AppControl event for %d.", reqId);
134
135         // erase _AppArg after sending the result back to the caller
136         pAppMgr->__resultManager.RemoveItem(reqId);
137
138         return r;
139 }
140
141 AppId
142 _AppControlProviderManagerImpl::GetClientAppId(RequestId reqId) const
143 {
144         SysTryReturn(NID_APP, reqId != -1, L"", E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The application control request %d is not found.", reqId);
145
146         _ResultInfo* pInfo = _AppControlManager::GetInstance()->__resultManager.FindItem(reqId);
147         SysTryReturn(NID_APP, pInfo != null, L"", E_OBJ_NOT_FOUND, "[E_OB_NOT_FOUND] The application control request %d is not found.", reqId);
148
149         const _AppArg& arg = pInfo->arg;
150
151         return arg.GetCallerAppId();
152 }
153
154 const _AppControlProviderManagerImpl*
155 _AppControlProviderManagerImpl::GetInstance(const AppControlProviderManager& ac)
156 {
157         return ac.__pAppControlProviderManagerImpl;
158 }
159
160 _AppControlProviderManagerImpl*
161 _AppControlProviderManagerImpl::GetInstance(AppControlProviderManager& ac)
162 {
163         return ac.__pAppControlProviderManagerImpl;
164 }
165
166 } } // Tizen::App
167