Fix : Search APIs don't return exception despite the content in DB doesn't match...
[platform/framework/native/content.git] / src / FCntContentTransfer.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  * @file                FCntContentTransfer.cpp
18  * @brief               This is the implementation file for the %ContentTransfer class.
19  *
20  * This file contains implementation of the %ContentTransfer class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FCntContentTransfer.h>
25 #include <FBaseColIList.h>
26 #include <FBaseUtilUri.h>
27 #include <FCnt_ContentTransferImpl.h>
28 #include <FSec_AccessController.h>
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Security;
32
33 namespace Tizen { namespace Content
34 {
35 ContentTransfer::ContentTransfer(void)
36         : Object()
37         , __pImpl(null)
38 {
39
40 }
41
42 ContentTransfer::~ContentTransfer(void)
43 {
44         if (__pImpl != null)
45         {
46                 delete __pImpl;
47                 __pImpl = null;
48         }
49 }
50
51 result
52 ContentTransfer::Construct(IContentTransferListener& listener)
53 {
54         ClearLastResult();
55         result r = E_SUCCESS;
56
57         SysAssertf(__pImpl == null,
58                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
59
60         _ContentTransferImpl* pContentTransferImpl = new (std::nothrow) _ContentTransferImpl();
61         SysTryReturn(NID_CNT, pContentTransferImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Construct failed.");
62
63         r = pContentTransferImpl->Construct(listener);
64         SysTryCatch(NID_CNT, r == E_SUCCESS, , r, "[%S] Propagating.", GetErrorMessage(r));
65
66         __pImpl = pContentTransferImpl;
67
68         return E_SUCCESS;
69
70 CATCH:
71         delete pContentTransferImpl;
72         pContentTransferImpl = null;
73
74         return r;
75 }
76
77 result
78 ContentTransfer::Cancel(RequestId reqId)
79 {
80         ClearLastResult();
81         result r = E_SUCCESS;
82
83         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
84
85         r = __pImpl->Cancel(reqId);
86         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Cancel failed.", GetErrorMessage(r));
87
88         return r;
89 }
90
91 void
92 ContentTransfer::SetDefaultTimeout(int sec)
93 {
94         if (__pImpl == null)
95         {
96                 SysLog(NID_CNT, "__pImpl is null.");
97                 return;
98         }
99         __pImpl->SetDefaultTimeout(sec);
100 }
101
102 int
103 ContentTransfer::GetDefaultTimeout(void) const
104 {
105         if (__pImpl == null)
106         {
107                 SysLog(NID_CNT, "__pImpl is null.");
108                 return 0;
109         }
110         return __pImpl->GetDefaultTimeout();
111 }
112
113 result
114 ContentTransfer::Remove(RequestId reqId)
115 {
116         ClearLastResult();
117         result r = E_SUCCESS;
118
119         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
120
121         r = __pImpl->Remove(reqId);
122         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Remove failed.", GetErrorMessage(r));
123
124         return r;
125 }
126
127 result
128 ContentTransfer::RemoveAll(void)
129 {
130         ClearLastResult();
131         result r = E_SUCCESS;
132
133         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
134
135         r = __pImpl->RemoveAll();
136         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] RemoveAll failed.", GetErrorMessage(r));
137
138         return r;
139 }
140
141 result
142 ContentTransfer::CancelAll(void)
143 {
144         ClearLastResult();
145         result r = E_SUCCESS;
146
147         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
148
149         r = __pImpl->CancelAll();
150         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] CancelAll failed.", GetErrorMessage(r));
151
152         return r;
153 }
154
155 Collection::IList*
156 ContentTransfer::GetContentTransferInfoListN(void) const
157 {
158         if (__pImpl == null)
159         {
160                 SysLog(NID_CNT, "__pImpl is null.");
161                 return null;
162         }
163         return __pImpl->GetContentTransferInfoListN();
164 }
165
166 Collection::IList*
167 ContentTransfer::GetContentTransferInfoListInProgressN(void) const
168 {
169         if (__pImpl == null)
170         {
171                 SysLog(NID_CNT, "__pImpl is null.");
172                 return null;
173         }
174         return __pImpl->GetContentTransferInfoListInProgressN();
175 }
176
177 void
178 ContentTransfer::SetProgressIntervalByPercent(int percent)
179 {
180         if (__pImpl == null)
181         {
182                 SysLog(NID_CNT, "__pImpl is null.");
183                 return;
184         }
185         __pImpl->SetProgressIntervalByPercent(percent);
186 }
187
188 result
189 ContentTransfer::Download(const Utility::Uri& uri, int fileSize, const String& destFilePath, bool replace,
190                 RequestId& reqId, IContentTransferListener* pListener, int sec)
191 {
192         ClearLastResult();
193         result r = E_SUCCESS;
194
195         // Checks the privilege
196         r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
197         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
198         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
199
200         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
201
202         r = __pImpl->Download(uri, fileSize, destFilePath, replace, reqId, pListener, sec);
203         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Download failed.", GetErrorMessage(r));
204
205         return r;
206 }
207
208 result
209 ContentTransfer::Download(const Utility::Uri& uri, const String& filePath,
210                                                   RequestId& reqId, bool replace, int timeout, int progressInterval)
211 {
212         ClearLastResult();
213         result r = E_SUCCESS;
214
215         // Checks the privilege
216         r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
217         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
218         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
219
220         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
221
222         r = __pImpl->Download(uri, filePath, reqId, replace, timeout, progressInterval);
223         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] Download failed.", GetErrorMessage(r));
224
225         return r;
226 }
227
228 result
229 ContentTransfer::DownloadToBuffer(const Utility::Uri& uri, int fileSize, RequestId& reqId,IContentTransferListener* pListener, int sec)
230 {
231         ClearLastResult();
232         result r = E_SUCCESS;
233
234         r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
235         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
236         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
237
238         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
239
240         r = __pImpl->DownloadToBuffer(uri, fileSize, reqId, pListener, sec);
241         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DownloadToBuffer failed.", GetErrorMessage(r));
242
243         return r;
244 }
245
246 result
247 ContentTransfer::DownloadToBuffer(const Utility::Uri& uri, RequestId& reqId, int timeout, int progressInterval)
248 {
249         ClearLastResult();
250         result r = E_SUCCESS;
251
252         r = _AccessController::CheckUserPrivilege(_PRV_DOWNLOAD);
253         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
254         SysTryReturnResult(NID_CNT, r == E_SUCCESS, r, "The application is not permitted to call this method.");
255
256         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
257
258         r = __pImpl->DownloadToBuffer(uri, reqId, timeout, progressInterval);
259         SysTryReturn(NID_CNT, !IsFailed(r), r, r, "[%s] DownloadToBuffer failed.", GetErrorMessage(r));
260
261         return r;
262 }
263 }}