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